From 06567358db3465c0f9823bc002101fe3eb949a9b Mon Sep 17 00:00:00 2001 From: jmaustpc Date: Mon, 11 Nov 2013 01:23:47 +1100 Subject: [PATCH] Add Part_RegularPolygon, regular polygon edge in Part workbench "create primitives", Add icons Part_Polygon and Part_Spline --- src/Mod/Part/App/AppPart.cpp | 1 + src/Mod/Part/App/PrimitiveFeature.cpp | 59 +++++ src/Mod/Part/App/PrimitiveFeature.h | 25 ++ src/Mod/Part/Gui/AppPartGui.cpp | 92 ++++---- src/Mod/Part/Gui/CMakeLists.txt | 2 + src/Mod/Part/Gui/DlgPrimitives.cpp | 13 ++ src/Mod/Part/Gui/DlgPrimitives.ui | 78 +++++++ src/Mod/Part/Gui/Resources/Part.qrc | 2 + .../icons/Part_Polygon_Parametric.svg | 220 ++++++++++++++++++ .../icons/Part_Spline_Parametric.svg | 208 +++++++++++++++++ .../Part/Gui/ViewProviderRegularPolygon.cpp | 68 ++++++ src/Mod/Part/Gui/ViewProviderRegularPolygon.h | 53 +++++ 12 files changed, 774 insertions(+), 47 deletions(-) create mode 100644 src/Mod/Part/Gui/Resources/icons/Part_Polygon_Parametric.svg create mode 100644 src/Mod/Part/Gui/Resources/icons/Part_Spline_Parametric.svg create mode 100644 src/Mod/Part/Gui/ViewProviderRegularPolygon.cpp create mode 100644 src/Mod/Part/Gui/ViewProviderRegularPolygon.h diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 0c21b44e00ed..c2bb5f8a838b 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -194,6 +194,7 @@ void PartExport initPart() Part::Sphere ::init(); Part::Cylinder ::init(); Part::Prism ::init(); + Part::RegularPolygon ::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 bbb0b8223fa7..8c6fe8fe8292 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -523,6 +523,65 @@ App::DocumentObjectExecReturn *Prism::execute(void) return App::DocumentObject::StdReturn; } +App::PropertyIntegerConstraint::Constraints RegularPolygon::numberOfSides = {3,INT_MAX,1}; + +PROPERTY_SOURCE(Part::RegularPolygon, Part::Primitive) + +RegularPolygon::RegularPolygon(void) +{ + ADD_PROPERTY_TYPE(NumberOfSides,(6.0),"RegularPolygon",App::Prop_None,"The number of sides of the regular polygon"); + ADD_PROPERTY_TYPE(Radius,(2.0),"RegularPolygon",App::Prop_None,"The inscribed radius of the regular polygon"); +// ADD_PROPERTY_TYPE(Height,(10.0f),"RegularPolygon",App::Prop_None,"The height of the regular polygon"); + NumberOfSides.setConstraints(&numberOfSides); +} + +short RegularPolygon::mustExecute() const +{ + if (NumberOfSides.isTouched()) + return 1; + if (Radius.isTouched()) + return 1; +// if (Height.isTouched()) +// return 1; + return Primitive::mustExecute(); +} + +App::DocumentObjectExecReturn *RegularPolygon::execute(void) +{ + // Build a regular polygon + if (NumberOfSides.getValue() < 3) + return new App::DocumentObjectExecReturn("Less than the minimum 3 sides is invalid"); + if (Radius.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 = NumberOfSides.getValue(); + + Base::Matrix4D mat; + mat.rotZ(Base::toRadians(360.0/nodes)); + + // create polygon + BRepBuilderAPI_MakePolygon mkPoly; + Base::Vector3d v(Radius.getValue(),0,0); + for (long i=0; iShape.setValue(mkPoly.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 5d081eec2233..422f6957e789 100644 --- a/src/Mod/Part/App/PrimitiveFeature.h +++ b/src/Mod/Part/App/PrimitiveFeature.h @@ -220,6 +220,31 @@ class PartExport Prism : public Primitive static App::PropertyIntegerConstraint::Constraints polygonRange; }; +class PartExport RegularPolygon : public Primitive +{ + PROPERTY_HEADER(Part::RegularPolygon); + +public: + RegularPolygon(); + + App::PropertyIntegerConstraint NumberOfSides; + App::PropertyLength Radius; + 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::ViewProviderRegularPolygon"; + } + //@} +private: + static App::PropertyIntegerConstraint::Constraints numberOfSides; +}; + 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 83dc2c1eacb6..2b6efdcaa97d 100644 --- a/src/Mod/Part/Gui/AppPartGui.cpp +++ b/src/Mod/Part/Gui/AppPartGui.cpp @@ -24,9 +24,8 @@ #include +#include "SoBrepShape.h" #include "SoBrepFaceSet.h" -#include "SoBrepEdgeSet.h" -#include "SoBrepPointSet.h" #include "SoFCShapeObject.h" #include "ViewProvider.h" #include "ViewProviderExt.h" @@ -51,7 +50,7 @@ #include "ViewProviderTorusParametric.h" #include "ViewProviderRuledSurface.h" #include "ViewProviderPrism.h" -#include "ViewProviderSpline.h" +#include "ViewProviderRegularPolygon.h" #include "DlgSettingsGeneral.h" #include "DlgSettingsObjectColor.h" @@ -59,6 +58,7 @@ #include "Workbench.h" #include +#include "qrc_Part.cpp" #include "Resources/icons/PartFeature.xpm" #include "Resources/icons/PartFeatureImport.xpm" @@ -100,52 +100,50 @@ void PartGuiExport initPartGui() (void) Py_InitModule("PartGui", PartGui_methods); /* mod name, table ptr */ Base::Console().Log("Loading GUI of Part module... done\n"); - PartGui::SoBrepFaceSet ::initClass(); - PartGui::SoBrepEdgeSet ::initClass(); - PartGui::SoBrepPointSet ::initClass(); - PartGui::SoFCControlPoints ::initClass(); - PartGui::ViewProviderPartBase ::init(); - PartGui::ViewProviderPartExt ::init(); - PartGui::ViewProviderPart ::init(); - PartGui::ViewProviderEllipsoid ::init(); - PartGui::ViewProviderPython ::init(); - PartGui::ViewProviderBox ::init(); - PartGui::ViewProviderPrism ::init(); - PartGui::ViewProviderWedge ::init(); - PartGui::ViewProviderImport ::init(); - PartGui::ViewProviderCurveNet ::init(); - PartGui::ViewProviderExtrusion ::init(); - PartGui::ViewProvider2DObject ::init(); - PartGui::ViewProvider2DObjectPython ::init(); - PartGui::ViewProviderMirror ::init(); - PartGui::ViewProviderFillet ::init(); - PartGui::ViewProviderChamfer ::init(); - PartGui::ViewProviderRevolution ::init(); - PartGui::ViewProviderLoft ::init(); - PartGui::ViewProviderSweep ::init(); - PartGui::ViewProviderOffset ::init(); - PartGui::ViewProviderThickness ::init(); - PartGui::ViewProviderCustom ::init(); - PartGui::ViewProviderCustomPython ::init(); - PartGui::ViewProviderBoolean ::init(); - PartGui::ViewProviderMultiFuse ::init(); - PartGui::ViewProviderMultiCommon ::init(); - PartGui::ViewProviderCompound ::init(); - PartGui::ViewProviderSpline ::init(); - PartGui::ViewProviderCircleParametric ::init(); - PartGui::ViewProviderLineParametric ::init(); - PartGui::ViewProviderPointParametric ::init(); - PartGui::ViewProviderEllipseParametric ::init(); - PartGui::ViewProviderHelixParametric ::init(); - PartGui::ViewProviderSpiralParametric ::init(); - PartGui::ViewProviderPlaneParametric ::init(); - PartGui::ViewProviderSphereParametric ::init(); + PartGui::SoBrepFaceSet ::initClass(); + PartGui::SoBrepEdgeSet ::initClass(); + PartGui::SoBrepPointSet ::initClass(); + PartGui::SoFCControlPoints ::initClass(); + PartGui::ViewProviderPartBase ::init(); + PartGui::ViewProviderPartExt ::init(); + PartGui::ViewProviderPart ::init(); + PartGui::ViewProviderEllipsoid ::init(); + PartGui::ViewProviderPython ::init(); + PartGui::ViewProviderBox ::init(); + PartGui::ViewProviderPrism ::init(); + PartGui::ViewProviderRegularPolygon ::init(); + PartGui::ViewProviderImport ::init(); + PartGui::ViewProviderCurveNet ::init(); + PartGui::ViewProviderExtrusion ::init(); + PartGui::ViewProvider2DObject ::init(); + PartGui::ViewProvider2DObjectPython ::init(); + PartGui::ViewProviderMirror ::init(); + PartGui::ViewProviderFillet ::init(); + PartGui::ViewProviderChamfer ::init(); + PartGui::ViewProviderRevolution ::init(); + PartGui::ViewProviderLoft ::init(); + PartGui::ViewProviderSweep ::init(); + PartGui::ViewProviderOffset ::init(); + PartGui::ViewProviderThickness ::init(); + PartGui::ViewProviderCustom ::init(); + PartGui::ViewProviderCustomPython ::init(); + PartGui::ViewProviderBoolean ::init(); + PartGui::ViewProviderMultiFuse ::init(); + PartGui::ViewProviderMultiCommon ::init(); + PartGui::ViewProviderCompound ::init(); + PartGui::ViewProviderCircleParametric ::init(); + PartGui::ViewProviderLineParametric ::init(); + PartGui::ViewProviderPointParametric ::init(); + PartGui::ViewProviderEllipseParametric ::init(); + PartGui::ViewProviderHelixParametric ::init(); + PartGui::ViewProviderPlaneParametric ::init(); + PartGui::ViewProviderSphereParametric ::init(); PartGui::ViewProviderCylinderParametric ::init(); - PartGui::ViewProviderConeParametric ::init(); - PartGui::ViewProviderTorusParametric ::init(); - PartGui::ViewProviderRuledSurface ::init(); + PartGui::ViewProviderConeParametric ::init(); + PartGui::ViewProviderTorusParametric ::init(); + PartGui::ViewProviderRuledSurface ::init(); - PartGui::Workbench ::init(); + PartGui::Workbench ::init(); // instantiating the commands CreatePartCommands(); diff --git a/src/Mod/Part/Gui/CMakeLists.txt b/src/Mod/Part/Gui/CMakeLists.txt index fd6f6b465b60..d301196b058f 100644 --- a/src/Mod/Part/Gui/CMakeLists.txt +++ b/src/Mod/Part/Gui/CMakeLists.txt @@ -167,6 +167,8 @@ SET(PartGui_SRCS ViewProviderConeParametric.h ViewProviderPrism.cpp ViewProviderPrism.h + ViewProviderRegularPolygon.cpp + ViewProviderRegularPolygon.h ViewProviderTorusParametric.cpp ViewProviderTorusParametric.h ViewProviderCurveNet.cpp diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index b4351b1949ed..f4f48fd536af 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -259,6 +259,7 @@ DlgPrimitives::DlgPrimitives(QWidget* parent) ui.edgeY2->setMinimum(INT_MIN); ui.edgeZ2->setMaximum(INT_MAX); ui.edgeZ2->setMinimum(INT_MIN); + // RegularPolygon } /* @@ -593,6 +594,18 @@ void DlgPrimitives::createPrimitive(const QString& placement) .arg(ui.edgeZ2->value(),0,'f',2) .arg(placement); } + else if (ui.comboBox1->currentIndex() == 14) { // RegularPolygon + name = QString::fromAscii(doc->getUniqueObjectName("RegularPolygon").c_str()); + cmd = QString::fromAscii( + "App.ActiveDocument.addObject(\"Part::RegularPolygon\",\"%1\")\n" + "App.ActiveDocument.%1.NumberOfSides=%2\n" + "App.ActiveDocument.%1.Radius=%3\n" + "App.ActiveDocument.%1.Placement=%5\n") + .arg(name) + .arg(ui.regularPolygonNumberOfSides->value()) + .arg(ui.regularPolygonRadius->value(),0,'f',2) + .arg(placement); + } // Execute the Python block QString prim = tr("Create %1").arg(ui.comboBox1->currentText()); diff --git a/src/Mod/Part/Gui/DlgPrimitives.ui b/src/Mod/Part/Gui/DlgPrimitives.ui index 058f150ee781..42b8bf97a9ac 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.ui +++ b/src/Mod/Part/Gui/DlgPrimitives.ui @@ -103,6 +103,11 @@ Line + + + RegularPolygon + + @@ -1853,6 +1858,79 @@ + + + + 9 + + + 6 + + + + + 0 + + + 6 + + + + + Number Of Sides: + + + + + + + 1000 + + + 3 + + + 6 + + + + + + + Radius: + + + + + + + 0.000000000000000 + + + 1000.000000000000000 + + + 2.000000000000000 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + diff --git a/src/Mod/Part/Gui/Resources/Part.qrc b/src/Mod/Part/Gui/Resources/Part.qrc index be6965e8f832..7fcb7c3ef302 100644 --- a/src/Mod/Part/Gui/Resources/Part.qrc +++ b/src/Mod/Part/Gui/Resources/Part.qrc @@ -40,6 +40,8 @@ icons/Part_Line_Parametric.svg icons/Part_Circle_Parametric.svg icons/Part_Point_Parametric.svg + icons/Part_Polygon_Parametric.svg + icons/Part_Spline_Parametric.svg icons/Tree_Part_Box_Parametric.svg icons/Tree_Part_Cylinder_Parametric.svg icons/Tree_Part_Cone_Parametric.svg diff --git a/src/Mod/Part/Gui/Resources/icons/Part_Polygon_Parametric.svg b/src/Mod/Part/Gui/Resources/icons/Part_Polygon_Parametric.svg new file mode 100644 index 000000000000..d013a40fb953 --- /dev/null +++ b/src/Mod/Part/Gui/Resources/icons/Part_Polygon_Parametric.svg @@ -0,0 +1,220 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/src/Mod/Part/Gui/Resources/icons/Part_Spline_Parametric.svg b/src/Mod/Part/Gui/Resources/icons/Part_Spline_Parametric.svg new file mode 100644 index 000000000000..861ce50746a3 --- /dev/null +++ b/src/Mod/Part/Gui/Resources/icons/Part_Spline_Parametric.svg @@ -0,0 +1,208 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/src/Mod/Part/Gui/ViewProviderRegularPolygon.cpp b/src/Mod/Part/Gui/ViewProviderRegularPolygon.cpp new file mode 100644 index 000000000000..1fff370a7680 --- /dev/null +++ b/src/Mod/Part/Gui/ViewProviderRegularPolygon.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 "ViewProviderRegularPolygon.h" + +using namespace PartGui; +using namespace std; + + +//************************************************************************** +// Construction/Destruction + +PROPERTY_SOURCE(PartGui::ViewProviderRegularPolygon, PartGui::ViewProviderPart) + + +ViewProviderRegularPolygon::ViewProviderRegularPolygon() +{ + sPixmap = "Part_Polygon_Parametric.svg"; +} + +ViewProviderRegularPolygon::~ViewProviderRegularPolygon() +{ + +} + + + +// ********************************************************************************** + +std::vector ViewProviderRegularPolygon::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/ViewProviderRegularPolygon.h b/src/Mod/Part/Gui/ViewProviderRegularPolygon.h new file mode 100644 index 000000000000..7e0f94fb6c5b --- /dev/null +++ b/src/Mod/Part/Gui/ViewProviderRegularPolygon.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_VIEWPROVIDERREGULARPOLYGON_H +#define PARTGUI_VIEWPROVIDERREGULARPOLYGON_H + +#include "ViewProvider.h" + + +namespace PartGui { + + +class PartGuiExport ViewProviderRegularPolygon : public ViewProviderPart +{ + PROPERTY_HEADER(PartGui::ViewProviderRegularPolygon); + +public: + /// constructor + ViewProviderRegularPolygon(); + /// destructor + virtual ~ViewProviderRegularPolygon(); + + std::vector getDisplayModes(void) const; + +protected: + +}; + +} // namespace PartGui + + +#endif // PARTGUI_VIEWPROVIDERREGULARPOLYGON_H +