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())
80 //=======================================================================
81 //function : IGESToBRep_CurveAndSurface
83 //=======================================================================
85 IGESToBRep_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)
93 myEpsCoeff (epsCoeff),
98 myModeApprox (modeapprox),
99 myContIsOpti (optimized),
104 myIsResolCom (Standard_False),
105 myTP (new Transfer_TransientProcess())
110 //=======================================================================
113 //=======================================================================
115 void IGESToBRep_CurveAndSurface::Init()
120 myModeIsTopo = Standard_True;
121 myModeApprox = Standard_False;
122 myContIsOpti = Standard_False;
126 myTP = new Transfer_TransientProcess();
129 myIsResolCom = Standard_False;
134 //=======================================================================
135 //function : SetEpsGeom
137 //=======================================================================
138 void IGESToBRep_CurveAndSurface::SetEpsGeom(const Standard_Real eps)
145 //=======================================================================
146 //function : UpdateMinMaxTol
148 //=======================================================================
150 void IGESToBRep_CurveAndSurface::UpdateMinMaxTol()
152 //#74 rln 11.03.99 S4135: Setting maximum tolerances according to
154 myMaxTol = Max (Interface_Static::RVal ("read.maxprecision.val"), myEpsGeom * myUnitFactor);
155 myMinTol = Precision::Confusion();
158 //=======================================================================
159 //function : SetModel
161 //=======================================================================
162 void IGESToBRep_CurveAndSurface::SetModel(const Handle(IGESData_IGESModel)& model)
165 Standard_Real unitfactor = myModel->GlobalSection().UnitValue();
166 if (unitfactor != 1.)
168 if ( myTP->TraceLevel() > 2 )
169 myTP->Messenger()->SendInfo() << "UnitFactor = "<< unitfactor << std::endl;
170 myUnitFactor = unitfactor;
175 //=======================================================================
176 //function : TransferCurveAndSurface
178 //=======================================================================
180 TopoDS_Shape IGESToBRep_CurveAndSurface::TransferCurveAndSurface
181 (const Handle(IGESData_IGESEntity)& start)
184 if (start.IsNull()) {
185 Message_Msg msg1005("IGES_1005");
186 SendFail(start, msg1005);
189 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
190 // Standard_Integer typeNumber = start->TypeNumber();
192 if (IGESToBRep::IsTopoCurve(start)) {
193 IGESToBRep_TopoCurve TC(*this);
194 res = TC.TransferTopoCurve(start);
196 else if (IGESToBRep::IsTopoSurface(start)) {
197 IGESToBRep_TopoSurface TS(*this);
198 res = TS.TransferTopoSurface(start);
200 else if (IGESToBRep::IsBRepEntity(start)) {
201 IGESToBRep_BRepEntity TS(*this);
202 res = TS.TransferBRepEntity(start);
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.");
214 Standard_Real Eps = GetEpsGeom()*GetUnitFactor();
215 BRepLib::SameParameter(res,Eps);
217 catch(Standard_Failure) {
218 Message_Msg msg1010("IGES_1010");
219 SendWarning (start,msg1010);
228 //=======================================================================
229 //function : TransferGeometry
231 //=======================================================================
233 TopoDS_Shape IGESToBRep_CurveAndSurface::TransferGeometry
234 (const Handle(IGESData_IGESEntity)& start)
236 // Declaration of messages//
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 ////////////////////////////
247 if (start.IsNull()) {
248 Message_Msg msg1005("IGES_1005"); // Software error : start IsNull.
249 SendFail(start, msg1005);
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();
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");
261 if (IGESToBRep::IsCurveAndSurface(start)) {
262 if(onlyvisible && start->BlankStatus() == 1)
266 res = TransferCurveAndSurface(start);
268 catch(Standard_Failure const&) {
269 Message_Msg msg1015("IGES_1015");
270 SendFail(start, msg1015);
275 //408 : SingularSubfigure
276 if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure)))
278 if(onlyvisible && start->BlankStatus() == 1)
281 DeclareAndCast(IGESBasic_SingularSubfigure, st408, start);
282 Handle (IGESBasic_SubfigureDef) stsub = st408->Subfigure();
283 gp_XYZ trans = st408->Translation();
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);
292 if (HasShapeResult(stsub)) {
293 res = GetShapeResult(stsub);
298 res = TransferGeometry(stsub);
300 catch(Standard_Failure const&) {
302 Message_Msg msg1015("IGES_1015");
303 SendFail( st408, msg1015);
306 SetShapeResult(stsub,res);
311 // 308 : SubfigureDefinition
312 else if (start->IsKind(STANDARD_TYPE(IGESBasic_SubfigureDef))) {
313 DeclareAndCast(IGESBasic_SubfigureDef, st308, start);
314 TopoDS_Compound group;
316 B.MakeCompound (group);
317 if (st308->NbEntities() < 1) {
318 Message_Msg msg210 ("XSTEP_210");
319 SendFail( st308, msg210);
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()) {
325 if (st308->AssociatedEntity(i).IsNull()) {
326 Message_Msg msg1020("IGES_1020");
328 SendWarning( st308, msg1020);
331 if(onlyvisible && st308->AssociatedEntity(i)->BlankStatus() == 1 )
334 if (HasShapeResult(st308->AssociatedEntity(i)))
336 item = GetShapeResult(st308->AssociatedEntity(i));
341 item = TransferGeometry(st308->AssociatedEntity(i));
343 catch(Standard_Failure const&) {
345 Message_Msg msg1015("IGES_1015");
346 SendFail( st308->AssociatedEntity(i), msg1015);
350 Message_Msg msg1025("IGES_1025");
352 SendWarning (start,msg1025);
356 SetShapeResult (st308->AssociatedEntity(i),item);
361 else if (start->IsKind(STANDARD_TYPE(IGESBasic_Group))) {
362 if(onlyvisible && start->BlankStatus() == 1)
365 DeclareAndCast(IGESBasic_Group, st402f1, start);
366 TopoDS_Compound group;
368 B.MakeCompound (group);
369 if (st402f1->NbEntities() < 1) {
370 Message_Msg msg202 ("XSTEP_202");
371 msg202.Arg(st402f1->FormNumber());
372 SendFail(st402f1, msg202);
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()) {
379 if (st402f1->Entity(i).IsNull()) {
380 Message_Msg msg1020("IGES_1020");
382 SendFail( st402f1, msg1020);
386 if(onlyvisible && st402f1->Entity(i)->BlankStatus() == 1)
389 if (HasShapeResult(st402f1->Entity(i))) {
390 item = GetShapeResult(st402f1->Entity(i));
395 item = TransferGeometry(st402f1->Entity(i));
397 catch(Standard_Failure const&) {
399 Message_Msg msg1015("IGES_1015");
400 SendFail(st402f1->Entity(i),msg1015);
404 //Message_Msg msg1030("IGES_1030");
405 //msg1030.Arg(st402f1->FormNumber());
407 //SendWarning (st402f1,msg1030);
408 ProblemInGroup = Standard_True;
412 SetShapeResult (st402f1->Entity(i),item);
417 Message_Msg msg1030("IGES_1030");
418 msg1030.Arg(st402f1->FormNumber());
419 SendWarning (st402f1,msg1030);
422 else if (start->IsKind(STANDARD_TYPE(IGESBasic_GroupWithoutBackP))) {
424 if(onlyvisible && start->BlankStatus() == 1)
427 DeclareAndCast(IGESBasic_GroupWithoutBackP, st402f7, start);
428 TopoDS_Compound group;
429 //unused Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(st402f7);
431 B.MakeCompound (group);
432 if (st402f7->NbEntities() < 1) {
433 Message_Msg msg202 ("XSTEP_202");
434 msg202.Arg(st402f7->FormNumber());
435 SendFail(st402f7, msg202);
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()) {
442 if (st402f7->Entity(i).IsNull()) {
443 Message_Msg msg1020("IGES_1020");
445 SendFail( st402f7, msg1020);
449 if(onlyvisible && st402f7->Entity(i)->BlankStatus() == 1 )
452 if (HasShapeResult(st402f7->Entity(i))) {
453 item = GetShapeResult(st402f7->Entity(i));
458 item = TransferGeometry(st402f7->Entity(i));
460 catch(Standard_Failure const&) {
462 Message_Msg msg1015("IGES_1015");
463 SendFail(st402f7->Entity(i),msg1015);
467 //Message_Msg msg1030("IGES_1030");
468 //msg1030.Arg(st402f7->FormNumber());
470 //SendWarning (st402f7,msg1030);
471 ProblemInGroup = Standard_True;
475 SetShapeResult (st402f7->Entity(i),item);
480 Message_Msg msg1030("IGES_1030");
481 msg1030.Arg(st402f7->FormNumber());
482 SendWarning (st402f7,msg1030);
486 Message_Msg msg1001("IGES_1001");
487 msg1001.Arg(start->FormNumber());
488 SendFail (start,msg1001);
492 if (start->HasTransf()) {
495 if (IGESData_ToolLocation::ConvertLocation(GetEpsilon(),start->CompoundLocation(),
496 T,GetUnitFactor())) {
497 if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure)))
499 gp_XYZ tra = T.TranslationPart();
500 gp_XYZ trans = T408.TranslationPart();
502 T.SetTranslationPart(tra);
503 Standard_Real sc = T.ScaleFactor();
504 Standard_Real scalef = T408.ScaleFactor();
506 T.SetScaleFactor(sc);
508 TopLoc_Location L(T);
512 Message_Msg msg1035("IGES_1035");
513 SendWarning (start,msg1035);
517 if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure))) {
518 TopLoc_Location L(T408);
526 //=======================================================================
527 //function : HasShapeResult
529 //=======================================================================
531 Standard_Boolean IGESToBRep_CurveAndSurface::HasShapeResult
532 (const Handle(IGESData_IGESEntity)& start) const
534 DeclareAndCast(TransferBRep_ShapeBinder,binder,myTP->Find(start));
535 if (binder.IsNull()) return Standard_False;
536 return binder->HasResult();
540 //=======================================================================
541 //function : GetShapeResult
543 //=======================================================================
545 TopoDS_Shape IGESToBRep_CurveAndSurface::GetShapeResult
546 (const Handle(IGESData_IGESEntity)& start) const
550 DeclareAndCast(TransferBRep_ShapeBinder, binder, myTP->Find(start));
551 if (binder.IsNull()) return res;
552 if (binder->HasResult())
553 res = binder->Result();
558 //=======================================================================
559 //function : SetShapeResult
561 //=======================================================================
563 void IGESToBRep_CurveAndSurface::SetShapeResult
564 (const Handle(IGESData_IGESEntity)& start,
565 const TopoDS_Shape& result)
567 Handle(TransferBRep_ShapeBinder) binder = new TransferBRep_ShapeBinder;
568 myTP->Bind(start,binder);
569 binder->SetResult(result);
572 //=======================================================================
573 //function : NbShapeResult
575 //=======================================================================
577 Standard_Integer IGESToBRep_CurveAndSurface::NbShapeResult
578 (const Handle(IGESData_IGESEntity)& start) const
580 Standard_Integer nbres = 0;
581 DeclareAndCast(TransferBRep_ShapeListBinder,binder,myTP->Find(start));
582 if (binder.IsNull()) return nbres;
583 nbres = binder->NbShapes();
588 //=======================================================================
589 //function : GetShapeResult
591 //=======================================================================
593 TopoDS_Shape IGESToBRep_CurveAndSurface::GetShapeResult
594 (const Handle(IGESData_IGESEntity)& start, const Standard_Integer num) const
598 DeclareAndCast(TransferBRep_ShapeListBinder,binder,myTP->Find(start));
599 if (binder.IsNull()) return res;
601 if (num <= binder->NbShapes())
602 res = binder->Shape(num);
607 //=======================================================================
608 //function : AddShapeResult
610 //=======================================================================
612 void IGESToBRep_CurveAndSurface::AddShapeResult
613 (const Handle(IGESData_IGESEntity)& start,
614 const TopoDS_Shape& result)
616 DeclareAndCast(TransferBRep_ShapeListBinder,binder,myTP->Find(start));
617 if (binder.IsNull()){
618 binder = new TransferBRep_ShapeListBinder;
619 myTP->Bind(start,binder);
621 binder->AddResult(result);
624 void IGESToBRep_CurveAndSurface::SetSurface(const Handle(Geom_Surface)& theSurface)
626 if(mySurface!=theSurface) {
627 mySurface = theSurface;
628 myIsResolCom = Standard_False;
633 Handle(Geom_Surface) IGESToBRep_CurveAndSurface::Surface() const
638 Standard_Real IGESToBRep_CurveAndSurface::GetUVResolution()
640 if(!myIsResolCom && !mySurface.IsNull()) {
641 myIsResolCom = Standard_True;
642 GeomAdaptor_Surface aGAS(mySurface);
643 myUVResolution = Min(aGAS.UResolution(1.), aGAS.VResolution(1.));
645 return myUVResolution;