summaryrefslogtreecommitdiff
path: root/src/IGESSolid/IGESSolid_ToolLoop.cxx
blob: 4fe06e68fefa05385ff8a8aa2c30e9a0d6289eca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
//--------------------------------------------------------------------
//
//  File Name : IGESSolid_Loop.cxx
//  Date      :
//  Author    : CKY / Contract Toubro-Larsen
//  Copyright : MATRA-DATAVISION 1993
//
//--------------------------------------------------------------------
//pdn 20.04.99 STC22655 avoid of exceptions on empty loops

#include <IGESSolid_ToolLoop.ixx>
#include <IGESData_ParamCursor.hxx>
#include <IGESData_IGESEntity.hxx>
#include <IGESData_HArray1OfIGESEntity.hxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <IGESBasic_HArray1OfHArray1OfInteger.hxx>
#include <IGESBasic_HArray1OfHArray1OfIGESEntity.hxx>
#include <IGESData_Dump.hxx>
#include <IGESSolid_EdgeList.hxx>
#include <IGESSolid_VertexList.hxx>
#include <Interface_Macros.hxx>
#include <stdio.h>

// MGE 03/08/98
#include <Message_Msg.hxx>
#include <IGESData_Status.hxx>

//=======================================================================
//function : IGESSolid_ToolLoop
//purpose  : 
//=======================================================================

IGESSolid_ToolLoop::IGESSolid_ToolLoop ()
{
}


//=======================================================================
//function : ReadOwnParams
//purpose  : 
//=======================================================================

