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