Salome HOME
Update mail address
[modules/geom.git] / src / NMTTools / NMTTools_PaveFiller_1.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_1.cxx
21 // Created:     Mon Dec  8 11:47:55 2003
22 // Author:      Peter KURNEV
23 //              <pkv@irinox>
24
25
26 #include <NMTTools_PaveFiller.ixx>
27
28 #include <TColStd_IndexedMapOfInteger.hxx>
29
30 #include <TopoDS.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Vertex.hxx>
33
34 #include <TopTools_ListOfShape.hxx>
35
36 #include <IntTools_Tools.hxx>
37 #include <BOPTools_VVInterference.hxx>
38 #include <BOPTools_CArray1OfVVInterference.hxx>
39 #include <BOPTools_VVInterference.hxx>
40 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
41 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
42
43 #include <NMTDS_ShapesDataStructure.hxx>
44 #include <NMTTools_Tools.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
46
47
48   
49 //=======================================================================
50 // function: PerformVV
51 // purpose: 
52 //=======================================================================
53   void NMTTools_PaveFiller::PerformVV() 
54 {
55   myIsDone=Standard_False;
56   //
57   Standard_Integer n1, n2,anIndexIn, aFlag, aWhat, aWith, aNbVVs, aBlockLength;
58   Standard_Boolean bJustAddInterference;
59   //
60   BOPTools_CArray1OfVVInterference& aVVs=myIntrPool->VVInterferences();
61   //
62   // BlockLength correction
63   aNbVVs=ExpectedPoolLength();
64   aBlockLength=aVVs.BlockLength();
65   if (aNbVVs > aBlockLength) {
66     aVVs.SetBlockLength(aNbVVs);
67   }
68   //
69   // V/V  BooleanOperations_VertexVertex
70   myDSIt.Initialize(TopAbs_VERTEX, TopAbs_VERTEX);
71   //
72   for (; myDSIt.More(); myDSIt.Next()) {
73     myDSIt.Current(n1, n2, bJustAddInterference);
74     //
75     if (!myIntrPool->IsComputed(n1, n2)) {
76       anIndexIn=0;
77       aWhat=n1;
78       aWith=n2;
79       SortTypes(aWhat, aWith);
80       if (!bJustAddInterference) {
81         const TopoDS_Shape& aS1=myDS->GetShape(aWhat);
82         const TopoDS_Shape& aS2=myDS->GetShape(aWith);
83         //
84         const TopoDS_Vertex& aV1=TopoDS::Vertex(aS1);
85         const TopoDS_Vertex& aV2=TopoDS::Vertex(aS2);
86         aFlag=IntTools_Tools::ComputeVV (aV1, aV2);
87         //
88         if (!aFlag) {
89           BOPTools_VVInterference anInterf (aWhat, aWith);
90           anIndexIn=aVVs.Append(anInterf);
91         }
92       }
93       myIntrPool->AddInterference(aWhat, aWith, BooleanOperations_VertexVertex, anIndexIn);
94     }
95   }
96   myIsDone=Standard_True;
97 }
98 //=======================================================================
99 // function: PerformNewVertices
100 // purpose: 
101 //=======================================================================
102   void NMTTools_PaveFiller::PerformNewVertices() 
103 {
104   myIsDone=Standard_False;
105   //
106   Standard_Integer i, aNb, anIndex1, anIndex2, aNewShape;
107   TopoDS_Vertex aNewVertex;
108   BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
109   //
110   Standard_Integer aNbChains, j, aNbV, aIdV, aNbL;
111   TColStd_IndexedMapOfInteger aMapWhole;
112   BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMapChains;//aMCV
113   TopTools_ListOfShape aLV;
114   TopTools_IndexedMapOfShape aM;
115   //
116   // 1. VV Interferences
117   BOPTools_CArray1OfVVInterference& VVs=myIntrPool->VVInterferences();
118   //
119   NMTTools_Tools::FindChains(VVs, aMapChains);
120   //
121   aNbChains=aMapChains.Extent();
122   for (i=1; i<=aNbChains; ++i) {
123     const TColStd_IndexedMapOfInteger& aChain=aMapChains(i);
124     //
125     aM.Clear();
126     aLV.Clear();
127     aNbV=aChain.Extent();
128     for (j=1; j<=aNbV; ++j) {
129       aIdV=aChain(j);
130       const TopoDS_Shape& aV=myDS->Shape(aIdV);
131       if (!aM.Contains(aV)) {
132         aM.Add(aV);
133         aLV.Append(aV);
134       }
135     }
136     //
137     aNbL=aLV.Extent();
138     if (aNbL==1){
139       aNewShape=aChain(1);
140     }
141     else if (aNbL>1) {
142       //
143       // Make new Vertex
144       NMTTools_Tools::MakeNewVertex(aLV, aNewVertex);
145       // Insert New Vertex in DS;
146       // aNewShape is # of DS-line, where aNewVertex is kept
147       myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
148       aNewShape=myDS->NumberOfInsertedShapes();
149       //
150       // State of New Vertex is ON
151       myDS->SetState (aNewShape, BooleanOperations_ON);
152     }
153     //
154     // Insert New Vertex in Interference
155     aNb=VVs.Extent();
156     for (j=1; j<=aNb; ++j) {
157       BOPTools_VVInterference& VV=VVs(j);
158       anIndex1=VV.Index1();
159       anIndex2=VV.Index2();
160       if (aChain.Contains(anIndex1) || aChain.Contains(anIndex2)) {
161         VV.SetNewShape(aNewShape);
162       }
163     }
164   }
165   myIsDone=Standard_True;
166 }
167
168 //=======================================================================
169 // function: FindSDVertex
170 // purpose: 
171 //=======================================================================
172   Standard_Integer NMTTools_PaveFiller::FindSDVertex(const Standard_Integer nV)const
173 {
174   Standard_Integer i, aNb, anIndex1, anIndex2, aNewShape=0;
175
176   BOPTools_CArray1OfVVInterference& VVs=myIntrPool->VVInterferences();
177   aNb=VVs.Extent();
178   
179   for (i=1; i<=aNb; i++) {
180     const BOPTools_VVInterference& VV=VVs(i);
181     anIndex1=VV.Index1();
182     anIndex2=VV.Index2();
183     if (nV==anIndex1 || nV==anIndex2) {
184       aNewShape=VV.NewShape();
185       return aNewShape;
186     }
187   }
188   return aNewShape;
189 }