1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
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
19 #include <BRep_Builder.hxx>
20 #include <BRepLib.hxx>
21 #include <Geom_Surface.hxx>
22 #include <GeomAdaptor_Surface.hxx>
23 #include <gp_GTrsf.hxx>
24 #include <gp_Trsf.hxx>
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>
38 #include <Interface_Macros.hxx>
39 #include <Interface_Static.hxx>
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>
46 #include <TopExp_Explorer.hxx>
47 #include <TopLoc_Location.hxx>
49 #include <TopoDS_Compound.hxx>
50 #include <TopoDS_Edge.hxx>
51 #include <TopoDS_Shape.hxx>
52 #include <Transfer_TransientProcess.hxx>
53 #include <TransferBRep_ShapeBinder.hxx>
54 #include <TransferBRep_ShapeListBinder.hxx>
57 //=======================================================================
58 //function : IGESToBRep_CurveAndSurface
60 //=======================================================================
61 IGESToBRep_CurveAndSurface::IGESToBRep_CurveAndSurface()
67 myModeIsTopo (Standard_True),
68 myModeApprox (Standard_False),
69 myContIsOpti (Standard_False),
74 myIsResolCom (Standard_False),
75 myTP (new Transfer_TransientProcess())
81 //=======================================================================
82 //function : IGESToBRep_CurveAndSurface
84 //=======================================================================
86 IGESToBRep_CurveAndSurface::IGESToBRep_CurveAndSurface
87 (const IGESToBRep_CurveAndSurface& other)
88 : myEps (other.myEps),
89 myEpsCoeff (other.myEpsCoeff),
90 myEpsGeom (other.myEpsGeom),
91 myMinTol (other.myMinTol),
92 myMaxTol (other.myMaxTol),
93 myModeIsTopo (other.myModeIsTopo),
94 myModeApprox (other.myModeApprox),
95 myContIsOpti (other.myContIsOpti),
96 myUnitFactor (other.myUnitFactor),
97 mySurfaceCurve(other.mySurfaceCurve),
98 myContinuity (other.myContinuity),
99 mySurface (other.mySurface),
100 myUVResolution(other.myUVResolution),
101 myIsResolCom (other.myIsResolCom),
102 myModel (other.myModel),
108 //=======================================================================
109 //function : IGESToBRep_CurveAndSurface
111 //=======================================================================
113 IGESToBRep_CurveAndSurface::IGESToBRep_CurveAndSurface
114 (const Standard_Real eps,
115 const Standard_Real epsCoeff,
116 const Standard_Real epsGeom,
117 const Standard_Boolean mode,
118 const Standard_Boolean modeapprox,
119 const Standard_Boolean optimized)
121 myEpsCoeff (epsCoeff),
126 myModeApprox (modeapprox),
127 myContIsOpti (optimized),
132 myIsResolCom (Standard_False),
133 myTP (new Transfer_TransientProcess())
138 //=======================================================================
141 //=======================================================================
143 void IGESToBRep_CurveAndSurface::Init()
148 myModeIsTopo = Standard_True;
149 myModeApprox = Standard_False;
150 myContIsOpti = Standard_False;
154 myTP = new Transfer_TransientProcess();
157 myIsResolCom = Standard_False;
162 //=======================================================================
163 //function : SetEpsGeom
165 //=======================================================================
166 void IGESToBRep_CurveAndSurface::SetEpsGeom(const Standard_Real eps)
173 //=======================================================================
174 //function : UpdateMinMaxTol
176 //=======================================================================
178 void IGESToBRep_CurveAndSurface::UpdateMinMaxTol()
180 //#74 rln 11.03.99 S4135: Setting maximum tolerances according to
182 myMaxTol = Max (Interface_Static::RVal ("read.maxprecision.val"), myEpsGeom * myUnitFactor);
183 myMinTol = Precision::Confusion();
186 //=======================================================================
187 //function : SetModel
189 //=======================================================================
190 void IGESToBRep_CurveAndSurface::SetModel(const Handle(IGESData_IGESModel)& model)
193 Standard_Real unitfactor = myModel->GlobalSection().UnitValue();
194 if (unitfactor != 1.)
196 if ( myTP->TraceLevel() > 2 )
197 myTP->Messenger()->SendInfo() << "UnitFactor = "<< unitfactor << std::endl;
198 myUnitFactor = unitfactor;
203 //=======================================================================
204 //function : TransferCurveAndSurface
206 //=======================================================================
208 TopoDS_Shape IGESToBRep_CurveAndSurface::TransferCurveAndSurface
209 (const Handle(IGESData_IGESEntity)& start)
212 if (start.IsNull()) {
213 Message_Msg msg1005("IGES_1005");
214 SendFail(start, msg1005);
217 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
218 // Standard_Integer typeNumber = start->TypeNumber();
220 if (IGESToBRep::IsTopoCurve(start)) {
221 IGESToBRep_TopoCurve TC(*this);
222 res = TC.TransferTopoCurve(start);
224 else if (IGESToBRep::IsTopoSurface(start)) {
225 IGESToBRep_TopoSurface TS(*this);
226 res = TS.TransferTopoSurface(start);
228 else if (IGESToBRep::IsBRepEntity(start)) {
229 IGESToBRep_BRepEntity TS(*this);
230 res = TS.TransferBRepEntity(start);
233 Message_Msg msg1015("IGES_1015");
234 SendFail(start, msg1015);
235 // AddFail(start, "The IGESEntity is not a curve a Surface or a BRep Entity.");
242 Standard_Real Eps = GetEpsGeom()*GetUnitFactor();
243 BRepLib::SameParameter(res,Eps);
245 catch(Standard_Failure) {
246 Message_Msg msg1010("IGES_1010");
247 SendWarning (start,msg1010);
256 //=======================================================================
257 //function : TransferGeometry
259 //=======================================================================
261 TopoDS_Shape IGESToBRep_CurveAndSurface::TransferGeometry
262 (const Handle(IGESData_IGESEntity)& start)
264 // Declaration of messages//
266 //Message_Msg msg1005("IGES_1005"); // Software error : start IsNull.
267 //Message_Msg msg1015("IGES_1015"); // invalid type or execption raising (software error).
268 //Message_Msg msg1010("IGES_1010"); // Not sameparameter.
269 // Message_Msg msg1015("IGES_1015");
270 //Message_Msg msg210 ("XSTEP_210");
271 //Message_Msg msg202 ("XSTEP_202");
272 ////////////////////////////
275 if (start.IsNull()) {
276 Message_Msg msg1005("IGES_1005"); // Software error : start IsNull.
277 SendFail(start, msg1005);
281 // Read of the DE number and the type number of the entity
282 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
283 //Standard_Integer typeNumber = start->TypeNumber();
285 // sln 13.06.2002 OCC448: Avoid transfering invisiable sub entities which
286 // logicaly depend on the one
287 Standard_Integer onlyvisible = Interface_Static::IVal("read.iges.onlyvisible");
289 if (IGESToBRep::IsCurveAndSurface(start)) {
290 if(onlyvisible && start->BlankStatus() == 1)
294 res = TransferCurveAndSurface(start);
296 catch(Standard_Failure const&) {
297 Message_Msg msg1015("IGES_1015");
298 SendFail(start, msg1015);
303 //408 : SingularSubfigure
304 if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure)))
306 if(onlyvisible && start->BlankStatus() == 1)
309 DeclareAndCast(IGESBasic_SingularSubfigure, st408, start);
310 Handle (IGESBasic_SubfigureDef) stsub = st408->Subfigure();
311 gp_XYZ trans = st408->Translation();
313 Standard_Real scunit = GetUnitFactor();
314 vectr.Multiply(scunit);
315 T408.SetTranslation(vectr);
316 if (st408->HasScaleFactor()) {
317 Standard_Real scalef = st408->ScaleFactor();
318 T408.SetScaleFactor(scalef);
320 if (HasShapeResult(stsub)) {
321 res = GetShapeResult(stsub);
326 res = TransferGeometry(stsub);
328 catch(Standard_Failure const&) {
330 Message_Msg msg1015("IGES_1015");
331 SendFail( st408, msg1015);
334 SetShapeResult(stsub,res);
339 // 308 : SubfigureDefinition
340 else if (start->IsKind(STANDARD_TYPE(IGESBasic_SubfigureDef))) {
341 DeclareAndCast(IGESBasic_SubfigureDef, st308, start);
342 TopoDS_Compound group;
344 B.MakeCompound (group);
345 if (st308->NbEntities() < 1) {
346 Message_Msg msg210 ("XSTEP_210");
347 SendFail( st308, msg210);
350 Message_ProgressSentry PS ( myTP->GetProgress(), "Subfigure item", 0, st308->NbEntities(), 1 );
351 for (Standard_Integer i=1; i <= st308->NbEntities() && PS.More(); i++, PS.Next()) {
353 if (st308->AssociatedEntity(i).IsNull()) {
354 Message_Msg msg1020("IGES_1020");
356 SendWarning( st308, msg1020);
359 if(onlyvisible && st308->AssociatedEntity(i)->BlankStatus() == 1 )
362 if (HasShapeResult(st308->AssociatedEntity(i)))
364 item = GetShapeResult(st308->AssociatedEntity(i));
369 item = TransferGeometry(st308->AssociatedEntity(i));
371 catch(Standard_Failure const&) {
373 Message_Msg msg1015("IGES_1015");
374 SendFail( st308->AssociatedEntity(i), msg1015);
378 Message_Msg msg1025("IGES_1025");
380 SendWarning (start,msg1025);
384 SetShapeResult (st308->AssociatedEntity(i),item);
389 else if (start->IsKind(STANDARD_TYPE(IGESBasic_Group))) {
390 if(onlyvisible && start->BlankStatus() == 1)
393 DeclareAndCast(IGESBasic_Group, st402f1, start);
394 TopoDS_Compound group;
396 B.MakeCompound (group);
397 if (st402f1->NbEntities() < 1) {
398 Message_Msg msg202 ("XSTEP_202");
399 msg202.Arg(st402f1->FormNumber());
400 SendFail(st402f1, msg202);
403 Message_ProgressSentry PS ( myTP->GetProgress(), "Group item", 0, st402f1->NbEntities(), 1 );
404 Standard_Boolean ProblemInGroup = Standard_False;
405 for (Standard_Integer i=1; i <= st402f1->NbEntities() && PS.More(); i++, PS.Next()) {
407 if (st402f1->Entity(i).IsNull()) {
408 Message_Msg msg1020("IGES_1020");
410 SendFail( st402f1, msg1020);
414 if(onlyvisible && st402f1->Entity(i)->BlankStatus() == 1)
417 if (HasShapeResult(st402f1->Entity(i))) {
418 item = GetShapeResult(st402f1->Entity(i));
423 item = TransferGeometry(st402f1->Entity(i));
425 catch(Standard_Failure const&) {
427 Message_Msg msg1015("IGES_1015");
428 SendFail(st402f1->Entity(i),msg1015);
432 //Message_Msg msg1030("IGES_1030");
433 //msg1030.Arg(st402f1->FormNumber());
435 //SendWarning (st402f1,msg1030);
436 ProblemInGroup = Standard_True;
440 SetShapeResult (st402f1->Entity(i),item);
445 Message_Msg msg1030("IGES_1030");
446 msg1030.Arg(st402f1->FormNumber());
447 SendWarning (st402f1,msg1030);
450 else if (start->IsKind(STANDARD_TYPE(IGESBasic_GroupWithoutBackP))) {
452 if(onlyvisible && start->BlankStatus() == 1)
455 DeclareAndCast(IGESBasic_GroupWithoutBackP, st402f7, start);
456 TopoDS_Compound group;
457 //unused Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(st402f7);
459 B.MakeCompound (group);
460 if (st402f7->NbEntities() < 1) {
461 Message_Msg msg202 ("XSTEP_202");
462 msg202.Arg(st402f7->FormNumber());
463 SendFail(st402f7, msg202);
466 Message_ProgressSentry PS ( myTP->GetProgress(), "Group item", 0, st402f7->NbEntities(), 1 );
467 Standard_Boolean ProblemInGroup = Standard_False;
468 for (Standard_Integer i=1; i <= st402f7->NbEntities() && PS.More(); i++, PS.Next()) {
470 if (st402f7->Entity(i).IsNull()) {
471 Message_Msg msg1020("IGES_1020");
473 SendFail( st402f7, msg1020);
477 if(onlyvisible && st402f7->Entity(i)->BlankStatus() == 1 )
480 if (HasShapeResult(st402f7->Entity(i))) {
481 item = GetShapeResult(st402f7->Entity(i));
486 item = TransferGeometry(st402f7->Entity(i));
488 catch(Standard_Failure const&) {
490 Message_Msg msg1015("IGES_1015");
491 SendFail(st402f7->Entity(i),msg1015);
495 //Message_Msg msg1030("IGES_1030");
496 //msg1030.Arg(st402f7->FormNumber());
498 //SendWarning (st402f7,msg1030);
499 ProblemInGroup = Standard_True;
503 SetShapeResult (st402f7->Entity(i),item);
508 Message_Msg msg1030("IGES_1030");
509 msg1030.Arg(st402f7->FormNumber());
510 SendWarning (st402f7,msg1030);
514 Message_Msg msg1001("IGES_1001");
515 msg1001.Arg(start->FormNumber());
516 SendFail (start,msg1001);
520 if (start->HasTransf()) {
523 if (IGESData_ToolLocation::ConvertLocation(GetEpsilon(),start->CompoundLocation(),
524 T,GetUnitFactor())) {
525 if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure)))
527 gp_XYZ tra = T.TranslationPart();
528 gp_XYZ trans = T408.TranslationPart();
530 T.SetTranslationPart(tra);
531 Standard_Real sc = T.ScaleFactor();
532 Standard_Real scalef = T408.ScaleFactor();
534 T.SetScaleFactor(sc);
536 TopLoc_Location L(T);
540 Message_Msg msg1035("IGES_1035");
541 SendWarning (start,msg1035);
545 if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure))) {
546 TopLoc_Location L(T408);
554 //=======================================================================
555 //function : HasShapeResult
557 //=======================================================================
559 Standard_Boolean IGESToBRep_CurveAndSurface::HasShapeResult
560 (const Handle(IGESData_IGESEntity)& start) const
562 DeclareAndCast(TransferBRep_ShapeBinder,binder,myTP->Find(start));
563 if (binder.IsNull()) return Standard_False;
564 return binder->HasResult();
568 //=======================================================================
569 //function : GetShapeResult
571 //=======================================================================
573 TopoDS_Shape IGESToBRep_CurveAndSurface::GetShapeResult
574 (const Handle(IGESData_IGESEntity)& start) const
578 DeclareAndCast(TransferBRep_ShapeBinder, binder, myTP->Find(start));
579 if (binder.IsNull()) return res;
580 if (binder->HasResult())
581 res = binder->Result();
586 //=======================================================================
587 //function : SetShapeResult
589 //=======================================================================
591 void IGESToBRep_CurveAndSurface::SetShapeResult
592 (const Handle(IGESData_IGESEntity)& start,
593 const TopoDS_Shape& result)
595 Handle(TransferBRep_ShapeBinder) binder = new TransferBRep_ShapeBinder;
596 myTP->Bind(start,binder);
597 binder->SetResult(result);
600 //=======================================================================
601 //function : NbShapeResult
603 //=======================================================================
605 Standard_Integer IGESToBRep_CurveAndSurface::NbShapeResult
606 (const Handle(IGESData_IGESEntity)& start) const
608 Standard_Integer nbres = 0;
609 DeclareAndCast(TransferBRep_ShapeListBinder,binder,myTP->Find(start));
610 if (binder.IsNull()) return nbres;
611 nbres = binder->NbShapes();
616 //=======================================================================
617 //function : GetShapeResult
619 //=======================================================================
621 TopoDS_Shape IGESToBRep_CurveAndSurface::GetShapeResult
622 (const Handle(IGESData_IGESEntity)& start, const Standard_Integer num) const
626 DeclareAndCast(TransferBRep_ShapeListBinder,binder,myTP->Find(start));
627 if (binder.IsNull()) return res;
629 if (num <= binder->NbShapes())
630 res = binder->Shape(num);
635 //=======================================================================
636 //function : AddShapeResult
638 //=======================================================================
640 void IGESToBRep_CurveAndSurface::AddShapeResult
641 (const Handle(IGESData_IGESEntity)& start,
642 const TopoDS_Shape& result)
644 DeclareAndCast(TransferBRep_ShapeListBinder,binder,myTP->Find(start));
645 if (binder.IsNull()){
646 binder = new TransferBRep_ShapeListBinder;
647 myTP->Bind(start,binder);
649 binder->AddResult(result);
652 void IGESToBRep_CurveAndSurface::SetSurface(const Handle(Geom_Surface)& theSurface)
654 if(mySurface!=theSurface) {
655 mySurface = theSurface;
656 myIsResolCom = Standard_False;
661 Handle(Geom_Surface) IGESToBRep_CurveAndSurface::Surface() const
666 Standard_Real IGESToBRep_CurveAndSurface::GetUVResolution()
668 if(!myIsResolCom && !mySurface.IsNull()) {
669 myIsResolCom = Standard_True;
670 GeomAdaptor_Surface aGAS(mySurface);
671 myUVResolution = Min(aGAS.UResolution(1.), aGAS.VResolution(1.));
673 return myUVResolution;