Simplified datum features by making use of the placement property

This commit is contained in:
jrheinlaender 2013-05-09 11:26:32 +04:30 committed by Stefan Tröger
parent 2c378a4f8c
commit 0e8921c21f
11 changed files with 121 additions and 111 deletions

View File

@ -317,7 +317,6 @@ App::DocumentObjectExecReturn *Body::execute(void)
return App::DocumentObject::StdReturn;
Shape.setValue(TipShape);
return App::DocumentObject::StdReturn;
}
@ -338,13 +337,13 @@ Base::BoundBox3d Body::getBoundBox()
for (std::vector<App::DocumentObject*>::const_iterator m = model.begin(); m != model.end(); m++) {
if ((*m)->getTypeId().isDerivedFrom(PartDesign::Point::getClassTypeId())) {
PartDesign::Point* point = static_cast<PartDesign::Point*>(*m);
result.Add(point->_Point.getValue());
result.Add(point->getPoint());
} else if ((*m)->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) {
PartDesign::Line* line = static_cast<PartDesign::Line*>(*m);
result.Add(line->_Base.getValue());
result.Add(line->getBasePoint());
} else if ((*m)->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
PartDesign::Plane* plane = static_cast<PartDesign::Plane*>(*m);
result.Add(plane->_Base.getValue());
result.Add(plane->getBasePoint());
} else if ((*m)->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
// Note: We only take into account the base planes here
result.Add(Base::Vector3d(0,0,0));

View File

@ -116,12 +116,14 @@ PROPERTY_SOURCE(PartDesign::Line, Part::Datum)
Line::Line()
{
ADD_PROPERTY_TYPE(_Base,(Base::Vector3d(0,0,0)),"DatumLine",
App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
"Coordinates of the line base point");
ADD_PROPERTY_TYPE(_Direction,(Base::Vector3d(1,1,1)),"DatumLine",
App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
"Coordinates of the line direction");
// Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of
// Sketcher on the PartDesign module
BRepBuilderAPI_MakeEdge builder(gp_Lin(gp_Pnt(0,0,0), gp_Dir(0,0,1)));
if (!builder.IsDone())
return;
Shape.setValue(builder.Shape());
References.touch();
}
Line::~Line()
@ -155,17 +157,17 @@ void Line::onChanged(const App::Property *prop)
if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Point::getClassTypeId())) {
PartDesign::Point* p = static_cast<PartDesign::Point*>(refs[i]);
if (p1 == NULL)
p1 = new Base::Vector3d (p->_Point.getValue());
p1 = new Base::Vector3d (p->getPoint());
else
p2 = new Base::Vector3d (p->_Point.getValue());
p2 = new Base::Vector3d (p->getPoint());
} else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) {
PartDesign::Line* l = static_cast<PartDesign::Line*>(refs[i]);
base = new Base::Vector3d (l->_Base.getValue());
direction = new Base::Vector3d (l->_Direction.getValue());
base = new Base::Vector3d (l->getBasePoint());
direction = new Base::Vector3d (l->getDirection());
} else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
PartDesign::Plane* p = static_cast<PartDesign::Plane*>(refs[i]);
Base::Vector3d base = p->_Base.getValue();
Base::Vector3d normal = p->_Normal.getValue();
Base::Vector3d base = p->getBasePoint();
Base::Vector3d normal = p->getNormal();
if (s1.IsNull())
s1 = new Geom_Plane(gp_Pnt(base.x, base.y, base.z), gp_Dir(normal.x, normal.y, normal.z));
else
@ -247,16 +249,7 @@ void Line::onChanged(const App::Property *prop)
return;
}
_Base.setValue(*base);
_Direction.setValue(*direction);
_Base.touch(); // This triggers ViewProvider::updateData()
// Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of
// Sketcher on the PartDesign module
BRepBuilderAPI_MakeEdge builder(gp_Lin(gp_Pnt(base->x, base->y, base->z), gp_Dir(direction->x, direction->y, direction->z)));
if (!builder.IsDone())
return;
Shape.setValue(builder.Shape());
Placement.setValue(Base::Placement(*base, Base::Rotation(Base::Vector3d(0,0,1), *direction)));
delete base;
delete direction;
@ -268,7 +261,6 @@ void Line::onChanged(const App::Property *prop)
Part::Datum::onChanged(prop);
}
const std::set<QString> Line::getHint()
{
if (hints.find(refTypes) != hints.end())
@ -276,3 +268,16 @@ const std::set<QString> Line::getHint()
else
return std::set<QString>();
}
Base::Vector3d Line::getBasePoint()
{
return Placement.getValue().getPosition();
}
Base::Vector3d Line::getDirection()
{
Base::Rotation rot = Placement.getValue().getRotation();
Base::Vector3d dir;
rot.multVec(Base::Vector3d(0,0,1), dir);
return dir;
}

