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