Salome HOME
untabify
[modules/geom.git] / src / NMTTools / NMTTools_PaveFiller_2.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:        NMTTools_PaveFiller_2.cxx
23 // Created:     Mon Dec  8 12:02:56 2003
24 // Author:      Peter KURNEV
25 //              <pkv@irinox>
26 //
27 #include <NMTTools_PaveFiller.ixx>
28
29 #include <Precision.hxx>
30
31 #include <gp_Pnt.hxx>
32
33 #include <Geom_Curve.hxx>
34
35 #include <TopAbs_Orientation.hxx>
36
37 #include <TopoDS.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS_Vertex.hxx>
40 #include <TopoDS_Iterator.hxx>
41
42 #include <BRep_Builder.hxx>
43 #include <BRep_Tool.hxx>
44
45 #include <BOPTools_Pave.hxx>
46 #include <BOPTools_PaveSet.hxx>
47 #include <BOPTools_CArray1OfVEInterference.hxx>
48 #include <BOPTools_VEInterference.hxx>
49
50 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
51 #include <NMTDS_Iterator.hxx>
52 #include <NMTDS_ShapesDataStructure.hxx>
53 #include <NMTDS_InterfPool.hxx>
54 //
55 // Modified  Thu Sep 14 14:35:18 2006 
56 // Contribution of Samtech www.samcef.com BEGIN
57 #include <BOPTools_IndexedMapOfCoupleOfInteger.hxx>
58 #include <BOPTools_CoupleOfInteger.hxx>
59 #include <BooleanOperations_OnceExplorer.hxx>
60
61
62 static
63   Standard_Boolean Contains(const TopoDS_Edge& aE,
64                             const TopoDS_Vertex& aV);
65 // Contribution of Samtech www.samcef.com END
66
67 //=======================================================================
68 // function: PerformVE
69 // purpose: 
70 //=======================================================================
71   void NMTTools_PaveFiller::PerformVE() 
72 {
73   myIsDone=Standard_False;
74   //
75   Standard_Boolean bJustAdd;
76   Standard_Integer n1, n2, anIndexIn, aFlag, aWhat, aWith, aNbVEs, aBlockLength, iSDV, nV1;
77   Standard_Real aT;
78   TopoDS_Vertex aV1;
79   TopoDS_Edge aE2;
80   BOPTools_IndexedMapOfCoupleOfInteger aSnareMap;
81   BOPTools_CoupleOfInteger aCouple;
82   //
83   BOPTools_CArray1OfVEInterference& aVEs=myIP->VEInterferences();
84   //
85   myDSIt->Initialize (TopAbs_VERTEX, TopAbs_EDGE);
86   //
87   // BlockLength correction
88   aNbVEs=myDSIt->BlockLength();
89   aBlockLength=aVEs.BlockLength();
90   if (aNbVEs > aBlockLength) {
91     aVEs.SetBlockLength(aNbVEs);
92   }
93   //
94   for (; myDSIt->More(); myDSIt->Next()) {
95     myDSIt->Current(n1, n2, bJustAdd);
96     if (!IsSuccessorsComputed(n1, n2)) {
97       anIndexIn=0;
98       aWhat=n1; // Vertex
99       aWith=n2; // Edge
100       if (myDS->GetShapeType(n1)==TopAbs_EDGE) {
101         aWhat=n2;
102         aWith=n1;
103       }
104       //
105       if(bJustAdd) {
106         //myIntrPool->AddInterference(aWhat, aWith, BooleanOperations_VertexEdge, anIndexIn);
107         continue;
108       }
109       // Edge
110       aE2=TopoDS::Edge(myDS->Shape(aWith));
111       if (BRep_Tool::Degenerated(aE2)){
112         continue;
113       }
114       // Vertex
115       nV1=aWhat;
116       aV1=TopoDS::Vertex(myDS->Shape(aWhat));
117       //
118       iSDV=FindSDVertex(aWhat);
119       if (iSDV) {
120         nV1=iSDV;
121         aV1=TopoDS::Vertex(myDS->Shape(nV1));
122         // Modified to find same domain vertex Thu Sep 14 14:35:18 2006 
123         // Contribution of Samtech www.samcef.com BEGIN
124         Standard_Integer nVE, iSDVE, iRet;
125         //
126         BooleanOperations_OnceExplorer aExp(*myDS);
127         iRet=0;
128         aExp.Init(aWith, TopAbs_VERTEX);
129         for (; aExp.More(); aExp.Next()) {
130           nVE=aExp.Current();
131           iSDVE=FindSDVertex(nVE);
132           if (iSDVE==iSDV) {
133             iRet=1;
134             break;
135           }
136         }
137         if (iRet) {
138           continue;
139         }
140       }
141       else {
142         if (Contains(aE2, aV1)) {
143           continue;
144         }
145         // Contribution of Samtech www.samcef.com END
146       }
147       //
148       aFlag=myContext.ComputeVE (aV1, aE2, aT);
149       //
150       if (!aFlag) {
151         // Add Interference to the Pool
152         BOPTools_VEInterference anInterf (aWhat, aWith, aT);
153         anIndexIn=aVEs.Append(anInterf);
154         //
155         // Add Pave to the Edge's myPavePool
156         aCouple.SetCouple(nV1, aWith);
157         if (!aSnareMap.Contains(aCouple)){
158           aSnareMap.Add(aCouple);
159           //
160           BOPTools_Pave aPave(nV1, aT, BooleanOperations_VertexEdge);
161           aPave.SetInterference(anIndexIn);
162           BOPTools_PaveSet& aPaveSet= myPavePool(myDS->RefEdge(aWith));
163           aPaveSet.Append(aPave);
164         }
165         //
166         // State for the Vertex in DS;
167         myDS->SetState (aWhat, BooleanOperations_ON);
168         // Insert Vertex in Interference Object
169         BOPTools_VEInterference& aVE=aVEs(anIndexIn);
170         aVE.SetNewShape(aWhat);
171         // qqf
172         {
173           myIP->Add(aWhat, aWith, Standard_True, NMTDS_TI_VE);
174         }         
175         // qqt
176       }
177       //myIntrPool->AddInterference(aWhat, aWith, BooleanOperations_VertexEdge, anIndexIn);
178     }
179   }
180   myIsDone=Standard_True;
181 }
182 //=======================================================================
183 // function: PrepareEdges
184 // purpose: 
185 //=======================================================================
186   void NMTTools_PaveFiller::PrepareEdges() 
187 {
188   Standard_Integer  i, nV, ii, aNBSuc, ip, aNbShapesObject;
189   Standard_Real aT;
190   TopAbs_Orientation anOr;
191   TopoDS_Edge   aE;
192   TopoDS_Vertex aV;
193   //
194   aNbShapesObject=myDS->NumberOfShapesOfTheObject();
195   for (i=1; i<=myNbSources; ++i) {
196     if (myDS->GetShapeType(i)==TopAbs_EDGE) {
197       aE=TopoDS::Edge(myDS->Shape(i));
198       //
199       if (BRep_Tool::Degenerated(aE)){
200         continue;
201       }
202       //
203       BOPTools_PaveSet& aPaveSet=myPavePool(myDS->RefEdge(i));
204       //
205       // A <-
206       aNBSuc=myDS->NumberOfSuccessors(i);
207       for (ii=1; ii <=aNBSuc; ii++) {
208         nV=myDS->GetSuccessor(i, ii);
209         anOr=myDS->GetOrientation(i, ii);
210         aV=TopoDS::Vertex(myDS->Shape(nV));
211         aV.Orientation(anOr);
212         aT=BRep_Tool::Parameter(aV, aE);
213         //
214         ip=FindSDVertex(nV);
215         if (ip) {
216           aV=TopoDS::Vertex(myDS->Shape(ip));
217           aV.Orientation(anOr);// XX ? if the edge is closed it'll be amazing result 
218           nV=ip;
219         }
220         //
221         BOPTools_Pave aPave(nV, aT); 
222         aPaveSet.Append (aPave);
223       }
224     }
225   }
226 }
227
228 // Modified  Thu Sep 14 14:35:18 2006 
229 // Contribution of Samtech www.samcef.com BEGIN
230 //=======================================================================
231 //function : Contains
232 //purpose  : 
233 //=======================================================================
234 Standard_Boolean Contains(const TopoDS_Edge& aE,
235                           const TopoDS_Vertex& aV)
236 {
237   Standard_Boolean bRet;
238   TopoDS_Iterator aIt;
239   //
240   bRet=Standard_False;
241   aIt.Initialize(aE);
242   for (; aIt.More(); aIt.Next()) {
243     const TopoDS_Shape& aVE=aIt.Value();
244     if (aVE.IsSame(aV)) {
245       bRet=!bRet;
246       break;
247     }
248   }
249   return bRet;
250 }
251 // Contribution of Samtech www.samcef.com END