-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include <BRepBuilderAPI_Sewing.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <BRepGProp.hxx>
+#include <GeomFill_Trihedron.hxx>
+#include <GeomFill_CorrectedFrenet.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
#include <BRepOffsetAPI_MakePipeShell.hxx>
#include <Geom_Conic.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_BSplineSurface.hxx>
+#include <GeomAdaptor_HCurve.hxx>
#include <GeomFill_BSplineCurves.hxx>
#include <GeomConvert_ApproxCurve.hxx>
#include <GeomConvert.hxx>
{
}
+//=======================================================================
+//function : EvaluateBestSweepMode
+//purpose : auxilary for right call of MakePipe and MakePipeShell
+//=======================================================================
+static GeomFill_Trihedron EvaluateBestSweepMode(const TopoDS_Shape& Spine)
+{
+ GeomFill_Trihedron theMode = GeomFill_IsFrenet;
+
+ TopExp_Explorer Explo(Spine, TopAbs_EDGE);
+ for (; Explo.More(); Explo.Next())
+ {
+ TopoDS_Edge anEdge = TopoDS::Edge(Explo.Current());
+ Standard_Real fpar, lpar;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, fpar, lpar);
+ GeomAdaptor_Curve GAcurve(aCurve, fpar, lpar);
+ Handle(GeomAdaptor_HCurve) GAHcurve = new GeomAdaptor_HCurve(GAcurve);
+
+ Handle(GeomFill_CorrectedFrenet) aCorrFrenet = new GeomFill_CorrectedFrenet(Standard_True); //for evaluation
+ aCorrFrenet->SetCurve(GAHcurve);
+ GeomFill_Trihedron aMode = aCorrFrenet->EvaluateBestMode();
+ if (aMode == GeomFill_IsDiscreteTrihedron)
+ {
+ theMode = aMode;
+ break;
+ }
+ if (aMode == GeomFill_IsCorrectedFrenet)
+ theMode = aMode;
+ }
+
+ return theMode;
+}
+
+//=======================================================================
+//function : BuildPipeShell
+//purpose : Builds a pipe shell. If failed, try to build in Descrete Trihedron
+// mode. Returns Standard_True if the building is done successfully.
+//=======================================================================
+static Standard_Boolean BuildPipeShell(BRepOffsetAPI_MakePipeShell &theBuilder)
+{
+ theBuilder.Build();
+
+ Standard_Boolean isDone = theBuilder.IsDone();
+
+ if (!isDone) {
+ // Try to use Descrete Trihedron mode.
+ theBuilder.SetDiscreteMode();
+ theBuilder.Build();
+ isDone = theBuilder.IsDone();
+ }
+
+ return isDone;
+}
+
//=======================================================================
//function : FillForOtherEdges
//purpose : auxilary for CreatePipeForShellSections()
TopExp_Explorer expw2(FS2,TopAbs_WIRE);
TopoDS_Wire aWire2 = TopoDS::Wire(expw2.Current());
BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
+ GeomFill_Trihedron theBestMode = EvaluateBestSweepMode(aWirePath);
+ if (theBestMode == GeomFill_IsDiscreteTrihedron)
+ aBuilder.SetDiscreteMode();
aBuilder.Add(aWire1, aLoc1);
aBuilder.Add(aWire2, aLoc2);
if (!aBuilder.IsReady()) {
return false;
}
- aBuilder.Build();
+
+ BuildPipeShell(aBuilder);
+
TopoDS_Shape aShape = aBuilder.Shape();
/*
TopoDS_Compound C;
TopTools_SequenceOfShape aSeqBases;
TopTools_SequenceOfShape aSeqLocs;
TopTools_SequenceOfShape aSeqFaces;
+ Standard_Boolean NeedCreateSolid = Standard_False;
Standard_Integer i = 1;
for (i = 1; i <= nbBases; i++) {
//if for section was specified face with a few wires then a few
// pipes were build and make solid
- Standard_Boolean NeedCreateSolid = Standard_False;
if (aTypeBase == TopAbs_SHELL) {
// create wire as boundary contour if shell is no closed
// get free boundary shapes
// and seguences of shapes, perform pipe for each
// and make sewing after that
double fp,lp;
- Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(Edges.Value(1)),fp,lp);
gp_Pnt P1,P2;
gp_Vec Vec1,Vec2;
- C->D1(fp,P1,Vec1);
- C->D1(lp,P2,Vec2);
- double SumAng = fabs(Vec1.Angle(Vec2));
- Vec1 = Vec2;
- P1 = P2;
+ double SumAng = 0;
+ if ( Edges.Length() > 0 ) {
+ Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(Edges.Value(1)),fp,lp);
+ C->D1(fp,P1,Vec1);
+ C->D1(lp,P2,Vec2);
+ SumAng = fabs(Vec1.Angle(Vec2));
+ Vec1 = Vec2;
+ P1 = P2;
+ }
TColStd_SequenceOfInteger SplitEdgeNums,SplitLocNums;
int LastLoc = 1;
//cout<<"Edges.Length()="<<Edges.Length()<<endl;
num2 = SplitLocNums.Value(nn);
// make pipe
BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
+ GeomFill_Trihedron theBestMode = EvaluateBestSweepMode(tmpW);
+ if (theBestMode == GeomFill_IsDiscreteTrihedron)
+ aBuilder.SetDiscreteMode();
Standard_Integer nbShapes = aTmpSeqBases.Length();
for (i=1; i<=nbShapes; i++) {
TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
if (!aBuilder.IsReady()) {
Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
}
- aBuilder.Build();
+
+ BuildPipeShell(aBuilder);
+
TopoDS_Shape resShape = aBuilder.Shape();
aSeqRes.Append(resShape);
}
}
// make pipe for last part
BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
+ GeomFill_Trihedron theBestMode = EvaluateBestSweepMode(tmpW);
+ if (theBestMode == GeomFill_IsDiscreteTrihedron)
+ aBuilder.SetDiscreteMode();
Standard_Integer nbShapes = aTmpSeqBases.Length();
for (i=1; i<=nbShapes; i++) {
TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
if (!aBuilder.IsReady()) {
Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
}
- aBuilder.Build();
+
+ BuildPipeShell(aBuilder);
+
TopoDS_Shape resShape = aBuilder.Shape();
aSeqRes.Append(resShape);
// make sewing for result
else {
// old implementation without splitting
BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
+ GeomFill_Trihedron theBestMode = EvaluateBestSweepMode(aWirePath);
+ if (theBestMode == GeomFill_IsDiscreteTrihedron)
+ aBuilder.SetDiscreteMode();
Standard_Integer nbShapes = aSeqBases.Length();
Standard_Integer step = nbShapes/nbBases;
aBuilder.SetTolerance(aTolConf, aTolConf, aTolAng);
- aBuilder.Build();
+ Standard_Boolean isDone = BuildPipeShell(aBuilder);
+
+ if (isDone && NeedCreateSolid) {
+ isDone = aBuilder.MakeSolid();
+ }
+
+ if (!isDone) {
+ Standard_ConstructionError::Raise("Pipe construction failure");
+ }
aShape = aBuilder.Shape();
aSeqFaces.Append(aShape);
for (j = 1; j <=usedBases.Length(); j++)
aBuilder.Delete(usedBases.Value(j));
}
-
- //for case if section is face
- if (aSeqFaces.Length() >1) {
- BRep_Builder aB;
- TopoDS_Compound aComp;
- aB.MakeCompound(aComp);
- for (i = 1; i <= aSeqFaces.Length(); i++)
- aB.Add(aComp,aSeqFaces.Value(i));
- aShape = aComp;
- }
}
return aShape;
if (!aWire1.IsNull() && !aWire2.IsNull()) {
//BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
BRepOffsetAPI_MakePipeShell aBuilder(WPath);
+ GeomFill_Trihedron theBestMode = EvaluateBestSweepMode(WPath);
+ if (theBestMode == GeomFill_IsDiscreteTrihedron)
+ aBuilder.SetDiscreteMode();
aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
aWithContact, aWithCorrect);
aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
if (aCI) delete aCI;
Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
}
- aBuilder.Build();
+
+ BuildPipeShell(aBuilder);
+
TopoDS_Shape aShape = aBuilder.Shape();
TopoDS_Shell aShell;
B.MakeShell(aShell);
// make pipe using aWire1 and aWire2
if (!aWire1.IsNull() && !aWire2.IsNull()) {
BRepOffsetAPI_MakePipeShell aBuilder(WPath);
+ GeomFill_Trihedron theBestMode = EvaluateBestSweepMode(WPath);
+ if (theBestMode == GeomFill_IsDiscreteTrihedron)
+ aBuilder.SetDiscreteMode();
aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
aWithContact, aWithCorrect);
aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
if (aCI) delete aCI;
Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
}
- aBuilder.Build();
+
+ BuildPipeShell(aBuilder);
+
TopoDS_Shape aShape = aBuilder.Shape();
TopoDS_Shell aShell;
B.MakeShell(aShell);
gp_Vec aVec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
gp_Dir BiNormal(aVec);
PipeBuilder.SetMode(BiNormal);
- PipeBuilder.Build();
- if (aShapeBase.ShapeType() == TopAbs_FACE) {
+
+ Standard_Boolean isDone = BuildPipeShell(PipeBuilder);
+
+ if (isDone && aShapeBase.ShapeType() == TopAbs_FACE) {
PipeBuilder.MakeSolid();
}
if (FaceBuilder.IsDone())
Sweep.SetMode(FaceBuilder.Face());
Sweep.Add(Profile);
- Sweep.Build();
-
- if (!Sweep.IsDone())
+
+ Standard_Boolean isDone = BuildPipeShell(Sweep);
+
+ if (!isDone)
{
if (aCI) delete aCI;
Standard_ConstructionError::Raise("MakePipeShell failed");
}
else
- aShape = BRepOffsetAPI_MakePipe(aWirePath, aShapeBase);
+ {
+ GeomFill_Trihedron theBestMode = EvaluateBestSweepMode(aWirePath);
+ BRepOffsetAPI_MakePipe aMkPipe(aWirePath, aShapeBase, theBestMode);
+
+ if (aMkPipe.IsDone()) {
+ aShape = aMkPipe.Shape();
+ } else if (theBestMode != GeomFill_IsDiscreteTrihedron) {
+ // Try to use Descrete Trihedron mode.
+ BRepOffsetAPI_MakePipe aMkPipeDescrete
+ (aWirePath, aShapeBase, GeomFill_IsDiscreteTrihedron);
+
+ if (aMkPipeDescrete.IsDone()) {
+ aShape = aMkPipeDescrete.Shape();
+ }
+ }
+ }
}
//building pipe with different sections