From 5380a03266b80ad6b9e59d89fb9861a2ffbbf3d9 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 30 Jul 2018 22:31:24 +0200 Subject: [PATCH] add option to resize datum planes manually --- src/Mod/PartDesign/App/DatumPlane.cpp | 27 ++++++++++++++++++- src/Mod/PartDesign/App/DatumPlane.h | 9 +++++++ .../PartDesign/Gui/ViewProviderDatumPlane.cpp | 23 +++++++++++++++- .../PartDesign/Gui/ViewProviderDatumPlane.h | 1 + 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/Mod/PartDesign/App/DatumPlane.cpp b/src/Mod/PartDesign/App/DatumPlane.cpp index 21962440a2..a669b5150b 100644 --- a/src/Mod/PartDesign/App/DatumPlane.cpp +++ b/src/Mod/PartDesign/App/DatumPlane.cpp @@ -36,10 +36,20 @@ using namespace Attacher; // ============================================================================ +const char* Plane::ResizeModeEnums[]= {"Automatic","Manual",NULL}; + PROPERTY_SOURCE(PartDesign::Plane, Part::Datum) Plane::Plane() { + ADD_PROPERTY_TYPE(ResizeMode,(static_cast(0)), "Size", App::Prop_None, "Automatic or manual resizing"); + ResizeMode.setEnums(ResizeModeEnums); + ADD_PROPERTY_TYPE(Length,(20), "Size", App::Prop_None, "Length of the plane"); + ADD_PROPERTY_TYPE(Width,(20), "Size", App::Prop_None, "Width of the plane"); + + Length.setReadOnly(true); + Width.setReadOnly(true); + this->setAttacher(new AttachEnginePlane); // Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of // Sketcher on the PartDesign module @@ -47,7 +57,6 @@ Plane::Plane() if (!builder.IsDone()) return; Shape.setValue(builder.Shape()); - } Plane::~Plane() @@ -61,3 +70,19 @@ Base::Vector3d Plane::getNormal() rot.multVec(Base::Vector3d(0,0,1), normal); return normal; } + +void Plane::onChanged(const App::Property *prop) +{ + if (prop == &ResizeMode) { + if (ResizeMode.getValue() == 0) { + Length.setReadOnly(true); + Width.setReadOnly(true); + } + else { + Length.setReadOnly(false); + Width.setReadOnly(false); + } + } + + Datum::onChanged(prop); +} diff --git a/src/Mod/PartDesign/App/DatumPlane.h b/src/Mod/PartDesign/App/DatumPlane.h index c107d777be..64ea0d509c 100644 --- a/src/Mod/PartDesign/App/DatumPlane.h +++ b/src/Mod/PartDesign/App/DatumPlane.h @@ -25,6 +25,7 @@ #define PARTDESIGN_DATUMPLANE_H #include +#include namespace PartDesign { @@ -37,11 +38,19 @@ public: Plane(); virtual ~Plane(); + App::PropertyEnumeration ResizeMode; + App::PropertyLength Length; + App::PropertyLength Width; + + virtual void onChanged(const App::Property *prop); const char* getViewProviderName(void) const { return "PartDesignGui::ViewProviderDatumPlane"; } Base::Vector3d getNormal(); + +private: + static const char* ResizeModeEnums[]; }; } //namespace PartDesign diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp index d5f84fb4e4..45c8ae4ff6 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp @@ -92,6 +92,12 @@ void ViewProviderDatumPlane::updateData(const App::Property* prop) if (strcmp(prop->getName(),"Placement") == 0) { updateExtents (); } + else if (strcmp(prop->getName(),"Length") == 0 || + strcmp(prop->getName(),"Width") == 0) { + PartDesign::Plane* pcDatum = static_cast(this->getObject()); + if (pcDatum->ResizeMode.getValue() != 0) + setExtents(pcDatum->Length.getValue(), pcDatum->Width.getValue()); + } ViewProviderDatum::updateData(prop); } @@ -99,6 +105,10 @@ void ViewProviderDatumPlane::updateData(const App::Property* prop) void ViewProviderDatumPlane::setExtents (Base::BoundBox3d bbox) { PartDesign::Plane* pcDatum = static_cast(this->getObject()); + if (pcDatum->ResizeMode.getValue() != 0) { + setExtents(pcDatum->Length.getValue(), pcDatum->Width.getValue()); + return; + } Base::Placement plm = pcDatum->Placement.getValue ().inverse (); @@ -109,12 +119,23 @@ void ViewProviderDatumPlane::setExtents (Base::BoundBox3d bbox) { double margin = sqrt(bbox.LengthX ()*bbox.LengthY ()) * marginFactor (); + pcDatum->Length.setValue(bbox.LengthX() + 2*margin); + pcDatum->Width.setValue(bbox.LengthY() + 2*margin); + // Change the coordinates of the line pCoords->point.setNum (4); pCoords->point.set1Value(0, bbox.MaxX + margin, bbox.MaxY + margin, 0 ); pCoords->point.set1Value(1, bbox.MinX - margin, bbox.MaxY + margin, 0 ); pCoords->point.set1Value(2, bbox.MinX - margin, bbox.MinY - margin, 0 ); pCoords->point.set1Value(3, bbox.MaxX + margin, bbox.MinY - margin, 0 ); - } +void ViewProviderDatumPlane::setExtents(double l, double w) +{ + // Change the coordinates of the line + pCoords->point.setNum (4); + pCoords->point.set1Value(0, l, w, 0); + pCoords->point.set1Value(1, 0, w, 0); + pCoords->point.set1Value(2, 0, 0, 0); + pCoords->point.set1Value(3, l, 0, 0); +} diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.h b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.h index bc9d0ecd3d..2b09e975cd 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.h +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.h @@ -42,6 +42,7 @@ public: virtual void updateData(const App::Property*); void setExtents (Base::BoundBox3d bbox); + void setExtents(double l, double w); private: SoCoordinate3 *pCoords;