add option to resize datum planes manually

This commit is contained in:
wmayer
2018-07-30 22:31:24 +02:00
parent 07be6e30bf
commit 5380a03266
4 changed files with 58 additions and 2 deletions

View File

@@ -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<long>(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);
}

View File

@@ -25,6 +25,7 @@
#define PARTDESIGN_DATUMPLANE_H
#include <Mod/Part/App/DatumFeature.h>
#include <App/PropertyUnits.h>
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

View File

@@ -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<PartDesign::Plane*>(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<PartDesign::Plane*>(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);
}

View File

@@ -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;