void IGESSolid_ToolLoop::ReadOwnParams (const Handle(IGESSolid_Loop)& ent,
                                        const Handle(IGESData_IGESReaderData)& IR,
                                        IGESData_ParamReader& PR) const
{
  // MGE 03/08/98

  Standard_Boolean abool; //szv#4:S4163:12Mar99 `st` moved down
  Standard_Integer nbedges = 0;
  Standard_Integer i, j;
  Standard_Integer anint;
  Handle(IGESData_IGESEntity) anent;
  Handle(TColStd_HArray1OfInteger) tempTypes;
  Handle(IGESData_HArray1OfIGESEntity) tempEdges;
  Handle(TColStd_HArray1OfInteger) tempIndex;
  Handle(TColStd_HArray1OfInteger) tempOrientation;
  Handle(TColStd_HArray1OfInteger) nbParameterCurves;
  Handle(IGESBasic_HArray1OfHArray1OfInteger) isoparametricFlags;
  Handle(IGESBasic_HArray1OfHArray1OfIGESEntity) tempCurves;
  IGESData_Status aStatus;

  //st = PR.ReadInteger(PR.Current(),Msg184, nbedges); //szv#4:S4163:12Mar99 moved in if
  //st = PR.ReadInteger(PR.Current(), "Number of edges", nbedges);
  Standard_Boolean sb = PR.ReadInteger(PR.Current(), nbedges);
  if (sb && (nbedges > 0)) {
   
    Message_Msg Msg180("XSTEP_180");
    Message_Msg Msg190("XSTEP_190");

    tempTypes = new TColStd_HArray1OfInteger(1, nbedges);
    tempEdges = new IGESData_HArray1OfIGESEntity(1, nbedges);
    tempIndex = new TColStd_HArray1OfInteger(1, nbedges);
    tempOrientation = new TColStd_HArray1OfInteger(1, nbedges);
    nbParameterCurves = new TColStd_HArray1OfInteger(1, nbedges);
    isoparametricFlags =
      new IGESBasic_HArray1OfHArray1OfInteger(1, nbedges);
    tempCurves =
      new IGESBasic_HArray1OfHArray1OfIGESEntity(1, nbedges);
    
    for (i=1; i<= nbedges; i++)
      {
	//st = PR.ReadInteger(PR.Current(), Msg190, anint); //szv#4:S4163:12Mar99 moved in if
	//st = PR.ReadInteger(PR.Current(), "Edge types", anint);
	if (PR.ReadInteger(PR.Current(), anint))
	  tempTypes->SetValue(i, anint);
	else  PR.SendFail(Msg190);
	
	if (!PR.ReadEntity(IR, PR.Current(), aStatus, anent)){ //szv#4:S4163:12Mar99 `st=` not needed
	    Message_Msg Msg193("XSTEP_193");
	    switch(aStatus) {
	    case IGESData_ReferenceError: {  
	      Message_Msg Msg216 ("IGES_216");
	      Msg193.Arg(Msg216.Value());
	      PR.SendFail(Msg193);
	      break; }
	    case IGESData_EntityError: {
	      Message_Msg Msg217 ("IGES_217");
	      Msg193.Arg(Msg217.Value());
	      PR.SendFail(Msg193);
	      break; }
	    default:{
	    }
	    }
	  }
	//st = PR.ReadEntity(IR, PR.Current(), "Edges", anent);
	//if (!st) {  }    // WARNING : Two possible Types : //szv#4:S4163:12Mar99 not needed
	if (!anent->IsKind(STANDARD_TYPE(IGESSolid_VertexList))
	    && !anent->IsKind(STANDARD_TYPE(IGESSolid_EdgeList)) )
	  PR.SendFail(Msg190);
	else  tempEdges->SetValue(i, anent);
	
	//st = PR.ReadInteger(PR.Current(), Msg191, anint); //szv#4:S4163:12Mar99 moved in if
	//st = PR.ReadInteger(PR.Current(), "List index", anint);
	if (PR.ReadInteger(PR.Current(), anint))
	  tempIndex->SetValue(i, anint);
	else{
	  Message_Msg Msg191("XSTEP_191");
	  PR.SendFail(Msg191);
	}
	
	//st = PR.ReadBoolean(PR.Current(), Msg180, abool); //szv#4:S4163:12Mar99 moved in if
	//st = PR.ReadBoolean(PR.Current(), "Orientation flags", abool);
	if (PR.ReadBoolean(PR.Current(), Msg180, abool))
	  tempOrientation->SetValue(i, (abool ? 1 : 0));    // bool;
	
	Standard_Boolean st = PR.ReadInteger(PR.Current(),anint);
	if(!st){
	  Message_Msg Msg192("XSTEP_192");
	  PR.SendFail(Msg192);
	}
	//st = PR.ReadInteger(PR.Current(), "Number of parameter curves", anint);
	if (st && anint > 0)
	  {
	    Message_Msg Msg195("XSTEP_195");
	    nbParameterCurves->SetValue(i, anint);
	    Handle(IGESData_HArray1OfIGESEntity) tmpents =
	      new IGESData_HArray1OfIGESEntity(1, anint);
	    Handle(TColStd_HArray1OfInteger) tmpints =
	      new TColStd_HArray1OfInteger(1, anint);
	    for (j = 1; j <= anint; j ++)
	      {
		//st = PR.ReadBoolean(PR.Current(), Msg195, abool); //szv#4:S4163:12Mar99 moved in if
		//st = PR.ReadBoolean(PR.Current(), "Isoparametric flags", abool);
		if (PR.ReadBoolean(PR.Current(), Msg195, abool))
		  tmpints->SetValue(j, (abool ? 1 : 0));    // bool;
		
		//st = PR.ReadEntity(IR, PR.Current(), Msg194, anent); //szv#4:S4163:12Mar99 moved in if
		//st = PR.ReadEntity(IR, PR.Current(), "Curves", anent);
		if (PR.ReadEntity(IR, PR.Current(), aStatus, anent))
		  tmpents->SetValue(j, anent);
		else {
		  Message_Msg Msg194("XSTEP_194");
		  switch(aStatus) {
		  case IGESData_ReferenceError: {  
		    Message_Msg Msg216 ("IGES_216");
		    Msg194.Arg(Msg216.Value());
		    PR.SendFail(Msg194);
		    break; }
		  case IGESData_EntityError: {
		    Message_Msg Msg217 ("IGES_217");
		    Msg194.Arg(Msg217.Value());
		    PR.SendFail(Msg194);
		    break; }
		  default:{
		  }
		  }
		}
	      }
	    isoparametricFlags->SetValue(i, tmpints);
	    tempCurves->SetValue(i, tmpents);
	  }
	else  nbParameterCurves->SetValue(i, anint);
      }
  }
  else {
    //pdn 20.04.99 STC22655 avoid of exceptions on empty loops
    Message_Msg Msg184("XSTEP_184");
    PR.SendFail(Msg184);
    return;
  }   

  DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
  ent->Init
    (tempTypes, tempEdges, tempIndex, tempOrientation,
     nbParameterCurves, isoparametricFlags, tempCurves);
}


