Add function to Close Part.Loft (Gui & scripting)

This commit is contained in:
WandererFan
2014-04-07 15:50:18 -04:00
committed by wmayer
parent 9affb1886a
commit 113e6026e4
7 changed files with 77 additions and 19 deletions

View File

@@ -74,6 +74,7 @@
# include <BRepTools.hxx>
# include <BRepTools_ReShape.hxx>
# include <BRepTools_ShapeSet.hxx>
#include <BRepFill_CompatibleWires.hxx>
# include <GCE2d_MakeSegment.hxx>
# include <Geom2d_Line.hxx>
# include <Geom2d_TrimmedCurve.hxx>
@@ -154,6 +155,8 @@
#include <Base/FileInfo.h>
#include <Base/Exception.h>
#include <Base/Tools.h>
#include <Base/Console.h>
#include "TopoShape.h"
#include "CrossSection.h"
@@ -1788,13 +1791,14 @@ TopoDS_Shape TopoShape::makeThread(Standard_Real pitch,
TopoDS_Shape TopoShape::makeLoft(const TopTools_ListOfShape& profiles,
Standard_Boolean isSolid,
Standard_Boolean isRuled) const
Standard_Boolean isRuled,
Standard_Boolean isClosed) const
{
// http://opencascade.blogspot.com/2010/01/surface-modeling-part5.html
BRepOffsetAPI_ThruSections aGenerator (isSolid,isRuled);
int countShapes = 0;
TopTools_ListIteratorOfListOfShape it;
int countShapes = 0;
for (it.Initialize(profiles); it.More(); it.Next()) {
const TopoDS_Shape& item = it.Value();
if (!item.IsNull() && item.ShapeType() == TopAbs_VERTEX) {
@@ -1812,15 +1816,44 @@ TopoDS_Shape TopoShape::makeLoft(const TopTools_ListOfShape& profiles,
}
}
if (countShapes < 2)
Standard_Failure::Raise("Need at least two vertices, edges or wires to create loft face");
if (countShapes < 2) {
Standard_Failure::Raise("Need at least two vertices, edges or wires to create loft face"); }
else {
// close loft by duplicating initial profile as last profile. not perfect.
if (isClosed) {
/* can only close loft in certain combinations of Vertex/Wire(Edge):
- V1-W1-W2-W3-V2 ==> V1-W1-W2-W3-V2-V1 invalid closed
- V1-W1-W2-W3 ==> V1-W1-W2-W3-V1 valid closed
- W1-W2-W3-V1 ==> W1-W2-W3-V1-W1 invalid closed
- W1-W2-W3 ==> W1-W2-W3-W1 valid closed*/
if (profiles.Last().ShapeType() == TopAbs_VERTEX) {
Base::Console().Message("TopoShape::makeLoft: can't close Loft with Vertex as last profile. 'Closed' ignored.\n"); }
else {
// repeat Add logic above for first profile
const TopoDS_Shape& firstProfile = profiles.First();
if (firstProfile.ShapeType() == TopAbs_VERTEX) {
aGenerator.AddVertex(TopoDS::Vertex (firstProfile));
countShapes++;
}
else if (firstProfile.ShapeType() == TopAbs_EDGE) {
aGenerator.AddWire(TopoDS::Wire (firstProfile));
countShapes++;
}
else if (firstProfile.ShapeType() == TopAbs_WIRE) {
aGenerator.AddWire(TopoDS::Wire (firstProfile));
countShapes++;
}
}
}
}
Standard_Boolean anIsCheck = Standard_True;
aGenerator.CheckCompatibility (anIsCheck);
aGenerator.CheckCompatibility (anIsCheck); // use BRepFill_CompatibleWires on profiles. force #edges, orientation, "origin" to match.
aGenerator.Build();
if (!aGenerator.IsDone())
Standard_Failure::Raise("Failed to create loft face");
//Base::Console().Message("DEBUG: TopoShape::makeLoft returns.\n");
return aGenerator.Shape();
}