View File

@ -37,9 +37,6 @@ class PartDesignExport Line : public Part::Datum
PROPERTY_HEADER(PartDesign::Line);
public:
App::PropertyVector _Base;
App::PropertyVector _Direction;
Line();
virtual ~Line();
@ -50,6 +47,9 @@ public:
static void initHints();
const std::set<QString> getHint();
Base::Vector3d getBasePoint();
Base::Vector3d getDirection();
protected:
virtual void onChanged(const App::Property* prop);

View File

@ -131,7 +131,6 @@ void Plane::initHints()
key.insert(LINE); key.insert(PLANE); key.insert(ANGLE);
hints[key] = DONE; // {LINE, PLANE, ANGLE} -> DONE. Plane through line with angle to other plane
key.clear(); value.clear();
value.insert(POINT); value.insert(LINE); value.insert(PLANE); value.insert(ANGLE);
hints[key] = value;
@ -143,12 +142,18 @@ PROPERTY_SOURCE(PartDesign::Plane, Part::Datum)
Plane::Plane()
{
ADD_PROPERTY_TYPE(_Base,(Base::Vector3d(0,0,0)),"DatumPlane",
App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
"Coordinates of the plane base point");
ADD_PROPERTY_TYPE(_Normal,(Base::Vector3d(1,1,1)),"DatumPlane",
App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
"Coordinates of the plane normal");
// Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of
// Sketcher on the PartDesign module
BRepBuilderAPI_MakeFace builder(gp_Pln(gp_Pnt(0,0,0), gp_Dir(0,0,1)));
if (!builder.IsDone())
return;
Shape.setValue(builder.Shape());
References.touch();
}
Plane::~Plane()
{
}
void Plane::onChanged(const App::Property *prop)
@ -187,20 +192,20 @@ void Plane::onChanged(const App::Property *prop)
if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Point::getClassTypeId())) {
PartDesign::Point* p = static_cast<PartDesign::Point*>(refs[i]);
if (p1 == NULL)
p1 = new Base::Vector3d (p->_Point.getValue());
p1 = new Base::Vector3d (p->getPoint());
else if (p2 == NULL)
p2 = new Base::Vector3d (p->_Point.getValue());
p2 = new Base::Vector3d (p->getPoint());
else
p3 = new Base::Vector3d (p->_Point.getValue());
p3 = new Base::Vector3d (p->getPoint());
} else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) {
PartDesign::Line* l = static_cast<PartDesign::Line*>(refs[i]);
Base::Vector3d base = l->_Base.getValue();
Base::Vector3d dir = l->_Direction.getValue();
Base::Vector3d base = l->getBasePoint();
Base::Vector3d dir = l->getDirection();
line = new gp_Lin(gp_Pnt(base.x, base.y, base.z), gp_Dir(dir.x, dir.y, dir.z));
} else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
PartDesign::Plane* p = static_cast<PartDesign::Plane*>(refs[i]);
p1 = new Base::Vector3d(p->_Base.getValue());
normal = new Base::Vector3d(p->_Normal.getValue());
p1 = new Base::Vector3d(p->getBasePoint());
normal = new Base::Vector3d(p->getNormal());
} else if (refs[i]->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
App::Plane* p = static_cast<App::Plane*>(refs[i]);
// Note: We only handle the three base planes here
@ -284,16 +289,7 @@ void Plane::onChanged(const App::Property *prop)
if (fabs(Offset.getValue()) > Precision::Confusion())
*p1 += Offset.getValue() * *normal;
_Base.setValue(*p1);
_Normal.setValue(*normal);
_Base.touch(); // This triggers ViewProvider::updateData()
// Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of
// Sketcher on the PartDesign module
BRepBuilderAPI_MakeFace builder(gp_Pln(gp_Pnt(p1->x, p1->y, p1->z), gp_Dir(normal->x, normal->y, normal->z)));
if (!builder.IsDone())
return;
Shape.setValue(builder.Shape());
Placement.setValue(Base::Placement(*p1,Base::Rotation(Base::Vector3d(0,0,1), *normal)));
delete p1;
delete normal;
@ -313,3 +309,16 @@ const std::set<QString> Plane::getHint()
else
return std::set<QString>();
}
Base::Vector3d Plane::getBasePoint()
{
return Placement.getValue().getPosition();
}
Base::Vector3d Plane::getNormal()
{
Base::Rotation rot = Placement.getValue().getRotation();
Base::Vector3d normal;
rot.multVec(Base::Vector3d(0,0,1), normal);
return normal;
}

