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