0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / IGESSolid / IGESSolid_ToolEdgeList.cxx
1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 //--------------------------------------------------------------------
17 //--------------------------------------------------------------------
18
19 #include <IGESSolid_ToolEdgeList.ixx>
20 #include <IGESData_ParamCursor.hxx>
21 #include <IGESData_IGESEntity.hxx>
22 #include <IGESSolid_VertexList.hxx>
23 #include <IGESData_HArray1OfIGESEntity.hxx>
24 #include <IGESSolid_HArray1OfVertexList.hxx>
25 #include <TColStd_HArray1OfInteger.hxx>
26 #include <IGESData_Dump.hxx>
27 #include <Interface_Macros.hxx>
28
29 // MGE 03/08/98
30 #include <Message_Msg.hxx>
31 #include <IGESData_Status.hxx>
32
33 //=======================================================================
34 //function : IGESSolid_ToolEdgeList
35 //purpose  : 
36 //=======================================================================
37
38 IGESSolid_ToolEdgeList::IGESSolid_ToolEdgeList ()
39 {
40 }
41
42
43 //=======================================================================
44 //function : ReadOwnParams
45 //purpose  : 
46 //=======================================================================
47
48 void IGESSolid_ToolEdgeList::ReadOwnParams(const Handle(IGESSolid_EdgeList)& ent,
49                                            const Handle(IGESData_IGESReaderData)& IR,
50                                            IGESData_ParamReader& PR) const
51 {
52   // MGE 03/08/98
53   //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down
54   Standard_Integer length, anint;
55   Handle(IGESData_IGESEntity) anent;
56   Handle(IGESSolid_VertexList) avert;
57   Handle(IGESData_HArray1OfIGESEntity) tempCurves;
58   Handle(IGESSolid_HArray1OfVertexList) tempStartVertexList;
59   Handle(TColStd_HArray1OfInteger)   tempStartVertexIndex;
60   Handle(IGESSolid_HArray1OfVertexList) tempEndVertexList;
61   Handle(TColStd_HArray1OfInteger)   tempEndVertexIndex;
62   IGESData_Status aStatus;
63
64   Standard_Boolean st = PR.ReadInteger(PR.Current(), length);
65   if(!st){
66     Message_Msg Msg184("XSTEP_184");
67     PR.SendFail(Msg184);
68   }
69   //st = PR.ReadInteger(PR.Current(), "Number of edges", length);
70   if (st && length > 0)
71     {
72       tempCurves = new IGESData_HArray1OfIGESEntity(1, length);
73       tempStartVertexList = new IGESSolid_HArray1OfVertexList(1, length);
74       tempStartVertexIndex = new TColStd_HArray1OfInteger(1, length);
75       tempEndVertexList = new IGESSolid_HArray1OfVertexList(1, length);
76       tempEndVertexIndex = new TColStd_HArray1OfInteger(1, length);
77       for (Standard_Integer i=1 ; i<=length ; i++)
78         {
79           // Curves
80           //st = PR.ReadEntity(IR, PR.Current(), Msg185, anent); //szv#4:S4163:12Mar99 moved in if
81           //st = PR.ReadEntity(IR, PR.Current(), "Model space curve", anent);
82           if (PR.ReadEntity(IR, PR.Current(), aStatus, anent))
83             tempCurves->SetValue(i, anent);
84           else{
85             Message_Msg Msg185("XSTEP_185");
86             switch(aStatus) {
87             case IGESData_ReferenceError: {  
88               Message_Msg Msg216 ("IGES_216");
89               Msg185.Arg(Msg216.Value());
90               PR.SendFail(Msg185);
91               break; }
92             case IGESData_EntityError: {
93               Message_Msg Msg217 ("IGES_217");
94               Msg185.Arg(Msg217.Value());
95               PR.SendFail(Msg185);
96               break; }
97             default:{
98             }
99             }
100           }
101           // Start vertex list
102           //st = PR.ReadEntity(IR, PR.Current(), Msg188,
103                              //STANDARD_TYPE(IGESSolid_VertexList), avert); //szv#4:S4163:12Mar99 moved in if
104           /*
105           st = PR.ReadEntity(IR, PR.Current(), "Start vertex list",
106                              STANDARD_TYPE(IGESSolid_VertexList), avert);
107           */
108           if (PR.ReadEntity(IR, PR.Current(), aStatus, STANDARD_TYPE(IGESSolid_VertexList), avert))
109             tempStartVertexList->SetValue(i, avert);
110           else{
111             Message_Msg Msg188("XSTEP_188");
112             switch(aStatus) {
113             case IGESData_ReferenceError: {  
114               Message_Msg Msg216 ("IGES_216");
115               Msg188.Arg(Msg216.Value());
116               PR.SendFail(Msg188);
117               break; }
118             case IGESData_EntityError: {
119               Message_Msg Msg217 ("IGES_217");
120               Msg188.Arg(Msg217.Value());
121               PR.SendFail(Msg188);
122               break; }
123             case IGESData_TypeError: {
124               Message_Msg Msg218 ("IGES_218");
125               Msg188.Arg(Msg218.Value());
126               PR.SendFail(Msg188);
127               break; }
128             default:{
129             }
130             }
131           }
132
133           // Start vertex index
134           //st = PR.ReadInteger(PR.Current(), Msg186, anint); //szv#4:S4163:12Mar99 moved in if
135           //st = PR.ReadInteger(PR.Current(), "Start vertex index", anint);
136           if (PR.ReadInteger(PR.Current(), anint))
137             tempStartVertexIndex->SetValue(i, anint);
138           else{
139             Message_Msg Msg186("XSTEP_186");
140             PR.SendFail(Msg186);
141           }
142
143           // End vertex list
144           //st = PR.ReadEntity(IR, PR.Current(),Msg189 ,
145                              //STANDARD_TYPE(IGESSolid_VertexList), avert); //szv#4:S4163:12Mar99 moved in if
146           /*
147           st = PR.ReadEntity(IR, PR.Current(), "End vertex list",
148                              STANDARD_TYPE(IGESSolid_VertexList), avert);
149           */
150           if (PR.ReadEntity(IR, PR.Current(), aStatus, STANDARD_TYPE(IGESSolid_VertexList), avert))
151             tempEndVertexList->SetValue(i, avert);
152           else{
153             Message_Msg Msg189("XSTEP_189");
154             switch(aStatus) {
155             case IGESData_ReferenceError: {  
156               Message_Msg Msg216 ("IGES_216");
157               Msg189.Arg(Msg216.Value());
158               PR.SendFail(Msg189);
159               break; }
160             case IGESData_EntityError: {
161               Message_Msg Msg217 ("IGES_217");
162               Msg189.Arg(Msg217.Value());
163               PR.SendFail(Msg189);
164               break; }
165             case IGESData_TypeError: {
166               Message_Msg Msg218 ("IGES_218");
167               Msg189.Arg(Msg218.Value());
168               PR.SendFail(Msg189);
169               break; }
170             default:{
171             }
172             }
173           }
174           // End vertex index
175           //st = PR.ReadInteger(PR.Current(), Msg187, anint); //szv#4:S4163:12Mar99 moved in if
176           //st = PR.ReadInteger(PR.Current(), "End vertex index", anint);
177           if (PR.ReadInteger(PR.Current(), anint))
178             tempEndVertexIndex->SetValue(i, anint);
179           else {
180             Message_Msg Msg187("XSTEP_187");
181             PR.SendFail(Msg187);
182           }
183         }
184     }
185   
186   if (st && length <= 0){
187     Message_Msg Msg184("XSTEP_184");
188     PR.SendFail(Msg184);
189   }
190   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
191   if (length > 0) ent->Init
192     (tempCurves, tempStartVertexList, tempStartVertexIndex,
193      tempEndVertexList, tempEndVertexIndex);
194 }
195
196
197 //=======================================================================
198 //function : WriteOwnParams
199 //purpose  : 
200 //=======================================================================
201
202 void IGESSolid_ToolEdgeList::WriteOwnParams(const Handle(IGESSolid_EdgeList)& ent,
203                                             IGESData_IGESWriter& IW) const
204 {
205   Standard_Integer length = ent->NbEdges();
206
207   IW.Send(length);
208   for (Standard_Integer i = 1; i <= length; i ++)
209     {
210       IW.Send(ent->Curve(i));
211       IW.Send(ent->StartVertexList(i));
212       IW.Send(ent->StartVertexIndex(i));
213       IW.Send(ent->EndVertexList(i));
214       IW.Send(ent->EndVertexIndex(i));
215     }
216 }
217
218
219 //=======================================================================
220 //function : OwnShared
221 //purpose  : 
222 //=======================================================================
223
224 void IGESSolid_ToolEdgeList::OwnShared(const Handle(IGESSolid_EdgeList)& ent,
225                                        Interface_EntityIterator& iter) const
226 {
227   Standard_Integer length = ent->NbEdges();
228   for (Standard_Integer i = 1; i <= length; i ++)
229     {
230       iter.GetOneItem(ent->Curve(i));
231       iter.GetOneItem(ent->StartVertexList(i));
232       iter.GetOneItem(ent->EndVertexList(i));
233     }
234 }
235
236
237 //=======================================================================
238 //function : OwnCopy
239 //purpose  : 
240 //=======================================================================
241
242 void IGESSolid_ToolEdgeList::OwnCopy(const Handle(IGESSolid_EdgeList)& another,
243                                      const Handle(IGESSolid_EdgeList)& ent,
244                                      Interface_CopyTool& TC) const
245 {
246   Standard_Integer length;
247
248   length = another->NbEdges();
249   Handle(IGESData_HArray1OfIGESEntity) tempCurves =
250     new IGESData_HArray1OfIGESEntity(1, length);
251   Handle(IGESSolid_HArray1OfVertexList) tempStartVertexList =
252     new IGESSolid_HArray1OfVertexList(1, length);
253   Handle(TColStd_HArray1OfInteger)   tempStartVertexIndex =
254     new TColStd_HArray1OfInteger(1, length);
255   Handle(IGESSolid_HArray1OfVertexList) tempEndVertexList =
256     new IGESSolid_HArray1OfVertexList(1, length);
257   Handle(TColStd_HArray1OfInteger)   tempEndVertexIndex =
258     new TColStd_HArray1OfInteger(1, length);
259
260   for (Standard_Integer i=1 ; i<=length ; i++)
261     {
262       // Curves
263       DeclareAndCast(IGESData_IGESEntity, curve,
264                      TC.Transferred(another->Curve(i)));
265       tempCurves->SetValue(i, curve);
266
267       // Start vertex list
268       DeclareAndCast(IGESSolid_VertexList, start,
269                      TC.Transferred(another->StartVertexList(i)));
270       tempStartVertexList->SetValue(i, start);
271
272       // Start vertex index
273       tempStartVertexIndex->SetValue(i, another->StartVertexIndex(i));
274
275       // End vertex list
276       DeclareAndCast(IGESSolid_VertexList, end,
277                      TC.Transferred(another->EndVertexList(i)));
278       tempEndVertexList->SetValue(i, end);
279
280       // End vertex index
281       tempEndVertexIndex->SetValue(i, another->EndVertexIndex(i));
282     }
283
284   ent->Init (tempCurves, tempStartVertexList, tempStartVertexIndex,
285              tempEndVertexList, tempEndVertexIndex);
286 }
287
288
289 //=======================================================================
290 //function : DirChecker
291 //purpose  : 
292 //=======================================================================
293
294 IGESData_DirChecker IGESSolid_ToolEdgeList::DirChecker
295   (const Handle(IGESSolid_EdgeList)& /* ent */ ) const
296 {
297   IGESData_DirChecker DC(504, 1);
298
299   DC.Structure  (IGESData_DefVoid);
300   DC.LineFont   (IGESData_DefVoid);
301   DC.LineWeight (IGESData_DefVoid);
302   DC.Color      (IGESData_DefVoid);
303
304   DC.SubordinateStatusRequired (1);
305   DC.HierarchyStatusRequired (1);
306   return DC;
307 }
308
309
310 //=======================================================================
311 //function : OwnCheck
312 //purpose  : 
313 //=======================================================================
314
315 void IGESSolid_ToolEdgeList::OwnCheck(const Handle(IGESSolid_EdgeList)& ent,
316                                       const Interface_ShareTool&,
317                                       Handle(Interface_Check)& ach) const
318 {
319   // MGE 03/08/98
320   // Building of messages
321   //========================================
322   //Message_Msg Msg184("XSTEP_184");
323   //========================================
324
325   if (ent->NbEdges() <= 0) {
326     Message_Msg Msg184("XSTEP_184");
327     ach->SendFail(Msg184);
328   }
329 }
330
331
332 //=======================================================================
333 //function : OwnDump
334 //purpose  : 
335 //=======================================================================
336
337 void IGESSolid_ToolEdgeList::OwnDump(const Handle(IGESSolid_EdgeList)& ent,
338                                      const IGESData_IGESDumper& dumper,
339                                      const Handle(Message_Messenger)& S,
340                                      const Standard_Integer level) const
341 {
342   Standard_Integer i, length = ent->NbEdges();
343
344   S << "IGESSolid_EdgeList" << endl;
345   S << "Number of edge tuples : " << length << endl;
346   switch (level)
347     {
348     case 4 :
349       S << "Curves : ";
350       S << "Start Vertex List : ";
351       S << "Start Vertex Index : ";
352       IGESData_DumpVals(S ,level,1, length,ent->StartVertexIndex);
353       S << endl;
354       S << "End Vertex List : ";
355       S << "End Vertex Index : ";
356       IGESData_DumpVals(S ,level,1, length,ent->EndVertexIndex);
357       S << endl;
358       break;
359     case 5 :
360     case 6 :
361       S<<" Curve - Vertices. Start : (VertexList,Index)  End : (VertexList,Index)"<<endl;
362       for (i = 1; i <= length; i ++)
363         {
364 //[123]:Curve : #1234 - Vertices. Start = (#5678 , 3467)  End = (#1234 , 4664)
365           S << "[" << i << "]:Curve : ";
366           dumper.Dump (ent->Curve(i),S, level-5);
367           S <<" - Vertices. Start : (";
368           dumper.Dump (ent->StartVertexList(i),S, 0);
369           S << " , " << ent->StartVertexIndex(i);
370           S << ")  End : (";
371           dumper.Dump (ent->EndVertexList(i),S, 0);
372           S << " , " << ent->EndVertexIndex(i);
373           S << ")"   << endl;
374         }
375       break;
376       default :
377         break;
378     }
379   S << endl;
380 }