41f76f7bf41aacf325c441638cdf5dbd6f187909
[occt.git] / src / BOPAlgo / BOPAlgo_CheckerSI_1.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2012 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 //                         EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 //
7 //
8 // This file is part of Open CASCADE Technology software library.
9 //
10 // This library is free software; you can redistribute it and/or modify it under
11 // the terms of the GNU Lesser General Public License version 2.1 as published
12 // by the Free Software Foundation, with special exception defined in the file
13 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
14 // distribution for complete text of the license and disclaimer of any warranty.
15 //
16 // Alternatively, this file may be used under the terms of Open CASCADE
17 // commercial license or contractual agreement.
18
19 #include <BOPAlgo_CheckerSI.ixx>
20
21 #include <BOPDS_DS.hxx>
22 #include <BOPDS_IteratorSI.hxx>
23 #include <BOPInt_Context.hxx>
24
25 #include <BOPDS_Interf.hxx>
26 #include <TopoDS_Solid.hxx>
27 #include <BRepClass3d_SolidClassifier.hxx>
28 #include <TopoDS_Vertex.hxx>
29 #include <gp_Pnt.hxx>
30 #include <TopAbs_State.hxx>
31 #include <BRep_Tool.hxx>
32 #include <BOPDS_VectorOfInterfVZ.hxx>
33
34
35 //=======================================================================
36 //function : PerformVZ
37 //purpose  : 
38 //=======================================================================
39 void BOPAlgo_CheckerSI::PerformVZ()
40 {
41   Standard_Boolean bJustAdd;
42   Standard_Integer iSize, nV, nZ, i;
43   Standard_Real aTol;
44   gp_Pnt aPV;
45   TopAbs_State aState;
46   //
47   myErrorStatus=0;
48   //
49   myIterator->Initialize(TopAbs_VERTEX, TopAbs_SOLID);
50   iSize=myIterator->ExpectedLength();
51   if (!iSize) {
52     return; 
53   }
54   //
55   BOPDS_VectorOfInterfVZ& aVZs=myDS->InterfVZ();
56   aVZs.SetStartSize(iSize);
57   aVZs.SetIncrement(iSize);
58   aVZs.Init();
59   //
60   for (; myIterator->More(); myIterator->Next()) {
61     myIterator->Value(nV, nZ, bJustAdd);
62     if(bJustAdd) {
63       continue;
64     }
65     //
66     const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
67     const BOPDS_ShapeInfo& aSIZ=myDS->ShapeInfo(nZ);
68     //
69     const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aSIV.Shape()); 
70     const TopoDS_Solid& aZ=*((TopoDS_Solid*)&aSIZ.Shape()); 
71     //
72     BRepClass3d_SolidClassifier& aSC=myContext->SolidClassifier(aZ);
73     //
74     aPV=BRep_Tool::Pnt(aV);
75     aTol=BRep_Tool::Tolerance(aV);
76     //
77     aSC.Perform(aPV, aTol);
78     //
79     aState=aSC.State();
80     if (aState==TopAbs_IN)  {
81       i=aVZs.Append()-1;
82       BOPDS_InterfVZ& aVZ=aVZs(i);
83       aVZ.SetIndices(nV, nZ);
84       //
85       myDS->AddInterf(nV, nZ);
86     }
87   }
88   //
89 }
90 //=======================================================================
91 //function : PerformEZ
92 //purpose  : 
93 //=======================================================================
94 void BOPAlgo_CheckerSI::PerformEZ()
95 {
96   Standard_Boolean bJustAdd, bHasInterf;
97   Standard_Integer iSize, nE, nZ, i;
98   //
99   myErrorStatus=0;
100   //
101   myIterator->Initialize(TopAbs_EDGE, TopAbs_SOLID);
102   iSize=myIterator->ExpectedLength();
103   if (!iSize) {
104     return; 
105   }
106   //
107   BOPDS_VectorOfInterfEZ& aEZs=myDS->InterfEZ();
108   aEZs.SetStartSize(iSize);
109   aEZs.SetIncrement(iSize);
110   aEZs.Init();
111   //
112   for (; myIterator->More(); myIterator->Next()) {
113     myIterator->Value(nE, nZ, bJustAdd);
114     if(bJustAdd) {
115       continue;
116     }
117     //
118     bHasInterf=myDS->HasInterfShapeSubShapes(nE, nZ);
119     if (bHasInterf) {
120       continue;
121     }
122     //
123     bHasInterf=myDS->HasInterfShapeSubShapes(nZ, nE);
124     if (!bHasInterf) {
125       continue;
126     }
127     //
128     i=aEZs.Append()-1;
129     BOPDS_InterfEZ& aEZ=aEZs(i);
130     aEZ.SetIndices(nE, nZ);
131     //
132     myDS->AddInterf(nE, nZ);
133   }
134 }
135 //=======================================================================
136 //function : PerformFZ
137 //purpose  : 
138 //=======================================================================
139 void BOPAlgo_CheckerSI::PerformFZ()
140 {
141   Standard_Boolean bJustAdd, bHasInterf;
142   Standard_Integer iSize, nF, nZ, i;
143   //
144   myErrorStatus=0;
145   //
146   myIterator->Initialize(TopAbs_FACE, TopAbs_SOLID);
147   iSize=myIterator->ExpectedLength();
148   if (!iSize) {
149     return; 
150   }
151   //
152   BOPDS_VectorOfInterfFZ& aFZs=myDS->InterfFZ();
153   aFZs.SetStartSize(iSize);
154   aFZs.SetIncrement(iSize);
155   aFZs.Init();
156   //
157   for (; myIterator->More(); myIterator->Next()) {
158     myIterator->Value(nF, nZ, bJustAdd);
159     if(bJustAdd) {
160       continue;
161     }
162     //
163     bHasInterf=myDS->HasInterfShapeSubShapes(nF, nZ);
164     if (bHasInterf) {
165       continue;
166     }
167     //
168     bHasInterf=myDS->HasInterfShapeSubShapes(nZ, nF);
169     if (!bHasInterf) {
170       continue;
171     }
172     //
173     i=aFZs.Append()-1;
174     BOPDS_InterfFZ& aFZ=aFZs(i);
175     aFZ.SetIndices(nF, nZ);
176     //
177     myDS->AddInterf(nF, nZ);
178   }
179 }
180 //=======================================================================
181 //function : PerformZZ
182 //purpose  : 
183 //=======================================================================
184 void BOPAlgo_CheckerSI::PerformZZ()
185 {
186   Standard_Boolean bJustAdd, bHasInterf, bFlag;
187   Standard_Integer iSize, nZ1, nZ, i;
188   //
189   myErrorStatus=0;
190   //
191   myIterator->Initialize(TopAbs_SOLID, TopAbs_SOLID);
192   iSize=myIterator->ExpectedLength();
193   if (!iSize) {
194     return; 
195   }
196   //
197   BOPDS_VectorOfInterfZZ& aZZs=myDS->InterfZZ();
198   aZZs.SetStartSize(iSize);
199   aZZs.SetIncrement(iSize);
200   aZZs.Init();
201   //
202   bFlag=Standard_False;
203   //
204   for (; myIterator->More(); myIterator->Next()) {
205     myIterator->Value(nZ1, nZ, bJustAdd);
206     if(bJustAdd) {
207       continue;
208     }
209     //
210     bHasInterf=myDS->HasInterfShapeSubShapes(nZ, nZ1, bFlag);
211     if (!bHasInterf) {
212       bHasInterf=myDS->HasInterfShapeSubShapes(nZ1, nZ, bFlag);
213     }
214     if (!bHasInterf) {
215       continue; 
216     }
217     //
218     i=aZZs.Append()-1;
219     BOPDS_InterfZZ& aZZ=aZZs(i);
220     aZZ.SetIndices(nZ1, nZ);
221     //
222     myDS->AddInterf(nZ1, nZ);
223   }
224 }