Skip to content

Commit

Permalink
Core datums: Rework to improve new sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddleStroke authored and maxwxyz committed Dec 30, 2024
1 parent 7083362 commit e977eb4
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 77 deletions.
45 changes: 42 additions & 3 deletions src/Gui/ViewProviderCoordinateSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<App::Origin*>( getObject() );

bool saveState = tempVisMap.empty();
Expand Down Expand Up @@ -137,7 +137,7 @@ void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane)
if (saveState) {
tempVisMap[vp] = vp->isVisible();
}
vp->setVisible(plane);
vp->setVisible(points);
}
}

Expand Down Expand Up @@ -170,6 +170,45 @@ bool ViewProviderCoordinateSystem::isTemporaryVisibility() {
return !tempVisMap.empty();
}

void ViewProviderCoordinateSystem::setPlaneLabelVisibility(bool val)
{
auto lcs = getObject<App::LocalCoordinateSystem>();
for (auto* plane : lcs->planes()) {
auto* vp = dynamic_cast<Gui::ViewProviderPlane*>(
Gui::Application::Instance->getViewProvider(plane));
if (vp) {
vp->setLabelVisibility(val);
}
}

}

void ViewProviderCoordinateSystem::setTemporaryScale(double factor)
{
auto lcs = getObject<App::LocalCoordinateSystem>();
auto& objs = lcs->OriginFeatures.getValues();
for (auto* obj : objs) {
auto* vp = dynamic_cast<Gui::ViewProviderDatum*>(
Gui::Application::Instance->getViewProvider(obj));
if (vp) {
vp->setTemporaryScale(factor);
}
}
}

void ViewProviderCoordinateSystem::resetTemporarySize()
{
auto lcs = getObject<App::LocalCoordinateSystem>();
auto& objs = lcs->OriginFeatures.getValues();
for (auto* obj : objs) {
auto* vp = dynamic_cast<Gui::ViewProviderDatum*>(
Gui::Application::Instance->getViewProvider(obj));
if (vp) {
vp->resetTemporarySize();
}
}
}

void ViewProviderCoordinateSystem::updateData(const App::Property* prop) {
auto* jcs = dynamic_cast<App::LocalCoordinateSystem*>(getObject());
if(jcs) {
Expand All @@ -181,7 +220,7 @@ void ViewProviderCoordinateSystem::updateData(const App::Property* prop) {
}

bool ViewProviderCoordinateSystem::onDelete(const std::vector<std::string> &) {
auto lcs = static_cast<App::LocalCoordinateSystem*>(getObject());
auto lcs = getObject<App::LocalCoordinateSystem>();

auto origin = dynamic_cast<App::Origin*>(lcs);
if (origin && !origin->getInList().empty()) {
Expand Down
7 changes: 6 additions & 1 deletion src/Gui/ViewProviderCoordinateSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ class GuiExport ViewProviderCoordinateSystem : public ViewProviderGeoFeatureGrou
*/
///@{
/// 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;
}
Expand Down
27 changes: 14 additions & 13 deletions src/Gui/ViewProviderDatum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "PreCompiled.h"

#ifndef _PreComp_
# include <Inventor/nodes/SoText2.h>
# include <Inventor/nodes/SoAnnotation.h>
# include <Inventor/nodes/SoDrawStyle.h>
# include <Inventor/nodes/SoFont.h>
Expand Down Expand Up @@ -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();
}


Expand Down Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions src/Gui/ViewProviderDatum.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include "ViewProviderGeometryObject.h"

class SoText2;
class SoScale;

namespace Gui
Expand All @@ -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<std::string> getDisplayModes() const override;
void setDisplayMode(const char* ModeName) override;
Expand All @@ -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<std::string>&) override;
protected:
SoSeparator* pRoot;
SoShapeScale* soScale;
SoText2* pLabel;
double lineThickness;
};

Expand Down
11 changes: 6 additions & 5 deletions src/Gui/ViewProviderLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#ifndef _PreComp_
# include <Inventor/nodes/SoText2.h>
# include <Inventor/nodes/SoAsciiText.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoIndexedLineSet.h>
# include <Inventor/nodes/SoPickStyle.h>
Expand All @@ -48,6 +47,8 @@ PROPERTY_SOURCE(Gui::ViewProviderLine, Gui::ViewProviderDatum)
ViewProviderLine::ViewProviderLine()
{
sPixmap = "Std_Axis";

pLabel = new SoText2();
}

ViewProviderLine::~ViewProviderLine() = default;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
5 changes: 5 additions & 0 deletions src/Gui/ViewProviderLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include "ViewProviderDatum.h"

class SoText2;

namespace Gui
{

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

void attach ( App::DocumentObject * ) override;

protected:
CoinPtr<SoText2> pLabel;
};

} //namespace Gui
Expand Down
Loading

0 comments on commit e977eb4

Please sign in to comment.