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