b311480e |
1 | // Created on: 1995-06-14 |
2 | // Created by: Jean Yves LEBEY |
3 | // Copyright (c) 1995-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
22 | #include <TopOpeBRep_FaceEdgeFiller.ixx> |
23 | |
24 | #include <TopOpeBRep_PointGeomTool.hxx> |
25 | #include <TopOpeBRepDS_InterferenceTool.hxx> |
26 | #include <TopOpeBRepDS_DataStructure.hxx> |
27 | #include <TopOpeBRepDS_Point.hxx> |
28 | #include <TopOpeBRepDS_CurvePointInterference.hxx> |
29 | |
30 | #include <TopoDS.hxx> |
31 | #include <TopoDS_Face.hxx> |
32 | #include <TopoDS_Edge.hxx> |
33 | #include <gp_Pnt2d.hxx> |
34 | |
35 | #ifdef DEB |
1d0a9d4d |
36 | extern void FEINT_DUMPPOINTS(TopOpeBRep_FaceEdgeIntersector& FEINT, |
7fd59977 |
37 | const TopOpeBRepDS_DataStructure& BDS); |
1d0a9d4d |
38 | extern Standard_Boolean TopOpeBRepDS_GettraceDSF(); |
7fd59977 |
39 | #endif |
40 | |
41 | //======================================================================= |
42 | //function : TopOpeBRep_FaceEdgeFiller |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | TopOpeBRep_FaceEdgeFiller::TopOpeBRep_FaceEdgeFiller() |
47 | { |
48 | } |
49 | |
50 | |
51 | //======================================================================= |
52 | //function : Insert |
53 | //purpose : |
54 | //======================================================================= |
55 | |
56 | void TopOpeBRep_FaceEdgeFiller::Insert |
57 | (const TopoDS_Shape& F, |
58 | const TopoDS_Shape& E, |
59 | TopOpeBRep_FaceEdgeIntersector& FEINT, |
60 | const Handle(TopOpeBRepDS_HDataStructure)& HDS) |
61 | { |
62 | const TopoDS_Face& FF = TopoDS::Face(F); |
63 | const TopoDS_Edge& EE = TopoDS::Edge(E); |
64 | |
65 | #ifdef DEB |
66 | if (TopOpeBRepDS_GettraceDSF()) { |
67 | FEINT_DUMPPOINTS(FEINT,HDS->DS()); |
68 | } |
69 | #endif |
70 | |
71 | // exit if no point. |
72 | FEINT.InitPoint(); |
73 | if ( ! FEINT.MorePoint() ) return; |
74 | |
75 | TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS(); |
76 | |
77 | TopAbs_Orientation FFori = FF.Orientation(); |
78 | TopAbs_Orientation EEori = EE.Orientation(); |
79 | |
80 | // --- Add <FF,EE> in BDS |
81 | Standard_Integer FFindex = BDS.AddShape(FF,1); |
7fd59977 |
82 | BDS.AddShape(EE,2); |
83 | |
84 | // --- get list of interferences connected to edges <FF>,<EE> |
85 | TopOpeBRepDS_ListOfInterference& EIL1 = BDS.ChangeShapeInterferences(FF); |
86 | TopOpeBRepDS_ListOfInterference& EIL2 = BDS.ChangeShapeInterferences(EE); |
87 | |
88 | Handle(TopOpeBRepDS_Interference) EPI; //edge/point interference |
89 | Handle(TopOpeBRepDS_Interference) EVI; //edge/vertex interference |
90 | |
91 | for (; FEINT.MorePoint(); FEINT.NextPoint() ) { |
92 | gp_Pnt2d pUV; FEINT.UVPoint(pUV); |
7fd59977 |
93 | Standard_Real parE = FEINT.Parameter(); |
94 | |
95 | #ifdef DEB |
96 | TopOpeBRepDS_Transition TFF = |
97 | #endif |
98 | FEINT.Transition(1,EEori); // EEori bidon = EXTERNAL |
99 | TopOpeBRepDS_Transition TEE = FEINT.Transition(2,FFori); |
100 | TEE.Index(FFindex); |
101 | |
102 | TopoDS_Vertex V1; |
103 | Standard_Boolean isvertexF = FEINT.IsVertex(1,V1); |
104 | TopoDS_Vertex V2; |
105 | Standard_Boolean isvertexE = FEINT.IsVertex(2,V2); |
106 | Standard_Boolean isvertex = isvertexF || isvertexE; |
107 | |
108 | Standard_Integer DSPindex; |
109 | Standard_Boolean EPIfound; |
110 | |
111 | if ( ! isvertex ) { |
112 | // create a new geometry in DS ( and get its index <DSPindex> ) |
113 | // or get the index <DSPindex> of an equal geometry |
114 | // among those of Edge/Point interferences connected to <FF> (or <EE>). |
115 | |
116 | TopOpeBRepDS_ListIteratorOfListOfInterference itEIL1(EIL1); |
117 | EPIfound = GetGeometry(itEIL1,FEINT,DSPindex,BDS); |
118 | if ( ! EPIfound ) DSPindex = MakeGeometry(FEINT,BDS); |
119 | |
120 | // sur FF |
121 | // NYI : FacePointInterference : on ajoute un point INTERNAL a F |
122 | // FPI = new TopOpeBRepDS_FacePointInterference(TopAbs_INTERNAL, |
123 | // TopOpeBRepDS_FACE,FFindex, |
124 | // TopOpeBRepDS_POINT,DSPindex, |
125 | // pUV); |
126 | // StoreInterference(FPI,EIL1,BDS); |
127 | |
128 | // sur EE |
129 | EPI = TopOpeBRepDS_InterferenceTool::MakeCurveInterference |
130 | (TEE,TopOpeBRepDS_FACE,FFindex,TopOpeBRepDS_POINT,DSPindex,parE); |
131 | StoreInterference(EPI,EIL2,BDS); |
132 | } |
133 | |
134 | else if ( isvertexF ) { |
135 | // si aussi vertex de E, in privilegie le vertex de la face |
136 | Standard_Integer Vindex = BDS.AddShape(V1,1); |
137 | |
138 | // sur FF |
139 | // NYI pour toute arete de F qui accede V , une EVI |
140 | // EVI = new TopOpeBRepDS_EdgeVertexInterference(Transition ?? <-> TFF, |
141 | // TopOpeBRepDS_EDGE,E de F, |
142 | // TopOpeBRepDS_VERTEX,Vindex, |
143 | // param de V sur E de F); |
144 | // StoreInterference(EVI,EIL1,BDS); |
145 | |
146 | // sur EE |
147 | EPI = new TopOpeBRepDS_CurvePointInterference(TEE, |
148 | TopOpeBRepDS_FACE,FFindex, |
149 | TopOpeBRepDS_VERTEX,Vindex, |
150 | parE); |
151 | StoreInterference(EPI,EIL2,BDS); |
152 | } |
153 | |
154 | else if ( isvertexE ) { |
155 | Standard_Integer Vindex = BDS.AddShape(V2,2); |
156 | |
157 | // sur FF |
158 | // NYI : FaceVertexInterference : on ajoute un vertex INTERNAL a F |
159 | // FVI = new TopOpeBRepDS_FaceVertexInterference(TopAbs_INTERNAL, |
160 | // TopOpeBRepDS_FACE,FFindex, |
161 | // TopOpeBRepDS_VERTEX,Vindex, |
162 | // pUV); |
163 | // StoreInterference(FPI,EIL1,BDS); |
164 | |
165 | // sur EE |
166 | EPI = new TopOpeBRepDS_CurvePointInterference(TEE, |
167 | TopOpeBRepDS_FACE,FFindex, |
168 | TopOpeBRepDS_VERTEX,Vindex, |
169 | parE); |
170 | StoreInterference(EPI,EIL2,BDS); |
171 | } |
172 | } |
173 | } |
174 | |
175 | |
176 | |
177 | // =============== |
178 | // private methods |
179 | // =============== |
180 | |
181 | //----------------------------------------------------------------------- |
182 | // Search, among a list of interferences accessed by the iterator <IT>, |
183 | // a geometry whose 3D point is identical yo the 3D point of a DS point <DSP>. |
184 | // TheDSPointGeomTool is a tool able to access the 3D point of the DS point |
185 | // DSP,and to test identity (according to tolerance connected to DSP) of the |
186 | // DS points. |
187 | // return True if such an interference has been found, False else. |
188 | // if True, iterator <IT> points (by the Value() method) on the first |
189 | // interference accessing an identical 3D point. |
190 | //----------------------------------------------------------------------- |
191 | //======================================================================= |
192 | //function : ScanInterfList |
193 | //purpose : private |
194 | //======================================================================= |
195 | |
196 | Standard_Boolean TopOpeBRep_FaceEdgeFiller::ScanInterfList |
197 | (TopOpeBRepDS_ListIteratorOfListOfInterference& IT, |
198 | const TopOpeBRepDS_Point& DSP, |
199 | const TopOpeBRepDS_DataStructure& BDS) const |
200 | { |
201 | for ( ; IT.More(); IT.Next() ) { |
202 | Standard_Integer DSPG = IT.Value()->Geometry(); |
203 | const TopOpeBRepDS_Point& otherDSP = BDS.Point(DSPG); |
204 | if (TopOpeBRep_PointGeomTool::IsEqual(DSP,otherDSP)) return Standard_True; |
205 | } |
206 | return Standard_False; |
207 | } |
208 | |
209 | |
210 | //======================================================================= |
211 | //function : GetGeometry |
212 | //purpose : private |
213 | //======================================================================= |
214 | |
215 | Standard_Boolean TopOpeBRep_FaceEdgeFiller::GetGeometry |
216 | (TopOpeBRepDS_ListIteratorOfListOfInterference& IT, |
217 | const TopOpeBRep_FaceEdgeIntersector& FEINT, |
218 | Standard_Integer& G, |
219 | const TopOpeBRepDS_DataStructure& BDS) const |
220 | { |
221 | TopOpeBRepDS_Point DSP = TopOpeBRep_PointGeomTool::MakePoint(FEINT); |
222 | Standard_Boolean found = ScanInterfList(IT,DSP,BDS); |
223 | if (found) G = IT.Value()->Geometry(); |
224 | return found; |
225 | } |
226 | |
227 | |
228 | //======================================================================= |
229 | //function : GetGeometry |
230 | //purpose : private |
231 | //======================================================================= |
232 | |
233 | Standard_Boolean TopOpeBRep_FaceEdgeFiller::GetGeometry |
234 | (const TopOpeBRepDS_ListOfInterference& L, |
235 | const TopOpeBRepDS_Point& DSP, |
236 | Standard_Integer& G, |
237 | TopOpeBRepDS_DataStructure& BDS) const |
238 | { |
239 | TopOpeBRepDS_ListIteratorOfListOfInterference itI(L); |
240 | Standard_Boolean Ifound = ScanInterfList(itI,DSP,BDS); |
241 | if (Ifound) G = itI.Value()->Geometry(); |
242 | else G = BDS.AddPoint(DSP); |
243 | return Ifound; // interference found or not |
244 | } |
245 | |
246 | |
247 | //----------------------------------------------------------------------- |
248 | // StoreInterference : Append an interference I to a list of interference LI |
249 | // : Append I to the interf. list connected to I Geometry() |
250 | //----------------------------------------------------------------------- |
251 | //======================================================================= |
252 | //function : StoreInterference |
253 | //purpose : private |
254 | //======================================================================= |
255 | |
256 | void TopOpeBRep_FaceEdgeFiller::StoreInterference |
257 | (const Handle(TopOpeBRepDS_Interference)& I, |
258 | TopOpeBRepDS_ListOfInterference& LI, |
259 | TopOpeBRepDS_DataStructure& BDS) const |
260 | { |
261 | // append I to list LI |
262 | LI.Append(I); |
263 | |
264 | Standard_Boolean appendtoG = Standard_False; |
265 | Standard_Integer G = I->Geometry(); |
266 | |
267 | // append I to list of interference connected to G = I->Geometry() |
268 | switch (I->GeometryType()) { |
269 | |
270 | case TopOpeBRepDS_SOLID : case TopOpeBRepDS_FACE : |
271 | case TopOpeBRepDS_EDGE : case TopOpeBRepDS_VERTEX : |
272 | // appendtoG = Standard_True; |
273 | // BDS.ChangeShapeInterferences(G).Append(I); |
274 | break; |
275 | |
276 | case TopOpeBRepDS_SURFACE : |
277 | appendtoG = Standard_True; |
278 | BDS.ChangeSurfaceInterferences(G).Append(I); |
279 | break; |
280 | |
281 | case TopOpeBRepDS_CURVE : |
282 | appendtoG = Standard_True; |
283 | BDS.ChangeCurveInterferences(G).Append(I); |
284 | break; |
285 | |
286 | case TopOpeBRepDS_POINT : |
287 | // appendtoG = Standard_True; |
288 | // BDS.ChangePointInterferences(G).Append(I); |
289 | break; |
7fd59977 |
290 | default: |
291 | break; |
7fd59977 |
292 | } |
293 | |
294 | #ifdef DEB |
295 | if (TopOpeBRepDS_GettraceDSF()) { |
296 | cout<<"append "; I->Dump(cout); |
297 | if (appendtoG) cout<<" and to G"<<G<<" list"; |
298 | cout<<endl; |
299 | } |
300 | #endif |
301 | } |
302 | |
303 | //======================================================================= |
304 | //function : MakeGeometry |
305 | //purpose : |
306 | //======================================================================= |
307 | |
308 | Standard_Integer TopOpeBRep_FaceEdgeFiller::MakeGeometry |
309 | (TopOpeBRep_FaceEdgeIntersector& FEINT, |
310 | TopOpeBRepDS_DataStructure& BDS) const |
311 | { |
7fd59977 |
312 | Standard_Integer G=0; |
7fd59977 |
313 | |
314 | TopoDS_Vertex V1; |
315 | Standard_Boolean isvertexF = FEINT.IsVertex(1,V1); |
316 | TopoDS_Vertex V2; |
317 | Standard_Boolean isvertexE = FEINT.IsVertex(2,V2); |
318 | Standard_Boolean isvertex = isvertexF || isvertexE; |
319 | |
320 | if ( isvertex ) { |
321 | if ( isvertexF ) G = BDS.AddShape(V1,1); |
322 | else if ( isvertexE ) G = BDS.AddShape(V2,2); |
323 | } |
324 | else |
325 | G = BDS.AddPoint(TopOpeBRep_PointGeomTool::MakePoint(FEINT)); |
326 | return G; |
327 | } |