//=======================================================================
//function : WriteOwnParams
//purpose  : 
//=======================================================================

void IGESSolid_ToolLoop::WriteOwnParams(const Handle(IGESSolid_Loop)& ent,
                                        IGESData_IGESWriter& IW) const
{
  Standard_Integer i, j;
  Standard_Integer length = ent->NbEdges();

  IW.Send(length);
  for (i = 1; i <= length; i ++)
    {
      IW.Send(ent->EdgeType(i));
      IW.Send(ent->Edge(i));
      IW.Send(ent->ListIndex(i));
      IW.SendBoolean(ent->Orientation(i));
      IW.Send(ent->NbParameterCurves(i));
      for (j = 1; j <= ent->NbParameterCurves(i); j ++)
	{
          IW.SendBoolean(ent->IsIsoparametric(i,j));
          IW.Send(ent->ParametricCurve(i,j));
	}
    }
}


//=======================================================================
//function : OwnShared
//purpose  : 
//=======================================================================

void IGESSolid_ToolLoop::OwnShared(const Handle(IGESSolid_Loop)& ent,
                                   Interface_EntityIterator& iter) const
{
  Standard_Integer i, j;
  Standard_Integer length = ent->NbEdges();

  for (i = 1; i <= length; i ++)
    {
      iter.GetOneItem(ent->Edge(i));
      for (j = 1; j <= ent->NbParameterCurves(i); j ++)
	iter.GetOneItem(ent->ParametricCurve(i,j));
    }
}


//=======================================================================
//function : OwnCopy
//purpose  : 
//=======================================================================

void IGESSolid_ToolLoop::OwnCopy(const Handle(IGESSolid_Loop)& another,
                                 const Handle(IGESSolid_Loop)& ent,
                                 Interface_CopyTool& TC) const
{
  Standard_Integer nbedges = another->NbEdges();
  Standard_Integer i, j;
  Standard_Integer anint;

  Handle(TColStd_HArray1OfInteger) tempTypes =
    new TColStd_HArray1OfInteger(1, nbedges);
  Handle(IGESData_HArray1OfIGESEntity) tempEdges =
    new IGESData_HArray1OfIGESEntity(1, nbedges);
  Handle(TColStd_HArray1OfInteger) tempIndex =
    new TColStd_HArray1OfInteger(1, nbedges);
  Handle(TColStd_HArray1OfInteger) tempOrientation =
    new TColStd_HArray1OfInteger(1, nbedges);
  Handle(TColStd_HArray1OfInteger) nbParameterCurves =
    new TColStd_HArray1OfInteger(1, nbedges);
  Handle(IGESBasic_HArray1OfHArray1OfInteger) isoparametricFlags =
    new IGESBasic_HArray1OfHArray1OfInteger(1, nbedges);
  Handle(IGESBasic_HArray1OfHArray1OfIGESEntity) tempCurves =
    new IGESBasic_HArray1OfHArray1OfIGESEntity(1, nbedges);

  for (i = 1; i <= nbedges; i ++)
    {
      tempTypes->SetValue(i, another->EdgeType(i));

      DeclareAndCast(IGESData_IGESEntity, anent,
		     TC.Transferred(another->Edge(i)));
      tempEdges->SetValue(i, anent);

      tempIndex->SetValue(i, another->ListIndex(i));

      tempOrientation->SetValue(i, (another->Orientation(i) ? 1 : 0) );

      anint = another->NbParameterCurves(i);
      nbParameterCurves->SetValue(i, anint);

      Handle(IGESData_HArray1OfIGESEntity) tmpents;
      if (anint > 0) tmpents = new IGESData_HArray1OfIGESEntity(1, anint);
      Handle(TColStd_HArray1OfInteger) tmpints;
      if (anint > 0) tmpints = new TColStd_HArray1OfInteger(1, anint);
      for (j = 1; j <= anint; j ++)
	{
          tmpints->SetValue(j, (another->IsIsoparametric(i, j) ? 1 : 0) );

          DeclareAndCast(IGESData_IGESEntity, localent,
			 TC.Transferred(another->ParametricCurve(i, j)));
          tmpents->SetValue(j, localent);
	}
      isoparametricFlags->SetValue(i, tmpints);
      tempCurves->SetValue(i, tmpents);
    }
  ent->Init(tempTypes, tempEdges, tempIndex, tempOrientation,
	    nbParameterCurves, isoparametricFlags, tempCurves);
}


