0032961: Coding - get rid of unused headers [IGESAppli to IGESToBRep]
[occt.git] / src / IGESGeom / IGESGeom_ToolBoundary.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 <IGESBasic_HArray1OfHArray1OfIGESEntity.hxx>
20 #include <IGESData_DirChecker.hxx>
21 #include <IGESData_Dump.hxx>
22 #include <IGESData_HArray1OfIGESEntity.hxx>
23 #include <IGESData_IGESDumper.hxx>
24 #include <IGESData_IGESEntity.hxx>
25 #include <IGESData_IGESReaderData.hxx>
26 #include <IGESData_IGESWriter.hxx>
27 #include <IGESData_ParamReader.hxx>
28 #include <IGESData_Status.hxx>
29 #include <IGESGeom_Boundary.hxx>
30 #include <IGESGeom_ToolBoundary.hxx>
31 #include <Interface_Check.hxx>
32 #include <Interface_CopyTool.hxx>
33 #include <Interface_EntityIterator.hxx>
34 #include <Interface_Macros.hxx>
35 #include <Interface_ShareTool.hxx>
36 #include <Message_Msg.hxx>
37 #include <Standard_DomainError.hxx>
38 #include <TColStd_HArray1OfInteger.hxx>
39
40 #include <stdio.h>
41 // MGE 30/07/98
42 //=======================================================================
43 //function : IGESGeom_ToolBoundary
44 //purpose  : 
45 //=======================================================================
46 IGESGeom_ToolBoundary::IGESGeom_ToolBoundary ()
47 {
48 }
49
50
51 //=======================================================================
52 //function : ReadOwnParams
53 //purpose  : 
54 //=======================================================================
55
56 void IGESGeom_ToolBoundary::ReadOwnParams(const Handle(IGESGeom_Boundary)& ent,
57                                           const Handle(IGESData_IGESReaderData)& IR,
58                                           IGESData_ParamReader& PR) const
59 {
60   // MGE 30/07/98
61
62   //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
63   Standard_Integer num; //szv#4:S4163:12Mar99 j not needed, i moved down in `for`
64   Standard_Integer tempType, tempPreference;
65   Handle(IGESData_IGESEntity) tempSurface;
66   Handle(TColStd_HArray1OfInteger) tempSenses;
67   Handle(IGESData_HArray1OfIGESEntity) tempModelCurves;
68   Handle(IGESBasic_HArray1OfHArray1OfIGESEntity) tempParameterCurves;
69   IGESData_Status aStatus;
70
71   //szv#4:S4163:12Mar99 `st=` not needed
72   if (!PR.ReadInteger(PR.Current(), tempType)){
73     Message_Msg Msg122("XTSEP_122");
74     PR.SendFail(Msg122);
75   }
76   if (!PR.ReadInteger(PR.Current(), tempPreference)){
77     Message_Msg Msg123("XTSEP_123");
78     PR.SendFail(Msg123);
79   }
80
81   if (!PR.ReadEntity(IR, PR.Current(), aStatus, tempSurface)){
82     Message_Msg Msg124("XTSEP_124");
83     switch(aStatus) {
84     case IGESData_ReferenceError: {  
85       Message_Msg Msg216 ("IGES_216");
86       Msg124.Arg(Msg216.Value());
87       PR.SendFail(Msg124);
88       break; }
89     case IGESData_EntityError: {
90       Message_Msg Msg217 ("IGES_217");
91       Msg124.Arg(Msg217.Value());
92       PR.SendFail(Msg124);
93       break; }
94     default:{
95     }
96     }
97   }
98  
99   if (PR.ReadInteger(PR.Current(), num) && (num > 0)) {
100     tempSenses = new TColStd_HArray1OfInteger(1, num);
101     tempModelCurves = new IGESData_HArray1OfIGESEntity(1, num);
102     tempParameterCurves = new IGESBasic_HArray1OfHArray1OfIGESEntity(1, num);
103   }
104   else{
105     Message_Msg Msg126("XTSEP_126");
106     PR.SendFail(Msg126);
107   }
108
109   if (!tempSenses.IsNull() && !tempModelCurves.IsNull() && !tempParameterCurves.IsNull() ) {
110     for ( Standard_Integer i = 1;  i <= num;  i++ ) //szv#4:S4163:12Mar99 Standard_Integer moved in `for`
111       {
112         Handle(IGESData_IGESEntity) tempEnt;
113         //st = PR.ReadEntity(IR, PR.Current(), Msg127, tempEnt); //szv#4:S4163:12Mar99 moved in if
114         //st = PR.ReadEntity(IR, PR.Current(), "Model Space Curves", tempEnt);
115         if (PR.ReadEntity(IR, PR.Current(), aStatus, tempEnt))
116           tempModelCurves->SetValue(i, tempEnt);
117         else {
118           Message_Msg Msg127("XTSEP_127");
119           switch(aStatus) {
120           case IGESData_ReferenceError: {  
121             Message_Msg Msg216 ("IGES_216");
122             Msg127.Arg(Msg216.Value());
123             PR.SendFail(Msg127);
124             break; }
125           case IGESData_EntityError: {
126             Message_Msg Msg217 ("IGES_217");
127             Msg127.Arg(Msg217.Value());
128             PR.SendFail(Msg127);
129             break; }
130           default:{
131           }
132           }
133         }
134
135         Standard_Integer tempSense;
136         //st = PR.ReadInteger(PR.Current(), Msg128, tempSense); //szv#4:S4163:12Mar99 moved in if
137         //st = PR.ReadInteger(PR.Current(), "Orientation flags", tempSense);
138         if (PR.ReadInteger(PR.Current(), tempSense))
139           tempSenses->SetValue(i, tempSense);
140         else{
141           Message_Msg Msg128("XTSEP_128");
142           PR.SendFail(Msg128);
143         }
144
145         Standard_Integer tempCount;
146         //st = PR.ReadInteger(PR.Current(), Msg129, tempCount); //szv#4:S4163:12Mar99 moved in if
147         //st = PR.ReadInteger(PR.Current(), "Count of Parameter Space Curves", tempCount);
148         //szv#4:S4163:12Mar99 optimized
149 /*      
150         if (st && tempCount >= 0)
151           {
152             Handle(IGESData_HArray1OfIGESEntity) tempParCurves;
153             if (tempCount > 0)
154               st = PR.ReadEnts (IR,PR.CurrentList(tempCount), Msg130, tempParCurves);
155               //st = PR.ReadEnts (IR,PR.CurrentList(tempCount), "Parameter Space Curves", tempParCurves);
156 */
157 /*
158               {
159                 tempParCurves = new
160                   IGESData_HArray1OfIGESEntity(1, tempCount);
161                 for ( j = 1; j <= tempCount; j++ ) {
162                   Handle(IGESData_IGESEntity) tempEnt;
163                   st = PR.ReadEntity(IR, PR.Current(),
164                                      "Parameter Space Curves", tempEnt);
165                   if (st) tempParCurves->SetValue(j, tempEnt);
166                 }
167               }
168 */
169 /*
170             tempParameterCurves->SetValue(i, tempParCurves);
171           }
172         if (st && tempCount < 0)
173           PR.SendFail(Msg129);
174 */
175         if (PR.ReadInteger(PR.Current(), tempCount) && (tempCount >= 0)) {
176               Handle(IGESData_HArray1OfIGESEntity) tempParCurves;
177               if (tempCount > 0){
178                 Message_Msg Msg130("XTSEP_130");
179                 PR.ReadEnts (IR,PR.CurrentList(tempCount), Msg130, tempParCurves); //szv#4:S4163:12Mar99 `st=` not needed
180               }
181               tempParameterCurves->SetValue(i, tempParCurves);
182         }
183         else  {
184           Message_Msg Msg129("XTSEP_129");
185           PR.SendFail(Msg129);
186         }
187       }
188   }
189
190   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
191   ent->Init
192     (tempType, tempPreference, tempSurface, tempModelCurves,
193      tempSenses, tempParameterCurves);
194 }
195
196
197 //=======================================================================
198 //function : WriteOwnParams
199 //purpose  : 
200 //=======================================================================
201
202 void IGESGeom_ToolBoundary::WriteOwnParams(const Handle(IGESGeom_Boundary)& ent,
203                                            IGESData_IGESWriter& IW)  const
204 {
205   Standard_Integer i, j, num1;
206   IW.Send(ent->BoundaryType());
207   IW.Send(ent->PreferenceType());
208   IW.Send(ent->Surface());
209   IW.Send(ent->NbModelSpaceCurves());
210   for ( num1 = ent->NbModelSpaceCurves(), i = 1; i <= num1; i++)
211     {
212       IW.Send(ent->ModelSpaceCurve(i));
213       IW.Send(ent->Sense(i));
214       Handle(IGESData_HArray1OfIGESEntity) curves = ent->ParameterCurves(i);
215       Standard_Integer nbc = ent->NbParameterCurves(i);
216       IW.Send(nbc);
217       if (nbc > 0)
218         {
219           for ( j = 1; j <= nbc; j ++)
220             IW.Send(curves->Value(j));
221         }
222     }
223 }
224
225
226 //=======================================================================
227 //function : OwnShared
228 //purpose  : 
229 //=======================================================================
230
231 void IGESGeom_ToolBoundary::OwnShared(const Handle(IGESGeom_Boundary)& ent,
232                                       Interface_EntityIterator& iter) const
233 {
234   Standard_Integer i, j, num1;
235   iter.GetOneItem(ent->Surface());
236   for ( num1 = ent->NbModelSpaceCurves(), i = 1; i <= num1; i++)
237     {
238       iter.GetOneItem(ent->ModelSpaceCurve(i));
239       Handle(IGESData_HArray1OfIGESEntity) curves = ent->ParameterCurves(i);
240       if (!curves.IsNull())
241         {
242           Standard_Integer nbc = curves->Length();
243           for ( j = 1; j <= nbc; j ++)
244             iter.GetOneItem(curves->Value(j));
245         }
246     }
247 }
248
249
250 //=======================================================================
251 //function : OwnCopy
252 //purpose  : 
253 //=======================================================================
254
255 void IGESGeom_ToolBoundary::OwnCopy(const Handle(IGESGeom_Boundary)& another,
256                                     const Handle(IGESGeom_Boundary)& ent,
257                                     Interface_CopyTool& TC) const
258 {
259   Standard_Integer i, j;
260   Standard_Integer tempType = another->BoundaryType();
261   Standard_Integer tempPreference = another->PreferenceType();
262   Standard_Integer num1 = another->NbModelSpaceCurves();
263
264   DeclareAndCast(IGESData_IGESEntity, tempSurface,
265                  TC.Transferred(another->Surface()) );
266
267   Handle(TColStd_HArray1OfInteger) tempSenses =
268     new TColStd_HArray1OfInteger(1, num1);
269   Handle(IGESData_HArray1OfIGESEntity) tempModelCurves =
270     new IGESData_HArray1OfIGESEntity(1, num1);
271   Handle(IGESBasic_HArray1OfHArray1OfIGESEntity) tempParameterCurves =
272     new IGESBasic_HArray1OfHArray1OfIGESEntity(1, num1);
273
274   for ( i = 1; i <= num1; i++ )
275     {
276       DeclareAndCast(IGESData_IGESEntity, tempEnt,
277                      TC.Transferred(another->ModelSpaceCurve(i)) );
278       tempModelCurves->SetValue(i, tempEnt);
279       tempSenses->SetValue(i, another->Sense(i));
280       Standard_Integer num2 = another->NbParameterCurves(i);
281       Handle(IGESData_HArray1OfIGESEntity) ParCurves =
282         another->ParameterCurves(i);
283       Handle(IGESData_HArray1OfIGESEntity) tempParCurves;
284       if (num2 > 0) tempParCurves = new IGESData_HArray1OfIGESEntity(1, num2);
285       for ( j = 1; j <= num2; j++ )
286         {
287           DeclareAndCast(IGESData_IGESEntity, tempEnt1,
288                          TC.Transferred(ParCurves->Value(j)) );
289           tempParCurves->SetValue(j, tempEnt1);
290         }
291       tempParameterCurves->SetValue(i, tempParCurves);
292     }
293   ent->Init(tempType, tempPreference, tempSurface, tempModelCurves,
294             tempSenses, tempParameterCurves);
295 }
296
297
298 //=======================================================================
299 //function : OwnCorrect
300 //purpose  : 
301 //=======================================================================
302
303 Standard_Boolean IGESGeom_ToolBoundary::OwnCorrect
304   (const Handle(IGESGeom_Boundary)& ent) const
305 {
306 //  Standard_Boolean t0 = (ent->BoundaryType() == 0);
307   Standard_Boolean res = Standard_False;
308   Standard_Boolean r2d = Standard_False;
309   Standard_Integer nb = ent->NbModelSpaceCurves();
310   Standard_Integer i; // svv Jan11 2000 : porting on DEC
311   for (i = 1; i <= nb; i ++) {
312     Standard_Integer nbi = ent->NbParameterCurves(i);
313     if (nbi == 0) continue;
314     for (Standard_Integer j = 1; j <= nbi; j ++) {
315       Handle(IGESData_IGESEntity) c2d = ent->ParameterCurve (i,j);
316       if (c2d.IsNull()) continue;
317       c2d->InitStatus
318         (c2d->BlankStatus(),c2d->SubordinateStatus(),5,c2d->HierarchyStatus());
319       res = Standard_True;
320     }
321     r2d = Standard_True;
322   }
323   if (!r2d) return res;
324   if (ent->BoundaryType() != 0) return res;    // OK
325
326 //  Reste Boundary Type : s ilya des ParameterCurves, il doit valoir 1
327 //  On reconstruit donc la Boundary a l identique, mais avec BoundaryType = 1
328
329 // si type = 0, annuller tous les ParameterCurves
330 //  -> On reconstruit, avec ParameterCurves Nulles
331 // En plus, les ParameterCurves doivent avoir leur UseFlag a 5
332
333   Handle(IGESBasic_HArray1OfHArray1OfIGESEntity) cv2d  =
334     new IGESBasic_HArray1OfHArray1OfIGESEntity(1,nb);
335   Handle(IGESData_HArray1OfIGESEntity) modcv  =
336     new IGESData_HArray1OfIGESEntity(1,nb);
337   Handle(TColStd_HArray1OfInteger) senses = new TColStd_HArray1OfInteger(1,nb);
338   for (i = 1; i <= nb; i ++) {
339     senses->SetValue(i, ent->Sense(i));
340     modcv->SetValue (i, ent->ModelSpaceCurve(i));
341     cv2d->SetValue  (i, ent->ParameterCurves(i));
342   }
343   ent->Init (1, ent->PreferenceType(), ent->Surface(),
344              modcv, senses, cv2d);
345   return Standard_True;
346 }
347
348
349 //=======================================================================
350 //function : DirChecker
351 //purpose  : 
352 //=======================================================================
353
354 IGESData_DirChecker IGESGeom_ToolBoundary::DirChecker
355   (const Handle(IGESGeom_Boundary)& /* ent */ )  const
356 {
357   IGESData_DirChecker DC(141, 0);
358   DC.Structure(IGESData_DefVoid);
359   DC.GraphicsIgnored();
360   DC.LineFont(IGESData_DefAny);
361 //  DC.LineWeight(IGESData_DefValue);
362   DC.Color(IGESData_DefAny);
363   DC.SubordinateStatusRequired(0);
364   DC.HierarchyStatusIgnored();
365   return DC;
366 }
367
368
369 //=======================================================================
370 //function : OwnCheck
371 //purpose  : 
372 //=======================================================================
373
374 void IGESGeom_ToolBoundary::OwnCheck(const Handle(IGESGeom_Boundary)& ent,
375                                      const Interface_ShareTool&,
376                                      Handle(Interface_Check)& ach)  const
377 {
378   // MGE 30/07/98
379   // Building of messages
380   //========================================
381   //Message_Msg Msg122("XTSEP_122");
382   //Message_Msg Msg123("XTSEP_123");
383   //Message_Msg Msg125("XTSEP_125");
384   //Message_Msg Msg128("XTSEP_128");
385   //========================================
386
387   if ((ent->BoundaryType() != 0) && (ent->BoundaryType() != 1)) {
388     Message_Msg Msg122("XTSEP_122");
389     ach->SendFail(Msg122);
390   }
391   if ((ent->PreferenceType() < 0) || (ent->PreferenceType() > 3)) {
392     Message_Msg Msg123("XTSEP_123");
393     ach->SendFail(Msg123);
394   }
395
396 // il faudrait aussi tester que, pour BoundaryType = 1, la Surface est bien
397 //  Parametrique ... (au moins un cas ne passe pas : c est Plane 108)
398   if (ent->BoundaryType() == 1) {
399     if (ent->Surface()->TypeNumber() == 108) {
400       Message_Msg Msg125("XTSEP_125");
401       ach->SendFail(Msg125);
402     }
403   }
404
405   Standard_Integer i, num;
406   for ( num = ent->NbModelSpaceCurves(), i = 1; i <= num; i++ )
407     if (ent->Sense(i) != 1 && ent->Sense(i) != 2) {
408       Message_Msg Msg128("XTSEP_128");
409       ach->SendFail(Msg128);
410     }
411 /*
412   if (ent->BoundaryType() == 0)
413     for ( num = ent->NbModelSpaceCurves(), i = 1; i <= num; i++ )
414       if (ent->NbParameterCurves(i) != 0)
415         {
416           char mess[80];
417           sprintf(mess,"Nb. Parameter Space Curve %d !=0 while Boundary Type=0",i);
418           ach.SendFail(mess);
419         }
420 */
421 }
422
423
424 //=======================================================================
425 //function : OwnDump
426 //purpose  : 
427 //=======================================================================
428
429 void IGESGeom_ToolBoundary::OwnDump(const Handle(IGESGeom_Boundary)& ent,
430                                     const IGESData_IGESDumper& dumper,
431                                     Standard_OStream& S,
432                                     const Standard_Integer level)  const
433 {
434   Standard_Integer i, num, sublevel = (level > 4) ? 1 : 0;
435   S << "IGESGeom_Boundary\n"
436     << "Bounded Surface Representation Type : " << ent->BoundaryType() << "\n"
437     << "Trimming Curves Representation : " << ent->PreferenceType() << "\n"
438     << "Bounded Surface    : ";
439   dumper.Dump(ent->Surface(),S, sublevel);
440   S << "\n"
441     << "Model Space Curves :\n"
442     << "Orientation Flags  :\n"
443     << "Parameter Curves Set : ";
444   IGESData_DumpEntities(S,dumper,-level,1,ent->NbModelSpaceCurves(),ent->ModelSpaceCurve);
445   S << "\n";
446   if (level > 4)
447     for ( num = ent->NbModelSpaceCurves(), i = 1; i <= num; i++ )
448       {
449         S << "[" << i << "]: "
450           << "Model Space Curve : ";
451         dumper.Dump (ent->ModelSpaceCurve(i),S, 1);
452         S << "  Orientation Flags : " << ent->Sense(i) << "\n"
453           << "  Parameter Curves : ";
454         Handle(IGESData_HArray1OfIGESEntity) curves = ent->ParameterCurves(i);
455         if (!curves.IsNull()) {
456           IGESData_DumpEntities(S,dumper, level,1,curves->Length(),curves->Value);
457         }
458         else
459   {
460     S << " List Empty";
461   }
462         S << "\n";
463       }
464   S << std::endl;
465 }