0001290: Add spiral tool in Part Module

This commit is contained in:
wmayer 2013-10-30 14:48:42 +01:00
parent 12803c1de4
commit 712bc170c2
10 changed files with 513 additions and 90 deletions

View File

@ -197,6 +197,7 @@ void PartExport initPart()
Part::Cone ::init();
Part::Torus ::init();
Part::Helix ::init();
Part::Spiral ::init();
Part::Wedge ::init();
Part::Part2DObject ::init();
Part::Part2DObjectPython ::init();

View File

@ -39,6 +39,7 @@
# include <BRepBuilderAPI_MakeSolid.hxx>
# include <BRepBuilderAPI_MakePolygon.hxx>
# include <BRepBuilderAPI_GTransform.hxx>
# include <BRepProj_Projection.hxx>
# include <gp_Circ.hxx>
# include <gp_Elips.hxx>
# include <gp_GTrsf.hxx>
@ -711,6 +712,98 @@ App::DocumentObjectExecReturn *Helix::execute(void)
return App::DocumentObject::StdReturn;
}
PROPERTY_SOURCE(Part::Spiral, Part::Primitive)
Spiral::Spiral(void)
{
ADD_PROPERTY_TYPE(Growth, (1.0),"Spiral",App::Prop_None,"The growth of the spiral per rotation");
Growth.setConstraints(&floatRange);
ADD_PROPERTY_TYPE(Radius,(1.0),"Spiral",App::Prop_None,"The radius of the spiral");
Radius.setConstraints(&floatRange);
ADD_PROPERTY_TYPE(Rotations,(2.0),"Spiral",App::Prop_None,"The number of rotations");
Rotations.setConstraints(&floatRange);
}
void Spiral::onChanged(const App::Property* prop)
{
if (!isRestoring()) {
if (prop == &Growth || prop == &Rotations || prop == &Radius) {
try {
App::DocumentObjectExecReturn *ret = recompute();
delete ret;
}
catch (...) {
}
}
}
Part::Feature::onChanged(prop);
}
short Spiral::mustExecute() const
{
if (Growth.isTouched())
return 1;
if (Rotations.isTouched())
return 1;
if (Radius.isTouched())
return 1;
return Primitive::mustExecute();
}
App::DocumentObjectExecReturn *Spiral::execute(void)
{
try {
Standard_Real myNumRot = Rotations.getValue();
Standard_Real myRadius = Radius.getValue();
Standard_Real myGrowth = Growth.getValue();
Standard_Real myPitch = 1.0;
Standard_Real myHeight = myNumRot * myPitch;
Standard_Real myAngle = atan(myGrowth / myPitch);
TopoShape helix;
if (myGrowth < Precision::Confusion())
Standard_Failure::Raise("Growth too small");
if (myNumRot < Precision::Confusion())
Standard_Failure::Raise("Number of rotations too small");
gp_Ax2 cylAx2(gp_Pnt(0.0,0.0,0.0) , gp::DZ());
Handle_Geom_Surface surf = new Geom_ConicalSurface(gp_Ax3(cylAx2), myAngle, myRadius);
gp_Pnt2d aPnt(0, 0);
gp_Dir2d aDir(2. * M_PI, myPitch);
gp_Ax2d aAx2d(aPnt, aDir);
Handle(Geom2d_Line) line = new Geom2d_Line(aAx2d);
gp_Pnt2d beg = line->Value(0);
gp_Pnt2d end = line->Value(sqrt(4.0*M_PI*M_PI+myPitch*myPitch)*(myHeight/myPitch));
// calculate end point for conical helix
Standard_Real v = myHeight / cos(myAngle);
Standard_Real u = (myHeight/myPitch) * 2.0 * M_PI;
gp_Pnt2d cend(u, v);
end = cend;
Handle(Geom2d_TrimmedCurve) segm = GCE2d_MakeSegment(beg , end);
TopoDS_Edge edgeOnSurf = BRepBuilderAPI_MakeEdge(segm , surf);
TopoDS_Wire wire = BRepBuilderAPI_MakeWire(edgeOnSurf);
BRepLib::BuildCurves3d(wire);
Handle_Geom_Plane aPlane = new Geom_Plane(gp_Pnt(0.0,0.0,0.0), gp::DZ());
Standard_Real range = (myNumRot+1) * myGrowth + 1;
BRepBuilderAPI_MakeFace mkFace(aPlane, -range, range, -range, range);
BRepProj_Projection proj(wire, mkFace.Face(), gp::DZ());
this->Shape.setValue(proj.Shape());
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
return App::DocumentObject::StdReturn;
}
PROPERTY_SOURCE(Part::Wedge, Part::Primitive)
Wedge::Wedge()

View File

@ -300,6 +300,32 @@ private:
static const char* LocalCSEnums[];
};
class PartExport Spiral : public Primitive
{
PROPERTY_HEADER(Part::Spiral);
public:
Spiral();
App::PropertyFloatConstraint Growth;
App::PropertyFloatConstraint Rotations;
App::PropertyFloatConstraint Radius;
/** @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::ViewProviderSpiralParametric";
}
//@}
protected:
void onChanged (const App::Property* prop);
};
class PartExport Wedge : public Primitive
{
PROPERTY_HEADER(Part::Wedge);

View File

@ -129,18 +129,19 @@ void PartGuiExport initPartGui()
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::ViewProviderCylinderParametric ::init();
PartGui::ViewProviderConeParametric ::init();
PartGui::ViewProviderTorusParametric ::init();
PartGui::ViewProviderRuledSurface ::init();
PartGui::ViewProviderSpline ::init();
PartGui::Workbench ::init();

View File

@ -514,7 +514,21 @@ void DlgPrimitives::createPrimitive(const QString& placement)
.arg(ui.helixLocalCS->currentIndex())
.arg(placement);
}
else if (ui.comboBox1->currentIndex() == 10) { // circle
else if (ui.comboBox1->currentIndex() == 10) { // spiral
name = QString::fromAscii(doc->getUniqueObjectName("Spiral").c_str());
cmd = QString::fromAscii(
"App.ActiveDocument.addObject(\"Part::Spiral\",\"%1\")\n"
"App.ActiveDocument.%1.Growth=%2\n"
"App.ActiveDocument.%1.Rotations=%3\n"
"App.ActiveDocument.%1.Radius=%4\n"
"App.ActiveDocument.%1.Placement=%5\n")
.arg(name)
.arg(ui.spiralGrowth->value(),0,'f',2)
.arg(ui.spiralRotation->value(),0,'f',2)
.arg(ui.spiralRadius->value(),0,'f',2)
.arg(placement);
}
else if (ui.comboBox1->currentIndex() == 11) { // circle
name = QString::fromAscii(doc->getUniqueObjectName("Circle").c_str());
cmd = QString::fromAscii(
"App.ActiveDocument.addObject(\"Part::Circle\",\"%1\")\n"
@ -528,7 +542,7 @@ void DlgPrimitives::createPrimitive(const QString& placement)
.arg(ui.circleAngle1->value(),0,'f',2)
.arg(placement);
}
else if (ui.comboBox1->currentIndex() == 11) { // ellipse
else if (ui.comboBox1->currentIndex() == 12) { // ellipse
name = QString::fromAscii(doc->getUniqueObjectName("Ellipse").c_str());
cmd = QString::fromAscii(
"App.ActiveDocument.addObject(\"Part::Ellipse\",\"%1\")\n"
@ -544,7 +558,7 @@ void DlgPrimitives::createPrimitive(const QString& placement)
.arg(ui.ellipseAngle1->value(),0,'f',2)
.arg(placement);
}
else if (ui.comboBox1->currentIndex() == 12) { // vertex
else if (ui.comboBox1->currentIndex() == 13) { // vertex
name = QString::fromAscii(doc->getUniqueObjectName("Vertex").c_str());
cmd = QString::fromAscii(
"App.ActiveDocument.addObject(\"Part::Vertex\",\"%1\")\n"
@ -558,7 +572,7 @@ void DlgPrimitives::createPrimitive(const QString& placement)
.arg(ui.vertexZ->value(),0,'f',2)
.arg(placement);
}
else if (ui.comboBox1->currentIndex() == 13) { // line
else if (ui.comboBox1->currentIndex() == 14) { // line
name = QString::fromAscii(doc->getUniqueObjectName("Line").c_str());
cmd = QString::fromAscii(
"App.ActiveDocument.addObject(\"Part::Line\",\"%1\")\n"

View File

@ -78,6 +78,11 @@
<string>Helix</string>
</property>
</item>
<item>
<property name="text">
<string>Spiral</string>
</property>
</item>
<item>
<property name="text">
<string>Circle</string>
@ -1351,7 +1356,91 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page9_circle">
<widget class="QWidget" name="page9_spiral">
<layout class="QGridLayout">
<property name="margin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<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>
<item row="0" column="0">
<layout class="QGridLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="2" column="0">
<widget class="QLabel" name="label_spiral_radius">
<property name="text">
<string>Radius:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_spiral_growth">
<property name="text">
<string>Growth:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="spiralRadius">
<property name="maximum">
<double>1000.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="spiralGrowth">
<property name="maximum">
<double>1000.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="spiralRotation">
<property name="maximum">
<double>1000.000000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_spiral_rotation">
<property name="text">
<string>Number of rotations:</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="page10_circle">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QGridLayout" name="circleParameters">
@ -1554,7 +1643,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page10_vertex">
<widget class="QWidget" name="page11_vertex">
<layout class="QGridLayout" name="gridLayout_9">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_4">
@ -1614,7 +1703,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page11_edge">
<widget class="QWidget" name="page12_edge">
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_5">

View File

@ -36,6 +36,7 @@
<file>icons/Part_CheckGeometry.svg</file>
<file>icons/Part_Ellipse_Parametric.svg</file>
<file>icons/Part_Helix_Parametric.svg</file>
<file>icons/Part_Spiral_Parametric.svg</file>
<file>icons/Part_Line_Parametric.svg</file>
<file>icons/Part_Circle_Parametric.svg</file>
<file>icons/Part_Point_Parametric.svg</file>

View File

@ -0,0 +1,195 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="64px"
height="64px"
id="svg3052"
sodipodi:version="0.32"
inkscape:version="0.48.3.1 r9886"
sodipodi:docname="Part_Helix_Parametric_1.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape"
version="1.1">
<defs
id="defs3054">
<linearGradient
id="linearGradient4032">
<stop
style="stop-color:#71b2f8;stop-opacity:1;"
offset="0"
id="stop4034" />
<stop
style="stop-color:#002795;stop-opacity:1;"
offset="1"
id="stop4036" />
</linearGradient>
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 32 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="64 : 32 : 1"
inkscape:persp3d-origin="32 : 21.333333 : 1"
id="perspective3060" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3377"
id="radialGradient3705"
gradientUnits="userSpaceOnUse"
cx="148.88333"
cy="81.869568"
fx="148.88333"
fy="81.869568"
r="19.467436"
gradientTransform="matrix(1.6244669,-0.05136783,0.04345521,0.9993132,-102.99033,7.7040438)" />
<linearGradient
id="linearGradient3377">
<stop
id="stop3379"
offset="0"
style="stop-color:#4bff54;stop-opacity:1;" />
<stop
id="stop3381"
offset="1"
style="stop-color:#00b800;stop-opacity:1;" />
</linearGradient>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3206"
id="radialGradient3703"
gradientUnits="userSpaceOnUse"
cx="135.38333"
cy="97.369568"
fx="135.38333"
fy="97.369568"
r="19.467436"
gradientTransform="matrix(0.87904684,0.2250379,-0.41709097,2.0016728,56.73751,-127.99883)" />
<linearGradient
id="linearGradient3199">
<stop
id="stop3201"
offset="0"
style="stop-color:#faff2b;stop-opacity:1;" />
<stop
id="stop3203"
offset="1"
style="stop-color:#ffaa00;stop-opacity:1;" />
</linearGradient>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3377"
id="radialGradient3692"
cx="45.883327"
cy="28.869568"
fx="45.883327"
fy="28.869568"
r="19.467436"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient3206">
<stop
id="stop3208"
offset="0"
style="stop-color:#faff2b;stop-opacity:1;" />
<stop
id="stop3210"
offset="1"
style="stop-color:#ffaa00;stop-opacity:1;" />
</linearGradient>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient4032"
id="radialGradient4030"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1.260164,-0.05136783,0.03370995,0.9993132,-43.139781,7.2044077)"
cx="148.88333"
cy="81.869568"
fx="148.88333"
fy="81.869568"
r="19.467436" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="12.328125"
inkscape:cx="32"
inkscape:cy="32"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="1280"
inkscape:window-height="964"
inkscape:window-x="-2"
inkscape:window-y="-3"
inkscape:window-maximized="1"
inkscape:snap-global="false"
showguides="true"
inkscape:guide-bbox="true">
<sodipodi:guide
orientation="0,1"
position="31.959442,64.811153"
id="guide3868" />
</sodipodi:namedview>
<metadata
id="metadata3057">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<path
sodipodi:type="spiral"
style="fill:none;stroke:#0034ff;stroke-width:3.2275939;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path3966"
sodipodi:cx="19.143219"
sodipodi:cy="14.844107"
sodipodi:expansion="1"
sodipodi:revolution="2.3563685"
sodipodi:radius="18.899866"
sodipodi:argument="-15.995531"
sodipodi:t0="0.15930842"
d="m 20.587456,12.202186 c 2.391334,0.238186 3.496663,2.944487 2.957137,5.047984 -0.855757,3.33642 -4.684462,4.77851 -7.769263,3.754765 C 11.491675,19.583329 9.697603,14.569419 11.222937,10.514391 13.19188,5.2800533 19.413923,3.129392 24.434761,5.1643713 30.622035,7.6721156 33.131417,15.113096 30.582408,21.097474 27.540466,28.239126 18.874603,31.108432 11.928025,28.042749 3.8310425,24.469367 0.60105228,14.574996 4.1851225,6.6670867 7.9264003,-1.5876856 17.658048,-5.4590431 26.166999,-2.7021594"
transform="matrix(1.9811671,0,0,1.7431127,-2.0708868,9.5087624)" />
<path
sodipodi:type="arc"
style="fill:#ff0900;fill-opacity:1;fill-rule:nonzero;stroke:none"
id="path3078-5"
sodipodi:cx="65.622307"
sodipodi:cy="12.613435"
sodipodi:rx="7.6248417"
sodipodi:ry="7.3409381"
d="m 73.247149,12.613435 a 7.6248417,7.3409381 0 1 1 -15.249684,0 7.6248417,7.3409381 0 1 1 15.249684,0 z"
transform="matrix(0.52066529,0,0,0.50212748,3.8352769,24.125256)" />
<path
sodipodi:type="arc"
style="fill:#ff0900;fill-opacity:1;fill-rule:nonzero;stroke:none"
id="path3078-5-8"
sodipodi:cx="65.622307"
sodipodi:cy="12.613435"
sodipodi:rx="7.6248417"
sodipodi:ry="7.3409381"
d="m 73.247149,12.613435 a 7.6248417,7.3409381 0 1 1 -15.249684,0 7.6248417,7.3409381 0 1 1 15.249684,0 z"
transform="matrix(0.50470785,0,0,0.49660262,16.441376,-1.356387)" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -26,24 +26,12 @@
#ifndef _PreComp_
#endif
/// Here the FreeCAD includes sorted by Base,App,Gui......
#include <Base/Parameter.h>
#include "ViewProviderHelixParametric.h"
//#include "Tree.h"
using namespace PartGui;
using namespace std;
//**************************************************************************
// Construction/Destruction
PROPERTY_SOURCE(PartGui::ViewProviderHelixParametric, PartGui::ViewProviderPart)
PROPERTY_SOURCE(PartGui::ViewProviderHelixParametric, PartGui::ViewProviderSpline)
ViewProviderHelixParametric::ViewProviderHelixParametric()
@ -56,16 +44,35 @@ ViewProviderHelixParametric::~ViewProviderHelixParametric()
}
// **********************************************************************************
std::vector<std::string> ViewProviderHelixParametric::getDisplayModes(void) const
{
// get the modes of the father
std::vector<std::string> StrList;
// add your own modes
std::vector<std::string> StrList;
StrList.push_back("Wireframe");
StrList.push_back("Points");
return StrList;
}
// ------------------------------------------------------------------
PROPERTY_SOURCE(PartGui::ViewProviderSpiralParametric, PartGui::ViewProviderSpline)
ViewProviderSpiralParametric::ViewProviderSpiralParametric()
{
sPixmap = "Part_Spiral_Parametric.svg";
}
ViewProviderSpiralParametric::~ViewProviderSpiralParametric()
{
}
std::vector<std::string> ViewProviderSpiralParametric::getDisplayModes(void) const
{
// add your own modes
std::vector<std::string> StrList;
StrList.push_back("Wireframe");
StrList.push_back("Points");

View File

@ -24,24 +24,12 @@
#ifndef PARTGUI_VIEWPROVIDERHELIXPARAMETRIC_H
#define PARTGUI_VIEWPROVIDERHELIXPARAMETRIC_H
#include "ViewProvider.h"
class TopoDS_Shape;
class TopoDS_Face;
class SoSeparator;
class SbVec3f;
class SoTransform;
namespace Gui {
class View3DInventorViewer;
class SoFCSelection;
}
#include "ViewProviderSpline.h"
namespace PartGui {
class PartGuiExport ViewProviderHelixParametric:public ViewProviderPart
class PartGuiExport ViewProviderHelixParametric : public ViewProviderSpline
{
PROPERTY_HEADER(PartGui::ViewProviderHelixParametric);
@ -50,11 +38,19 @@ public:
ViewProviderHelixParametric();
/// destructor
virtual ~ViewProviderHelixParametric();
std::vector<std::string> getDisplayModes(void) const;
};
protected:
class PartGuiExport ViewProviderSpiralParametric : public ViewProviderSpline
{
PROPERTY_HEADER(PartGui::ViewProviderSpiralParametric);
public:
/// constructor
ViewProviderSpiralParametric();
/// destructor
virtual ~ViewProviderSpiralParametric();
std::vector<std::string> getDisplayModes(void) const;
};
} // namespace PartGui