setting Datum Line size manually

This commit is contained in:
Zolko
2020-04-14 10:14:26 +02:00
committed by wwmayer
parent 17c79f19e2
commit fc4e83ad63
4 changed files with 54 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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