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 transferring invisible 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_ProgressScope.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,
182 const Message_ProgressRange& theProgress)
185 if (start.IsNull()) {
186 Message_Msg msg1005("IGES_1005");
187 SendFail(start, msg1005);
190 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
191 // Standard_Integer typeNumber = start->TypeNumber();
193 if (IGESToBRep::IsTopoCurve(start)) {
194 IGESToBRep_TopoCurve TC(*this);
195 res = TC.TransferTopoCurve(start);
197 else if (IGESToBRep::IsTopoSurface(start)) {
198 IGESToBRep_TopoSurface TS(*this);
199 res = TS.TransferTopoSurface(start);
201 else if (IGESToBRep::IsBRepEntity(start)) {
202 IGESToBRep_BRepEntity TS(*this);
203 res = TS.TransferBRepEntity(start, theProgress);
206 Message_Msg msg1015("IGES_1015");
207 SendFail(start, msg1015);
208 // AddFail(start, "The IGESEntity is not a curve a Surface or a BRep Entity.");
215 Standard_Real Eps = GetEpsGeom()*GetUnitFactor();
216 BRepLib::SameParameter(res,Eps);
218 catch(Standard_Failure) {
219 Message_Msg msg1010("IGES_1010");
220 SendWarning (start,msg1010);
229 //=======================================================================
230 //function : TransferGeometry
232 //=======================================================================
234 TopoDS_Shape IGESToBRep_CurveAndSurface::TransferGeometry
235 (const Handle(IGESData_IGESEntity)& start,
236 const Message_ProgressRange& theProgress)
238 // Declaration of messages//
240 //Message_Msg msg1005("IGES_1005"); // Software error : start IsNull.
241 //Message_Msg msg1015("IGES_1015"); // invalid type or exception raising (software error).
242 //Message_Msg msg1010("IGES_1010"); // Not sameparameter.
243 // Message_Msg msg1015("IGES_1015");
244 //Message_Msg msg210 ("XSTEP_210");
245 //Message_Msg msg202 ("XSTEP_202");
246 ////////////////////////////
249 if (start.IsNull()) {
250 Message_Msg msg1005("IGES_1005"); // Software error : start IsNull.
251 SendFail(start, msg1005);
255 // Read of the DE number and the type number of the entity
256 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
257 //Standard_Integer typeNumber = start->TypeNumber();
259 // sln 13.06.2002 OCC448: Avoid transferring invisible sub entities which
260 // logically depend on the one
261 Standard_Integer onlyvisible = Interface_Static::IVal("read.iges.onlyvisible");
263 if (IGESToBRep::IsCurveAndSurface(start)) {
264 if(onlyvisible && start->BlankStatus() == 1)
268 res = TransferCurveAndSurface(start, theProgress);
270 catch(Standard_Failure const&) {
271 Message_Msg msg1015("IGES_1015");
272 SendFail(start, msg1015);
277 //408 : SingularSubfigure
278 if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure)))
280 if(onlyvisible && start->BlankStatus() == 1)
283 DeclareAndCast(IGESBasic_SingularSubfigure, st408, start);
284 Handle (IGESBasic_SubfigureDef) stsub = st408->Subfigure();
285 gp_XYZ trans = st408->Translation();
287 Standard_Real scunit = GetUnitFactor();
288 vectr.Multiply(scunit);
289 T408.SetTranslation(vectr);
290 if (st408->HasScaleFactor()) {
291 Standard_Real scalef = st408->ScaleFactor();
292 T408.SetScaleFactor(scalef);
294 if (HasShapeResult(stsub)) {
295 res = GetShapeResult(stsub);
300 res = TransferGeometry(stsub, theProgress);
302 catch(Standard_Failure const&) {
304 Message_Msg msg1015("IGES_1015");
305 SendFail( st408, msg1015);
308 SetShapeResult(stsub,res);
313 // 308 : SubfigureDefinition
314 else if (start->IsKind(STANDARD_TYPE(IGESBasic_SubfigureDef))) {
315 DeclareAndCast(IGESBasic_SubfigureDef, st308, start);
316 TopoDS_Compound group;
318 B.MakeCompound (group);
319 if (st308->NbEntities() < 1) {
320 Message_Msg msg210 ("XSTEP_210");
321 SendFail( st308, msg210);
324 Message_ProgressScope PS (theProgress, "Subfigure item", st308->NbEntities());
325 for (Standard_Integer i=1; i <= st308->NbEntities() && PS.More(); i++)
327 Message_ProgressRange aRange = PS.Next();
329 if (st308->AssociatedEntity(i).IsNull()) {
330 Message_Msg msg1020("IGES_1020");
332 SendWarning( st308, msg1020);
335 if(onlyvisible && st308->AssociatedEntity(i)->BlankStatus() == 1 )
338 if (HasShapeResult(st308->AssociatedEntity(i)))
340 item = GetShapeResult(st308->AssociatedEntity(i));
345 item = TransferGeometry (st308->AssociatedEntity(i), aRange);
347 catch(Standard_Failure const&) {
349 Message_Msg msg1015("IGES_1015");
350 SendFail( st308->AssociatedEntity(i), msg1015);
354 Message_Msg msg1025("IGES_1025");
356 SendWarning (start,msg1025);
360 SetShapeResult (st308->AssociatedEntity(i),item);
365 else if (start->IsKind(STANDARD_TYPE(IGESBasic_Group))) {
366 if(onlyvisible && start->BlankStatus() == 1)
369 DeclareAndCast(IGESBasic_Group, st402f1, start);
370 TopoDS_Compound group;
372 B.MakeCompound (group);
373 if (st402f1->NbEntities() < 1) {
374 Message_Msg msg202 ("XSTEP_202");
375 msg202.Arg(st402f1->FormNumber());
376 SendFail(st402f1, msg202);
379 Message_ProgressScope PS (theProgress, "Group item", st402f1->NbEntities());
380 Standard_Boolean ProblemInGroup = Standard_False;
381 for (Standard_Integer i=1; i <= st402f1->NbEntities() && PS.More(); i++)
383 Message_ProgressRange aRange = PS.Next();
385 if (st402f1->Entity(i).IsNull()) {
386 Message_Msg msg1020("IGES_1020");
388 SendFail( st402f1, msg1020);
392 if(onlyvisible && st402f1->Entity(i)->BlankStatus() == 1)
395 if (HasShapeResult(st402f1->Entity(i))) {
396 item = GetShapeResult(st402f1->Entity(i));
401 item = TransferGeometry (st402f1->Entity(i), aRange);
403 catch(Standard_Failure const&) {
405 Message_Msg msg1015("IGES_1015");
406 SendFail(st402f1->Entity(i),msg1015);
410 //Message_Msg msg1030("IGES_1030");
411 //msg1030.Arg(st402f1->FormNumber());
413 //SendWarning (st402f1,msg1030);
414 ProblemInGroup = Standard_True;
418 SetShapeResult (st402f1->Entity(i),item);
423 Message_Msg msg1030("IGES_1030");
424 msg1030.Arg(st402f1->FormNumber());
425 SendWarning (st402f1,msg1030);
428 else if (start->IsKind(STANDARD_TYPE(IGESBasic_GroupWithoutBackP))) {
430 if(onlyvisible && start->BlankStatus() == 1)
433 DeclareAndCast(IGESBasic_GroupWithoutBackP, st402f7, start);
434 TopoDS_Compound group;
435 //unused Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(st402f7);
437 B.MakeCompound (group);
438 if (st402f7->NbEntities() < 1) {
439 Message_Msg msg202 ("XSTEP_202");
440 msg202.Arg(st402f7->FormNumber());
441 SendFail(st402f7, msg202);
444 Message_ProgressScope PS (theProgress, "Group item", st402f7->NbEntities());
445 Standard_Boolean ProblemInGroup = Standard_False;
446 for (Standard_Integer i=1; i <= st402f7->NbEntities() && PS.More(); i++)
448 Message_ProgressRange aRange = PS.Next();
450 if (st402f7->Entity(i).IsNull()) {
451 Message_Msg msg1020("IGES_1020");
453 SendFail( st402f7, msg1020);
457 if(onlyvisible && st402f7->Entity(i)->BlankStatus() == 1 )
460 if (HasShapeResult(st402f7->Entity(i))) {
461 item = GetShapeResult(st402f7->Entity(i));
466 item = TransferGeometry (st402f7->Entity(i), aRange);
468 catch(Standard_Failure const&) {
470 Message_Msg msg1015("IGES_1015");
471 SendFail(st402f7->Entity(i),msg1015);
475 //Message_Msg msg1030("IGES_1030");
476 //msg1030.Arg(st402f7->FormNumber());
478 //SendWarning (st402f7,msg1030);
479 ProblemInGroup = Standard_True;
483 SetShapeResult (st402f7->Entity(i),item);
488 Message_Msg msg1030("IGES_1030");
489 msg1030.Arg(st402f7->FormNumber());
490 SendWarning (st402f7,msg1030);
494 Message_Msg msg1001("IGES_1001");
495 msg1001.Arg(start->FormNumber());
496 SendFail (start,msg1001);
500 if (start->HasTransf()) {
503 if (IGESData_ToolLocation::ConvertLocation(GetEpsilon(),start->CompoundLocation(),
504 T,GetUnitFactor())) {
505 if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure)))
507 gp_XYZ tra = T.TranslationPart();
508 gp_XYZ trans = T408.TranslationPart();
510 T.SetTranslationPart(tra);
511 Standard_Real sc = T.ScaleFactor();
512 Standard_Real scalef = T408.ScaleFactor();
514 T.SetScaleFactor(sc);
516 TopLoc_Location L(T);
520 Message_Msg msg1035("IGES_1035");
521 SendWarning (start,msg1035);
525 if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure))) {
526 TopLoc_Location L(T408);
534 //=======================================================================
535 //function : HasShapeResult
537 //=======================================================================
539 Standard_Boolean IGESToBRep_CurveAndSurface::HasShapeResult
540 (const Handle(IGESData_IGESEntity)& start) const
542 DeclareAndCast(TransferBRep_ShapeBinder,binder,myTP->Find(start));
543 if (binder.IsNull()) return Standard_False;
544 return binder->HasResult();
548 //=======================================================================
549 //function : GetShapeResult
551 //=======================================================================
553 TopoDS_Shape IGESToBRep_CurveAndSurface::GetShapeResult
554 (const Handle(IGESData_IGESEntity)& start) const
558 DeclareAndCast(TransferBRep_ShapeBinder, binder, myTP->Find(start));
559 if (binder.IsNull()) return res;
560 if (binder->HasResult())
561 res = binder->Result();
566 //=======================================================================
567 //function : SetShapeResult
569 //=======================================================================
571 void IGESToBRep_CurveAndSurface::SetShapeResult
572 (const Handle(IGESData_IGESEntity)& start,
573 const TopoDS_Shape& result)
575 Handle(TransferBRep_ShapeBinder) binder = new TransferBRep_ShapeBinder;
576 myTP->Bind(start,binder);
577 binder->SetResult(result);
580 //=======================================================================
581 //function : NbShapeResult
583 //=======================================================================
585 Standard_Integer IGESToBRep_CurveAndSurface::NbShapeResult
586 (const Handle(IGESData_IGESEntity)& start) const
588 Standard_Integer nbres = 0;
589 DeclareAndCast(TransferBRep_ShapeListBinder,binder,myTP->Find(start));
590 if (binder.IsNull()) return nbres;
591 nbres = binder->NbShapes();
596 //=======================================================================
597 //function : GetShapeResult
599 //=======================================================================
601 TopoDS_Shape IGESToBRep_CurveAndSurface::GetShapeResult
602 (const Handle(IGESData_IGESEntity)& start, const Standard_Integer num) const
606 DeclareAndCast(TransferBRep_ShapeListBinder,binder,myTP->Find(start));
607 if (binder.IsNull()) return res;
609 if (num <= binder->NbShapes())
610 res = binder->Shape(num);
615 //=======================================================================
616 //function : AddShapeResult
618 //=======================================================================
620 void IGESToBRep_CurveAndSurface::AddShapeResult
621 (const Handle(IGESData_IGESEntity)& start,
622 const TopoDS_Shape& result)
624 DeclareAndCast(TransferBRep_ShapeListBinder,binder,myTP->Find(start));
625 if (binder.IsNull()){
626 binder = new TransferBRep_ShapeListBinder;
627 myTP->Bind(start,binder);
629 binder->AddResult(result);
632 void IGESToBRep_CurveAndSurface::SetSurface(const Handle(Geom_Surface)& theSurface)
634 if(mySurface!=theSurface) {
635 mySurface = theSurface;
636 myIsResolCom = Standard_False;
641 Handle(Geom_Surface) IGESToBRep_CurveAndSurface::Surface() const
646 Standard_Real IGESToBRep_CurveAndSurface::GetUVResolution()
648 if(!myIsResolCom && !mySurface.IsNull()) {
649 myIsResolCom = Standard_True;
650 GeomAdaptor_Surface aGAS(mySurface);
651 myUVResolution = Min(aGAS.UResolution(1.), aGAS.VResolution(1.));
653 return myUVResolution;