0001239: Part --> Geometric Primitives --> Regular Prism

This commit is contained in:
wmayer 2013-09-21 14:20:04 +02:00
parent 80e7f52b5f
commit 24a3c2cdd9
9 changed files with 326 additions and 6 deletions

View File

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

View File

@ -27,6 +27,7 @@
# include <BRepLib.hxx>
# include <BRepPrimAPI_MakeCone.hxx>
# include <BRepPrimAPI_MakeCylinder.hxx>
# include <BRepPrimAPI_MakePrism.hxx>
# include <BRepPrimAPI_MakeRevol.hxx>
# include <BRepPrimAPI_MakeSphere.hxx>
# include <BRepPrimAPI_MakeTorus.hxx>
@ -36,6 +37,7 @@
# include <BRepBuilderAPI_MakeVertex.hxx>
# include <BRepBuilderAPI_MakeWire.hxx>
# include <BRepBuilderAPI_MakeSolid.hxx>
# include <BRepBuilderAPI_MakePolygon.hxx>
# include <BRepBuilderAPI_GTransform.hxx>
# include <gp_Circ.hxx>
# include <gp_Elips.hxx>
@ -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; i<nodes; i++) {
mkPoly.Add(gp_Pnt(v.x,v.y,v.z));
v = mat * v;
}
mkPoly.Add(gp_Pnt(v.x,v.y,v.z));
BRepBuilderAPI_MakeFace mkFace(mkPoly.Wire());
BRepPrimAPI_MakePrism mkPrism(mkFace.Face(), gp_Vec(0,0,Height.getValue()));
this->Shape.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)

View File

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

View File

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

View File

@ -163,6 +163,8 @@ SET(PartGui_SRCS
ViewProviderCylinderParametric.h
ViewProviderConeParametric.cpp
ViewProviderConeParametric.h
ViewProviderPrism.cpp
ViewProviderPrism.h
ViewProviderTorusParametric.cpp
ViewProviderTorusParametric.h
ViewProviderCurveNet.cpp

View File

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

View File

@ -63,6 +63,11 @@
<string>Torus</string>
</property>
</item>
<item>
<property name="text">
<string>Prism</string>
</property>
</item>
<item>
<property name="text">
<string>Wedge</string>
@ -951,6 +956,96 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page_prism">
<layout class="QGridLayout">
<property name="margin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<layout class="QGridLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="labelPrismPolygon">
<property name="text">
<string>Polygon:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="prismPolygon">
<property name="maximum">
<double>1000</double>
</property>
<property name="minimum">
<double>3</double>
</property>
<property name="value">
<double>6</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelPrismLength">
<property name="text">
<string>Length:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="prismLength">
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>1000.000000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelPrismHeight">
<property name="text">
<string>Height:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="prismHeight">
<property name="maximum">
<double>1000.000000000000000</double>
</property>
<property name="value">
<double>10.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="page7_wedge">
<layout class="QGridLayout" name="gridLayout_8">
<item row="0" column="0">

View File

@ -0,0 +1,68 @@
/***************************************************************************
* Copyright (c) 2013 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <Base/Parameter.h>
#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<std::string> ViewProviderPrism::getDisplayModes(void) const
{
// get the modes of the father
std::vector<std::string> StrList;
// add your own modes
StrList.push_back("Flat Lines");
StrList.push_back("Shaded");
StrList.push_back("Wireframe");
StrList.push_back("Points");
return StrList;
}

View File

@ -0,0 +1,53 @@
/***************************************************************************
* Copyright (c) 2013 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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<std::string> getDisplayModes(void) const;
protected:
};
} // namespace PartGui
#endif // PARTGUI_VIEWPROVIDERPRISM_H