From 022a887d5e9ecd1034aed666b3aa009d5b8e3449 Mon Sep 17 00:00:00 2001 From: dkulikov Date: Fri, 20 Dec 2024 14:31:04 +0000 Subject: [PATCH] Data Exchange - Update Readers with ShapeHealing parameters #247 All instances of using XSAlgo_AlgoContainer are replaced with XSAlgo_ShapeProcessor. Parameters for XSAlgo_ShapeProcessor operations are now can be passes via the updated interface of respective classes. --- src/DE/DE_ShapeFixParameters.hxx | 2 +- src/IGESCAFControl/IGESCAFControl_Writer.hxx | 1 + src/IGESControl/IGESControl_ActorWrite.cxx | 56 ++- src/IGESControl/IGESControl_ActorWrite.hxx | 24 +- src/IGESControl/IGESControl_Reader.cxx | 20 + src/IGESControl/IGESControl_Reader.hxx | 28 +- src/IGESControl/IGESControl_Writer.cxx | 133 ++++--- src/IGESControl/IGESControl_Writer.hxx | 61 ++- src/IGESToBRep/IGESToBRep_Actor.cxx | 160 ++++---- src/IGESToBRep/IGESToBRep_Actor.hxx | 25 +- src/IGESToBRep/IGESToBRep_Reader.cxx | 352 +++++++++--------- src/IGESToBRep/IGESToBRep_Reader.hxx | 47 ++- src/STEPCAFControl/STEPCAFControl_Reader.cxx | 35 ++ src/STEPCAFControl/STEPCAFControl_Reader.hxx | 34 +- src/STEPCAFControl/STEPCAFControl_Writer.cxx | 28 ++ src/STEPCAFControl/STEPCAFControl_Writer.hxx | 23 +- src/STEPControl/STEPControl_ActorRead.cxx | 83 +++-- src/STEPControl/STEPControl_ActorRead.hxx | 20 +- src/STEPControl/STEPControl_ActorWrite.cxx | 78 ++-- src/STEPControl/STEPControl_ActorWrite.hxx | 18 +- src/STEPControl/STEPControl_Reader.cxx | 21 +- src/STEPControl/STEPControl_Reader.hxx | 16 +- src/STEPControl/STEPControl_Writer.cxx | 68 ++++ src/STEPControl/STEPControl_Writer.hxx | 43 ++- .../Transfer_ActorOfFinderProcess.cxx | 32 ++ .../Transfer_ActorOfFinderProcess.hxx | 33 +- .../Transfer_ActorOfTransientProcess.cxx | 31 +- .../Transfer_ActorOfTransientProcess.hxx | 41 +- src/XSAlgo/XSAlgo_ShapeProcessor.cxx | 162 +++++--- src/XSAlgo/XSAlgo_ShapeProcessor.hxx | 32 +- src/XSControl/XSControl_Reader.cxx | 58 ++- src/XSControl/XSControl_Reader.hxx | 35 +- 32 files changed, 1148 insertions(+), 652 deletions(-) diff --git a/src/DE/DE_ShapeFixParameters.hxx b/src/DE/DE_ShapeFixParameters.hxx index c02450aa91..288a041dfb 100644 --- a/src/DE/DE_ShapeFixParameters.hxx +++ b/src/DE/DE_ShapeFixParameters.hxx @@ -30,7 +30,7 @@ struct DE_ShapeFixParameters double Tolerance3d = 1.e-6; double MaxTolerance3d = 1.0; double MinTolerance3d = 1.e-7; - TopAbs_ShapeEnum DetalizationLevel = TopAbs_ShapeEnum::TopAbs_FACE; + TopAbs_ShapeEnum DetalizationLevel = TopAbs_ShapeEnum::TopAbs_VERTEX; bool NonManifold = false; FixMode FixFreeShellMode = FixMode::FixOrNot; FixMode FixFreeFaceMode = FixMode::FixOrNot; diff --git a/src/IGESCAFControl/IGESCAFControl_Writer.hxx b/src/IGESCAFControl/IGESCAFControl_Writer.hxx index 56d6fe4a93..f6554e94d1 100644 --- a/src/IGESCAFControl/IGESCAFControl_Writer.hxx +++ b/src/IGESCAFControl/IGESCAFControl_Writer.hxx @@ -26,6 +26,7 @@ #include #include #include + class XSControl_WorkSession; class TDocStd_Document; class TCollection_AsciiString; diff --git a/src/IGESControl/IGESControl_ActorWrite.cxx b/src/IGESControl/IGESControl_ActorWrite.cxx index de6ca78fcb..29774891c7 100644 --- a/src/IGESControl/IGESControl_ActorWrite.cxx +++ b/src/IGESControl/IGESControl_ActorWrite.cxx @@ -29,11 +29,19 @@ #include #include #include -#include +#include IMPLEMENT_STANDARD_RTTIEXT(IGESControl_ActorWrite,Transfer_ActorOfFinderProcess) -IGESControl_ActorWrite::IGESControl_ActorWrite () { ModeTrans() = 0; } +//============================================================================= + +IGESControl_ActorWrite::IGESControl_ActorWrite() +{ + ModeTrans() = 0; + SetParameters(GetDefaultParams()); +} + +//============================================================================= Standard_Boolean IGESControl_ActorWrite::Recognize (const Handle(Transfer_Finder)& start) @@ -50,12 +58,14 @@ Standard_Boolean IGESControl_ActorWrite::Recognize return Standard_False; } +//============================================================================= + Handle(Transfer_Binder) IGESControl_ActorWrite::Transfer (const Handle(Transfer_Finder)& start, const Handle(Transfer_FinderProcess)& FP, const Message_ProgressRange& theProgress) { - XSAlgo::AlgoContainer()->PrepareForTransfer(); + XSAlgo_ShapeProcessor::PrepareForTransfer(); DeclareAndCast(IGESData_IGESModel,modl,FP->Model()); if (modl.IsNull()) return NullResult(); @@ -63,27 +73,25 @@ Handle(Transfer_Binder) IGESControl_ActorWrite::Transfer Handle(Standard_Transient) ent; DeclareAndCast(TransferBRep_ShapeMapper,shmap,start); - if (!shmap.IsNull()) { + if (!shmap.IsNull()) + { TopoDS_Shape shape = shmap->Value(); - if (shape.IsNull()) return NullResult(); -// modified by NIZHNY-EAP Tue Aug 29 11:16:54 2000 ___BEGIN___ - Handle(Standard_Transient) info; - Standard_Real Tol = Interface_Static::RVal("write.precision.val"); - Standard_Real maxTol = Interface_Static::RVal("read.maxprecision.val"); - shape = XSAlgo::AlgoContainer()->ProcessShape( shape, Tol, maxTol, - "write.iges.resource.name", - "write.iges.sequence", info, - theProgress, false, TopAbs_EDGE); -// modified by NIZHNY-EAP Tue Aug 29 11:17:01 2000 ___END___ + if (shape.IsNull()) + { + return NullResult(); + } + + XSAlgo_ShapeProcessor aShapeProcessor(GetParameters()); + ShapeProcess::OperationsFlags aFlags; + aFlags.set(ShapeProcess::Operation::DirectFaces); + shape = aShapeProcessor.ProcessShape(shape, aFlags, theProgress); BRepToIGES_BREntity BR0; BR0.SetModel(modl); BR0.SetTransferProcess(FP); BRepToIGESBRep_Entity BR1; BR1.SetModel(modl); BR1.SetTransferProcess(FP); if (themodetrans == 0) ent = BR0.TransferShape(shape, theProgress); if (themodetrans == 1) ent = BR1.TransferShape(shape, theProgress); -// modified by NIZHNY-EAP Tue Aug 29 11:37:18 2000 ___BEGIN___ - XSAlgo::AlgoContainer()->MergeTransferInfo(FP, info); -// modified by NIZHNY-EAP Tue Aug 29 11:37:25 2000 ___END___ + aShapeProcessor.MergeTransferInfo(FP); if (!ent.IsNull()) return TransientResult(ent); } DeclareAndCast(Transfer_TransientMapper,gemap,start); @@ -111,3 +119,17 @@ Handle(Transfer_Binder) IGESControl_ActorWrite::Transfer return NullResult(); } + +//============================================================================= + +IGESControl_ActorWrite::ParameterMap IGESControl_ActorWrite::GetDefaultParams() +{ + static ParameterMap aParams; + if (aParams.empty()) + { + DE_ShapeFixParameters aShapeFixParameters; + aShapeFixParameters.DetalizationLevel = TopAbs_EDGE; + XSAlgo_ShapeProcessor::FillParameterMap(aShapeFixParameters, false, aParams); + } + return aParams; +} diff --git a/src/IGESControl/IGESControl_ActorWrite.hxx b/src/IGESControl/IGESControl_ActorWrite.hxx index 9b27e13e4e..94d02673e9 100644 --- a/src/IGESControl/IGESControl_ActorWrite.hxx +++ b/src/IGESControl/IGESControl_ActorWrite.hxx @@ -21,21 +21,18 @@ #include #include + class Transfer_Finder; class Transfer_Binder; class Transfer_FinderProcess; - - class IGESControl_ActorWrite; + DEFINE_STANDARD_HANDLE(IGESControl_ActorWrite, Transfer_ActorOfFinderProcess) //! Actor to write Shape to IGES class IGESControl_ActorWrite : public Transfer_ActorOfFinderProcess { - public: - - Standard_EXPORT IGESControl_ActorWrite(); //! Recognizes a ShapeMapper @@ -50,21 +47,12 @@ public: const Handle(Transfer_FinderProcess)& FP, const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - + //! Returns the default parameters for shape processing. + //! These parameters are used by default in the constructor. + //! @return the default parameters for shape processing. + Standard_EXPORT static ParameterMap GetDefaultParams(); DEFINE_STANDARD_RTTIEXT(IGESControl_ActorWrite,Transfer_ActorOfFinderProcess) - -protected: - - - - -private: - - - - }; diff --git a/src/IGESControl/IGESControl_Reader.cxx b/src/IGESControl/IGESControl_Reader.cxx index 93eb955eaf..e8540fdcab 100644 --- a/src/IGESControl/IGESControl_Reader.cxx +++ b/src/IGESControl/IGESControl_Reader.cxx @@ -15,6 +15,7 @@ //abv 10.04.99 S4136: eliminate using BRepAPI::Precision() #include +#include #include #include #include @@ -35,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -312,3 +314,21 @@ void IGESControl_Reader::PrintTransferInfo } } } + +//============================================================================= + +IGESToBRep_Actor::ParameterMap IGESControl_Reader::GetDefaultParams() +{ + static ParameterMap aParams; + if (aParams.empty()) + { + DE_ShapeFixParameters aShapeFixParameters; + aShapeFixParameters.DetalizationLevel = TopAbs_EDGE; + aShapeFixParameters.CreateOpenSolidMode = DE_ShapeFixParameters::FixMode::Fix; + aShapeFixParameters.FixTailMode = DE_ShapeFixParameters::FixMode::FixOrNot; + aShapeFixParameters.MaxTailAngle = DE_ShapeFixParameters::FixMode::FixOrNot; + aShapeFixParameters.MaxTailWidth = DE_ShapeFixParameters::FixMode::FixOrNot; + XSAlgo_ShapeProcessor::FillParameterMap(aShapeFixParameters, false, aParams); + } + return aParams; +} diff --git a/src/IGESControl/IGESControl_Reader.hxx b/src/IGESControl/IGESControl_Reader.hxx index b473549a4f..29eb785afb 100644 --- a/src/IGESControl/IGESControl_Reader.hxx +++ b/src/IGESControl/IGESControl_Reader.hxx @@ -20,15 +20,12 @@ #include #include #include - #include #include #include #include -class XSControl_WorkSession; -class IGESData_IGESModel; - +class IGESData_IGESModel; //! Reads IGES files, checks them and translates their contents into Open CASCADE models. //! The IGES data can be that of a whole model or that of a specific list of entities in the model. @@ -68,9 +65,7 @@ class IGESData_IGESModel; class IGESControl_Reader : public XSControl_Reader { public: - DEFINE_STANDARD_ALLOC - //! Creates a Reader from scratch Standard_EXPORT IGESControl_Reader(); @@ -96,29 +91,16 @@ public: //! Prints Statistics and check list for Transfer Standard_EXPORT void PrintTransferInfo (const IFSelect_PrintFail failwarn, const IFSelect_PrintCount mode) const; - - - -protected: - - - - + //! Returns the default parameters for shape processing. + //! These parameters are used by default in the constructor. + //! @return the default parameters for shape processing. + Standard_EXPORT static ParameterMap GetDefaultParams(); private: - - - Standard_Boolean theReadOnlyVisible; - }; - #include - - - - #endif // _IGESControl_Reader_HeaderFile diff --git a/src/IGESControl/IGESControl_Writer.cxx b/src/IGESControl/IGESControl_Writer.cxx index f1608adede..6b76c8a2ca 100644 --- a/src/IGESControl/IGESControl_Writer.cxx +++ b/src/IGESControl/IGESControl_Writer.cxx @@ -41,62 +41,74 @@ #include #include #include -#include +#include #include -IGESControl_Writer::IGESControl_Writer () - : myTP (new Transfer_FinderProcess(10000)) , - myIsComputed (Standard_False) + +//============================================================================= + +IGESControl_Writer::IGESControl_Writer(const ParameterMap& theShapeProcParams) +: myTP(new Transfer_FinderProcess(10000)), + myIsComputed(Standard_False), + myShapeProcParams(theShapeProcParams) { -// faudrait aussi (?) prendre les parametres par defaut ... ? IGESControl_Controller::Init(); myEditor.Init(IGESSelect_WorkLibrary::DefineProtocol()); - myEditor.SetUnitName(Interface_Static::CVal ("write.iges.unit")); - myEditor.ApplyUnit(); - myWriteMode = Interface_Static::IVal ("write.iges.brep.mode"); - myModel = myEditor.Model(); + myEditor.SetUnitName(Interface_Static::CVal("write.iges.unit")); + myEditor.ApplyUnit(); + myWriteMode = Interface_Static::IVal("write.iges.brep.mode"); + myModel = myEditor.Model(); } -IGESControl_Writer::IGESControl_Writer - (const Standard_CString unit, const Standard_Integer modecr) - : myTP (new Transfer_FinderProcess(10000)) , - myWriteMode (modecr) , myIsComputed (Standard_False) +//============================================================================= + +IGESControl_Writer::IGESControl_Writer(const Standard_CString theUnit, + const Standard_Integer theModecr, + const ParameterMap& theShapeProcParams) +: myTP(new Transfer_FinderProcess(10000)), + myWriteMode(theModecr), + myIsComputed(Standard_False), + myShapeProcParams(theShapeProcParams) { -// faudrait aussi (?) prendre les parametres par defaut ... ? IGESControl_Controller::Init(); myEditor.Init(IGESSelect_WorkLibrary::DefineProtocol()); - myEditor.SetUnitName(unit); + myEditor.SetUnitName(theUnit); myEditor.ApplyUnit(); myModel = myEditor.Model(); } -IGESControl_Writer::IGESControl_Writer - (const Handle(IGESData_IGESModel)& model, const Standard_Integer modecr) - : myTP (new Transfer_FinderProcess(10000)) , - myModel (model) , - myEditor (model,IGESSelect_WorkLibrary::DefineProtocol()) , - myWriteMode (modecr) , myIsComputed (Standard_False) { } +//============================================================================= + +IGESControl_Writer::IGESControl_Writer(const Handle(IGESData_IGESModel)& theModel, + const Standard_Integer theModecr, + const ParameterMap& theShapeProcParams) +: myTP(new Transfer_FinderProcess(10000)), + myModel(theModel), + myEditor(theModel, IGESSelect_WorkLibrary::DefineProtocol()), + myWriteMode(theModecr), + myIsComputed(Standard_False), + myShapeProcParams(theShapeProcParams) +{} + +//============================================================================= Standard_Boolean IGESControl_Writer::AddShape (const TopoDS_Shape& theShape, const Message_ProgressRange& theProgress) { if (theShape.IsNull()) return Standard_False; - XSAlgo::AlgoContainer()->PrepareForTransfer(); + XSAlgo_ShapeProcessor::PrepareForTransfer(); Message_ProgressScope aPS(theProgress, NULL, 2); - // modified by NIZHNY-EAP Tue Aug 29 11:16:54 2000 ___BEGIN___ - Handle(Standard_Transient) info; - Standard_Real Tol = Interface_Static::RVal("write.precision.val"); - Standard_Real maxTol = Interface_Static::RVal("read.maxprecision.val"); - TopoDS_Shape Shape = XSAlgo::AlgoContainer()->ProcessShape( theShape, Tol, maxTol, - "write.iges.resource.name", - "write.iges.sequence", info, - aPS.Next(), false, TopAbs_EDGE); + + XSAlgo_ShapeProcessor aShapeProcessor(myShapeProcParams); + ShapeProcess::OperationsFlags aFlags; + aFlags.set(ShapeProcess::Operation::DirectFaces); + TopoDS_Shape Shape = aShapeProcessor.ProcessShape(theShape, aFlags, aPS.Next()); + if (!aPS.More()) return Standard_False; - // modified by NIZHNY-EAP Tue Aug 29 11:17:01 2000 ___END___ BRepToIGES_BREntity B0; B0.SetTransferProcess(myTP); B0.SetModel(myModel); BRepToIGESBRep_Entity B1; B1.SetTransferProcess(myTP); B1.SetModel(myModel); Handle(IGESData_IGESEntity) ent = myWriteMode? @@ -106,9 +118,7 @@ Standard_Boolean IGESControl_Writer::AddShape (const TopoDS_Shape& theShape, if(ent.IsNull()) return Standard_False; -// modified by NIZHNY-EAP Tue Aug 29 11:37:18 2000 ___BEGIN___ - XSAlgo::AlgoContainer()->MergeTransferInfo(myTP, info); -// modified by NIZHNY-EAP Tue Aug 29 11:37:25 2000 ___END___ + aShapeProcessor.MergeTransferInfo(myTP); //22.10.98 gka BUC60080 @@ -203,6 +213,8 @@ Standard_Boolean IGESControl_Writer::AddGeom (const Handle(Standard_Transient)& return AddEntity (ent); } +//============================================================================= + Standard_Boolean IGESControl_Writer::AddEntity (const Handle(IGESData_IGESEntity)& ent) { if (ent.IsNull()) return Standard_False; @@ -211,6 +223,8 @@ Standard_Boolean IGESControl_Writer::AddEntity (const Handle(IGESData_IGESEntity return Standard_True; } +//============================================================================= + void IGESControl_Writer::ComputeModel () { if (!myIsComputed) { @@ -220,31 +234,26 @@ void IGESControl_Writer::ComputeModel () } } +//============================================================================= + Standard_Boolean IGESControl_Writer::Write (Standard_OStream& S, const Standard_Boolean fnes) { if (!S) return Standard_False; ComputeModel(); Standard_Integer nbEnt = myModel->NbEntities(); -#ifdef OCCT_DEBUG - std::cout<<" IGES Write : "< #include +#include + +struct DE_ShapeFixParameters; class Transfer_FinderProcess; class IGESData_IGESModel; class TopoDS_Shape; @@ -47,30 +50,36 @@ class IGESData_IGESEntity; class IGESControl_Writer { public: - DEFINE_STANDARD_ALLOC - + + using ParameterMap = std::unordered_map; + +public: //! Creates a writer object with the //! default unit (millimeters) and write mode (Face). //! IGESControl_Writer (const Standard_CString unit, //! const Standard_Integer modecr = 0); - Standard_EXPORT IGESControl_Writer(); + Standard_EXPORT IGESControl_Writer(const ParameterMap& theShapeProcParams = GetDefaultParams()); //! Creates a writer with given //! values for units and for write mode. - //! unit may be any unit that is accepted by the IGES standard. + //! theUnit may be any unit that is accepted by the IGES standard. //! By default, it is the millimeter. - //! modecr defines the write mode and may be: + //! theModecr defines the write mode and may be: //! - 0: Faces (default) //! - 1: BRep. - Standard_EXPORT IGESControl_Writer(const Standard_CString unit, const Standard_Integer modecr = 0); + Standard_EXPORT IGESControl_Writer(const Standard_CString theUnit, + const Standard_Integer theModecr = 0, + const ParameterMap& theShapeProcParams = GetDefaultParams()); //! Creates a writer object with the - //! prepared IGES model model in write mode. - //! modecr defines the write mode and may be: + //! prepared IGES model theModel in write mode. + //! theModecr defines the write mode and may be: //! - 0: Faces (default) //! - 1: BRep. - Standard_EXPORT IGESControl_Writer(const Handle(IGESData_IGESModel)& model, const Standard_Integer modecr = 0); + Standard_EXPORT IGESControl_Writer(const Handle(IGESData_IGESModel)& theModel, + const Standard_Integer theModecr = 0, + const ParameterMap& theShapeProcParams = GetDefaultParams()); //! Returns the IGES model to be written in output. const Handle(IGESData_IGESModel) & Model() const @@ -114,13 +123,37 @@ public: //! if the processor could not create the file). Standard_EXPORT Standard_Boolean Write (const Standard_CString file, const Standard_Boolean fnes = Standard_False); - private: + //! Sets parameters for shape processing. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const ParameterMap& theParameters); + + //! Sets parameters for shape processing. + //! Parameters are moved from the input map. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(ParameterMap&& theParameters); + + //! Sets parameters for shape processing. + //! Parameters from @p theParameters are copied to the internal map. Parameters in the + //! internal map that are not present in @p theParameters are left unchanged. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const DE_ShapeFixParameters& theParameters); + //! Returns parameters for shape processing that was set by SetParameters() method. + //! @return the parameters for shape processing. Empty map if no parameters were set. + inline const ParameterMap& GetParameters() const { return myShapeProcParams; } + + //! Returns the default parameters for shape processing. + //! These parameters are used by default in the constructor. + //! @return the default parameters for shape processing. + Standard_EXPORT static ParameterMap GetDefaultParams(); + + private: Handle(Transfer_FinderProcess) myTP; - Handle(IGESData_IGESModel) myModel; - IGESData_BasicEditor myEditor; - Standard_Integer myWriteMode; - Standard_Boolean myIsComputed; + Handle(IGESData_IGESModel) myModel; + IGESData_BasicEditor myEditor; + Standard_Integer myWriteMode; + Standard_Boolean myIsComputed; + ParameterMap myShapeProcParams; //!< Parameters for shape processing. }; #endif // _IGESControl_Writer_HeaderFile diff --git a/src/IGESToBRep/IGESToBRep_Actor.cxx b/src/IGESToBRep/IGESToBRep_Actor.cxx index 090df0c9f1..d6eb53e372 100644 --- a/src/IGESToBRep/IGESToBRep_Actor.cxx +++ b/src/IGESToBRep/IGESToBRep_Actor.cxx @@ -33,51 +33,87 @@ #include #include #include +#include IMPLEMENT_STANDARD_RTTIEXT(IGESToBRep_Actor,Transfer_ActorOfTransientProcess) -//======================================================================= -//function : IGESToBRep_Actor -//purpose : -//======================================================================= -IGESToBRep_Actor::IGESToBRep_Actor () -{ thecontinuity = 0; theeps = 0.0001; } +namespace +{ + //======================================================================= + //function : EncodeRegul + //purpose : INTERNAL to encode regularity on edges + //======================================================================= + static Standard_Boolean EncodeRegul(const TopoDS_Shape& theShape) + { + const Standard_Real aToleranceAngle = Interface_Static::RVal("read.encoderegularity.angle"); + if (theShape.IsNull()) + { + return Standard_True; + } + if (aToleranceAngle <= 0.) + { + return Standard_True; + } + try + { + OCC_CATCH_SIGNALS + BRepLib::EncodeRegularity(theShape, aToleranceAngle); + } + catch (const Standard_Failure&) + { + return Standard_False; + } + return Standard_True; + } + + //======================================================================= + //function : TrimTolerances + //purpose : Trims tolerances of the shape according to static parameters + //======================================================================= + static void TrimTolerances(const TopoDS_Shape& theShape, const Standard_Real theTolerance) + { + if (Interface_Static::IVal("read.maxprecision.mode") == 1) + { + ShapeFix_ShapeTolerance aSFST; + aSFST.LimitTolerance(theShape, 0, Max(theTolerance, Interface_Static::RVal("read.maxprecision.val"))); + } + } +} //======================================================================= -//function : SetModel -//purpose : + +IGESToBRep_Actor::IGESToBRep_Actor() +: thecontinuity(0), + theeps(0.0001) +{ + SetParameters(GetDefaultParams()); +} + //======================================================================= + void IGESToBRep_Actor::SetModel (const Handle(Interface_InterfaceModel)& model) { themodel = model; theeps = Handle(IGESData_IGESModel)::DownCast(themodel)->GlobalSection().Resolution(); } - -//======================================================================= -//function : SetContinuity -//purpose : //======================================================================= + void IGESToBRep_Actor::SetContinuity (const Standard_Integer continuity) { thecontinuity = continuity; } - -//======================================================================= -//function : GetContinuity -//purpose : //======================================================================= + Standard_Integer IGESToBRep_Actor::GetContinuity () const { return thecontinuity; } //======================================================================= -//function : Recognize -//purpose : -//======================================================================= + Standard_Boolean IGESToBRep_Actor::Recognize (const Handle(Standard_Transient)& start) { @@ -97,44 +133,9 @@ Standard_Boolean IGESToBRep_Actor::Recognize // Cas restants : non reconnus return Standard_False; } -//======================================================================= -//function : EncodeRegul -//purpose : INTERNAL to encode regularity on edges -//======================================================================= -static Standard_Boolean EncodeRegul (const TopoDS_Shape& sh) -{ - Standard_Real tolang = Interface_Static::RVal("read.encoderegularity.angle"); - if (sh.IsNull()) return Standard_True; - if (tolang <= 0) return Standard_True; - try { - OCC_CATCH_SIGNALS - BRepLib::EncodeRegularity (sh,tolang); - } - catch(Standard_Failure const&) { - return Standard_False; - } - return Standard_True; -} //======================================================================= -//function : TrimTolerances -//purpose : Trims tolerances of the shape according to static parameters -// -//======================================================================= - -static void TrimTolerances (const TopoDS_Shape& shape, - const Standard_Real tol) -{ - if( Interface_Static::IVal("read.maxprecision.mode")==1) { - ShapeFix_ShapeTolerance SFST; - SFST.LimitTolerance (shape, 0, Max(tol,Interface_Static::RVal ("read.maxprecision.val"))); - } -} -//======================================================================= -//function : Transfer -//purpose : -//======================================================================= Handle(Transfer_Binder) IGESToBRep_Actor::Transfer (const Handle(Standard_Transient)& start, const Handle(Transfer_TransientProcess)& TP, const Message_ProgressRange& theProgress) @@ -148,7 +149,7 @@ Handle(Transfer_Binder) IGESToBRep_Actor::Transfer return NullResult(); TopoDS_Shape shape; -// appeler le transfert seulement si type OK + // Call the transfer only if type is OK. Standard_Integer typnum = ent->TypeNumber(); Standard_Integer fornum = ent->FormNumber(); Standard_Real eps; @@ -160,7 +161,7 @@ Handle(Transfer_Binder) IGESToBRep_Actor::Transfer // Start progress scope (no need to check if progress exists -- it is safe) Message_ProgressScope aPS(theProgress, "Transfer stage", 2); - XSAlgo::AlgoContainer()->PrepareForTransfer(); + XSAlgo_ShapeProcessor::PrepareForTransfer(); IGESToBRep_CurveAndSurface CAS; CAS.SetModel(mymodel); CAS.SetContinuity(thecontinuity); @@ -179,7 +180,6 @@ Handle(Transfer_Binder) IGESToBRep_Actor::Transfer if (eps > 1.E-08) { CAS.SetEpsGeom(eps); theeps = eps*CAS.GetUnitFactor(); -// Interface_Static::SetRVal("lastpreci",theeps); } Standard_Integer nbTPitems = TP->NbMapped(); { @@ -191,15 +191,20 @@ Handle(Transfer_Binder) IGESToBRep_Actor::Transfer shape.Nullify(); } } - + // fixing shape - Handle(Standard_Transient) info; - shape = XSAlgo::AlgoContainer()->ProcessShape(shape, theeps, CAS.GetMaxTol(), - "read.iges.resource.name", - "read.iges.sequence", - info, aPS.Next(), - false, TopAbs_EDGE); - XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems); + + // Set tolerances for shape processing. + // These parameters are calculated inside IGESToBRep_Actor::Transfer() and cannot be set from outside. + Transfer_ActorOfTransientProcess::ParameterMap aParameters = GetParameters(); + XSAlgo_ShapeProcessor::SetParameter("FixShape.Tolerance3d", theeps, true, aParameters); + XSAlgo_ShapeProcessor::SetParameter("FixShape.MaxTolerance3d", CAS.GetMaxTol(), true, aParameters); + + XSAlgo_ShapeProcessor aShapeProcessor(aParameters); + ShapeProcess::OperationsFlags aFlags; + aFlags.set(ShapeProcess::Operation::FixShape); + shape = aShapeProcessor.ProcessShape(shape, aFlags, aPS.Next()); + aShapeProcessor.MergeTransferInfo(TP, nbTPitems); } ShapeExtend_Explorer SBE; @@ -216,6 +221,27 @@ Handle(Transfer_Binder) IGESToBRep_Actor::Transfer return binder; } +//============================================================================= - Standard_Real IGESToBRep_Actor::UsedTolerance () const - { return theeps; } +Standard_Real IGESToBRep_Actor::UsedTolerance() const +{ + return theeps; +} + +//============================================================================= + +Transfer_ActorOfTransientProcess::ParameterMap IGESToBRep_Actor::GetDefaultParams() +{ + static ParameterMap aParams; + if (aParams.empty()) + { + DE_ShapeFixParameters aShapeFixParameters; + aShapeFixParameters.DetalizationLevel = TopAbs_EDGE; + aShapeFixParameters.CreateOpenSolidMode = DE_ShapeFixParameters::FixMode::Fix; + aShapeFixParameters.FixTailMode = DE_ShapeFixParameters::FixMode::FixOrNot; + aShapeFixParameters.MaxTailAngle = DE_ShapeFixParameters::FixMode::FixOrNot; + aShapeFixParameters.MaxTailWidth = DE_ShapeFixParameters::FixMode::FixOrNot; + XSAlgo_ShapeProcessor::FillParameterMap(aShapeFixParameters, false, aParams); + } + return aParams; +} diff --git a/src/IGESToBRep/IGESToBRep_Actor.hxx b/src/IGESToBRep/IGESToBRep_Actor.hxx index 6e157fbd4b..e58d312a60 100644 --- a/src/IGESToBRep/IGESToBRep_Actor.hxx +++ b/src/IGESToBRep/IGESToBRep_Actor.hxx @@ -24,6 +24,7 @@ #include #include +struct DE_ShapeFixParameters; class Interface_InterfaceModel; class Standard_Transient; class Transfer_Binder; @@ -39,10 +40,7 @@ DEFINE_STANDARD_HANDLE(IGESToBRep_Actor, Transfer_ActorOfTransientProcess) //! then returns the Binder which contains the Result class IGESToBRep_Actor : public Transfer_ActorOfTransientProcess { - public: - - Standard_EXPORT IGESToBRep_Actor(); Standard_EXPORT void SetModel (const Handle(Interface_InterfaceModel)& model); @@ -66,30 +64,17 @@ public: //! the file or from statics Standard_EXPORT Standard_Real UsedTolerance() const; - - + //! Returns the default parameters for shape processing. + //! These parameters are used by default in the constructor. + //! @return the default parameters for shape processing. + Standard_EXPORT static ParameterMap GetDefaultParams(); DEFINE_STANDARD_RTTIEXT(IGESToBRep_Actor,Transfer_ActorOfTransientProcess) -protected: - - - - private: - - Handle(Interface_InterfaceModel) themodel; Standard_Integer thecontinuity; Standard_Real theeps; - - }; - - - - - - #endif // _IGESToBRep_Actor_HeaderFile diff --git a/src/IGESToBRep/IGESToBRep_Reader.cxx b/src/IGESToBRep/IGESToBRep_Reader.cxx index 0230ca403f..73fd59f7b4 100644 --- a/src/IGESToBRep/IGESToBRep_Reader.cxx +++ b/src/IGESToBRep/IGESToBRep_Reader.cxx @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include //#include @@ -58,29 +58,69 @@ static Handle(IGESData_FileProtocol) protocol; +namespace +{ + //======================================================================= + //function : EncodeRegul + //purpose : INTERNAL to encode regularity on edges + //======================================================================= + static Standard_Boolean EncodeRegul(const TopoDS_Shape& theShape) + { + const Standard_Real aToleranceAngle = Interface_Static::RVal("read.encoderegularity.angle"); + if (theShape.IsNull()) + { + return Standard_True; + } + if (aToleranceAngle <= 0.) + { + return Standard_True; + } + + try + { + OCC_CATCH_SIGNALS + BRepLib::EncodeRegularity(theShape, aToleranceAngle); + } + catch (const Standard_Failure&) + { + return Standard_False; + } + return Standard_True; + } -//======================================================================= -//function : IGESToBRep_Reader -//purpose : -//======================================================================= - IGESToBRep_Reader::IGESToBRep_Reader () + //======================================================================= + //function : TrimTolerances + //purpose : Trims tolerances of the shape according to static parameters + //======================================================================= + static void TrimTolerances(const TopoDS_Shape& theShape, const Standard_Real theTolerance) + { + if (Interface_Static::IVal("read.maxprecision.mode") == 1) + { + ShapeFix_ShapeTolerance SFST; + SFST.LimitTolerance(theShape, 0, Max(theTolerance, Interface_Static::RVal("read.maxprecision.val"))); + } + } +} + +//============================================================================= + +IGESToBRep_Reader::IGESToBRep_Reader(const ParameterMap& theShapeProcParams) +: theDone(Standard_False), + myShapeProcParams(theShapeProcParams) { - theDone = Standard_False; - if (protocol.IsNull()) { - IGESAppli::Init(); IGESSolid::Init(); + if (protocol.IsNull()) + { + IGESAppli::Init(); + IGESSolid::Init(); protocol = new IGESData_FileProtocol; protocol->Add(IGESAppli::Protocol()); protocol->Add(IGESSolid::Protocol()); } theActor = new IGESToBRep_Actor; - theProc = new Transfer_TransientProcess; + theProc = new Transfer_TransientProcess; } - -//======================================================================= -//function : LoadFile -//purpose : loads a Model from a file -//======================================================================= +//============================================================================= Standard_Integer IGESToBRep_Reader::LoadFile (const Standard_CString filename) { @@ -187,12 +227,9 @@ Standard_Integer IGESToBRep_Reader::LoadFile (const Standard_CString filename) return StatusFile; } +//============================================================================= -//======================================================================= -//function : SetModel -//purpose : Specifies a Model to work on -//======================================================================= - void IGESToBRep_Reader::SetModel (const Handle(IGESData_IGESModel)& model) +void IGESToBRep_Reader::SetModel (const Handle(IGESData_IGESModel)& model) { theModel = model; theDone = Standard_False; @@ -203,55 +240,45 @@ Standard_Integer IGESToBRep_Reader::LoadFile (const Standard_CString filename) theProc->Clear(); } +//============================================================================= -//======================================================================= -//function : Model -//purpose : returns the Model to be worked on -//======================================================================= - Handle(IGESData_IGESModel) IGESToBRep_Reader::Model () const - { return theModel; } - - -//======================================================================= -//function : SetTransientProcess -//purpose : Specifies a TransferProcess -//======================================================================= - void IGESToBRep_Reader::SetTransientProcess - (const Handle(Transfer_TransientProcess)& TP) - { theProc = TP; } - -//======================================================================= -//function : TransientProcess -//purpose : Returns the TransferProcess -//======================================================================= - Handle(Transfer_TransientProcess) IGESToBRep_Reader::TransientProcess () const - { return theProc; } - -//======================================================================= -//function : Actor -//purpose : returns theActor -//======================================================================= - Handle(IGESToBRep_Actor) IGESToBRep_Reader::Actor () const - { return theActor; } - - -//======================================================================= -//function : Clear -//purpose : Clears the result and Done status -//======================================================================= - void IGESToBRep_Reader::Clear () +Handle(IGESData_IGESModel) IGESToBRep_Reader::Model() const { - theDone = Standard_False; + return theModel; +} + +//============================================================================= + +void IGESToBRep_Reader::SetTransientProcess(const Handle(Transfer_TransientProcess)& TP) +{ + theProc = TP; +} + +//============================================================================= + +Handle(Transfer_TransientProcess) IGESToBRep_Reader::TransientProcess() const +{ + return theProc; +} + +//============================================================================= + +Handle(IGESToBRep_Actor) IGESToBRep_Reader::Actor() const +{ + return theActor; +} + +//============================================================================= + +void IGESToBRep_Reader::Clear() +{ + theDone = Standard_False; theShapes.Clear(); } +//============================================================================= -//======================================================================= -//function : Check -//purpose : Checks the Model -//======================================================================= - Standard_Boolean IGESToBRep_Reader::Check - (const Standard_Boolean withprint) const +Standard_Boolean IGESToBRep_Reader::Check(const Standard_Boolean withprint) const { Interface_CheckTool cht (theModel,protocol); Interface_CheckIterator chl = cht.CompleteCheckList(); @@ -265,96 +292,15 @@ Standard_Integer IGESToBRep_Reader::LoadFile (const Standard_CString filename) return chl.IsEmpty(Standard_True); } +//============================================================================= -//======================================================================= -//function : IsDone -//purpose : returns True if the last transfert was a success -//======================================================================= - Standard_Boolean IGESToBRep_Reader::IsDone () const - { return theDone; } - - -//======================================================================= -//function : EncodeRegul -//purpose : INTERNAL to encode regularity on edges -//======================================================================= - -static Standard_Boolean EncodeRegul (const TopoDS_Shape& sh) +Standard_Boolean IGESToBRep_Reader::IsDone() const { - Standard_Real tolang = Interface_Static::RVal("read.encoderegularity.angle"); - if (sh.IsNull()) return Standard_True; - if (tolang <= 0) return Standard_True; - try { - OCC_CATCH_SIGNALS - BRepLib::EncodeRegularity (sh,tolang); - } - catch(Standard_Failure const&) { - return Standard_False; - } - return Standard_True; + return theDone; } -//======================================================================= -//function : UpdateMap -//purpose : Updates the correspondence map (Transfer_TransientProcess), -// setting as translation results, the shapes received after -// modification by modifier (BRepTools_Modifier) -//warning : BRepTools_Modifier raises exception when it cannot find input -// shape in its internal list -//======================================================================= - -// comment as unused PTV 18.09.2000 -// static void UpdateMap (const Handle(Transfer_TransientProcess)& map, -// const BRepTools_Modifier& modifier) -// { -// Transfer_IteratorOfProcessForTransient iterator = map->CompleteResult(Standard_True); -// for (iterator.Start(); iterator.More(); iterator.Next()) { -// const Handle(Transfer_Binder) binder = iterator.Value(); -// try { //to avoid exception in BRepTools_Modifier -// OCC_CATCH_SIGNALS -// if (binder->IsKind (STANDARD_TYPE (TransferBRep_ShapeBinder))) { -// DeclareAndCast(TransferBRep_ShapeBinder, shapebinder, binder); -// if (shapebinder->HasResult()) { -// TopoDS_Shape result = shapebinder->Result(); -// TopoDS_Shape modified = modifier.ModifiedShape (result); -// if (shapebinder->Status() != Transfer_StatusUsed) //to avoid exception -// shapebinder->SetResult (modified); -// } -// } -// else if (binder->IsKind (STANDARD_TYPE (TransferBRep_ShapeListBinder))) { -// DeclareAndCast(TransferBRep_ShapeListBinder, shapelistbinder, binder); -// for (Standard_Integer i = 1; i <= shapelistbinder->NbShapes(); i++) { -// TopoDS_Shape result = shapelistbinder->Shape (i); -// TopoDS_Shape modified = modifier.ModifiedShape (result); -// shapelistbinder->SetResult (i, modified); -// } -// } -// } -// catch(Standard_Failure) { -// continue; -// } -// } -// } - -//======================================================================= -//function : TrimTolerances -//purpose : Trims tolerances of the shape according to static parameters -// -//======================================================================= - -static void TrimTolerances (const TopoDS_Shape& shape, - const Standard_Real tol) -{ - if( Interface_Static::IVal("read.maxprecision.mode")==1) { - ShapeFix_ShapeTolerance SFST; - SFST.LimitTolerance (shape, 0, Max(tol,Interface_Static::RVal ("read.maxprecision.val"))); - } -} - -//======================================================================= -//function : TransferRoots -//purpose : Transfers all Roots Entities -//======================================================================= +//============================================================================= + void IGESToBRep_Reader::TransferRoots (const Standard_Boolean onlyvisible, const Message_ProgressRange& theProgress) { @@ -463,11 +409,8 @@ void IGESToBRep_Reader::TransferRoots (const Standard_Boolean onlyvisible, TF->Send (msg2065, Message_Info); } +//============================================================================= -//======================================================================= -//function : Transfer -//purpose : Transfers an Entity given -//======================================================================= Standard_Boolean IGESToBRep_Reader::Transfer(const Standard_Integer num, const Message_ProgressRange& theProgress) { @@ -494,7 +437,7 @@ Standard_Boolean IGESToBRep_Reader::Transfer(const Standard_Integer num, Message_ProgressScope aPS(theProgress, "OneEnt", 2); - XSAlgo::AlgoContainer()->PrepareForTransfer(); + XSAlgo_ShapeProcessor::PrepareForTransfer(); IGESToBRep_CurveAndSurface CAS; CAS.SetModel(theModel); Standard_Real eps; @@ -544,19 +487,24 @@ Standard_Boolean IGESToBRep_Reader::Transfer(const Standard_Integer num, exceptionRaised = Standard_True; } } - if (!exceptionRaised) { - // fixing shape -// shape = XSAlgo::AlgoContainer()->PerformFixShape ( shape, theProc, eps*CAS.GetUnitFactor(), CAS.GetMaxTol() ); - - Handle(Standard_Transient) info; - shape = XSAlgo::AlgoContainer()->ProcessShape( shape, eps*CAS.GetUnitFactor(), CAS.GetMaxTol(), - "read.iges.resource.name", - "read.iges.sequence", info, - aPS.Next(), false, TopAbs_EDGE); + if (!exceptionRaised) + { + // Set tolerances for shape processing. + // These parameters are calculated inside IGESToBRep_Reader::Transfer() and cannot be set from outside. + XSAlgo_ShapeProcessor::SetParameter("FixShape.Tolerance3d", eps * CAS.GetUnitFactor(), true, myShapeProcParams); + XSAlgo_ShapeProcessor::SetParameter("FixShape.MaxTolerance3d", CAS.GetMaxTol(), true, myShapeProcParams); + + XSAlgo_ShapeProcessor aShapeProcessor(myShapeProcParams); + ShapeProcess::OperationsFlags aFlags; + aFlags.set(ShapeProcess::Operation::FixShape); + shape = aShapeProcessor.ProcessShape(shape, aFlags, aPS.Next()); + if (aPS.UserBreak()) + { return Standard_False; + } - XSAlgo::AlgoContainer()->MergeTransferInfo(theProc, info, nbTPitems); + aShapeProcessor.MergeTransferInfo(theProc, nbTPitems); ShapeExtend_Explorer SBE; if (SBE.ShapeType (shape,Standard_True) != TopAbs_SHAPE) { @@ -589,39 +537,32 @@ Standard_Boolean IGESToBRep_Reader::Transfer(const Standard_Integer num, return Standard_True; } +//============================================================================= -//======================================================================= -//function : UsedTolerance -//purpose : Returns the used tolerance (input) -//======================================================================= - Standard_Real IGESToBRep_Reader::UsedTolerance () const - { return theActor->UsedTolerance(); } +Standard_Real IGESToBRep_Reader::UsedTolerance() const +{ + return theActor->UsedTolerance(); +} -//======================================================================= -//function : NbShapes -//purpose : Returns the count of produced Shapes -//======================================================================= - Standard_Integer IGESToBRep_Reader::NbShapes () const - { return theShapes.Length(); } +//============================================================================= + +Standard_Integer IGESToBRep_Reader::NbShapes() const +{ + return theShapes.Length(); +} +//============================================================================= -//======================================================================= -//function : Shape -//purpose : Returns a Shape given its rank -//======================================================================= - TopoDS_Shape IGESToBRep_Reader::Shape (const Standard_Integer num) const +TopoDS_Shape IGESToBRep_Reader::Shape(const Standard_Integer num) const { TopoDS_Shape res; if (num > 0 && num <= theShapes.Length()) res = theShapes.Value(num); return res; } +//============================================================================= -//======================================================================= -//function : OneShape -//purpose : Returns a unique Shape -//======================================================================= - TopoDS_Shape IGESToBRep_Reader::OneShape () const +TopoDS_Shape IGESToBRep_Reader::OneShape() const { TopoDS_Shape res; Standard_Integer nb = theShapes.Length(); @@ -635,3 +576,42 @@ Standard_Boolean IGESToBRep_Reader::Transfer(const Standard_Integer num, return C; } } + +//============================================================================= + +void IGESToBRep_Reader::SetParameters(const ParameterMap& theParameters) +{ + myShapeProcParams = theParameters; +} + +//============================================================================= + +void IGESToBRep_Reader::SetParameters(ParameterMap&& theParameters) +{ + myShapeProcParams = std::move(theParameters); +} + +//============================================================================= + +void IGESToBRep_Reader::SetParameters(const DE_ShapeFixParameters& theParameters) +{ + XSAlgo_ShapeProcessor::FillParameterMap(theParameters, true, myShapeProcParams); +} + +//============================================================================= + +IGESToBRep_Reader::ParameterMap IGESToBRep_Reader::GetDefaultParams() +{ + static ParameterMap aParams; + if (aParams.empty()) + { + DE_ShapeFixParameters aShapeFixParameters; + aShapeFixParameters.DetalizationLevel = TopAbs_EDGE; + aShapeFixParameters.CreateOpenSolidMode = DE_ShapeFixParameters::FixMode::Fix; + aShapeFixParameters.FixTailMode = DE_ShapeFixParameters::FixMode::FixOrNot; + aShapeFixParameters.MaxTailAngle = DE_ShapeFixParameters::FixMode::FixOrNot; + aShapeFixParameters.MaxTailWidth = DE_ShapeFixParameters::FixMode::FixOrNot; + XSAlgo_ShapeProcessor::FillParameterMap(aShapeFixParameters, false, aParams); + } + return aParams; +} diff --git a/src/IGESToBRep/IGESToBRep_Reader.hxx b/src/IGESToBRep/IGESToBRep_Reader.hxx index f3547eca22..a3922652fb 100644 --- a/src/IGESToBRep/IGESToBRep_Reader.hxx +++ b/src/IGESToBRep/IGESToBRep_Reader.hxx @@ -26,6 +26,9 @@ #include #include +#include + +struct DE_ShapeFixParameters; class IGESData_IGESModel; class IGESToBRep_Actor; class Transfer_TransientProcess; @@ -36,12 +39,13 @@ class TopoDS_Shape; class IGESToBRep_Reader { public: - DEFINE_STANDARD_ALLOC - + using ParameterMap = std::unordered_map; + +public: //! Creates a Reader - Standard_EXPORT IGESToBRep_Reader(); + Standard_EXPORT IGESToBRep_Reader(const ParameterMap& theShapeProcParams = GetDefaultParams()); //! Loads a Model from a file.Returns 0 if success. //! returns 1 if the file could not be opened, @@ -108,26 +112,37 @@ public: //! - a compound containing the resulting shapes if there are several. Standard_EXPORT TopoDS_Shape OneShape() const; + //! Sets parameters for shape processing. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const ParameterMap& theParameters); + //! Sets parameters for shape processing. + //! Parameters are moved from the input map. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(ParameterMap&& theParameters); + //! Sets parameters for shape processing. + //! Parameters from @p theParameters are copied to the internal map. Parameters in the + //! internal map that are not present in @p theParameters are left unchanged. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const DE_ShapeFixParameters& theParameters); -protected: - - - + //! Returns parameters for shape processing that was set by SetParameters() method. + //! @return the parameters for shape processing. Empty map if no parameters were set. + inline const ParameterMap& GetParameters() const { return myShapeProcParams; } + //! Returns the default parameters for shape processing. + //! These parameters are used by default in the constructor. + //! @return the default parameters for shape processing. + Standard_EXPORT static ParameterMap GetDefaultParams(); private: - - - - Handle(IGESData_IGESModel) theModel; - Standard_Boolean theDone; - TopTools_SequenceOfShape theShapes; - Handle(IGESToBRep_Actor) theActor; + Handle(IGESData_IGESModel) theModel; + Standard_Boolean theDone; + TopTools_SequenceOfShape theShapes; + Handle(IGESToBRep_Actor) theActor; Handle(Transfer_TransientProcess) theProc; - - + ParameterMap myShapeProcParams; //!< Parameters for shape processing. }; diff --git a/src/STEPCAFControl/STEPCAFControl_Reader.cxx b/src/STEPCAFControl/STEPCAFControl_Reader.cxx index 2034d02ded..c040311b45 100644 --- a/src/STEPCAFControl/STEPCAFControl_Reader.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Reader.cxx @@ -5368,6 +5368,41 @@ Standard_Boolean STEPCAFControl_Reader::GetViewMode() const return myViewMode; } +//============================================================================= + +void STEPCAFControl_Reader::SetParameters(const ParameterMap& theParameters) +{ + myReader.SetParameters(theParameters); +} + +//============================================================================= + +void STEPCAFControl_Reader::SetParameters(ParameterMap&& theParameters) +{ + myReader.SetParameters(std::move(theParameters)); +} + +//============================================================================= + +void STEPCAFControl_Reader::SetParameters(const DE_ShapeFixParameters& theParameters) +{ + myReader.SetParameters(theParameters); +} + +//============================================================================= + +const STEPCAFControl_Reader::ParameterMap& STEPCAFControl_Reader::GetParameters() const +{ + return myReader.GetParameters(); +} + +//============================================================================= + +STEPCAFControl_Reader::ParameterMap STEPCAFControl_Reader::GetDefaultParams() +{ + return STEPControl_Reader::GetDefaultParams(); +} + //======================================================================= //function : ReadMetadata //purpose : diff --git a/src/STEPCAFControl/STEPCAFControl_Reader.hxx b/src/STEPCAFControl/STEPCAFControl_Reader.hxx index 262c422f40..775b4918fa 100644 --- a/src/STEPCAFControl/STEPCAFControl_Reader.hxx +++ b/src/STEPCAFControl/STEPCAFControl_Reader.hxx @@ -59,10 +59,11 @@ class Transfer_Binder; class STEPCAFControl_Reader { public: - DEFINE_STANDARD_ALLOC - + using ParameterMap = XSControl_Reader::ParameterMap; + +public: //! Creates a reader with an empty //! STEP model and sets ColorMode, LayerMode, NameMode and //! PropsMode to Standard_True. @@ -209,9 +210,31 @@ public: const XCAFDoc_DataMapOfShapeLabel& GetShapeLabelMap() const { return myMap; } -protected: + //! Sets parameters for shape processing. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const ParameterMap& theParameters); - + //! Sets parameters for shape processing. + //! Parameters are moved from the input map. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(ParameterMap&& theParameters); + + //! Sets parameters for shape processing. + //! Parameters from @p theParameters are copied to the internal map. Parameters in the + //! internal map that are not present in @p theParameters are left unchanged. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const DE_ShapeFixParameters& theParameters); + + //! Returns parameters for shape processing that was set by SetParameters() method. + //! @return the parameters for shape processing. Empty map if no parameters were set. + Standard_EXPORT const ParameterMap& GetParameters() const; + + //! Returns the default parameters for shape processing. + //! These parameters are used by default in the constructor. + //! @return the default parameters for shape processing. + Standard_EXPORT static ParameterMap GetDefaultParams(); + +protected: //! Translates STEP file already loaded into the reader //! into the document //! If num==0, translates all roots, else only root number num @@ -319,7 +342,6 @@ protected: Standard_EXPORT virtual TCollection_ExtendedString convertName (const TCollection_AsciiString& theName) const; private: - //! Internal method. Import all Datum attributes and set them to XCAF object. Set connection of Datum to GeomTolerance (theGDTL). Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat, const TDF_Label theGDTL, @@ -361,7 +383,6 @@ private: Handle(TDataStd_NamedData)& theAttr) const; private: - STEPControl_Reader myReader; NCollection_DataMap myFiles; XCAFDoc_DataMapOfShapeLabel myMap; @@ -375,7 +396,6 @@ private: Standard_Boolean myMatMode; Standard_Boolean myViewMode; NCollection_DataMap myGDTMap; - }; #endif // _STEPCAFControl_Reader_HeaderFile diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.cxx b/src/STEPCAFControl/STEPCAFControl_Writer.cxx index d9a716269b..9e54d2e28b 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.cxx @@ -563,6 +563,34 @@ Standard_Boolean STEPCAFControl_Writer::ExternFile(const Standard_CString theNam return Standard_True; } +//============================================================================= + +void STEPCAFControl_Writer::SetParameters(const ParameterMap& theParameters) +{ + myWriter.SetParameters(theParameters); +} + +//============================================================================= + +void STEPCAFControl_Writer::SetParameters(ParameterMap&& theParameters) +{ + myWriter.SetParameters(std::move(theParameters)); +} + +//============================================================================= + +void STEPCAFControl_Writer::SetParameters(const DE_ShapeFixParameters& theParameters) +{ + myWriter.SetParameters(theParameters); +} + +//============================================================================= + +const STEPCAFControl_Writer::ParameterMap& STEPCAFControl_Writer::GetParameters() const +{ + return myWriter.GetParameters(); +} + //======================================================================= //function : Transfer //purpose : diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.hxx b/src/STEPCAFControl/STEPCAFControl_Writer.hxx index ef970c6914..1abc5a85f6 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.hxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.hxx @@ -52,8 +52,9 @@ class STEPCAFControl_Writer public: DEFINE_STANDARD_ALLOC -public: + using ParameterMap = STEPControl_Writer::ParameterMap; +public: //! Creates a writer with an empty //! STEP model and sets ColorMode, LayerMode, NameMode and //! PropsMode to Standard_True. @@ -212,8 +213,26 @@ public: Standard_Boolean GetMaterialMode() const { return myMatMode; } -protected: + //! Sets parameters for shape processing. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const ParameterMap& theParameters); + + //! Sets parameters for shape processing. + //! Parameters are moved from the input map. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(ParameterMap&& theParameters); + //! Sets parameters for shape processing. + //! Parameters from @p theParameters are copied to the internal map. Parameters in the + //! internal map that are not present in @p theParameters are left unchanged. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const DE_ShapeFixParameters& theParameters); + + //! Returns parameters for shape processing that was set by SetParameters() method. + //! @return the parameters for shape processing. Empty map if no parameters were set. + Standard_EXPORT const ParameterMap& GetParameters() const; + +protected: //! Transfers labels to a STEP model //! Returns True if translation is OK //! isExternFile setting from transferExternFiles method diff --git a/src/STEPControl/STEPControl_ActorRead.cxx b/src/STEPControl/STEPControl_ActorRead.cxx index 413b6f4f19..736248f08c 100644 --- a/src/STEPControl/STEPControl_ActorRead.cxx +++ b/src/STEPControl/STEPControl_ActorRead.cxx @@ -119,7 +119,7 @@ #include #include #include -#include +#include #include #include #include @@ -217,6 +217,7 @@ STEPControl_ActorRead::STEPControl_ActorRead(const Handle(Interface_InterfaceMod myMaxTol(0.0), myModel(theModel) { + SetParameters(GetDefaultParams()); } // ============================================================================ @@ -309,7 +310,7 @@ Handle(Transfer_Binder) STEPControl_ActorRead::Transfer Handle(StepData_StepModel) aStepModel = Handle(StepData_StepModel)::DownCast ( TP->Model() ); if (!aStepModel->IsInitializedUnit()) { - XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info + XSAlgo_ShapeProcessor::PrepareForTransfer(); // update unit info aStepModel->SetLocalLengthUnit(UnitsMethods::GetCasCadeLengthUnit()); aLocalFactors.SetCascadeUnit(UnitsMethods::GetCasCadeLengthUnit()); } @@ -809,7 +810,6 @@ Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity( return shbinder; isBound = Standard_False; Standard_Integer nb = sr->NbItems(); - // Used in XSAlgo::AlgoContainer()->ProcessShape (ssv; 13.11.2010) Standard_Integer nbTPitems = TP->NbMapped(); Message_Messenger::StreamBuffer sout = TP->Messenger()->SendInfo(); #ifdef TRANSLOG @@ -930,17 +930,21 @@ Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity( } // [BEGIN] Proceed with non-manifold topology (ssv; 12.11.2010) - if (!isManifold) { + if (!isManifold) + { Message_ProgressScope aPS1 (aPSRoot.Next(), "Process", 1); - Handle(Standard_Transient) info; - // IMPORTANT: any fixing on non-manifold topology must be done after the shape is transferred from STEP - TopoDS_Shape fixedResult = - XSAlgo::AlgoContainer()->ProcessShape( comp, myPrecision, myMaxTol, - "read.step.resource.name", - "read.step.sequence", info, - aPS1.Next(), Standard_True); - XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems); + // Set tolerances for shape processing. + // These parameters are calculated inside STEPControl_ActorRead::Transfer() and cannot be set from outside. + Transfer_ActorOfTransientProcess::ParameterMap aParameters = GetParameters(); + XSAlgo_ShapeProcessor::SetParameter("FixShape.Tolerance3d", myPrecision, true, aParameters); + XSAlgo_ShapeProcessor::SetParameter("FixShape.MaxTolerance3d", myMaxTol, true, aParameters); + XSAlgo_ShapeProcessor::SetParameter("FixShape.NonManifold", std::to_string(true), true, aParameters); + XSAlgo_ShapeProcessor aShapeProcessor(aParameters); + ShapeProcess::OperationsFlags aFlags; + aFlags.set(ShapeProcess::Operation::FixShape); + TopoDS_Shape fixedResult = aShapeProcessor.ProcessShape(comp, aFlags, aPS1.Next()); + aShapeProcessor.MergeTransferInfo(TP, nbTPitems); if (fixedResult.ShapeType() == TopAbs_COMPOUND) { @@ -1552,15 +1556,18 @@ Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity if (found && myShapeBuilder.IsDone()) { mappedShape = myShapeBuilder.Value(); // Apply ShapeFix (on manifold shapes only. Non-manifold topology is processed separately: ssv; 13.11.2010) - if (isManifold && aHasGeom) + if (isManifold && aHasGeom) { - Handle(Standard_Transient) info; - mappedShape = - XSAlgo::AlgoContainer()->ProcessShape( mappedShape, myPrecision, myMaxTol, - "read.step.resource.name", - "read.step.sequence", info, - aPS.Next()); - XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems); + // Set tolerances for shape processing. + // These parameters are calculated inside STEPControl_ActorRead::Transfer() and cannot be set from outside. + Transfer_ActorOfTransientProcess::ParameterMap aParameters = GetParameters(); + XSAlgo_ShapeProcessor::SetParameter("FixShape.Tolerance3d", myPrecision, true, aParameters); + XSAlgo_ShapeProcessor::SetParameter("FixShape.MaxTolerance3d", myMaxTol, true, aParameters); + XSAlgo_ShapeProcessor aShapeProcessor(aParameters); + ShapeProcess::OperationsFlags aFlags; + aFlags.set(ShapeProcess::Operation::FixShape); + mappedShape = aShapeProcessor.ProcessShape(mappedShape, aFlags, aPS.Next()); + aShapeProcessor.MergeTransferInfo(TP, nbTPitems); } } found = !mappedShape.IsNull(); @@ -1723,19 +1730,25 @@ Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity // Apply ShapeFix Handle(Transfer_Binder) binder = TP->Find(fs); sb = Handle(TransferBRep_ShapeBinder)::DownCast(binder); - if (!sb.IsNull() && !sb->Result().IsNull()) { + if (!sb.IsNull() && !sb->Result().IsNull()) + { TopoDS_Shape S = sb->Result(); - Handle(Standard_Transient) info; - TopoDS_Shape shape = XSAlgo::AlgoContainer()->ProcessShape(S, myPrecision, myMaxTol, - "read.step.resource.name", - "read.step.sequence", info, - theProgress); - // TopoDS_Shape shape = XSAlgo::AlgoContainer()->PerformFixShape( S, TP, myPrecision, myMaxTol ); + Transfer_ActorOfTransientProcess::ParameterMap aParameters = GetParameters(); + XSAlgo_ShapeProcessor::SetParameter("FixShape.Tolerance3d", myPrecision, true, aParameters); + XSAlgo_ShapeProcessor::SetParameter("FixShape.MaxTolerance3d", myMaxTol, true, aParameters); + XSAlgo_ShapeProcessor aShapeProcessor(aParameters); + ShapeProcess::OperationsFlags aFlags; + aFlags.set(ShapeProcess::Operation::FixShape); + TopoDS_Shape shape = aShapeProcessor.ProcessShape(S, aFlags, theProgress); + aShapeProcessor.MergeTransferInfo(TP, nbTPitems); + if (shape != S) + { sb->SetResult(shape); + } - XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems); + aShapeProcessor.MergeTransferInfo(TP, nbTPitems); } @@ -2055,6 +2068,20 @@ Standard_Boolean STEPControl_ActorRead::ComputeSRRWT (const Handle(StepRepr_Repr return ComputeTransformation ( Ax1, Ax2, SRR->Rep1(), SRR->Rep2(), TP, Trsf, aLocalFactors); } +//============================================================================= + +Transfer_ActorOfTransientProcess::ParameterMap STEPControl_ActorRead::GetDefaultParams() +{ + static ParameterMap aParams; + if (aParams.empty()) + { + DE_ShapeFixParameters aShapeFixParameters; + aShapeFixParameters.DetalizationLevel = TopAbs_VERTEX; + XSAlgo_ShapeProcessor::FillParameterMap(aShapeFixParameters, false, aParams); + } + return aParams; +} + //======================================================================= // Method : closeIDEASShell // Purpose : Attempts to close the passed Shell with the passed closing diff --git a/src/STEPControl/STEPControl_ActorRead.hxx b/src/STEPControl/STEPControl_ActorRead.hxx index d6e4723187..7715ffe64b 100644 --- a/src/STEPControl/STEPControl_ActorRead.hxx +++ b/src/STEPControl/STEPControl_ActorRead.hxx @@ -64,7 +64,6 @@ class STEPControl_ActorRead : public Transfer_ActorOfTransientProcess { public: - Standard_EXPORT STEPControl_ActorRead(const Handle(Interface_InterfaceModel)& theModel); Standard_EXPORT virtual Standard_Boolean Recognize (const Handle(Standard_Transient)& start) Standard_OVERRIDE; @@ -115,14 +114,15 @@ public: gp_Trsf& Trsf, const StepData_Factors& theLocalFactors = StepData_Factors()); - + //! Returns the default parameters for shape processing. + //! These parameters are used by default in the constructor. + //! @return the default parameters for shape processing. + Standard_EXPORT static ParameterMap GetDefaultParams(); DEFINE_STANDARD_RTTIEXT(STEPControl_ActorRead,Transfer_ActorOfTransientProcess) protected: - - //! Transfers product definition entity //! theUseTrsf - special flag for using Axis2Placement from ShapeRepresentation for transform root shape Standard_EXPORT Handle(TransferBRep_ShapeBinder) TransferEntity ( @@ -204,11 +204,7 @@ protected: const Handle(Transfer_TransientProcess)& TP, const Message_ProgressRange& theProgress); - - private: - - Standard_EXPORT TopoDS_Shell closeIDEASShell (const TopoDS_Shell& shell, const TopTools_ListOfShape& closingShells); Standard_EXPORT void computeIDEASClosings (const TopoDS_Compound& comp, TopTools_IndexedDataMapOfShapeListOfShape& shellClosingMap); @@ -221,18 +217,12 @@ private: TopoDS_Compound& theCund, Message_ProgressScope& thePS); +private: StepToTopoDS_NMTool myNMTool; Standard_Real myPrecision; Standard_Real myMaxTol; Handle(StepRepr_Representation) mySRContext; Handle(Interface_InterfaceModel) myModel; - }; - - - - - - #endif // _STEPControl_ActorRead_HeaderFile diff --git a/src/STEPControl/STEPControl_ActorWrite.cxx b/src/STEPControl/STEPControl_ActorWrite.cxx index f3256d0146..98736aef66 100644 --- a/src/STEPControl/STEPControl_ActorWrite.cxx +++ b/src/STEPControl/STEPControl_ActorWrite.cxx @@ -94,7 +94,7 @@ #include #include #include -#include +#include IMPLEMENT_STANDARD_RTTIEXT(STEPControl_ActorWrite,Transfer_ActorOfFinderProcess) @@ -273,6 +273,7 @@ STEPControl_ActorWrite::STEPControl_ActorWrite () : mygroup (0) , mytoler (-1.) { SetMode(STEPControl_ShellBasedSurfaceModel); + SetParameters(GetDefaultParams()); } //======================================================================= @@ -540,7 +541,7 @@ Handle(Transfer_Binder) STEPControl_ActorWrite::Transfer (const Handle(Transfer_ myContext.SetLevel ( 1 ); // set assembly level to 1 (to ensure) if (!model->IsInitializedUnit()) { - XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info + XSAlgo_ShapeProcessor::PrepareForTransfer(); // update unit info model->SetLocalLengthUnit(UnitsMethods::GetCasCadeLengthUnit()); } Standard_Real aLFactor = model->WriteLengthUnit(); @@ -634,32 +635,19 @@ Standard_Boolean STEPControl_ActorWrite::IsAssembly (const Handle(StepData_StepM return IsAssembly ( theModel, S ); } -//======================================================================= -//function : TransferShape -//purpose : -//======================================================================= +//============================================================================= -/* -static void UpdateMap (const TopoDS_Shape &shape, - BRepTools_Modifier &M1, - BRepTools_Modifier &M2, - const Handle(Transfer_FinderProcess) &FinderProcess) +Transfer_ActorOfFinderProcess::ParameterMap STEPControl_ActorWrite::GetDefaultParams() { - TopoDS_Shape S = M1.ModifiedShape ( shape ); - S = M2.ModifiedShape ( S ); - if ( S == shape ) return; - - Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FinderProcess, S ); - Handle(Transfer_Binder) binder = FinderProcess->Find ( mapper ); - if ( ! binder.IsNull() ) { - mapper = TransferBRep::ShapeMapper ( FinderProcess, shape ); - FinderProcess->Bind ( mapper, binder ); + static ParameterMap aParams; + if (aParams.empty()) + { + DE_ShapeFixParameters aShapeFixParameters; + aShapeFixParameters.DetalizationLevel = TopAbs_VERTEX; + XSAlgo_ShapeProcessor::FillParameterMap(aShapeFixParameters, false, aParams); } - - for ( TopoDS_Iterator it(shape); it.More(); it.Next() ) - UpdateMap ( it.Value(), M1, M2, FinderProcess ); + return aParams; } -*/ // PTV 16.09.2002 added for transferring vertices. static Standard_Boolean transferVertex (const Handle(Transfer_FinderProcess)& FP, @@ -984,37 +972,35 @@ Handle(Transfer_Binder) STEPControl_ActorWrite::TransferShape default : trmode =STEPControl_GeometricCurveSet; break; } } - //:abv 24Jan99 CAX-IF TRJ3: expanded Shape Processing -// TopoDS_Shape aShape = xShape; - // eliminate conical surfaces with negative semiangles -// Handle(TopoDSToStep_ConicalSurfModif) CSM = new TopoDSToStep_ConicalSurfModif(); -// BRepTools_Modifier CSMT(aShape,CSM); -// if ( CSMT.IsDone() ) aShape = CSMT.ModifiedShape ( aShape ); -// // eliminate indirect elementary surfaces -// Handle(TopoDSToStep_DirectModification) DM = new TopoDSToStep_DirectModification(); -// BRepTools_Modifier DMT(aShape,DM); -// if ( DMT.IsDone() ) aShape = DMT.ModifiedShape ( aShape ); -//// aShape = TopoDSToStep::DirectFaces(xShape); + Message_ProgressScope aPS1(aPS.Next(), NULL, 2); TopoDS_Shape aShape = xShape; - Handle(Standard_Transient) info; - if (hasGeometry(aShape)) + Transfer_ActorOfFinderProcess::ParameterMap aParameters = GetParameters(); + XSAlgo_ShapeProcessor::SetParameter("FixShape.Tolerance3d", Tol, true, aParameters); + XSAlgo_ShapeProcessor::SetParameter("FixShape.MaxTolerance3d", + aStepModel->InternalParameters.ReadMaxPrecisionVal, + true, + aParameters); + XSAlgo_ShapeProcessor aShapeProcessor(aParameters); + + if (hasGeometry(aShape)) { - Standard_Real maxTol = aStepModel->InternalParameters.ReadMaxPrecisionVal; + ShapeProcess::OperationsFlags aFlags; + aFlags.set(ShapeProcess::Operation::SplitCommonVertex); + aFlags.set(ShapeProcess::Operation::DirectFaces); + aShape = aShapeProcessor.ProcessShape(xShape, aFlags, aPS1.Next()); - aShape = XSAlgo::AlgoContainer()->ProcessShape(xShape, Tol, maxTol, - "write.step.resource.name", - "write.step.sequence", info, - aPS1.Next()); if (aPS1.UserBreak()) + { return Handle(Transfer_Binder)(); + } } if (!isManifold) { - mergeInfoForNM(FP, info); + mergeInfoForNM(FP, aShapeProcessor.GetContext()); } // create a STEP entity corresponding to shape @@ -1248,10 +1234,8 @@ Handle(Transfer_Binder) STEPControl_ActorWrite::TransferShape subbind->AddResult(TransientResult(itemTess)); } - //:abv 24Jan99 CAX-IF TRJ3: Update FinderProcess map to take into account shape processing -// UpdateMap ( xShape, CSMT, DMT, FP ); - if (!info.IsNull()) - XSAlgo::AlgoContainer()->MergeTransferInfo(FP, info); + // If shape is not processed, this function does nothing. Intentionally. + aShapeProcessor.MergeTransferInfo(FP); } // - Make Shape Representation diff --git a/src/STEPControl/STEPControl_ActorWrite.hxx b/src/STEPControl/STEPControl_ActorWrite.hxx index bb75947ff2..5d33d4ee2a 100644 --- a/src/STEPControl/STEPControl_ActorWrite.hxx +++ b/src/STEPControl/STEPControl_ActorWrite.hxx @@ -43,8 +43,6 @@ class STEPControl_ActorWrite : public Transfer_ActorOfFinderProcess { public: - - Standard_EXPORT STEPControl_ActorWrite(); Standard_EXPORT virtual Standard_Boolean Recognize (const Handle(Transfer_Finder)& start) Standard_OVERRIDE; @@ -98,19 +96,14 @@ public: Standard_EXPORT virtual Standard_Boolean IsAssembly (const Handle(StepData_StepModel)& theModel, TopoDS_Shape& S) const; - - + //! Returns the default parameters for shape processing. + //! These parameters are used by default in the constructor. + //! @return the default parameters for shape processing. + Standard_EXPORT static Transfer_ActorOfFinderProcess::ParameterMap GetDefaultParams(); DEFINE_STANDARD_RTTIEXT(STEPControl_ActorWrite,Transfer_ActorOfFinderProcess) -protected: - - - - private: - - //! Non-manifold shapes are stored in NMSSR group //! (NON_MANIFOLD_SURFACE_SHAPE_REPRESENTATION). //! Use this method to get the corresponding NMSSR (or @@ -128,8 +121,7 @@ private: Standard_Boolean separateShapeToSoloVertex(const TopoDS_Shape& theShape, TopTools_SequenceOfShape& theVertices); - - +private: Standard_Integer mygroup; Standard_Real mytoler; STEPConstruct_ContextTool myContext; diff --git a/src/STEPControl/STEPControl_Reader.cxx b/src/STEPControl/STEPControl_Reader.cxx index a35346360d..df1ef2a34c 100644 --- a/src/STEPControl/STEPControl_Reader.cxx +++ b/src/STEPControl/STEPControl_Reader.cxx @@ -11,7 +11,7 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. - +#include #include #include #include @@ -60,6 +60,7 @@ #include #include #include +#include #include #include @@ -71,6 +72,7 @@ STEPControl_Reader::STEPControl_Reader () { STEPControl_Controller::Init(); SetNorm ("STEP"); + SetParameters(GetDefaultParams()); } //======================================================================= @@ -83,7 +85,8 @@ STEPControl_Reader::STEPControl_Reader { STEPControl_Controller::Init(); SetWS (WS,scratch); - SetNorm ("STEP"); + SetNorm("STEP"); + SetParameters(GetDefaultParams()); } //======================================================================= @@ -651,6 +654,20 @@ inline static TCollection_AsciiString getSiName(const Handle(StepBasic_SiUnit)& return aName; } +//============================================================================= + +XSControl_Reader::ParameterMap STEPControl_Reader::GetDefaultParams() +{ + static ParameterMap aParams; + if (aParams.empty()) + { + DE_ShapeFixParameters aShapeFixParameters; + aShapeFixParameters.DetalizationLevel = TopAbs_VERTEX; + XSAlgo_ShapeProcessor::FillParameterMap(aShapeFixParameters, false, aParams); + } + return aParams; +} + //======================================================================= //function : findUnits //purpose : diff --git a/src/STEPControl/STEPControl_Reader.hxx b/src/STEPControl/STEPControl_Reader.hxx index 86550b9737..7208f9db28 100644 --- a/src/STEPControl/STEPControl_Reader.hxx +++ b/src/STEPControl/STEPControl_Reader.hxx @@ -126,22 +126,14 @@ public: //! Performs only if a model is not NULL Standard_EXPORT Standard_Real SystemLengthUnit() const; - -protected: - - - - + //! Returns the default parameters for shape processing. + //! These parameters are used by default in the constructor. + //! @return the default parameters for shape processing. + Standard_EXPORT static ParameterMap GetDefaultParams(); private: - - //! Returns units for length , angle and solidangle for shape representations Standard_EXPORT Standard_Boolean findUnits (const Handle(StepRepr_RepresentationContext)& theReprContext, TColStd_Array1OfAsciiString& theNameUnits, TColStd_Array1OfReal& theFactorUnits); - - - - }; diff --git a/src/STEPControl/STEPControl_Writer.cxx b/src/STEPControl/STEPControl_Writer.cxx index e16cb584c3..af726f5599 100644 --- a/src/STEPControl/STEPControl_Writer.cxx +++ b/src/STEPControl/STEPControl_Writer.cxx @@ -215,3 +215,71 @@ void STEPControl_Writer::PrintStatsTransfer { thesession->TransferWriter()->PrintStats (what,mode); } +//============================================================================= + +void STEPControl_Writer::SetParameters(const ParameterMap& theParameters) +{ + if (Handle(Transfer_ActorOfFinderProcess) anActor = GetActor()) + { + anActor->SetParameters(theParameters); + } +} + +//============================================================================= + +void STEPControl_Writer::SetParameters(ParameterMap&& theParameters) +{ + if (Handle(Transfer_ActorOfFinderProcess) anActor = GetActor()) + { + anActor->SetParameters(std::move(theParameters)); + } +} + +//============================================================================= + +void STEPControl_Writer::SetParameters(const DE_ShapeFixParameters& theParameters) +{ + if (Handle(Transfer_ActorOfFinderProcess) anActor = GetActor()) + { + anActor->SetParameters(theParameters); + } +} + +//============================================================================= + +const STEPControl_Writer::ParameterMap& STEPControl_Writer::GetParameters() const +{ + static const ParameterMap anEmptyMap; + const Handle(Transfer_ActorOfFinderProcess) anActor = GetActor(); + return anActor.IsNull() ? anEmptyMap : anActor->GetParameters(); +} + +//============================================================================= + +Handle(Transfer_ActorOfFinderProcess) STEPControl_Writer::GetActor() const +{ + Handle(XSControl_WorkSession) aSession = WS(); + if (aSession.IsNull()) + { + return nullptr; + } + Handle(XSControl_TransferWriter) aTransferWriter = aSession->TransferWriter(); + if (aTransferWriter.IsNull()) + { + return nullptr; + } + + Handle(Transfer_FinderProcess) aTransferFinderProcess = aTransferWriter->FinderProcess(); + if (aTransferFinderProcess.IsNull()) + { + return nullptr; + } + + Handle(Transfer_ActorOfProcessForFinder) anActor = aTransferFinderProcess->Actor(); + if (anActor.IsNull()) + { + return nullptr; + } + + return Handle(Transfer_ActorOfFinderProcess)::DownCast(anActor); +} diff --git a/src/STEPControl/STEPControl_Writer.hxx b/src/STEPControl/STEPControl_Writer.hxx index 312a6fb0fc..5574164952 100644 --- a/src/STEPControl/STEPControl_Writer.hxx +++ b/src/STEPControl/STEPControl_Writer.hxx @@ -20,7 +20,6 @@ #include #include #include - #include #include #include @@ -28,10 +27,13 @@ #include #include +#include + +struct DE_ShapeFixParameters; class XSControl_WorkSession; class StepData_StepModel; class TopoDS_Shape; - +class Transfer_ActorOfFinderProcess; //! This class creates and writes //! STEP files from Open CASCADE models. A STEP file can be @@ -41,9 +43,9 @@ class TopoDS_Shape; class STEPControl_Writer { public: - DEFINE_STANDARD_ALLOC + using ParameterMap = std::unordered_map; //! Creates a Writer from scratch Standard_EXPORT STEPControl_Writer(); @@ -126,28 +128,33 @@ public: //! AND the list of entity numbers in the STEP model. Standard_EXPORT void PrintStatsTransfer (const Standard_Integer what, const Standard_Integer mode = 0) const; + //! Sets parameters for shape processing. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const ParameterMap& theParameters); + //! Sets parameters for shape processing. + //! Parameters are moved from the input map. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(ParameterMap&& theParameters); + //! Sets parameters for shape processing. + //! Parameters from @p theParameters are copied to the internal map. Parameters in the + //! internal map that are not present in @p theParameters are left unchanged. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const DE_ShapeFixParameters& theParameters); -protected: - - - - + //! Returns parameters for shape processing that was set by SetParameters() method. + //! @return the parameters for shape processing. Empty map if no parameters were set. + Standard_EXPORT const ParameterMap& GetParameters() const; private: + //! Returns the Actor for the Transfer of an Entity. + //! This Actor is used by the Writer to perform the Transfer. + //! @return the Actor for the Transfer of an Entity. May be nullptr. + Handle(Transfer_ActorOfFinderProcess) GetActor() const; - - +private: Handle(XSControl_WorkSession) thesession; - - }; - - - - - - #endif // _STEPControl_Writer_HeaderFile diff --git a/src/Transfer/Transfer_ActorOfFinderProcess.cxx b/src/Transfer/Transfer_ActorOfFinderProcess.cxx index a5019409bd..085c6df5b0 100644 --- a/src/Transfer/Transfer_ActorOfFinderProcess.cxx +++ b/src/Transfer/Transfer_ActorOfFinderProcess.cxx @@ -20,14 +20,21 @@ #include #include #include +#include IMPLEMENT_STANDARD_RTTIEXT(Transfer_ActorOfFinderProcess,Transfer_ActorOfProcessForFinder) +//============================================================================= + Transfer_ActorOfFinderProcess::Transfer_ActorOfFinderProcess () { themodetrans = 0; } +//============================================================================= + Standard_Integer& Transfer_ActorOfFinderProcess::ModeTrans () { return themodetrans; } +//============================================================================= + Handle(Transfer_Binder) Transfer_ActorOfFinderProcess::Transfer (const Handle(Transfer_Finder)& fnd, const Handle(Transfer_FinderProcess)& FP, @@ -40,6 +47,8 @@ Handle(Transfer_Binder) Transfer_ActorOfFinderProcess::Transfer return TransientResult (res); } +//============================================================================= + Handle(Transfer_Binder) Transfer_ActorOfFinderProcess::Transferring (const Handle(Transfer_Finder)& ent, const Handle(Transfer_ProcessForFinder)& TP, @@ -48,6 +57,8 @@ Handle(Transfer_Binder) Transfer_ActorOfFinderProcess::Transferring return Transfer(ent,Handle(Transfer_FinderProcess)::DownCast(TP), theProgress); } +//============================================================================= + Handle(Standard_Transient) Transfer_ActorOfFinderProcess::TransferTransient (const Handle(Standard_Transient)& /*ent*/, const Handle(Transfer_FinderProcess)&, @@ -56,3 +67,24 @@ Handle(Standard_Transient) Transfer_ActorOfFinderProcess::TransferTransient Handle(Standard_Transient) nulres; return nulres; } + +//============================================================================= + +void Transfer_ActorOfFinderProcess::SetParameters(const ParameterMap& theParameters) +{ + myShapeProcParams = theParameters; +} + +//============================================================================= + +void Transfer_ActorOfFinderProcess::SetParameters(ParameterMap&& theParameters) +{ + myShapeProcParams = std::move(theParameters); +} + +//============================================================================= + +void Transfer_ActorOfFinderProcess::SetParameters(const DE_ShapeFixParameters& theParameters) +{ + XSAlgo_ShapeProcessor::FillParameterMap(theParameters, true, myShapeProcParams); +} diff --git a/src/Transfer/Transfer_ActorOfFinderProcess.hxx b/src/Transfer/Transfer_ActorOfFinderProcess.hxx index 0170e7d20c..f3fcd33e7e 100644 --- a/src/Transfer/Transfer_ActorOfFinderProcess.hxx +++ b/src/Transfer/Transfer_ActorOfFinderProcess.hxx @@ -18,8 +18,11 @@ #define _Transfer_ActorOfFinderProcess_HeaderFile #include - #include + +#include + +struct DE_ShapeFixParameters; class Transfer_Binder; class Transfer_Finder; class Transfer_ProcessForFinder; @@ -36,10 +39,10 @@ DEFINE_STANDARD_HANDLE(Transfer_ActorOfFinderProcess, Transfer_ActorOfProcessFor //! a user. To be interpreted for each norm class Transfer_ActorOfFinderProcess : public Transfer_ActorOfProcessForFinder { - public: + using ParameterMap = std::unordered_map; - +public: Standard_EXPORT Transfer_ActorOfFinderProcess(); //! Returns the Transfer Mode, modifiable @@ -60,22 +63,32 @@ public: const Handle(Transfer_FinderProcess)& TP, const Message_ProgressRange& theProgress = Message_ProgressRange()); + //! Sets parameters for shape processing. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const ParameterMap& theParameters); + + //! Sets parameters for shape processing. + //! Parameters are moved from the input map. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(ParameterMap&& theParameters); + //! Sets parameters for shape processing. + //! Parameters from @p theParameters are copied to the internal map. Parameters in the + //! internal map that are not present in @p theParameters are left unchanged. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const DE_ShapeFixParameters& theParameters); + //! Returns parameters for shape processing that was set by SetParameters() method. + //! @return the parameters for shape processing. Empty map if no parameters were set. + inline const ParameterMap& GetParameters() const { return myShapeProcParams; } DEFINE_STANDARD_RTTIEXT(Transfer_ActorOfFinderProcess,Transfer_ActorOfProcessForFinder) protected: - - Standard_Integer themodetrans; - private: - - - - + ParameterMap myShapeProcParams; //!< Parameters for shape processing. }; diff --git a/src/Transfer/Transfer_ActorOfTransientProcess.cxx b/src/Transfer/Transfer_ActorOfTransientProcess.cxx index f339a1f4d3..3e4e408d01 100644 --- a/src/Transfer/Transfer_ActorOfTransientProcess.cxx +++ b/src/Transfer/Transfer_ActorOfTransientProcess.cxx @@ -17,10 +17,14 @@ #include #include #include +#include IMPLEMENT_STANDARD_RTTIEXT(Transfer_ActorOfTransientProcess,Transfer_ActorOfProcessForTransient) -Transfer_ActorOfTransientProcess::Transfer_ActorOfTransientProcess () { } +Transfer_ActorOfTransientProcess::Transfer_ActorOfTransientProcess() +{} + +//============================================================================= Handle(Transfer_Binder) Transfer_ActorOfTransientProcess::Transfer (const Handle(Standard_Transient)& start, @@ -32,6 +36,8 @@ Handle(Transfer_Binder) Transfer_ActorOfTransientProcess::Transfer return TransientResult (res); } +//============================================================================= + Handle(Transfer_Binder) Transfer_ActorOfTransientProcess::Transferring (const Handle(Standard_Transient)& ent, const Handle(Transfer_ProcessForTransient)& TP, @@ -40,6 +46,8 @@ Handle(Transfer_Binder) Transfer_ActorOfTransientProcess::Transferring return Transfer(ent,Handle(Transfer_TransientProcess)::DownCast(TP), theProgress); } +//============================================================================= + Handle(Standard_Transient) Transfer_ActorOfTransientProcess::TransferTransient (const Handle(Standard_Transient)& /*ent*/, const Handle(Transfer_TransientProcess)& /*TP*/, @@ -48,3 +56,24 @@ Handle(Standard_Transient) Transfer_ActorOfTransientProcess::TransferTransient Handle(Standard_Transient) nulres; return nulres; } + +//============================================================================= + +void Transfer_ActorOfTransientProcess::SetParameters(const ParameterMap& theParameters) +{ + myShapeProcParams = theParameters; +} + +//============================================================================= + +void Transfer_ActorOfTransientProcess::SetParameters(ParameterMap&& theParameters) +{ + myShapeProcParams = std::move(theParameters); +} + +//============================================================================= + +void Transfer_ActorOfTransientProcess::SetParameters(const DE_ShapeFixParameters& theParameters) +{ + XSAlgo_ShapeProcessor::FillParameterMap(theParameters, true, myShapeProcParams); +} diff --git a/src/Transfer/Transfer_ActorOfTransientProcess.hxx b/src/Transfer/Transfer_ActorOfTransientProcess.hxx index 0f3fd6c44e..ac4e4e0ccd 100644 --- a/src/Transfer/Transfer_ActorOfTransientProcess.hxx +++ b/src/Transfer/Transfer_ActorOfTransientProcess.hxx @@ -18,8 +18,11 @@ #define _Transfer_ActorOfTransientProcess_HeaderFile #include - #include + +#include + +struct DE_ShapeFixParameters; class Transfer_Binder; class Standard_Transient; class Transfer_ProcessForTransient; @@ -31,10 +34,10 @@ DEFINE_STANDARD_HANDLE(Transfer_ActorOfTransientProcess, Transfer_ActorOfProcess //! The original class was renamed. Compatibility only class Transfer_ActorOfTransientProcess : public Transfer_ActorOfProcessForTransient { - public: + using ParameterMap = std::unordered_map; - +public: Standard_EXPORT Transfer_ActorOfTransientProcess(); Standard_EXPORT virtual Handle(Transfer_Binder) Transferring @@ -52,27 +55,29 @@ public: const Handle(Transfer_TransientProcess)& TP, const Message_ProgressRange& theProgress = Message_ProgressRange()); + //! Sets parameters for shape processing. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const ParameterMap& theParameters); + //! Sets parameters for shape processing. + //! Parameters are moved from the input map. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(ParameterMap&& theParameters); + //! Sets parameters for shape processing. + //! Parameters from @p theParameters are copied to the internal map. Parameters in the + //! internal map that are not present in @p theParameters are left unchanged. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const DE_ShapeFixParameters& theParameters); - DEFINE_STANDARD_RTTIEXT(Transfer_ActorOfTransientProcess,Transfer_ActorOfProcessForTransient) - -protected: - - + //! Returns parameters for shape processing that was set by SetParameters() method. + //! @return the parameters for shape processing. Empty map if no parameters were set. + inline const ParameterMap& GetParameters() const { return myShapeProcParams; } + DEFINE_STANDARD_RTTIEXT(Transfer_ActorOfTransientProcess,Transfer_ActorOfProcessForTransient) private: - - - - + ParameterMap myShapeProcParams; //!< Parameters for shape processing. }; - - - - - - #endif // _Transfer_ActorOfTransientProcess_HeaderFile diff --git a/src/XSAlgo/XSAlgo_ShapeProcessor.cxx b/src/XSAlgo/XSAlgo_ShapeProcessor.cxx index a24c8afdaf..818832f2b6 100644 --- a/src/XSAlgo/XSAlgo_ShapeProcessor.cxx +++ b/src/XSAlgo/XSAlgo_ShapeProcessor.cxx @@ -42,7 +42,7 @@ XSAlgo_ShapeProcessor::XSAlgo_ShapeProcessor(const ParameterMap& thePar const DE_ShapeFixParameters& theShapeFixParameters) : myParameters(theParameters) { - FillParameterMap(theShapeFixParameters, myParameters); + FillParameterMap(theShapeFixParameters, false, myParameters); } //============================================================================= @@ -50,7 +50,7 @@ XSAlgo_ShapeProcessor::XSAlgo_ShapeProcessor(const ParameterMap& thePar XSAlgo_ShapeProcessor::XSAlgo_ShapeProcessor(const DE_ShapeFixParameters& theParameters) { ParameterMap aMap; - FillParameterMap(theParameters, aMap); + FillParameterMap(theParameters, false, aMap); myParameters = aMap; } @@ -441,68 +441,108 @@ Standard_Boolean XSAlgo_ShapeProcessor::CheckPCurve(const TopoDS_Edge& theEd //============================================================================= void XSAlgo_ShapeProcessor::FillParameterMap(const DE_ShapeFixParameters& theParameters, + const bool theIsReplace, XSAlgo_ShapeProcessor::ParameterMap& theMap) { - // Helper lambda to convert enum to string. - auto makeString = [](const DE_ShapeFixParameters::FixMode theMode) + SetParameter("FixShape.Tolerance3d", theParameters.Tolerance3d, theIsReplace, theMap); + SetParameter("FixShape.MaxTolerance3d", theParameters.MaxTolerance3d, theIsReplace, theMap); + SetParameter("FixShape.MinTolerance3d", theParameters.MinTolerance3d, theIsReplace, theMap); + SetParameter("DetalizationLevel", std::to_string(theParameters.DetalizationLevel), theIsReplace, theMap); + SetParameter("NonManifold", std::to_string(theParameters.NonManifold), theIsReplace, theMap); + SetParameter("FixShape.FixFreeShellMode", theParameters.FixFreeShellMode, theIsReplace, theMap); + SetParameter("FixShape.FixFreeFaceMode", theParameters.FixFreeFaceMode, theIsReplace, theMap); + SetParameter("FixShape.FixFreeWireMode", theParameters.FixFreeWireMode, theIsReplace, theMap); + SetParameter("FixShape.FixSameParameterMode", theParameters.FixSameParameterMode, theIsReplace, theMap); + SetParameter("FixShape.FixSolidMode", theParameters.FixSolidMode, theIsReplace, theMap); + SetParameter("FixShape.FixShellOrientationMode", theParameters.FixShellOrientationMode, theIsReplace, theMap); + SetParameter("FixShape.CreateOpenSolidMode", theParameters.CreateOpenSolidMode, theIsReplace, theMap); + SetParameter("FixShape.FixShellMode", theParameters.FixShellMode, theIsReplace, theMap); + SetParameter("FixShape.FixFaceOrientationMode", theParameters.FixFaceOrientationMode, theIsReplace, theMap); + SetParameter("FixShape.FixFaceMode", theParameters.FixFaceMode, theIsReplace, theMap); + SetParameter("FixShape.FixWireMode", theParameters.FixWireMode, theIsReplace, theMap); + SetParameter("FixShape.FixOrientationMode", theParameters.FixOrientationMode, theIsReplace, theMap); + SetParameter("FixShape.FixAddNaturalBoundMode", theParameters.FixAddNaturalBoundMode, theIsReplace, theMap); + SetParameter("FixShape.FixMissingSeamMode", theParameters.FixMissingSeamMode, theIsReplace, theMap); + SetParameter("FixShape.FixSmallAreaWireMode", theParameters.FixSmallAreaWireMode, theIsReplace, theMap); + SetParameter("FixShape.RemoveSmallAreaFaceMode", theParameters.RemoveSmallAreaFaceMode, theIsReplace, theMap); + SetParameter("FixShape.FixIntersectingWiresMode", theParameters.FixIntersectingWiresMode, theIsReplace, theMap); + SetParameter("FixShape.FixLoopWiresMode", theParameters.FixLoopWiresMode, theIsReplace, theMap); + SetParameter("FixShape.FixSplitFaceMode", theParameters.FixSplitFaceMode, theIsReplace, theMap); + SetParameter("FixShape.AutoCorrectPrecisionMode", theParameters.AutoCorrectPrecisionMode, theIsReplace, theMap); + SetParameter("FixShape.ModifyTopologyMode", theParameters.ModifyTopologyMode, theIsReplace, theMap); + SetParameter("FixShape.ModifyGeometryMode", theParameters.ModifyGeometryMode, theIsReplace, theMap); + SetParameter("FixShape.ClosedWireMode", theParameters.ClosedWireMode, theIsReplace, theMap); + SetParameter("FixShape.PreferencePCurveMode", theParameters.PreferencePCurveMode, theIsReplace, theMap); + SetParameter("FixShape.FixReorderMode", theParameters.FixReorderMode, theIsReplace, theMap); + SetParameter("FixShape.FixSmallMode", theParameters.FixSmallMode, theIsReplace, theMap); + SetParameter("FixShape.FixConnectedMode", theParameters.FixConnectedMode, theIsReplace, theMap); + SetParameter("FixShape.FixEdgeCurvesMode", theParameters.FixEdgeCurvesMode, theIsReplace, theMap); + SetParameter("FixShape.FixDegeneratedMode", theParameters.FixDegeneratedMode, theIsReplace, theMap); + SetParameter("FixShape.FixLackingMode", theParameters.FixLackingMode, theIsReplace, theMap); + SetParameter("FixShape.FixSelfIntersectionMode", theParameters.FixSelfIntersectionMode, theIsReplace, theMap); + SetParameter("FixShape.RemoveLoopMode", theParameters.RemoveLoopMode, theIsReplace, theMap); + SetParameter("FixShape.FixReversed2dMode", theParameters.FixReversed2dMode, theIsReplace, theMap); + SetParameter("FixShape.FixRemovePCurveMode", theParameters.FixRemovePCurveMode, theIsReplace, theMap); + SetParameter("FixShape.FixRemoveCurve3dMode", theParameters.FixRemoveCurve3dMode, theIsReplace, theMap); + SetParameter("FixShape.FixAddPCurveMode", theParameters.FixAddPCurveMode, theIsReplace, theMap); + SetParameter("FixShape.FixAddCurve3dMode", theParameters.FixAddCurve3dMode, theIsReplace, theMap); + SetParameter("FixShape.FixSeamMode", theParameters.FixSeamMode, theIsReplace, theMap); + SetParameter("FixShape.FixShiftedMode", theParameters.FixShiftedMode, theIsReplace, theMap); + SetParameter("FixShape.FixEdgeSameParameterMode", theParameters.FixEdgeSameParameterMode, theIsReplace, theMap); + SetParameter("FixShape.FixNotchedEdgesMode", theParameters.FixNotchedEdgesMode, theIsReplace, theMap); + SetParameter("FixShape.FixTailMode", theParameters.FixTailMode, theIsReplace, theMap); + SetParameter("FixShape.MaxTailAngle", theParameters.MaxTailAngle, theIsReplace, theMap); + SetParameter("FixShape.MaxTailWidth", theParameters.MaxTailWidth, theIsReplace, theMap); + SetParameter("FixShape.FixSelfIntersectingEdgeMode", theParameters.FixSelfIntersectingEdgeMode, theIsReplace, theMap); + SetParameter("FixShape.FixIntersectingEdgesMode", theParameters.FixIntersectingEdgesMode, theIsReplace, theMap); + SetParameter("FixShape.FixNonAdjacentIntersectingEdgesMode", + theParameters.FixNonAdjacentIntersectingEdgesMode, + theIsReplace, + theMap); + SetParameter("FixShape.FixVertexPositionMode", theParameters.FixVertexPositionMode, theIsReplace, theMap); + SetParameter("FixShape.FixVertexToleranceMode", theParameters.FixVertexToleranceMode, theIsReplace, theMap); +} + +//============================================================================= + +void XSAlgo_ShapeProcessor::SetParameter(const char* theKey, + DE_ShapeFixParameters::FixMode theValue, + const bool theIsReplace, + ParameterMap& theMap) +{ + SetParameter(theKey, + std::to_string(static_cast::type>(theValue)), + theIsReplace, + theMap); +} + +//============================================================================= + +void XSAlgo_ShapeProcessor::SetParameter(const char* theKey, double theValue, const bool theIsReplace, ParameterMap& theMap) +{ + // Note that conversion with std::to_string() here is not possible, since it normally preserves only + // first 6 significant digits (before C++26). As a result, any value of 1e-7 or below will turn into 0. + // By using std::ostringstream with std::scientific formatting we can avoid this limitation. + std::ostringstream aStrStream; + aStrStream << std::scientific << theValue; + SetParameter(theKey, aStrStream.str(), theIsReplace, theMap); +} + +//============================================================================= + +void XSAlgo_ShapeProcessor::SetParameter(const char* theKey, + std::string&& theValue, + const bool theIsReplace, + ParameterMap& theMap) +{ + if (theIsReplace) { - return std::to_string(static_cast::type>(theMode)); - }; - - theMap.emplace("ShapeFix.Tolerance3d", std::to_string(theParameters.Tolerance3d)); - theMap.emplace("ShapeFix.MaxTolerance3d", std::to_string(theParameters.MaxTolerance3d)); - theMap.emplace("ShapeFix.MinTolerance3d", std::to_string(theParameters.MinTolerance3d)); - theMap.emplace("DetalizationLevel", std::to_string(theParameters.DetalizationLevel)); - theMap.emplace("NonManifold", std::to_string(theParameters.NonManifold)); - theMap.emplace("ShapeFix.FixFreeShellMode", makeString(theParameters.FixFreeShellMode)); - theMap.emplace("ShapeFix.FixFreeFaceMode", makeString(theParameters.FixFreeFaceMode)); - theMap.emplace("ShapeFix.FixFreeWireMode", makeString(theParameters.FixFreeWireMode)); - theMap.emplace("ShapeFix.FixSameParameterMode", makeString(theParameters.FixSameParameterMode)); - theMap.emplace("ShapeFix.FixSolidMode", makeString(theParameters.FixSolidMode)); - theMap.emplace("ShapeFix.FixShellOrientationMode", makeString(theParameters.FixShellOrientationMode)); - theMap.emplace("ShapeFix.CreateOpenSolidMode", makeString(theParameters.CreateOpenSolidMode)); - theMap.emplace("ShapeFix.FixShellMode", makeString(theParameters.FixShellMode)); - theMap.emplace("ShapeFix.FixFaceOrientationMode", makeString(theParameters.FixFaceOrientationMode)); - theMap.emplace("ShapeFix.FixFaceMode", makeString(theParameters.FixFaceMode)); - theMap.emplace("ShapeFix.FixWireMode", makeString(theParameters.FixWireMode)); - theMap.emplace("ShapeFix.FixOrientationMode", makeString(theParameters.FixOrientationMode)); - theMap.emplace("ShapeFix.FixAddNaturalBoundMode", makeString(theParameters.FixAddNaturalBoundMode)); - theMap.emplace("ShapeFix.FixMissingSeamMode", makeString(theParameters.FixMissingSeamMode)); - theMap.emplace("ShapeFix.FixSmallAreaWireMode", makeString(theParameters.FixSmallAreaWireMode)); - theMap.emplace("ShapeFix.RemoveSmallAreaFaceMode", makeString(theParameters.RemoveSmallAreaFaceMode)); - theMap.emplace("ShapeFix.FixIntersectingWiresMode", makeString(theParameters.FixIntersectingWiresMode)); - theMap.emplace("ShapeFix.FixLoopWiresMode", makeString(theParameters.FixLoopWiresMode)); - theMap.emplace("ShapeFix.FixSplitFaceMode", makeString(theParameters.FixSplitFaceMode)); - theMap.emplace("ShapeFix.AutoCorrectPrecisionMode", makeString(theParameters.AutoCorrectPrecisionMode)); - theMap.emplace("ShapeFix.ModifyTopologyMode", makeString(theParameters.ModifyTopologyMode)); - theMap.emplace("ShapeFix.ModifyGeometryMode", makeString(theParameters.ModifyGeometryMode)); - theMap.emplace("ShapeFix.ClosedWireMode", makeString(theParameters.ClosedWireMode)); - theMap.emplace("ShapeFix.PreferencePCurveMode", makeString(theParameters.PreferencePCurveMode)); - theMap.emplace("ShapeFix.FixReorderMode", makeString(theParameters.FixReorderMode)); - theMap.emplace("ShapeFix.FixSmallMode", makeString(theParameters.FixSmallMode)); - theMap.emplace("ShapeFix.FixConnectedMode", makeString(theParameters.FixConnectedMode)); - theMap.emplace("ShapeFix.FixEdgeCurvesMode", makeString(theParameters.FixEdgeCurvesMode)); - theMap.emplace("ShapeFix.FixDegeneratedMode", makeString(theParameters.FixDegeneratedMode)); - theMap.emplace("ShapeFix.FixLackingMode", makeString(theParameters.FixLackingMode)); - theMap.emplace("ShapeFix.FixSelfIntersectionMode", makeString(theParameters.FixSelfIntersectionMode)); - theMap.emplace("ShapeFix.RemoveLoopMode", makeString(theParameters.RemoveLoopMode)); - theMap.emplace("ShapeFix.FixReversed2dMode", makeString(theParameters.FixReversed2dMode)); - theMap.emplace("ShapeFix.FixRemovePCurveMode", makeString(theParameters.FixRemovePCurveMode)); - theMap.emplace("ShapeFix.FixRemoveCurve3dMode", makeString(theParameters.FixRemoveCurve3dMode)); - theMap.emplace("ShapeFix.FixAddPCurveMode", makeString(theParameters.FixAddPCurveMode)); - theMap.emplace("ShapeFix.FixAddCurve3dMode", makeString(theParameters.FixAddCurve3dMode)); - theMap.emplace("ShapeFix.FixSeamMode", makeString(theParameters.FixSeamMode)); - theMap.emplace("ShapeFix.FixShiftedMode", makeString(theParameters.FixShiftedMode)); - theMap.emplace("ShapeFix.FixEdgeSameParameterMode", makeString(theParameters.FixEdgeSameParameterMode)); - theMap.emplace("ShapeFix.FixNotchedEdgesMode", makeString(theParameters.FixNotchedEdgesMode)); - theMap.emplace("ShapeFix.FixTailMode", makeString(theParameters.FixTailMode)); - theMap.emplace("ShapeFix.MaxTailAngle", makeString(theParameters.MaxTailAngle)); - theMap.emplace("ShapeFix.MaxTailWidth", makeString(theParameters.MaxTailWidth)); - theMap.emplace("ShapeFix.FixSelfIntersectingEdgeMode", makeString(theParameters.FixSelfIntersectingEdgeMode)); - theMap.emplace("ShapeFix.FixIntersectingEdgesMode", makeString(theParameters.FixIntersectingEdgesMode)); - theMap.emplace("ShapeFix.FixNonAdjacentIntersectingEdgesMode", makeString(theParameters.FixNonAdjacentIntersectingEdgesMode)); - theMap.emplace("ShapeFix.FixVertexPositionMode", makeString(theParameters.FixVertexPositionMode)); - theMap.emplace("ShapeFix.FixVertexToleranceMode", makeString(theParameters.FixVertexToleranceMode)); + theMap[theKey] = std::move(theValue); + } + else + { + theMap.emplace(theKey, std::move(theValue)); + } } //============================================================================= diff --git a/src/XSAlgo/XSAlgo_ShapeProcessor.hxx b/src/XSAlgo/XSAlgo_ShapeProcessor.hxx index 29f8b37788..509d66cfed 100644 --- a/src/XSAlgo/XSAlgo_ShapeProcessor.hxx +++ b/src/XSAlgo/XSAlgo_ShapeProcessor.hxx @@ -86,8 +86,38 @@ public: //! Fill the parameter map with the values from the specified parameters. //! @param theParameters Parameters to be used in the processing. + //! @param theIsForce Flag indicating whether parameter should be replaced if it already exists in the map. //! @param theMap Map to fill. - Standard_EXPORT static void FillParameterMap(const DE_ShapeFixParameters& theParameters, ParameterMap& theMap); + Standard_EXPORT static void FillParameterMap(const DE_ShapeFixParameters& theParameters, + const bool theIsReplace, + ParameterMap& theMap); + + //! Set the parameter in the map. + //! @param theKey Key of the parameter. + //! @param theValue Value of the parameter. + //! @param theIsReplace Flag indicating whether parameter should be replaced if it already exists in the map. + //! @param theMap Map to set the parameter in. + Standard_EXPORT static void SetParameter(const char* theKey, + DE_ShapeFixParameters::FixMode theValue, + const bool theIsReplace, + ParameterMap& theMap); + + //! Set the parameter in the map. + //! @param theKey Key of the parameter. + //! @param theValue Value of the parameter. + //! @param theIsReplace Flag indicating whether parameter should be replaced if it already exists in the map. + //! @param theMap Map to set the parameter in. + Standard_EXPORT static void SetParameter(const char* theKey, double theValue, const bool theIsReplace, ParameterMap& theMap); + + //! Set the parameter in the map. + //! @param theKey Key of the parameter. + //! @param theValue Value of the parameter. + //! @param theIsReplace Flag indicating whether parameter should be replaced if it already exists in the map. + //! @param theMap Map to set the parameter in. + Standard_EXPORT static void SetParameter(const char* theKey, + std::string&& theValue, + const bool theIsReplace, + ParameterMap& theMap); //! The function is designed to set the length unit for the application before performing a //! transfer operation. It ensures that the length unit is correctly configured based on the diff --git a/src/XSControl/XSControl_Reader.cxx b/src/XSControl/XSControl_Reader.cxx index f93878ae4e..5ccd038f42 100644 --- a/src/XSControl/XSControl_Reader.cxx +++ b/src/XSControl/XSControl_Reader.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -483,4 +484,59 @@ void XSControl_Reader::GetStatsTransfer (const Handle(TColStd_HSequenceOfTransie } } } - + +//============================================================================= + +void XSControl_Reader::SetParameters(const ParameterMap& theParameters) +{ + if (Handle(Transfer_ActorOfTransientProcess) anActor = GetActor()) + { + anActor->SetParameters(theParameters); + } +} + +//============================================================================= + +void XSControl_Reader::SetParameters(ParameterMap&& theParameters) +{ + if (Handle(Transfer_ActorOfTransientProcess) anActor = GetActor()) + { + anActor->SetParameters(std::move(theParameters)); + } +} + +//============================================================================= + +void XSControl_Reader::SetParameters(const DE_ShapeFixParameters& theParameters) +{ + if (Handle(Transfer_ActorOfTransientProcess) anActor = GetActor()) + { + anActor->SetParameters(theParameters); + } +} + +//============================================================================= + +const XSControl_Reader::ParameterMap& XSControl_Reader::GetParameters() const +{ + static const ParameterMap anEmptyMap; + const Handle(Transfer_ActorOfTransientProcess) anActor = GetActor(); + return anActor.IsNull() ? anEmptyMap : anActor->GetParameters(); +} + +//============================================================================= + +Handle(Transfer_ActorOfTransientProcess) XSControl_Reader::GetActor() const +{ + Handle(XSControl_WorkSession) aSession = WS(); + if (aSession.IsNull()) + { + return nullptr; + } + Handle(XSControl_TransferReader) aTransferReader = aSession->TransferReader(); + if (aTransferReader.IsNull()) + { + return nullptr; + } + return aTransferReader->Actor(); +} diff --git a/src/XSControl/XSControl_Reader.hxx b/src/XSControl/XSControl_Reader.hxx index 4a8dc06e0a..187c802bb4 100644 --- a/src/XSControl/XSControl_Reader.hxx +++ b/src/XSControl/XSControl_Reader.hxx @@ -30,12 +30,15 @@ #include #include +#include + +struct DE_ShapeFixParameters; class XSControl_WorkSession; class Interface_InterfaceModel; class Standard_Transient; +class Transfer_ActorOfTransientProcess; class TopoDS_Shape; - //! A groundwork to convert a shape to data which complies //! with a particular norm. This data can be that of a whole //! model or that of a specific list of entities in the model. @@ -70,9 +73,9 @@ class TopoDS_Shape; class XSControl_Reader { public: - DEFINE_STANDARD_ALLOC + using ParameterMap = std::unordered_map; //! Creates a Reader from scratch (creates an empty WorkSession) //! A WorkSession or a Controller must be provided before running @@ -260,24 +263,40 @@ public: //! Gives statistics about Transfer Standard_EXPORT void GetStatsTransfer (const Handle(TColStd_HSequenceOfTransient)& list, Standard_Integer& nbMapped, Standard_Integer& nbWithResult, Standard_Integer& nbWithFail) const; + //! Sets parameters for shape processing. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const ParameterMap& theParameters); + //! Sets parameters for shape processing. + //! Parameters are moved from the input map. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(ParameterMap&& theParameters); + //! Sets parameters for shape processing. + //! Parameters from @p theParameters are copied to the internal map. Parameters in the + //! internal map that are not present in @p theParameters are left unchanged. + //! @param theParameters the parameters for shape processing. + Standard_EXPORT void SetParameters(const DE_ShapeFixParameters& theParameters); -protected: + //! Returns parameters for shape processing that was set by SetParameters() method. + //! @return the parameters for shape processing. Empty map if no parameters were set. + Standard_EXPORT const ParameterMap& GetParameters() const; - +protected: //! Returns a sequence of produced shapes Standard_EXPORT TopTools_SequenceOfShape& Shapes(); +private: + //! Returns the Actor for the Transfer of an Entity. + //! This Actor is used by the Reader to perform the Transfer. + //! @return the Actor for the Transfer of an Entity. May be nullptr. + Handle(Transfer_ActorOfTransientProcess) GetActor() const; +protected: Standard_Boolean therootsta; TColStd_SequenceOfTransient theroots; - private: - - - Handle(XSControl_WorkSession) thesession; TopTools_SequenceOfShape theshapes;