0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / TopOpeBRep / TopOpeBRep_FaceEdgeFiller.cxx
1 // Created on: 1995-06-14
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <gp_Pnt2d.hxx>
19 #include <TopoDS.hxx>
20 #include <TopoDS_Shape.hxx>
21 #include <TopOpeBRep_FaceEdgeFiller.hxx>
22 #include <TopOpeBRep_FaceEdgeIntersector.hxx>
23 #include <TopOpeBRep_PointGeomTool.hxx>
24 #include <TopOpeBRepDS_CurvePointInterference.hxx>
25 #include <TopOpeBRepDS_HDataStructure.hxx>
26 #include <TopOpeBRepDS_Interference.hxx>
27 #include <TopOpeBRepDS_InterferenceTool.hxx>
28 #include <TopOpeBRepDS_Point.hxx>
29
30 #ifdef OCCT_DEBUG
31 extern void FEINT_DUMPPOINTS(TopOpeBRep_FaceEdgeIntersector& FEINT,
32                              const TopOpeBRepDS_DataStructure& BDS);
33 #endif
34
35 //=======================================================================
36 //function : TopOpeBRep_FaceEdgeFiller
37 //purpose  : 
38 //=======================================================================
39
40 TopOpeBRep_FaceEdgeFiller::TopOpeBRep_FaceEdgeFiller() 
41 {
42 }
43
44
45 //=======================================================================
46 //function : Insert
47 //purpose  : 
48 //=======================================================================
49
50 void TopOpeBRep_FaceEdgeFiller::Insert
51 (const TopoDS_Shape& F,
52  const TopoDS_Shape& E,
53  TopOpeBRep_FaceEdgeIntersector& FEINT,
54  const Handle(TopOpeBRepDS_HDataStructure)& HDS)
55 {
56   const TopoDS_Face& FF = TopoDS::Face(F);
57   const TopoDS_Edge& EE = TopoDS::Edge(E);
58
59   // exit if no point.
60   FEINT.InitPoint(); 
61   if ( ! FEINT.MorePoint() ) return;
62
63   TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
64
65   TopAbs_Orientation FFori = FF.Orientation();
66
67   // --- Add <FF,EE> in BDS
68   Standard_Integer FFindex = BDS.AddShape(FF,1);
69                              BDS.AddShape(EE,2);
70
71   // --- get list of interferences connected to edges <FF>,<EE>
72   TopOpeBRepDS_ListOfInterference& EIL1 = BDS.ChangeShapeInterferences(FF);
73   TopOpeBRepDS_ListOfInterference& EIL2 = BDS.ChangeShapeInterferences(EE);
74
75   Handle(TopOpeBRepDS_Interference) EPI;  //edge/point interference
76   Handle(TopOpeBRepDS_Interference) EVI;  //edge/vertex interference
77
78   for (; FEINT.MorePoint(); FEINT.NextPoint() ) {
79     gp_Pnt2d      pUV; FEINT.UVPoint(pUV);
80     Standard_Real parE = FEINT.Parameter();
81
82 #ifdef OCCT_DEBUG
83     TopAbs_Orientation EEori = EE.Orientation();
84     TopOpeBRepDS_Transition TFF = FEINT.Transition(1,EEori); (void)TFF;
85 #endif
86     TopOpeBRepDS_Transition TEE = FEINT.Transition(2,FFori);
87     TEE.Index(FFindex);
88     
89     TopoDS_Vertex V1;
90     Standard_Boolean isvertexF = FEINT.IsVertex(1,V1);
91     TopoDS_Vertex V2;
92     Standard_Boolean isvertexE = FEINT.IsVertex(2,V2);
93     Standard_Boolean isvertex = isvertexF || isvertexE;
94
95     Standard_Integer DSPindex;
96     Standard_Boolean EPIfound;
97
98     if ( ! isvertex ) {
99       // create a new geometry in DS ( and get its index <DSPindex> )
100       // or get the index <DSPindex> of an equal geometry
101       // among those of Edge/Point interferences connected to <FF> (or <EE>).
102
103       TopOpeBRepDS_ListIteratorOfListOfInterference itEIL1(EIL1);
104       EPIfound = GetGeometry(itEIL1,FEINT,DSPindex,BDS);
105       if ( ! EPIfound ) DSPindex = MakeGeometry(FEINT,BDS);
106
107       // sur FF
108       // NYI : FacePointInterference : on ajoute un point INTERNAL a F
109 //      FPI = new TopOpeBRepDS_FacePointInterference(TopAbs_INTERNAL,
110 //                                             TopOpeBRepDS_FACE,FFindex,
111 //                                             TopOpeBRepDS_POINT,DSPindex,
112 //                                             pUV);
113 //      StoreInterference(FPI,EIL1,BDS);
114
115       // sur EE
116       EPI = TopOpeBRepDS_InterferenceTool::MakeCurveInterference
117         (TEE,TopOpeBRepDS_FACE,FFindex,TopOpeBRepDS_POINT,DSPindex,parE);
118       StoreInterference(EPI,EIL2,BDS);
119     }
120
121     else if ( isvertexF ) {
122       // si aussi vertex de E, in privilegie le vertex de la face
123       Standard_Integer Vindex = BDS.AddShape(V1,1);
124
125       // sur FF
126       // NYI pour toute arete de F qui accede V , une EVI
127 //      EVI = new TopOpeBRepDS_EdgeVertexInterference(Transition ?? <-> TFF,
128 //                                                  TopOpeBRepDS_EDGE,E de F,
129 //                                                  TopOpeBRepDS_VERTEX,Vindex,
130 //                                                  param de V sur E de F);
131 //      StoreInterference(EVI,EIL1,BDS);
132
133       // sur EE
134       EPI = new TopOpeBRepDS_CurvePointInterference(TEE,
135                                                     TopOpeBRepDS_FACE,FFindex,
136                                                     TopOpeBRepDS_VERTEX,Vindex,
137                                                     parE);
138       StoreInterference(EPI,EIL2,BDS);
139     }
140
141     else if ( isvertexE ) {
142       Standard_Integer Vindex = BDS.AddShape(V2,2);
143
144       // sur FF
145       // NYI : FaceVertexInterference : on ajoute un vertex INTERNAL a F
146 //      FVI = new TopOpeBRepDS_FaceVertexInterference(TopAbs_INTERNAL,
147 //                                             TopOpeBRepDS_FACE,FFindex,
148 //                                             TopOpeBRepDS_VERTEX,Vindex,
149 //                                             pUV);
150 //      StoreInterference(FPI,EIL1,BDS);
151       
152       // sur EE
153       EPI = new TopOpeBRepDS_CurvePointInterference(TEE,
154                                                     TopOpeBRepDS_FACE,FFindex,
155                                                     TopOpeBRepDS_VERTEX,Vindex,
156                                                     parE);
157       StoreInterference(EPI,EIL2,BDS);
158     }
159   }
160 }
161
162
163
164 // ===============
165 // private methods
166 // ===============
167
168 //-----------------------------------------------------------------------
169 // Search, among a list of interferences accessed by the iterator <IT>,
170 // a geometry whose 3D point is identical yo the 3D point of a DS point <DSP>.
171 // TheDSPointGeomTool is a tool able to access the 3D point of the DS point 
172 // DSP,and to test identity (according to tolerance connected to DSP) of the
173 // DS points.
174 // return True if such an interference has been found, False else.
175 // if True, iterator <IT> points (by the Value() method) on the first 
176 // interference accessing an identical 3D point.
177 //-----------------------------------------------------------------------
178 //=======================================================================
179 //function : ScanInterfList
180 //purpose  : private
181 //=======================================================================
182
183 Standard_Boolean TopOpeBRep_FaceEdgeFiller::ScanInterfList
184    (TopOpeBRepDS_ListIteratorOfListOfInterference& IT,
185     const TopOpeBRepDS_Point& DSP,
186     const TopOpeBRepDS_DataStructure& BDS) const
187 {
188   for ( ; IT.More(); IT.Next() ) {
189     Standard_Integer DSPG = IT.Value()->Geometry();
190     const TopOpeBRepDS_Point& otherDSP = BDS.Point(DSPG);
191     if (TopOpeBRep_PointGeomTool::IsEqual(DSP,otherDSP)) return Standard_True;
192   }
193   return Standard_False;
194 }
195
196
197 //=======================================================================
198 //function : GetGeometry
199 //purpose  : private
200 //=======================================================================
201
202 Standard_Boolean TopOpeBRep_FaceEdgeFiller::GetGeometry
203     (TopOpeBRepDS_ListIteratorOfListOfInterference& IT,
204      const TopOpeBRep_FaceEdgeIntersector& FEINT,
205      Standard_Integer& G,
206      const TopOpeBRepDS_DataStructure& BDS) const
207 {
208   TopOpeBRepDS_Point DSP = TopOpeBRep_PointGeomTool::MakePoint(FEINT);
209   Standard_Boolean found = ScanInterfList(IT,DSP,BDS);
210   if (found) G = IT.Value()->Geometry();
211   return found;
212 }
213
214
215 //=======================================================================
216 //function : GetGeometry
217 //purpose  : private
218 //=======================================================================
219
220 Standard_Boolean TopOpeBRep_FaceEdgeFiller::GetGeometry
221     (const TopOpeBRepDS_ListOfInterference& L,
222      const TopOpeBRepDS_Point& DSP,
223      Standard_Integer& G,
224      TopOpeBRepDS_DataStructure& BDS) const
225 {
226   TopOpeBRepDS_ListIteratorOfListOfInterference itI(L);
227   Standard_Boolean Ifound = ScanInterfList(itI,DSP,BDS);
228   if (Ifound) G = itI.Value()->Geometry();
229   else        G = BDS.AddPoint(DSP);
230   return Ifound;   // interference found or not
231 }
232
233
234 //-----------------------------------------------------------------------
235 // StoreInterference : Append an interference I to a list of interference LI
236 //                   : Append I to the interf. list connected to I Geometry()
237 //-----------------------------------------------------------------------
238 //=======================================================================
239 //function : StoreInterference
240 //purpose  : private
241 //=======================================================================
242
243 void TopOpeBRep_FaceEdgeFiller::StoreInterference
244 (const Handle(TopOpeBRepDS_Interference)& I,
245  TopOpeBRepDS_ListOfInterference& LI,
246  TopOpeBRepDS_DataStructure& BDS) const
247 {
248   // append I to list LI
249   LI.Append(I);
250
251   Standard_Integer G = I->Geometry();
252
253   // append I to list of interference connected to G = I->Geometry()
254   switch (I->GeometryType()) {
255
256   case TopOpeBRepDS_SOLID : case TopOpeBRepDS_FACE : 
257   case TopOpeBRepDS_EDGE : case TopOpeBRepDS_VERTEX :
258 //    appendtoG = Standard_True;
259 //    BDS.ChangeShapeInterferences(G).Append(I);
260     break;
261     
262   case TopOpeBRepDS_SURFACE :
263     BDS.ChangeSurfaceInterferences(G).Append(I);
264     break;
265     
266   case TopOpeBRepDS_CURVE :
267     BDS.ChangeCurveInterferences(G).Append(I);
268     break;
269     
270   case TopOpeBRepDS_POINT :
271 //    appendtoG = Standard_True;
272 //    BDS.ChangePointInterferences(G).Append(I);
273     break;
274   default:
275     break;
276   }
277 }
278
279 //=======================================================================
280 //function : MakeGeometry
281 //purpose  : 
282 //=======================================================================
283
284 Standard_Integer TopOpeBRep_FaceEdgeFiller::MakeGeometry
285     (TopOpeBRep_FaceEdgeIntersector& FEINT,
286      TopOpeBRepDS_DataStructure& BDS) const
287 {
288   Standard_Integer G=0;
289
290   TopoDS_Vertex V1;
291   Standard_Boolean isvertexF = FEINT.IsVertex(1,V1);
292   TopoDS_Vertex V2;
293   Standard_Boolean isvertexE = FEINT.IsVertex(2,V2);
294   Standard_Boolean isvertex = isvertexF || isvertexE;
295
296   if ( isvertex ) {
297     if      ( isvertexF ) G = BDS.AddShape(V1,1);
298     else if ( isvertexE ) G = BDS.AddShape(V2,2);
299   }
300   else 
301     G = BDS.AddPoint(TopOpeBRep_PointGeomTool::MakePoint(FEINT));
302   return G;
303 }