From fc4e83ad63082777d042146683ed22e2df60000b Mon Sep 17 00:00:00 2001 From: Zolko Date: Tue, 14 Apr 2020 10:14:26 +0200 Subject: [PATCH] setting Datum Line size manually --- src/Mod/PartDesign/App/DatumLine.cpp | 26 +++++++++++++++++++ src/Mod/PartDesign/App/DatumLine.h | 8 ++++++ .../PartDesign/Gui/ViewProviderDatumLine.cpp | 19 +++++++++++++- .../PartDesign/Gui/ViewProviderDatumLine.h | 3 ++- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/Mod/PartDesign/App/DatumLine.cpp b/src/Mod/PartDesign/App/DatumLine.cpp index e446f0b656..bd63bf1c96 100644 --- a/src/Mod/PartDesign/App/DatumLine.cpp +++ b/src/Mod/PartDesign/App/DatumLine.cpp @@ -35,10 +35,23 @@ using namespace PartDesign; using namespace Attacher; +// ============================================================================ + +const char* Line::ResizeModeEnums[]= {"Automatic","Manual",NULL}; + PROPERTY_SOURCE(PartDesign::Line, Part::Datum) Line::Line() { + // These properties are only relevant for the visual appearance. + // Since they are getting changed from within its view provider + // their type is set to "Output" to avoid that they are marked as + // touched all the time. + ADD_PROPERTY_TYPE(ResizeMode,(static_cast(0)), "Size", App::Prop_Output, "Automatic or manual resizing"); + ResizeMode.setEnums(ResizeModeEnums); + ADD_PROPERTY_TYPE(Length,(20), "Size", App::Prop_Output, "Length of the line"); + Length.setReadOnly(true); + this->setAttacher(new AttachEngineLine); // Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of // Sketcher on the PartDesign module @@ -63,3 +76,16 @@ Base::Vector3d Line::getDirection() const rot.multVec(Base::Vector3d(0,0,1), dir); return dir; } + +void Line::onChanged(const App::Property *prop) +{ + if (prop == &ResizeMode) { + if (ResizeMode.getValue() == 0) { + Length.setReadOnly(true); + } + else { + Length.setReadOnly(false); + } + } + Datum::onChanged(prop); +} diff --git a/src/Mod/PartDesign/App/DatumLine.h b/src/Mod/PartDesign/App/DatumLine.h index 1351ef5dfc..d7f1c044b0 100644 --- a/src/Mod/PartDesign/App/DatumLine.h +++ b/src/Mod/PartDesign/App/DatumLine.h @@ -26,6 +26,7 @@ #define PARTDESIGN_DATUMLINE_H #include +#include namespace PartDesign { @@ -38,11 +39,18 @@ public: Line(); virtual ~Line(); + App::PropertyEnumeration ResizeMode; + App::PropertyLength Length; + virtual void onChanged(const App::Property *prop); + const char* getViewProviderName(void) const { return "PartDesignGui::ViewProviderDatumLine"; } Base::Vector3d getDirection() const; + +private: + static const char* ResizeModeEnums[]; }; } //namespace PartDesign diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp index 1c608f3ced..2129b01e2c 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp @@ -71,6 +71,11 @@ void ViewProviderDatumLine::updateData(const App::Property* prop) if (strcmp(prop->getName(),"Placement") == 0) { updateExtents (); } + else if (strcmp(prop->getName(),"Length") == 0) { + PartDesign::Line* pcDatum = static_cast(this->getObject()); + if (pcDatum->ResizeMode.getValue() != 0) + setExtents(pcDatum->Length.getValue()); + } ViewProviderDatum::updateData(prop); } @@ -78,7 +83,11 @@ void ViewProviderDatumLine::updateData(const App::Property* prop) void ViewProviderDatumLine::setExtents (Base::BoundBox3d bbox) { PartDesign::Line* pcDatum = static_cast(this->getObject()); - + // set manual size + if (pcDatum->ResizeMode.getValue() != 0) { + setExtents(pcDatum->Length.getValue()); + return; + } Base::Placement plm = pcDatum->Placement.getValue ().inverse (); // Transform the box to the line's coordinates, the result line will be larger than the bbox @@ -93,3 +102,11 @@ void ViewProviderDatumLine::setExtents (Base::BoundBox3d bbox) { pCoords->point.set1Value(0, 0, 0, bbox.MaxZ + margin ); pCoords->point.set1Value(1, 0, 0, bbox.MinZ - margin ); } + +void ViewProviderDatumLine::setExtents(double l) +{ + // Change the coordinates of the line + pCoords->point.setNum (2); + pCoords->point.set1Value(0, 0, 0, l/2 ); + pCoords->point.set1Value(1, 0, 0, -l/2 ); +} diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.h b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.h index 204e47d07b..fde0c63ae0 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.h +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.h @@ -43,7 +43,8 @@ public: virtual void attach ( App::DocumentObject *obj ); virtual void updateData(const App::Property*); - virtual void setExtents (Base::BoundBox3d bbox); + void setExtents (Base::BoundBox3d bbox); + void setExtents(double l); private: SoCoordinate3 *pCoords;