File size: 7,965 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | // SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 David Friedli <david[at]friedli-be.ch> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#ifndef GUI_VIEWPROVIDER_MEASUREMENTBASE_H
#define GUI_VIEWPROVIDER_MEASUREMENTBASE_H
#include <Mod/Measure/MeasureGlobal.h>
#include <QString>
#include <App/Application.h>
#include <App/PropertyStandard.h>
#include <Base/Parameter.h>
#include <Gui/ViewProviderDocumentObject.h>
#include <Gui/SoTextLabel.h>
#include <Gui/ViewProviderDocumentObjectGroup.h>
#include <Mod/Measure/App/MeasureBase.h>
// NOLINTBEGIN
class SbVec2s;
class SoFontStyle;
class SoBaseColor;
class SoText2;
class SoTranslation;
class SoPickStyle;
class SoCoordinate3;
class SoIndexedLineSet;
class SoTranslate2Dragger;
// NOLINTEND
namespace MeasureGui
{
class MeasureGuiExport ViewProviderMeasureGroup: public Gui::ViewProviderDocumentObjectGroup
{
PROPERTY_HEADER_WITH_OVERRIDE(MeasureGui::ViewProviderMeasureGroup);
public:
ViewProviderMeasureGroup();
~ViewProviderMeasureGroup() override;
bool allowOverride(const App::DocumentObject&) const override
{
return true;
}
QIcon getIcon() const override;
};
// NOLINTBEGIN
class MeasureGuiExport ViewProviderMeasureBase: public Gui::ViewProviderDocumentObject
{
PROPERTY_HEADER_WITH_OVERRIDE(MeasureGui::ViewProviderMeasureBase);
public:
/// constructor.
ViewProviderMeasureBase();
/// destructor.
~ViewProviderMeasureBase() override;
// Display properties
App::PropertyColor TextColor;
App::PropertyColor TextBackgroundColor;
App::PropertyColor LineColor;
App::PropertyInteger FontSize;
// NOLINTEND
// Fields
SoSFFloat fieldFontSize;
/**
* Attaches the document object to this view provider.
*/
bool isPartOfPhysicalObject() const override
{
return false;
};
void attach(App::DocumentObject* pcObj) override;
void updateData(const App::Property* prop) override;
virtual void positionAnno(const Measure::MeasureBase* measureObject);
void finishRestoring() override;
bool useNewSelectionModel() const override
{
return true;
}
std::vector<std::string> getDisplayModes() const override;
void setDisplayMode(const char* ModeName) override;
/// Show the annotation in the 3d window
void show() override;
virtual void redrawAnnotation();
Measure::MeasureBase* getMeasureObject();
virtual bool isSubjectVisible();
static Base::Vector3d toVector3d(SbVec3f svec)
{
return Base::Vector3d(svec[0], svec[1], svec[2]);
}
static SbVec3f toSbVec3f(Base::Vector3d vec3)
{
return SbVec3f(vec3.x, vec3.y, vec3.z);
}
void onSubjectVisibilityChanged(const App::DocumentObject& docObj, const App::Property& prop);
void connectToSubject(App::DocumentObject* subject);
void connectToSubject(std::vector<App::DocumentObject*> subject);
protected:
static void draggerChangedCallback(void* data, SoDragger*);
void onChanged(const App::Property* prop) override;
virtual void onLabelMoved() {};
void setLabelValue(const Base::Quantity& value);
void setLabelValue(const QString& value);
void setLabelTranslation(const SbVec3f& position);
void updateIcon();
SoPickStyle* getSoPickStyle();
SoDrawStyle* getSoLineStylePrimary();
SoDrawStyle* getSoLineStyleSecondary();
SoSeparator* getSoSeparatorText();
static constexpr double defaultTolerance = 10e-6;
virtual Base::Vector3d getTextDirection(
Base::Vector3d elementDirection,
double tolerance = defaultTolerance
);
float getViewScale();
// TODO: getters & setters and move variables to private?
bool _mShowTree = true;
SoSeparator* pGlobalSeparator; // Separator in the global coordinate space
Gui::SoFrameLabel* pLabel;
SoTranslate2Dragger* pDragger;
SoTransform* pDraggerOrientation;
SoTransform* pLabelTranslation;
SoBaseColor* pColor;
SoSeparator* pRootSeparator;
SoSeparator* pTextSeparator;
SoSeparator* pLineSeparator;
SoSeparator* pLineSeparatorSecondary;
private:
fastsignals::connection _mVisibilityChangedConnection;
};
// NOLINTBEGIN
class MeasureGuiExport ViewProviderMeasure: public MeasureGui::ViewProviderMeasureBase
{
PROPERTY_HEADER_WITH_OVERRIDE(MeasureGui::ViewProviderMeasure);
// NOLINTEND
public:
/// Constructor
ViewProviderMeasure();
~ViewProviderMeasure() override;
void redrawAnnotation() override;
void positionAnno(const Measure::MeasureBase* measureObject) override;
protected:
void onChanged(const App::Property* prop) override;
virtual Base::Vector3d getBasePosition();
virtual Base::Vector3d getTextPosition();
private:
SoCoordinate3* pCoords;
SoIndexedLineSet* pLines;
};
class ViewProviderMeasureArea: public ViewProviderMeasure
{
PROPERTY_HEADER(MeasureGui::ViewProviderMeasureArea);
public:
ViewProviderMeasureArea()
{
sPixmap = "Measurement-Area";
}
};
class ViewProviderMeasureLength: public ViewProviderMeasure
{
PROPERTY_HEADER(MeasureGui::ViewProviderMeasureLength);
public:
ViewProviderMeasureLength()
{
sPixmap = "Measurement-Distance";
}
};
class ViewProviderMeasurePosition: public ViewProviderMeasure
{
PROPERTY_HEADER(MeasureGui::ViewProviderMeasurePosition);
public:
ViewProviderMeasurePosition()
{
sPixmap = "Measurement-Position";
}
};
class ViewProviderMeasureRadius: public ViewProviderMeasure
{
PROPERTY_HEADER(MeasureGui::ViewProviderMeasureRadius);
public:
ViewProviderMeasureRadius()
{
sPixmap = "Measurement-Radius";
}
};
class ViewProviderMeasureDiameter: public ViewProviderMeasure
{
PROPERTY_HEADER(MeasureGui::ViewProviderMeasureDiameter);
public:
ViewProviderMeasureDiameter()
{
sPixmap = "Measurement-Diameter";
}
};
class ViewProviderMeasureCOM: public ViewProviderMeasure
{
PROPERTY_HEADER(MeasureGui::ViewProviderMeasureCOM);
public:
ViewProviderMeasureCOM()
{
sPixmap = "Measurement-CenterOfMass";
}
};
} // namespace MeasureGui
#endif // GUI_VIEWPROVIDER_MEASUREMENTBASE_H
|