View File

@ -36,10 +36,8 @@ class PartDesignExport Plane : public Part::Datum
PROPERTY_HEADER(PartDesign::Plane);
public:
App::PropertyVector _Base;
App::PropertyVector _Normal;
Plane();
virtual ~Plane();
const char* getViewProviderName(void) const {
return "PartDesignGui::ViewProviderDatumPlane";
@ -48,6 +46,9 @@ public:
static void initHints();
const std::set<QString> getHint();
Base::Vector3d getBasePoint();
Base::Vector3d getNormal();
protected:
virtual void onChanged(const App::Property* prop);

View File

@ -129,9 +129,14 @@ PROPERTY_SOURCE(PartDesign::Point, Part::Datum)
Point::Point()
{
ADD_PROPERTY_TYPE(_Point,(Base::Vector3d(0,0,0)),"DatumPoint",
App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
"Coordinates of the datum point");
// Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of
// Sketcher on the PartDesign module
BRepBuilderAPI_MakeVertex builder(gp_Pnt(0,0,0));
if (!builder.IsDone())
return;
Shape.setValue(builder.Shape());
References.touch();
}
Point::~Point()
@ -163,19 +168,19 @@ void Point::onChanged(const App::Property* prop)
for (int i = 0; i < refs.size(); i++) {
if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Point::getClassTypeId())) {
PartDesign::Point* p = static_cast<PartDesign::Point*>(refs[i]);
point = new Base::Vector3d (p->_Point.getValue());
point = new Base::Vector3d (p->getPoint());
} else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) {
PartDesign::Line* l = static_cast<PartDesign::Line*>(refs[i]);
Base::Vector3d base = l->_Base.getValue();
Base::Vector3d dir = l->_Direction.getValue();
Base::Vector3d base = l->getBasePoint();
Base::Vector3d dir = l->getDirection();
if (c1.IsNull())
c1 = new Geom_Line(gp_Pnt(base.x, base.y, base.z), gp_Dir(dir.x, dir.y, dir.z));
else
c2 = new Geom_Line(gp_Pnt(base.x, base.y, base.z), gp_Dir(dir.x, dir.y, dir.z));
} else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
PartDesign::Plane* p = static_cast<PartDesign::Plane*>(refs[i]);
Base::Vector3d base = p->_Base.getValue();
Base::Vector3d normal = p->_Normal.getValue();
Base::Vector3d base = p->getBasePoint();
Base::Vector3d normal = p->getNormal();
if (s1.IsNull())
s1 = new Geom_Plane(gp_Pnt(base.x, base.y, base.z), gp_Dir(normal.x, normal.y, normal.z));
else if (s2.IsNull())
@ -278,15 +283,7 @@ void Point::onChanged(const App::Property* prop)
return;
}
_Point.setValue(*point);
_Point.touch(); // This triggers ViewProvider::updateData()
// Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of
// Sketcher on the PartDesign module
BRepBuilderAPI_MakeVertex builder(gp_Pnt(point->x, point->y, point->z));
if (!builder.IsDone())
return;
Shape.setValue(builder.Shape());
Placement.setValue(Base::Placement(*point, Base::Rotation()));
delete point;
}
@ -294,6 +291,11 @@ void Point::onChanged(const App::Property* prop)
Part::Datum::onChanged(prop);
}
Base::Vector3d Point::getPoint()
{
return Placement.getValue().getPosition();
}
const std::set<QString> Point::getHint()
{

View File

@ -37,8 +37,6 @@ class PartDesignExport Point : public Part::Datum
PROPERTY_HEADER(PartDesign::Point);
public:
App::PropertyVector _Point;
Point();
virtual ~Point();
@ -49,7 +47,7 @@ public:
static void initHints();
const std::set<QString> getHint();
Base::Vector3d getPoint();
protected:
virtual void onChanged(const App::Property* prop);

View File

@ -185,16 +185,16 @@ void ViewProviderBody::updateData(const App::Property* prop)
PartDesign::Body* body = static_cast<PartDesign::Body*>(getObject());
std::vector<App::DocumentObject*> features = body->Model.getValues();
for (std::vector<App::DocumentObject*>::const_iterator f = features.begin(); f != features.end(); f++) {
App::PropertyVector* baseProp = NULL;
App::PropertyPlacement* plm = NULL;
if ((*f)->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId()))
baseProp = &(static_cast<PartDesign::Line*>(*f)->_Base);
plm = &(static_cast<PartDesign::Line*>(*f)->Placement);
else if ((*f)->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId()))
baseProp = &(static_cast<PartDesign::Plane*>(*f)->_Base);
plm = &(static_cast<PartDesign::Plane*>(*f)->Placement);
if (baseProp != NULL) {
if (plm != NULL) {
Gui::ViewProviderDocumentObject* vp = dynamic_cast<Gui::ViewProviderDocumentObject*>(Gui::Application::Instance->getViewProvider(*f));
if (vp != NULL)
vp->updateData(baseProp);
vp->updateData(plm);
}
}

