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