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