0030895: Coding Rules - specify std namespace explicitly for std::cout and streams
[occt.git] / src / IGESSolid / IGESSolid_ToolLoop.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 //pdn 20.04.99 STC22655 avoid of exceptions on empty loops
19
20 #include <IGESBasic_HArray1OfHArray1OfIGESEntity.hxx>
21 #include <IGESBasic_HArray1OfHArray1OfInteger.hxx>
22 #include <IGESData_DirChecker.hxx>
23 #include <IGESData_Dump.hxx>
24 #include <IGESData_HArray1OfIGESEntity.hxx>
25 #include <IGESData_IGESDumper.hxx>
26 #include <IGESData_IGESEntity.hxx>
27 #include <IGESData_IGESReaderData.hxx>
28 #include <IGESData_IGESWriter.hxx>
29 #include <IGESData_ParamCursor.hxx>
30 #include <IGESData_ParamReader.hxx>
31 #include <IGESData_Status.hxx>
32 #include <IGESSolid_EdgeList.hxx>
33 #include <IGESSolid_Loop.hxx>
34 #include <IGESSolid_ToolLoop.hxx>
35 #include <IGESSolid_VertexList.hxx>
36 #include <Interface_Check.hxx>
37 #include <Interface_CopyTool.hxx>
38 #include <Interface_EntityIterator.hxx>
39 #include <Interface_Macros.hxx>
40 #include <Interface_ShareTool.hxx>
41 #include <Message_Messenger.hxx>
42 #include <Message_Msg.hxx>
43 #include <Standard_DomainError.hxx>
44 #include <TColStd_HArray1OfInteger.hxx>
45
46 #include <stdio.h>
47 // MGE 03/08/98
48 //=======================================================================
49 //function : IGESSolid_ToolLoop
50 //purpose  : 
51 //=======================================================================
52 IGESSolid_ToolLoop::IGESSolid_ToolLoop ()
53 {
54 }
55
56
57 //=======================================================================
58 //function : ReadOwnParams
59 //purpose  : 
60 //=======================================================================
61
62 void IGESSolid_ToolLoop::ReadOwnParams (const Handle(IGESSolid_Loop)& ent,
63                                         const Handle(IGESData_IGESReaderData)& IR,
64                                         IGESData_ParamReader& PR) const
65 {
66   // MGE 03/08/98
67
68   Standard_Boolean abool; //szv#4:S4163:12Mar99 `st` moved down
69   Standard_Integer nbedges = 0;
70   Standard_Integer i, j;
71   Standard_Integer anint;
72   Handle(IGESData_IGESEntity) anent;
73   Handle(TColStd_HArray1OfInteger) tempTypes;
74   Handle(IGESData_HArray1OfIGESEntity) tempEdges;
75   Handle(TColStd_HArray1OfInteger) tempIndex;
76   Handle(TColStd_HArray1OfInteger) tempOrientation;
77   Handle(TColStd_HArray1OfInteger) nbParameterCurves;
78   Handle(IGESBasic_HArray1OfHArray1OfInteger) isoparametricFlags;
79   Handle(IGESBasic_HArray1OfHArray1OfIGESEntity) tempCurves;
80   IGESData_Status aStatus;
81
82   //st = PR.ReadInteger(PR.Current(),Msg184, nbedges); //szv#4:S4163:12Mar99 moved in if
83   //st = PR.ReadInteger(PR.Current(), "Number of edges", nbedges);
84   Standard_Boolean sb = PR.ReadInteger(PR.Current(), nbedges);
85   if (sb && (nbedges > 0)) {
86    
87     Message_Msg Msg180("XSTEP_180");
88     Message_Msg Msg190("XSTEP_190");
89
90     tempTypes = new TColStd_HArray1OfInteger(1, nbedges);
91     tempEdges = new IGESData_HArray1OfIGESEntity(1, nbedges);
92     tempIndex = new TColStd_HArray1OfInteger(1, nbedges);
93     tempOrientation = new TColStd_HArray1OfInteger(1, nbedges);
94     nbParameterCurves = new TColStd_HArray1OfInteger(1, nbedges);
95     isoparametricFlags =
96       new IGESBasic_HArray1OfHArray1OfInteger(1, nbedges);
97     tempCurves =
98       new IGESBasic_HArray1OfHArray1OfIGESEntity(1, nbedges);
99     
100     for (i=1; i<= nbedges; i++)
101       {
102         //st = PR.ReadInteger(PR.Current(), Msg190, anint); //szv#4:S4163:12Mar99 moved in if
103         //st = PR.ReadInteger(PR.Current(), "Edge types", anint);
104         if (PR.ReadInteger(PR.Current(), anint))
105           tempTypes->SetValue(i, anint);
106         else  PR.SendFail(Msg190);
107         
108         if (!PR.ReadEntity(IR, PR.Current(), aStatus, anent)){ //szv#4:S4163:12Mar99 `st=` not needed
109             Message_Msg Msg193("XSTEP_193");
110             switch(aStatus) {
111             case IGESData_ReferenceError: {  
112               Message_Msg Msg216 ("IGES_216");
113               Msg193.Arg(Msg216.Value());
114               PR.SendFail(Msg193);
115               break; }
116             case IGESData_EntityError: {
117               Message_Msg Msg217 ("IGES_217");
118               Msg193.Arg(Msg217.Value());
119               PR.SendFail(Msg193);
120               break; }
121             default:{
122             }
123             }
124           }
125         //st = PR.ReadEntity(IR, PR.Current(), "Edges", anent);
126         //if (!st) {  }    // WARNING : Two possible Types : //szv#4:S4163:12Mar99 not needed
127         if (!anent->IsKind(STANDARD_TYPE(IGESSolid_VertexList))
128             && !anent->IsKind(STANDARD_TYPE(IGESSolid_EdgeList)) )
129           PR.SendFail(Msg190);
130         else  tempEdges->SetValue(i, anent);
131         
132         //st = PR.ReadInteger(PR.Current(), Msg191, anint); //szv#4:S4163:12Mar99 moved in if
133         //st = PR.ReadInteger(PR.Current(), "List index", anint);
134         if (PR.ReadInteger(PR.Current(), anint))
135           tempIndex->SetValue(i, anint);
136         else{
137           Message_Msg Msg191("XSTEP_191");
138           PR.SendFail(Msg191);
139         }
140         
141         //st = PR.ReadBoolean(PR.Current(), Msg180, abool); //szv#4:S4163:12Mar99 moved in if
142         //st = PR.ReadBoolean(PR.Current(), "Orientation flags", abool);
143         if (PR.ReadBoolean(PR.Current(), Msg180, abool))
144           tempOrientation->SetValue(i, (abool ? 1 : 0));    // bool;
145         
146         Standard_Boolean st = PR.ReadInteger(PR.Current(),anint);
147         if(!st){
148           Message_Msg Msg192("XSTEP_192");
149           PR.SendFail(Msg192);
150         }
151         //st = PR.ReadInteger(PR.Current(), "Number of parameter curves", anint);
152         if (st && anint > 0)
153           {
154             Message_Msg Msg195("XSTEP_195");
155             nbParameterCurves->SetValue(i, anint);
156             Handle(IGESData_HArray1OfIGESEntity) tmpents =
157               new IGESData_HArray1OfIGESEntity(1, anint);
158             Handle(TColStd_HArray1OfInteger) tmpints =
159               new TColStd_HArray1OfInteger(1, anint);
160             for (j = 1; j <= anint; j ++)
161               {
162                 //st = PR.ReadBoolean(PR.Current(), Msg195, abool); //szv#4:S4163:12Mar99 moved in if
163                 //st = PR.ReadBoolean(PR.Current(), "Isoparametric flags", abool);
164                 if (PR.ReadBoolean(PR.Current(), Msg195, abool))
165                   tmpints->SetValue(j, (abool ? 1 : 0));    // bool;
166                 
167                 //st = PR.ReadEntity(IR, PR.Current(), Msg194, anent); //szv#4:S4163:12Mar99 moved in if
168                 //st = PR.ReadEntity(IR, PR.Current(), "Curves", anent);
169                 if (PR.ReadEntity(IR, PR.Current(), aStatus, anent))
170                   tmpents->SetValue(j, anent);
171                 else {
172                   Message_Msg Msg194("XSTEP_194");
173                   switch(aStatus) {
174                   case IGESData_ReferenceError: {  
175                     Message_Msg Msg216 ("IGES_216");
176                     Msg194.Arg(Msg216.Value());
177                     PR.SendFail(Msg194);
178                     break; }
179                   case IGESData_EntityError: {
180                     Message_Msg Msg217 ("IGES_217");
181                     Msg194.Arg(Msg217.Value());
182                     PR.SendFail(Msg194);
183                     break; }
184                   default:{
185                   }
186                   }
187                 }
188               }
189             isoparametricFlags->SetValue(i, tmpints);
190             tempCurves->SetValue(i, tmpents);
191           }
192         else  nbParameterCurves->SetValue(i, anint);
193       }
194   }
195   else {
196     //pdn 20.04.99 STC22655 avoid of exceptions on empty loops
197     Message_Msg Msg184("XSTEP_184");
198     PR.SendFail(Msg184);
199     return;
200   }   
201
202   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
203   ent->Init
204     (tempTypes, tempEdges, tempIndex, tempOrientation,
205      nbParameterCurves, isoparametricFlags, tempCurves);
206 }
207
208
209 //=======================================================================
210 //function : WriteOwnParams
211 //purpose  : 
212 //=======================================================================
213
214 void IGESSolid_ToolLoop::WriteOwnParams(const Handle(IGESSolid_Loop)& ent,
215                                         IGESData_IGESWriter& IW) const
216 {
217   Standard_Integer i, j;
218   Standard_Integer length = ent->NbEdges();
219
220   IW.Send(length);
221   for (i = 1; i <= length; i ++)
222     {
223       IW.Send(ent->EdgeType(i));
224       IW.Send(ent->Edge(i));
225       IW.Send(ent->ListIndex(i));
226       IW.SendBoolean(ent->Orientation(i));
227       IW.Send(ent->NbParameterCurves(i));
228       for (j = 1; j <= ent->NbParameterCurves(i); j ++)
229         {
230           IW.SendBoolean(ent->IsIsoparametric(i,j));
231           IW.Send(ent->ParametricCurve(i,j));
232         }
233     }
234 }
235
236
237 //=======================================================================
238 //function : OwnShared
239 //purpose  : 
240 //=======================================================================
241
242 void IGESSolid_ToolLoop::OwnShared(const Handle(IGESSolid_Loop)& ent,
243                                    Interface_EntityIterator& iter) const
244 {
245   Standard_Integer i, j;
246   Standard_Integer length = ent->NbEdges();
247
248   for (i = 1; i <= length; i ++)
249     {
250       iter.GetOneItem(ent->Edge(i));
251       for (j = 1; j <= ent->NbParameterCurves(i); j ++)
252         iter.GetOneItem(ent->ParametricCurve(i,j));
253     }
254 }
255
256
257 //=======================================================================
258 //function : OwnCopy
259 //purpose  : 
260 //=======================================================================
261
262 void IGESSolid_ToolLoop::OwnCopy(const Handle(IGESSolid_Loop)& another,
263                                  const Handle(IGESSolid_Loop)& ent,
264                                  Interface_CopyTool& TC) const
265 {
266   Standard_Integer nbedges = another->NbEdges();
267   Standard_Integer i, j;
268   Standard_Integer anint;
269
270   Handle(TColStd_HArray1OfInteger) tempTypes =
271     new TColStd_HArray1OfInteger(1, nbedges);
272   Handle(IGESData_HArray1OfIGESEntity) tempEdges =
273     new IGESData_HArray1OfIGESEntity(1, nbedges);
274   Handle(TColStd_HArray1OfInteger) tempIndex =
275     new TColStd_HArray1OfInteger(1, nbedges);
276   Handle(TColStd_HArray1OfInteger) tempOrientation =
277     new TColStd_HArray1OfInteger(1, nbedges);
278   Handle(TColStd_HArray1OfInteger) nbParameterCurves =
279     new TColStd_HArray1OfInteger(1, nbedges);
280   Handle(IGESBasic_HArray1OfHArray1OfInteger) isoparametricFlags =
281     new IGESBasic_HArray1OfHArray1OfInteger(1, nbedges);
282   Handle(IGESBasic_HArray1OfHArray1OfIGESEntity) tempCurves =
283     new IGESBasic_HArray1OfHArray1OfIGESEntity(1, nbedges);
284
285   for (i = 1; i <= nbedges; i ++)
286     {
287       tempTypes->SetValue(i, another->EdgeType(i));
288
289       DeclareAndCast(IGESData_IGESEntity, anent,
290                      TC.Transferred(another->Edge(i)));
291       tempEdges->SetValue(i, anent);
292
293       tempIndex->SetValue(i, another->ListIndex(i));
294
295       tempOrientation->SetValue(i, (another->Orientation(i) ? 1 : 0) );
296
297       anint = another->NbParameterCurves(i);
298       nbParameterCurves->SetValue(i, anint);
299
300       Handle(IGESData_HArray1OfIGESEntity) tmpents;
301       if (anint > 0) tmpents = new IGESData_HArray1OfIGESEntity(1, anint);
302       Handle(TColStd_HArray1OfInteger) tmpints;
303       if (anint > 0) tmpints = new TColStd_HArray1OfInteger(1, anint);
304       for (j = 1; j <= anint; j ++)
305         {
306           tmpints->SetValue(j, (another->IsIsoparametric(i, j) ? 1 : 0) );
307
308           DeclareAndCast(IGESData_IGESEntity, localent,
309                          TC.Transferred(another->ParametricCurve(i, j)));
310           tmpents->SetValue(j, localent);
311         }
312       isoparametricFlags->SetValue(i, tmpints);
313       tempCurves->SetValue(i, tmpents);
314     }
315   ent->Init(tempTypes, tempEdges, tempIndex, tempOrientation,
316             nbParameterCurves, isoparametricFlags, tempCurves);
317 }
318
319
320 //=======================================================================
321 //function : DirChecker
322 //purpose  : 
323 //=======================================================================
324
325 IGESData_DirChecker IGESSolid_ToolLoop::DirChecker
326   (const Handle(IGESSolid_Loop)& /* ent  */) const
327 {
328   IGESData_DirChecker DC(508, 0,1);
329
330   DC.Structure  (IGESData_DefVoid);
331   DC.LineFont   (IGESData_DefVoid);
332   DC.LineWeight (IGESData_DefVoid);
333   DC.Color      (IGESData_DefVoid);
334
335   DC.SubordinateStatusRequired(1);
336   return DC;
337 }
338
339
340 //=======================================================================
341 //function : OwnCheck
342 //purpose  : 
343 //=======================================================================
344
345 void IGESSolid_ToolLoop::OwnCheck(const Handle(IGESSolid_Loop)& ent,
346                                   const Interface_ShareTool&,
347                                   Handle(Interface_Check)& ach) const
348 {
349   // MGE 03/08/98
350   // Building of messages
351   //========================================
352   //Message_Msg Msg190("XSTEP_190");
353   //========================================
354
355   Standard_Integer upper = ent->NbEdges();
356   for (Standard_Integer i = 1; i <= upper; i ++)
357     if (ent->EdgeType(i) != 0 && ent->EdgeType(i) != 1) {
358       Message_Msg Msg190("XSTEP_190");
359       ach->SendFail(Msg190);
360     }
361 }
362
363
364 //=======================================================================
365 //function : OwnDump
366 //purpose  : 
367 //=======================================================================
368
369 void IGESSolid_ToolLoop::OwnDump(const Handle(IGESSolid_Loop)& ent,
370                                  const IGESData_IGESDumper& dumper,
371                                  const Handle(Message_Messenger)& S,
372                                  const Standard_Integer level) const
373 {
374   Standard_Integer i, j;
375   Standard_Integer nbedges  = ent->NbEdges();
376   Standard_Integer sublevel = (level <= 4) ? 0 : 1;
377
378   S << "IGESSolid_Loop" << Message_EndLine;
379
380   S << "Edge types : " << Message_EndLine;
381   S << "Edges      : " << Message_EndLine;
382   S << "List index : " << Message_EndLine;
383   S << "Orientation flags : " << Message_EndLine;
384   S << "Parametric flags  : ";
385   IGESData_DumpEntities(S,dumper,-level,1, nbedges,ent->Edge);
386   S << Message_EndLine;
387   if (level > 4)
388     {
389       S << "[ ";
390       for (i = 1; i <= nbedges; i ++)
391         {
392           Standard_Integer nbc = ent->NbParameterCurves(i);
393           S << "[" << i << "]:  ";
394           S << "Edge type : " << ent->EdgeType(i) << "  ";
395           S << "Edge : ";
396           dumper.Dump (ent->Edge(i),S, sublevel);
397           S << "  - Index : " << ent->ListIndex(i)
398             << ", Orientation flag : " << ( ent->Orientation(i) ? "Positive" : "Negative" )
399             << ", Number of parametric curves : " << nbc;
400           if (nbc != 0)
401             {
402               if (level <= 5) S << "[ ask level > 5 for content ]";
403               else {
404                 S << ":\n [ ";
405                 for (j = 1; j <= nbc; j ++)
406                   {
407                     S << "[" << j << "]:  ";
408                     S << "Isoparametric flag : "
409                       << ( ent->IsIsoparametric(i,j) ? "True" : "False" ) << "  ";
410                     S << "Parametric curve : ";
411                     dumper.Dump (ent->ParametricCurve(i,j),S, sublevel);
412                     S << Message_EndLine;
413                   }
414                 S << " ]";
415               }
416             }
417           S << Message_EndLine;
418         }
419       S << " ]";
420     }
421   S << Message_EndLine;
422 }