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