0031004: Coding - eliminate warnings issued by gcc 9.1.0
[occt.git] / src / IGESToBRep / IGESToBRep_CurveAndSurface.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14// 22.12.98 dce S3767
15// 21.12.98 rln, gka S4054
16//#74 rln,pdn 11.03.99 S4135: Setting minimum and maximum tolerances according to static parameters
17// sln 13.06.2002 OCC448 : Correction in method TransferGeometry to avoid transfering invisiable sub entities
18
7fd59977 19#include <BRep_Builder.hxx>
7fd59977 20#include <BRepLib.hxx>
42cf5bc1 21#include <Geom_Surface.hxx>
22#include <GeomAdaptor_Surface.hxx>
7fd59977 23#include <gp_GTrsf.hxx>
42cf5bc1 24#include <gp_Trsf.hxx>
7fd59977 25#include <gp_Vec.hxx>
42cf5bc1 26#include <IGESBasic_Group.hxx>
27#include <IGESBasic_GroupWithoutBackP.hxx>
28#include <IGESBasic_SingularSubfigure.hxx>
29#include <IGESBasic_SubfigureDef.hxx>
30#include <IGESData_IGESEntity.hxx>
31#include <IGESData_IGESModel.hxx>
32#include <IGESData_ToolLocation.hxx>
33#include <IGESToBRep.hxx>
34#include <IGESToBRep_BRepEntity.hxx>
35#include <IGESToBRep_CurveAndSurface.hxx>
36#include <IGESToBRep_TopoCurve.hxx>
37#include <IGESToBRep_TopoSurface.hxx>
7fd59977 38#include <Interface_Macros.hxx>
39#include <Interface_Static.hxx>
42cf5bc1 40#include <Message_Messenger.hxx>
41#include <Message_Msg.hxx>
42#include <Message_ProgressSentry.hxx>
43#include <Precision.hxx>
44#include <Standard_ErrorHandler.hxx>
45#include <Standard_Failure.hxx>
7fd59977 46#include <TopExp_Explorer.hxx>
47#include <TopLoc_Location.hxx>
48#include <TopoDS.hxx>
49#include <TopoDS_Compound.hxx>
50#include <TopoDS_Edge.hxx>
51#include <TopoDS_Shape.hxx>
7fd59977 52#include <Transfer_TransientProcess.hxx>
53#include <TransferBRep_ShapeBinder.hxx>
54#include <TransferBRep_ShapeListBinder.hxx>
7fd59977 55
42cf5bc1 56#include <stdio.h>
7fd59977 57//=======================================================================
58//function : IGESToBRep_CurveAndSurface
cbff1e55 59//purpose :
7fd59977 60//=======================================================================
7fd59977 61IGESToBRep_CurveAndSurface::IGESToBRep_CurveAndSurface()
cbff1e55 62: myEps (1.e-04),
63 myEpsCoeff (1.e-06),
64 myEpsGeom (1.e-04),
65 myMinTol (-1.0),
66 myMaxTol (-1.0),
67 myModeIsTopo (Standard_True),
68 myModeApprox (Standard_False),
69 myContIsOpti (Standard_False),
70 myUnitFactor (1.0),
71 mySurfaceCurve(0),
72 myContinuity (0),
73 myUVResolution(0.0),
74 myIsResolCom (Standard_False),
75 myTP (new Transfer_TransientProcess())
7fd59977 76{
cbff1e55 77 UpdateMinMaxTol();
7fd59977 78}
79
7fd59977 80//=======================================================================
81//function : IGESToBRep_CurveAndSurface
82//purpose :
83//=======================================================================
84
85IGESToBRep_CurveAndSurface::IGESToBRep_CurveAndSurface
86 (const Standard_Real eps,
87 const Standard_Real epsCoeff,
88 const Standard_Real epsGeom,
89 const Standard_Boolean mode,
90 const Standard_Boolean modeapprox,
91 const Standard_Boolean optimized)
cbff1e55 92: myEps (eps),
93 myEpsCoeff (epsCoeff),
94 myEpsGeom (epsGeom),
95 myMinTol (-1.0),
96 myMaxTol (-1.0),
97 myModeIsTopo (mode),
98 myModeApprox (modeapprox),
99 myContIsOpti (optimized),
100 myUnitFactor (1.0),
101 mySurfaceCurve(0),
102 myContinuity (0),
103 myUVResolution(0.0),
104 myIsResolCom (Standard_False),
105 myTP (new Transfer_TransientProcess())
106{
7fd59977 107 UpdateMinMaxTol();
108}
109
110//=======================================================================
111//function : Init
112//purpose :
113//=======================================================================
114
115void IGESToBRep_CurveAndSurface::Init()
116{
117 myEps = 1.E-04;
118 myEpsCoeff = 1.E-06;
119 myEpsGeom = 1.E-04;
120 myModeIsTopo = Standard_True;
121 myModeApprox = Standard_False;
122 myContIsOpti = Standard_False;
123 myUnitFactor = 1.;
124 mySurfaceCurve = 0;
125 myContinuity = 0;
126 myTP = new Transfer_TransientProcess();
127
128 mySurface.Nullify();
129 myIsResolCom = Standard_False;
130 myUVResolution = 0.;
131 UpdateMinMaxTol();
132}
133
134//=======================================================================
135//function : SetEpsGeom
136//purpose :
137//=======================================================================
138void IGESToBRep_CurveAndSurface::SetEpsGeom(const Standard_Real eps)
139{
140 myEpsGeom = eps;
141 UpdateMinMaxTol();
142}
143
144
145//=======================================================================
146//function : UpdateMinMaxTol
147//purpose :
148//=======================================================================
149
150void IGESToBRep_CurveAndSurface::UpdateMinMaxTol()
151{
152 //#74 rln 11.03.99 S4135: Setting maximum tolerances according to
153 //static parameter
154 myMaxTol = Max (Interface_Static::RVal ("read.maxprecision.val"), myEpsGeom * myUnitFactor);
155 myMinTol = Precision::Confusion();
156}
157
158//=======================================================================
159//function : SetModel
160//purpose :
161//=======================================================================
162void IGESToBRep_CurveAndSurface::SetModel(const Handle(IGESData_IGESModel)& model)
163{
164 myModel = model;
165 Standard_Real unitfactor = myModel->GlobalSection().UnitValue();
166 if (unitfactor != 1.)
167 {
168 if ( myTP->TraceLevel() > 2 )
0ebe5b0a 169 myTP->Messenger()->SendInfo() << "UnitFactor = "<< unitfactor << std::endl;
7fd59977 170 myUnitFactor = unitfactor;
171 }
172 UpdateMinMaxTol();
173}
174
175//=======================================================================
176//function : TransferCurveAndSurface
177//purpose :
178//=======================================================================
179
180TopoDS_Shape IGESToBRep_CurveAndSurface::TransferCurveAndSurface
181 (const Handle(IGESData_IGESEntity)& start)
182{
183 TopoDS_Shape res;
184 if (start.IsNull()) {
185 Message_Msg msg1005("IGES_1005");
186 SendFail(start, msg1005);
187 return res;
188 }
189 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
190// Standard_Integer typeNumber = start->TypeNumber();
191
192 if (IGESToBRep::IsTopoCurve(start)) {
193 IGESToBRep_TopoCurve TC(*this);
194 res = TC.TransferTopoCurve(start);
195 }
196 else if (IGESToBRep::IsTopoSurface(start)) {
197 IGESToBRep_TopoSurface TS(*this);
198 res = TS.TransferTopoSurface(start);
199 }
200 else if (IGESToBRep::IsBRepEntity(start)) {
201 IGESToBRep_BRepEntity TS(*this);
202 res = TS.TransferBRepEntity(start);
203 }
204 else {
205 Message_Msg msg1015("IGES_1015");
206 SendFail(start, msg1015);
207 // AddFail(start, "The IGESEntity is not a curve a Surface or a BRep Entity.");
208 }
209 // mjm le 12/09/96
210/*
211 if (!res.IsNull()) {
212 try {
213 OCC_CATCH_SIGNALS
214 Standard_Real Eps = GetEpsGeom()*GetUnitFactor();
215 BRepLib::SameParameter(res,Eps);
216 }
217 catch(Standard_Failure) {
218 Message_Msg msg1010("IGES_1010");
219 SendWarning (start,msg1010);
220 }
221 }
222*/
223 return res;
224}
225
226
227
228//=======================================================================
229//function : TransferGeometry
230//purpose :
231//=======================================================================
232
233TopoDS_Shape IGESToBRep_CurveAndSurface::TransferGeometry
234 (const Handle(IGESData_IGESEntity)& start)
235{
236 // Declaration of messages//
237 // DCE 22/12/98
238 //Message_Msg msg1005("IGES_1005"); // Software error : start IsNull.
239 //Message_Msg msg1015("IGES_1015"); // invalid type or execption raising (software error).
240 //Message_Msg msg1010("IGES_1010"); // Not sameparameter.
241 // Message_Msg msg1015("IGES_1015");
242 //Message_Msg msg210 ("XSTEP_210");
243 //Message_Msg msg202 ("XSTEP_202");
244 ////////////////////////////
245 TopoDS_Shape res;
246 gp_Trsf T408;
247 if (start.IsNull()) {
248 Message_Msg msg1005("IGES_1005"); // Software error : start IsNull.
249 SendFail(start, msg1005);
250 return res;
251 }
252
253 // Read of the DE number and the type number of the entity
254 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
255 //Standard_Integer typeNumber = start->TypeNumber();
256
257 // sln 13.06.2002 OCC448: Avoid transfering invisiable sub entities which
258 // logicaly depend on the one
259 Standard_Integer onlyvisible = Interface_Static::IVal("read.iges.onlyvisible");
260
261 if (IGESToBRep::IsCurveAndSurface(start)) {
262 if(onlyvisible && start->BlankStatus() == 1)
263 return res;
264 try {
265 OCC_CATCH_SIGNALS
266 res = TransferCurveAndSurface(start);
267 }
a738b534 268 catch(Standard_Failure const&) {
7fd59977 269 Message_Msg msg1015("IGES_1015");
270 SendFail(start, msg1015);
271 }
272 return res;
273 }
274
275 //408 : SingularSubfigure
276 if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure)))
277 {
278 if(onlyvisible && start->BlankStatus() == 1)
279 return res;
280
281 DeclareAndCast(IGESBasic_SingularSubfigure, st408, start);
282 Handle (IGESBasic_SubfigureDef) stsub = st408->Subfigure();
283 gp_XYZ trans = st408->Translation();
284 gp_Vec vectr(trans);
285 Standard_Real scunit = GetUnitFactor();
286 vectr.Multiply(scunit);
287 T408.SetTranslation(vectr);
288 if (st408->HasScaleFactor()) {
289 Standard_Real scalef = st408->ScaleFactor();
290 T408.SetScaleFactor(scalef);
291 }
292 if (HasShapeResult(stsub)) {
293 res = GetShapeResult(stsub);
294 }
295 else {
296 try {
297 OCC_CATCH_SIGNALS
298 res = TransferGeometry(stsub);
299 }
a738b534 300 catch(Standard_Failure const&) {
7fd59977 301 res.Nullify();
302 Message_Msg msg1015("IGES_1015");
303 SendFail( st408, msg1015);
304 }
305 if (!res.IsNull()) {
306 SetShapeResult(stsub,res);
307 }
308 }
309 }
310
311 // 308 : SubfigureDefinition
312 else if (start->IsKind(STANDARD_TYPE(IGESBasic_SubfigureDef))) {
313 DeclareAndCast(IGESBasic_SubfigureDef, st308, start);
314 TopoDS_Compound group;
315 BRep_Builder B;
316 B.MakeCompound (group);
317 if (st308->NbEntities() < 1) {
318 Message_Msg msg210 ("XSTEP_210");
319 SendFail( st308, msg210);
320 return res;
321 }
322 Message_ProgressSentry PS ( myTP->GetProgress(), "Subfigure item", 0, st308->NbEntities(), 1 );
323 for (Standard_Integer i=1; i <= st308->NbEntities() && PS.More(); i++, PS.Next()) {
324 TopoDS_Shape item;
325 if (st308->AssociatedEntity(i).IsNull()) {
326 Message_Msg msg1020("IGES_1020");
327 msg1020.Arg(i);
328 SendWarning( st308, msg1020);
329 continue;
330 }
331 if(onlyvisible && st308->AssociatedEntity(i)->BlankStatus() == 1 )
332 continue;
333
334 if (HasShapeResult(st308->AssociatedEntity(i)))
335 {
336 item = GetShapeResult(st308->AssociatedEntity(i));
337 }
338 else {
339 try {
340 OCC_CATCH_SIGNALS
341 item = TransferGeometry(st308->AssociatedEntity(i));
342 }
a738b534 343 catch(Standard_Failure const&) {
7fd59977 344 item.Nullify();
345 Message_Msg msg1015("IGES_1015");
346 SendFail( st308->AssociatedEntity(i), msg1015);
347 }
348 }
349 if (item.IsNull()) {
350 Message_Msg msg1025("IGES_1025");
351 msg1025.Arg(i);
352 SendWarning (start,msg1025);
353 }
354 else {
355 B.Add(group, item);
356 SetShapeResult (st308->AssociatedEntity(i),item);
357 }
358 }
359 res = group;
360 }
361 else if (start->IsKind(STANDARD_TYPE(IGESBasic_Group))) {
362 if(onlyvisible && start->BlankStatus() == 1)
363 return res;
364
365 DeclareAndCast(IGESBasic_Group, st402f1, start);
366 TopoDS_Compound group;
367 BRep_Builder B;
368 B.MakeCompound (group);
369 if (st402f1->NbEntities() < 1) {
370 Message_Msg msg202 ("XSTEP_202");
371 msg202.Arg(st402f1->FormNumber());
372 SendFail(st402f1, msg202);
373 return res;
374 }
375 Message_ProgressSentry PS ( myTP->GetProgress(), "Group item", 0, st402f1->NbEntities(), 1 );
376 Standard_Boolean ProblemInGroup = Standard_False;
377 for (Standard_Integer i=1; i <= st402f1->NbEntities() && PS.More(); i++, PS.Next()) {
378 TopoDS_Shape item;
379 if (st402f1->Entity(i).IsNull()) {
380 Message_Msg msg1020("IGES_1020");
381 msg1020.Arg(i);
382 SendFail( st402f1, msg1020);
383 continue;
384 }
385
386 if(onlyvisible && st402f1->Entity(i)->BlankStatus() == 1)
387 continue;
388
389 if (HasShapeResult(st402f1->Entity(i))) {
390 item = GetShapeResult(st402f1->Entity(i));
391 }
392 else {
393 try {
394 OCC_CATCH_SIGNALS
395 item = TransferGeometry(st402f1->Entity(i));
396 }
a738b534 397 catch(Standard_Failure const&) {
7fd59977 398 item.Nullify();
399 Message_Msg msg1015("IGES_1015");
400 SendFail(st402f1->Entity(i),msg1015);
401 }
402 }
403 if (item.IsNull()) {
404 //Message_Msg msg1030("IGES_1030");
405 //msg1030.Arg(st402f1->FormNumber());
406 //msg1030.Arg(i);
407 //SendWarning (st402f1,msg1030);
408 ProblemInGroup = Standard_True;
409 }
410 else {
411 B.Add(group, item);
412 SetShapeResult (st402f1->Entity(i),item);
413 }
414 }
415 res = group;
416 if(ProblemInGroup) {
417 Message_Msg msg1030("IGES_1030");
418 msg1030.Arg(st402f1->FormNumber());
419 SendWarning (st402f1,msg1030);
420 }
421 }
422 else if (start->IsKind(STANDARD_TYPE(IGESBasic_GroupWithoutBackP))) {
423
424 if(onlyvisible && start->BlankStatus() == 1)
425 return res;
426
427 DeclareAndCast(IGESBasic_GroupWithoutBackP, st402f7, start);
428 TopoDS_Compound group;
429//unused Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(st402f7);
430 BRep_Builder B;
431 B.MakeCompound (group);
432 if (st402f7->NbEntities() < 1) {
433 Message_Msg msg202 ("XSTEP_202");
434 msg202.Arg(st402f7->FormNumber());
435 SendFail(st402f7, msg202);
436 return res;
437 }
438 Message_ProgressSentry PS ( myTP->GetProgress(), "Group item", 0, st402f7->NbEntities(), 1 );
439 Standard_Boolean ProblemInGroup = Standard_False;
440 for (Standard_Integer i=1; i <= st402f7->NbEntities() && PS.More(); i++, PS.Next()) {
441 TopoDS_Shape item;
442 if (st402f7->Entity(i).IsNull()) {
443 Message_Msg msg1020("IGES_1020");
444 msg1020.Arg(i);
445 SendFail( st402f7, msg1020);
446 continue;
447 }
448
449 if(onlyvisible && st402f7->Entity(i)->BlankStatus() == 1 )
450 continue;
451
452 if (HasShapeResult(st402f7->Entity(i))) {
453 item = GetShapeResult(st402f7->Entity(i));
454 }
455 else {
456 try {
457 OCC_CATCH_SIGNALS
458 item = TransferGeometry(st402f7->Entity(i));
459 }
a738b534 460 catch(Standard_Failure const&) {
7fd59977 461 item.Nullify();
462 Message_Msg msg1015("IGES_1015");
463 SendFail(st402f7->Entity(i),msg1015);
464 }
465 }
466 if (item.IsNull()) {
467 //Message_Msg msg1030("IGES_1030");
468 //msg1030.Arg(st402f7->FormNumber());
469 //msg1030.Arg(i);
470 //SendWarning (st402f7,msg1030);
471 ProblemInGroup = Standard_True;
472 }
473 else {
474 B.Add(group, item);
475 SetShapeResult (st402f7->Entity(i),item);
476 }
477 }
478 res = group;
479 if(ProblemInGroup) {
480 Message_Msg msg1030("IGES_1030");
481 msg1030.Arg(st402f7->FormNumber());
482 SendWarning (st402f7,msg1030);
483 }
484 }
485 else {
486 Message_Msg msg1001("IGES_1001");
487 msg1001.Arg(start->FormNumber());
488 SendFail (start,msg1001);
489 return res;
490 }
491
492 if (start->HasTransf()) {
493 gp_Trsf T;
494 SetEpsilon(1.E-04);
495 if (IGESData_ToolLocation::ConvertLocation(GetEpsilon(),start->CompoundLocation(),
496 T,GetUnitFactor())) {
497 if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure)))
498 {
499 gp_XYZ tra = T.TranslationPart();
500 gp_XYZ trans = T408.TranslationPart();
501 tra.Add(trans);
502 T.SetTranslationPart(tra);
503 Standard_Real sc = T.ScaleFactor();
504 Standard_Real scalef = T408.ScaleFactor();
505 sc = sc*scalef;
506 T.SetScaleFactor(sc);
507 }
508 TopLoc_Location L(T);
509 res.Move(L);
510 }
511 else {
512 Message_Msg msg1035("IGES_1035");
513 SendWarning (start,msg1035);
514 }
515 }
516 else {
517 if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure))) {
518 TopLoc_Location L(T408);
519 res.Move(L);
520 }
521 }
522 return res;
523}
524
525
526//=======================================================================
527//function : HasShapeResult
528//purpose :
529//=======================================================================
530
531Standard_Boolean IGESToBRep_CurveAndSurface::HasShapeResult
532 (const Handle(IGESData_IGESEntity)& start) const
533{
534 DeclareAndCast(TransferBRep_ShapeBinder,binder,myTP->Find(start));
535 if (binder.IsNull()) return Standard_False;
536 return binder->HasResult();
537}
538
539
540//=======================================================================
541//function : GetShapeResult
542//purpose :
543//=======================================================================
544
545TopoDS_Shape IGESToBRep_CurveAndSurface::GetShapeResult
546 (const Handle(IGESData_IGESEntity)& start) const
547{
548 TopoDS_Shape res;
549
550 DeclareAndCast(TransferBRep_ShapeBinder, binder, myTP->Find(start));
551 if (binder.IsNull()) return res;
552 if (binder->HasResult())
553 res = binder->Result();
554 return res;
555}
556
557
558//=======================================================================
559//function : SetShapeResult
560//purpose :
561//=======================================================================
562
563void IGESToBRep_CurveAndSurface::SetShapeResult
564 (const Handle(IGESData_IGESEntity)& start,
565 const TopoDS_Shape& result)
566{
567 Handle(TransferBRep_ShapeBinder) binder = new TransferBRep_ShapeBinder;
568 myTP->Bind(start,binder);
569 binder->SetResult(result);
570}
571
572//=======================================================================
573//function : NbShapeResult
574//purpose :
575//=======================================================================
576
577Standard_Integer IGESToBRep_CurveAndSurface::NbShapeResult
578 (const Handle(IGESData_IGESEntity)& start) const
579{
580 Standard_Integer nbres = 0;
581 DeclareAndCast(TransferBRep_ShapeListBinder,binder,myTP->Find(start));
582 if (binder.IsNull()) return nbres;
583 nbres = binder->NbShapes();
584 return nbres;
585}
586
587
588//=======================================================================
589//function : GetShapeResult
590//purpose :
591//=======================================================================
592
593TopoDS_Shape IGESToBRep_CurveAndSurface::GetShapeResult
594 (const Handle(IGESData_IGESEntity)& start, const Standard_Integer num) const
595{
596 TopoDS_Shape res;
597
598 DeclareAndCast(TransferBRep_ShapeListBinder,binder,myTP->Find(start));
599 if (binder.IsNull()) return res;
600
601 if (num <= binder->NbShapes())
602 res = binder->Shape(num);
603 return res;
604}
605
606
607//=======================================================================
608//function : AddShapeResult
609//purpose :
610//=======================================================================
611
612void IGESToBRep_CurveAndSurface::AddShapeResult
613 (const Handle(IGESData_IGESEntity)& start,
614 const TopoDS_Shape& result)
615{
616 DeclareAndCast(TransferBRep_ShapeListBinder,binder,myTP->Find(start));
617 if (binder.IsNull()){
618 binder = new TransferBRep_ShapeListBinder;
619 myTP->Bind(start,binder);
620 }
621 binder->AddResult(result);
622}
623
624void IGESToBRep_CurveAndSurface::SetSurface(const Handle(Geom_Surface)& theSurface)
625{
626 if(mySurface!=theSurface) {
627 mySurface = theSurface;
628 myIsResolCom = Standard_False;
629 myUVResolution = 0.;
630 }
631}
632
633Handle(Geom_Surface) IGESToBRep_CurveAndSurface::Surface() const
634{
635 return mySurface;
636}
637
638Standard_Real IGESToBRep_CurveAndSurface::GetUVResolution()
639{
640 if(!myIsResolCom && !mySurface.IsNull()) {
641 myIsResolCom = Standard_True;
642 GeomAdaptor_Surface aGAS(mySurface);
643 myUVResolution = Min(aGAS.UResolution(1.), aGAS.VResolution(1.));
644 }
645 return myUVResolution;
646}
647
648
649
650
651
652