//=======================================================================
//function : DirChecker
//purpose  : 
//=======================================================================

IGESData_DirChecker IGESSolid_ToolLoop::DirChecker
  (const Handle(IGESSolid_Loop)& /* ent  */) const
{
  IGESData_DirChecker DC(508, 0,1);

  DC.Structure  (IGESData_DefVoid);
  DC.LineFont   (IGESData_DefVoid);
  DC.LineWeight (IGESData_DefVoid);
  DC.Color      (IGESData_DefVoid);

  DC.SubordinateStatusRequired(1);
  return DC;
}


//=======================================================================
//function : OwnCheck
//purpose  : 
//=======================================================================

void IGESSolid_ToolLoop::OwnCheck(const Handle(IGESSolid_Loop)& ent,
                                  const Interface_ShareTool&,
                                  Handle(Interface_Check)& ach) const
{
  // MGE 03/08/98
  // Building of messages
  //========================================
  //Message_Msg Msg190("XSTEP_190");
  //========================================

  Standard_Integer upper = ent->NbEdges();
  for (Standard_Integer i = 1; i <= upper; i ++)
    if (ent->EdgeType(i) != 0 && ent->EdgeType(i) != 1) {
      Message_Msg Msg190("XSTEP_190");
      ach->SendFail(Msg190);
    }
}


//=======================================================================
//function : OwnDump
//purpose  : 
//=======================================================================

void IGESSolid_ToolLoop::OwnDump(const Handle(IGESSolid_Loop)& ent,
                                 const IGESData_IGESDumper& dumper,
                                 const Handle(Message_Messenger)& S,
                                 const Standard_Integer level) const
{
  Standard_Integer i, j;
  Standard_Integer nbedges  = ent->NbEdges();
  Standard_Integer sublevel = (level <= 4) ? 0 : 1;

  S << "IGESSolid_Loop" << endl;

  S << "Edge types : " << endl;
  S << "Edges      : " << endl;
  S << "List index : " << endl;
  S << "Orientation flags : " << endl;
  S << "Parametric flags  : ";
  IGESData_DumpEntities(S,dumper,-level,1, nbedges,ent->Edge);
  S << endl;
  if (level > 4)
    {
      S << "[ ";
      for (i = 1; i <= nbedges; i ++)
	{
	  Standard_Integer nbc = ent->NbParameterCurves(i);
          S << "[" << i << "]:  ";
          S << "Edge type : " << ent->EdgeType(i) << "  ";
          S << "Edge : ";
          dumper.Dump (ent->Edge(i),S, sublevel);
          S << "  - Index : " << ent->ListIndex(i)
            << ", Orientation flag : " << ( ent->Orientation(i) ? "Positive" : "Negative" )
	    << ", Number of parametric curves : " << nbc;
          if (nbc != 0)
	    {
	      if (level <= 5) S << "[ ask level > 5 for content ]";
	      else {
		S << ":\n [ ";
		for (j = 1; j <= nbc; j ++)
		  {
		    S << "[" << j << "]:  ";
		    S << "Isoparametric flag : "
		      << ( ent->IsIsoparametric(i,j) ? "True" : "False" ) << "  ";
		    S << "Parametric curve : ";
		    dumper.Dump (ent->ParametricCurve(i,j),S, sublevel);
		    S << endl;
		  }
		S << " ]";
	      }
	    }
	  S << endl;
	}
      S << " ]";
    }
  S << endl;
}