Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/geom.git] / src / NMTTools / NMTTools_PaveFiller_7.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
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.
8 // 
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File:        NMTTools_PaveFiller_7.cxx
21 // Created:     Thu Dec 18 15:14:55 2003
22 // Author:      Peter KURNEV
23 //              <pkv@irinox>
24
25
26 #include <NMTTools_PaveFiller.ixx>
27
28 #include <TopoDS_Vertex.hxx>
29 #include <TopoDS_Edge.hxx>
30 #include <TopoDS.hxx>
31
32 #include <NMTDS_ShapesDataStructure.hxx>
33 #include <TopAbs_Orientation.hxx>
34 #include <BOPTools_ListOfPaveBlock.hxx>
35 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
36 #include <BOPTools_PaveBlock.hxx>
37 #include <BOPTools_Pave.hxx>
38 #include <BOPTools_Tools.hxx>
39 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
40 #include <BRep_Tool.hxx>
41 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
42 #include <BOPTools_SSInterference.hxx>
43 #include <BOPTools_CArray1OfSSInterference.hxx>
44 #include <TopExp_Explorer.hxx>
45 #include <TopoDS_Shape.hxx>
46 #include <TopExp.hxx>
47 #include <TColStd_IndexedMapOfInteger.hxx>
48
49 //=======================================================================
50 // function: MakeSplitEdges
51 // purpose: 
52 //=======================================================================
53   void NMTTools_PaveFiller::MakeSplitEdges()
54 {
55   myIsDone=Standard_False;
56   //
57   Standard_Boolean bIsNewVertex1, bIsNewVertex2;
58   Standard_Integer i, aNbS, nV1, nV2, aNbPaveBlocks, aNewShapeIndex;
59   Standard_Real    t1, t2;
60   TopAbs_Orientation anOri;
61   TopoDS_Edge aE, aESplit;
62   TopoDS_Vertex aV1, aV2;
63   //
64   aNbS=myDS->NumberOfShapesOfTheObject();
65   for (i=1; i<=aNbS; ++i) {
66     if (myDS->GetShapeType(i) != TopAbs_EDGE)
67       continue;
68     //
69     // Original Edge
70     aE=TopoDS::Edge(myDS->Shape(i));
71     if (BRep_Tool::Degenerated(aE)){
72       continue;
73     }
74     //
75     anOri=aE.Orientation(); 
76     aE.Orientation(TopAbs_FORWARD);
77     //
78     // Making Split Edges
79     //
80     // Split Set for the Original Edge i
81     BOPTools_ListOfPaveBlock& aSplitEdges=mySplitShapesPool(myDS->RefEdge(i));
82     BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSplitEdges);
83     //
84     aNbPaveBlocks=aSplitEdges.Extent();
85   
86     for (; aPBIt.More(); aPBIt.Next()) {
87       BOPTools_PaveBlock& aPB=aPBIt.Value();
88       // aPave1
89       const BOPTools_Pave& aPave1=aPB.Pave1();
90       nV1=aPave1.Index();
91       t1=aPave1.Param();
92       aV1=TopoDS::Vertex(myDS->GetShape(nV1));
93       aV1.Orientation(TopAbs_FORWARD);
94       // aPave2
95       const BOPTools_Pave& aPave2=aPB.Pave2();
96       nV2=aPave2.Index();
97       t2=aPave2.Param();
98       aV2=TopoDS::Vertex(myDS->GetShape(nV2));
99       aV2.Orientation(TopAbs_REVERSED);
100       //xx
101       if (aNbPaveBlocks==1) {
102         bIsNewVertex1=myDS->IsNewShape (nV1);
103         bIsNewVertex2=myDS->IsNewShape (nV2);
104         if (!bIsNewVertex1 && !bIsNewVertex2) {
105           aPB.SetEdge(i);
106           continue;
107         }
108       }
109       //xx
110       BOPTools_Tools::MakeSplitEdge(aE, aV1, t1, aV2, t2, aESplit);  
111       //
112       // Add Split Part of the Original Edge to the DS
113       BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
114
115       anASSeq.SetNewSuccessor(nV1);
116       anASSeq.SetNewOrientation(aV1.Orientation());
117
118       anASSeq.SetNewSuccessor(nV2);
119       anASSeq.SetNewOrientation(aV2.Orientation());
120       //
121       if (anOri==TopAbs_INTERNAL) {
122         anASSeq.SetNewAncestor(i);
123         aESplit.Orientation(anOri);
124       }
125       //
126       myDS->InsertShapeAndAncestorsSuccessors(aESplit, anASSeq);
127       aNewShapeIndex=myDS->NumberOfInsertedShapes();
128       myDS->SetState(aNewShapeIndex, BooleanOperations_UNKNOWN);
129       //
130       // Fill Split Set for the Original Edge
131       aPB.SetEdge(aNewShapeIndex);
132       //
133     }
134   } 
135   myIsDone=Standard_True;
136 }
137 //=======================================================================
138 // function: UpdateCommonBlocks
139 // purpose: 
140 //=======================================================================
141   void NMTTools_PaveFiller::UpdateCommonBlocks()
142 {
143   myIsDone=Standard_False;
144   //
145   Standard_Integer nE, aNbS,  nSp, nEx, nSpx;
146   NMTTools_ListIteratorOfListOfCommonBlock aCBIt;
147   BOPTools_ListIteratorOfListOfPaveBlock aPBIt;
148   //
149   aNbS=myDS->NumberOfShapesOfTheObject();
150   //
151   for (nE=1; nE<=aNbS; ++nE) {
152     if (myDS->GetShapeType(nE)!=TopAbs_EDGE){
153       continue;
154     }
155     if (BRep_Tool::Degenerated(TopoDS::Edge(myDS->Shape(nE)))){
156       continue;
157     }
158     //
159     NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nE));
160     BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool  (myDS->RefEdge(nE));
161     //
162     aCBIt.Initialize(aLCB);
163     for (; aCBIt.More(); aCBIt.Next()) {
164       NMTTools_CommonBlock& aCB=aCBIt.Value();
165       BOPTools_PaveBlock& aPB=aCB.PaveBlock1(nE);
166       nSp=SplitIndex(aPB);
167       aPB.SetEdge(nSp);
168       //
169       const BOPTools_ListOfPaveBlock& aCBLPB=aCB.PaveBlocks();
170       aPBIt.Initialize(aCBLPB);
171       for (; aPBIt.More(); aPBIt.Next()) {
172         BOPTools_PaveBlock& aPBx=aPBIt.Value();
173         nEx=aPBx.OriginalEdge();
174         if (nEx==nE) {
175           continue;
176         }
177         //
178         nSpx=SplitIndex(aPBx);
179         aPBx.SetEdge(nSpx);
180       }
181       //
182     }
183   }
184 }
185 //=======================================================================
186 // function: SplitIndex
187 // purpose: 
188 //=======================================================================
189   Standard_Integer NMTTools_PaveFiller::SplitIndex(const BOPTools_PaveBlock& aPBx)const 
190 {
191   Standard_Integer anOriginalEdge, anEdgeIndex=0;
192
193   anOriginalEdge=aPBx.OriginalEdge();
194
195   const BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(anOriginalEdge));
196   //
197   BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
198   for (; anIt.More(); anIt.Next()) {
199     BOPTools_PaveBlock& aPB=anIt.Value();
200     if (aPB.IsEqual(aPBx)) {
201       anEdgeIndex=aPB.Edge();
202       return anEdgeIndex;
203     }
204   }
205   return anEdgeIndex;
206
207 //=======================================================================
208 // function: UpdatePaveBlocks
209 // purpose: 
210 //=======================================================================
211   void NMTTools_PaveFiller::UpdatePaveBlocks()
212 {
213   myIsDone=Standard_False;
214   //
215   
216   Standard_Integer i, aNbFFs, nF1, nF2, aNbF, nF, iRankF, nE, nV1, nV2, aNbPB;
217   Standard_Real aT1, aT2;
218   TColStd_IndexedMapOfInteger aMF, aME;
219   TopExp_Explorer aExp;
220   TopoDS_Vertex aV1, aV2;
221   TopoDS_Edge aE;
222   BOPTools_Pave aPave1, aPave2;
223   BOPTools_PaveBlock aPB;
224   //
225   BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
226   //
227   aNbFFs=aFFs.Extent();
228   for (i=1; i<=aNbFFs; ++i) {
229     BOPTools_SSInterference& aFFi=aFFs(i);
230     aFFi.Indices(nF1, nF2);
231     aMF.Add(nF1);
232     aMF.Add(nF2);
233   }
234   //
235   aNbF=aMF.Extent();
236   for(i=1; i<=aNbF; ++i) {
237     nF=aMF(i);
238     iRankF=myDS->Rank(nF);
239     const TopoDS_Shape& aF=myDS->Shape(nF);
240     aExp.Init(aF, TopAbs_EDGE);
241     for(; aExp.More();  aExp.Next()) {
242       aE=TopoDS::Edge(aExp.Current());
243       //
244       if (BRep_Tool::Degenerated(aE)) {
245         continue;
246       }
247       //
248       nE=myDS->ShapeIndex(aE, iRankF);
249       //
250       if (aME.Contains(nE)) {
251         continue;
252       }
253       aME.Add(nE);
254       //
255       BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(nE));
256       aNbPB=aLPB.Extent();
257       if (aNbPB) {
258         continue;
259       }
260       TopExp::Vertices(aE, aV1, aV2);
261       //
262       nV1=myDS->ShapeIndex(aV1, iRankF);
263       aT1=BRep_Tool::Parameter(aV1, aE);
264       aPave1.SetIndex(nV1);
265       aPave1.SetParam(aT1);
266       //
267       nV2=myDS->ShapeIndex(aV2, iRankF);
268       aT2=BRep_Tool::Parameter(aV2, aE);
269       aPave2.SetIndex(nV2);
270       aPave2.SetParam(aT2);
271       //
272       aPB.SetEdge(nE);
273       aPB.SetOriginalEdge(nE);
274       aPB.SetPave1(aPave1);
275       aPB.SetPave2(aPave2);
276       //
277       aLPB.Append(aPB);
278     }
279   }
280