[PD] use existing definition for PI in Helix
- also a lot of style fixes kindly done by MSVC
This commit is contained in:
@@ -63,11 +63,9 @@
|
||||
|
||||
# include "FeatureHelix.h"
|
||||
|
||||
const double PI = 3.14159265359;
|
||||
|
||||
using namespace PartDesign;
|
||||
|
||||
const char* Helix::ModeEnums[] = {"pitch-height-angle", "pitch-turns-angle", "height-turns-angle", "height-turns-growth", NULL};
|
||||
const char* Helix::ModeEnums[] = { "pitch-height-angle", "pitch-turns-angle", "height-turns-angle", "height-turns-growth", NULL };
|
||||
|
||||
PROPERTY_SOURCE(PartDesign::Helix, PartDesign::ProfileBased)
|
||||
|
||||
@@ -108,43 +106,48 @@ short Helix::mustExecute() const
|
||||
return ProfileBased::mustExecute();
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *Helix::execute(void)
|
||||
App::DocumentObjectExecReturn* Helix::execute(void)
|
||||
{
|
||||
// Validate and normalize parameters
|
||||
// Validate and normalize parameters
|
||||
HelixMode mode = static_cast<HelixMode>(Mode.getValue());
|
||||
if (mode == HelixMode::pitch_height_angle) {
|
||||
if (Pitch.getValue() < Precision::Confusion())
|
||||
return new App::DocumentObjectExecReturn("Error: Pitch too small");
|
||||
if (Height.getValue() < Precision::Confusion())
|
||||
return new App::DocumentObjectExecReturn("Error: height too small!");
|
||||
Turns.setValue(Height.getValue()/Pitch.getValue());
|
||||
} else if (mode == HelixMode::pitch_turns_angle) {
|
||||
Turns.setValue(Height.getValue() / Pitch.getValue());
|
||||
}
|
||||
else if (mode == HelixMode::pitch_turns_angle) {
|
||||
if (Pitch.getValue() < Precision::Confusion())
|
||||
return new App::DocumentObjectExecReturn("Error: pitch too small!");
|
||||
if (Turns.getValue() < Precision::Confusion())
|
||||
return new App::DocumentObjectExecReturn("Error: turns too small!");
|
||||
Height.setValue(Turns.getValue()*Pitch.getValue());
|
||||
} else if (mode == HelixMode::height_turns_angle) {
|
||||
Height.setValue(Turns.getValue() * Pitch.getValue());
|
||||
}
|
||||
else if (mode == HelixMode::height_turns_angle) {
|
||||
if (Height.getValue() < Precision::Confusion())
|
||||
return new App::DocumentObjectExecReturn("Error: height too small!");
|
||||
if (Turns.getValue() < Precision::Confusion())
|
||||
return new App::DocumentObjectExecReturn("Error: turns too small!");
|
||||
Pitch.setValue(Height.getValue()/Turns.getValue());
|
||||
} else if (mode == HelixMode::height_turns_growth) {
|
||||
Pitch.setValue(Height.getValue() / Turns.getValue());
|
||||
}
|
||||
else if (mode == HelixMode::height_turns_growth) {
|
||||
if (Turns.getValue() < Precision::Confusion())
|
||||
return new App::DocumentObjectExecReturn("Error: turns too small!");
|
||||
if ((Height.getValue() < Precision::Confusion())
|
||||
&& (abs(Growth.getValue()) < Precision::Confusion()))
|
||||
return new App::DocumentObjectExecReturn("Error: either height or growth must not be zero!");
|
||||
Pitch.setValue(Height.getValue()/Turns.getValue());
|
||||
} else {
|
||||
Pitch.setValue(Height.getValue() / Turns.getValue());
|
||||
}
|
||||
else {
|
||||
return new App::DocumentObjectExecReturn("Error: unsupported mode");
|
||||
}
|
||||
|
||||
TopoDS_Shape sketchshape;
|
||||
try {
|
||||
sketchshape = getVerifiedFace();
|
||||
} catch (const Base::Exception& e) {
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
return new App::DocumentObjectExecReturn(e.what());
|
||||
}
|
||||
|
||||
@@ -165,7 +168,8 @@ App::DocumentObjectExecReturn *Helix::execute(void)
|
||||
TopoDS_Shape base;
|
||||
try {
|
||||
base = getBaseShape();
|
||||
} catch (const Base::Exception&) {
|
||||
}
|
||||
catch (const Base::Exception&) {
|
||||
// fall back to support (for legacy features)
|
||||
base = TopoDS_Shape();
|
||||
}
|
||||
@@ -173,7 +177,8 @@ App::DocumentObjectExecReturn *Helix::execute(void)
|
||||
// update Axis from ReferenceAxis
|
||||
try {
|
||||
updateAxis();
|
||||
} catch (const Base::Exception& e) {
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
return new App::DocumentObjectExecReturn(e.what());
|
||||
}
|
||||
|
||||
@@ -189,18 +194,19 @@ App::DocumentObjectExecReturn *Helix::execute(void)
|
||||
std::vector<TopoDS_Wire> wires;
|
||||
try {
|
||||
wires = getProfileWires();
|
||||
} catch (const Base::Exception& e) {
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
return new App::DocumentObjectExecReturn(e.what());
|
||||
}
|
||||
|
||||
std::vector<std::vector<TopoDS_Wire>> wiresections;
|
||||
for(TopoDS_Wire& wire : wires)
|
||||
for (TopoDS_Wire& wire : wires)
|
||||
wiresections.emplace_back(1, wire);
|
||||
|
||||
//build all shells
|
||||
std::vector<TopoDS_Shape> shells;
|
||||
std::vector<TopoDS_Wire> frontwires, backwires;
|
||||
for(std::vector<TopoDS_Wire>& wires : wiresections) {
|
||||
for (std::vector<TopoDS_Wire>& wires : wiresections) {
|
||||
|
||||
BRepOffsetAPI_MakePipeShell mkPS(TopoDS::Wire(path));
|
||||
|
||||
@@ -208,7 +214,7 @@ App::DocumentObjectExecReturn *Helix::execute(void)
|
||||
mkPS.SetTransitionMode(BRepBuilderAPI_Transformed);
|
||||
mkPS.SetMode(true); //This is for frenet
|
||||
|
||||
for(TopoDS_Wire& wire : wires) {
|
||||
for (TopoDS_Wire& wire : wires) {
|
||||
wire.Move(invObjLoc);
|
||||
mkPS.Add(wire);
|
||||
}
|
||||
@@ -233,19 +239,20 @@ App::DocumentObjectExecReturn *Helix::execute(void)
|
||||
if (!frontwires.empty()) {
|
||||
// build the end faces, sew the shell and build the final solid
|
||||
TopoDS_Shape front = Part::FaceMakerCheese::makeFace(frontwires);
|
||||
TopoDS_Shape back = Part::FaceMakerCheese::makeFace(backwires);
|
||||
TopoDS_Shape back = Part::FaceMakerCheese::makeFace(backwires);
|
||||
|
||||
BRepBuilderAPI_Sewing sewer;
|
||||
sewer.SetTolerance(Precision::Confusion());
|
||||
sewer.Add(front);
|
||||
sewer.Add(back);
|
||||
|
||||
for(TopoDS_Shape& s : shells)
|
||||
for (TopoDS_Shape& s : shells)
|
||||
sewer.Add(s);
|
||||
|
||||
sewer.Perform();
|
||||
mkSolid.Add(TopoDS::Shell(sewer.SewedShape()));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// shells are already closed - add them directly
|
||||
for (TopoDS_Shape& s : shells) {
|
||||
mkSolid.Add(TopoDS::Shell(s));
|
||||
@@ -307,7 +314,8 @@ App::DocumentObjectExecReturn *Helix::execute(void)
|
||||
return new App::DocumentObjectExecReturn("Error: Intersecting the helix failed");
|
||||
boolOp = this->getSolid(mkCom.Shape());
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
BRepAlgoAPI_Cut mkCut(base, result);
|
||||
if (!mkCut.IsDone())
|
||||
return new App::DocumentObjectExecReturn("Error: Subtracting the helix failed");
|
||||
@@ -343,14 +351,14 @@ App::DocumentObjectExecReturn *Helix::execute(void)
|
||||
|
||||
void Helix::updateAxis(void)
|
||||
{
|
||||
App::DocumentObject *pcReferenceAxis = ReferenceAxis.getValue();
|
||||
const std::vector<std::string> &subReferenceAxis = ReferenceAxis.getSubValues();
|
||||
App::DocumentObject* pcReferenceAxis = ReferenceAxis.getValue();
|
||||
const std::vector<std::string>& subReferenceAxis = ReferenceAxis.getSubValues();
|
||||
Base::Vector3d base;
|
||||
Base::Vector3d dir;
|
||||
getAxis(pcReferenceAxis, subReferenceAxis, base, dir, false);
|
||||
|
||||
Base.setValue(base.x,base.y,base.z);
|
||||
Axis.setValue(dir.x,dir.y,dir.z);
|
||||
Base.setValue(base.x, base.y, base.z);
|
||||
Axis.setValue(dir.x, dir.y, dir.z);
|
||||
}
|
||||
|
||||
TopoDS_Shape Helix::generateHelixPath(void)
|
||||
@@ -367,9 +375,9 @@ TopoDS_Shape Helix::generateHelixPath(void)
|
||||
|
||||
// get revolve axis
|
||||
Base::Vector3d b = Base.getValue();
|
||||
gp_Pnt pnt(b.x,b.y,b.z);
|
||||
gp_Pnt pnt(b.x, b.y, b.z);
|
||||
Base::Vector3d v = Axis.getValue();
|
||||
gp_Dir dir(v.x,v.y,v.z);
|
||||
gp_Dir dir(v.x, v.y, v.z);
|
||||
|
||||
Base::Vector3d normal = getProfileNormal();
|
||||
Base::Vector3d start = v.Cross(normal); // pointing towards the desired helix start point.
|
||||
@@ -391,14 +399,14 @@ TopoDS_Shape Helix::generateHelixPath(void)
|
||||
|
||||
// Find out in what quadrant relative to the axis the profile is located, and the exact position.
|
||||
Base::Vector3d profileCenter = getProfileCenterPoint();
|
||||
double axisOffset = profileCenter*start - b*start;
|
||||
double startOffset = profileCenter*v - b*v;
|
||||
double axisOffset = profileCenter * start - b * start;
|
||||
double startOffset = profileCenter * v - b * v;
|
||||
double radius = std::fabs(axisOffset);
|
||||
bool turned = axisOffset < 0;
|
||||
|
||||
if (radius < Precision::Confusion()) {
|
||||
if (radius < Precision::Confusion()) {
|
||||
// in this case ensure that axis is not in the sketch plane
|
||||
if (std::fabs(v*normal) < Precision::Confusion())
|
||||
if (std::fabs(v * normal) < Precision::Confusion())
|
||||
throw Base::ValueError("Error: Result is self intersecting");
|
||||
radius = 1.0; //fallback to radius 1
|
||||
}
|
||||
@@ -430,19 +438,19 @@ TopoDS_Shape Helix::generateHelixPath(void)
|
||||
|
||||
|
||||
if (reversed) {
|
||||
mov.SetRotation(gp_Ax1(origo, dir_axis2), PI);
|
||||
mov.SetRotation(gp_Ax1(origo, dir_axis2), M_PI);
|
||||
TopLoc_Location loc(mov);
|
||||
path.Move(loc);
|
||||
}
|
||||
|
||||
if (abs(startOffset) > 0) { // translate the helix so that the starting point aligns with the profile
|
||||
mov.SetTranslation(startOffset*gp_Vec(dir_axis1));
|
||||
mov.SetTranslation(startOffset * gp_Vec(dir_axis1));
|
||||
TopLoc_Location loc(mov);
|
||||
path.Move(loc);
|
||||
}
|
||||
|
||||
if (turned) { // turn the helix so that the starting point aligns with the profile
|
||||
mov.SetRotation(gp_Ax1(origo, dir_axis1), PI);
|
||||
mov.SetRotation(gp_Ax1(origo, dir_axis1), M_PI);
|
||||
TopLoc_Location loc(mov);
|
||||
path.Move(loc);
|
||||
}
|
||||
@@ -472,7 +480,7 @@ double Helix::safePitch()
|
||||
// Below is an approximation. It is possible to do the general way by solving for the pitch
|
||||
// where the helix is self intersecting.
|
||||
|
||||
double angle = Angle.getValue()/180.0*PI;
|
||||
double angle = Angle.getValue() / 180.0 * M_PI;
|
||||
|
||||
TopoDS_Shape sketchshape = getVerifiedFace();
|
||||
Bnd_Box bb;
|
||||
@@ -483,15 +491,15 @@ double Helix::safePitch()
|
||||
|
||||
double X = Xmax - Xmin, Y = Ymax - Ymin, Z = Zmax - Zmin;
|
||||
|
||||
gp_Dir dir(v.x,v.y,v.z);
|
||||
gp_Dir dir(v.x, v.y, v.z);
|
||||
gp_Vec bbvec(X, Y, Z);
|
||||
|
||||
double p0 = bbvec*dir; // safe pitch if angle=0
|
||||
double p0 = bbvec * dir; // safe pitch if angle=0
|
||||
|
||||
gp_Dir dir_s(s.x, s.y, s.z);
|
||||
|
||||
if (tan(abs(angle))*p0 > abs(bbvec*dir_s))
|
||||
return abs(bbvec*dir_s)/tan(abs(angle));
|
||||
if (tan(abs(angle)) * p0 > abs(bbvec * dir_s))
|
||||
return abs(bbvec * dir_s) / tan(abs(angle));
|
||||
else
|
||||
return p0;
|
||||
}
|
||||
@@ -507,7 +515,7 @@ void Helix::proposeParameters(bool force)
|
||||
double pitch = 1.1 * sqrt(bb.SquareExtent());
|
||||
|
||||
Pitch.setValue(pitch);
|
||||
Height.setValue(pitch*3.0);
|
||||
Height.setValue(pitch * 3.0);
|
||||
HasBeenEdited.setValue(1);
|
||||
}
|
||||
}
|
||||
@@ -521,7 +529,7 @@ Base::Vector3d Helix::getProfileCenterPoint()
|
||||
box.SetGap(0.0);
|
||||
double xmin, ymin, zmin, xmax, ymax, zmax;
|
||||
box.Get(xmin, ymin, zmin, xmax, ymax, zmax);
|
||||
return Base::Vector3d(0.5*(xmin+xmax), 0.5*(ymin+ymax), 0.5*(zmin+zmax));
|
||||
return Base::Vector3d(0.5 * (xmin + xmax), 0.5 * (ymin + ymax), 0.5 * (zmin + zmax));
|
||||
}
|
||||
|
||||
void Helix::handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, App::Property* prop)
|
||||
|
||||
Reference in New Issue
Block a user