All: Reformat according to new standard

This commit is contained in:
pre-commit-ci[bot]
2025-11-11 13:49:01 +01:00
committed by Kacper Donat
parent ef997f2259
commit 9fe130cd73
2390 changed files with 154630 additions and 115818 deletions

View File

@@ -24,21 +24,21 @@
#include <FCConfig.h>
# include <Mod/Part/App/FCBRepAlgoAPI_Cut.h>
# include <BRepBuilderAPI_MakeFace.hxx>
# include <BRepBuilderAPI_MakeWire.hxx>
# include <BRepBuilderAPI_Sewing.hxx>
# include <BRepGProp.hxx>
# include <BRepOffsetAPI_MakeOffset.hxx>
# include <BRepOffsetAPI_ThruSections.hxx>
# include <BRepPrimAPI_MakePrism.hxx>
# include <gp_Ax1.hxx>
# include <gp_Dir.hxx>
# include <gp_Trsf.hxx>
# include <GProp_GProps.hxx>
# include <Precision.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
#include <Mod/Part/App/FCBRepAlgoAPI_Cut.h>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_Sewing.hxx>
#include <BRepGProp.hxx>
#include <BRepOffsetAPI_MakeOffset.hxx>
#include <BRepOffsetAPI_ThruSections.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <gp_Ax1.hxx>
#include <gp_Dir.hxx>
#include <gp_Trsf.hxx>
#include <GProp_GProps.hxx>
#include <Precision.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <Base/Console.h>
@@ -55,15 +55,17 @@ using namespace Part;
ExtrusionHelper::ExtrusionHelper() = default;
void ExtrusionHelper::makeDraft(const TopoDS_Shape& shape,
const gp_Dir& direction,
const double LengthFwd,
const double LengthRev,
const double AngleFwd,
const double AngleRev,
bool isSolid,
std::list<TopoDS_Shape>& drafts,
bool isPartDesign)
void ExtrusionHelper::makeDraft(
const TopoDS_Shape& shape,
const gp_Dir& direction,
const double LengthFwd,
const double LengthRev,
const double AngleFwd,
const double AngleRev,
bool isSolid,
std::list<TopoDS_Shape>& drafts,
bool isPartDesign
)
{
std::vector<std::vector<TopoDS_Shape>> wiresections;
@@ -89,13 +91,15 @@ void ExtrusionHelper::makeDraft(const TopoDS_Shape& shape,
// we can omit the source shape as loft section
bool bMid = !bFwd || !bRev || -1.0 * AngleFwd != AngleRev;
if (shape.IsNull())
if (shape.IsNull()) {
Standard_Failure::Raise("Not a valid shape");
}
// store all wires of the shape into an array
size_t numWires = addWiresToWireSections(wiresections);
if (numWires == 0)
if (numWires == 0) {
Standard_Failure::Raise("Extrusion: Input must not only consist if a vertex");
}
// to store the sections for the loft
std::list<TopoDS_Wire> list_of_sections;
@@ -103,7 +107,10 @@ void ExtrusionHelper::makeDraft(const TopoDS_Shape& shape,
// we need for all found wires an offset copy of them
// we store them in an array
TopoDS_Wire offsetWire;
std::vector<std::vector<TopoDS_Shape>> extrusionSections(wiresections.size(), std::vector<TopoDS_Shape>());
std::vector<std::vector<TopoDS_Shape>> extrusionSections(
wiresections.size(),
std::vector<TopoDS_Shape>()
);
size_t rows = 0;
int numEdges = 0;
@@ -120,8 +127,9 @@ void ExtrusionHelper::makeDraft(const TopoDS_Shape& shape,
BRepBuilderAPI_MakeFace mkFace(TopoDS::Wire(singleWire));
auto tempFace = mkFace.Shape();
BRepPrimAPI_MakePrism mkPrism(tempFace, vecFwd);
if (!mkPrism.IsDone())
if (!mkPrism.IsDone()) {
Standard_Failure::Raise("Extrusion: Generating prism failed");
}
singlePrism = mkPrism.Shape();
resultPrisms.push_back(singlePrism);
}
@@ -135,8 +143,9 @@ void ExtrusionHelper::makeDraft(const TopoDS_Shape& shape,
// count the number of inner wires
int numInnerWires = 0;
for (auto isInner : isInnerWire) {
if (isInner)
if (isInner) {
++numInnerWires;
}
}
// at first create offset wires for the reversed part of extrusion
@@ -159,16 +168,32 @@ void ExtrusionHelper::makeDraft(const TopoDS_Shape& shape,
createTaperedPrismOffset(TopoDS::Wire(singleWire), vecRev, distanceRev, true, offsetWire);
}
else {
// there is an OCC bug with single-edge wires (circles), see inside createTaperedPrismOffset
if (numEdges > 1 || !isPartDesign)
// there is an OCC bug with single-edge wires (circles), see inside
// createTaperedPrismOffset
if (numEdges > 1 || !isPartDesign) {
// inner wires must get the negated offset
createTaperedPrismOffset(TopoDS::Wire(singleWire), vecRev, -distanceRev, true, offsetWire);
else
createTaperedPrismOffset(
TopoDS::Wire(singleWire),
vecRev,
-distanceRev,
true,
offsetWire
);
}
else {
// circles in PartDesign must not get the negated offset
createTaperedPrismOffset(TopoDS::Wire(singleWire), vecRev, distanceRev, true, offsetWire);
createTaperedPrismOffset(
TopoDS::Wire(singleWire),
vecRev,
distanceRev,
true,
offsetWire
);
}
}
if (offsetWire.IsNull())
if (offsetWire.IsNull()) {
return;
}
extrusionSections[rows].push_back(offsetWire);
}
++rows;
@@ -204,19 +229,41 @@ void ExtrusionHelper::makeDraft(const TopoDS_Shape& shape,
// create an offset copy of the wire
if (!isInnerWire[rows]) {
// this is an outer wire
createTaperedPrismOffset(TopoDS::Wire(singleWire), vecFwd, distanceFwd, false, offsetWire);
createTaperedPrismOffset(
TopoDS::Wire(singleWire),
vecFwd,
distanceFwd,
false,
offsetWire
);
}
else {
// there is an OCC bug with single-edge wires (circles), see inside createTaperedPrismOffset
if (numEdges > 1 || !isPartDesign)
// there is an OCC bug with single-edge wires (circles), see inside
// createTaperedPrismOffset
if (numEdges > 1 || !isPartDesign) {
// inner wires must get the negated offset
createTaperedPrismOffset(TopoDS::Wire(singleWire), vecFwd, -distanceFwd, false, offsetWire);
else
createTaperedPrismOffset(
TopoDS::Wire(singleWire),
vecFwd,
-distanceFwd,
false,
offsetWire
);
}
else {
// circles in PartDesign must not get the negated offset
createTaperedPrismOffset(TopoDS::Wire(singleWire), vecFwd, distanceFwd, false, offsetWire);
createTaperedPrismOffset(
TopoDS::Wire(singleWire),
vecFwd,
distanceFwd,
false,
offsetWire
);
}
}
if (offsetWire.IsNull())
if (offsetWire.IsNull()) {
return;
}
extrusionSections[rows].push_back(offsetWire);
}
++rows;
@@ -231,14 +278,17 @@ void ExtrusionHelper::makeDraft(const TopoDS_Shape& shape,
BRepOffsetAPI_ThruSections mkTS(isSolid, /*ruled=*/Standard_True, Precision::Confusion());
for (auto& singleWire : wires) {
if (singleWire.ShapeType() == TopAbs_VERTEX)
if (singleWire.ShapeType() == TopAbs_VERTEX) {
mkTS.AddVertex(TopoDS::Vertex(singleWire));
else
}
else {
mkTS.AddWire(TopoDS::Wire(singleWire));
}
}
mkTS.Build();
if (!mkTS.IsDone())
if (!mkTS.IsDone()) {
Standard_Failure::Raise("Extrusion: Loft could not be built");
}
shells.push_back(mkTS.Shape());
}
@@ -246,8 +296,8 @@ void ExtrusionHelper::makeDraft(const TopoDS_Shape& shape,
if (isSolid) {
// we only need to cut if we have inner wires
if (numInnerWires > 0) {
// we take every outer wire prism and cut subsequently all inner wires prisms from it
// every resulting shape is the final drafted extrusion shape
// we take every outer wire prism and cut subsequently all inner wires prisms from
// it every resulting shape is the final drafted extrusion shape
GProp_GProps tempProperties;
Standard_Real momentOfInertiaInitial;
Standard_Real momentOfInertiaFinal;
@@ -266,17 +316,24 @@ void ExtrusionHelper::makeDraft(const TopoDS_Shape& shape,
}
// get MomentOfInertia of first shape
BRepGProp::VolumeProperties(*itOuter, tempProperties);
momentOfInertiaInitial = tempProperties.MomentOfInertia(gp_Ax1(gp_Pnt(), direction));
momentOfInertiaInitial = tempProperties.MomentOfInertia(
gp_Ax1(gp_Pnt(), direction)
);
FCBRepAlgoAPI_Cut mkCut(*itOuter, *itInner);
if (!mkCut.IsDone())
if (!mkCut.IsDone()) {
Standard_Failure::Raise("Extrusion: Final cut out failed");
}
BRepGProp::VolumeProperties(mkCut.Shape(), tempProperties);
momentOfInertiaFinal = tempProperties.MomentOfInertia(gp_Ax1(gp_Pnt(), direction));
// if the whole shape was cut away the resulting shape is not Null but its MomentOfInertia is 0.0
// therefore we have a valid cut if the MomentOfInertia is not zero and changed
momentOfInertiaFinal = tempProperties.MomentOfInertia(
gp_Ax1(gp_Pnt(), direction)
);
// if the whole shape was cut away the resulting shape is not Null but its
// MomentOfInertia is 0.0 therefore we have a valid cut if the
// MomentOfInertia is not zero and changed
if ((momentOfInertiaInitial != momentOfInertiaFinal)
&& (momentOfInertiaFinal > Precision::Confusion())) {
// immediately update the outer shape since more inner wire prism might cut it
// immediately update the outer shape since more inner wire prism might
// cut it
*itOuter = mkCut.Shape();
}
++isInnerWireIteratorLoop;
@@ -285,16 +342,19 @@ void ExtrusionHelper::makeDraft(const TopoDS_Shape& shape,
++isInnerWireIterator;
}
}
else
else {
// we already have the results
for (const auto & shell : shells)
for (const auto& shell : shells) {
drafts.push_back(shell);
}
}
}
else { // no solid
else { // no solid
BRepBuilderAPI_Sewing sewer;
sewer.SetTolerance(Precision::Confusion());
for (TopoDS_Shape& s : shells)
for (TopoDS_Shape& s : shells) {
sewer.Add(s);
}
sewer.Perform();
drafts.push_back(sewer.SewedShape());
}
@@ -310,14 +370,20 @@ void ExtrusionHelper::makeDraft(const TopoDS_Shape& shape,
}
}
void ExtrusionHelper::checkInnerWires(std::vector<bool>& isInnerWire, const gp_Dir direction,
std::vector<bool>&checklist, bool forInner, std::vector<TopoDS_Shape> prisms)
void ExtrusionHelper::checkInnerWires(
std::vector<bool>& isInnerWire,
const gp_Dir direction,
std::vector<bool>& checklist,
bool forInner,
std::vector<TopoDS_Shape> prisms
)
{
// store the number of wires to be checked
size_t numCheckWiresInitial = 0;
for (auto checks : checklist) {
if (checks)
if (checks) {
++numCheckWiresInitial;
}
}
GProp_GProps tempProperties;
Standard_Real momentOfInertiaInitial;
@@ -348,12 +414,13 @@ void ExtrusionHelper::checkInnerWires(std::vector<bool>& isInnerWire, const gp_D
BRepGProp::VolumeProperties(*itInner, tempProperties);
momentOfInertiaInitial = tempProperties.MomentOfInertia(gp_Ax1(gp_Pnt(), direction));
FCBRepAlgoAPI_Cut mkCut(*itInner, *itOuter);
if (!mkCut.IsDone())
if (!mkCut.IsDone()) {
Standard_Failure::Raise("Extrusion: Cut out failed");
}
BRepGProp::VolumeProperties(mkCut.Shape(), tempProperties);
momentOfInertiaFinal = tempProperties.MomentOfInertia(gp_Ax1(gp_Pnt(), direction));
// if the whole shape was cut away the resulting shape is not Null but its MomentOfInertia is 0.0
// therefore we have an inner wire if the MomentOfInertia is not zero and changed
// if the whole shape was cut away the resulting shape is not Null but its MomentOfInertia
// is 0.0 therefore we have an inner wire if the MomentOfInertia is not zero and changed
if ((momentOfInertiaInitial != momentOfInertiaFinal)
&& (momentOfInertiaFinal > Precision::Confusion())) {
*isInnerWireIterator = !forInner;
@@ -363,10 +430,11 @@ void ExtrusionHelper::checkInnerWires(std::vector<bool>& isInnerWire, const gp_D
}
++toCheckIteratorInner;
}
if (saveIsInnerWireIterator == *isInnerWireIterator)
if (saveIsInnerWireIterator == *isInnerWireIterator) {
// nothing was changed and we can remove it from the list to be checked
// but we cannot do this before the for loop was fully run
toDisable[outer] = true;
}
++isInnerWireIterator;
++toCheckIterator;
}
@@ -374,8 +442,9 @@ void ExtrusionHelper::checkInnerWires(std::vector<bool>& isInnerWire, const gp_D
// cancel prisms from the checklist whose wire state did not change
size_t i = 0;
for (auto disable : toDisable) {
if (disable)
if (disable) {
checklist[i] = false;
}
++i;
}
@@ -401,27 +470,34 @@ void ExtrusionHelper::checkInnerWires(std::vector<bool>& isInnerWire, const gp_D
}
++i;
}
Base::Console().warning("Extrusion: too many self-intersection structures!\n\
Base::Console().warning(
"Extrusion: too many self-intersection structures!\n\
Impossible to determine what structure is an inner one.\n\
All undeterminable structures will therefore be taken as outer ones.\n");
All undeterminable structures will therefore be taken as outer ones.\n"
);
}
// recursively call the function until all wires are checked
if (numCheckWires > 1)
if (numCheckWires > 1) {
checkInnerWires(isInnerWire, direction, checklist, !forInner, prisms);
}
}
void ExtrusionHelper::createTaperedPrismOffset(TopoDS_Wire sourceWire,
const gp_Vec& translation,
double offset,
bool isSecond,
TopoDS_Wire& result) {
void ExtrusionHelper::createTaperedPrismOffset(
TopoDS_Wire sourceWire,
const gp_Vec& translation,
double offset,
bool isSecond,
TopoDS_Wire& result
)
{
// if the wire consists of a single edge which has applied a placement
// then this placement must be reset because otherwise
// BRepOffsetAPI_MakeOffset shows weird behaviour by applying the placement, see
// https://dev.opencascade.org/content/brepoffsetapimakeoffset-wire-and-face-odd-occt-740
// therefore we use here the workaround of BRepOffsetAPI_MakeOffsetFix and not BRepOffsetAPI_MakeOffset
// therefore we use here the workaround of BRepOffsetAPI_MakeOffsetFix and not
// BRepOffsetAPI_MakeOffset
gp_Trsf tempTransform;
tempTransform.SetTranslation(translation);
@@ -451,12 +527,18 @@ void ExtrusionHelper::createTaperedPrismOffset(TopoDS_Wire sourceWire,
offsetShape = movedSourceWire;
}
if (offsetShape.IsNull()) {
if (isSecond)
Base::Console().error("Extrusion: end face of tapered against extrusion is empty\n" \
"This means most probably that the against taper angle is too large or small.\n");
else
Base::Console().error("Extrusion: end face of tapered along extrusion is empty\n" \
"This means most probably that the along taper angle is too large or small.\n");
if (isSecond) {
Base::Console().error(
"Extrusion: end face of tapered against extrusion is empty\n"
"This means most probably that the against taper angle is too large or small.\n"
);
}
else {
Base::Console().error(
"Extrusion: end face of tapered along extrusion is empty\n"
"This means most probably that the along taper angle is too large or small.\n"
);
}
Standard_Failure::Raise("Extrusion: end face of tapered extrusion is empty");
}
// assure we return a wire and no edge
@@ -471,22 +553,30 @@ void ExtrusionHelper::createTaperedPrismOffset(TopoDS_Wire sourceWire,
else {
// this happens usually if type == TopAbs_COMPOUND and means the angle is too small
// since this is a common mistake users will quickly do, issue a warning dialog
// FIXME: Standard_Failure::Raise or App::DocumentObjectExecReturn don't output the message to the user
// FIXME: Standard_Failure::Raise or App::DocumentObjectExecReturn don't output the message
// to the user
result = TopoDS_Wire();
if (isSecond)
Base::Console().error("Extrusion: type of against extrusion end face is not supported.\n" \
"This means most probably that the against taper angle is too large or small.\n");
else
Base::Console().error("Extrusion: type of along extrusion is not supported.\n" \
"This means most probably that the along taper angle is too large or small.\n");
if (isSecond) {
Base::Console().error(
"Extrusion: type of against extrusion end face is not supported.\n"
"This means most probably that the against taper angle is too large or small.\n"
);
}
else {
Base::Console().error(
"Extrusion: type of along extrusion is not supported.\n"
"This means most probably that the along taper angle is too large or small.\n"
);
}
}
}
void ExtrusionHelper::makeElementDraft(const ExtrusionParameters& params,
const TopoShape& _shape,
std::vector<TopoShape>& drafts,
App::StringHasherRef hasher)
void ExtrusionHelper::makeElementDraft(
const ExtrusionParameters& params,
const TopoShape& _shape,
std::vector<TopoShape>& drafts,
App::StringHasherRef hasher
)
{
double distanceFwd = tan(params.taperAngleFwd) * params.lengthFwd;
double distanceRev = tan(params.taperAngleRev) * params.lengthRev;
@@ -529,7 +619,8 @@ void ExtrusionHelper::makeElementDraft(const ExtrusionParameters& params,
innerWires.makeElementCompound(
wires,
"",
TopoShape::SingleShapeCompoundCreationPolicy::returnShape);
TopoShape::SingleShapeCompoundCreationPolicy::returnShape
);
makeElementDraft(params, innerWires, inner, hasher);
if (inner.empty()) {
Standard_Failure::Raise("Failed to make drafted extrusion with inner hole");
@@ -563,11 +654,13 @@ void ExtrusionHelper::makeElementDraft(const ExtrusionParameters& params,
std::vector<TopoShape> list_of_sections;
if (bRev) {
TopoDS_Wire offsetWire;
createTaperedPrismOffset(TopoDS::Wire(sourceWire.getShape()),
vecRev,
distanceRev,
false,
offsetWire);
createTaperedPrismOffset(
TopoDS::Wire(sourceWire.getShape()),
vecRev,
distanceRev,
false,
offsetWire
);
list_of_sections.push_back(TopoShape(offsetWire, sourceWire.Tag));
}
@@ -579,11 +672,13 @@ void ExtrusionHelper::makeElementDraft(const ExtrusionParameters& params,
// finally. Forward extrusion offset wire.
if (bFwd) {
TopoDS_Wire offsetWire;
createTaperedPrismOffset(TopoDS::Wire(sourceWire.getShape()),
vecFwd,
distanceFwd,
false,
offsetWire);
createTaperedPrismOffset(
TopoDS::Wire(sourceWire.getShape()),
vecFwd,
distanceFwd,
false,
offsetWire
);
list_of_sections.push_back(TopoShape(offsetWire, sourceWire.Tag));
}
@@ -593,8 +688,10 @@ void ExtrusionHelper::makeElementDraft(const ExtrusionParameters& params,
#endif
// make loft
BRepOffsetAPI_ThruSections mkGenerator(params.solid ? Standard_True : Standard_False,
/*ruled=*/Standard_True);
BRepOffsetAPI_ThruSections mkGenerator(
params.solid ? Standard_True : Standard_False,
/*ruled=*/Standard_True
);
for (auto& s : list_of_sections) {
mkGenerator.AddWire(TopoDS::Wire(s.getShape()));
}