diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 025926a4f..f4a1d4093 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -157,6 +157,7 @@ void PartExport initPart() Part::Polygon ::init(); Part::Circle ::init(); Part::Vertex ::init(); + Part::Edge ::init(); Part::Ellipsoid ::init(); Part::Plane ::init(); Part::Sphere ::init(); diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp index 26b368dc4..2d1bd471f 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -162,6 +162,70 @@ void Vertex::onChanged(const App::Property* prop) Part::Feature::onChanged(prop); } +PROPERTY_SOURCE(Part::Edge, Part::Primitive) + +Edge::Edge() +{ + ADD_PROPERTY_TYPE(X1,(0.0f),"Vertex 1 - Start",App::Prop_None,"X value of the start vertex"); + ADD_PROPERTY_TYPE(Y1,(0.0f),"Vertex 1 - Start",App::Prop_None,"Y value of the Start vertex"); + ADD_PROPERTY_TYPE(Z1,(0.0f),"Vertex 1 - Start",App::Prop_None,"Z value of the Start vertex"); + ADD_PROPERTY_TYPE(X2,(0.0f),"Vertex 2 - Finish",App::Prop_None,"X value of the finish vertex"); + ADD_PROPERTY_TYPE(Y2,(0.0f),"Vertex 2 - Finish",App::Prop_None,"Y value of the finish vertex"); + ADD_PROPERTY_TYPE(Z2,(1.0f),"Vertex 2 - Finish",App::Prop_None,"Z value of the finish vertex"); +} + +Edge::~Edge() +{ +} + +short Edge::mustExecute() const +{ + if (X1.isTouched() || + Y1.isTouched() || + Z1.isTouched() || + X2.isTouched() || + Y2.isTouched() || + Z2.isTouched()) + return 1; + return Part::Feature::mustExecute(); +} + +App::DocumentObjectExecReturn *Edge::execute(void) +{ + gp_Pnt point1; + point1.SetX(this->X1.getValue()); + point1.SetY(this->Y1.getValue()); + point1.SetZ(this->Z1.getValue()); + + gp_Pnt point2; + point2.SetX(this->X2.getValue()); + point2.SetY(this->Y2.getValue()); + point2.SetZ(this->Z2.getValue()); + + BRepBuilderAPI_MakeEdge mkEdge(point1, point2); + if (!mkEdge.IsDone()) + return new App::DocumentObjectExecReturn("Failed to create edge"); + const TopoDS_Edge& edge = mkEdge.Edge(); + this->Shape.setValue(edge); + + return App::DocumentObject::StdReturn; +} + +void Edge::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + if (prop == &X1 || prop == &Y1 || prop == &Z1 || prop == &X2 || prop == &Y2 || prop == &Z2){ + try { + App::DocumentObjectExecReturn *ret = recompute(); + delete ret; + } + catch (...) { + } + } + } + Part::Feature::onChanged(prop); +} + PROPERTY_SOURCE(Part::Plane, Part::Primitive) Plane::Plane() diff --git a/src/Mod/Part/App/PrimitiveFeature.h b/src/Mod/Part/App/PrimitiveFeature.h index 7d70f1052..7100b2ecd 100644 --- a/src/Mod/Part/App/PrimitiveFeature.h +++ b/src/Mod/Part/App/PrimitiveFeature.h @@ -69,6 +69,30 @@ public: void onChanged(const App::Property*); //@} }; + +class PartExport Edge : public Part::Primitive +{ + PROPERTY_HEADER(Part::Edge); + +public: + Edge(); + virtual ~Edge(); + + App::PropertyFloat X1; + App::PropertyFloat Y1; + App::PropertyFloat Z1; + App::PropertyFloat X2; + App::PropertyFloat Y2; + App::PropertyFloat Z2; + + /** @name methods override feature */ + //@{ + /// recalculate the Feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + void onChanged(const App::Property*); + //@} +}; class PartExport Plane : public Primitive { diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index 4be9e537c..0092cf756 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -108,12 +108,25 @@ DlgPrimitives::DlgPrimitives(QWidget* parent, Qt::WFlags fl) // circle ui.circleRadius->setMaximum(INT_MAX); // vertex - ui.VertexXAxisValue->setMaximum(INT_MAX); - ui.VertexYAxisValue->setMaximum(INT_MAX); - ui.VertexZAxisValue->setMaximum(INT_MAX); - ui.VertexXAxisValue->setMinimum(-INT_MAX); - ui.VertexYAxisValue->setMinimum(-INT_MAX); - ui.VertexZAxisValue->setMinimum(-INT_MAX); + ui.vertexX->setMaximum(INT_MAX); + ui.vertexY->setMaximum(INT_MAX); + ui.vertexZ->setMaximum(INT_MAX); + ui.vertexX->setMinimum(INT_MIN); + ui.vertexY->setMinimum(INT_MIN); + ui.vertexZ->setMinimum(INT_MIN); + // edge + ui.edgeX1->setMaximum(INT_MAX); + ui.edgeX1->setMinimum(INT_MIN); + ui.edgeY1->setMaximum(INT_MAX); + ui.edgeY1->setMinimum(INT_MIN); + ui.edgeZ1->setMaximum(INT_MAX); + ui.edgeZ1->setMinimum(INT_MIN); + ui.edgeX2->setMaximum(INT_MAX); + ui.edgeX2->setMinimum(INT_MIN); + ui.edgeY2->setMaximum(INT_MAX); + ui.edgeY2->setMinimum(INT_MIN); + ui.edgeZ2->setMaximum(INT_MAX); + ui.edgeZ2->setMinimum(INT_MIN); } /* @@ -440,9 +453,29 @@ void DlgPrimitives::accept() "App.ActiveDocument.%1.Z=%4\n" "App.ActiveDocument.%1.Placement=%5\n") .arg(name) - .arg(ui.VertexXAxisValue->value(),0,'f',2) - .arg(ui.VertexYAxisValue->value(),0,'f',2) - .arg(ui.VertexZAxisValue->value(),0,'f',2) + .arg(ui.vertexX->value(),0,'f',2) + .arg(ui.vertexY->value(),0,'f',2) + .arg(ui.vertexZ->value(),0,'f',2) + .arg(this->toPlacement()); + } + else if (ui.comboBox1->currentIndex() == 11) { // edge + name = QString::fromAscii(doc->getUniqueObjectName("Edge").c_str()); + cmd = QString::fromAscii( + "App.ActiveDocument.addObject(\"Part::Edge\",\"%1\")\n" + "App.ActiveDocument.%1.X1=%2\n" + "App.ActiveDocument.%1.Y1=%3\n" + "App.ActiveDocument.%1.Z1=%4\n" + "App.ActiveDocument.%1.X2=%5\n" + "App.ActiveDocument.%1.Y2=%6\n" + "App.ActiveDocument.%1.Z2=%7\n" + "App.ActiveDocument.%1.Placement=%8\n") + .arg(name) + .arg(ui.edgeX1->value(),0,'f',2) + .arg(ui.edgeY1->value(),0,'f',2) + .arg(ui.edgeZ1->value(),0,'f',2) + .arg(ui.edgeX2->value(),0,'f',2) + .arg(ui.edgeY2->value(),0,'f',2) + .arg(ui.edgeZ2->value(),0,'f',2) .arg(this->toPlacement()); } diff --git a/src/Mod/Part/Gui/DlgPrimitives.ui b/src/Mod/Part/Gui/DlgPrimitives.ui index 1a92f2582..afbcc9441 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.ui +++ b/src/Mod/Part/Gui/DlgPrimitives.ui @@ -1171,7 +1171,7 @@ 0.000000000000000 - 89.99 + 89.989999999999995 1.000000000000000 @@ -1281,47 +1281,184 @@ - + - + - + - X Axis Value: + X Value: - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - Y Axis Value: + Y Value: - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - Z Axis Value: + Z Value: - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + X + + + Qt::AlignCenter + + + + + + + Y + + + Qt::AlignCenter + + + + + + + Z + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + + + + + Finish Vertex + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Start Vertex + + + + + + + X + + + Qt::AlignCenter + + + + + + + Y + + + Qt::AlignCenter + + + + + + + Z + + + Qt::AlignCenter + + + + + + + 0.000000000000000 + + + + + + + 0.000000000000000 + + + + + + + + + + 0.000000000000000 + + + + + + + 1.000000000000000 + + + + + + + 1.000000000000000 + + + + + + + 1.000000000000000 + + + + + + + @@ -1342,6 +1479,15 @@ + + + 0 + 0 + + + + 14 + Plane @@ -1397,6 +1543,11 @@ Vertex + + + Edge + +