Loading files
3d097a032This file is pinned to the selected release. Download the original to open it in your design tool.
// Created on: 1997-10-08
// Created by: Olga KOULECHOVA
// Copyright (c) 1997-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BRep_Builder.hxx>
#include <BRepAlgo.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepBndLib.hxx>
#include <BRepClass3d_SolidClassifier.hxx>
#include <BRepFeat.hxx>
#include <BRepFeat_Builder.hxx>
#include <BRepFeat_RibSlot.hxx>
#include <BRepIntCurveSurface_Inter.hxx>
#include <BRepLib.hxx>
#include <BRepLib_MakeEdge.hxx>
#include <BRepLib_MakeFace.hxx>
#include <BRepLib_MakeVertex.hxx>
#include <BRepLib_MakeWire.hxx>
#include <BRepTools_WireExplorer.hxx>
#include <BRepTopAdaptor_FClass2d.hxx>
#include <CSLib.hxx>
#include <ElCLib.hxx>
#include <ElSLib.hxx>
#include <Geom2dAPI_InterCurveCurve.hxx>
#include <Geom_Circle.hxx>
#include <Geom_Curve.hxx>
#include <Geom_Ellipse.hxx>
#include <Geom_Hyperbola.hxx>
#include <Geom_Line.hxx>
#include <Geom_Parabola.hxx>
#include <Geom_Plane.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <GeomAPI.hxx>
#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <GeomLib.hxx>
#include <gp_Ax1.hxx>
#include <gp_Dir.hxx>
#include <gp_Pln.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <LocOpe.hxx>
#include <LocOpe_CSIntersector.hxx>
#include <LocOpe_FindEdges.hxx>
#include <LocOpe_Gluer.hxx>
#include <LocOpe_PntFace.hxx>
#include <Precision.hxx>
#include <NCollection_Sequence.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
#include <NCollection_List.hxx>
#include <TopTools_ShapeMapHasher.hxx>
#include <NCollection_Map.hxx>
//=======================================================================
// function : LFPerform
// purpose : topological reconstruction of ribs
//=======================================================================
void BRepFeat_RibSlot::LFPerform()
{
if (mySbase.IsNull() || myPbase.IsNull() || mySkface.IsNull() || myGShape.IsNull()
|| myLFMap.IsEmpty())
{
myStatusError = BRepFeat_NotInitialized;
NotDone();
return;
}
TopExp_Explorer exp, exp2;
int theOpe = 2;
if (!myGluedF.IsEmpty())
{
theOpe = 1;
}
// Hope that there is just a solid in the result
if (!mySUntil.IsNull())
{
for (exp2.Init(mySUntil, TopAbs_FACE); exp2.More(); exp2.Next())
{
const TopoDS_Shape& funtil = exp2.Current();
for (exp.Init(mySbase, TopAbs_FACE); exp.More(); exp.Next())
{
if (exp.Current().IsSame(funtil))
{
break;
}
}
if (!exp.More())
{
break;
}
}
}
NCollection_List<TopoDS_Shape>::Iterator it, it2;
NCollection_DataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>::Iterator itm;
// int sens = 0;
LocOpe_Gluer theGlue;
// case of gluing
if (theOpe == 1)
{
bool Collage = true;
LocOpe_FindEdges theFE;
NCollection_DataMap<TopoDS_Shape, NCollection_List<TopoDS_Shape>, TopTools_ShapeMapHasher>
locmap;
theGlue.Init(mySbase, myGShape);
for (itm.Initialize(myGluedF); itm.More(); itm.Next())
{
const TopoDS_Face& glface = TopoDS::Face(itm.Key());
const TopoDS_Face& fac = TopoDS::Face(myGluedF(glface));
for (exp.Init(myGShape, TopAbs_FACE); exp.More(); exp.Next())
{
if (exp.Current().IsSame(glface))
{
break;
}
}
if (exp.More())
{
Collage = BRepFeat::IsInside(glface, fac);
if (!Collage)
{
theOpe = 2;
break;
}
else
{
theGlue.Bind(glface, fac);
theFE.Set(glface, fac);
for (theFE.InitIterator(); theFE.More(); theFE.Next())
{
theGlue.Bind(theFE.EdgeFrom(), theFE.EdgeTo());
}
}
}
}
LocOpe_Operation ope = theGlue.OpeType();
if (ope == LocOpe_INVALID || (myFuse && ope != LocOpe_FUSE) || (!myFuse && ope != LocOpe_CUT)
|| (!Collage))
{
theOpe = 2;
#ifdef OCCT_DEBUG
std::cout << "Passage to topological operations" << std::endl;
#endif
}
}
// gluing is always applicable
if (theOpe == 1)
{
theGlue.Perform();
if (theGlue.IsDone())
{
UpdateDescendants(theGlue);
myNewEdges = theGlue.Edges();
myTgtEdges = theGlue.TgtEdges();
//
Done();
myShape = theGlue.ResultingShape();
BRepLib::SameParameter(myShape, 1.e-7, true);
}
else
{
theOpe = 2;
#ifdef OCCT_DEBUG
std::cout << "Passage to topologic operation" << std::endl;
#endif
}
}
// case without gluing
if (theOpe == 2)
{
BRepFeat_Builder theBuilder;
NCollection_List<TopoDS_Shape> partsoftool;
BRepClass3d_SolidClassifier oussa;
bool bFlag;
NCollection_List<TopoDS_Shape>::Iterator aIt;
bFlag = myPerfSelection != BRepFeat_NoSelection;
//
theBuilder.Init(mySbase, myGShape);
theBuilder.SetOperation(myFuse, bFlag);
//
theBuilder.Perform();
if (bFlag)
{
theBuilder.PartsOfTool(partsoftool);
aIt.Initialize(partsoftool);
if (aIt.More() && myPerfSelection != BRepFeat_NoSelection)
{
double toler = (BRep_Tool::Tolerance(myPbase)) * 2;
//
for (; aIt.More(); aIt.Next())
{
oussa.Load(aIt.Value());
oussa.Perform(myFirstPnt, toler);
TopAbs_State sp1 = oussa.State();
oussa.Perform(myLastPnt, toler);
TopAbs_State sp2 = oussa.State();
if (sp1 != TopAbs_OUT && sp2 != TopAbs_OUT)
{
const TopoDS_Shape& S = aIt.Value();
theBuilder.KeepPart(S);
}
}
}
//
theBuilder.PerformResult();
myShape = theBuilder.Shape();
}
else
{
myShape = theBuilder.Shape();
}
Done();
}
}
//=================================================================================================
bool BRepFeat_RibSlot::IsDeleted(const TopoDS_Shape& F)
{
return (myMap(F).IsEmpty());
}
//=================================================================================================
const NCollection_List<TopoDS_Shape>& BRepFeat_RibSlot::Modified(const TopoDS_Shape& F)
{
if (myMap.IsBound(F))
{
static NCollection_List<TopoDS_Shape> list;
list.Clear();
NCollection_List<TopoDS_Shape>::Iterator ite(myMap(F));
for (; ite.More(); ite.Next())
{
const TopoDS_Shape& sh = ite.Value();
if (!sh.IsSame(F))
{
list.Append(sh);
}
}
return list;
}
return myGenerated; // empty list
}
//=================================================================================================
const NCollection_List<TopoDS_Shape>& BRepFeat_RibSlot::Generated(const TopoDS_Shape& S)
{
if (S.ShapeType() != TopAbs_FACE)
{
myGenerated.Clear();
if (myLFMap.IsEmpty() || !myLFMap.IsBound(S))
{
if (myMap.IsBound(S))
{ // check if filter on face or not
static NCollection_List<TopoDS_Shape> list;
list.Clear();
NCollection_List<TopoDS_Shape>::Iterator ite(myMap(S));
for (; ite.More(); ite.Next())
{
const TopoDS_Shape& sh = ite.Value();
if (!sh.IsSame(S))
{
list.Append(sh);
}
}
return list;
}
else
{
return myGenerated;
}
}
else
{
myGenerated.Clear();
NCollection_List<TopoDS_Shape>::Iterator it(myLFMap(S));
static NCollection_List<TopoDS_Shape> list;
list.Clear();
for (; it.More(); it.Next())
{
if (myMap.IsBound(it.Value()))
{
NCollection_List<TopoDS_Shape>::Iterator it1(myMap(it.Value()));
for (; it1.More(); it1.Next())
{
const TopoDS_Shape& sh = it1.Value();
if (!sh.IsSame(S))
{
list.Append(sh);
}
}
}
}
return list;
}
}
else
{
return myGenerated;
}
}
//=================================================================================================
void BRepFeat_RibSlot::UpdateDescendants(const LocOpe_Gluer& G)
{
NCollection_DataMap<TopoDS_Shape, NCollection_List<TopoDS_Shape>, TopTools_ShapeMapHasher>::
Iterator itdm;
NCollection_List<TopoDS_Shape>::Iterator it, it2;
NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher>::Iterator itm;
for (itdm.Initialize(myMap); itdm.More(); itdm.Next())
{
const TopoDS_Shape& orig = itdm.Key();
NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> newdsc;
for (it.Initialize(itdm.Value()); it.More(); it.Next())
{
const TopoDS_Face& fdsc = TopoDS::Face(it.Value());
for (it2.Initialize(G.DescendantFaces(fdsc)); it2.More(); it2.Next())
{
newdsc.Add(it2.Value());
}
}
myMap.ChangeFind(orig).Clear();
for (itm.Initialize(newdsc); itm.More(); itm.Next())
{
myMap.ChangeFind(orig).Append(itm.Key());
}
}
}
//=================================================================================================
const NCollection_List<TopoDS_Shape>& BRepFeat_RibSlot::FirstShape() const
{
if (!myFShape.IsNull())
{
return myMap(myFShape);
}
return myGenerated; // empty list
}
//=================================================================================================
const NCollection_List<TopoDS_Shape>& BRepFeat_RibSlot::LastShape() const
{
if (!myLShape.IsNull())
{
return myMap(myLShape);
}
return myGenerated; // empty list
}
//=================================================================================================
const NCollection_List<TopoDS_Shape>& BRepFeat_RibSlot::FacesForDraft() const
{
return myFacesForDraft;
}
//=================================================================================================
const NCollection_List<TopoDS_Shape>& BRepFeat_RibSlot::NewEdges() const
{
return myNewEdges;
}
//=================================================================================================
const NCollection_List<TopoDS_Shape>& BRepFeat_RibSlot::TgtEdges() const
{
return myTgtEdges;
}
//=================================================================================================
BRepFeat_StatusError BRepFeat_RibSlot::CurrentStatusError() const
{
return myStatusError;
}
//=======================================================================
// function : CheckPoint
// purpose : Proofing point material side (side of extrusion)
//=======================================================================
gp_Pnt BRepFeat_RibSlot::CheckPoint(const TopoDS_Edge& e,
const double, // bnd,
const occ::handle<Geom_Plane>& Pln)
{
// Vector product : normal to plane X direction Wire
// -> gives the material side
// Proofing point somewhat inside the material side
double f, l;
occ::handle<Geom_Curve> cc = BRep_Tool::Curve(e, f, l);
gp_Vec tgt;
gp_Pnt pp;
double par = (f + l) / 2.;
cc->D1(par, pp, tgt);
if (e.Orientation() == TopAbs_REVERSED)
{
tgt.Reverse();
}
gp_Vec D = -tgt.Crossed(Pln->Pln().Position().Direction()) / 10.;
pp.Translate(D);
return pp;
}
//=======================================================================
// function : Normal
// purpose : calculate the normal to a face in a point
//=======================================================================
gp_Dir BRepFeat_RibSlot::Normal(const TopoDS_Face& F, const gp_Pnt& P)
{
double U, V;
gp_Pnt pt;
BRepAdaptor_Surface AS(F, true);
switch (AS.GetType())
{
case GeomAbs_Plane:
ElSLib::Parameters(AS.Plane(), P, U, V);
break;
case GeomAbs_Cylinder:
ElSLib::Parameters(AS.Cylinder(), P, U, V);
break;
case GeomAbs_Cone:
ElSLib::Parameters(AS.Cone(), P, U, V);
break;
case GeomAbs_Torus:
ElSLib::Parameters(AS.Torus(), P, U, V);
break;
default: {
return gp_Dir(gp_Dir::D::X);
}
}
gp_Vec D1U, D1V;
AS.D1(U, V, pt, D1U, D1V);
gp_Dir N;
CSLib_DerivativeStatus St;
CSLib::Normal(D1U, D1V, Precision::Confusion(), St, N);
if (F.Orientation() == TopAbs_FORWARD)
{
N.Reverse();
}
return N;
}
//=======================================================================
// function : IntPar
// purpose : calculate the parameter of a point on a curve
//=======================================================================
double BRepFeat_RibSlot::IntPar(const occ::handle<Geom_Curve>& C, const gp_Pnt& P)
{
if (C.IsNull())
{
return 0.;
}
GeomAdaptor_Curve AC(C);
double U;
switch (AC.GetType())
{
case GeomAbs_Line:
U = ElCLib::Parameter(AC.Line(), P);
break;
case GeomAbs_Circle:
U = ElCLib::Parameter(AC.Circle(), P);
break;
case GeomAbs_Ellipse:
U = ElCLib::Parameter(AC.Ellipse(), P);
break;
case GeomAbs_Hyperbola:
U = ElCLib::Parameter(AC.Hyperbola(), P);
break;
case GeomAbs_Parabola:
U = ElCLib::Parameter(AC.Parabola(), P);
break;
default:
U = 0.;
}
return U;
}
//=======================================================================
// function : EdgeExtention
// purpose : extension of a edge by tangence
//=======================================================================
void BRepFeat_RibSlot::EdgeExtention(TopoDS_Edge& e, const double bnd, const bool FirstLast)
{
double f, l;
occ::handle<Geom_Curve> cu = BRep_Tool::Curve(e, f, l);
occ::handle<Geom_BoundedCurve> C = new Geom_TrimmedCurve(cu, f, l);
TopoDS_Edge E;
if (cu->DynamicType() == STANDARD_TYPE(Geom_Line)
|| cu->DynamicType() == STANDARD_TYPE(Geom_Circle)
|| cu->DynamicType() == STANDARD_TYPE(Geom_Ellipse)
|| cu->DynamicType() == STANDARD_TYPE(Geom_Hyperbola)
|| cu->DynamicType() == STANDARD_TYPE(Geom_Parabola))
{
if (FirstLast)
{
BRepLib_MakeEdge Edg(cu, f - bnd / 10., l);
E = TopoDS::Edge(Edg.Shape());
}
else
{
BRepLib_MakeEdge Edg(cu, f, l + bnd / 10.);
E = TopoDS::Edge(Edg.Shape());
}
}
else
{
occ::handle<Geom_Line> ln;
gp_Pnt Pt;
gp_Pnt pnt;
gp_Vec vct;
if (FirstLast)
{
C->D1(f, pnt, vct);
ln = new Geom_Line(pnt, -vct);
ln->D0(bnd / 1000., Pt);
GeomLib::ExtendCurveToPoint(C, Pt, GeomAbs_G1, false);
BRepLib_MakeEdge Edg(C, Pt, BRep_Tool::Pnt(TopExp::LastVertex(e, true)));
E = TopoDS::Edge(Edg.Shape());
}
else
{
C->D1(l, pnt, vct);
ln = new Geom_Line(pnt, vct);
ln->D0(bnd / 1000., Pt);
GeomLib::ExtendCurveToPoint(C, Pt, GeomAbs_G1, true);
BRepLib_MakeEdge Edg(C, BRep_Tool::Pnt(TopExp::FirstVertex(e, true)), Pt);
E = TopoDS::Edge(Edg.Shape());
}
}
e = E;
}
//=======================================================================
// function : ChoiceOfFaces
// purpose : choose face of support in case of support on an edge
//=======================================================================
TopoDS_Face BRepFeat_RibSlot::ChoiceOfFaces(NCollection_List<TopoDS_Shape>& faces,
const occ::handle<Geom_Curve>& cc,
const double par,
const double, // bnd,
const occ::handle<Geom_Plane>& Pln)
{
TopoDS_Face FFF;
gp_Pnt pp;
gp_Vec tgt;
cc->D1(par, pp, tgt);
occ::handle<Geom_Line> l1 = new Geom_Line(pp, tgt);
NCollection_Sequence<occ::handle<Geom_Curve>> scur;
int Counter = 0;
gp_Ax1 Axe(pp, Pln->Position().Direction());
for (int i = 1; i <= 8; i++)
{
occ::handle<Geom_Curve> L = occ::down_cast<Geom_Curve>(l1->Rotated(Axe, i * M_PI / 9.));
scur.Append(L);
Counter++;
}
NCollection_List<TopoDS_Shape>::Iterator it;
it.Initialize(faces);
double Par = RealLast();
for (; it.More(); it.Next())
{
const TopoDS_Face& f = TopoDS::Face(it.Value());
LocOpe_CSIntersector ASI(f);
ASI.Perform(scur);
if (!ASI.IsDone())
{
continue;
}
for (int jj = 1; jj <= Counter; jj++)
{
if (ASI.NbPoints(jj) >= 1)
{
double app = ASI.Point(jj, 1).Parameter();
if (app >= 0 && app < Par)
{
Par = app;
FFF = f;
}
}
}
}
return FFF;
}
//=======================================================================
// function : HeightMax
// purpose : Calculate the height of the prism following the parameters of a bounding box
//=======================================================================
double BRepFeat_RibSlot::HeightMax(const TopoDS_Shape& theSbase,
const TopoDS_Shape& theSUntil,
gp_Pnt& p1,
gp_Pnt& p2)
{
Bnd_Box Box;
BRepBndLib::Add(theSbase, Box);
if (!theSUntil.IsNull())
{
BRepBndLib::Add(theSUntil, Box);
}
double c[6], bnd;
Box.Get(c[0], c[2], c[4], c[1], c[3], c[5]);
bnd = c[0];
for (int i = 0; i < 6; i++)
{
if (c[i] > bnd)
{
bnd = c[i];
}
}
p1.SetCoord(c[0] - 2. * bnd, c[1] - 2. * bnd, c[2] - 2. * bnd);
p2.SetCoord(c[3] + 2. * bnd, c[4] + 2. * bnd, c[5] + 2. * bnd);
return (bnd);
}
//=======================================================================
// function : ExtremeFaces
// purpose : Calculate the base faces of the rib
//=======================================================================
bool BRepFeat_RibSlot::ExtremeFaces(const bool RevolRib,
const double bnd,
const occ::handle<Geom_Plane>& Pln,
TopoDS_Edge& FirstEdge,
TopoDS_Edge& LastEdge,
TopoDS_Face& FirstFace,
TopoDS_Face& LastFace,
TopoDS_Vertex& FirstVertex,
TopoDS_Vertex& LastVertex,
bool& OnFirstFace,
bool& OnLastFace,
bool& PtOnFirstEdge,
bool& PtOnLastEdge,
TopoDS_Edge& OnFirstEdge,
TopoDS_Edge& OnLastEdge)
{
bool Data = true;
FirstFace.Nullify();
LastFace.Nullify();
FirstEdge.Nullify();
LastEdge.Nullify();
PtOnFirstEdge = false;
PtOnLastEdge = false;
OnFirstEdge.Nullify();
OnLastEdge.Nullify();
BRepIntCurveSurface_Inter inter;
BRep_Builder B;
TopExp_Explorer ex1;
bool FirstOK = false, LastOK = false;
int NumberOfEdges = 0;
TopExp_Explorer exp(myWire, TopAbs_EDGE);
for (; exp.More(); exp.Next())
{
NumberOfEdges++;
}
// ---the wire includes only one edge
if (NumberOfEdges == 1)
{
exp.ReInit();
double f, l; //, f1, l1, temp;
gp_Pnt firstpoint, lastpoint;
// Points limit the unique edge
const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
occ::handle<Geom_Curve> cc = BRep_Tool::Curve(E, f, l);
gp_Pnt p1 = BRep_Tool::Pnt(TopExp::FirstVertex(E, true));
gp_Pnt p2 = BRep_Tool::Pnt(TopExp::LastVertex(E, true));
double FirstPar = f;
double LastPar = l;
// ---Find if 2 points limiting the unique edge of the wire
// are on an edge or a vertex of the base shape
bool PtOnFirstVertex = false;
bool PtOnLastVertex = false;
TopoDS_Vertex OnFirstVertex, OnLastVertex;
PtOnEdgeVertex(RevolRib,
mySbase,
p1,
FirstVertex,
LastVertex,
PtOnFirstEdge,
OnFirstEdge,
PtOnFirstVertex,
OnFirstVertex);
PtOnEdgeVertex(RevolRib,
mySbase,
p2,
FirstVertex,
LastVertex,
PtOnLastEdge,
OnLastEdge,
PtOnLastVertex,
OnLastVertex);
NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> Map;
if (PtOnFirstEdge)
{
if (!PtOnFirstVertex)
{
// Find FirstFace : face of the base shape containing OnFirstEdge
// meeting ChoiceOfFaces
TopExp_Explorer ex4, ex5;
ex4.Init(mySbase, TopAbs_FACE);
NCollection_List<TopoDS_Shape> faces;
faces.Clear();
Map.Clear();
for (; ex4.More(); ex4.Next())
{
const TopoDS_Face& fx = TopoDS::Face(ex4.Current());
if (!Map.Add(fx))
{
continue;
}
ex5.Init(ex4.Current(), TopAbs_EDGE);
for (; ex5.More(); ex5.Next())
{
const TopoDS_Edge& ee = TopoDS::Edge(ex5.Current());
if (ee.IsSame(OnFirstEdge))
{
faces.Append(fx);
}
}
}
if (!faces.IsEmpty())
{
TopoDS_Face FFF = ChoiceOfFaces(faces, cc, FirstPar + bnd / 50., bnd / 50., Pln);
if (!FFF.IsNull())
{
FirstFace = FFF;
}
}
}
else if (PtOnFirstVertex)
{
// Find FirstFace : face of the base shape containing OnFirstVertex
// meeting ChoiceOfFaces
TopExp_Explorer ex4, ex5;
ex4.Init(mySbase, TopAbs_FACE);
NCollection_List<TopoDS_Shape> faces;
faces.Clear();
Map.Clear();
for (; ex4.More(); ex4.Next())
{
const TopoDS_Face& fx = TopoDS::Face(ex4.Current());
if (!Map.Add(fx))
{
continue;
}
ex5.Init(ex4.Current(), TopAbs_VERTEX);
for (; ex5.More(); ex5.Next())
{
const TopoDS_Vertex& vv = TopoDS::Vertex(ex5.Current());
if (vv.IsSame(OnFirstVertex))
{
faces.Append(fx);
break;
}
}
}
if (!faces.IsEmpty())
{
TopoDS_Face FFF = ChoiceOfFaces(faces, cc, FirstPar + bnd / 50., bnd / 50., Pln);
if (!FFF.IsNull())
{
FirstFace = FFF;
}
}
}
FirstEdge = E;
BRepLib_MakeVertex v(p1);
FirstVertex = v;
OnFirstFace = true;
}
if (PtOnLastEdge)
{
if (!PtOnLastVertex)
{
// Find LastFace : face of the base shape containing OnLastEdge
// meeting ChoiceOfFaces
TopExp_Explorer ex4, ex5;
ex4.Init(mySbase, TopAbs_FACE);
NCollection_List<TopoDS_Shape> faces;
faces.Clear();
Map.Clear();
for (; ex4.More(); ex4.Next())
{
const TopoDS_Face& fx = TopoDS::Face(ex4.Current());
if (!Map.Add(fx))
{
continue;
}
ex5.Init(ex4.Current(), TopAbs_EDGE);
for (; ex5.More(); ex5.Next())
{
const TopoDS_Edge& ee = TopoDS::Edge(ex5.Current());
if (ee.IsSame(OnLastEdge))
{
faces.Append(fx);
break;
}
}
}
if (!faces.IsEmpty())
{
TopoDS_Face FFF = ChoiceOfFaces(faces, cc, LastPar - bnd / 50., bnd / 50., Pln);
if (!FFF.IsNull())
{
LastFace = FFF;
}
}
}
else if (PtOnLastEdge && PtOnLastVertex)
{
// Find LastFace : face of the base shape containing OnLastVertex
// meeting ChoiceOfFaces
TopExp_Explorer ex4, ex5;
ex4.Init(mySbase, TopAbs_FACE);
NCollection_List<TopoDS_Shape> faces;
faces.Clear();
Map.Clear();
for (; ex4.More(); ex4.Next())
{
const TopoDS_Face& fx = TopoDS::Face(ex4.Current());
if (!Map.Add(fx))
{
continue;
}
ex5.Init(ex4.Current(), TopAbs_VERTEX);
for (; ex5.More(); ex5.Next())
{
const TopoDS_Vertex& vv = TopoDS::Vertex(ex5.Current());
if (vv.IsSame(OnLastVertex))
{
faces.Append(fx);
break;
}
}
}
if (!faces.IsEmpty())
{
TopoDS_Face FFF = ChoiceOfFaces(faces, cc, LastPar - bnd / 50., bnd / 50., Pln);
if (!FFF.IsNull())
{
LastFace = FFF;
}
}
}
LastEdge = E;
BRepLib_MakeVertex v(p2);
LastVertex = v;
OnLastFace = true;
}
if (!FirstFace.IsNull() && !LastFace.IsNull())
{
return true;
}
//--- FirstFace or LastFace was not found
LocOpe_CSIntersector ASI(mySbase);
NCollection_Sequence<occ::handle<Geom_Curve>> scur;
scur.Clear();
scur.Append(cc);
ASI.Perform(scur);
double lastpar, firstpar;
if (ASI.IsDone() && ASI.NbPoints(1) >= 2)
{
lastpar = ASI.Point(1, ASI.NbPoints(1)).Parameter();
int lastindex = ASI.NbPoints(1);
if (lastpar > l)
{
for (int jj = ASI.NbPoints(1) - 1; jj >= 1; jj--)
{
double par = ASI.Point(1, jj).Parameter();
if (par <= l)
{
lastpar = par;
lastindex = jj;
break;
}
}
}
int firstindex = lastindex - 1;
firstpar = ASI.Point(1, firstindex).Parameter();
if (FirstFace.IsNull())
{
FirstFace = ASI.Point(1, firstindex).Face();
cc->D0(firstpar, firstpoint);
BRepLib_MakeVertex v1(firstpoint);
FirstVertex = TopoDS::Vertex(v1.Shape());
FirstEdge = E;
}
if (LastFace.IsNull())
{
LastFace = ASI.Point(1, lastindex).Face();
cc->D0(lastpar, lastpoint);
BRepLib_MakeVertex v2(lastpoint);
LastVertex = TopoDS::Vertex(v2.Shape());
LastEdge = E;
}
}
else
{
Data = false;
return Data;
}
if (!OnFirstFace)
{
OnFirstFace = p1.Distance(firstpoint) <= Precision::Confusion();
}
if (!OnLastFace)
{
OnLastFace = p2.Distance(lastpoint) <= Precision::Confusion();
}
Data = !(FirstFace.IsNull() || LastFace.IsNull());
return Data;
}
// ---The wire consists of several edges
else
{
BRepTools_WireExplorer ex(myWire);
for (; ex.More(); ex.Next())
{
const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
double f, l;
occ::handle<Geom_Curve> Cur = BRep_Tool::Curve(E, f, l);
f = f - bnd / 10000;
l = l + bnd / 10000;
occ::handle<Geom_TrimmedCurve> curve;
curve = new Geom_TrimmedCurve(Cur, f, l, true);
#ifdef OCCT_DEBUG
gp_Pnt P1 = BRep_Tool::Pnt(TopExp::FirstVertex(E, true));
(void)P1;
#endif
gp_Pnt P2 = BRep_Tool::Pnt(TopExp::LastVertex(E, true));
ex1.Init(mySbase, TopAbs_FACE);
TopoDS_Vertex theVertex;
TopoDS_Edge theEdge;
TopoDS_Face theFace;
bool PtOnEdge = false;
bool PtOnVertex = false;
TopoDS_Edge OnEdge;
TopoDS_Vertex OnVertex;
double intpar;
for (; ex1.More(); ex1.Next())
{
const TopoDS_Face& aCurFace = TopoDS::Face(ex1.Current());
GeomAdaptor_Curve aGAC(curve);
inter.Init(aCurFace, aGAC, BRep_Tool::Tolerance(aCurFace));
if (!inter.More())
{
continue;
}
for (; inter.More(); inter.Next())
{
gp_Pnt thePoint = inter.Pnt();
if (!FirstVertex.IsNull())
{
gp_Pnt point = BRep_Tool::Pnt(FirstVertex);
if (point.Distance(thePoint) <= BRep_Tool::Tolerance(aCurFace))
{
continue;
}
}
intpar = IntPar(curve, thePoint);
theEdge = E;
theFace = aCurFace;
B.MakeVertex(theVertex, thePoint, Precision::Confusion());
if (!FirstOK)
{
if (thePoint.Distance(P2) <= Precision::Confusion())
{
continue;
}
}
// ---Find thepoint on an edge or a vertex of face f
PtOnEdgeVertex(RevolRib,
aCurFace,
thePoint,
FirstVertex,
LastVertex,
PtOnEdge,
OnEdge,
PtOnVertex,
OnVertex);
// if(!theEdge.IsNull()) break;
if (FirstEdge.IsNull() && !theEdge.IsNull() && !theFace.IsNull() && !theVertex.IsNull())
{
FirstEdge = theEdge;
FirstFace = theFace;
FirstVertex = theVertex;
PtOnFirstEdge = PtOnEdge;
OnFirstEdge = OnEdge;
theEdge.Nullify();
theFace.Nullify();
theVertex.Nullify();
if (PtOnEdge && !PtOnVertex)
{
NCollection_List<TopoDS_Shape> faces;
faces.Clear();
faces.Append(FirstFace);
TopExp_Explorer ex2;
ex2.Init(mySbase, TopAbs_FACE);
for (; ex2.More(); ex2.Next())
{
TopoDS_Face fx = TopoDS::Face(ex2.Current());
TopExp_Explorer ex3;
ex3.Init(fx, TopAbs_EDGE);
for (; ex3.More(); ex3.Next())
{
const TopoDS_Edge& e = TopoDS::Edge(ex3.Current());
if (e.IsSame(OnEdge) && !fx.IsSame(FirstFace))
{
faces.Append(fx);
}
}
}
TopoDS_Face FFF = ChoiceOfFaces(faces, curve, intpar + bnd / 10., bnd / 10., Pln);
if (!FFF.IsNull())
{
FirstFace = FFF;
}
}
else if (PtOnEdge && PtOnVertex)
{
NCollection_List<TopoDS_Shape> faces;
faces.Clear();
faces.Append(FirstFace);
TopExp_Explorer ex2;
ex2.Init(mySbase, TopAbs_FACE);
for (; ex2.More(); ex2.Next())
{
TopoDS_Face fx = TopoDS::Face(ex2.Current());
TopExp_Explorer ex3;
ex3.Init(fx, TopAbs_VERTEX);
for (; ex3.More(); ex3.Next())
{
const TopoDS_Vertex& v = TopoDS::Vertex(ex3.Current());
if (v.IsSame(OnVertex) && !fx.IsSame(FirstFace))
{
faces.Append(fx);
}
}
}
TopoDS_Face FFF = ChoiceOfFaces(faces, curve, intpar + bnd / 10., bnd / 10., Pln);
if (!FFF.IsNull())
{
FirstFace = FFF;
}
}
if (!FirstEdge.IsNull() && !FirstFace.IsNull() && !FirstVertex.IsNull())
{
FirstOK = true;
}
}
if (LastEdge.IsNull() && !theEdge.IsNull() && !theFace.IsNull() && !theVertex.IsNull()
&& !FirstEdge.IsNull())
{
LastEdge = theEdge;
LastFace = theFace;
LastVertex = theVertex;
PtOnLastEdge = PtOnEdge;
OnLastEdge = OnEdge;
if (PtOnEdge && !PtOnVertex)
{
NCollection_List<TopoDS_Shape> faces;
faces.Clear();
faces.Append(LastFace);
TopExp_Explorer ex2;
ex2.Init(mySbase, TopAbs_FACE);
for (; ex2.More(); ex2.Next())
{
TopoDS_Face fx = TopoDS::Face(ex2.Current());
TopExp_Explorer ex3;
ex3.Init(fx, TopAbs_EDGE);
for (; ex3.More(); ex3.Next())
{
const TopoDS_Edge& e = TopoDS::Edge(ex3.Current());
if (e.IsSame(OnEdge) && !fx.IsSame(LastFace))
{
faces.Append(fx);
}
}
}
TopoDS_Face FFF = ChoiceOfFaces(faces, curve, intpar - bnd / 10., bnd / 10., Pln);
if (!FFF.IsNull())
{
LastFace = FFF;
}
}
else if (PtOnEdge && PtOnVertex)
{
NCollection_List<TopoDS_Shape> faces;
faces.Clear();
faces.Append(LastFace);
TopExp_Explorer ex2;
ex2.Init(mySbase, TopAbs_FACE);
for (; ex2.More(); ex2.Next())
{
TopoDS_Face fx = TopoDS::Face(ex2.Current());
TopExp_Explorer ex3;
ex3.Init(fx, TopAbs_VERTEX);
for (; ex3.More(); ex3.Next())
{
const TopoDS_Vertex& v = TopoDS::Vertex(ex3.Current());
if (v.IsSame(OnVertex) && !fx.IsSame(LastFace))
{
faces.Append(fx);
}
}
}
TopoDS_Face FFF = ChoiceOfFaces(faces, curve, intpar - bnd / 10., bnd / 10., Pln);
if (!FFF.IsNull())
{
LastFace = FFF;
}
}
if (!LastEdge.IsNull() && !LastFace.IsNull() && !LastVertex.IsNull())
{
LastOK = true;
}
break;
}
}
}
}
if (FirstOK && LastOK)
{
Data = true;
gp_Pnt PP1 = BRep_Tool::Pnt(TopExp::FirstVertex(FirstEdge, true));
gp_Pnt PP2 = BRep_Tool::Pnt(TopExp::LastVertex(LastEdge, true));
gp_Pnt p1 = BRep_Tool::Pnt(FirstVertex);
gp_Pnt p2 = BRep_Tool::Pnt(LastVertex);
if (p1.Distance(PP1) <= BRep_Tool::Tolerance(FirstFace))
{
OnFirstFace = true;
}
if (p2.Distance(PP2) <= BRep_Tool::Tolerance(LastFace))
{
OnLastFace = true;
}
return true;
}
else
{
return false;
}
}
}
//=======================================================================
// function : PtOnEdgeVertex
// purpose : Find if 2 limit points of the unique edge of a wire
// are on an edge or a vertex of the base shape
//=======================================================================
void BRepFeat_RibSlot::PtOnEdgeVertex(const bool RevolRib,
const TopoDS_Shape& shape,
const gp_Pnt& point,
const TopoDS_Vertex&, // FirstVertex,
const TopoDS_Vertex&, // LastVertex,
bool& PtOnEdge,
TopoDS_Edge& OnEdge,
bool& PtOnVertex,
TopoDS_Vertex& OnVertex)
{
bool TestOK;
// PtOnEdge = false;
// OnEdge.Nullify();
// PtOnVertex = false;
// OnVertex.Nullify();
TopExp_Explorer EXP;
EXP.Init(shape, TopAbs_EDGE);
NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> Map;
for (; EXP.More(); EXP.Next())
{
const TopoDS_Edge& e = TopoDS::Edge(EXP.Current());
if (!Map.Add(e))
{
continue;
}
if (!RevolRib)
{
if (BRep_Tool::Degenerated(e))
{
continue;
}
}
double fff, lll;
occ::handle<Geom_Curve> ccc = BRep_Tool::Curve(e, fff, lll);
if (!RevolRib)
{
ccc = new Geom_TrimmedCurve(ccc, fff, lll);
}
GeomAPI_ProjectPointOnCurve proj(point, ccc);
TestOK = false;
if (!RevolRib)
{
if (proj.NbPoints() == 1)
{
TestOK = true;
}
}
else
{
if (proj.NbPoints() >= 1)
{
TestOK = true;
}
}
if (TestOK && proj.Distance(1) <= BRep_Tool::Tolerance(e))
{
PtOnEdge = true;
OnEdge = e;
TopoDS_Vertex ev1 = TopExp::FirstVertex(e, true);
TopoDS_Vertex ev2 = TopExp::LastVertex(e, true);
gp_Pnt ep1 = BRep_Tool::Pnt(ev1);
gp_Pnt ep2 = BRep_Tool::Pnt(ev2);
if (point.Distance(ep1) <= BRep_Tool::Tolerance(ev1))
{
PtOnVertex = true;
OnVertex = ev1;
break;
}
else if (point.Distance(ep2) <= BRep_Tool::Tolerance(ev1))
{
PtOnVertex = true;
OnVertex = ev2;
break;
}
break;
}
}
}
//=======================================================================
// function : SlidingProfile
// purpose : construction of the profile face in case of sliding
//=======================================================================
bool BRepFeat_RibSlot::SlidingProfile(TopoDS_Face& Prof,
const bool RevolRib,
const double myTol,
int& Concavite,
const occ::handle<Geom_Plane>& myPln,
const TopoDS_Face& BndFace,
const gp_Pnt& CheckPnt,
const TopoDS_Face& FirstFace,
const TopoDS_Face& LastFace,
const TopoDS_Vertex&, // FirstVertex,
const TopoDS_Vertex&, // LastVertex,
const TopoDS_Edge& FirstEdge,
const TopoDS_Edge& LastEdge)
{
bool ProfileOK = true;
// --case of sliding : construction of the wire of the profile
// --> 1 part bounding box + 1 part wire
// attention to the compatibility of orientations
gp_Dir FN, LN;
BRepLib_MakeWire WW;
FN = Normal(FirstFace, myFirstPnt);
LN = Normal(LastFace, myLastPnt);
// Case of the groove (cut) <> rib (fuse)
// -> we are in the material
// -> make everything in 2d in the working plane : easier
if (!myFuse)
{
FN = -FN;
LN = -LN;
}
occ::handle<Geom_Line> ln1, ln2;
gp_Pnt Pt; //,p1, p2;
ln2 = new Geom_Line(myFirstPnt, FN);
ln1 = new Geom_Line(myLastPnt, LN);
occ::handle<Geom2d_Curve> ln2d1 = GeomAPI::To2d(ln1, myPln->Pln());
occ::handle<Geom2d_Curve> ln2d2 = GeomAPI::To2d(ln2, myPln->Pln());
Geom2dAPI_InterCurveCurve inter(ln2d1, ln2d2, Precision::Confusion());
bool TestOK = true;
if (RevolRib)
{
gp_Dir d1, d2;
d1 = ln1->Position().Direction();
d2 = ln2->Position().Direction();
if (d1.IsOpposite(d2, myTol))
{
double par1 = ElCLib::Parameter(ln1->Lin(), myFirstPnt);
double par2 = ElCLib::Parameter(ln2->Lin(), myLastPnt);
if (par1 >= myTol || par2 >= myTol)
{
Concavite = 2; // parallel and concave
BRepLib_MakeEdge e1(myLastPnt, myFirstPnt);
WW.Add(e1);
}
}
if (d1.IsEqual(d2, myTol))
{
if (Concavite == 3)
{
TestOK = false;
}
}
}
if (TestOK)
{
if (inter.NbPoints() > 0)
{
gp_Pnt2d P = inter.Point(1);
myPln->D0(P.X(), P.Y(), Pt);
double par = IntPar(ln1, Pt);
if (par > 0)
{
Concavite = 1; // concave
}
}
}
// ---Construction of the profile face
if (Concavite == 1)
{
// if concave : it is possible to extend first and last edges of the wire
// to the bounding box
BRepLib_MakeEdge e1(myLastPnt, Pt);
WW.Add(e1);
BRepLib_MakeEdge e2(Pt, myFirstPnt);
WW.Add(e2);
}
else if (Concavite == 3)
{
// BndEdge : edges of intersection with the bounding box
TopoDS_Edge BndEdge1, BndEdge2;
// Points of intersection with the bounding box / Find Profile
gp_Pnt BndPnt1, BndPnt2, LastPnt;
TopExp_Explorer expl;
expl.Init(BndFace, TopAbs_WIRE);
BRepTools_WireExplorer explo;
TopoDS_Wire BndWire = TopoDS::Wire(expl.Current());
explo.Init(BndWire);
for (; explo.More(); explo.Next())
{
const TopoDS_Edge& e = TopoDS::Edge(explo.Current());
double first, last;
occ::handle<Geom_Curve> c = BRep_Tool::Curve(e, first, last);
occ::handle<Geom2d_Curve> c2d = GeomAPI::To2d(c, myPln->Pln());
Geom2dAPI_InterCurveCurve intcln1(ln2d1, c2d, Precision::Confusion());
if (intcln1.NbPoints() > 0)
{
gp_Pnt2d p2d = intcln1.Point(1);
gp_Pnt p;
myPln->D0(p2d.X(), p2d.Y(), p);
double parl = IntPar(ln1, p);
double parc = IntPar(c, p);
if (parc >= first && parc <= last && parl >= 0)
{
BndEdge1 = e;
BndPnt1 = p;
}
}
Geom2dAPI_InterCurveCurve intcln2(ln2d2, c2d, Precision::Confusion());
if (intcln2.NbPoints() > 0)
{
gp_Pnt2d p2d = intcln2.Point(1);
gp_Pnt p;
myPln->D0(p2d.X(), p2d.Y(), p);
double parl = IntPar(ln2, p);
double parc = IntPar(c, p);
if (parc >= first && parc <= last && parl >= 0)
{
BndEdge2 = e;
BndPnt2 = p;
}
}
if (!BndEdge1.IsNull() && !BndEdge2.IsNull())
{
break;
}
}
if (BndEdge1.IsNull() || BndEdge2.IsNull())
{
ProfileOK = false;
return ProfileOK;
}
BRepLib_MakeEdge e1(myLastPnt, BndPnt1);
WW.Add(e1);
if (BndEdge1.IsSame(BndEdge2))
{
// Particular case : same edge -> simply determined path
BRepLib_MakeEdge e2(BndPnt1, BndPnt2);
WW.Add(e2);
BRepLib_MakeEdge e3(BndPnt2, myFirstPnt);
WW.Add(e3);
}
else
{
explo.Init(BndWire);
for (; explo.More(); explo.Next())
{
const TopoDS_Edge& e = TopoDS::Edge(explo.Current());
if (e.IsSame(BndEdge1))
{
gp_Pnt pp;
pp = BRep_Tool::Pnt(TopExp::LastVertex(e, true));
if (pp.Distance(BndPnt1) >= BRep_Tool::Tolerance(e))
{
LastPnt = pp;
}
// else { //LinearForm
// gp_Pnt ppp = BRep_Tool::Pnt(TopExp::FirstVertex(e,true));
// LastPnt = ppp;
// }
BRepLib_MakeEdge e2(BndPnt1, LastPnt);
WW.Add(e2);
break;
}
}
if (explo.More())
{
explo.Next();
if (explo.Current().IsNull())
{
explo.Init(BndWire);
}
}
else
{
explo.Init(BndWire);
}
// Check if this is BndEdge2
// -> if yes : it is required to turn to join FirstPnt
// -> if no : add edges
bool Fin = false;
while (!Fin)
{
const TopoDS_Edge& e = TopoDS::Edge(explo.Current());
if (!e.IsSame(BndEdge2))
{
gp_Pnt pp;
pp = BRep_Tool::Pnt(TopExp::LastVertex(e, true));
BRepLib_MakeEdge ee(LastPnt, pp);
WW.Add(ee);
LastPnt = pp;
}
else
{
// the path is closed
// -> since met BndEdge2, end of borders on BndFace
Fin = true;
BRepLib_MakeEdge ee(LastPnt, BndPnt2);
WW.Add(ee);
LastPnt = BndPnt2;
}
if (explo.More())
{
explo.Next();
if (explo.Current().IsNull())
{
explo.Init(BndWire);
}
}
else
{
explo.Init(BndWire);
}
}
BRepLib_MakeEdge e3(BndPnt2, myFirstPnt);
WW.Add(e3);
}
}
// ---Construction of the profile
// Explore the wire provided by the user
// BRepTools_WireExplorer : correct order - without repetition <> TopExp : non ordered
BRepTools_WireExplorer EX(myWire);
double ff, ll;
occ::handle<Geom_Curve> FirstCurve = BRep_Tool::Curve(FirstEdge, ff, ll);
if (!FirstEdge.IsSame(LastEdge))
{
TopoDS_Vertex FLVert = TopExp::LastVertex(FirstEdge, true);
gp_Pnt FLPnt = BRep_Tool::Pnt(FLVert);
BRepLib_MakeEdge ef(FirstCurve, myFirstPnt, FLPnt);
WW.Add(ef);
for (; EX.More(); EX.Next())
{
const TopoDS_Edge& E = EX.Current();
if (E.IsSame(FirstEdge))
{
break;
}
}
EX.Next();
for (; EX.More(); EX.Next())
{
const TopoDS_Edge& E = EX.Current();
if (!E.IsSame(LastEdge))
{
WW.Add(E);
}
else
{
break;
}
}
occ::handle<Geom_Curve> LastCurve = BRep_Tool::Curve(LastEdge, ff, ll);
TopoDS_Vertex LFVert = TopExp::FirstVertex(LastEdge, true);
gp_Pnt LFPnt = BRep_Tool::Pnt(LFVert);
BRepLib_MakeEdge el(LastCurve, LFPnt, myLastPnt);
WW.Add(el);
}
else
{
// only one edge : particular processing
double fpar = IntPar(FirstCurve, myFirstPnt);
double lpar = IntPar(FirstCurve, myLastPnt);
occ::handle<Geom_Curve> c;
if (fpar > lpar)
{
c = FirstCurve->Reversed();
}
else
{
c = FirstCurve;
}
BRepLib_MakeEdge ef(c, myFirstPnt, myLastPnt);
WW.Add(ef);
}
BRepLib_MakeFace f(myPln->Pln(), WW, true);
TopoDS_Face fac = TopoDS::Face(f.Shape());
if (!BRepAlgo::IsValid(fac))
{
ProfileOK = false;
return ProfileOK;
}
if (Concavite != 3)
{
// if concave : face is OK
Prof = fac;
}
else
{
// if not concave
// CheckPnt : point slightly inside the material side
// Bndface : face/cut of the bounding box in the plane of the profile
BRepTopAdaptor_FClass2d Cl(fac, BRep_Tool::Tolerance(fac));
double u, v;
ElSLib::Parameters(myPln->Pln(), CheckPnt, u, v);
gp_Pnt2d checkpnt2d(u, v);
if (Cl.Perform(checkpnt2d, true) == TopAbs_OUT)
{
// If face is not the correct part of BndFace take the complementary
BRepAlgoAPI_Cut c(BndFace, fac);
TopExp_Explorer exp(c.Shape(), TopAbs_WIRE);
const TopoDS_Wire& w = TopoDS::Wire(exp.Current());
BRepLib_MakeFace ffx(w);
Prof = TopoDS::Face(ffx.Shape());
}
else
{
// If face is the correct part of BndFace : face is OK
Prof = fac;
}
}
if (!BRepAlgo::IsValid(Prof))
{
ProfileOK = false;
return ProfileOK;
}
return ProfileOK;
}
//=======================================================================
// function : NoSlidingProfile
// purpose : construction of the face profile in case of sliding
//=======================================================================
bool BRepFeat_RibSlot::NoSlidingProfile(TopoDS_Face& Prof,
const bool RevolRib,
const double myTol,
int& Concavite,
const occ::handle<Geom_Plane>& myPln,
const double bnd,
const TopoDS_Face& BndFace,
const gp_Pnt& CheckPnt,
const TopoDS_Face&, // FirstFace,
const TopoDS_Face&, // LastFace,
const TopoDS_Vertex&, // FirstVertex,
const TopoDS_Vertex&, // LastVertex,
const TopoDS_Edge& FirstEdge,
const TopoDS_Edge& LastEdge,
const bool OnFirstFace,
const bool OnLastFace)
{
bool ProfileOK = true;
double l1, f1, f2, l2; //, p;
TopoDS_Vertex theFV;
theFV.Nullify();
gp_Pnt theFirstpoint;
TopoDS_Edge theLastEdge;
theLastEdge.Nullify();
gp_Pnt firstpoint, lastpoint; //, pp1, pp2;
gp_Vec firstvect, lastvect;
TopoDS_Wire w;
BRep_Builder BB;
BB.MakeWire(w);
// gp_Pnt p1, p3;
TopoDS_Edge FalseFirstEdge, FalseLastEdge, FalseOnlyOne;
occ::handle<Geom_Curve> FirstCurve = BRep_Tool::Curve(FirstEdge, f1, l1);
occ::handle<Geom_Curve> LastCurve = BRep_Tool::Curve(LastEdge, f2, l2);
occ::handle<Geom_Line> firstln, lastln;
FirstCurve->D1(f1, firstpoint, firstvect);
lastln = new Geom_Line(firstpoint, -firstvect);
LastCurve->D1(l2, lastpoint, lastvect);
firstln = new Geom_Line(lastpoint, lastvect);
gp_Pnt Pt;
occ::handle<Geom2d_Curve> ln2d1 = GeomAPI::To2d(firstln, myPln->Pln());
occ::handle<Geom2d_Curve> ln2d2 = GeomAPI::To2d(lastln, myPln->Pln());
Geom2dAPI_InterCurveCurve inter(ln2d1, ln2d2, Precision::Confusion());
bool TestOK = true;
if (RevolRib)
{
gp_Dir d1, d2;
d1 = firstln->Position().Direction();
d2 = lastln->Position().Direction();
if (d1.IsOpposite(d2, myTol))
{
double par1 = ElCLib::Parameter(firstln->Lin(), myFirstPnt);
double par2 = ElCLib::Parameter(lastln->Lin(), myLastPnt);
if (par1 >= myTol || par2 >= myTol)
{
Concavite = 2; // parallel and concave
}
}
if (d1.IsEqual(d2, myTol))
{
if (Concavite == 3)
{
TestOK = false;
}
}
}
if (TestOK)
{
if (inter.NbPoints() > 0)
{
gp_Pnt2d P = inter.Point(1);
myPln->D0(P.X(), P.Y(), Pt);
double par = IntPar(firstln, Pt);
if (par > 0)
{
Concavite = 1; // concave
}
}
}
// ---Construction of the face profile
if (Concavite == 3)
{
if (OnFirstFace)
{
double f, l;
FalseFirstEdge = FirstEdge;
EdgeExtention(FalseFirstEdge, bnd, true);
const TopoDS_Vertex& vv1 = TopExp::FirstVertex(FalseFirstEdge, true);
firstpoint = BRep_Tool::Pnt(vv1);
occ::handle<Geom_Curve> cc = BRep_Tool::Curve(FalseFirstEdge, f, l);
cc->D1(f, firstpoint, firstvect);
lastln = new Geom_Line(firstpoint, -firstvect);
if (FirstEdge.IsSame(LastEdge))
{
FalseOnlyOne = FalseFirstEdge;
}
ln2d2 = GeomAPI::To2d(lastln, myPln->Pln());
}
if (OnLastFace)
{
double f, l;
if (!FirstEdge.IsSame(LastEdge))
{
FalseLastEdge = LastEdge;
}
else
{
if (FalseOnlyOne.IsNull())
{
FalseOnlyOne = LastEdge;
}
FalseLastEdge = FalseOnlyOne;
}
EdgeExtention(FalseLastEdge, bnd, false);
if (FirstEdge.IsSame(LastEdge))
{
FalseOnlyOne = FalseLastEdge;
}
const TopoDS_Vertex& vv2 = TopExp::LastVertex(FalseLastEdge, true);
lastpoint = BRep_Tool::Pnt(vv2);
occ::handle<Geom_Curve> cc = BRep_Tool::Curve(FalseLastEdge, f, l);
cc->D1(l, lastpoint, lastvect);
lastpoint = BRep_Tool::Pnt(vv2);
firstln = new Geom_Line(lastpoint, lastvect);
ln2d1 = GeomAPI::To2d(firstln, myPln->Pln());
}
TopoDS_Edge BndEdge1, BndEdge2;
gp_Pnt BndPnt1, BndPnt2, LastPnt;
TopExp_Explorer expl;
expl.Init(BndFace, TopAbs_WIRE);
BRepTools_WireExplorer explo;
TopoDS_Wire BndWire = TopoDS::Wire(expl.Current());
explo.Init(BndWire);
for (; explo.More(); explo.Next())
{
const TopoDS_Edge& e = TopoDS::Edge(explo.Current());
double first, last;
occ::handle<Geom_Curve> c = BRep_Tool::Curve(e, first, last);
occ::handle<Geom2d_Curve> c2d = GeomAPI::To2d(c, myPln->Pln());
Geom2dAPI_InterCurveCurve intcln1(ln2d1, c2d, Precision::Confusion());
if (intcln1.NbPoints() > 0)
{
gp_Pnt2d p2d = intcln1.Point(1);
gp_Pnt p;
myPln->D0(p2d.X(), p2d.Y(), p);
double parl = IntPar(firstln, p);
double parc = IntPar(c, p);
if (parc >= first && parc <= last && parl >= 0)
{
BndEdge1 = e;
BndPnt1 = p;
}
}
Geom2dAPI_InterCurveCurve intcln2(ln2d2, c2d, Precision::Confusion());
if (intcln2.NbPoints() > 0)
{
gp_Pnt2d p2d = intcln2.Point(1);
gp_Pnt p;
myPln->D0(p2d.X(), p2d.Y(), p);
double parl = IntPar(lastln, p);
double parc = IntPar(c, p);
if (parc >= first && parc <= last && parl >= 0)
{
BndEdge2 = e;
BndPnt2 = p;
}
}
if (!BndEdge1.IsNull() && !BndEdge2.IsNull())
{
break;
}
}
if (BndEdge1.IsNull() || BndEdge2.IsNull())
{
ProfileOK = false;
return ProfileOK;
}
TopoDS_Edge ee1;
if (theLastEdge.IsNull())
{
BRepLib_MakeEdge e1(lastpoint, BndPnt1);
ee1 = TopoDS::Edge(e1.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
BRepLib_MakeVertex v2(BndPnt1);
BRepLib_MakeEdge e1(v1, v2);
ee1 = TopoDS::Edge(e1.Shape());
}
BB.Add(w, ee1);
theLastEdge = ee1;
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(ee1, true);
theFirstpoint = BRep_Tool::Pnt(theFV);
}
if (BndEdge1.IsSame(BndEdge2))
{
TopoDS_Edge ee2, ee3;
if (theLastEdge.IsNull())
{
BRepLib_MakeEdge e2(BndPnt1, BndPnt2);
ee2 = TopoDS::Edge(e2.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
BRepLib_MakeVertex v2(BndPnt2);
BRepLib_MakeEdge e2(v1, v2);
ee2 = TopoDS::Edge(e2.Shape());
}
BB.Add(w, ee2);
theLastEdge = ee2;
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(ee2, true);
theFirstpoint = BRep_Tool::Pnt(theFV);
}
if (theLastEdge.IsNull())
{
BRepLib_MakeEdge e3(BndPnt2, firstpoint);
ee3 = TopoDS::Edge(e3.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
BRepLib_MakeVertex v2(firstpoint);
BRepLib_MakeEdge e3(v1, v2);
ee3 = TopoDS::Edge(e3.Shape());
}
BB.Add(w, ee3);
theLastEdge = ee3;
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(ee3, true);
theFirstpoint = BRep_Tool::Pnt(theFV);
}
}
else
{
explo.Init(BndWire);
for (; explo.More(); explo.Next())
{
const TopoDS_Edge& e = TopoDS::Edge(explo.Current());
if (e.IsSame(BndEdge1))
{
gp_Pnt pp;
pp = BRep_Tool::Pnt(TopExp::LastVertex(e, true));
if (pp.Distance(BndPnt1) > BRep_Tool::Tolerance(e))
{
LastPnt = pp;
}
TopoDS_Edge eee;
if (theLastEdge.IsNull())
{
BRepLib_MakeEdge e2(BndPnt1, LastPnt);
eee = TopoDS::Edge(e2.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
BRepLib_MakeVertex v2(LastPnt);
BRepLib_MakeEdge e2(v1, v2);
eee = TopoDS::Edge(e2.Shape());
}
BB.Add(w, eee);
theLastEdge = eee;
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(eee, true);
theFirstpoint = BRep_Tool::Pnt(theFV);
}
break;
}
}
if (explo.More())
{
explo.Next();
if (explo.Current().IsNull())
{
explo.Init(BndWire);
}
}
else
{
explo.Init(BndWire);
}
bool Fin = false;
while (!Fin)
{
const TopoDS_Edge& e = TopoDS::Edge(explo.Current());
if (!e.IsSame(BndEdge2))
{
gp_Pnt pp;
pp = BRep_Tool::Pnt(TopExp::LastVertex(e, true));
TopoDS_Edge eee1;
if (theLastEdge.IsNull())
{
BRepLib_MakeEdge ee(LastPnt, pp);
eee1 = TopoDS::Edge(ee.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
BRepLib_MakeVertex v2(pp);
BRepLib_MakeEdge ee(v1, v2);
eee1 = TopoDS::Edge(ee.Shape());
}
BB.Add(w, eee1);
theLastEdge = eee1;
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(eee1, true);
theFirstpoint = BRep_Tool::Pnt(theFV);
}
LastPnt = pp;
}
else
{
Fin = true;
TopoDS_Edge eee2;
if (theLastEdge.IsNull())
{
BRepLib_MakeEdge ee(LastPnt, BndPnt2);
eee2 = TopoDS::Edge(ee.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
BRepLib_MakeVertex v2(BndPnt2);
BRepLib_MakeEdge ee(v1, v2);
eee2 = TopoDS::Edge(ee.Shape());
}
BB.Add(w, eee2);
theLastEdge = eee2;
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(eee2, true);
theFirstpoint = BRep_Tool::Pnt(theFV);
}
LastPnt = BndPnt2;
}
if (explo.More())
{
explo.Next();
if (explo.Current().IsNull())
{
explo.Init(BndWire);
}
}
else
{
explo.Init(BndWire);
}
}
TopoDS_Edge eee3;
if (theLastEdge.IsNull())
{
BRepLib_MakeEdge e3(BndPnt2, firstpoint);
eee3 = TopoDS::Edge(e3.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
BRepLib_MakeVertex v2(firstpoint);
BRepLib_MakeEdge e3(v1, v2);
eee3 = TopoDS::Edge(e3.Shape());
}
BB.Add(w, eee3);
theLastEdge = eee3;
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(eee3, true);
theFirstpoint = BRep_Tool::Pnt(theFV);
}
}
}
if (Concavite == 1)
{
TopoDS_Edge eee4;
if (theLastEdge.IsNull())
{
BRepLib_MakeEdge e(Pt, firstpoint);
eee4 = TopoDS::Edge(e.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
BRepLib_MakeVertex v2(firstpoint);
BRepLib_MakeEdge e(v1, v2);
eee4 = TopoDS::Edge(e.Shape());
}
BB.Add(w, eee4);
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(eee4, true);
theFirstpoint = BRep_Tool::Pnt(theFV);
}
theLastEdge = eee4;
}
if (FirstEdge.IsSame(LastEdge))
{
if (!myLFMap.IsBound(FirstEdge))
{
NCollection_List<TopoDS_Shape> thelist;
myLFMap.Bind(FirstEdge, thelist);
}
if (OnFirstFace || OnLastFace)
{
TopoDS_Edge theEdge;
double f, l;
occ::handle<Geom_Curve> cc = BRep_Tool::Curve(FalseOnlyOne, f, l);
if (!theLastEdge.IsNull())
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
TopoDS_Vertex v2;
const gp_Pnt& pp = BRep_Tool::Pnt(TopExp::LastVertex(FalseOnlyOne, true));
if (!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol)
{
v2 = theFV;
}
else
{
v2 = TopExp::LastVertex(FalseOnlyOne, true);
}
BRepLib_MakeEdge e(cc, v1, v2);
theEdge = TopoDS::Edge(e.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::FirstVertex(FalseOnlyOne, true);
TopoDS_Vertex v2;
const gp_Pnt& pp = BRep_Tool::Pnt(TopExp::LastVertex(FalseOnlyOne, true));
if (!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol)
{
v2 = theFV;
}
else
{
v2 = TopExp::LastVertex(FalseOnlyOne, true);
}
BRepLib_MakeEdge e(cc, v1, v2);
theEdge = TopoDS::Edge(e.Shape());
}
myLFMap(FirstEdge).Append(theEdge);
BB.Add(w, theEdge);
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(theEdge, true);
}
theLastEdge = theEdge;
}
else
{
double f, l;
occ::handle<Geom_Curve> cc = BRep_Tool::Curve(FirstEdge, f, l);
TopoDS_Edge theEdge;
if (!theLastEdge.IsNull())
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
TopoDS_Vertex v2;
// Attention case Wire Reversed -> LastVertex without true
const gp_Pnt& pp = BRep_Tool::Pnt(TopExp::LastVertex(FirstEdge));
if (!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol)
{
v2 = theFV;
}
else
{
v2 = TopExp::LastVertex(FirstEdge);
}
BRepLib_MakeEdge e(cc, v1, v2);
theEdge = TopoDS::Edge(e.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::FirstVertex(FirstEdge, true);
TopoDS_Vertex v2;
const gp_Pnt& pp = BRep_Tool::Pnt(TopExp::LastVertex(FirstEdge, true));
if (!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol)
{
v2 = theFV;
}
else
{
v2 = TopExp::LastVertex(FirstEdge, true);
}
BRepLib_MakeEdge e(cc, v1, v2);
theEdge = TopoDS::Edge(e.Shape());
}
myLFMap(FirstEdge).Append(theEdge);
BB.Add(w, theEdge);
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(theEdge, true);
}
theLastEdge = theEdge;
}
}
else
{
if (!myLFMap.IsBound(FirstEdge))
{
NCollection_List<TopoDS_Shape> thelist1;
myLFMap.Bind(FirstEdge, thelist1);
}
if (!OnFirstFace)
{
TopoDS_Edge theEdge;
double f, l;
occ::handle<Geom_Curve> cc = BRep_Tool::Curve(FirstEdge, f, l);
if (!theLastEdge.IsNull())
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
const TopoDS_Vertex& v2 = TopExp::LastVertex(FirstEdge, true);
BRepLib_MakeEdge e(cc, v1, v2);
theEdge = TopoDS::Edge(e.Shape());
}
else
{
theEdge = FirstEdge;
}
myLFMap(FirstEdge).Append(theEdge);
BB.Add(w, theEdge);
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(theEdge, true);
}
theLastEdge = theEdge;
}
else
{
TopoDS_Edge theEdge;
double f, l;
occ::handle<Geom_Curve> cc = BRep_Tool::Curve(FalseFirstEdge, f, l);
if (!theLastEdge.IsNull())
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
const TopoDS_Vertex& v2 = TopExp::LastVertex(FalseFirstEdge, true);
BRepLib_MakeEdge e(cc, v1, v2);
theEdge = TopoDS::Edge(e.Shape());
}
else
{
theEdge = FalseFirstEdge;
}
myLFMap(FirstEdge).Append(theEdge);
BB.Add(w, theEdge);
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(theEdge, true);
}
theLastEdge = theEdge;
}
BRepTools_WireExplorer ex(myWire);
for (; ex.More(); ex.Next())
{
const TopoDS_Edge& E = ex.Current();
if (E.IsSame(FirstEdge))
{
break;
}
}
ex.Next();
for (; ex.More(); ex.Next())
{
const TopoDS_Edge& E = ex.Current();
if (!E.IsSame(LastEdge))
{
if (!myLFMap.IsBound(E))
{
NCollection_List<TopoDS_Shape> thelist2;
myLFMap.Bind(E, thelist2);
}
TopoDS_Edge eee;
double f, l;
occ::handle<Geom_Curve> cc = BRep_Tool::Curve(E, f, l);
if (!theLastEdge.IsNull())
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
const TopoDS_Vertex& v2 = TopExp::LastVertex(E, true);
BRepLib_MakeEdge e(cc, v1, v2);
eee = TopoDS::Edge(e.Shape());
}
else
{
eee = E;
}
myLFMap(E).Append(eee);
BB.Add(w, eee);
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(eee, true);
}
theLastEdge = eee;
}
else
{
break;
}
}
if (!OnLastFace)
{
if (!FirstEdge.IsSame(LastEdge))
{
const TopoDS_Edge& edg = TopoDS::Edge(ex.Current());
if (!myLFMap.IsBound(edg))
{
NCollection_List<TopoDS_Shape> thelist3;
myLFMap.Bind(edg, thelist3);
}
TopoDS_Edge eee;
double f, l;
occ::handle<Geom_Curve> cc = BRep_Tool::Curve(edg, f, l);
if (!theLastEdge.IsNull())
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
TopoDS_Vertex v2;
const gp_Pnt& pp = BRep_Tool::Pnt(TopExp::LastVertex(edg, true));
if (!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol)
{
v2 = theFV;
}
else
{
v2 = TopExp::LastVertex(edg, true);
}
BRepLib_MakeEdge e(cc, v1, v2);
eee = TopoDS::Edge(e.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::FirstVertex(edg, true);
TopoDS_Vertex v2;
const gp_Pnt& pp = BRep_Tool::Pnt(TopExp::LastVertex(edg, true));
if (!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol)
{
v2 = theFV;
}
else
{
v2 = TopExp::LastVertex(edg, true);
}
BRepLib_MakeEdge e(cc, v1, v2);
eee = TopoDS::Edge(e.Shape());
}
myLFMap(edg).Append(eee);
BB.Add(w, eee);
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(eee, true);
}
theLastEdge = eee;
}
else
{
TopoDS_Edge eee;
double f, l;
if (!myLFMap.IsBound(LastEdge))
{
NCollection_List<TopoDS_Shape> thelist4;
myLFMap.Bind(LastEdge, thelist4);
}
occ::handle<Geom_Curve> cc = BRep_Tool::Curve(FalseOnlyOne, f, l);
if (!theLastEdge.IsNull())
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
TopoDS_Vertex v2;
const gp_Pnt& pp = BRep_Tool::Pnt(TopExp::LastVertex(FalseOnlyOne, true));
if (!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol)
{
v2 = theFV;
}
else
{
v2 = TopExp::LastVertex(FalseOnlyOne, true);
}
BRepLib_MakeEdge e(cc, v1, v2);
eee = TopoDS::Edge(e.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::FirstVertex(FalseOnlyOne, true);
TopoDS_Vertex v2;
const gp_Pnt& pp = BRep_Tool::Pnt(TopExp::LastVertex(FalseOnlyOne, true));
if (!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol)
{
v2 = theFV;
}
else
{
v2 = TopExp::LastVertex(FalseOnlyOne, true);
}
BRepLib_MakeEdge e(cc, v1, v2);
eee = TopoDS::Edge(e.Shape());
}
myLFMap(LastEdge).Append(eee);
BB.Add(w, eee);
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(eee, true);
}
theLastEdge = eee;
}
}
else
{
TopoDS_Edge eee;
double f, l;
if (!myLFMap.IsBound(LastEdge))
{
NCollection_List<TopoDS_Shape> thelist5;
myLFMap.Bind(LastEdge, thelist5);
}
occ::handle<Geom_Curve> cc = BRep_Tool::Curve(FalseLastEdge, f, l);
if (!theLastEdge.IsNull())
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
TopoDS_Vertex v2;
const gp_Pnt& pp = BRep_Tool::Pnt(TopExp::LastVertex(FalseLastEdge, true));
if (!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol)
{
v2 = theFV;
}
else
{
v2 = TopExp::LastVertex(FalseLastEdge, true);
}
BRepLib_MakeEdge e(cc, v1, v2);
eee = TopoDS::Edge(e.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::FirstVertex(FalseLastEdge, true);
TopoDS_Vertex v2;
const gp_Pnt& pp = BRep_Tool::Pnt(TopExp::LastVertex(FalseLastEdge, true));
if (!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol)
{
v2 = theFV;
}
else
{
v2 = TopExp::LastVertex(FalseLastEdge, true);
}
BRepLib_MakeEdge e(cc, v1, v2);
eee = TopoDS::Edge(e.Shape());
}
myLFMap(LastEdge).Append(eee);
BB.Add(w, eee);
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(eee, true);
}
theLastEdge = eee;
}
}
if (Concavite == 1)
{
TopoDS_Edge eef;
if (theLastEdge.IsNull())
{
BRepLib_MakeEdge ef(lastpoint, Pt);
eef = TopoDS::Edge(ef.Shape());
}
else
{
const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge, true);
BRepLib_MakeVertex vv(Pt);
TopoDS_Vertex v2 = TopoDS::Vertex(vv.Shape());
if (!theFV.IsNull() && Pt.Distance(theFirstpoint) <= myTol)
{
v2 = theFV;
}
BRepLib_MakeEdge ef(v1, v2);
eef = TopoDS::Edge(ef.Shape());
}
BB.Add(w, eef);
if (theFV.IsNull())
{
theFV = TopExp::FirstVertex(eef, true);
}
theLastEdge = eef;
}
if (Concavite == 2)
{
BRepLib_MakeEdge ee(lastpoint, firstpoint);
const TopoDS_Edge& e = ee.Edge();
BB.Add(w, e);
}
w.Closed(BRep_Tool::IsClosed(w));
BRepLib_MakeFace fa(myPln->Pln(), w, true);
TopoDS_Face fac = TopoDS::Face(fa.Shape());
if (!BRepAlgo::IsValid(fac))
{
ProfileOK = false;
return ProfileOK;
}
// if(!Concavite) {
if (Concavite == 3)
{
BRepTopAdaptor_FClass2d Cl(fac, BRep_Tool::Tolerance(fac));
double u, v;
ElSLib::Parameters(myPln->Pln(), CheckPnt, u, v);
gp_Pnt2d checkpnt2d(u, v);
if (Cl.Perform(checkpnt2d, true) == TopAbs_OUT)
{
BRepAlgoAPI_Cut c(BndFace, fac);
TopExp_Explorer exp(c.Shape(), TopAbs_WIRE);
UpdateDescendants(c, c.Shape(), false);
const TopoDS_Wire& ww = TopoDS::Wire(exp.Current());
BRepLib_MakeFace ff(ww);
Prof = TopoDS::Face(ff.Shape());
}
else
{
Prof = fac;
}
}
else
{
Prof = fac;
}
if (!BRepAlgo::IsValid(Prof))
{
ProfileOK = false;
return ProfileOK;
}
return ProfileOK;
}
//=================================================================================================
void BRepFeat_RibSlot::UpdateDescendants(const BRepAlgoAPI_BooleanOperation& aBOP,
const TopoDS_Shape& S,
const bool SkipFace)
{
NCollection_DataMap<TopoDS_Shape, NCollection_List<TopoDS_Shape>, TopTools_ShapeMapHasher>::
Iterator itdm;
NCollection_List<TopoDS_Shape>::Iterator it, it2;
NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher>::Iterator itm;
TopExp_Explorer exp;
for (itdm.Initialize(myMap); itdm.More(); itdm.Next())
{
const TopoDS_Shape& orig = itdm.Key();
if (SkipFace && orig.ShapeType() == TopAbs_FACE)
{
continue;
}
NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> newdsc;
// if (itdm.Value().IsEmpty()) {myMap.ChangeFind(orig).Append(orig);}
for (it.Initialize(itdm.Value()); it.More(); it.Next())
{
const TopoDS_Shape& sh = it.Value();
if (sh.ShapeType() != TopAbs_FACE)
{
continue;
}
const TopoDS_Face& fdsc = TopoDS::Face(it.Value());
for (exp.Init(S, TopAbs_FACE); exp.More(); exp.Next())
{
if (exp.Current().IsSame(fdsc))
{ // preserved
newdsc.Add(fdsc);
break;
}
}
if (!exp.More())
{
BRepAlgoAPI_BooleanOperation* pBOP = (BRepAlgoAPI_BooleanOperation*)&aBOP;
const NCollection_List<TopoDS_Shape>& aLM = pBOP->Modified(fdsc);
it2.Initialize(aLM);
for (; it2.More(); it2.Next())
{
const TopoDS_Shape& aS = it2.Value();
newdsc.Add(aS);
}
}
}
myMap.ChangeFind(orig).Clear();
for (itm.Initialize(newdsc); itm.More(); itm.Next())
{
// check the belonging to the shape...
for (exp.Init(S, TopAbs_FACE); exp.More(); exp.Next())
{
if (exp.Current().IsSame(itm.Key()))
{
// const TopoDS_Shape& sh = itm.Key();
myMap.ChangeFind(orig).Append(itm.Key());
break;
}
}
}
}
}