From 11358e1b86bfa09afdd2c9051d6851b0c1b8c900 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 1 May 2012 13:17:10 +0200 Subject: [PATCH] left hand helix --- src/Mod/Part/App/PrimitiveFeature.cpp | 11 ++++- src/Mod/Part/App/PrimitiveFeature.h | 4 ++ src/Mod/Part/App/TopoShape.cpp | 65 +++++++++++++++------------ src/Mod/Part/App/TopoShape.h | 2 +- src/Mod/Part/Gui/DlgPrimitives.cpp | 4 +- src/Mod/Part/Gui/DlgPrimitives.ui | 21 +++++++++ 6 files changed, 74 insertions(+), 33 deletions(-) diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp index 2aef7aa07..0213ac04d 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -100,7 +100,7 @@ void Primitive::onChanged(const App::Property* prop) // Do not support sphere, ellipsoid and torus because the creation // takes too long and thus is not feasible std::string grp = (prop->getGroup() ? prop->getGroup() : ""); - if (grp == "Plane" || grp == "Cylinder" || grp == "Cone"){ + if (grp == "Plane" || grp == "Cylinder" || grp == "Cone" || grp == "Helix") { try { App::DocumentObjectExecReturn *ret = recompute(); delete ret; @@ -585,6 +585,8 @@ App::DocumentObjectExecReturn *Torus::execute(void) PROPERTY_SOURCE(Part::Helix, Part::Primitive) +const char* Part::Helix::LocalCSEnums[]= {"Right-handed","Left-handed",NULL}; + Helix::Helix(void) { ADD_PROPERTY_TYPE(Pitch, (1.0),"Helix",App::Prop_None,"The pitch of the helix"); @@ -595,6 +597,8 @@ Helix::Helix(void) Radius.setConstraints(&floatRange); ADD_PROPERTY_TYPE(Angle,(0.0),"Helix",App::Prop_None,"If angle is > 0 a conical otherwise a cylindircal surface is used"); Angle.setConstraints(&apexRange); + ADD_PROPERTY_TYPE(LocalCoord,(long(0)),"Coordinate System",App::Prop_None,"Orientation of the local coordinate system of the helix"); + LocalCoord.setEnums(LocalCSEnums); } short Helix::mustExecute() const @@ -607,6 +611,8 @@ short Helix::mustExecute() const return 1; if (Angle.isTouched()) return 1; + if (LocalCoord.isTouched()) + return 1; return Primitive::mustExecute(); } @@ -617,8 +623,9 @@ App::DocumentObjectExecReturn *Helix::execute(void) Standard_Real myHeight = Height.getValue(); Standard_Real myRadius = Radius.getValue(); Standard_Real myAngle = Angle.getValue(); + Standard_Boolean myLocalCS = LocalCoord.getValue() ? Standard_True : Standard_False; TopoShape helix; - this->Shape.setValue(helix.makeHelix(myPitch, myHeight, myRadius, myAngle)); + this->Shape.setValue(helix.makeHelix(myPitch, myHeight, myRadius, myAngle, myLocalCS)); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); diff --git a/src/Mod/Part/App/PrimitiveFeature.h b/src/Mod/Part/App/PrimitiveFeature.h index fe1eb0609..e90a4d6a1 100644 --- a/src/Mod/Part/App/PrimitiveFeature.h +++ b/src/Mod/Part/App/PrimitiveFeature.h @@ -227,6 +227,7 @@ public: App::PropertyFloatConstraint Height; App::PropertyFloatConstraint Radius; App::PropertyFloatConstraint Angle; + App::PropertyEnumeration LocalCoord; /** @name methods override feature */ //@{ @@ -234,6 +235,9 @@ public: App::DocumentObjectExecReturn *execute(void); short mustExecute() const; //@} + +private: + static const char* LocalCSEnums[]; }; class PartExport Wedge : public Primitive diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 0a434914a..f78bc5026 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -1493,42 +1493,49 @@ TopoDS_Shape TopoShape::makeSweep(const TopoDS_Shape& profile, double tol, int f } TopoDS_Shape TopoShape::makeHelix(Standard_Real pitch, Standard_Real height, - Standard_Real radius, Standard_Real angle) const + Standard_Real radius, Standard_Real angle, + Standard_Boolean leftHanded) const { - if (pitch < Precision::Confusion()) - Standard_Failure::Raise("Pitch of helix too small"); + if (pitch < Precision::Confusion()) + Standard_Failure::Raise("Pitch of helix too small"); - if (height < Precision::Confusion()) - Standard_Failure::Raise("Height of helix too small"); + if (height < Precision::Confusion()) + Standard_Failure::Raise("Height of helix too small"); - if (radius < Precision::Confusion()) - Standard_Failure::Raise("Radius of helix too small"); + if (radius < Precision::Confusion()) + Standard_Failure::Raise("Radius of helix too small"); - gp_Ax2 cylAx2(gp_Pnt(0.0,0.0,0.0) , gp::DZ()); - Handle_Geom_Surface surf; - if (angle < Precision::Confusion()) { - surf = new Geom_CylindricalSurface(cylAx2, radius); - } - else { - angle = Base::toRadians(angle); - if (angle < Precision::Confusion()) - Standard_Failure::Raise("Angle of helix too small"); - surf = new Geom_ConicalSurface(gp_Ax3(cylAx2), angle, radius); - } + gp_Ax2 cylAx2(gp_Pnt(0.0,0.0,0.0) , gp::DZ()); + Handle_Geom_Surface surf; + if (angle < Precision::Confusion()) { + surf = new Geom_CylindricalSurface(cylAx2, radius); + } + else { + angle = Base::toRadians(angle); + if (angle < Precision::Confusion()) + Standard_Failure::Raise("Angle of helix too small"); + surf = new Geom_ConicalSurface(gp_Ax3(cylAx2), angle, radius); + } - gp_Pnt2d aPnt(0, 0); - gp_Dir2d aDir(2. * PI, pitch); - gp_Ax2d aAx2d(aPnt, aDir); + gp_Pnt2d aPnt(0, 0); + gp_Dir2d aDir(2. * PI, pitch); + if (leftHanded) { + //aPnt.SetCoord(0.0, height); + //aDir.SetCoord(2.0 * PI, -pitch); + aPnt.SetCoord(2. * PI, 0.0); + aDir.SetCoord(-2. * PI, pitch); + } + 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*PI*PI+pitch*pitch)*(height/pitch)); - Handle(Geom2d_TrimmedCurve) segm = GCE2d_MakeSegment(beg , end); + Handle(Geom2d_Line) line = new Geom2d_Line(aAx2d); + gp_Pnt2d beg = line->Value(0); + gp_Pnt2d end = line->Value(sqrt(4.0*PI*PI+pitch*pitch)*(height/pitch)); + Handle(Geom2d_TrimmedCurve) segm = GCE2d_MakeSegment(beg , end); - TopoDS_Edge edgeOnSurf = BRepBuilderAPI_MakeEdge(segm , surf); - TopoDS_Wire wire = BRepBuilderAPI_MakeWire(edgeOnSurf); - BRepLib::BuildCurves3d(wire); - return wire; + TopoDS_Edge edgeOnSurf = BRepBuilderAPI_MakeEdge(segm , surf); + TopoDS_Wire wire = BRepBuilderAPI_MakeWire(edgeOnSurf); + BRepLib::BuildCurves3d(wire); + return wire; } TopoDS_Shape TopoShape::makeLoft(const TopTools_ListOfShape& profiles, diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 9f3b17562..0cf1087f9 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -161,7 +161,7 @@ public: TopoDS_Shape makeTube(double radius, double tol) const; TopoDS_Shape makeTube() const; TopoDS_Shape makeHelix(Standard_Real pitch, Standard_Real height, - Standard_Real radius, Standard_Real angle=0) const; + Standard_Real radius, Standard_Real angle=0, Standard_Boolean left=Standard_False) const; TopoDS_Shape makeLoft(const TopTools_ListOfShape& profiles, Standard_Boolean isSolid, Standard_Boolean isRuled) const; TopoDS_Shape makeOffset(double offset, double tol, diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index 83b6b53cc..3665dd196 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -481,12 +481,14 @@ void DlgPrimitives::createPrimitive(const QString& placement) "App.ActiveDocument.%1.Height=%3\n" "App.ActiveDocument.%1.Radius=%4\n" "App.ActiveDocument.%1.Angle=%5\n" - "App.ActiveDocument.%1.Placement=%6\n") + "App.ActiveDocument.%1.LocalCoord=%6\n" + "App.ActiveDocument.%1.Placement=%7\n") .arg(name) .arg(ui.helixPitch->value(),0,'f',2) .arg(ui.helixHeight->value(),0,'f',2) .arg(ui.helixRadius->value(),0,'f',2) .arg(ui.helixAngle->value(),0,'f',2) + .arg(ui.helixLocalCS->currentIndex()) .arg(placement); } else if (ui.comboBox1->currentIndex() == 9) { // circle diff --git a/src/Mod/Part/Gui/DlgPrimitives.ui b/src/Mod/Part/Gui/DlgPrimitives.ui index 6138066ea..4bc21969f 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.ui +++ b/src/Mod/Part/Gui/DlgPrimitives.ui @@ -1231,6 +1231,27 @@ + + + + Coordinate system: + + + + + + + + Right-handed + + + + + Left-handed + + + +