1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: NMTTools_PaveFiller_2.cxx
21 // Created: Mon Dec 8 12:02:56 2003
22 // Author: Peter KURNEV
26 #include <NMTTools_PaveFiller.ixx>
28 #include <Precision.hxx>
32 #include <Geom_Curve.hxx>
34 #include <TopAbs_Orientation.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Vertex.hxx>
40 #include <BRep_Builder.hxx>
41 #include <BRep_Tool.hxx>
43 #include <BOPTools_Pave.hxx>
44 #include <BOPTools_PaveSet.hxx>
45 #include <BOPTools_CArray1OfVEInterference.hxx>
46 #include <BOPTools_VEInterference.hxx>
48 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
50 #include <NMTDS_ShapesDataStructure.hxx>
52 #include <BOPTools_IndexedMapOfCoupleOfInteger.hxx>
53 #include <BOPTools_CoupleOfInteger.hxx>
55 //=======================================================================
56 // function: PrepareEdges
58 //=======================================================================
59 void NMTTools_PaveFiller::PrepareEdges()
61 Standard_Integer i, nV, ii, aNBSuc, ip, aNbShapesObject;
63 TopAbs_Orientation anOr;
67 aNbShapesObject=myDS->NumberOfShapesOfTheObject();
68 for (i=1; i<=myNbSources; ++i) {
69 if (myDS->GetShapeType(i)==TopAbs_EDGE) {
70 aE=TopoDS::Edge(myDS->Shape(i));
72 if (BRep_Tool::Degenerated(aE)){
76 BOPTools_PaveSet& aPaveSet=myPavePool(myDS->RefEdge(i));
79 aNBSuc=myDS->NumberOfSuccessors(i);
80 for (ii=1; ii <=aNBSuc; ii++) {
81 nV=myDS->GetSuccessor(i, ii);
82 anOr=myDS->GetOrientation(i, ii);
83 aV=TopoDS::Vertex(myDS->Shape(nV));
85 aT=BRep_Tool::Parameter(aV, aE);
89 aV=TopoDS::Vertex(myDS->Shape(ip));
90 aV.Orientation(anOr);// XX ? if the edge is closed it'll be amazing result
94 BOPTools_Pave aPave(nV, aT);
95 aPaveSet.Append (aPave);
100 //=======================================================================
101 // function: PerformVE
103 //=======================================================================
104 void NMTTools_PaveFiller::PerformVE()
106 myIsDone=Standard_False;
108 Standard_Boolean bJustAddInterference;
109 Standard_Integer n1, n2, anIndexIn, aFlag, aWhat, aWith, aNbVEs, aBlockLength, iSDV, nV1;
113 BOPTools_IndexedMapOfCoupleOfInteger aSnareMap;
114 BOPTools_CoupleOfInteger aCouple;
116 BOPTools_CArray1OfVEInterference& aVEs=myIntrPool->VEInterferences();
118 myDSIt.Initialize (TopAbs_VERTEX, TopAbs_EDGE);
120 // BlockLength correction
121 aNbVEs=ExpectedPoolLength();
122 aBlockLength=aVEs.BlockLength();
123 if (aNbVEs > aBlockLength) {
124 aVEs.SetBlockLength(aNbVEs);
127 for (; myDSIt.More(); myDSIt.Next()) {
128 myDSIt.Current(n1, n2, bJustAddInterference);
130 if (! myIntrPool->IsComputed(n1, n2)) {
131 if (! IsSuccesstorsComputed(n1, n2)) {
135 SortTypes(aWhat, aWith);
137 if(bJustAddInterference) {
138 myIntrPool->AddInterference(aWhat, aWith, BooleanOperations_VertexEdge, anIndexIn);
142 aE2=TopoDS::Edge(myDS->Shape(aWith));
144 if (BRep_Tool::Degenerated(aE2)){
149 aV1=TopoDS::Vertex(myDS->Shape(aWhat));
151 iSDV=FindSDVertex(aWhat);
154 aV1=TopoDS::Vertex(myDS->Shape(nV1));
157 aFlag=myContext.ComputeVE (aV1, aE2, aT);
161 // Add Interference to the Pool
162 BOPTools_VEInterference anInterf (aWhat, aWith, aT);
163 anIndexIn=aVEs.Append(anInterf);
165 // Add Pave to the Edge's myPavePool
166 aCouple.SetCouple(nV1, aWith);
167 if (!aSnareMap.Contains(aCouple)){
168 aSnareMap.Add(aCouple);
170 BOPTools_Pave aPave(nV1, aT, BooleanOperations_VertexEdge);
171 aPave.SetInterference(anIndexIn);
172 BOPTools_PaveSet& aPaveSet= myPavePool(myDS->RefEdge(aWith));
173 aPaveSet.Append(aPave);
176 // State for the Vertex in DS;
177 myDS->SetState (aWhat, BooleanOperations_ON);
178 // Insert Vertex in Interference Object
179 BOPTools_VEInterference& aVE=aVEs(anIndexIn);
180 aVE.SetNewShape(aWhat);
182 myIntrPool->AddInterference(aWhat, aWith, BooleanOperations_VertexEdge, anIndexIn);
186 myIsDone=Standard_True;
193 // Some of Edges can be [Semi] Infinite. Such Edges have no
194 // vertices on correspondant INF ends. So we must provide
195 // these vertices formally (to obtain Shrunk Ranges for e.g).
196 // In reality this vertex(-es) does not belong to the INF Edge.
197 // It just has reference in the DS.
198 // PKV Tue Apr 23 10:21:45 2002
200 Standard_Real aT1, aT2, aTolE;
201 Standard_Boolean bInf1, bInf2;
205 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
207 aTolE=BRep_Tool::Tolerance(aE);
208 Handle(Geom_Curve) aC3D=BRep_Tool::Curve (aE, aT1, aT2);
209 bInf1=Precision::IsNegativeInfinite(aT1);
210 bInf2=Precision::IsPositiveInfinite(aT2);
214 aBB.MakeVertex(aVx, aPx, aTolE);
215 myDS->InsertShapeAndAncestorsSuccessors(aVx, anASSeq);
216 nV=myDS->NumberOfInsertedShapes();
217 BOPTools_Pave aPave(nV, aT1);
218 aPaveSet.Append (aPave);
223 aBB.MakeVertex(aVx, aPx, aTolE);
224 myDS->InsertShapeAndAncestorsSuccessors(aVx, anASSeq);
225 nV=myDS->NumberOfInsertedShapes();
226 BOPTools_Pave aPave(nV, aT2);
227 aPaveSet.Append (aPave);