diff --git a/src/Gui/ViewProviderCoordinateSystem.cpp b/src/Gui/ViewProviderCoordinateSystem.cpp index 689c51aef4..2d57a94c8e 100644 --- a/src/Gui/ViewProviderCoordinateSystem.cpp +++ b/src/Gui/ViewProviderCoordinateSystem.cpp @@ -97,7 +97,7 @@ void ViewProviderCoordinateSystem::setDisplayMode(const char* ModeName) ViewProviderDocumentObject::setDisplayMode(ModeName); } -void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane) { +void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane, bool points) { auto origin = static_cast( getObject() ); bool saveState = tempVisMap.empty(); @@ -137,7 +137,7 @@ void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane) if (saveState) { tempVisMap[vp] = vp->isVisible(); } - vp->setVisible(plane); + vp->setVisible(points); } } @@ -170,6 +170,45 @@ bool ViewProviderCoordinateSystem::isTemporaryVisibility() { return !tempVisMap.empty(); } +void ViewProviderCoordinateSystem::setPlaneLabelVisibility(bool val) +{ + auto lcs = getObject(); + for (auto* plane : lcs->planes()) { + auto* vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(plane)); + if (vp) { + vp->setLabelVisibility(val); + } + } + +} + +void ViewProviderCoordinateSystem::setTemporaryScale(double factor) +{ + auto lcs = getObject(); + auto& objs = lcs->OriginFeatures.getValues(); + for (auto* obj : objs) { + auto* vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(obj)); + if (vp) { + vp->setTemporaryScale(factor); + } + } +} + +void ViewProviderCoordinateSystem::resetTemporarySize() +{ + auto lcs = getObject(); + auto& objs = lcs->OriginFeatures.getValues(); + for (auto* obj : objs) { + auto* vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(obj)); + if (vp) { + vp->resetTemporarySize(); + } + } +} + void ViewProviderCoordinateSystem::updateData(const App::Property* prop) { auto* jcs = dynamic_cast(getObject()); if(jcs) { @@ -181,7 +220,7 @@ void ViewProviderCoordinateSystem::updateData(const App::Property* prop) { } bool ViewProviderCoordinateSystem::onDelete(const std::vector &) { - auto lcs = static_cast(getObject()); + auto lcs = getObject(); auto origin = dynamic_cast(lcs); if (origin && !origin->getInList().empty()) { diff --git a/src/Gui/ViewProviderCoordinateSystem.h b/src/Gui/ViewProviderCoordinateSystem.h index 02a392d4e1..1f812a5a66 100644 --- a/src/Gui/ViewProviderCoordinateSystem.h +++ b/src/Gui/ViewProviderCoordinateSystem.h @@ -60,13 +60,18 @@ public: */ ///@{ /// Set temporary visibility of some of origin's objects e.g. while rotating or mirroring - void setTemporaryVisibility (bool axis, bool planes); + void setTemporaryVisibility (bool axis, bool planes, bool points = false); /// Returns true if the origin in temporary visibility mode bool isTemporaryVisibility (); /// Reset the visibility void resetTemporaryVisibility (); ///@} + void setTemporaryScale(double factor); + void resetTemporarySize(); + + void setPlaneLabelVisibility(bool val); + bool canDragObjects() const override { return false; } diff --git a/src/Gui/ViewProviderDatum.cpp b/src/Gui/ViewProviderDatum.cpp index 1e30a3ea66..c4714c9c6e 100644 --- a/src/Gui/ViewProviderDatum.cpp +++ b/src/Gui/ViewProviderDatum.cpp @@ -23,7 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include # include # include # include @@ -60,17 +59,12 @@ ViewProviderDatum::ViewProviderDatum() { pRoot = new SoSeparator(); pRoot->ref(); - // Create the Label node - pLabel = new SoText2(); - pLabel->ref(); - lineThickness = 2.0; } ViewProviderDatum::~ViewProviderDatum() { pRoot->unref(); - pLabel->unref(); } @@ -132,20 +126,27 @@ void ViewProviderDatum::attach(App::DocumentObject* pcObject) sep->addChild(visible); - - // Scale feature to the given size - float sz = App::GetApplication() - .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") - ->GetFloat("LocalCoordinateSystemSize", 1.0); // NOLINT - soScale->setPart("shape", sep); - soScale->scaleFactor = sz; + resetTemporarySize(); highlight->addChild(soScale); addDisplayMaskMode(highlight, "Base"); } +void ViewProviderDatum::setTemporaryScale(double factor) +{ + soScale->scaleFactor = soScale->scaleFactor.getValue() * factor; +} + +void ViewProviderDatum::resetTemporarySize() +{ + float sz = App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetFloat("LocalCoordinateSystemSize", 1.0); // NOLINT + + soScale->scaleFactor = sz; +} void ViewProviderDatum::onChanged(const App::Property* prop) { ViewProviderGeometryObject::onChanged(prop); diff --git a/src/Gui/ViewProviderDatum.h b/src/Gui/ViewProviderDatum.h index e2c25559d0..6ae24abae3 100644 --- a/src/Gui/ViewProviderDatum.h +++ b/src/Gui/ViewProviderDatum.h @@ -25,7 +25,6 @@ #include "ViewProviderGeometryObject.h" -class SoText2; class SoScale; namespace Gui @@ -46,9 +45,6 @@ namespace Gui /// Get point derived classes will add their specific stuff SoSeparator* getDatumRoot() const { return pRoot; } - /// Get pointer to the text label associated with the feature - SoText2* getLabel() const { return pLabel; } - void attach(App::DocumentObject*) override; std::vector getDisplayModes() const override; void setDisplayMode(const char* ModeName) override; @@ -63,13 +59,15 @@ namespace Gui { } ///@} + void setTemporaryScale(double factor); + void resetTemporarySize(); + protected: void onChanged(const App::Property* prop) override; bool onDelete(const std::vector&) override; protected: SoSeparator* pRoot; SoShapeScale* soScale; - SoText2* pLabel; double lineThickness; }; diff --git a/src/Gui/ViewProviderLine.cpp b/src/Gui/ViewProviderLine.cpp index 3cf3fdb85b..d2e2482c32 100644 --- a/src/Gui/ViewProviderLine.cpp +++ b/src/Gui/ViewProviderLine.cpp @@ -25,7 +25,6 @@ #ifndef _PreComp_ # include -# include # include # include # include @@ -48,6 +47,8 @@ PROPERTY_SOURCE(Gui::ViewProviderLine, Gui::ViewProviderDatum) ViewProviderLine::ViewProviderLine() { sPixmap = "Std_Axis"; + + pLabel = new SoText2(); } ViewProviderLine::~ViewProviderLine() = default; @@ -63,17 +64,17 @@ void ViewProviderLine::attach(App::DocumentObject *obj) { if (strncmp(name, axisRoles[0], strlen(axisRoles[0])) == 0) { // X-axis: red ShapeAppearance.setDiffuseColor(ViewParams::instance()->getAxisXColor()); - pLabel->string.setValue(SbString("X")); + pLabel->string.setValue("X"); } else if (strncmp(name, axisRoles[1], strlen(axisRoles[1])) == 0) { // Y-axis: green ShapeAppearance.setDiffuseColor(ViewParams::instance()->getAxisYColor()); - pLabel->string.setValue(SbString("Y")); + pLabel->string.setValue("Y"); } else if (strncmp(name, axisRoles[2], strlen(axisRoles[2])) == 0) { // Z-axis: blue ShapeAppearance.setDiffuseColor(ViewParams::instance()->getAxisZColor()); - pLabel->string.setValue(SbString("Z")); + pLabel->string.setValue("Z"); } else { noRole = true; @@ -114,5 +115,5 @@ void ViewProviderLine::attach(App::DocumentObject *obj) { ps->style.setValue(SoPickStyle::SHAPE_ON_TOP); sep->addChild(ps); - sep->addChild ( getLabel () ); + sep->addChild (pLabel); } diff --git a/src/Gui/ViewProviderLine.h b/src/Gui/ViewProviderLine.h index 7a9c8f5085..614299c304 100644 --- a/src/Gui/ViewProviderLine.h +++ b/src/Gui/ViewProviderLine.h @@ -27,6 +27,8 @@ #include "ViewProviderDatum.h" +class SoText2; + namespace Gui { @@ -38,6 +40,9 @@ public: ~ViewProviderLine() override; void attach ( App::DocumentObject * ) override; + +protected: + CoinPtr pLabel; }; } //namespace Gui diff --git a/src/Gui/ViewProviderPlane.cpp b/src/Gui/ViewProviderPlane.cpp index a0ea2c40bb..b11c95c68b 100644 --- a/src/Gui/ViewProviderPlane.cpp +++ b/src/Gui/ViewProviderPlane.cpp @@ -24,7 +24,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include # include # include # include @@ -34,6 +33,7 @@ # include # include # include +# include # include #endif @@ -53,6 +53,8 @@ ViewProviderPlane::ViewProviderPlane() { sPixmap = "Std_Plane"; lineThickness = 1.0; + + pLabel = new SoAsciiText(); } ViewProviderPlane::~ViewProviderPlane() = default; @@ -60,44 +62,31 @@ ViewProviderPlane::~ViewProviderPlane() = default; void ViewProviderPlane::attach(App::DocumentObject * obj) { ViewProviderDatum::attach(obj); - const char* name = pcObject->getNameInDocument(); + std::string role = getRole(); + + SoSeparator* sep = getDatumRoot(); // Setup colors + // Can't use transparency because of https://github.com/FreeCAD/FreeCAD/issues/18395 + // When this issue is fixed then we can use the below and remove the material here + // and faceSeparator... + //ShapeAppearance.setTransparency(0.8); auto material = new SoMaterial(); - SbColor color; material->transparency.setValue(0.95f); - float alpha = 0.0f; - float lineTransparency = 0.5; - bool noRole = false; - auto planesRoles = App::LocalCoordinateSystem::PlaneRoles; - if (strncmp(name, planesRoles[0], strlen(planesRoles[0])) == 0) { - // XY-axis: blue - ShapeAppearance.setDiffuseColor(ViewParams::instance()->getAxisZColor()); - ShapeAppearance.setTransparency(lineTransparency); - color.setPackedValue(ViewParams::instance()->getAxisZColor(), alpha); - } - else if (strncmp(name, planesRoles[1], strlen(planesRoles[1])) == 0) { - // XZ-axis: green - ShapeAppearance.setDiffuseColor(ViewParams::instance()->getAxisYColor()); - ShapeAppearance.setTransparency(lineTransparency); - color.setPackedValue(ViewParams::instance()->getAxisYColor(), alpha); - } - else if (strncmp(name, planesRoles[2], strlen(planesRoles[2])) == 0) { - // YZ-axis: red - ShapeAppearance.setDiffuseColor(ViewParams::instance()->getAxisXColor()); - ShapeAppearance.setTransparency(lineTransparency); - color.setPackedValue(ViewParams::instance()->getAxisXColor(), alpha); - } - else { - noRole = true; + if (!role.empty()) { + ShapeAppearance.setDiffuseColor(getColor(role)); + SbColor color; + float alpha = 0.0f; + color.setPackedValue(getColor(role), alpha); + material->ambientColor.setValue(color); + material->diffuseColor.setValue(color); } static const float size = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetFloat("DatumPlaneSize", 40.0); static const float startSize = 0.25 * size; //NOLINT - SbVec3f verts[4]; - if (noRole) { + if (role.empty()) { verts[0] = SbVec3f(size, size, 0); verts[1] = SbVec3f(size, -size, 0); verts[2] = SbVec3f(-size, -size, 0); @@ -110,29 +99,27 @@ void ViewProviderPlane::attach(App::DocumentObject * obj) { verts[3] = SbVec3f(startSize, size, 0); } - - // indexes used to create the edges - static const int32_t lines[6] = { 0, 1, 2, 3, 0, -1 }; - - SoSeparator* sep = getDatumRoot(); - auto pCoords = new SoCoordinate3(); pCoords->point.setNum(4); pCoords->point.setValues(0, 4, verts); sep->addChild(pCoords); + auto lineSeparator = new SoSeparator(); auto pLines = new SoIndexedLineSet(); + static const int32_t lines[6] = { 0, 1, 2, 3, 0, -1 }; pLines->coordIndex.setNum(6); pLines->coordIndex.setValues(0, 6, lines); - sep->addChild(pLines); + + auto ps = new SoPickStyle(); + ps->style.setValue(SoPickStyle::SHAPE_ON_TOP); + lineSeparator->addChild(ps); + lineSeparator->addChild(pLines); + sep->addChild(lineSeparator); // add semi transparent face auto faceSeparator = new SoSeparator(); sep->addChild(faceSeparator); - - material->ambientColor.setValue(color); - material->diffuseColor.setValue(color); faceSeparator->addChild(material); // disable backface culling and render with two-sided lighting @@ -141,19 +128,75 @@ void ViewProviderPlane::attach(App::DocumentObject * obj) { shapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; faceSeparator->addChild(shapeHints); - auto pickStyle = new SoPickStyle(); - pickStyle->style = SoPickStyle::SHAPE_ON_TOP; - faceSeparator->addChild(pickStyle); - auto faceSet = new SoFaceSet(); auto vertexProperty = new SoVertexProperty(); vertexProperty->vertex.setValues(0, 4, verts); faceSet->vertexProperty.setValue(vertexProperty); faceSeparator->addChild(faceSet); - auto ps = new SoPickStyle(); - ps->style.setValue(SoPickStyle::BOUNDING_BOX); - sep->addChild(ps); + auto textTranslation = new SoTranslation(); + SbVec3f centeringVec = size * SbVec3f(0.36, 0.49, 0); // NOLINT + textTranslation->translation.setValue(centeringVec); + sep->addChild(textTranslation); - sep->addChild(getLabel()); + pLabel->string.setValue(getLabelText(role).c_str()); + + labelSwitch = new SoSwitch(); + setLabelVisibility(false); + labelSwitch->addChild(pLabel); + sep->addChild(labelSwitch); } + +void ViewProviderPlane::setLabelVisibility(bool val) +{ + labelSwitch->whichChild = val ? SO_SWITCH_ALL : SO_SWITCH_NONE; +} + +unsigned long ViewProviderPlane::getColor(std::string& role) +{ + auto planesRoles = App::LocalCoordinateSystem::PlaneRoles; + if (role == planesRoles[0]) { + return ViewParams::instance()->getAxisZColor(); // XY-plane + } + else if (role == planesRoles[1]) { + return ViewParams::instance()->getAxisYColor(); // XZ-plane + } + else if (role == planesRoles[2]) { + return ViewParams::instance()->getAxisXColor(); // YZ-plane + } + return 0; +} + +std::string ViewProviderPlane::getLabelText(std::string& role) +{ + std::string text; + auto planesRoles = App::LocalCoordinateSystem::PlaneRoles; + if (role == planesRoles[0]) { + text = "XY"; + } + else if (role == planesRoles[1]) { + text = "XZ"; + } + else if (role == planesRoles[2]) { + text = "YZ"; + } + return text; +} + +std::string ViewProviderPlane::getRole() +{ + // Note: Role property of App::Plane is not set yet when attaching. + const char* name = pcObject->getNameInDocument(); + auto planesRoles = App::LocalCoordinateSystem::PlaneRoles; + if (strncmp(name, planesRoles[0], strlen(planesRoles[0])) == 0) { + return planesRoles[0]; + } + else if (strncmp(name, planesRoles[1], strlen(planesRoles[1])) == 0) { + return planesRoles[1]; + } + else if (strncmp(name, planesRoles[2], strlen(planesRoles[2])) == 0) { + return planesRoles[2]; + } + + return ""; +} \ No newline at end of file diff --git a/src/Gui/ViewProviderPlane.h b/src/Gui/ViewProviderPlane.h index f1daecf432..eeb142a9ce 100644 --- a/src/Gui/ViewProviderPlane.h +++ b/src/Gui/ViewProviderPlane.h @@ -27,6 +27,9 @@ #include "ViewProviderDatum.h" +class SoSwitch; +class SoAsciiText; + namespace Gui { @@ -38,7 +41,16 @@ public: ViewProviderPlane(); ~ViewProviderPlane() override; - void attach ( App::DocumentObject * ) override; + void attach (App::DocumentObject*) override; + + unsigned long getColor(std::string& role); + std::string getRole(); + std::string getLabelText(std::string& role); + void setLabelVisibility(bool val); + +private: + CoinPtr labelSwitch; + CoinPtr pLabel; }; } //namespace Gui diff --git a/src/Mod/Part/parttests/ColorTransparencyTest.py b/src/Mod/Part/parttests/ColorTransparencyTest.py index bf2786327a..ec306914d9 100644 --- a/src/Mod/Part/parttests/ColorTransparencyTest.py +++ b/src/Mod/Part/parttests/ColorTransparencyTest.py @@ -64,6 +64,6 @@ class ColorTransparencyTest(unittest.TestCase): obj = self._doc.addObject('App::Origin') t = self._doc.findObjects('App::Plane')[0].ViewObject.Transparency - self.assertEqual(t, 50, - 'transparency of App::Plane object is {} instead of 50'.format(t)) + self.assertEqual(t, 0, + 'transparency of App::Plane object is {} instead of 0'.format(t)) diff --git a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp index 93132894f2..2a039750c7 100644 --- a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp @@ -162,6 +162,8 @@ TaskFeaturePick::TaskFeaturePick(std::vector& objects, if (vpo) { vpo->setTemporaryVisibility(originVisStatus[origin][axisBit], originVisStatus[origin][planeBit]); + vpo->setTemporaryScale(4.0); // NOLINT + vpo->setPlaneLabelVisibility(true); origins.push_back(vpo); } } @@ -177,6 +179,8 @@ TaskFeaturePick::~TaskFeaturePick() { for (Gui::ViewProviderCoordinateSystem* vpo : origins) { vpo->resetTemporaryVisibility(); + vpo->resetTemporarySize(); + vpo->setPlaneLabelVisibility(false); } }