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

Commit 5b23208

Browse files
committed
Core datums: Rework to improve new sketch
1 parent 9efa615 commit 5b23208

File tree

9 files changed

+179
-74
lines changed

9 files changed

+179
-74
lines changed

src/Gui/ViewProviderCoordinateSystem.cpp

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

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

101101
bool saveState = tempVisMap.empty();
@@ -135,7 +135,7 @@ void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane)
135135
if (saveState) {
136136
tempVisMap[vp] = vp->isVisible();
137137
}
138-
vp->setVisible(plane);
138+
vp->setVisible(points);
139139
}
140140
}
141141

@@ -168,6 +168,45 @@ bool ViewProviderCoordinateSystem::isTemporaryVisibility() {
168168
return !tempVisMap.empty();
169169
}
170170

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

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

184223
auto origin = dynamic_cast<App::Origin*>(lcs);
185224
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)