Salome HOME
Merge with OCC_development_01
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_VertexSolid.cxx
1 // File:        GEOMAlgo_VertexSolid.cxx
2 // Created:     Wed Jan 12 16:36:40 2005
3 // Author:      Peter KURNEV
4 //              <pkv@irinox>
5
6
7 #include <GEOMAlgo_VertexSolid.ixx>
8
9 #include <gp_Pnt.hxx>
10
11 #include <TopAbs_ShapeEnum.hxx>
12 #include <TopAbs_State.hxx>
13
14 #include <TopTools_ListIteratorOfListOfShape.hxx>
15 #include <TopTools_ListOfShape.hxx>
16 #include <TopTools_IndexedMapOfShape.hxx>
17
18 #include <TopoDS.hxx>
19 #include <TopoDS_Solid.hxx>
20 #include <TopoDS_Vertex.hxx>
21
22 #include <TopExp.hxx>
23
24 #include <BRep_Tool.hxx>
25 #include <BRepClass3d_SolidClassifier.hxx>
26
27 #include <BOPTColStd_Dump.hxx>
28
29 #include <IntTools_Context.hxx>
30
31 #include <BooleanOperations_StateOfShape.hxx>
32 #include <BooleanOperations_ShapesDataStructure.hxx>
33
34 #include <BOPTools_InterferencePool.hxx>
35 #include <BOPTools_CArray1OfVVInterference.hxx>
36 #include <BOPTools_VVInterference.hxx>
37 #include <BOPTools_PaveFiller.hxx>
38 #include <BOPTools_DSFiller.hxx>
39
40 //=======================================================================
41 //function : GEOMAlgo_VertexSolid
42 //purpose  : 
43 //=======================================================================
44 GEOMAlgo_VertexSolid::GEOMAlgo_VertexSolid()
45 :
46   GEOMAlgo_ShapeSolid()
47 {
48 }
49 //=======================================================================
50 //function : ~
51 //purpose  : 
52 //=======================================================================
53 GEOMAlgo_VertexSolid::~GEOMAlgo_VertexSolid()
54 {
55 }
56 //=======================================================================
57 // function: Perform
58 // purpose: 
59 //=======================================================================
60 void GEOMAlgo_VertexSolid::Perform()
61 {
62   myErrorStatus=0;
63   //
64   try {
65     if (myDSFiller==NULL) {
66       myErrorStatus=10;
67       return;
68     }
69     if(!myDSFiller->IsDone()) {
70       myErrorStatus=11;
71       return;
72     }
73     //
74     Standard_Boolean bIsNewFiller;
75     Standard_Integer aNbF;
76     TopTools_IndexedMapOfShape aM;
77     //
78     const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
79     const TopoDS_Shape& aObj=aDS.Object();
80     //
81     TopExp::MapShapes(aObj, TopAbs_FACE, aM);
82     aNbF=aM.Extent();
83     myRank=(aNbF) ? 2 : 1;
84     //
85     bIsNewFiller=myDSFiller->IsNewFiller();
86     
87     if (bIsNewFiller) {
88       Prepare();
89       myDSFiller->SetNewFiller(!bIsNewFiller);
90     }
91     BuildResult();
92   }
93   //
94   catch (Standard_Failure) {
95     myErrorStatus = 12;
96   }
97
98 //=======================================================================
99 // function: Prepare
100 // purpose: 
101 //=======================================================================
102 void GEOMAlgo_VertexSolid::Prepare()
103 {
104   Standard_Integer i, iBeg, iEnd, aNbVV, j, n1, n2, iFound;
105   Standard_Real aTol;
106   TopAbs_State aSt;
107   TopAbs_ShapeEnum aType;
108   BooleanOperations_StateOfShape aState;
109   gp_Pnt aP3D;
110   //
111   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
112   BooleanOperations_ShapesDataStructure* pDS=(BooleanOperations_ShapesDataStructure*)&aDS;
113   const BOPTools_InterferencePool& aIP=myDSFiller->InterfPool();
114   BOPTools_InterferencePool* pIP=(BOPTools_InterferencePool*) &aIP;
115   BOPTools_CArray1OfVVInterference& aVVs=pIP->VVInterferences();
116   const BOPTools_PaveFiller& aPF=myDSFiller->PaveFiller();
117   BOPTools_PaveFiller* pPF=(BOPTools_PaveFiller*)&aPF; 
118   IntTools_Context& aCtx=pPF->ChangeContext();
119   //
120   const TopoDS_Shape& aObj=aDS.Object();
121   const TopoDS_Shape& aTool=aDS.Tool();
122   //
123   const TopoDS_Solid& aSolid=(myRank==1) ? TopoDS::Solid(aTool) : TopoDS::Solid(aObj);
124   const TopoDS_Shape& aSV   =(myRank==1)? aObj : aTool;
125   //
126   BRepClass3d_SolidClassifier& aSC=aCtx.SolidClassifier(aSolid);
127   //
128   iBeg=1;
129   iEnd=aDS.NumberOfShapesOfTheObject();
130   if (myRank==2) {
131     iBeg=iEnd+1;
132     iEnd=aDS.NumberOfSourceShapes();
133   }
134   //
135   for (i=iBeg; i<=iEnd; ++i) {
136     aType=aDS.GetShapeType(i);
137     if (aType!=TopAbs_VERTEX) {
138       continue;
139     }
140     //
141     const TopoDS_Vertex& aV=TopoDS::Vertex(aDS.Shape(i));
142     //
143     aState=aDS.GetState(i);
144     if (aState==BooleanOperations_ON ||
145         aState==BooleanOperations_IN ||
146         aState==BooleanOperations_OUT) {
147       continue;
148     }
149     //
150     iFound=0;
151     aNbVV=aVVs.Extent();
152     for (j=1; j<=aNbVV; ++j) {
153       BOPTools_VVInterference& aVV=aVVs(j);
154       aVV.Indices(n1, n2);
155       if (n1==i || n2==i) {
156         pDS->SetState (n1, BooleanOperations_ON);
157         pDS->SetState (n2, BooleanOperations_ON);
158         iFound=1;
159         break;
160       } 
161     }
162     if (iFound) {
163       continue;
164     }
165     // 
166     aP3D=BRep_Tool::Pnt(aV);
167     aTol=1.E-7;
168     aSC.Perform(aP3D, aTol);
169     aSt=aSC.State();
170     if (aSt==TopAbs_IN) {
171       pDS->SetState (i, BooleanOperations_IN);
172     }
173     else if (aSt==TopAbs_OUT) {
174       pDS->SetState (i, BooleanOperations_OUT);
175     }
176   }
177 }
178 //=======================================================================
179 // function: BuildResult
180 // purpose: 
181 //=======================================================================
182 void GEOMAlgo_VertexSolid::BuildResult()
183 {
184   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
185   //
186   Standard_Integer i, iBeg, iEnd;
187   TopAbs_ShapeEnum aType;
188   BooleanOperations_StateOfShape aState;
189   //
190   myLSIN.Clear();
191   myLSOUT.Clear();
192   myLSON.Clear();
193   //
194   iBeg=1;
195   iEnd=aDS.NumberOfShapesOfTheObject();
196   if (myRank==2) {
197     iBeg=iEnd+1;
198     iEnd=aDS.NumberOfSourceShapes();
199   }
200   //
201   for (i=iBeg; i<=iEnd; ++i) {
202     aType=aDS.GetShapeType(i);
203     if (aType!=TopAbs_VERTEX) {
204       continue;
205     }
206     const TopoDS_Shape& aV=aDS.Shape(i);
207     aState=aDS.GetState(i);
208     //
209     if (aState==BooleanOperations_IN) {
210       myLSIN.Append(aV);
211     }
212     else if (aState==BooleanOperations_OUT) {
213       myLSOUT.Append(aV);
214     }
215     else if (aState==BooleanOperations_ON) {
216       myLSON.Append(aV);
217     }
218   }
219 }