Skip to content
This repository was archived by the owner on Mar 1, 2025. It is now read-only.

Commit e977eb4

Browse files
PaddleStrokemaxwxyz
authored andcommitted
Core datums: Rework to improve new sketch
1 parent 7083362 commit e977eb4

File tree

10 files changed

+185
-77
lines changed

10 files changed

+185
-77
lines changed

src/Gui/ViewProviderCoordinateSystem.cpp

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void ViewProviderCoordinateSystem::setDisplayMode(const char* ModeName)
9797
ViewProviderDocumentObject::setDisplayMode(ModeName);
9898
}
9999

100-
void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane) {
100+
void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane, bool points) {
101101
auto origin = static_cast<App::Origin*>( getObject() );
102102

103103
bool saveState = tempVisMap.empty();
@@ -137,7 +137,7 @@ void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane)
137137
if (saveState) {
138138
tempVisMap[vp] = vp->isVisible();
139139
}
140-
vp->setVisible(plane);
140+
vp->setVisible(points);
141141
}
142142
}
143143

@@ -170,6 +170,45 @@ bool ViewProviderCoordinateSystem::isTemporaryVisibility() {
170170
return !tempVisMap.empty();
171171
}
172172

173+
void ViewProviderCoordinateSystem::setPlaneLabelVisibility(bool val)
174+
{
175+
auto lcs = getObject<App::LocalCoordinateSystem>();
176+
for (auto* plane : lcs->planes()) {
177+
auto* vp = dynamic_cast<Gui::ViewProviderPlane*>(
178+
Gui::Application::Instance->getViewProvider(plane));
179+
if (vp) {
180+
vp->setLabelVisibility(val);
181+
}
182+
}
183+
184+
}
185+
186+
void ViewProviderCoordinateSystem::setTemporaryScale(double factor)
187+
{
188+
auto lcs = getObject<App::LocalCoordinateSystem>();
189+
auto& objs = lcs->OriginFeatures.getValues();
190+
for (auto* obj : objs) {
191+
auto* vp = dynamic_cast<Gui::ViewProviderDatum*>(
192+
Gui::Application::Instance->getViewProvider(obj));
193+
if (vp) {
194+
vp->setTemporaryScale(factor);
195+
}
196+
}
197+
}
198+
199+
void ViewProviderCoordinateSystem::resetTemporarySize()
200+
{
201+
auto lcs = getObject<App::LocalCoordinateSystem>();
202+
auto& objs = lcs->OriginFeatures.getValues();
203+
for (auto* obj : objs) {
204+
auto* vp = dynamic_cast<Gui::ViewProviderDatum*>(
205+
Gui::Application::Instance->getViewProvider(obj));
206+
if (vp) {
207+
vp->resetTemporarySize();
208+
}
209+
}
210+
}
211+
173212
void ViewProviderCoordinateSystem::updateData(const App::Property* prop) {
174213
auto* jcs = dynamic_cast<App::LocalCoordinateSystem*>(getObject());
175214
if(jcs) {
@@ -181,7 +220,7 @@ void ViewProviderCoordinateSystem::updateData(const App::Property* prop) {
181220
}
182221

183222
bool ViewProviderCoordinateSystem::onDelete(const std::vector<std::string> &) {
184-
auto lcs = static_cast<App::LocalCoordinateSystem*>(getObject());
223+
auto lcs = getObject<App::LocalCoordinateSystem>();
185224

186225
auto origin = dynamic_cast<App::Origin*>(lcs);
187226
if (origin && !origin->getInList().empty()) {

src/Gui/ViewProviderCoordinateSystem.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,18 @@ class GuiExport ViewProviderCoordinateSystem : public ViewProviderGeoFeatureGrou
6060
*/
6161
///@{
6262
/// Set temporary visibility of some of origin's objects e.g. while rotating or mirroring
63-
void setTemporaryVisibility (bool axis, bool planes);
63+
void setTemporaryVisibility (bool axis, bool planes, bool points = false);
6464
/// Returns true if the origin in temporary visibility mode
6565
bool isTemporaryVisibility ();
6666
/// Reset the visibility
6767
void resetTemporaryVisibility ();
6868
///@}
6969

70+
void setTemporaryScale(double factor);
71+
void resetTemporarySize();
72+
73+
void setPlaneLabelVisibility(bool val);
74+
7075
bool canDragObjects() const override {
7176
return false;
7277
}

src/Gui/ViewProviderDatum.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "PreCompiled.h"
2424

2525
#ifndef _PreComp_
26-
# include <Inventor/nodes/SoText2.h>
2726
# include <Inventor/nodes/SoAnnotation.h>
2827
# include <Inventor/nodes/SoDrawStyle.h>
2928
# include <Inventor/nodes/SoFont.h>
@@ -60,17 +59,12 @@ ViewProviderDatum::ViewProviderDatum() {
6059
pRoot = new SoSeparator();
6160
pRoot->ref();
6261

63-
// Create the Label node
64-
pLabel = new SoText2();
65-
pLabel->ref();
66-
6762
lineThickness = 2.0;
6863
}
6964

7065

7166
ViewProviderDatum::~ViewProviderDatum() {
7267
pRoot->unref();
73-
pLabel->unref();
7468
}
7569

7670

@@ -132,20 +126,27 @@ void ViewProviderDatum::attach(App::DocumentObject* pcObject)
132126

133127
sep->addChild(visible);
134128

135-
136-
// Scale feature to the given size
137-
float sz = App::GetApplication()
138-
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
139-
->GetFloat("LocalCoordinateSystemSize", 1.0); // NOLINT
140-
141129
soScale->setPart("shape", sep);
142-
soScale->scaleFactor = sz;
130+
resetTemporarySize();
143131

144132
highlight->addChild(soScale);
145133

146134
addDisplayMaskMode(highlight, "Base");
147135
}
148136

137+
void ViewProviderDatum::setTemporaryScale(double factor)
138+
{
139+
soScale->scaleFactor = soScale->scaleFactor.getValue() * factor;
140+
}
141+
142+
void ViewProviderDatum::resetTemporarySize()
143+
{
144+
float sz = App::GetApplication()
145+
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
146+
->GetFloat("LocalCoordinateSystemSize", 1.0); // NOLINT
147+
148+
soScale->scaleFactor = sz;
149+
}
149150

150151
void ViewProviderDatum::onChanged(const App::Property* prop) {
151152
ViewProviderGeometryObject::onChanged(prop);

src/Gui/ViewProviderDatum.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#include "ViewProviderGeometryObject.h"
2727

28-
class SoText2;
2928
class SoScale;
3029

3130
namespace Gui
@@ -46,9 +45,6 @@ namespace Gui
4645
/// Get point derived classes will add their specific stuff
4746
SoSeparator* getDatumRoot() const { return pRoot; }
4847

49-
/// Get pointer to the text label associated with the feature
50-
SoText2* getLabel() const { return pLabel; }
51-
5248
void attach(App::DocumentObject*) override;
5349
std::vector<std::string> getDisplayModes() const override;
5450
void setDisplayMode(const char* ModeName) override;
@@ -63,13 +59,15 @@ namespace Gui
6359
{ }
6460
///@}
6561

62+
void setTemporaryScale(double factor);
63+
void resetTemporarySize();
64+
6665
protected:
6766
void onChanged(const App::Property* prop) override;
6867
bool onDelete(const std::vector<std::string>&) override;
6968
protected:
7069
SoSeparator* pRoot;
7170
SoShapeScale* soScale;
72-
SoText2* pLabel;
7371
double lineThickness;
7472
};
7573

src/Gui/ViewProviderLine.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#ifndef _PreComp_
2727
# include <Inventor/nodes/SoText2.h>
28-
# include <Inventor/nodes/SoAsciiText.h>
2928
# include <Inventor/nodes/SoCoordinate3.h>
3029
# include <Inventor/nodes/SoIndexedLineSet.h>
3130
# include <Inventor/nodes/SoPickStyle.h>
@@ -48,6 +47,8 @@ PROPERTY_SOURCE(Gui::ViewProviderLine, Gui::ViewProviderDatum)
4847
ViewProviderLine::ViewProviderLine()
4948
{
5049
sPixmap = "Std_Axis";
50+
51+
pLabel = new SoText2();
5152
}
5253

5354
ViewProviderLine::~ViewProviderLine() = default;
@@ -63,17 +64,17 @@ void ViewProviderLine::attach(App::DocumentObject *obj) {
6364
if (strncmp(name, axisRoles[0], strlen(axisRoles[0])) == 0) {
6465
// X-axis: red
6566
ShapeAppearance.setDiffuseColor(ViewParams::instance()->getAxisXColor());
66-
pLabel->string.setValue(SbString("X"));
67+
pLabel->string.setValue("X");
6768
}
6869
else if (strncmp(name, axisRoles[1], strlen(axisRoles[1])) == 0) {
6970
// Y-axis: green
7071
ShapeAppearance.setDiffuseColor(ViewParams::instance()->getAxisYColor());
71-
pLabel->string.setValue(SbString("Y"));
72+
pLabel->string.setValue("Y");
7273
}
7374
else if (strncmp(name, axisRoles[2], strlen(axisRoles[2])) == 0) {
7475
// Z-axis: blue
7576
ShapeAppearance.setDiffuseColor(ViewParams::instance()->getAxisZColor());
76-
pLabel->string.setValue(SbString("Z"));
77+
pLabel->string.setValue("Z");
7778
}
7879
else {
7980
noRole = true;
@@ -114,5 +115,5 @@ void ViewProviderLine::attach(App::DocumentObject *obj) {
114115
ps->style.setValue(SoPickStyle::SHAPE_ON_TOP);
115116
sep->addChild(ps);
116117

117-
sep->addChild ( getLabel () );
118+
sep->addChild (pLabel);
118119
}

src/Gui/ViewProviderLine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#include "ViewProviderDatum.h"
2929

30+
class SoText2;
31+
3032
namespace Gui
3133
{
3234

@@ -38,6 +40,9 @@ class GuiExport ViewProviderLine : public ViewProviderDatum {
3840
~ViewProviderLine() override;
3941

4042
void attach ( App::DocumentObject * ) override;
43+
44+
protected:
45+
CoinPtr<SoText2> pLabel;
4146
};
4247

4348
} //namespace Gui

0 commit comments

Comments
 (0)