From 24a3c2cdd9e99a02cfd9bd673c2b03edd61a44ee Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 21 Sep 2013 14:20:04 +0200 Subject: [PATCH] 0001239: Part --> Geometric Primitives --> Regular Prism --- src/Mod/Part/App/AppPart.cpp | 1 + src/Mod/Part/App/PrimitiveFeature.cpp | 60 ++++++++++++++++ src/Mod/Part/App/PrimitiveFeature.h | 25 +++++++ src/Mod/Part/Gui/AppPartGui.cpp | 2 + src/Mod/Part/Gui/CMakeLists.txt | 2 + src/Mod/Part/Gui/DlgPrimitives.cpp | 26 +++++-- src/Mod/Part/Gui/DlgPrimitives.ui | 95 ++++++++++++++++++++++++++ src/Mod/Part/Gui/ViewProviderPrism.cpp | 68 ++++++++++++++++++ src/Mod/Part/Gui/ViewProviderPrism.h | 53 ++++++++++++++ 9 files changed, 326 insertions(+), 6 deletions(-) create mode 100644 src/Mod/Part/Gui/ViewProviderPrism.cpp create mode 100644 src/Mod/Part/Gui/ViewProviderPrism.h diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index cd3bb4149..689903ebc 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -191,6 +191,7 @@ void PartExport initPart() Part::Plane ::init(); Part::Sphere ::init(); Part::Cylinder ::init(); + Part::Prism ::init(); Part::Cone ::init(); Part::Torus ::init(); Part::Helix ::init(); diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp index c2e818a52..bf7934c69 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -27,6 +27,7 @@ # include # include # include +# include # include # include # include @@ -36,6 +37,7 @@ # include # include # include +# include # include # include # include @@ -462,6 +464,64 @@ App::DocumentObjectExecReturn *Cylinder::execute(void) return App::DocumentObject::StdReturn; } +App::PropertyIntegerConstraint::Constraints Prism::polygonRange = {3,INT_MAX,1}; + +PROPERTY_SOURCE(Part::Prism, Part::Primitive) + +Prism::Prism(void) +{ + ADD_PROPERTY_TYPE(Polygon,(6.0),"Prism",App::Prop_None,"The polygon of the prism"); + ADD_PROPERTY_TYPE(Length,(2.0),"Prism",App::Prop_None,"The edge length of the prism"); + ADD_PROPERTY_TYPE(Height,(10.0f),"Prism",App::Prop_None,"The height of the prism"); + Polygon.setConstraints(&polygonRange); +} + +short Prism::mustExecute() const +{ + if (Polygon.isTouched()) + return 1; + if (Length.isTouched()) + return 1; + if (Height.isTouched()) + return 1; + return Primitive::mustExecute(); +} + +App::DocumentObjectExecReturn *Prism::execute(void) +{ + // Build a prism + if (Polygon.getValue() < 3) + return new App::DocumentObjectExecReturn("Polygon of prism is invalid"); + if (Length.getValue() < Precision::Confusion()) + return new App::DocumentObjectExecReturn("Radius of prism too small"); + if (Height.getValue() < Precision::Confusion()) + return new App::DocumentObjectExecReturn("Height of prism too small"); + try { + long nodes = Polygon.getValue(); + + Base::Matrix4D mat; + mat.rotZ(Base::toRadians(360.0/nodes)); + + // create polygon + BRepBuilderAPI_MakePolygon mkPoly; + Base::Vector3d v(Length.getValue(),0,0); + for (long i=0; iShape.setValue(mkPrism.Shape()); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + return new App::DocumentObjectExecReturn(e->GetMessageString()); + } + + return App::DocumentObject::StdReturn; +} + PROPERTY_SOURCE(Part::Cone, Part::Primitive) Cone::Cone(void) diff --git a/src/Mod/Part/App/PrimitiveFeature.h b/src/Mod/Part/App/PrimitiveFeature.h index 1f3589ed7..f2c94121c 100644 --- a/src/Mod/Part/App/PrimitiveFeature.h +++ b/src/Mod/Part/App/PrimitiveFeature.h @@ -195,6 +195,31 @@ public: //@} }; +class PartExport Prism : public Primitive +{ + PROPERTY_HEADER(Part::Prism); + +public: + Prism(); + + App::PropertyIntegerConstraint Polygon; + App::PropertyLength Length; + App::PropertyLength Height; + + /** @name methods override feature */ + //@{ + /// recalculate the feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + /// returns the type name of the ViewProvider + const char* getViewProviderName(void) const { + return "PartGui::ViewProviderPrism"; + } + //@} +private: + static App::PropertyIntegerConstraint::Constraints polygonRange; +}; + class PartExport Cone : public Primitive { PROPERTY_HEADER(Part::Cone); diff --git a/src/Mod/Part/Gui/AppPartGui.cpp b/src/Mod/Part/Gui/AppPartGui.cpp index 6c2c04ed3..9c3ebb31a 100644 --- a/src/Mod/Part/Gui/AppPartGui.cpp +++ b/src/Mod/Part/Gui/AppPartGui.cpp @@ -49,6 +49,7 @@ #include "ViewProviderConeParametric.h" #include "ViewProviderTorusParametric.h" #include "ViewProviderRuledSurface.h" +#include "ViewProviderPrism.h" #include "DlgSettingsGeneral.h" #include "DlgSettingsObjectColor.h" @@ -108,6 +109,7 @@ void PartGuiExport initPartGui() PartGui::ViewProviderEllipsoid ::init(); PartGui::ViewProviderPython ::init(); PartGui::ViewProviderBox ::init(); + PartGui::ViewProviderPrism ::init(); PartGui::ViewProviderImport ::init(); PartGui::ViewProviderCurveNet ::init(); PartGui::ViewProviderExtrusion ::init(); diff --git a/src/Mod/Part/Gui/CMakeLists.txt b/src/Mod/Part/Gui/CMakeLists.txt index ef5922aa6..375f6e470 100644 --- a/src/Mod/Part/Gui/CMakeLists.txt +++ b/src/Mod/Part/Gui/CMakeLists.txt @@ -163,6 +163,8 @@ SET(PartGui_SRCS ViewProviderCylinderParametric.h ViewProviderConeParametric.cpp ViewProviderConeParametric.h + ViewProviderPrism.cpp + ViewProviderPrism.h ViewProviderTorusParametric.cpp ViewProviderTorusParametric.h ViewProviderCurveNet.cpp diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index 7ef822edf..a534b3412 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -454,7 +454,21 @@ void DlgPrimitives::createPrimitive(const QString& placement) .arg(ui.torusAngle3->value(),0,'f',2) .arg(placement); } - else if (ui.comboBox1->currentIndex() == 7) { // wedge + else if (ui.comboBox1->currentIndex() == 7) { // prism + name = QString::fromAscii(doc->getUniqueObjectName("Prism").c_str()); + cmd = QString::fromAscii( + "App.ActiveDocument.addObject(\"Part::Prism\",\"%1\")\n" + "App.ActiveDocument.%1.Polygon=%2\n" + "App.ActiveDocument.%1.Length=%3\n" + "App.ActiveDocument.%1.Height=%4\n" + "App.ActiveDocument.%1.Placement=%5\n") + .arg(name) + .arg(ui.prismPolygon->value()) + .arg(ui.prismLength->value(),0,'f',2) + .arg(ui.prismHeight->value(),0,'f',2) + .arg(placement); + } + else if (ui.comboBox1->currentIndex() == 8) { // wedge name = QString::fromAscii(doc->getUniqueObjectName("Wedge").c_str()); cmd = QString::fromAscii( "App.ActiveDocument.addObject(\"Part::Wedge\",\"%1\")\n" @@ -482,7 +496,7 @@ void DlgPrimitives::createPrimitive(const QString& placement) .arg(ui.wedgeZ2max->value(),0,'f',2) .arg(placement); } - else if (ui.comboBox1->currentIndex() == 8) { // helix + else if (ui.comboBox1->currentIndex() == 9) { // helix name = QString::fromAscii(doc->getUniqueObjectName("Helix").c_str()); cmd = QString::fromAscii( "App.ActiveDocument.addObject(\"Part::Helix\",\"%1\")\n" @@ -500,7 +514,7 @@ void DlgPrimitives::createPrimitive(const QString& placement) .arg(ui.helixLocalCS->currentIndex()) .arg(placement); } - else if (ui.comboBox1->currentIndex() == 9) { // circle + else if (ui.comboBox1->currentIndex() == 10) { // circle name = QString::fromAscii(doc->getUniqueObjectName("Circle").c_str()); cmd = QString::fromAscii( "App.ActiveDocument.addObject(\"Part::Circle\",\"%1\")\n" @@ -514,7 +528,7 @@ void DlgPrimitives::createPrimitive(const QString& placement) .arg(ui.circleAngle1->value(),0,'f',2) .arg(placement); } - else if (ui.comboBox1->currentIndex() == 10) { // ellipse + else if (ui.comboBox1->currentIndex() == 11) { // ellipse name = QString::fromAscii(doc->getUniqueObjectName("Ellipse").c_str()); cmd = QString::fromAscii( "App.ActiveDocument.addObject(\"Part::Ellipse\",\"%1\")\n" @@ -530,7 +544,7 @@ void DlgPrimitives::createPrimitive(const QString& placement) .arg(ui.ellipseAngle1->value(),0,'f',2) .arg(placement); } - else if (ui.comboBox1->currentIndex() == 11) { // vertex + else if (ui.comboBox1->currentIndex() == 12) { // vertex name = QString::fromAscii(doc->getUniqueObjectName("Vertex").c_str()); cmd = QString::fromAscii( "App.ActiveDocument.addObject(\"Part::Vertex\",\"%1\")\n" @@ -544,7 +558,7 @@ void DlgPrimitives::createPrimitive(const QString& placement) .arg(ui.vertexZ->value(),0,'f',2) .arg(placement); } - else if (ui.comboBox1->currentIndex() == 12) { // line + else if (ui.comboBox1->currentIndex() == 13) { // line name = QString::fromAscii(doc->getUniqueObjectName("Line").c_str()); cmd = QString::fromAscii( "App.ActiveDocument.addObject(\"Part::Line\",\"%1\")\n" diff --git a/src/Mod/Part/Gui/DlgPrimitives.ui b/src/Mod/Part/Gui/DlgPrimitives.ui index 4bc21969f..a0f4b9af9 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.ui +++ b/src/Mod/Part/Gui/DlgPrimitives.ui @@ -63,6 +63,11 @@ Torus + + + Prism + + Wedge @@ -951,6 +956,96 @@ + + + + 9 + + + 6 + + + + + 0 + + + 6 + + + + + Polygon: + + + + + + + 1000 + + + 3 + + + 6 + + + + + + + Length: + + + + + + + 0.000000000000000 + + + 1000.000000000000000 + + + 2.000000000000000 + + + + + + + Height: + + + + + + + 1000.000000000000000 + + + 10.000000000000000 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + diff --git a/src/Mod/Part/Gui/ViewProviderPrism.cpp b/src/Mod/Part/Gui/ViewProviderPrism.cpp new file mode 100644 index 000000000..aa10b73f3 --- /dev/null +++ b/src/Mod/Part/Gui/ViewProviderPrism.cpp @@ -0,0 +1,68 @@ +/*************************************************************************** + * Copyright (c) 2013 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +#include +#include "ViewProviderPrism.h" + +using namespace PartGui; +using namespace std; + + +//************************************************************************** +// Construction/Destruction + +PROPERTY_SOURCE(PartGui::ViewProviderPrism, PartGui::ViewProviderPart) + + +ViewProviderPrism::ViewProviderPrism() +{ + //sPixmap = "Tree_Part_Cone_Parametric.svg"; +} + +ViewProviderPrism::~ViewProviderPrism() +{ + +} + + + +// ********************************************************************************** + +std::vector ViewProviderPrism::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList; + + // add your own modes + StrList.push_back("Flat Lines"); + StrList.push_back("Shaded"); + StrList.push_back("Wireframe"); + StrList.push_back("Points"); + + return StrList; +} diff --git a/src/Mod/Part/Gui/ViewProviderPrism.h b/src/Mod/Part/Gui/ViewProviderPrism.h new file mode 100644 index 000000000..92b1ccc05 --- /dev/null +++ b/src/Mod/Part/Gui/ViewProviderPrism.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (c) 2013 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef PARTGUI_VIEWPROVIDERPRISM_H +#define PARTGUI_VIEWPROVIDERPRISM_H + +#include "ViewProvider.h" + + +namespace PartGui { + + +class PartGuiExport ViewProviderPrism : public ViewProviderPart +{ + PROPERTY_HEADER(PartGui::ViewProviderPrism); + +public: + /// constructor + ViewProviderPrism(); + /// destructor + virtual ~ViewProviderPrism(); + + std::vector getDisplayModes(void) const; + +protected: + +}; + +} // namespace PartGui + + +#endif // PARTGUI_VIEWPROVIDERPRISM_H +