View File

@ -77,15 +77,18 @@ void ViewProviderDatumLine::updateData(const App::Property* prop)
// Gets called whenever a property of the attached object changes
PartDesign::Line* pcDatum = static_cast<PartDesign::Line*>(this->getObject());
if (strcmp(prop->getName(),"_Base") == 0) {
Base::Vector3d base = pcDatum->_Base.getValue();
Base::Vector3d dir = pcDatum->_Direction.getValue();
if (strcmp(prop->getName(),"Placement") == 0) {
Base::Placement plm = pcDatum->Placement.getValue();
plm.invert();
Base::Vector3d base(0,0,0);
Base::Vector3d dir(0,0,1);
// Get limits of the line from bounding box of the body
PartDesign::Body* body = static_cast<PartDesign::Body*>(Part::BodyBase::findBodyOf(this->getObject()));
if (body == NULL)
return;
Base::BoundBox3d bbox = body->getBoundBox();
bbox = bbox.Transformed(plm.toMatrix());
bbox.Enlarge(0.1 * bbox.CalcDiagonalLength());
Base::Vector3d p1, p2;
if (bbox.IsInBox(base)) {

View File

@ -77,15 +77,18 @@ void ViewProviderDatumPlane::updateData(const App::Property* prop)
// Gets called whenever a property of the attached object changes
PartDesign::Plane* pcDatum = static_cast<PartDesign::Plane*>(this->getObject());
if (strcmp(prop->getName(),"_Base") == 0) {
Base::Vector3d base = pcDatum->_Base.getValue();
Base::Vector3d normal = pcDatum->_Normal.getValue();
if (strcmp(prop->getName(),"Placement") == 0) {
Base::Placement plm = pcDatum->Placement.getValue();
plm.invert();
Base::Vector3d base(0,0,0);
Base::Vector3d normal(0,0,1);
// Get limits of the plane from bounding box of the body
PartDesign::Body* body = static_cast<PartDesign::Body*>(Part::BodyBase::findBodyOf(this->getObject()));
if (body == NULL)
return;
Base::BoundBox3d bbox = body->getBoundBox();
bbox = bbox.Transformed(plm.toMatrix());
double dlength = bbox.CalcDiagonalLength();
bbox.Enlarge(0.1 * dlength);

View File

@ -62,39 +62,29 @@ PROPERTY_SOURCE(PartDesignGui::ViewProviderDatumPoint,PartDesignGui::ViewProvide
ViewProviderDatumPoint::ViewProviderDatumPoint()
{
SoMarkerSet* points = new SoMarkerSet();
points->markerIndex = SoMarkerSet::DIAMOND_FILLED_9_9;
points->numPoints = 0;
points->markerIndex = SoMarkerSet::DIAMOND_FILLED_9_9;
SoMFVec3f v;
v.setNum(1);
v.set1Value(0, 0,0,0);
SoVertexProperty* vprop = new SoVertexProperty();
vprop->vertex = v;
points->vertexProperty = vprop;
points->numPoints = 1;
pShapeSep->addChild(points);
}
ViewProviderDatumPoint::~ViewProviderDatumPoint()
{
}
void ViewProviderDatumPoint::updateData(const App::Property* prop)
{
// Gets called whenever a property of the attached object changes
PartDesign::Point* pcDatum = static_cast<PartDesign::Point*>(this->getObject());
if (strcmp(prop->getName(),"_Point") == 0) {
Base::Vector3d p = pcDatum->_Point.getValue();
SoMFVec3f v;
v.setNum(1);
v.set1Value(0, p.x, p.y, p.z);
if (strcmp(prop->getName(),"Placement") == 0) {
// The only reason to do this is to display the point in the correct position after loading the document
SoMarkerSet* points = static_cast<SoMarkerSet*>(pShapeSep->getChild(0));
SoVertexProperty* vprop;
if (points->vertexProperty.getValue() == NULL) {
vprop = new SoVertexProperty();
vprop->vertex = v;
points->vertexProperty = vprop;
} else {
vprop = static_cast<SoVertexProperty*>(points->vertexProperty.getValue());
vprop->vertex = v;
}
points->numPoints = 1;
points->touch();
//points->numPoints = 0;
//points->numPoints = 1;
}
ViewProviderDatum::updateData(prop);