Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/geom.git] / src / NMTTools / NMTTools_PaveFiller_2.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_2.cxx
21 // Created:     Mon Dec  8 12:02:56 2003
22 // Author:      Peter KURNEV
23 //              <pkv@irinox>
24
25
26 #include <NMTTools_PaveFiller.ixx>
27
28 #include <Precision.hxx>
29
30 #include <gp_Pnt.hxx>
31
32 #include <Geom_Curve.hxx>
33
34 #include <TopAbs_Orientation.hxx>
35
36 #include <TopoDS.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Vertex.hxx>
39 #include <TopoDS_Iterator.hxx>
40
41 #include <BRep_Builder.hxx>
42 #include <BRep_Tool.hxx>
43
44 #include <BOPTools_Pave.hxx>
45 #include <BOPTools_PaveSet.hxx>
46 #include <BOPTools_CArray1OfVEInterference.hxx>
47 #include <BOPTools_VEInterference.hxx>
48
49 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
50 #include <NMTDS_Iterator.hxx>
51 #include <NMTDS_ShapesDataStructure.hxx>
52 #include <NMTDS_InterfPool.hxx>
53 //
54 // Modified  Thu Sep 14 14:35:18 2006 
55 // Contribution of Samtech www.samcef.com BEGIN
56 #include <BOPTools_IndexedMapOfCoupleOfInteger.hxx>
57 #include <BOPTools_CoupleOfInteger.hxx>
58 #include <BooleanOperations_OnceExplorer.hxx>
59
60
61 static
62   Standard_Boolean Contains(const TopoDS_Edge& aE,
63                             const TopoDS_Vertex& aV);
64 // Contribution of Samtech www.samcef.com END
65
66 //=======================================================================
67 // function: PerformVE
68 // purpose: 
69 //=======================================================================
70   void NMTTools_PaveFiller::PerformVE() 
71 {
72   myIsDone=Standard_False;
73   //
74   Standard_Boolean bJustAdd;
75   Standard_Integer n1, n2, anIndexIn, aFlag, aWhat, aWith, aNbVEs, aBlockLength, iSDV, nV1;
76   Standard_Real aT;
77   TopoDS_Vertex aV1;
78   TopoDS_Edge aE2;
79   BOPTools_IndexedMapOfCoupleOfInteger aSnareMap;
80   BOPTools_CoupleOfInteger aCouple;
81   //
82   BOPTools_CArray1OfVEInterference& aVEs=myIP->VEInterferences();
83   //
84   myDSIt->Initialize (TopAbs_VERTEX, TopAbs_EDGE);
85   //
86   // BlockLength correction
87   aNbVEs=myDSIt->BlockLength();
88   aBlockLength=aVEs.BlockLength();
89   if (aNbVEs > aBlockLength) {
90     aVEs.SetBlockLength(aNbVEs);
91   }
92   //
93   for (; myDSIt->More(); myDSIt->Next()) {
94     myDSIt->Current(n1, n2, bJustAdd);
95     if (!IsSuccessorsComputed(n1, n2)) {
96       anIndexIn=0;
97       aWhat=n1; // Vertex
98       aWith=n2; // Edge
99       if (myDS->GetShapeType(n1)==TopAbs_EDGE) {
100         aWhat=n2;
101         aWith=n1;
102       }
103       //
104       if(bJustAdd) {
105         //myIntrPool->AddInterference(aWhat, aWith, BooleanOperations_VertexEdge, anIndexIn);
106         continue;
107       }
108       // Edge
109       aE2=TopoDS::Edge(myDS->Shape(aWith));
110       if (BRep_Tool::Degenerated(aE2)){
111         continue;
112       }
113       // Vertex
114       nV1=aWhat;
115       aV1=TopoDS::Vertex(myDS->Shape(aWhat));
116       //
117       iSDV=FindSDVertex(aWhat);
118       if (iSDV) {
119         nV1=iSDV;
120         aV1=TopoDS::Vertex(myDS->Shape(nV1));
121         // Modified to find same domain vertex Thu Sep 14 14:35:18 2006 
122         // Contribution of Samtech www.samcef.com BEGIN
123         Standard_Integer nVE, iSDVE, iRet;
124         //
125         BooleanOperations_OnceExplorer aExp(*myDS);
126         iRet=0;
127         aExp.Init(aWith, TopAbs_VERTEX);
128         for (; aExp.More(); aExp.Next()) {
129           nVE=aExp.Current();
130           iSDVE=FindSDVertex(nVE);
131           if (iSDVE==iSDV) {
132             iRet=1;
133             break;
134           }
135         }
136         if (iRet) {
137           continue;
138         }
139       }
140       else {
141         if (Contains(aE2, aV1)) {
142           continue;
143         }
144         // Contribution of Samtech www.samcef.com END
145       }
146       //
147       aFlag=myContext.ComputeVE (aV1, aE2, aT);
148       //
149       if (!aFlag) {
150         // Add Interference to the Pool
151         BOPTools_VEInterference anInterf (aWhat, aWith, aT);
152         anIndexIn=aVEs.Append(anInterf);
153         //
154         // Add Pave to the Edge's myPavePool
155         aCouple.SetCouple(nV1, aWith);
156         if (!aSnareMap.Contains(aCouple)){
157           aSnareMap.Add(aCouple);
158           //
159           BOPTools_Pave aPave(nV1, aT, BooleanOperations_VertexEdge);
160           aPave.SetInterference(anIndexIn);
161           BOPTools_PaveSet& aPaveSet= myPavePool(myDS->RefEdge(aWith));
162           aPaveSet.Append(aPave);
163         }
164         //
165         // State for the Vertex in DS;
166         myDS->SetState (aWhat, BooleanOperations_ON);
167         // Insert Vertex in Interference Object
168         BOPTools_VEInterference& aVE=aVEs(anIndexIn);
169         aVE.SetNewShape(aWhat);
170         // qqf
171         {
172           myIP->Add(aWhat, aWith, Standard_True, NMTDS_TI_VE);
173         }         
174         // qqt
175       }
176       //myIntrPool->AddInterference(aWhat, aWith, BooleanOperations_VertexEdge, anIndexIn);
177     }
178   }
179   myIsDone=Standard_True;
180 }
181 //=======================================================================
182 // function: PrepareEdges
183 // purpose: 
184 //=======================================================================
185   void NMTTools_PaveFiller::PrepareEdges() 
186 {
187   Standard_Integer  i, nV, ii, aNBSuc, ip, aNbShapesObject;
188   Standard_Real aT;
189   TopAbs_Orientation anOr;
190   TopoDS_Edge   aE;
191   TopoDS_Vertex aV;
192   //
193   aNbShapesObject=myDS->NumberOfShapesOfTheObject();
194   for (i=1; i<=myNbSources; ++i) {
195     if (myDS->GetShapeType(i)==TopAbs_EDGE) {
196       aE=TopoDS::Edge(myDS->Shape(i));
197       //
198       if (BRep_Tool::Degenerated(aE)){
199         continue;
200       }
201       //
202       BOPTools_PaveSet& aPaveSet=myPavePool(myDS->RefEdge(i));
203       //
204       // A <-
205       aNBSuc=myDS->NumberOfSuccessors(i);
206       for (ii=1; ii <=aNBSuc; ii++) {
207         nV=myDS->GetSuccessor(i, ii);
208         anOr=myDS->GetOrientation(i, ii);
209         aV=TopoDS::Vertex(myDS->Shape(nV));
210         aV.Orientation(anOr);
211         aT=BRep_Tool::Parameter(aV, aE);
212         //
213         ip=FindSDVertex(nV);
214         if (ip) {
215           aV=TopoDS::Vertex(myDS->Shape(ip));
216           aV.Orientation(anOr);// XX ? if the edge is closed it'll be amazing result 
217           nV=ip;
218         }
219         //
220         BOPTools_Pave aPave(nV, aT); 
221         aPaveSet.Append (aPave);
222       }
223     }
224   }
225 }
226
227 // Modified  Thu Sep 14 14:35:18 2006 
228 // Contribution of Samtech www.samcef.com BEGIN
229 //=======================================================================
230 //function : Contains
231 //purpose  : 
232 //=======================================================================
233 Standard_Boolean Contains(const TopoDS_Edge& aE,
234                           const TopoDS_Vertex& aV)
235 {
236   Standard_Boolean bRet;
237   TopoDS_Iterator aIt;
238   //
239   bRet=Standard_False;
240   aIt.Initialize(aE);
241   for (; aIt.More(); aIt.Next()) {
242     const TopoDS_Shape& aVE=aIt.Value();
243     if (aVE.IsSame(aV)) {
244       bRet=!bRet;
245       break;
246     }
247   }
248   return bRet;
249 }
250 // Contribution of Samtech www.samcef.com END