[Part] Extrusion: just style fixes

to keep following PR diffs small

all changes were automatically done by MSVC
This commit is contained in:
Uwe
2022-01-20 01:08:35 +01:00
parent 0019726cd8
commit 9c828d6efd
2 changed files with 63 additions and 60 deletions

View File

@@ -56,27 +56,27 @@ using namespace Part;
PROPERTY_SOURCE(Part::Extrusion, Part::Feature)
const char* Extrusion::eDirModeStrings[]= {
const char* Extrusion::eDirModeStrings[] = {
"Custom",
"Edge",
"Normal",
NULL};
NULL };
Extrusion::Extrusion()
{
ADD_PROPERTY_TYPE(Base,(0), "Extrude", App::Prop_None, "Shape to extrude");
ADD_PROPERTY_TYPE(Dir,(Base::Vector3d(0.0,0.0,1.0)), "Extrude", App::Prop_None, "Direction of extrusion (also magnitude, if both lengths are zero).");
ADD_PROPERTY_TYPE(Base, (0), "Extrude", App::Prop_None, "Shape to extrude");
ADD_PROPERTY_TYPE(Dir, (Base::Vector3d(0.0, 0.0, 1.0)), "Extrude", App::Prop_None, "Direction of extrusion (also magnitude, if both lengths are zero).");
ADD_PROPERTY_TYPE(DirMode, (dmCustom), "Extrude", App::Prop_None, "Sets, how Dir is updated.");
DirMode.setEnums(eDirModeStrings);
ADD_PROPERTY_TYPE(DirLink,(nullptr), "Extrude", App::Prop_None, "Link to edge defining extrusion direction.");
ADD_PROPERTY_TYPE(LengthFwd,(0.0), "Extrude", App::Prop_None, "Length of extrusion along direction. If both LengthFwd and LengthRev are zero, magnitude of Dir is used.");
ADD_PROPERTY_TYPE(LengthRev,(0.0), "Extrude", App::Prop_None, "Length of additional extrusion, against direction.");
ADD_PROPERTY_TYPE(Solid,(false), "Extrude", App::Prop_None, "If true, extruding a wire yields a solid. If false, a shell.");
ADD_PROPERTY_TYPE(Reversed,(false), "Extrude", App::Prop_None, "Set to true to swap the direction of extrusion.");
ADD_PROPERTY_TYPE(Symmetric,(false), "Extrude", App::Prop_None, "If true, extrusion is done in both directions to a total of LengthFwd. LengthRev is ignored.");
ADD_PROPERTY_TYPE(TaperAngle,(0.0), "Extrude", App::Prop_None, "Sets the angle of slope (draft) to apply to the sides. The angle is for outward taper; negative value yields inward tapering.");
ADD_PROPERTY_TYPE(TaperAngleRev,(0.0), "Extrude", App::Prop_None, "Taper angle of reverse part of extrusion.");
ADD_PROPERTY_TYPE(FaceMakerClass,("Part::FaceMakerExtrusion"), "Extrude", App::Prop_None, "If Solid is true, this sets the facemaker class to use when converting wires to faces. Otherwise, ignored."); //default for old documents. See setupObject for default for new extrusions.
ADD_PROPERTY_TYPE(DirLink, (nullptr), "Extrude", App::Prop_None, "Link to edge defining extrusion direction.");
ADD_PROPERTY_TYPE(LengthFwd, (0.0), "Extrude", App::Prop_None, "Length of extrusion along direction. If both LengthFwd and LengthRev are zero, magnitude of Dir is used.");
ADD_PROPERTY_TYPE(LengthRev, (0.0), "Extrude", App::Prop_None, "Length of additional extrusion, against direction.");
ADD_PROPERTY_TYPE(Solid, (false), "Extrude", App::Prop_None, "If true, extruding a wire yields a solid. If false, a shell.");
ADD_PROPERTY_TYPE(Reversed, (false), "Extrude", App::Prop_None, "Set to true to swap the direction of extrusion.");
ADD_PROPERTY_TYPE(Symmetric, (false), "Extrude", App::Prop_None, "If true, extrusion is done in both directions to a total of LengthFwd. LengthRev is ignored.");
ADD_PROPERTY_TYPE(TaperAngle, (0.0), "Extrude", App::Prop_None, "Sets the angle of slope (draft) to apply to the sides. The angle is for outward taper; negative value yields inward tapering.");
ADD_PROPERTY_TYPE(TaperAngleRev, (0.0), "Extrude", App::Prop_None, "Taper angle of reverse part of extrusion.");
ADD_PROPERTY_TYPE(FaceMakerClass, ("Part::FaceMakerExtrusion"), "Extrude", App::Prop_None, "If Solid is true, this sets the facemaker class to use when converting wires to faces. Otherwise, ignored."); //default for old documents. See setupObject for default for new extrusions.
}
short Extrusion::mustExecute() const
@@ -105,9 +105,10 @@ bool Extrusion::fetchAxisLink(const App::PropertyLinkSub& axisLink, Base::Vector
auto linked = axisLink.getValue();
TopoDS_Shape axEdge;
if (axisLink.getSubValues().size() > 0 && axisLink.getSubValues()[0].length() > 0){
if (axisLink.getSubValues().size() > 0 && axisLink.getSubValues()[0].length() > 0) {
axEdge = Feature::getTopoShape(linked).getSubShape(axisLink.getSubValues()[0].c_str());
} else {
}
else {
axEdge = Feature::getShape(linked);
}
@@ -119,12 +120,13 @@ bool Extrusion::fetchAxisLink(const App::PropertyLinkSub& axisLink, Base::Vector
BRepAdaptor_Curve crv(TopoDS::Edge(axEdge));
gp_Pnt startpoint;
gp_Pnt endpoint;
if (crv.GetType() == GeomAbs_Line){
if (crv.GetType() == GeomAbs_Line) {
startpoint = crv.Value(crv.FirstParameter());
endpoint = crv.Value(crv.LastParameter());
if (axEdge.Orientation() == TopAbs_REVERSED)
std::swap(startpoint, endpoint);
} else {
}
else {
throw Base::TypeError("DirLink edge is not a line.");
}
basepoint.Set(startpoint.X(), startpoint.Y(), startpoint.Z());
@@ -137,26 +139,26 @@ Extrusion::ExtrusionParameters Extrusion::computeFinalParameters()
{
Extrusion::ExtrusionParameters result;
Base::Vector3d dir;
switch(this->DirMode.getValue()){
case dmCustom:
dir = this->Dir.getValue();
switch (this->DirMode.getValue()) {
case dmCustom:
dir = this->Dir.getValue();
break;
case dmEdge:{
bool fetched;
Base::Vector3d base;
fetched = fetchAxisLink(this->DirLink, base, dir);
if (!fetched)
throw Base::ValueError("DirMode is set to use edge, but no edge is linked.");
this->Dir.setValue(dir);
}break;
case dmNormal:
dir = calculateShapeNormal(this->Base);
this->Dir.setValue(dir);
case dmEdge: {
bool fetched;
Base::Vector3d base;
fetched = fetchAxisLink(this->DirLink, base, dir);
if (!fetched)
throw Base::ValueError("DirMode is set to use edge, but no edge is linked.");
this->Dir.setValue(dir);
} break;
case dmNormal:
dir = calculateShapeNormal(this->Base);
this->Dir.setValue(dir);
break;
default:
throw Base::ValueError("Unexpected enum value");
default:
throw Base::ValueError("Unexpected enum value");
}
if(dir.Length() < Precision::Confusion())
if (dir.Length() < Precision::Confusion())
throw Base::ValueError("Direction is zero-length");
result.dir = gp_Dir(dir.x, dir.y, dir.z);
if (this->Reversed.getValue())
@@ -164,12 +166,12 @@ Extrusion::ExtrusionParameters Extrusion::computeFinalParameters()
result.lengthFwd = this->LengthFwd.getValue();
result.lengthRev = this->LengthRev.getValue();
if(fabs(result.lengthFwd) < Precision::Confusion()
&& fabs(result.lengthRev) < Precision::Confusion() ){
if (fabs(result.lengthFwd) < Precision::Confusion()
&& fabs(result.lengthRev) < Precision::Confusion()) {
result.lengthFwd = dir.Length();
}
if (this->Symmetric.getValue()){
if (this->Symmetric.getValue()) {
result.lengthRev = result.lengthFwd * 0.5;
result.lengthFwd = result.lengthFwd * 0.5;
}
@@ -180,10 +182,10 @@ Extrusion::ExtrusionParameters Extrusion::computeFinalParameters()
result.solid = this->Solid.getValue();
result.taperAngleFwd = this->TaperAngle.getValue() * M_PI / 180.0;
if (fabs(result.taperAngleFwd) > M_PI * 0.5 - Precision::Angular() )
if (fabs(result.taperAngleFwd) > M_PI * 0.5 - Precision::Angular())
throw Base::ValueError("Magnitude of taper angle matches or exceeds 90 degrees. That is too much.");
result.taperAngleRev = this->TaperAngleRev.getValue() * M_PI / 180.0;
if (fabs(result.taperAngleRev) > M_PI * 0.5 - Precision::Angular() )
if (fabs(result.taperAngleRev) > M_PI * 0.5 - Precision::Angular())
throw Base::ValueError("Magnitude of taper angle matches or exceeds 90 degrees. That is too much.");
result.faceMakerClass = this->FaceMakerClass.getValue();
@@ -195,14 +197,14 @@ Base::Vector3d Extrusion::calculateShapeNormal(const App::PropertyLink& shapeLin
{
App::DocumentObject* docobj = 0;
Base::Matrix4D mat;
TopoDS_Shape sh = Feature::getShape(shapeLink.getValue(),0,false, &mat,&docobj);
TopoDS_Shape sh = Feature::getShape(shapeLink.getValue(), 0, false, &mat, &docobj);
if (!docobj)
throw Base::ValueError("calculateShapeNormal: link is empty");
//special case for sketches and the like: no matter what shape they have, use their local Z axis.
if (docobj->isDerivedFrom(Part::Part2DObject::getClassTypeId())){
Base::Vector3d OZ (0.0, 0.0, 1.0);
if (docobj->isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
Base::Vector3d OZ(0.0, 0.0, 1.0);
Base::Vector3d result;
Base::Rotation(mat).multVec(OZ, result);
return result;
@@ -213,7 +215,7 @@ Base::Vector3d Extrusion::calculateShapeNormal(const App::PropertyLink& shapeLin
//find plane
BRepLib_FindSurface planeFinder(sh, -1, /*OnlyPlane=*/true);
if (! planeFinder.Found())
if (!planeFinder.Found())
throw Base::ValueError("Can't find normal direction, because the shape is not on a plane.");
//find plane normal and return result.
@@ -224,10 +226,10 @@ Base::Vector3d Extrusion::calculateShapeNormal(const App::PropertyLink& shapeLin
//plane normal direction is not dependent on face orientation (because findPlane only uses edges).
//let's fix that.
TopExp_Explorer ex(sh, TopAbs_FACE);
if(ex.More()) {
if (ex.More()) {
BRepAdaptor_Surface surf(TopoDS::Face(ex.Current()));
normal = surf.Plane().Axis().Direction();
if (ex.Current().Orientation() == TopAbs_REVERSED){
if (ex.Current().Orientation() == TopAbs_REVERSED) {
normal.Reverse();
}
}
@@ -238,10 +240,10 @@ Base::Vector3d Extrusion::calculateShapeNormal(const App::PropertyLink& shapeLin
TopoShape Extrusion::extrudeShape(const TopoShape& source, const Extrusion::ExtrusionParameters& params)
{
TopoDS_Shape result;
gp_Vec vec = gp_Vec(params.dir).Multiplied(params.lengthFwd+params.lengthRev);//total vector of extrusion
gp_Vec vec = gp_Vec(params.dir).Multiplied(params.lengthFwd + params.lengthRev);//total vector of extrusion
if (std::fabs(params.taperAngleFwd) >= Precision::Angular() ||
std::fabs(params.taperAngleRev) >= Precision::Angular() ) {
std::fabs(params.taperAngleRev) >= Precision::Angular()) {
//Tapered extrusion!
#if defined(__GNUC__) && defined (FC_OS_LINUX)
Base::SignalException se;
@@ -279,9 +281,9 @@ TopoShape Extrusion::extrudeShape(const TopoShape& source, const Extrusion::Extr
myShape = BRepBuilderAPI_Copy(myShape).Shape();
//apply reverse part of extrusion by shifting the source shape
if (fabs(params.lengthRev)>Precision::Confusion() ){
if (fabs(params.lengthRev) > Precision::Confusion()) {
gp_Trsf mov;
mov.SetTranslation(gp_Vec(params.dir)*(-params.lengthRev));
mov.SetTranslation(gp_Vec(params.dir) * (-params.lengthRev));
TopLoc_Location loc(mov);
myShape.Move(loc);
}
@@ -290,9 +292,10 @@ TopoShape Extrusion::extrudeShape(const TopoShape& source, const Extrusion::Extr
if (params.solid) {
//test if we need to make faces from wires. If there are faces - we don't.
TopExp_Explorer xp(myShape, TopAbs_FACE);
if (xp.More()){
if (xp.More()) {
//source shape has faces. Just extrude as-is.
} else {
}
else {
std::unique_ptr<FaceMaker> mkFace = FaceMaker::ConstructFromType(params.faceMakerClass.c_str());
if (myShape.ShapeType() == TopAbs_COMPOUND)
@@ -315,7 +318,7 @@ TopoShape Extrusion::extrudeShape(const TopoShape& source, const Extrusion::Extr
}
App::DocumentObjectExecReturn *Extrusion::execute(void)
App::DocumentObjectExecReturn* Extrusion::execute(void)
{
App::DocumentObject* link = Base.getValue();
if (!link)
@@ -323,7 +326,7 @@ App::DocumentObjectExecReturn *Extrusion::execute(void)
try {
Extrusion::ExtrusionParameters params = computeFinalParameters();
TopoShape result = extrudeShape(Feature::getShape(link),params);
TopoShape result = extrudeShape(Feature::getShape(link), params);
this->Shape.setValue(result);
return App::DocumentObject::StdReturn;
}
@@ -464,7 +467,7 @@ void Extrusion::makeDraft(const ExtrusionParameters& params, const TopoDS_Shape&
//make loft
BRepOffsetAPI_ThruSections mkGenerator(params.solid ? Standard_True : Standard_False, /*ruled=*/Standard_True);
for (std::list<TopoDS_Wire>::const_iterator it = list_of_sections.begin(); it != list_of_sections.end(); ++it) {
const TopoDS_Wire &wire = *it;
const TopoDS_Wire& wire = *it;
mkGenerator.AddWire(wire);
}
@@ -542,9 +545,9 @@ void FaceMakerExtrusion::Build()
if (!wires.empty()) {
//try {
TopoDS_Shape res = FaceMakerCheese::makeFace(wires);
if (!res.IsNull())
this->myShape = res;
TopoDS_Shape res = FaceMakerCheese::makeFace(wires);
if (!res.IsNull())
this->myShape = res;
//}
//catch (...) {

View File

@@ -100,8 +100,8 @@ public:
* link is wrong.
*/
static bool fetchAxisLink(const App::PropertyLinkSub& axisLink,
Base::Vector3d &basepoint,
Base::Vector3d &dir);
Base::Vector3d& basepoint,
Base::Vector3d& dir);
/**
* @brief computeFinalParameters: applies mode logic and fetches links, to
@@ -110,7 +110,7 @@ public:
*/
ExtrusionParameters computeFinalParameters();
static Base::Vector3d calculateShapeNormal(const App::PropertyLink &shapeLink);
static Base::Vector3d calculateShapeNormal(const App::PropertyLink& shapeLink);
public: //mode enumerations
enum eDirMode{