From 1083052cc28764e03b6ecc12aea3176c5af072d8 Mon Sep 17 00:00:00 2001 From: dpasukhi Date: Fri, 17 Jan 2025 15:29:17 +0000 Subject: [PATCH] Coding - Separate DE Wrapper's plugins to own packages #260 Reorganize DE Wrapper classes to have single style and logic. Each TKDE* will have own DE*_Provider and DE*_ConfigurationNode DE* package will have all necessary classes and enums inside instead of another places. --- dox/user_guides/de_wrapper/de_wrapper.md | 8 +- .../DEBREP_ConfigurationNode.cxx} | 152 +++---- src/DEBREP/DEBREP_ConfigurationNode.hxx | 103 +++++ src/DEBREP/DEBREP_Provider.cxx | 297 ++++++++++++ src/DEBREP/DEBREP_Provider.hxx | 141 ++++++ src/DEBREP/FILES | 4 + .../DEBRepCascade_ConfigurationNode.hxx | 88 +--- src/DEBRepCascade/DEBRepCascade_Provider.cxx | 306 ------------- src/DEBRepCascade/DEBRepCascade_Provider.hxx | 120 +---- src/DEBRepCascade/FILES | 2 - .../DEGLTF_ConfigurationNode.cxx} | 275 ++++++----- src/DEGLTF/DEGLTF_ConfigurationNode.hxx | 118 +++++ src/DEGLTF/DEGLTF_Provider.cxx | 249 ++++++++++ src/DEGLTF/DEGLTF_Provider.hxx | 143 ++++++ src/DEGLTF/FILES | 4 + .../DEIGES_ConfigurationNode.cxx} | 274 +++++------ src/DEIGES/DEIGES_ConfigurationNode.hxx | 184 ++++++++ src/DEIGES/DEIGES_Provider.cxx | 424 +++++++++++++++++ src/DEIGES/DEIGES_Provider.hxx | 160 +++++++ src/DEIGES/FILES | 4 + .../DEOBJ_ConfigurationNode.cxx} | 183 ++++---- src/DEOBJ/DEOBJ_ConfigurationNode.hxx | 102 +++++ .../DEOBJ_Provider.cxx} | 204 ++++----- src/DEOBJ/DEOBJ_Provider.hxx | 141 ++++++ src/DEOBJ/FILES | 4 + .../DEPLY_ConfigurationNode.cxx} | 163 ++++--- src/DEPLY/DEPLY_ConfigurationNode.hxx | 109 +++++ .../DEPLY_Provider.cxx} | 123 +++-- src/DEPLY/DEPLY_Provider.hxx | 97 ++++ src/DEPLY/FILES | 4 + .../DESTEP_ConfigurationNode.cxx} | 400 +++++++++------- src/DESTEP/DESTEP_ConfigurationNode.hxx | 93 ++++ src/DESTEP/DESTEP_Provider.cxx | 332 ++++++++++++++ src/DESTEP/DESTEP_Provider.hxx | 148 ++++++ src/DESTEP/FILES | 4 + .../DESTL_ConfigurationNode.cxx} | 144 +++--- src/DESTL/DESTL_ConfigurationNode.hxx | 98 ++++ src/DESTL/DESTL_Provider.cxx | 242 ++++++++++ src/DESTL/DESTL_Provider.hxx | 136 ++++++ src/DESTL/FILES | 4 + src/DEVRML/DEVRML_ConfigurationNode.cxx | 195 ++++++++ src/DEVRML/DEVRML_ConfigurationNode.hxx | 111 +++++ src/DEVRML/DEVRML_Provider.cxx | 323 +++++++++++++ src/DEVRML/DEVRML_Provider.hxx | 141 ++++++ src/DEVRML/FILES | 4 + .../DEXCAF_ConfigurationNode.cxx} | 153 +++---- src/DEXCAF/DEXCAF_ConfigurationNode.hxx | 100 ++++ src/DEXCAF/DEXCAF_Provider.cxx | 297 ++++++++++++ src/DEXCAF/DEXCAF_Provider.hxx | 141 ++++++ src/DEXCAF/FILES | 4 + .../DEXCAFCascade_ConfigurationNode.hxx | 85 +--- src/DEXCAFCascade/DEXCAFCascade_Provider.cxx | 316 ------------- src/DEXCAFCascade/DEXCAFCascade_Provider.hxx | 120 +---- src/DEXCAFCascade/FILES | 2 - src/IGESCAFControl/FILES | 2 - .../IGESCAFControl_ConfigurationNode.hxx | 163 +------ .../IGESCAFControl_Provider.cxx | 428 ------------------ .../IGESCAFControl_Provider.hxx | 141 +----- src/RWGltf/FILES | 2 - src/RWGltf/RWGltf_ConfigurationNode.hxx | 103 +---- src/RWGltf/RWGltf_Provider.cxx | 269 ----------- src/RWGltf/RWGltf_Provider.hxx | 123 +---- src/RWObj/FILES | 2 - src/RWObj/RWObj_ConfigurationNode.hxx | 87 +--- src/RWObj/RWObj_Provider.hxx | 120 +---- src/RWPly/FILES | 2 - src/RWPly/RWPly_ConfigurationNode.hxx | 93 +--- src/RWPly/RWPly_Provider.hxx | 80 +--- src/RWStl/FILES | 2 - src/RWStl/RWStl_ConfigurationNode.hxx | 83 +--- src/RWStl/RWStl_Provider.cxx | 262 ----------- src/RWStl/RWStl_Provider.hxx | 120 +---- src/STEPCAFControl/FILES | 2 - .../STEPCAFControl_ConfigurationNode.hxx | 79 +--- .../STEPCAFControl_Provider.cxx | 342 -------------- .../STEPCAFControl_Provider.hxx | 129 +----- src/TKDECascade/PACKAGES | 2 + src/TKDEGLTF/PACKAGES | 1 + src/TKDEIGES/PACKAGES | 1 + src/TKDEOBJ/PACKAGES | 1 + src/TKDEPLY/PACKAGES | 1 + src/TKDESTEP/PACKAGES | 3 +- src/TKDESTL/PACKAGES | 1 + src/TKDEVRML/PACKAGES | 1 + src/Vrml/FILES | 2 - src/Vrml/Vrml_ConfigurationNode.cxx | 200 -------- src/Vrml/Vrml_ConfigurationNode.hxx | 96 +--- src/Vrml/Vrml_Provider.cxx | 308 ------------- src/Vrml/Vrml_Provider.hxx | 120 +---- src/XDEDRAW/XDEDRAW.cxx | 18 +- src/XSDRAWDE/XSDRAWDE.cxx | 4 +- 91 files changed, 5781 insertions(+), 5391 deletions(-) rename src/{DEBRepCascade/DEBRepCascade_ConfigurationNode.cxx => DEBREP/DEBREP_ConfigurationNode.cxx} (53%) create mode 100644 src/DEBREP/DEBREP_ConfigurationNode.hxx create mode 100644 src/DEBREP/DEBREP_Provider.cxx create mode 100644 src/DEBREP/DEBREP_Provider.hxx create mode 100644 src/DEBREP/FILES delete mode 100644 src/DEBRepCascade/DEBRepCascade_Provider.cxx rename src/{RWGltf/RWGltf_ConfigurationNode.cxx => DEGLTF/DEGLTF_ConfigurationNode.cxx} (58%) create mode 100644 src/DEGLTF/DEGLTF_ConfigurationNode.hxx create mode 100644 src/DEGLTF/DEGLTF_Provider.cxx create mode 100644 src/DEGLTF/DEGLTF_Provider.hxx create mode 100644 src/DEGLTF/FILES rename src/{IGESCAFControl/IGESCAFControl_ConfigurationNode.cxx => DEIGES/DEIGES_ConfigurationNode.cxx} (66%) create mode 100644 src/DEIGES/DEIGES_ConfigurationNode.hxx create mode 100644 src/DEIGES/DEIGES_Provider.cxx create mode 100644 src/DEIGES/DEIGES_Provider.hxx create mode 100644 src/DEIGES/FILES rename src/{RWObj/RWObj_ConfigurationNode.cxx => DEOBJ/DEOBJ_ConfigurationNode.cxx} (59%) create mode 100644 src/DEOBJ/DEOBJ_ConfigurationNode.hxx rename src/{RWObj/RWObj_Provider.cxx => DEOBJ/DEOBJ_Provider.cxx} (50%) create mode 100644 src/DEOBJ/DEOBJ_Provider.hxx create mode 100644 src/DEOBJ/FILES rename src/{RWPly/RWPly_ConfigurationNode.cxx => DEPLY/DEPLY_ConfigurationNode.cxx} (63%) create mode 100644 src/DEPLY/DEPLY_ConfigurationNode.hxx rename src/{RWPly/RWPly_Provider.cxx => DEPLY/DEPLY_Provider.cxx} (56%) create mode 100644 src/DEPLY/DEPLY_Provider.hxx create mode 100644 src/DEPLY/FILES rename src/{STEPCAFControl/STEPCAFControl_ConfigurationNode.cxx => DESTEP/DESTEP_ConfigurationNode.cxx} (63%) create mode 100644 src/DESTEP/DESTEP_ConfigurationNode.hxx create mode 100644 src/DESTEP/DESTEP_Provider.cxx create mode 100644 src/DESTEP/DESTEP_Provider.hxx create mode 100644 src/DESTEP/FILES rename src/{RWStl/RWStl_ConfigurationNode.cxx => DESTL/DESTL_ConfigurationNode.cxx} (53%) create mode 100644 src/DESTL/DESTL_ConfigurationNode.hxx create mode 100644 src/DESTL/DESTL_Provider.cxx create mode 100644 src/DESTL/DESTL_Provider.hxx create mode 100644 src/DESTL/FILES create mode 100644 src/DEVRML/DEVRML_ConfigurationNode.cxx create mode 100644 src/DEVRML/DEVRML_ConfigurationNode.hxx create mode 100644 src/DEVRML/DEVRML_Provider.cxx create mode 100644 src/DEVRML/DEVRML_Provider.hxx create mode 100644 src/DEVRML/FILES rename src/{DEXCAFCascade/DEXCAFCascade_ConfigurationNode.cxx => DEXCAF/DEXCAF_ConfigurationNode.cxx} (50%) create mode 100644 src/DEXCAF/DEXCAF_ConfigurationNode.hxx create mode 100644 src/DEXCAF/DEXCAF_Provider.cxx create mode 100644 src/DEXCAF/DEXCAF_Provider.hxx create mode 100644 src/DEXCAF/FILES delete mode 100644 src/DEXCAFCascade/DEXCAFCascade_Provider.cxx delete mode 100644 src/IGESCAFControl/IGESCAFControl_Provider.cxx delete mode 100644 src/RWGltf/RWGltf_Provider.cxx delete mode 100644 src/RWStl/RWStl_Provider.cxx delete mode 100644 src/STEPCAFControl/STEPCAFControl_Provider.cxx delete mode 100644 src/Vrml/Vrml_ConfigurationNode.cxx delete mode 100644 src/Vrml/Vrml_Provider.cxx diff --git a/dox/user_guides/de_wrapper/de_wrapper.md b/dox/user_guides/de_wrapper/de_wrapper.md index 13b0a348b7..c915dcd786 100644 --- a/dox/user_guides/de_wrapper/de_wrapper.md +++ b/dox/user_guides/de_wrapper/de_wrapper.md @@ -200,7 +200,7 @@ All registered providers are set to the map with information about its vendor an It is nesessary to register only one ConfigurationNode for all needed formats. ~~~~{.cpp} Handle(DE_Wrapper) aSession = DE_Wrapper::GlobalWrapper(); -Handle(DE_ConfigurationNode) aNode = new STEPCAFControl_ConfigurationNode(); +Handle(DE_ConfigurationNode) aNode = new DESTEP_ConfigurationNode(); aSession->Bind(aNode); ~~~~ @subsubsection occt_de_wrapper_3_3_2 Registering providers. DRAW Sample @@ -216,7 +216,7 @@ It is possible to change a parameter from code using a smart pointer. ~~~~{.cpp} // global variable -static Handle(STEPCAFControl_ConfigurationNode) THE_STEP_NODE; +static Handle(DESTEP_ConfigurationNode) THE_STEP_NODE; static Handle(DE_ConfigurationNode) RegisterStepNode() { @@ -226,7 +226,7 @@ static Handle(DE_ConfigurationNode) RegisterStepNode() return THE_STEP_NODE; } - THE_STEP_NODE = new STEPCAFControl_ConfigurationNode(); + THE_STEP_NODE = new DESTEP_ConfigurationNode(); aSession->Bind(THE_STEP_NODE); return THE_STEP_NODE; } @@ -351,7 +351,7 @@ It is possible to read and write CAD files directly from a special provider. ~~~~{.cpp} // Creating or getting node -Handle(STEPCAFControl_ConfigurationNode) aNode = new STEPCAFControl_ConfigurationNode(); +Handle(DESTEP_ConfigurationNode) aNode = new DESTEP_ConfigurationNode(); // Creating an one-time provider Handle(DE_Provider) aProvider = aNode->BuildProvider(); // Setting configuration with all parameters diff --git a/src/DEBRepCascade/DEBRepCascade_ConfigurationNode.cxx b/src/DEBREP/DEBREP_ConfigurationNode.cxx similarity index 53% rename from src/DEBRepCascade/DEBRepCascade_ConfigurationNode.cxx rename to src/DEBREP/DEBREP_ConfigurationNode.cxx index 69f44dcd82..2bc9ff7fd3 100644 --- a/src/DEBRepCascade/DEBRepCascade_ConfigurationNode.cxx +++ b/src/DEBREP/DEBREP_ConfigurationNode.cxx @@ -11,59 +11,59 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include +#include #include #include -#include #include -IMPLEMENT_STANDARD_RTTIEXT(DEBRepCascade_ConfigurationNode, DE_ConfigurationNode) +IMPLEMENT_STANDARD_RTTIEXT(DEBREP_ConfigurationNode, DE_ConfigurationNode) namespace { - static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() - { - static const TCollection_AsciiString aScope = "provider"; - return aScope; - } +static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() +{ + static const TCollection_AsciiString aScope = "provider"; + return aScope; +} + +// Wrapper to auto-load DE component +DE_PluginHolder THE_OCCT_BREP_COMPONENT_PLUGIN; +} // namespace - // Wrapper to auto-load DE component - DE_PluginHolder THE_OCCT_BREP_COMPONENT_PLUGIN; +//================================================================================================= + +DEBREP_ConfigurationNode::DEBREP_ConfigurationNode() + : DE_ConfigurationNode() +{ } -//======================================================================= -// function : DEBRepCascade_ConfigurationNode -// purpose : -//======================================================================= -DEBRepCascade_ConfigurationNode::DEBRepCascade_ConfigurationNode() : - DE_ConfigurationNode() -{} - -//======================================================================= -// function : DEBRepCascade_ConfigurationNode -// purpose : -//======================================================================= -DEBRepCascade_ConfigurationNode::DEBRepCascade_ConfigurationNode(const Handle(DEBRepCascade_ConfigurationNode)& theNode) - :DE_ConfigurationNode(theNode) +//================================================================================================= + +DEBREP_ConfigurationNode::DEBREP_ConfigurationNode(const Handle(DEBREP_ConfigurationNode)& theNode) + : DE_ConfigurationNode(theNode) { InternalParameters = theNode->InternalParameters; } -//======================================================================= -// function : Load -// purpose : -//======================================================================= -bool DEBRepCascade_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) +//================================================================================================= + +bool DEBREP_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) { - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); InternalParameters.WriteBinary = theResource->BooleanVal("write.binary", InternalParameters.WriteBinary, aScope); InternalParameters.WriteVersionBin = - (BinTools_FormatVersion)theResource->IntegerVal("write.version.binary", InternalParameters.WriteVersionBin, aScope); + (BinTools_FormatVersion)theResource->IntegerVal("write.version.binary", + InternalParameters.WriteVersionBin, + aScope); InternalParameters.WriteVersionAscii = - (TopTools_FormatVersion)theResource->IntegerVal("write.version.ascii", InternalParameters.WriteVersionAscii, aScope); + (TopTools_FormatVersion)theResource->IntegerVal("write.version.ascii", + InternalParameters.WriteVersionAscii, + aScope); InternalParameters.WriteTriangles = theResource->BooleanVal("write.triangles", InternalParameters.WriteTriangles, aScope); InternalParameters.WriteNormals = @@ -71,16 +71,16 @@ bool DEBRepCascade_ConfigurationNode::Load(const Handle(DE_ConfigurationContext) return true; } -//======================================================================= -// function : Save -// purpose : -//======================================================================= -TCollection_AsciiString DEBRepCascade_ConfigurationNode::Save() const +//================================================================================================= + +TCollection_AsciiString DEBREP_ConfigurationNode::Save() const { TCollection_AsciiString aResult; aResult += "!*****************************************************************************\n"; - aResult = aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; + aResult = + aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; aResult += "!\n"; aResult += "!Write parameters:\n"; @@ -120,88 +120,70 @@ TCollection_AsciiString DEBRepCascade_ConfigurationNode::Save() const return aResult; } -//======================================================================= -// function : Copy -// purpose : -//======================================================================= -Handle(DE_ConfigurationNode) DEBRepCascade_ConfigurationNode::Copy() const +//================================================================================================= + +Handle(DE_ConfigurationNode) DEBREP_ConfigurationNode::Copy() const { - return new DEBRepCascade_ConfigurationNode(*this); + return new DEBREP_ConfigurationNode(*this); } -//======================================================================= -// function : BuildProvider -// purpose : -//======================================================================= -Handle(DE_Provider) DEBRepCascade_ConfigurationNode::BuildProvider() +//================================================================================================= + +Handle(DE_Provider) DEBREP_ConfigurationNode::BuildProvider() { - return new DEBRepCascade_Provider(this); + return new DEBREP_Provider(this); } -//======================================================================= -// function : IsImportSupported -// purpose : -//======================================================================= -bool DEBRepCascade_ConfigurationNode::IsImportSupported() const +//================================================================================================= + +bool DEBREP_ConfigurationNode::IsImportSupported() const { return true; } -//======================================================================= -// function : IsExportSupported -// purpose : -//======================================================================= -bool DEBRepCascade_ConfigurationNode::IsExportSupported() const +//================================================================================================= + +bool DEBREP_ConfigurationNode::IsExportSupported() const { return true; } -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString DEBRepCascade_ConfigurationNode::GetFormat() const +//================================================================================================= + +TCollection_AsciiString DEBREP_ConfigurationNode::GetFormat() const { return TCollection_AsciiString("BREP"); } -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString DEBRepCascade_ConfigurationNode::GetVendor() const +//================================================================================================= + +TCollection_AsciiString DEBREP_ConfigurationNode::GetVendor() const { return TCollection_AsciiString("OCC"); } -//======================================================================= -// function : GetExtensions -// purpose : -//======================================================================= -TColStd_ListOfAsciiString DEBRepCascade_ConfigurationNode::GetExtensions() const +//================================================================================================= + +TColStd_ListOfAsciiString DEBREP_ConfigurationNode::GetExtensions() const { TColStd_ListOfAsciiString anExt; anExt.Append("brep"); return anExt; } -//======================================================================= -// function : CheckContent -// purpose : -//======================================================================= -bool DEBRepCascade_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const +//================================================================================================= + +bool DEBREP_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const { if (theBuffer.IsNull() || theBuffer->Size() < 20) { return false; } const char* aBytes = (const char*)theBuffer->Data(); - if (::strstr(aBytes, "DBRep_DrawableShape") || - ::strstr(aBytes, "CASCADE Topology V1") || - ::strstr(aBytes, "CASCADE Topology V3")) + if (::strstr(aBytes, "DBRep_DrawableShape") || ::strstr(aBytes, "CASCADE Topology V1") + || ::strstr(aBytes, "CASCADE Topology V3")) { return true; } return false; } - diff --git a/src/DEBREP/DEBREP_ConfigurationNode.hxx b/src/DEBREP/DEBREP_ConfigurationNode.hxx new file mode 100644 index 0000000000..240e842827 --- /dev/null +++ b/src/DEBREP/DEBREP_ConfigurationNode.hxx @@ -0,0 +1,103 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEBREP_ConfigurationNode_HeaderFile +#define _DEBREP_ConfigurationNode_HeaderFile + +#include + +#include +#include + +//! The purpose of this class is to configure the transfer process for BRep format +//! Stores the necessary settings for DEBREP_Provider. +//! Configures and creates special provider to transfer BRep files. +//! +//! Nodes grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "BREP" +//! The supported CAD extension is ".brep" +//! The import process is supported. +//! The export process is supported. +class DEBREP_ConfigurationNode : public DE_ConfigurationNode +{ + DEFINE_STANDARD_RTTIEXT(DEBREP_ConfigurationNode, DE_ConfigurationNode) +public: + //! Initializes all field by default + Standard_EXPORT DEBREP_ConfigurationNode(); + + //! Copies values of all fields + //! @param[in] theNode object to copy + Standard_EXPORT DEBREP_ConfigurationNode(const Handle(DEBREP_ConfigurationNode)& theNode); + + //! Updates values according the resource + //! @param[in] theResource input resource to use + //! @return true if theResource loading has ended correctly + Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) + Standard_OVERRIDE; + + //! Writes configuration to the string + //! @return result resource string + Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; + + //! Copies values of all fields + //! @return new object with the same field values + Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; + + //! Creates new provider for the own format + //! @return new created provider + Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; + +public: + //! Checks the import supporting + //! @return true if import is supported + Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; + + //! Checks the export supporting + //! @return true if export is supported + Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; + + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; + + //! Gets list of supported file extensions + //! @return list of extensions + Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; + + //! Checks the file content to verify a format + //! @param[in] theBuffer read stream buffer to check content + //! @return Standard_True if file is supported by a current provider + Standard_EXPORT virtual bool CheckContent(const Handle(NCollection_Buffer)& theBuffer) const + Standard_OVERRIDE; + +public: + struct DEBRep_InternalSection + { + // Write + bool WriteBinary = true; //!< Defines the binary file format + // clang-format off + BinTools_FormatVersion WriteVersionBin = BinTools_FormatVersion_CURRENT; //!< Defines the writer version for the binary format + TopTools_FormatVersion WriteVersionAscii = TopTools_FormatVersion_CURRENT; //!< Defines the writer version for the ASCII format + // clang-format on + bool WriteTriangles = true; //!< Defines the flag for storing shape with(without) triangles + bool WriteNormals = true; //!< Defines the flag for storing shape with(without) normals + + } InternalParameters; +}; + +#endif // _DEBREP_ConfigurationNode_HeaderFile diff --git a/src/DEBREP/DEBREP_Provider.cxx b/src/DEBREP/DEBREP_Provider.cxx new file mode 100644 index 0000000000..3f331e3154 --- /dev/null +++ b/src/DEBREP/DEBREP_Provider.cxx @@ -0,0 +1,297 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(DEBREP_Provider, DE_Provider) + +//================================================================================================= + +DEBREP_Provider::DEBREP_Provider() {} + +//================================================================================================= + +DEBREP_Provider::DEBREP_Provider(const Handle(DE_ConfigurationNode)& theNode) + : DE_Provider(theNode) +{ +} + +//================================================================================================= + +bool DEBREP_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Read(thePath, theDocument, theProgress); +} + +//================================================================================================= + +bool DEBREP_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Write(thePath, theDocument, theProgress); +} + +//================================================================================================= + +bool DEBREP_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + if (theDocument.IsNull()) + { + Message::SendFail() << "Error in the DEBREP_Provider during reading the file " << thePath + << "\t: theDocument shouldn't be null"; + return false; + } + TopoDS_Shape aShape; + if (!Read(thePath, aShape, theProgress)) + { + return false; + } + Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); + aShTool->AddShape(aShape); + return true; +} + +//================================================================================================= + +bool DEBREP_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + TopoDS_Shape aShape; + TDF_LabelSequence aLabels; + Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); + aSTool->GetFreeShapes(aLabels); + if (aLabels.Length() <= 0) + { + Message::SendFail() << "Error in the DEBREP_Provider during writing the file " << thePath + << "\t: Document contain no shapes"; + return false; + } + + Handle(DEBREP_ConfigurationNode) aNode = Handle(DEBREP_ConfigurationNode)::DownCast(GetNode()); + if (aNode->GlobalParameters.LengthUnit != 1.0) + { + Message::SendWarning() + << "Warning in the DEBREP_Provider during writing the file " << thePath + << "\t: Target Units for writing were changed, but current format doesn't support scaling"; + } + + if (aLabels.Length() == 1) + { + aShape = aSTool->GetShape(aLabels.Value(1)); + } + else + { + TopoDS_Compound aComp; + BRep_Builder aBuilder; + aBuilder.MakeCompound(aComp); + for (Standard_Integer anIndex = 1; anIndex <= aLabels.Length(); anIndex++) + { + TopoDS_Shape aS = aSTool->GetShape(aLabels.Value(anIndex)); + aBuilder.Add(aComp, aS); + } + aShape = aComp; + } + return Write(thePath, aShape, theProgress); +} + +//================================================================================================= + +bool DEBREP_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Read(thePath, theShape, theProgress); +} + +//================================================================================================= + +bool DEBREP_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Write(thePath, theShape, theProgress); +} + +//================================================================================================= + +bool DEBREP_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + bool isBinaryFormat = true; + { + // probe file header to recognize format + const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); + std::shared_ptr aFile = + aFileSystem->OpenIStream(thePath, std::ios::in | std::ios::binary); + if (aFile.get() == NULL) + { + Message::SendFail() << "Error in the DEBREP_Provider during reading the file " << thePath + << "\t: Cannot read the file"; + return false; + } + + char aStringBuf[255] = {}; + aFile->read(aStringBuf, 255); + if (aFile->fail()) + { + Message::SendFail() << "Error in the DEBREP_Provider during reading the file " << thePath + << "\t: Cannot read the file"; + return false; + } + isBinaryFormat = !(::strncmp(aStringBuf, "DBRep_DrawableShape", 19) == 0); + } + + if (isBinaryFormat) + { + if (!BinTools::Read(theShape, thePath.ToCString(), theProgress)) + { + Message::SendFail() << "Error in the DEBREP_Provider during reading the file " << thePath + << "\t: Cannot read from the file"; + return false; + } + } + else + { + if (!BRepTools::Read(theShape, thePath.ToCString(), BRep_Builder(), theProgress)) + { + Message::SendFail() << "Error in the DEBREP_Provider during reading the file " << thePath + << "\t: Cannot read from the file"; + return false; + } + } + + return true; +} + +//================================================================================================= + +bool DEBREP_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEBREP_ConfigurationNode))) + { + Message::SendFail() << "Error in the DEBREP_Provider during writing the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DEBREP_ConfigurationNode) aNode = Handle(DEBREP_ConfigurationNode)::DownCast(GetNode()); + if (aNode->GlobalParameters.LengthUnit != 1.0) + { + Message::SendWarning() + << "Warning in the DEBREP_Provider during writing the file " << thePath + << "\t: Target Units for writing were changed, but current format doesn't support scaling"; + } + if (aNode->InternalParameters.WriteBinary) + { + if (aNode->InternalParameters.WriteVersionBin + > static_cast(BinTools_FormatVersion_UPPER) + || aNode->InternalParameters.WriteVersionBin + < static_cast(BinTools_FormatVersion_LOWER)) + { + Message::SendFail() << "Error in the DEBREP_Provider during writing the file " << thePath + << "\t: Unknown format version"; + return false; + } + if (aNode->InternalParameters.WriteNormals + && aNode->InternalParameters.WriteVersionBin < BinTools_FormatVersion_VERSION_4) + { + Message::SendFail() << "Error in the DEBREP_Provider during writing the file " << thePath + << "\t: Vertex normals require binary format version 4 or later"; + return false; + } + + if (!BinTools::Write(theShape, + thePath.ToCString(), + aNode->InternalParameters.WriteTriangles, + aNode->InternalParameters.WriteNormals, + aNode->InternalParameters.WriteVersionBin, + theProgress)) + { + Message::SendFail() << "Error in the DEBREP_Provider during writing the file " << thePath + << "\t: Cannot write the file"; + return false; + } + } + else + { + if (aNode->InternalParameters.WriteVersionAscii + > static_cast(TopTools_FormatVersion_UPPER) + || aNode->InternalParameters.WriteVersionAscii + < static_cast(TopTools_FormatVersion_LOWER)) + { + Message::SendFail() << "Error in the DEBREP_Provider during writing the file " << thePath + << "\t: Unknown format version"; + return false; + } + if (aNode->InternalParameters.WriteNormals + && aNode->InternalParameters.WriteVersionAscii < TopTools_FormatVersion_VERSION_3) + { + Message::SendFail() << "Error in the DEBREP_Provider during writing the file " << thePath + << "\t: Error: vertex normals require ascii format version 3 or later"; + return false; + } + if (!BRepTools::Write(theShape, + thePath.ToCString(), + aNode->InternalParameters.WriteTriangles, + aNode->InternalParameters.WriteNormals, + aNode->InternalParameters.WriteVersionAscii, + theProgress)) + { + Message::SendFail() << "Error in the DEBREP_Provider during writing the file " << thePath + << "\t: Cannot write the file"; + return false; + } + } + + return true; +} + +//================================================================================================= + +TCollection_AsciiString DEBREP_Provider::GetFormat() const +{ + return TCollection_AsciiString("BREP"); +} + +//================================================================================================= + +TCollection_AsciiString DEBREP_Provider::GetVendor() const +{ + return TCollection_AsciiString("OCC"); +} diff --git a/src/DEBREP/DEBREP_Provider.hxx b/src/DEBREP/DEBREP_Provider.hxx new file mode 100644 index 0000000000..d239af3507 --- /dev/null +++ b/src/DEBREP/DEBREP_Provider.hxx @@ -0,0 +1,141 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEBREP_Provider_HeaderFile +#define _DEBREP_Provider_HeaderFile + +#include + +//! The class to transfer BRep files. +//! Reads and Writes any BRep files into/from OCCT. +//! Each operation needs configuration node. +//! +//! Providers grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "BREP" +//! The import process is supported. +//! The export process is supported. +class DEBREP_Provider : public DE_Provider +{ +public: + DEFINE_STANDARD_RTTIEXT(DEBREP_Provider, DE_Provider) + +public: + //! Default constructor + //! Configure translation process with global configuration + Standard_EXPORT DEBREP_Provider(); + + //! Configure translation process + //! @param[in] theNode object to init the DE_Provider + Standard_EXPORT DEBREP_Provider(const Handle(DE_ConfigurationNode)& theNode); + +public: + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + +public: + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; +}; + +#endif // _DEBREP_Provider_HeaderFile diff --git a/src/DEBREP/FILES b/src/DEBREP/FILES new file mode 100644 index 0000000000..1a86c27224 --- /dev/null +++ b/src/DEBREP/FILES @@ -0,0 +1,4 @@ +DEBREP_ConfigurationNode.cxx +DEBREP_ConfigurationNode.hxx +DEBREP_Provider.cxx +DEBREP_Provider.hxx diff --git a/src/DEBRepCascade/DEBRepCascade_ConfigurationNode.hxx b/src/DEBRepCascade/DEBRepCascade_ConfigurationNode.hxx index ac53b240d8..d7607703ea 100644 --- a/src/DEBRepCascade/DEBRepCascade_ConfigurationNode.hxx +++ b/src/DEBRepCascade/DEBRepCascade_ConfigurationNode.hxx @@ -14,91 +14,9 @@ #ifndef _DEBRepCascade_ConfigurationNode_HeaderFile #define _DEBRepCascade_ConfigurationNode_HeaderFile -#include +#include -#include -#include - -//! The purpose of this class is to configure the transfer process for BRep format -//! Stores the necessary settings for DEBRepCascade_Provider. -//! Configures and creates special provider to transfer BRep files. -//! -//! Nodes grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "BREP" -//! The supported CAD extension is ".brep" -//! The import process is supported. -//! The export process is supported. -class DEBRepCascade_ConfigurationNode : public DE_ConfigurationNode -{ - DEFINE_STANDARD_RTTIEXT(DEBRepCascade_ConfigurationNode, DE_ConfigurationNode) -public: - - //! Initializes all field by default - Standard_EXPORT DEBRepCascade_ConfigurationNode(); - - //! Copies values of all fields - //! @param[in] theNode object to copy - Standard_EXPORT DEBRepCascade_ConfigurationNode(const Handle(DEBRepCascade_ConfigurationNode)& theNode); - - //! Updates values according the resource - //! @param[in] theResource input resource to use - //! @return true if theResource loading has ended correctly - Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) Standard_OVERRIDE; - - //! Writes configuration to the string - //! @return result resource string - Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; - - //! Copies values of all fields - //! @return new object with the same field values - Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; - - - //! Creates new provider for the own format - //! @return new created provider - Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; - -public: - - //! Checks the import supporting - //! @return true if import is supported - Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; - - //! Checks the export supporting - //! @return true if export is supported - Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; - - //! Gets list of supported file extensions - //! @return list of extensions - Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; - - //! Checks the file content to verify a format - //! @param[in] theBuffer read stream buffer to check content - //! @return Standard_True if file is supported by a current provider - Standard_EXPORT virtual bool CheckContent(const Handle(NCollection_Buffer)& theBuffer) const Standard_OVERRIDE; - -public: - struct DEBRep_InternalSection - { - // Write - bool WriteBinary = true; //!< Defines the binary file format -// clang-format off - BinTools_FormatVersion WriteVersionBin = BinTools_FormatVersion_CURRENT; //!< Defines the writer version for the binary format - TopTools_FormatVersion WriteVersionAscii = TopTools_FormatVersion_CURRENT; //!< Defines the writer version for the ASCII format -// clang-format on - bool WriteTriangles = true; //!< Defines the flag for storing shape with(without) triangles - bool WriteNormals = true; //!< Defines the flag for storing shape with(without) normals - - } InternalParameters; -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DEBREP_ConfigurationNode DEBRepCascade_ConfigurationNode; #endif // _DEBRepCascade_ConfigurationNode_HeaderFile diff --git a/src/DEBRepCascade/DEBRepCascade_Provider.cxx b/src/DEBRepCascade/DEBRepCascade_Provider.cxx deleted file mode 100644 index a9a663ab46..0000000000 --- a/src/DEBRepCascade/DEBRepCascade_Provider.cxx +++ /dev/null @@ -1,306 +0,0 @@ -// Copyright (c) 2022 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -IMPLEMENT_STANDARD_RTTIEXT(DEBRepCascade_Provider, DE_Provider) - -//======================================================================= -// function : DEBRepCascade_Provider -// purpose : -//======================================================================= -DEBRepCascade_Provider::DEBRepCascade_Provider() -{} - -//======================================================================= -// function : DEBRepCascade_Provider -// purpose : -//======================================================================= -DEBRepCascade_Provider::DEBRepCascade_Provider(const Handle(DE_ConfigurationNode)& theNode) - :DE_Provider(theNode) -{} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool DEBRepCascade_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Read(thePath, theDocument, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool DEBRepCascade_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Write(thePath, theDocument, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool DEBRepCascade_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - if(theDocument.IsNull()) - { - Message::SendFail() << "Error in the DEBRepCascade_Provider during reading the file " << - thePath << "\t: theDocument shouldn't be null"; - return false; - } - TopoDS_Shape aShape; - if (!Read(thePath, aShape, theProgress)) - { - return false; - } - Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); - aShTool->AddShape(aShape); - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool DEBRepCascade_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - TopoDS_Shape aShape; - TDF_LabelSequence aLabels; - Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); - aSTool->GetFreeShapes(aLabels); - if (aLabels.Length() <= 0) - { - Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << - thePath << "\t: Document contain no shapes"; - return false; - } - - Handle(DEBRepCascade_ConfigurationNode) aNode = Handle(DEBRepCascade_ConfigurationNode)::DownCast(GetNode()); - if (aNode->GlobalParameters.LengthUnit != 1.0) - { - Message::SendWarning() << "Warning in the DEBRepCascade_Provider during writing the file " << - thePath << "\t: Target Units for writing were changed, but current format doesn't support scaling"; - } - - if (aLabels.Length() == 1) - { - aShape = aSTool->GetShape(aLabels.Value(1)); - } - else - { - TopoDS_Compound aComp; - BRep_Builder aBuilder; - aBuilder.MakeCompound(aComp); - for (Standard_Integer anIndex = 1; anIndex <= aLabels.Length(); anIndex++) - { - TopoDS_Shape aS = aSTool->GetShape(aLabels.Value(anIndex)); - aBuilder.Add(aComp, aS); - } - aShape = aComp; - } - return Write(thePath, aShape, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool DEBRepCascade_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Read(thePath, theShape, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool DEBRepCascade_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Write(thePath, theShape, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool DEBRepCascade_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - bool isBinaryFormat = true; - { - // probe file header to recognize format - const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); - std::shared_ptr aFile = aFileSystem->OpenIStream(thePath, std::ios::in | std::ios::binary); - if (aFile.get() == NULL) - { - Message::SendFail() << "Error in the DEBRepCascade_Provider during reading the file " << - thePath << "\t: Cannot read the file"; - return false; - } - - char aStringBuf[255] = {}; - aFile->read(aStringBuf, 255); - if (aFile->fail()) - { - Message::SendFail() << "Error in the DEBRepCascade_Provider during reading the file " << - thePath << "\t: Cannot read the file"; - return false; - } - isBinaryFormat = !(::strncmp(aStringBuf, "DBRep_DrawableShape", 19) == 0); - } - - if (isBinaryFormat) - { - if (!BinTools::Read(theShape, thePath.ToCString(), theProgress)) - { - Message::SendFail() << "Error in the DEBRepCascade_Provider during reading the file " << - thePath << "\t: Cannot read from the file"; - return false; - } - } - else - { - if (!BRepTools::Read(theShape, thePath.ToCString(), BRep_Builder(), theProgress)) - { - Message::SendFail() << "Error in the DEBRepCascade_Provider during reading the file " << - thePath << "\t: Cannot read from the file"; - return false; - } - } - - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool DEBRepCascade_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEBRepCascade_ConfigurationNode))) - { - Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(DEBRepCascade_ConfigurationNode) aNode = Handle(DEBRepCascade_ConfigurationNode)::DownCast(GetNode()); - if (aNode->GlobalParameters.LengthUnit != 1.0) - { - Message::SendWarning() << "Warning in the DEBRepCascade_Provider during writing the file " << - thePath << "\t: Target Units for writing were changed, but current format doesn't support scaling"; - } - if (aNode->InternalParameters.WriteBinary) - { - if (aNode->InternalParameters.WriteVersionBin > static_cast(BinTools_FormatVersion_UPPER) || - aNode->InternalParameters.WriteVersionBin < static_cast(BinTools_FormatVersion_LOWER)) - { - Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << - thePath << "\t: Unknown format version"; - return false; - } - if (aNode->InternalParameters.WriteNormals && - aNode->InternalParameters.WriteVersionBin < BinTools_FormatVersion_VERSION_4) - { - Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << - thePath << "\t: Vertex normals require binary format version 4 or later"; - return false; - } - - if (!BinTools::Write(theShape, thePath.ToCString(), aNode->InternalParameters.WriteTriangles, - aNode->InternalParameters.WriteNormals, aNode->InternalParameters.WriteVersionBin, theProgress)) - { - Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << - thePath << "\t: Cannot write the file"; - return false; - } - } - else - { - if (aNode->InternalParameters.WriteVersionAscii > static_cast(TopTools_FormatVersion_UPPER) || - aNode->InternalParameters.WriteVersionAscii < static_cast(TopTools_FormatVersion_LOWER)) - { - Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << - thePath << "\t: Unknown format version"; - return false; - } - if (aNode->InternalParameters.WriteNormals && - aNode->InternalParameters.WriteVersionAscii < TopTools_FormatVersion_VERSION_3) - { - Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << - thePath << "\t: Error: vertex normals require ascii format version 3 or later"; - return false; - } - if (!BRepTools::Write(theShape, thePath.ToCString(), aNode->InternalParameters.WriteTriangles, - aNode->InternalParameters.WriteNormals, aNode->InternalParameters.WriteVersionAscii, theProgress)) - { - Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << - thePath << "\t: Cannot write the file"; - return false; - } - } - - return true; -} - -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString DEBRepCascade_Provider::GetFormat() const -{ - return TCollection_AsciiString("BREP"); -} - -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString DEBRepCascade_Provider::GetVendor() const -{ - return TCollection_AsciiString("OCC"); -} diff --git a/src/DEBRepCascade/DEBRepCascade_Provider.hxx b/src/DEBRepCascade/DEBRepCascade_Provider.hxx index 423cfebf8b..43e37fb343 100644 --- a/src/DEBRepCascade/DEBRepCascade_Provider.hxx +++ b/src/DEBRepCascade/DEBRepCascade_Provider.hxx @@ -14,123 +14,9 @@ #ifndef _DEBRepCascade_Provider_HeaderFile #define _DEBRepCascade_Provider_HeaderFile -#include +#include -//! The class to transfer BRep files. -//! Reads and Writes any BRep files into/from OCCT. -//! Each operation needs configuration node. -//! -//! Providers grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "BREP" -//! The import process is supported. -//! The export process is supported. -class DEBRepCascade_Provider : public DE_Provider -{ -public: - DEFINE_STANDARD_RTTIEXT(DEBRepCascade_Provider, DE_Provider) - -public: - - //! Default constructor - //! Configure translation process with global configuration - Standard_EXPORT DEBRepCascade_Provider(); - - //! Configure translation process - //! @param[in] theNode object to init the DE_Provider - Standard_EXPORT DEBRepCascade_Provider(const Handle(DE_ConfigurationNode)& theNode); - -public: - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - -public: - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DEBREP_Provider DEBRepCascade_Provider; #endif // _DEBRepCascade_Provider_HeaderFile diff --git a/src/DEBRepCascade/FILES b/src/DEBRepCascade/FILES index e325744990..a3c04ebe58 100644 --- a/src/DEBRepCascade/FILES +++ b/src/DEBRepCascade/FILES @@ -1,4 +1,2 @@ -DEBRepCascade_ConfigurationNode.cxx DEBRepCascade_ConfigurationNode.hxx -DEBRepCascade_Provider.cxx DEBRepCascade_Provider.hxx diff --git a/src/RWGltf/RWGltf_ConfigurationNode.cxx b/src/DEGLTF/DEGLTF_ConfigurationNode.cxx similarity index 58% rename from src/RWGltf/RWGltf_ConfigurationNode.cxx rename to src/DEGLTF/DEGLTF_ConfigurationNode.cxx index afdd542b77..f20cb4ceef 100644 --- a/src/RWGltf/RWGltf_ConfigurationNode.cxx +++ b/src/DEGLTF/DEGLTF_ConfigurationNode.cxx @@ -11,125 +11,151 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include +#include #include #include -#include -IMPLEMENT_STANDARD_RTTIEXT(RWGltf_ConfigurationNode, DE_ConfigurationNode) +IMPLEMENT_STANDARD_RTTIEXT(DEGLTF_ConfigurationNode, DE_ConfigurationNode) namespace { - static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() - { - static const TCollection_AsciiString aScope = "provider"; - return aScope; - } - - // Wrapper to auto-load DE component - DE_PluginHolder THE_OCCT_GLTF_COMPONENT_PLUGIN; +static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() +{ + static const TCollection_AsciiString aScope = "provider"; + return aScope; +} + +// Wrapper to auto-load DE component +DE_PluginHolder THE_OCCT_GLTF_COMPONENT_PLUGIN; +} // namespace + +//================================================================================================= + +DEGLTF_ConfigurationNode::DEGLTF_ConfigurationNode() + : DE_ConfigurationNode() +{ } -//======================================================================= -// function : RWGltf_ConfigurationNode -// purpose : -//======================================================================= -RWGltf_ConfigurationNode::RWGltf_ConfigurationNode() : - DE_ConfigurationNode() -{} - -//======================================================================= -// function : RWGltf_ConfigurationNode -// purpose : -//======================================================================= -RWGltf_ConfigurationNode::RWGltf_ConfigurationNode(const Handle(RWGltf_ConfigurationNode)& theNode) - :DE_ConfigurationNode(theNode) +//================================================================================================= + +DEGLTF_ConfigurationNode::DEGLTF_ConfigurationNode(const Handle(DEGLTF_ConfigurationNode)& theNode) + : DE_ConfigurationNode(theNode) { InternalParameters = theNode->InternalParameters; } -//======================================================================= -// function : Load -// purpose : -//======================================================================= -bool RWGltf_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) +//================================================================================================= + +bool DEGLTF_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) { - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); - InternalParameters.FileLengthUnit = + InternalParameters.FileLengthUnit = theResource->RealVal("file.length.unit", InternalParameters.FileLengthUnit, aScope); - InternalParameters.SystemCS = (RWMesh_CoordinateSystem) - (theResource->IntegerVal("system.cs", (int)InternalParameters.SystemCS, aScope) % 2); - InternalParameters.FileCS = (RWMesh_CoordinateSystem) - (theResource->IntegerVal("file.cs", (int)InternalParameters.SystemCS, aScope) % 2); - - InternalParameters.ReadSinglePrecision = - theResource->BooleanVal("read.single.precision", InternalParameters.ReadSinglePrecision, aScope); - InternalParameters.ReadCreateShapes = + InternalParameters.SystemCS = + (RWMesh_CoordinateSystem)(theResource->IntegerVal("system.cs", + (int)InternalParameters.SystemCS, + aScope) + % 2); + InternalParameters.FileCS = + (RWMesh_CoordinateSystem)(theResource->IntegerVal("file.cs", + (int)InternalParameters.SystemCS, + aScope) + % 2); + + InternalParameters.ReadSinglePrecision = + theResource->BooleanVal("read.single.precision", + InternalParameters.ReadSinglePrecision, + aScope); + InternalParameters.ReadCreateShapes = theResource->BooleanVal("read.create.shapes", InternalParameters.ReadCreateShapes, aScope); - InternalParameters.ReadRootPrefix = + InternalParameters.ReadRootPrefix = theResource->StringVal("read.root.prefix", InternalParameters.ReadRootPrefix, aScope); - InternalParameters.ReadFillDoc = + InternalParameters.ReadFillDoc = theResource->BooleanVal("read.fill.doc", InternalParameters.ReadFillDoc, aScope); - InternalParameters.ReadFillIncomplete = + InternalParameters.ReadFillIncomplete = theResource->BooleanVal("read.fill.incomplete", InternalParameters.ReadFillIncomplete, aScope); - InternalParameters.ReadMemoryLimitMiB = + InternalParameters.ReadMemoryLimitMiB = theResource->IntegerVal("read.memory.limit.mib", InternalParameters.ReadMemoryLimitMiB, aScope); - InternalParameters.ReadParallel = + InternalParameters.ReadParallel = theResource->BooleanVal("read.parallel", InternalParameters.ReadParallel, aScope); - InternalParameters.ReadSkipEmptyNodes = + InternalParameters.ReadSkipEmptyNodes = theResource->BooleanVal("read.skip.empty.nodes", InternalParameters.ReadSkipEmptyNodes, aScope); - InternalParameters.ReadLoadAllScenes = + InternalParameters.ReadLoadAllScenes = theResource->BooleanVal("read.load.all.scenes", InternalParameters.ReadLoadAllScenes, aScope); - InternalParameters.ReadUseMeshNameAsFallback = - theResource->BooleanVal("read.use.mesh.name.as.fallback", InternalParameters.ReadUseMeshNameAsFallback, aScope); - InternalParameters.ReadSkipLateDataLoading = - theResource->BooleanVal("read.skip.late.data.loading", InternalParameters.ReadSkipLateDataLoading, aScope); - InternalParameters.ReadKeepLateData = + InternalParameters.ReadUseMeshNameAsFallback = + theResource->BooleanVal("read.use.mesh.name.as.fallback", + InternalParameters.ReadUseMeshNameAsFallback, + aScope); + InternalParameters.ReadSkipLateDataLoading = + theResource->BooleanVal("read.skip.late.data.loading", + InternalParameters.ReadSkipLateDataLoading, + aScope); + InternalParameters.ReadKeepLateData = theResource->BooleanVal("read.keep.late.data", InternalParameters.ReadKeepLateData, aScope); - InternalParameters.ReadPrintDebugMessages = - theResource->BooleanVal("read.print.debug.message", InternalParameters.ReadPrintDebugMessages, aScope); + InternalParameters.ReadPrintDebugMessages = + theResource->BooleanVal("read.print.debug.message", + InternalParameters.ReadPrintDebugMessages, + aScope); - InternalParameters.WriteComment = + InternalParameters.WriteComment = theResource->StringVal("write.comment", InternalParameters.WriteComment, aScope); - InternalParameters.WriteAuthor = + InternalParameters.WriteAuthor = theResource->StringVal("write.author", InternalParameters.WriteAuthor, aScope); - InternalParameters.WriteTrsfFormat = (RWGltf_WriterTrsfFormat) - (theResource->IntegerVal("write.trsf.format", InternalParameters.WriteTrsfFormat, aScope) % (RWGltf_WriterTrsfFormat_UPPER + 1)); - InternalParameters.WriteNodeNameFormat = (RWMesh_NameFormat) - (theResource->IntegerVal("write.node.name.format", InternalParameters.WriteNodeNameFormat, aScope) % (RWMesh_NameFormat_ProductAndInstanceAndOcaf + 1)); - InternalParameters.WriteMeshNameFormat = (RWMesh_NameFormat) - (theResource->IntegerVal("write.mesh.name.format", InternalParameters.WriteMeshNameFormat, aScope) % (RWMesh_NameFormat_ProductAndInstanceAndOcaf + 1)); - InternalParameters.WriteForcedUVExport = - theResource->BooleanVal("write.forced.uv.export", InternalParameters.WriteForcedUVExport, aScope); - InternalParameters.WriteEmbedTexturesInGlb = - theResource->BooleanVal("write.embed.textures.in.glb", InternalParameters.WriteEmbedTexturesInGlb, aScope); - InternalParameters.WriteMergeFaces = + InternalParameters.WriteTrsfFormat = + (RWGltf_WriterTrsfFormat)(theResource->IntegerVal("write.trsf.format", + InternalParameters.WriteTrsfFormat, + aScope) + % (RWGltf_WriterTrsfFormat_UPPER + 1)); + InternalParameters.WriteNodeNameFormat = + (RWMesh_NameFormat)(theResource->IntegerVal("write.node.name.format", + InternalParameters.WriteNodeNameFormat, + aScope) + % (RWMesh_NameFormat_ProductAndInstanceAndOcaf + 1)); + InternalParameters.WriteMeshNameFormat = + (RWMesh_NameFormat)(theResource->IntegerVal("write.mesh.name.format", + InternalParameters.WriteMeshNameFormat, + aScope) + % (RWMesh_NameFormat_ProductAndInstanceAndOcaf + 1)); + InternalParameters.WriteForcedUVExport = + theResource->BooleanVal("write.forced.uv.export", + InternalParameters.WriteForcedUVExport, + aScope); + InternalParameters.WriteEmbedTexturesInGlb = + theResource->BooleanVal("write.embed.textures.in.glb", + InternalParameters.WriteEmbedTexturesInGlb, + aScope); + InternalParameters.WriteMergeFaces = theResource->BooleanVal("write.merge.faces", InternalParameters.WriteMergeFaces, aScope); - InternalParameters.WriteSplitIndices16 = - theResource->BooleanVal("write.split.indices16", InternalParameters.WriteSplitIndices16, aScope); + InternalParameters.WriteSplitIndices16 = + theResource->BooleanVal("write.split.indices16", + InternalParameters.WriteSplitIndices16, + aScope); return true; } -//======================================================================= -// function : Save -// purpose : -//======================================================================= -TCollection_AsciiString RWGltf_ConfigurationNode::Save() const +//================================================================================================= + +TCollection_AsciiString DEGLTF_ConfigurationNode::Save() const { TCollection_AsciiString aResult; aResult += "!*****************************************************************************\n"; - aResult = aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; + aResult = + aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; aResult += "!\n"; aResult += "!Common parameters:\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!File length units to convert from while reading the file, defined as scale factor for m (meters)\n"; + aResult += "!File length units to convert from while reading the file, defined as scale factor " + "for m (meters)\n"; aResult += "!Default value: 1.0(M)\n"; aResult += aScope + "file.length.unit :\t " + InternalParameters.FileLengthUnit + "\n"; aResult += "!\n"; @@ -164,7 +190,8 @@ TCollection_AsciiString RWGltf_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Root folder for generating root labels names\n"; - aResult += "!Default value: ""(empty). Available values: \n"; + aResult += "!Default value: " + "(empty). Available values: \n"; aResult += aScope + "read.root.prefix :\t " + InternalParameters.ReadRootPrefix + "\n"; aResult += "!\n"; @@ -175,7 +202,8 @@ TCollection_AsciiString RWGltf_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!\n"; - aResult += "!Flag for fill the document with partially retrieved data even if reader has fa-iled with er-ror\n"; + aResult += "!Flag for fill the document with partially retrieved data even if reader has fa-iled " + "with er-ror\n"; aResult += "!Default value: 1(true). Available values: 0(false), 1(true)\n"; aResult += aScope + "read.fill.incomplete :\t " + InternalParameters.ReadFillIncomplete + "\n"; aResult += "!\n"; @@ -207,17 +235,20 @@ TCollection_AsciiString RWGltf_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Flag to use Mesh name in case if Node name is empty\n"; aResult += "!Default value: 1(true). Available values: 0(false), 1(true)\n"; - aResult += aScope + "read.use.mesh.name.as.fallback :\t " + InternalParameters.ReadUseMeshNameAsFallback + "\n"; + aResult += aScope + "read.use.mesh.name.as.fallback :\t " + + InternalParameters.ReadUseMeshNameAsFallback + "\n"; aResult += "!\n"; aResult += "!\n"; aResult += "!Flag to skip triangulation loading\n"; aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n"; - aResult += aScope + "read.skip.late.data.loading :\t " + InternalParameters.ReadSkipLateDataLoading + "\n"; + aResult += + aScope + "read.skip.late.data.loading :\t " + InternalParameters.ReadSkipLateDataLoading + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!Flag to keep information about deferred storage to load/unload triangulation later\n"; + aResult += + "!Flag to keep information about deferred storage to load/unload triangulation later\n"; aResult += "!Default value: 1(true). Available values: 0(false), 1(true)\n"; aResult += aScope + "read.keep.late.data :\t " + InternalParameters.ReadKeepLateData + "\n"; aResult += "!\n"; @@ -225,7 +256,8 @@ TCollection_AsciiString RWGltf_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Flag to print additional debug information\n"; aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n"; - aResult += aScope + "read.print.debug.message :\t " + InternalParameters.ReadPrintDebugMessages + "\n"; + aResult += + aScope + "read.print.debug.message :\t " + InternalParameters.ReadPrintDebugMessages + "\n"; aResult += "!\n"; aResult += "!\n"; @@ -234,13 +266,15 @@ TCollection_AsciiString RWGltf_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Export special comment\n"; - aResult += "!Default value: ""(empty). Available values: \n"; + aResult += "!Default value: " + "(empty). Available values: \n"; aResult += aScope + "write.comment :\t " + InternalParameters.WriteComment + "\n"; aResult += "!\n"; aResult += "!\n"; aResult += "!Author of exported file name\n"; - aResult += "!Default value: ""(empty). Available values: \n"; + aResult += "!Default value: " + "(empty). Available values: \n"; aResult += aScope + "write.author :\t " + InternalParameters.WriteAuthor + "\n"; aResult += "!\n"; @@ -252,13 +286,17 @@ TCollection_AsciiString RWGltf_ConfigurationNode::Save() const aResult += "!\n"; aResult += "! Name format for exporting Nodes\n"; - aResult += "!Default value: 3(InstanceOrProduct). Available values: 0(Compact), 1(Mat4), 2(TRS), 3(InstanceOrProduct), 4(ProductOrInstance), 5(ProductAndInstance), 6(ProductAndInstanceAndOcaf)\n"; + aResult += "!Default value: 3(InstanceOrProduct). Available values: 0(Compact), 1(Mat4), 2(TRS), " + "3(InstanceOrProduct), 4(ProductOrInstance), 5(ProductAndInstance), " + "6(ProductAndInstanceAndOcaf)\n"; aResult += aScope + "write.node.name.format :\t " + InternalParameters.WriteNodeNameFormat + "\n"; aResult += "!\n"; aResult += "!\n"; aResult += "!Name format for exporting Meshes\n"; - aResult += "!Default value: 1(Product). Available values: 0(Compact), 1(Mat4), 2(TRS), 3(InstanceOrProduct), 4(ProductOrInstance), 5(ProductAndInstance), 6(ProductAndInstanceAndOcaf)\n"; + aResult += "!Default value: 1(Product). Available values: 0(Compact), 1(Mat4), 2(TRS), " + "3(InstanceOrProduct), 4(ProductOrInstance), 5(ProductAndInstance), " + "6(ProductAndInstanceAndOcaf)\n"; aResult += aScope + "write.mesh.name.format :\t " + InternalParameters.WriteMeshNameFormat + "\n"; aResult += "!\n"; @@ -271,7 +309,8 @@ TCollection_AsciiString RWGltf_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Flag to write image textures into GLB file\n"; aResult += "!Default value: 1(true). Available values: 0(false), 1(true)\n"; - aResult += aScope + "write.embed.textures.in.glb :\t " + InternalParameters.WriteEmbedTexturesInGlb + "\n"; + aResult += + aScope + "write.embed.textures.in.glb :\t " + InternalParameters.WriteEmbedTexturesInGlb + "\n"; aResult += "!\n"; aResult += "!\n"; @@ -290,65 +329,51 @@ TCollection_AsciiString RWGltf_ConfigurationNode::Save() const return aResult; } -//======================================================================= -// function : Copy -// purpose : -//======================================================================= -Handle(DE_ConfigurationNode) RWGltf_ConfigurationNode::Copy() const +//================================================================================================= + +Handle(DE_ConfigurationNode) DEGLTF_ConfigurationNode::Copy() const { - return new RWGltf_ConfigurationNode(*this); + return new DEGLTF_ConfigurationNode(*this); } -//======================================================================= -// function : BuildProvider -// purpose : -//======================================================================= -Handle(DE_Provider) RWGltf_ConfigurationNode::BuildProvider() +//================================================================================================= + +Handle(DE_Provider) DEGLTF_ConfigurationNode::BuildProvider() { - return new RWGltf_Provider(this); + return new DEGLTF_Provider(this); } -//======================================================================= -// function : IsImportSupported -// purpose : -//======================================================================= -bool RWGltf_ConfigurationNode::IsImportSupported() const +//================================================================================================= + +bool DEGLTF_ConfigurationNode::IsImportSupported() const { return true; } -//======================================================================= -// function : IsExportSupported -// purpose : -//======================================================================= -bool RWGltf_ConfigurationNode::IsExportSupported() const +//================================================================================================= + +bool DEGLTF_ConfigurationNode::IsExportSupported() const { return true; } -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString RWGltf_ConfigurationNode::GetFormat() const +//================================================================================================= + +TCollection_AsciiString DEGLTF_ConfigurationNode::GetFormat() const { return TCollection_AsciiString("GLTF"); } -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString RWGltf_ConfigurationNode::GetVendor() const +//================================================================================================= + +TCollection_AsciiString DEGLTF_ConfigurationNode::GetVendor() const { return TCollection_AsciiString("OCC"); } -//======================================================================= -// function : GetExtensions -// purpose : -//======================================================================= -TColStd_ListOfAsciiString RWGltf_ConfigurationNode::GetExtensions() const +//================================================================================================= + +TColStd_ListOfAsciiString DEGLTF_ConfigurationNode::GetExtensions() const { TColStd_ListOfAsciiString anExt; anExt.Append("gltf"); diff --git a/src/DEGLTF/DEGLTF_ConfigurationNode.hxx b/src/DEGLTF/DEGLTF_ConfigurationNode.hxx new file mode 100644 index 0000000000..72fafaeab2 --- /dev/null +++ b/src/DEGLTF/DEGLTF_ConfigurationNode.hxx @@ -0,0 +1,118 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEGLTF_ConfigurationNode_HeaderFile +#define _DEGLTF_ConfigurationNode_HeaderFile + +#include +#include +#include +#include + +//! The purpose of this class is to configure the transfer process for glTF format +//! Stores the necessary settings for DEGLTF_Provider. +//! Configures and creates special provider to transfer glTF files. +//! +//! Nodes grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "GLTF" +//! The supported CAD extensions are ".gltf", ".glb" +//! The import process is supported. +//! The export process is supported. +class DEGLTF_ConfigurationNode : public DE_ConfigurationNode +{ + DEFINE_STANDARD_RTTIEXT(DEGLTF_ConfigurationNode, DE_ConfigurationNode) +public: + //! Initializes all field by default + Standard_EXPORT DEGLTF_ConfigurationNode(); + + //! Copies values of all fields + //! @param[in] theNode object to copy + Standard_EXPORT DEGLTF_ConfigurationNode(const Handle(DEGLTF_ConfigurationNode)& theNode); + + //! Updates values according the resource + //! @param[in] theResource input resource to use + //! @return true if theResource loading has ended correctly + Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) + Standard_OVERRIDE; + + //! Writes configuration to the string + //! @return result resource string + Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; + + //! Copies values of all fields + //! @return new object with the same field values + Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; + + //! Creates new provider for the own format + //! @return new created provider + Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; + +public: + //! Checks the import supporting + //! @return true if import is supported + Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; + + //! Checks the export supporting + //! @return true if export is supported + Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; + + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; + + //! Gets list of supported file extensions + //! @return list of extensions + Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; + +public: + struct RWGltf_InternalSection + { + // Common + // clang-format off + double FileLengthUnit = 1.; //!< File length units to convert from while reading the file, defined as scale factor for m (meters) + RWMesh_CoordinateSystem SystemCS = RWMesh_CoordinateSystem_Zup; //!< System origin coordinate system to perform conversion into during read + RWMesh_CoordinateSystem FileCS = RWMesh_CoordinateSystem_Yup; //!< File origin coordinate system to perform conversion during read + // Reading + bool ReadSinglePrecision = true; //!< Flag for reading vertex data with single or double floating point precision + bool ReadCreateShapes = false; //!< Flag for create a single triangulation + TCollection_AsciiString ReadRootPrefix; //!< Root folder for generating root labels names + bool ReadFillDoc = true; //!< Flag for fill document from shape sequence + bool ReadFillIncomplete = true; //!< Flag for fill the document with partially retrieved data even if reader has failed with error + int ReadMemoryLimitMiB = -1; //!< Memory usage limit + bool ReadParallel = false; //!< Flag to use multithreading + bool ReadSkipEmptyNodes = true; //!< Flag to ignore nodes without Geometry + bool ReadLoadAllScenes = false; //!< Flag to load all scenes in the document + bool ReadUseMeshNameAsFallback = true; //!< Flag to use Mesh name in case if Node name is empty + bool ReadSkipLateDataLoading = false; //!< Flag to skip triangulation loading + bool ReadKeepLateData = true;//!< Flag to keep information about deferred storage to load/unload triangulation later + bool ReadPrintDebugMessages = false; //!< Flag to print additional debug information + // Writing + TCollection_AsciiString WriteComment; //!< Export special comment + TCollection_AsciiString WriteAuthor; //!< Author of exported file name + RWGltf_WriterTrsfFormat WriteTrsfFormat = RWGltf_WriterTrsfFormat_Compact; //!< Transformation format to write into glTF file + RWMesh_NameFormat WriteNodeNameFormat = RWMesh_NameFormat_InstanceOrProduct; //!< Name format for exporting Nodes + RWMesh_NameFormat WriteMeshNameFormat = RWMesh_NameFormat_Product; //!< Name format for exporting Meshes + bool WriteForcedUVExport = false; //!< Export UV coordinates even if there are no mapped texture + bool WriteEmbedTexturesInGlb = true; //!< Flag to write image textures into GLB file + bool WriteMergeFaces = false; //!< Flag to merge faces within a single part + bool WriteSplitIndices16 = false; //!< Flag to prefer keeping 16-bit indexes while merging face + // clang-format on + } InternalParameters; +}; + +#endif // _DEGLTF_ConfigurationNode_HeaderFile diff --git a/src/DEGLTF/DEGLTF_Provider.cxx b/src/DEGLTF/DEGLTF_Provider.cxx new file mode 100644 index 0000000000..5ca76abfd2 --- /dev/null +++ b/src/DEGLTF/DEGLTF_Provider.cxx @@ -0,0 +1,249 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include + +namespace +{ +//================================================================================================= + +static void SetReaderParameters(RWGltf_CafReader& theReader, + const Handle(DEGLTF_ConfigurationNode)& theNode) +{ + theReader.SetDoublePrecision(!theNode->InternalParameters.ReadSinglePrecision); + theReader.SetSystemLengthUnit(theNode->GlobalParameters.LengthUnit / 1000); + theReader.SetSystemCoordinateSystem(theNode->InternalParameters.SystemCS); + theReader.SetFileLengthUnit(theNode->InternalParameters.FileLengthUnit); + theReader.SetFileCoordinateSystem(theNode->InternalParameters.FileCS); + theReader.SetRootPrefix(theNode->InternalParameters.ReadRootPrefix); + theReader.SetMemoryLimitMiB(theNode->InternalParameters.ReadMemoryLimitMiB); + + theReader.SetParallel(theNode->InternalParameters.ReadParallel); + theReader.SetSkipEmptyNodes(theNode->InternalParameters.ReadSkipEmptyNodes); + theReader.SetLoadAllScenes(theNode->InternalParameters.ReadLoadAllScenes); + theReader.SetMeshNameAsFallback(theNode->InternalParameters.ReadUseMeshNameAsFallback); + theReader.SetToSkipLateDataLoading(theNode->InternalParameters.ReadSkipLateDataLoading); + theReader.SetToKeepLateData(theNode->InternalParameters.ReadKeepLateData); + theReader.SetToPrintDebugMessages(theNode->InternalParameters.ReadPrintDebugMessages); +} +} // namespace + +IMPLEMENT_STANDARD_RTTIEXT(DEGLTF_Provider, DE_Provider) + +//================================================================================================= + +DEGLTF_Provider::DEGLTF_Provider() {} + +//================================================================================================= + +DEGLTF_Provider::DEGLTF_Provider(const Handle(DE_ConfigurationNode)& theNode) + : DE_Provider(theNode) +{ +} + +//================================================================================================= + +bool DEGLTF_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Read(thePath, theDocument, theProgress); +} + +//================================================================================================= + +bool DEGLTF_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Write(thePath, theDocument, theProgress); +} + +//================================================================================================= + +bool DEGLTF_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + if (theDocument.IsNull()) + { + Message::SendFail() << "Error in the DEGLTF_Provider during reading the file " << thePath + << "\t: theDocument shouldn't be null"; + return false; + } + if (GetNode().IsNull() + || (!GetNode().IsNull() && !GetNode()->IsKind(STANDARD_TYPE(DEGLTF_ConfigurationNode)))) + { + Message::SendFail() << "Error in the DEGLTF_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DEGLTF_ConfigurationNode) aNode = Handle(DEGLTF_ConfigurationNode)::DownCast(GetNode()); + RWGltf_CafReader aReader; + aReader.SetDocument(theDocument); + SetReaderParameters(aReader, aNode); + XCAFDoc_DocumentTool::SetLengthUnit(theDocument, + aNode->GlobalParameters.LengthUnit, + UnitsMethods_LengthUnit_Millimeter); + if (!aReader.Perform(thePath, theProgress)) + { + Message::SendFail() << "Error in the DEGLTF_Provider during reading the file " << thePath; + return false; + } + + return true; +} + +//================================================================================================= + +bool DEGLTF_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEGLTF_ConfigurationNode))) + { + Message::SendFail() << "Error in the DEGLTF_Provider during writing the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DEGLTF_ConfigurationNode) aNode = Handle(DEGLTF_ConfigurationNode)::DownCast(GetNode()); + + RWMesh_CoordinateSystemConverter aConverter; + Standard_Real aScaleFactorM = 1.; + if (!XCAFDoc_DocumentTool::GetLengthUnit(theDocument, aScaleFactorM)) + { + aConverter.SetInputLengthUnit(aNode->GlobalParameters.SystemUnit / 1000.); + Message::SendWarning() + << "Warning in the DEGLTF_Provider during writing the file " << thePath + << "\t: The document has no information on Units. Using global parameter as initial Unit."; + } + aConverter.SetInputCoordinateSystem(aNode->InternalParameters.SystemCS); + if (aNode->GlobalParameters.LengthUnit != 1000.) + { + Message::SendWarning() + << "Warning in the DEGLTF_Provider during writing the file " << thePath + << "\t: Target format doesn't support custom units. Model will be scaled to Meters"; + } + aConverter.SetOutputLengthUnit(1.); // gltf units always Meters + aConverter.SetOutputCoordinateSystem(aNode->InternalParameters.FileCS); + + TColStd_IndexedDataMapOfStringString aFileInfo; + if (!aNode->InternalParameters.WriteAuthor.IsEmpty()) + { + aFileInfo.Add("Author", aNode->InternalParameters.WriteAuthor); + } + if (!aNode->InternalParameters.WriteComment.IsEmpty()) + { + aFileInfo.Add("Comments", aNode->InternalParameters.WriteComment); + } + + TCollection_AsciiString anExt = thePath; + anExt.LowerCase(); + RWGltf_CafWriter aWriter(thePath, anExt.EndsWith(".glb")); + aWriter.SetCoordinateSystemConverter(aConverter); + aWriter.SetTransformationFormat(aNode->InternalParameters.WriteTrsfFormat); + aWriter.SetNodeNameFormat(aNode->InternalParameters.WriteNodeNameFormat); + aWriter.SetMeshNameFormat(aNode->InternalParameters.WriteMeshNameFormat); + aWriter.SetForcedUVExport(aNode->InternalParameters.WriteForcedUVExport); + aWriter.SetToEmbedTexturesInGlb(aNode->InternalParameters.WriteEmbedTexturesInGlb); + aWriter.SetMergeFaces(aNode->InternalParameters.WriteMergeFaces); + aWriter.SetSplitIndices16(aNode->InternalParameters.WriteSplitIndices16); + if (!aWriter.Perform(theDocument, aFileInfo, theProgress)) + { + Message::SendFail() << "Error in the DEGLTF_Provider during writing the file " << thePath; + return false; + } + return true; +} + +//================================================================================================= + +bool DEGLTF_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Read(thePath, theShape, theProgress); +} + +//================================================================================================= + +bool DEGLTF_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Write(thePath, theShape, theProgress); +} + +//================================================================================================= + +bool DEGLTF_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEGLTF_ConfigurationNode))) + { + Message::SendFail() << "Error in the DEGLTF_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DEGLTF_ConfigurationNode) aNode = Handle(DEGLTF_ConfigurationNode)::DownCast(GetNode()); + RWGltf_CafReader aReader; + SetReaderParameters(aReader, aNode); + if (!aReader.Perform(thePath, theProgress)) + { + Message::SendFail() << "Error in the DEGLTF_Provider during reading the file " << thePath; + return false; + } + theShape = aReader.SingleShape(); + return true; +} + +//================================================================================================= + +bool DEGLTF_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF"); + Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main()); + aShTool->AddShape(theShape); + return Write(thePath, aDoc, theProgress); +} + +//================================================================================================= + +TCollection_AsciiString DEGLTF_Provider::GetFormat() const +{ + return TCollection_AsciiString("GLTF"); +} + +//================================================================================================= + +TCollection_AsciiString DEGLTF_Provider::GetVendor() const +{ + return TCollection_AsciiString("OCC"); +} diff --git a/src/DEGLTF/DEGLTF_Provider.hxx b/src/DEGLTF/DEGLTF_Provider.hxx new file mode 100644 index 0000000000..7c591a2dcb --- /dev/null +++ b/src/DEGLTF/DEGLTF_Provider.hxx @@ -0,0 +1,143 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEGLTF_Provider_HeaderFile +#define _DEGLTF_Provider_HeaderFile + +#include +#include +#include + +//! The class to transfer glTF files. +//! Reads and Writes any glTF files into/from OCCT. +//! Each operation needs configuration node. +//! +//! Providers grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "GLTF" +//! The import process is supported. +//! The export process is supported. +class DEGLTF_Provider : public DE_Provider +{ +public: + DEFINE_STANDARD_RTTIEXT(DEGLTF_Provider, DE_Provider) + +public: + //! Default constructor + //! Configure translation process with global configuration + Standard_EXPORT DEGLTF_Provider(); + + //! Configure translation process + //! @param[in] theNode object to copy + Standard_EXPORT DEGLTF_Provider(const Handle(DE_ConfigurationNode)& theNode); + +public: + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + +public: + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; +}; + +#endif // _DEGLTF_Provider_HeaderFile diff --git a/src/DEGLTF/FILES b/src/DEGLTF/FILES new file mode 100644 index 0000000000..5f62c6a11e --- /dev/null +++ b/src/DEGLTF/FILES @@ -0,0 +1,4 @@ +DEGLTF_ConfigurationNode.cxx +DEGLTF_ConfigurationNode.hxx +DEGLTF_Provider.cxx +DEGLTF_Provider.hxx diff --git a/src/IGESCAFControl/IGESCAFControl_ConfigurationNode.cxx b/src/DEIGES/DEIGES_ConfigurationNode.cxx similarity index 66% rename from src/IGESCAFControl/IGESCAFControl_ConfigurationNode.cxx rename to src/DEIGES/DEIGES_ConfigurationNode.cxx index 3a4217e703..c47dd65502 100644 --- a/src/IGESCAFControl/IGESCAFControl_ConfigurationNode.cxx +++ b/src/DEIGES/DEIGES_ConfigurationNode.cxx @@ -11,91 +11,101 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include +#include #include #include -#include #include -IMPLEMENT_STANDARD_RTTIEXT(IGESCAFControl_ConfigurationNode, DE_ConfigurationNode) +IMPLEMENT_STANDARD_RTTIEXT(DEIGES_ConfigurationNode, DE_ConfigurationNode) namespace { - static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() - { - static const TCollection_AsciiString aScope = "provider"; - return aScope; - } +static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() +{ + static const TCollection_AsciiString aScope = "provider"; + return aScope; +} + +// Wrapper to auto-load DE component +DE_PluginHolder THE_OCCT_IGES_COMPONENT_PLUGIN; +} // namespace - // Wrapper to auto-load DE component - DE_PluginHolder THE_OCCT_IGES_COMPONENT_PLUGIN; +//================================================================================================= + +DEIGES_ConfigurationNode::DEIGES_ConfigurationNode() + : DE_ConfigurationNode() +{ } -//======================================================================= -// function : IGESCAFControl_ConfigurationNode -// purpose : -//======================================================================= -IGESCAFControl_ConfigurationNode::IGESCAFControl_ConfigurationNode() : - DE_ConfigurationNode() -{} - -//======================================================================= -// function : IGESCAFControl_ConfigurationNode -// purpose : -//======================================================================= -IGESCAFControl_ConfigurationNode::IGESCAFControl_ConfigurationNode(const Handle(IGESCAFControl_ConfigurationNode)& theNode) - :DE_ConfigurationNode(theNode) +//================================================================================================= + +DEIGES_ConfigurationNode::DEIGES_ConfigurationNode(const Handle(DEIGES_ConfigurationNode)& theNode) + : DE_ConfigurationNode(theNode) { InternalParameters = theNode->InternalParameters; } -//======================================================================= -// function : Load -// purpose : -//======================================================================= -bool IGESCAFControl_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) -{ - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); +//================================================================================================= - InternalParameters.ReadBSplineContinuity = (ReadMode_BSplineContinuity) - theResource->IntegerVal("read.iges.bspline.continuity", InternalParameters.ReadBSplineContinuity, aScope); - InternalParameters.ReadPrecisionMode = (ReadMode_Precision) - theResource->IntegerVal("read.precision.mode", InternalParameters.ReadPrecisionMode, aScope); +bool DEIGES_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) +{ + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); + + InternalParameters.ReadBSplineContinuity = + (ReadMode_BSplineContinuity)theResource->IntegerVal("read.iges.bspline.continuity", + InternalParameters.ReadBSplineContinuity, + aScope); + InternalParameters.ReadPrecisionMode = + (ReadMode_Precision)theResource->IntegerVal("read.precision.mode", + InternalParameters.ReadPrecisionMode, + aScope); InternalParameters.ReadPrecisionVal = theResource->RealVal("read.precision.val", InternalParameters.ReadPrecisionVal, aScope); - InternalParameters.ReadMaxPrecisionMode = (ReadMode_MaxPrecision) - theResource->IntegerVal("read.maxprecision.mode", InternalParameters.ReadMaxPrecisionMode, aScope); + InternalParameters.ReadMaxPrecisionMode = + (ReadMode_MaxPrecision)theResource->IntegerVal("read.maxprecision.mode", + InternalParameters.ReadMaxPrecisionMode, + aScope); InternalParameters.ReadMaxPrecisionVal = theResource->RealVal("read.maxprecision.val", InternalParameters.ReadMaxPrecisionVal, aScope); - InternalParameters.ReadSameParamMode = - theResource->BooleanVal("read.stdsameparameter.mode", InternalParameters.ReadSameParamMode, aScope); - InternalParameters.ReadSurfaceCurveMode = (ReadMode_SurfaceCurve) - theResource->IntegerVal("read.surfacecurve.mode", InternalParameters.ReadSurfaceCurveMode, aScope); + InternalParameters.ReadSameParamMode = + theResource->BooleanVal("read.stdsameparameter.mode", + InternalParameters.ReadSameParamMode, + aScope); + InternalParameters.ReadSurfaceCurveMode = + (ReadMode_SurfaceCurve)theResource->IntegerVal("read.surfacecurve.mode", + InternalParameters.ReadSurfaceCurveMode, + aScope); InternalParameters.EncodeRegAngle = theResource->RealVal("read.encoderegularity.angle", InternalParameters.EncodeRegAngle, aScope); - InternalParameters.ReadApproxd1 = + InternalParameters.ReadApproxd1 = theResource->BooleanVal("read.bspline.approxd1.mode", InternalParameters.ReadApproxd1, aScope); InternalParameters.ReadResourceName = theResource->StringVal("read.resource.name", InternalParameters.ReadResourceName, aScope); InternalParameters.ReadSequence = theResource->StringVal("read.sequence", InternalParameters.ReadSequence, aScope); - InternalParameters.ReadFaultyEntities = + InternalParameters.ReadFaultyEntities = theResource->BooleanVal("read.fau_lty.entities", InternalParameters.ReadFaultyEntities, aScope); - InternalParameters.ReadOnlyVisible = + InternalParameters.ReadOnlyVisible = theResource->BooleanVal("read.onlyvisible", InternalParameters.ReadOnlyVisible, aScope); - InternalParameters.ReadColor = + InternalParameters.ReadColor = theResource->BooleanVal("read.color", InternalParameters.ReadColor, aScope); - InternalParameters.ReadName = + InternalParameters.ReadName = theResource->BooleanVal("read.name", InternalParameters.ReadName, aScope); - InternalParameters.ReadLayer = + InternalParameters.ReadLayer = theResource->BooleanVal("read.layer", InternalParameters.ReadLayer, aScope); - InternalParameters.WriteBRepMode = (WriteMode_BRep) - theResource->IntegerVal("write.brep.mode", InternalParameters.WriteBRepMode, aScope); - InternalParameters.WriteConvertSurfaceMode = (WriteMode_ConvertSurface) - theResource->IntegerVal("write.convertsurface.mode", InternalParameters.WriteConvertSurfaceMode, aScope); + InternalParameters.WriteBRepMode = + (WriteMode_BRep)theResource->IntegerVal("write.brep.mode", + InternalParameters.WriteBRepMode, + aScope); + InternalParameters.WriteConvertSurfaceMode = + (WriteMode_ConvertSurface)theResource->IntegerVal("write.convertsurface.mode", + InternalParameters.WriteConvertSurfaceMode, + aScope); InternalParameters.WriteHeaderAuthor = theResource->StringVal("write.header.author", InternalParameters.WriteHeaderAuthor, aScope); InternalParameters.WriteHeaderCompany = @@ -108,34 +118,38 @@ bool IGESCAFControl_ConfigurationNode::Load(const Handle(DE_ConfigurationContext theResource->StringVal("write.resource.name", InternalParameters.WriteResourceName, aScope); InternalParameters.WriteSequence = theResource->StringVal("write.sequence", InternalParameters.WriteSequence, aScope); - InternalParameters.WritePrecisionMode = (WriteMode_PrecisionMode) - theResource->IntegerVal("write.precision.mode", InternalParameters.WritePrecisionMode, aScope); + InternalParameters.WritePrecisionMode = + (WriteMode_PrecisionMode)theResource->IntegerVal("write.precision.mode", + InternalParameters.WritePrecisionMode, + aScope); InternalParameters.WritePrecisionVal = theResource->RealVal("write.precision.val", InternalParameters.WritePrecisionVal, aScope); - InternalParameters.WritePlaneMode = (WriteMode_PlaneMode) - theResource->IntegerVal("write.plane.mode", InternalParameters.WritePlaneMode, aScope); - InternalParameters.WriteOffsetMode = + InternalParameters.WritePlaneMode = + (WriteMode_PlaneMode)theResource->IntegerVal("write.plane.mode", + InternalParameters.WritePlaneMode, + aScope); + InternalParameters.WriteOffsetMode = theResource->BooleanVal("write.offset", InternalParameters.WriteOffsetMode, aScope); - InternalParameters.WriteColor = + InternalParameters.WriteColor = theResource->BooleanVal("write.color", InternalParameters.WriteColor, aScope); - InternalParameters.WriteName = + InternalParameters.WriteName = theResource->BooleanVal("write.name", InternalParameters.WriteName, aScope); - InternalParameters.WriteLayer = + InternalParameters.WriteLayer = theResource->BooleanVal("write.layer", InternalParameters.WriteLayer, aScope); return true; } -//======================================================================= -// function : Save -// purpose : -//======================================================================= -TCollection_AsciiString IGESCAFControl_ConfigurationNode::Save() const +//================================================================================================= + +TCollection_AsciiString DEIGES_ConfigurationNode::Save() const { TCollection_AsciiString aResult; aResult += "!*****************************************************************************\n"; - aResult = aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; + aResult = + aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; aResult += "!\n"; aResult += "!Common parameters:\n"; @@ -145,7 +159,8 @@ TCollection_AsciiString IGESCAFControl_ConfigurationNode::Save() const aResult += "!Manages the continuity of BSpline curves (IGES entities 106, 112 and 126) "; aResult += "after translation to Open CASCADE Technology\n"; aResult += "!Default value: 1. Available values: 0, 1, 2\n"; - aResult += aScope + "read.iges.bspline.continuity :\t " + InternalParameters.ReadBSplineContinuity + "\n"; + aResult += + aScope + "read.iges.bspline.continuity :\t " + InternalParameters.ReadBSplineContinuity + "\n"; aResult += "!\n"; aResult += "!\n"; @@ -163,12 +178,15 @@ TCollection_AsciiString IGESCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Defines the mode of applying the maximum allowed tolerance\n"; - aResult += "!Default value: \"Preferred\"(0). Available values: \"Preferred\"(0), \"Forced\"(1)\n"; - aResult += aScope + "read.maxprecision.mode :\t " + InternalParameters.ReadMaxPrecisionMode + "\n"; + aResult += + "!Default value: \"Preferred\"(0). Available values: \"Preferred\"(0), \"Forced\"(1)\n"; + aResult += + aScope + "read.maxprecision.mode :\t " + InternalParameters.ReadMaxPrecisionMode + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!Defines the maximum allowable tolerance (in internal units, which are specified in xstep.cascade.unit)"; + aResult += "!Defines the maximum allowable tolerance (in internal units, which are specified in " + "xstep.cascade.unit)"; aResult += " of the shape\n"; aResult += "!Default value: 1. Available values: any real positive (non null) value\n"; aResult += aScope + "read.maxprecision.val :\t " + InternalParameters.ReadMaxPrecisionVal + "\n"; @@ -177,22 +195,28 @@ TCollection_AsciiString IGESCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Defines the using of BRepLib::SameParameter\n"; aResult += "!Default value: \"Off\"(0). Available values: \"Off\"(0), \"On\"(0)\n"; - aResult += aScope + "read.stdsameparameter.mode :\t " + InternalParameters.ReadSameParamMode + "\n"; + aResult += + aScope + "read.stdsameparameter.mode :\t " + InternalParameters.ReadSameParamMode + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!Preference for the computation of curves in case of 2D/3D inconsistency in an entity "; + aResult += + "!Preference for the computation of curves in case of 2D/3D inconsistency in an entity "; aResult += "which has both 2D and 3D representations.\n"; - aResult += "!Default value: \"Default\"(0). Available values: \"Default\"(0), \"2DUse_Preferred\"(2), "; + aResult += + "!Default value: \"Default\"(0). Available values: \"Default\"(0), \"2DUse_Preferred\"(2), "; aResult += "\"2DUse_Forced\"(-2), \"3DUse_Preferred\"(3), \"3DUse_Forced\"(-3)\n"; - aResult += aScope + "read.surfacecurve.mode :\t " + InternalParameters.ReadSurfaceCurveMode + "\n"; + aResult += + aScope + "read.surfacecurve.mode :\t " + InternalParameters.ReadSurfaceCurveMode + "\n"; aResult += "!\n"; aResult += "!\n"; aResult += "!This parameter is used within the BRepLib::EncodeRegularity() function "; aResult += "which is called for a shape read "; - aResult += "from an IGES or a STEP file at the end of translation process.This function sets the regularity flag of"; - aResult += " an edge in a shell when this edge is shared by two faces.This flag shows the continuity, "; + aResult += "from an IGES or a STEP file at the end of translation process.This function sets the " + "regularity flag of"; + aResult += + " an edge in a shell when this edge is shared by two faces.This flag shows the continuity, "; aResult += "which these two faces are connected with at that edge.\n"; aResult += "!Default value (in degrees): 0.57295779513. Available values: \n"; aResult += aScope + "read.encoderegularity.angle :\t " + InternalParameters.EncodeRegAngle + "\n"; @@ -203,8 +227,10 @@ TCollection_AsciiString IGESCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!\n"; - aResult += "!If set to True, it affects the translation of bspline curves of degree 1 from IGES: "; - aResult += "these curves(which geometrically are polylines) are split by duplicated points, and the translator "; + aResult += + "!If set to True, it affects the translation of bspline curves of degree 1 from IGES: "; + aResult += "these curves(which geometrically are polylines) are split by duplicated points, and " + "the translator "; aResult += "attempts to convert each of the obtained parts to a bspline of a higher continuity\n"; aResult += "!Default value: \"Off\"(0). Available values: \"Off\"(0), \"On\"(1)\n"; aResult += aScope + "read.bspline.approxd1.mode :\t " + InternalParameters.ReadApproxd1 + "\n"; @@ -229,7 +255,8 @@ TCollection_AsciiString IGESCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!\n"; - aResult += "!Controls transferring invisible sub entities which logically depend on the grouping entities\n"; + aResult += "!Controls transferring invisible sub entities which logically depend on the grouping " + "entities\n"; aResult += "!Default value: \"Off\"(0). Available values: \"Off\"(0), \"On\"(1)\n"; aResult += aScope + "read.onlyvisible :\t " + InternalParameters.ReadOnlyVisible + "\n"; aResult += "!\n"; @@ -263,11 +290,15 @@ TCollection_AsciiString IGESCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!\n"; - aResult += "!When writing to IGES in the BRep mode, this parameter indicates whether elementary surfaces"; - aResult += "(cylindrical, conical, spherical, and toroidal) are converted into corresponding IGES 5.3 entities"; - aResult += "(if the value of a parameter value is On), or written as surfaces of revolution(by default)\n"; + aResult += + "!When writing to IGES in the BRep mode, this parameter indicates whether elementary surfaces"; + aResult += "(cylindrical, conical, spherical, and toroidal) are converted into corresponding " + "IGES 5.3 entities"; + aResult += + "(if the value of a parameter value is On), or written as surfaces of revolution(by default)\n"; aResult += "!Default value: \"Off\"(0). Available values: \"Off\"(0), \"On\"(1)\n"; - aResult += aScope + "write.convertsurface.mode :\t " + InternalParameters.WriteConvertSurfaceMode + "\n"; + aResult += + aScope + "write.convertsurface.mode :\t " + InternalParameters.WriteConvertSurfaceMode + "\n"; aResult += "!\n"; aResult += "!\n"; @@ -278,7 +309,8 @@ TCollection_AsciiString IGESCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Gives the name of the sending company\n"; - aResult += "!Default value: ""(empty). Available values: \n"; + aResult += "!Default value: " + "(empty). Available values: \n"; aResult += aScope + "write.header.company :\t " + InternalParameters.WriteHeaderCompany + "\n"; aResult += "!\n"; @@ -292,7 +324,8 @@ TCollection_AsciiString IGESCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Gives the name of the receiving company\n"; - aResult += "!Default value: ""(empty). Available values: \n"; + aResult += "!Default value: " + "(empty). Available values: \n"; aResult += aScope + "write.header.receiver :\t " + InternalParameters.WriteHeaderReciever + "\n"; aResult += "!\n"; @@ -316,7 +349,8 @@ TCollection_AsciiString IGESCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!\n"; - aResult += "!This parameter gives the resolution value for an IGES file when the write.precision.mode parameter value is 1\n"; + aResult += "!This parameter gives the resolution value for an IGES file when the " + "write.precision.mode parameter value is 1\n"; aResult += "!Default value: 0.0001. Available values: any real positive (non null) value\n"; aResult += aScope + "write.precision.val :\t " + InternalParameters.WritePrecisionVal + "\n"; aResult += "!\n"; @@ -355,65 +389,51 @@ TCollection_AsciiString IGESCAFControl_ConfigurationNode::Save() const return aResult; } -//======================================================================= -// function : Copy -// purpose : -//======================================================================= -Handle(DE_ConfigurationNode) IGESCAFControl_ConfigurationNode::Copy() const +//================================================================================================= + +Handle(DE_ConfigurationNode) DEIGES_ConfigurationNode::Copy() const { - return new IGESCAFControl_ConfigurationNode(*this); + return new DEIGES_ConfigurationNode(*this); } -//======================================================================= -// function : BuildProvider -// purpose : -//======================================================================= -Handle(DE_Provider) IGESCAFControl_ConfigurationNode::BuildProvider() +//================================================================================================= + +Handle(DE_Provider) DEIGES_ConfigurationNode::BuildProvider() { - return new IGESCAFControl_Provider(this); + return new DEIGES_Provider(this); } -//======================================================================= -// function : IsImportSupported -// purpose : -//======================================================================= -bool IGESCAFControl_ConfigurationNode::IsImportSupported() const +//================================================================================================= + +bool DEIGES_ConfigurationNode::IsImportSupported() const { return true; } -//======================================================================= -// function : IsExportSupported -// purpose : -//======================================================================= -bool IGESCAFControl_ConfigurationNode::IsExportSupported() const +//================================================================================================= + +bool DEIGES_ConfigurationNode::IsExportSupported() const { return true; } -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString IGESCAFControl_ConfigurationNode::GetFormat() const +//================================================================================================= + +TCollection_AsciiString DEIGES_ConfigurationNode::GetFormat() const { return TCollection_AsciiString("IGES"); } -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString IGESCAFControl_ConfigurationNode::GetVendor() const +//================================================================================================= + +TCollection_AsciiString DEIGES_ConfigurationNode::GetVendor() const { return TCollection_AsciiString("OCC"); } -//======================================================================= -// function : GetExtensions -// purpose : -//======================================================================= -TColStd_ListOfAsciiString IGESCAFControl_ConfigurationNode::GetExtensions() const +//================================================================================================= + +TColStd_ListOfAsciiString DEIGES_ConfigurationNode::GetExtensions() const { TColStd_ListOfAsciiString anExt; anExt.Append("igs"); @@ -421,11 +441,9 @@ TColStd_ListOfAsciiString IGESCAFControl_ConfigurationNode::GetExtensions() cons return anExt; } -//======================================================================= -// function : CheckContent -// purpose : -//======================================================================= -bool IGESCAFControl_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const +//================================================================================================= + +bool DEIGES_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const { if (theBuffer.IsNull() || theBuffer->Size() < 83) { diff --git a/src/DEIGES/DEIGES_ConfigurationNode.hxx b/src/DEIGES/DEIGES_ConfigurationNode.hxx new file mode 100644 index 0000000000..53fefebdbd --- /dev/null +++ b/src/DEIGES/DEIGES_ConfigurationNode.hxx @@ -0,0 +1,184 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEIGES_ConfigurationNode_HeaderFile +#define _DEIGES_ConfigurationNode_HeaderFile + +#include +#include + +//! The purpose of this class is to configure the transfer process for IGES format +//! Stores the necessary settings for DEIGES_Provider. +//! Configures and creates special provider to transfer IGES files. +//! +//! Nodes grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "IGES" +//! The supported CAD extensions are ".igs", ".iges" +//! The import process is supported. +//! The export process is supported. +class DEIGES_ConfigurationNode : public DE_ConfigurationNode +{ + DEFINE_STANDARD_RTTIEXT(DEIGES_ConfigurationNode, DE_ConfigurationNode) +public: + //! Initializes all fields by default + Standard_EXPORT DEIGES_ConfigurationNode(); + + //! Copies values of all fields + //! @param[in] theNode object to copy + Standard_EXPORT DEIGES_ConfigurationNode(const Handle(DEIGES_ConfigurationNode)& theNode); + + //! Updates values according the resource + //! @param[in] theResource input resource to use + //! @return true if theResource loading has ended correctly + Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) + Standard_OVERRIDE; + + //! Writes configuration to the string + //! @return result resource string + Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; + + //! Copies values of all fields + //! @return new object with the same field values + Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; + + //! Creates new provider for the own format + //! @return new created provider + Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; + +public: + //! Checks the import supporting + //! @return true if import is supported + Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; + + //! Checks the export supporting + //! @return true if export is supported + Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; + + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; + + //! Gets list of supported file extensions + //! @return list of extensions + Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; + + //! Checks the file content to verify a format + //! @param[in] theBuffer read stream buffer to check content + //! @return Standard_True if file is supported by a current provider + Standard_EXPORT virtual bool CheckContent(const Handle(NCollection_Buffer)& theBuffer) const + Standard_OVERRIDE; + +public: + enum ReadMode_BSplineContinuity + { + ReadMode_BSplineContinuity_C0 = 0, + ReadMode_BSplineContinuity_C1, + ReadMode_BSplineContinuity_C2 + }; + + enum ReadMode_Precision + { + ReadMode_Precision_File = 0, + ReadMode_Precision_User + }; + + enum ReadMode_MaxPrecision + { + ReadMode_MaxPrecision_Preferred = 0, + ReadMode_MaxPrecision_Forced + }; + + enum ReadMode_SurfaceCurve + { + ReadMode_SurfaceCurve_Default = 0, + ReadMode_SurfaceCurve_2DUse_Preferred = 2, + ReadMode_SurfaceCurve_2DUse_Forced = -2, + ReadMode_SurfaceCurve_3DUse_Preferred = 3, + ReadMode_SurfaceCurve_3DUse_Forced = -3 + }; + + enum WriteMode_BRep + { + WriteMode_BRep_Faces = 0, + WriteMode_BRep_BRep + }; + + enum WriteMode_ConvertSurface + { + WriteMode_ConvertSurface_Off = 0, + WriteMode_ConvertSurface_On + }; + + enum WriteMode_PrecisionMode + { + WriteMode_PrecisionMode_Least = -1, + WriteMode_PrecisionMode_Average = 0, + WriteMode_PrecisionMode_Greatest = 1, + WriteMode_PrecisionMode_Session = 2 + }; + + enum WriteMode_PlaneMode + { + WriteMode_PlaneMode_Plane = 0, + WriteMode_PlaneMode_BSpline + }; + + struct IGESCAFControl_InternalSection + { + // Common + // clang-format off + ReadMode_BSplineContinuity ReadBSplineContinuity = ReadMode_BSplineContinuity_C1; // + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(DEIGES_Provider, DE_Provider) + +//================================================================================================= + +DEIGES_Provider::DEIGES_Provider() {} + +//================================================================================================= + +DEIGES_Provider::DEIGES_Provider(const Handle(DE_ConfigurationNode)& theNode) + : DE_Provider(theNode) +{ +} + +//================================================================================================= + +void DEIGES_Provider::personizeWS(Handle(XSControl_WorkSession)& theWS) +{ + if (theWS.IsNull()) + { + Message::SendWarning() << "Warning: DEIGES_Provider :" + << " Null work session, use internal temporary session"; + theWS = new XSControl_WorkSession(); + } + Handle(IGESControl_Controller) aCntrl = + Handle(IGESControl_Controller)::DownCast(theWS->NormAdaptor()); + if (aCntrl.IsNull()) + { + IGESControl_Controller::Init(); + theWS->SelectNorm("IGES"); + } +} + +//================================================================================================= + +void DEIGES_Provider::initStatic(const Handle(DE_ConfigurationNode)& theNode) +{ + Handle(DEIGES_ConfigurationNode) aNode = Handle(DEIGES_ConfigurationNode)::DownCast(theNode); + IGESData::Init(); + + // Get previous values + myOldValues.ReadBSplineContinuity = + (DEIGES_ConfigurationNode::ReadMode_BSplineContinuity)Interface_Static::IVal( + "read.iges.bspline.continuity"); + myOldValues.ReadPrecisionMode = + (DEIGES_ConfigurationNode::ReadMode_Precision)Interface_Static::IVal("read.precision.mode"); + myOldValues.ReadPrecisionVal = Interface_Static::RVal("read.precision.val"); + myOldValues.ReadMaxPrecisionMode = + (DEIGES_ConfigurationNode::ReadMode_MaxPrecision)Interface_Static::IVal( + "read.maxprecision.mode"); + myOldValues.ReadMaxPrecisionVal = Interface_Static::RVal("read.maxprecision.val"); + myOldValues.ReadSameParamMode = Interface_Static::IVal("read.stdsameparameter.mode") == 1; + myOldValues.ReadSurfaceCurveMode = + (DEIGES_ConfigurationNode::ReadMode_SurfaceCurve)Interface_Static::IVal( + "read.surfacecurve.mode"); + myOldValues.EncodeRegAngle = Interface_Static::RVal("read.encoderegularity.angle") * 180.0 / M_PI; + + myOldValues.ReadApproxd1 = Interface_Static::IVal("read.iges.bspline.approxd1.mode") == 1; + myOldValues.ReadResourceName = Interface_Static::CVal("read.iges.resource.name"); + myOldValues.ReadSequence = Interface_Static::CVal("read.iges.sequence"); + myOldValues.ReadFaultyEntities = Interface_Static::IVal("read.iges.faulty.entities") == 1; + myOldValues.ReadOnlyVisible = Interface_Static::IVal("read.iges.onlyvisible") == 1; + + myOldValues.WriteBRepMode = + (DEIGES_ConfigurationNode::WriteMode_BRep)Interface_Static::IVal("write.iges.brep.mode"); + myOldValues.WriteConvertSurfaceMode = + (DEIGES_ConfigurationNode::WriteMode_ConvertSurface)Interface_Static::IVal( + "write.convertsurface.mode"); + myOldValues.WriteHeaderAuthor = Interface_Static::CVal("write.iges.header.author"); + myOldValues.WriteHeaderCompany = Interface_Static::CVal("write.iges.header.company"); + myOldValues.WriteHeaderProduct = Interface_Static::CVal("write.iges.header.product"); + myOldValues.WriteHeaderReciever = Interface_Static::CVal("write.iges.header.receiver"); + myOldValues.WriteResourceName = Interface_Static::CVal("write.iges.resource.name"); + myOldValues.WriteSequence = Interface_Static::CVal("write.iges.sequence"); + myOldValues.WritePrecisionMode = + (DEIGES_ConfigurationNode::WriteMode_PrecisionMode)Interface_Static::IVal( + "write.precision.mode"); + myOldValues.WritePrecisionVal = Interface_Static::RVal("write.precision.val"); + myOldValues.WritePlaneMode = + (DEIGES_ConfigurationNode::WriteMode_PlaneMode)Interface_Static::IVal("write.iges.plane.mode"); + myOldValues.WriteOffsetMode = Interface_Static::IVal("write.iges.offset.mode") == 1; + + myOldLengthUnit = Interface_Static::IVal("xstep.cascade.unit"); + + // Set new values + UnitsMethods::SetCasCadeLengthUnit(aNode->GlobalParameters.LengthUnit, + UnitsMethods_LengthUnit_Millimeter); + TCollection_AsciiString aStrUnit( + UnitsMethods::DumpLengthUnit(aNode->GlobalParameters.LengthUnit)); + aStrUnit.UpperCase(); + Interface_Static::SetCVal("xstep.cascade.unit", aStrUnit.ToCString()); + setStatic(aNode->InternalParameters); +} + +//================================================================================================= + +void DEIGES_Provider::setStatic( + const DEIGES_ConfigurationNode::IGESCAFControl_InternalSection& theParameter) +{ + Interface_Static::SetIVal("read.iges.bspline.continuity", theParameter.ReadBSplineContinuity); + Interface_Static::SetIVal("read.precision.mode", theParameter.ReadPrecisionMode); + Interface_Static::SetRVal("read.precision.val", theParameter.ReadPrecisionVal); + Interface_Static::SetIVal("read.maxprecision.mode", theParameter.ReadMaxPrecisionMode); + Interface_Static::SetRVal("read.maxprecision.val", theParameter.ReadMaxPrecisionVal); + Interface_Static::SetIVal("read.stdsameparameter.mode", theParameter.ReadSameParamMode); + Interface_Static::SetIVal("read.surfacecurve.mode", theParameter.ReadSurfaceCurveMode); + Interface_Static::SetRVal("read.encoderegularity.angle", + theParameter.EncodeRegAngle * M_PI / 180.0); + + Interface_Static::SetIVal("read.iges.bspline.approxd1.mode", theParameter.ReadApproxd1); + Interface_Static::SetCVal("read.iges.resource.name", theParameter.ReadResourceName.ToCString()); + Interface_Static::SetCVal("read.iges.sequence", theParameter.ReadSequence.ToCString()); + Interface_Static::SetIVal("read.iges.faulty.entities", theParameter.ReadFaultyEntities); + Interface_Static::SetIVal("read.iges.onlyvisible", theParameter.ReadOnlyVisible); + + Interface_Static::SetIVal("write.iges.brep.mode", theParameter.WriteBRepMode); + Interface_Static::SetIVal("write.convertsurface.mode", theParameter.WriteConvertSurfaceMode); + Interface_Static::SetCVal("write.iges.header.author", theParameter.WriteHeaderAuthor.ToCString()); + Interface_Static::SetCVal("write.iges.header.company", + theParameter.WriteHeaderCompany.ToCString()); + Interface_Static::SetCVal("write.iges.header.product", + theParameter.WriteHeaderProduct.ToCString()); + Interface_Static::SetCVal("write.iges.header.receiver", + theParameter.WriteHeaderReciever.ToCString()); + Interface_Static::SetCVal("write.iges.resource.name", theParameter.WriteResourceName.ToCString()); + Interface_Static::SetCVal("write.iges.sequence", theParameter.WriteSequence.ToCString()); + Interface_Static::SetIVal("write.precision.mode", theParameter.WritePrecisionMode); + Interface_Static::SetRVal("write.precision.val", theParameter.WritePrecisionVal); + Interface_Static::SetIVal("write.iges.plane.mode", theParameter.WritePlaneMode); + Interface_Static::SetIVal("write.iges.offset.mode", theParameter.WriteOffsetMode); +} + +//================================================================================================= + +void DEIGES_Provider::resetStatic() +{ + Interface_Static::SetIVal("xstep.cascade.unit", myOldLengthUnit); + UnitsMethods::SetCasCadeLengthUnit(myOldLengthUnit); + setStatic(myOldValues); +} + +//================================================================================================= + +bool DEIGES_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + if (theDocument.IsNull()) + { + Message::SendFail() << "Error in the DEIGES_Provider during reading the file " << thePath + << "\t: theDocument shouldn't be null"; + return false; + } + if (!GetNode()->IsKind(STANDARD_TYPE(DEIGES_ConfigurationNode))) + { + Message::SendFail() << "Error in the DEIGES_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DEIGES_ConfigurationNode) aNode = Handle(DEIGES_ConfigurationNode)::DownCast(GetNode()); + personizeWS(theWS); + initStatic(aNode); + XCAFDoc_DocumentTool::SetLengthUnit(theDocument, + aNode->GlobalParameters.LengthUnit, + UnitsMethods_LengthUnit_Millimeter); + IGESCAFControl_Reader aReader; + aReader.SetWS(theWS); + + aReader.SetReadVisible(aNode->InternalParameters.ReadOnlyVisible); + + aReader.SetColorMode(aNode->InternalParameters.ReadColor); + aReader.SetNameMode(aNode->InternalParameters.ReadName); + aReader.SetLayerMode(aNode->InternalParameters.ReadLayer); + + IFSelect_ReturnStatus aReadStat = IFSelect_RetVoid; + aReadStat = aReader.ReadFile(thePath.ToCString()); + if (aReadStat != IFSelect_RetDone) + { + Message::SendFail() << "Error in the DEIGES_Provider during reading the file " << thePath + << "\t: abandon, no model loaded"; + resetStatic(); + return false; + } + + if (!aReader.Transfer(theDocument, theProgress)) + { + Message::SendFail() << "Error in the DEIGES_Provider during reading the file " << thePath + << "\t: Cannot read any relevant data from the IGES file"; + resetStatic(); + return false; + } + resetStatic(); + return true; +} + +//================================================================================================= + +bool DEIGES_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + if (!GetNode()->IsKind(STANDARD_TYPE(DEIGES_ConfigurationNode))) + { + Message::SendFail() << "Error in the DEIGES_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DEIGES_ConfigurationNode) aNode = Handle(DEIGES_ConfigurationNode)::DownCast(GetNode()); + personizeWS(theWS); + initStatic(aNode); + Standard_Integer aFlag = IGESData_BasicEditor::GetFlagByValue(aNode->GlobalParameters.LengthUnit); + IGESCAFControl_Writer aWriter(theWS, + (aFlag > 0) ? IGESData_BasicEditor::UnitFlagName(aFlag) : "MM"); + IGESData_GlobalSection aGS = aWriter.Model()->GlobalSection(); + Standard_Real aScaleFactorMM = 1.; + Standard_Boolean aHasUnits = + XCAFDoc_DocumentTool::GetLengthUnit(theDocument, + aScaleFactorMM, + UnitsMethods_LengthUnit_Millimeter); + if (aHasUnits) + { + aGS.SetCascadeUnit(aScaleFactorMM); + } + else + { + aGS.SetCascadeUnit(aNode->GlobalParameters.SystemUnit); + Message::SendWarning() + << "Warning in the DEIGES_Provider during writing the file " << thePath + << "\t: The document has no information on Units. Using global parameter as initial Unit."; + } + if (aFlag == 0) + { + aGS.SetScale(aNode->GlobalParameters.LengthUnit); + } + aWriter.Model()->SetGlobalSection(aGS); + aWriter.SetColorMode(aNode->InternalParameters.WriteColor); + aWriter.SetNameMode(aNode->InternalParameters.WriteName); + aWriter.SetLayerMode(aNode->InternalParameters.WriteLayer); + + if (!aWriter.Transfer(theDocument, theProgress)) + { + Message::SendFail() << "Error in the DEIGES_Provider during reading the file " << thePath + << "\t: The document cannot be translated or gives no result"; + resetStatic(); + return false; + } + if (!aWriter.Write(thePath.ToCString())) + { + Message::SendFail() << "Error in the DEIGES_Provider during reading the file " << thePath + << "\t: Write failed"; + resetStatic(); + return false; + } + resetStatic(); + return true; +} + +//================================================================================================= + +bool DEIGES_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); + return Read(thePath, theDocument, aWS, theProgress); +} + +//================================================================================================= + +bool DEIGES_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); + return Write(thePath, theDocument, aWS, theProgress); +} + +//================================================================================================= + +bool DEIGES_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theProgress; + if (!GetNode()->IsKind(STANDARD_TYPE(DEIGES_ConfigurationNode))) + { + Message::SendFail() << "Error in the DEIGES_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DEIGES_ConfigurationNode) aNode = Handle(DEIGES_ConfigurationNode)::DownCast(GetNode()); + initStatic(aNode); + personizeWS(theWS); + IGESControl_Reader aReader; + aReader.SetWS(theWS); + aReader.SetReadVisible(aNode->InternalParameters.ReadOnlyVisible); + IFSelect_ReturnStatus aReadStat = IFSelect_RetVoid; + aReadStat = aReader.ReadFile(thePath.ToCString()); + if (aReadStat != IFSelect_RetDone) + { + Message::SendFail() << "Error in the DEIGES_Provider during reading the file " << thePath + << "\t: Could not read file, no model loaded"; + resetStatic(); + return false; + } + if (aReader.TransferRoots() <= 0) + { + Message::SendFail() << "Error in the DEIGES_Provider during reading the file " << thePath + << "\t: Cannot read any relevant data from the IGES file"; + resetStatic(); + return false; + } + theShape = aReader.OneShape(); + resetStatic(); + return true; +} + +//================================================================================================= + +bool DEIGES_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + (void)theProgress; + if (!GetNode()->IsKind(STANDARD_TYPE(DEIGES_ConfigurationNode))) + { + Message::SendFail() << "Error in the DEIGES_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DEIGES_ConfigurationNode) aNode = Handle(DEIGES_ConfigurationNode)::DownCast(GetNode()); + initStatic(aNode); + Standard_Integer aFlag = IGESData_BasicEditor::GetFlagByValue(aNode->GlobalParameters.LengthUnit); + IGESControl_Writer aWriter((aFlag > 0) ? IGESData_BasicEditor::UnitFlagName(aFlag) : "MM", + aNode->InternalParameters.WriteBRepMode); + IGESData_GlobalSection aGS = aWriter.Model()->GlobalSection(); + aGS.SetCascadeUnit(aNode->GlobalParameters.SystemUnit); + if (!aFlag) + { + aGS.SetScale(aNode->GlobalParameters.LengthUnit); + } + aWriter.Model()->SetGlobalSection(aGS); + Standard_Boolean aIsOk = aWriter.AddShape(theShape); + if (!aIsOk) + { + Message::SendFail() << "DEIGES_Provider: Shape not written"; + resetStatic(); + return false; + } + + if (!(aWriter.Write(thePath.ToCString()))) + { + Message::SendFail() << "DEIGES_Provider: Error on writing file " << thePath; + resetStatic(); + return false; + } + resetStatic(); + return true; +} + +//================================================================================================= + +bool DEIGES_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); + return Read(thePath, theShape, aWS, theProgress); +} + +//================================================================================================= + +bool DEIGES_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); + return Write(thePath, theShape, aWS, theProgress); +} + +//================================================================================================= + +TCollection_AsciiString DEIGES_Provider::GetFormat() const +{ + return TCollection_AsciiString("IGES"); +} + +//================================================================================================= + +TCollection_AsciiString DEIGES_Provider::GetVendor() const +{ + return TCollection_AsciiString("OCC"); +} diff --git a/src/DEIGES/DEIGES_Provider.hxx b/src/DEIGES/DEIGES_Provider.hxx new file mode 100644 index 0000000000..0720eaa6a7 --- /dev/null +++ b/src/DEIGES/DEIGES_Provider.hxx @@ -0,0 +1,160 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEIGES_Provider_HeaderFile +#define _DEIGES_Provider_HeaderFile + +#include +#include + +//! The class to transfer IGES files. +//! Reads and Writes any IGES files into/from OCCT. +//! Each operation needs configuration node. +//! +//! Providers grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "IGES" +//! The import process is supported. +//! The export process is supported. +class DEIGES_Provider : public DE_Provider +{ +public: + DEFINE_STANDARD_RTTIEXT(DEIGES_Provider, DE_Provider) + +public: + //! Default constructor + //! Configure translation process with global configuration + Standard_EXPORT DEIGES_Provider(); + + //! Configure translation process + //! @param[in] theNode object to copy + Standard_EXPORT DEIGES_Provider(const Handle(DE_ConfigurationNode)& theNode); + +public: + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + +public: + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; + +private: + //! Personizes work session with current format. + //! Creates new temporary session if current session is null + //! @param[in] theWS current work session + void personizeWS(Handle(XSControl_WorkSession)& theWS); + + //! Initialize static variables + void initStatic(const Handle(DE_ConfigurationNode)& theNode); + + //! Initialize static variables + void setStatic(const DEIGES_ConfigurationNode::IGESCAFControl_InternalSection& theParameter); + + //! Reset used interface static variables + void resetStatic(); + + DEIGES_ConfigurationNode::IGESCAFControl_InternalSection myOldValues; + int myOldLengthUnit = 1; +}; + +#endif // _DEIGES_Provider_HeaderFile diff --git a/src/DEIGES/FILES b/src/DEIGES/FILES new file mode 100644 index 0000000000..4deb0c32da --- /dev/null +++ b/src/DEIGES/FILES @@ -0,0 +1,4 @@ +DEIGES_ConfigurationNode.cxx +DEIGES_ConfigurationNode.hxx +DEIGES_Provider.cxx +DEIGES_Provider.hxx diff --git a/src/RWObj/RWObj_ConfigurationNode.cxx b/src/DEOBJ/DEOBJ_ConfigurationNode.cxx similarity index 59% rename from src/RWObj/RWObj_ConfigurationNode.cxx rename to src/DEOBJ/DEOBJ_ConfigurationNode.cxx index 0dd7d8f7e6..3f7cb7dbf5 100644 --- a/src/RWObj/RWObj_ConfigurationNode.cxx +++ b/src/DEOBJ/DEOBJ_ConfigurationNode.cxx @@ -11,95 +11,100 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include +#include #include #include -#include -IMPLEMENT_STANDARD_RTTIEXT(RWObj_ConfigurationNode, DE_ConfigurationNode) +IMPLEMENT_STANDARD_RTTIEXT(DEOBJ_ConfigurationNode, DE_ConfigurationNode) namespace { - static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() - { - static const TCollection_AsciiString aScope = "provider"; - return aScope; - } - - // Wrapper to auto-load DE component - DE_PluginHolder THE_OCCT_OBJ_COMPONENT_PLUGIN; +static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() +{ + static const TCollection_AsciiString aScope = "provider"; + return aScope; +} + +// Wrapper to auto-load DE component +DE_PluginHolder THE_OCCT_OBJ_COMPONENT_PLUGIN; +} // namespace + +//================================================================================================= + +DEOBJ_ConfigurationNode::DEOBJ_ConfigurationNode() + : DE_ConfigurationNode() +{ } -//======================================================================= -// function : RWObj_ConfigurationNode -// purpose : -//======================================================================= -RWObj_ConfigurationNode::RWObj_ConfigurationNode() : - DE_ConfigurationNode() -{} - -//======================================================================= -// function : RWObj_ConfigurationNode -// purpose : -//======================================================================= -RWObj_ConfigurationNode::RWObj_ConfigurationNode(const Handle(RWObj_ConfigurationNode)& theNode) - :DE_ConfigurationNode(theNode) +//================================================================================================= + +DEOBJ_ConfigurationNode::DEOBJ_ConfigurationNode(const Handle(DEOBJ_ConfigurationNode)& theNode) + : DE_ConfigurationNode(theNode) { InternalParameters = theNode->InternalParameters; } -//======================================================================= -// function : Load -// purpose : -//======================================================================= -bool RWObj_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) +//================================================================================================= + +bool DEOBJ_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) { - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); - InternalParameters.FileLengthUnit = + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); + InternalParameters.FileLengthUnit = theResource->RealVal("file.length.unit", InternalParameters.FileLengthUnit, aScope); - InternalParameters.SystemCS = (RWMesh_CoordinateSystem) - (theResource->IntegerVal("system.cs", (int)InternalParameters.SystemCS, aScope) % 2); - InternalParameters.FileCS = (RWMesh_CoordinateSystem) - (theResource->IntegerVal("file.cs", (int)InternalParameters.SystemCS, aScope) % 2); - - InternalParameters.ReadSinglePrecision = - theResource->BooleanVal("read.single.precision", InternalParameters.ReadSinglePrecision, aScope); - InternalParameters.ReadCreateShapes = + InternalParameters.SystemCS = + (RWMesh_CoordinateSystem)(theResource->IntegerVal("system.cs", + (int)InternalParameters.SystemCS, + aScope) + % 2); + InternalParameters.FileCS = + (RWMesh_CoordinateSystem)(theResource->IntegerVal("file.cs", + (int)InternalParameters.SystemCS, + aScope) + % 2); + + InternalParameters.ReadSinglePrecision = + theResource->BooleanVal("read.single.precision", + InternalParameters.ReadSinglePrecision, + aScope); + InternalParameters.ReadCreateShapes = theResource->BooleanVal("read.create.shapes", InternalParameters.ReadCreateShapes, aScope); InternalParameters.ReadRootPrefix = theResource->StringVal("read.root.prefix", InternalParameters.ReadRootPrefix, aScope); - InternalParameters.ReadFillDoc = + InternalParameters.ReadFillDoc = theResource->BooleanVal("read.fill.doc", InternalParameters.ReadFillDoc, aScope); - InternalParameters.ReadFillIncomplete = + InternalParameters.ReadFillIncomplete = theResource->BooleanVal("read.fill.incomplete", InternalParameters.ReadFillIncomplete, aScope); - InternalParameters.ReadMemoryLimitMiB = + InternalParameters.ReadMemoryLimitMiB = theResource->IntegerVal("read.memory.limit.mib", InternalParameters.ReadMemoryLimitMiB, aScope); - InternalParameters.WriteComment = + InternalParameters.WriteComment = theResource->StringVal("write.comment", InternalParameters.WriteComment, aScope); - InternalParameters.WriteAuthor = + InternalParameters.WriteAuthor = theResource->StringVal("write.author", InternalParameters.WriteAuthor, aScope); return true; } -//======================================================================= -// function : Save -// purpose : -//======================================================================= -TCollection_AsciiString RWObj_ConfigurationNode::Save() const +//================================================================================================= + +TCollection_AsciiString DEOBJ_ConfigurationNode::Save() const { TCollection_AsciiString aResult; aResult += "!*****************************************************************************\n"; - aResult = aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; + aResult = + aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; aResult += "!\n"; aResult += "!Common parameters:\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!File length units to convert from while reading the file, defined as scale factor for m (meters)\n"; + aResult += "!File length units to convert from while reading the file, defined as scale factor " + "for m (meters)\n"; aResult += "!Default value: 1.0(M)\n"; aResult += aScope + "file.length.unit :\t " + InternalParameters.FileLengthUnit + "\n"; aResult += "!\n"; @@ -134,7 +139,8 @@ TCollection_AsciiString RWObj_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Root folder for generating root labels names\n"; - aResult += "!Default value: ""(empty). Available values: \n"; + aResult += "!Default value: " + "(empty). Available values: \n"; aResult += aScope + "read.root.prefix :\t " + InternalParameters.ReadRootPrefix + "\n"; aResult += "!\n"; @@ -145,7 +151,8 @@ TCollection_AsciiString RWObj_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!\n"; - aResult += "!Flag for fill the document with partially retrieved data even if reader has fa-iled with er-ror\n"; + aResult += "!Flag for fill the document with partially retrieved data even if reader has fa-iled " + "with er-ror\n"; aResult += "!Default value: 1(true). Available values: 0(false), 1(true)\n"; aResult += aScope + "read.fill.incomplete :\t " + InternalParameters.ReadFillIncomplete + "\n"; aResult += "!\n"; @@ -162,13 +169,15 @@ TCollection_AsciiString RWObj_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Export special comment\n"; - aResult += "!Default value: ""(empty). Available values: \n"; + aResult += "!Default value: " + "(empty). Available values: \n"; aResult += aScope + "write.comment :\t " + InternalParameters.WriteComment + "\n"; aResult += "!\n"; aResult += "!\n"; aResult += "!Author of exported file name\n"; - aResult += "!Default value: ""(empty). Available values: \n"; + aResult += "!Default value: " + "(empty). Available values: \n"; aResult += aScope + "write.author :\t " + InternalParameters.WriteAuthor + "\n"; aResult += "!\n"; @@ -176,65 +185,51 @@ TCollection_AsciiString RWObj_ConfigurationNode::Save() const return aResult; } -//======================================================================= -// function : Copy -// purpose : -//======================================================================= -Handle(DE_ConfigurationNode) RWObj_ConfigurationNode::Copy() const +//================================================================================================= + +Handle(DE_ConfigurationNode) DEOBJ_ConfigurationNode::Copy() const { - return new RWObj_ConfigurationNode(*this); + return new DEOBJ_ConfigurationNode(*this); } -//======================================================================= -// function : BuildProvider -// purpose : -//======================================================================= -Handle(DE_Provider) RWObj_ConfigurationNode::BuildProvider() +//================================================================================================= + +Handle(DE_Provider) DEOBJ_ConfigurationNode::BuildProvider() { - return new RWObj_Provider(this); + return new DEOBJ_Provider(this); } -//======================================================================= -// function : IsImportSupported -// purpose : -//======================================================================= -bool RWObj_ConfigurationNode::IsImportSupported() const +//================================================================================================= + +bool DEOBJ_ConfigurationNode::IsImportSupported() const { return true; } -//======================================================================= -// function : IsExportSupported -// purpose : -//======================================================================= -bool RWObj_ConfigurationNode::IsExportSupported() const +//================================================================================================= + +bool DEOBJ_ConfigurationNode::IsExportSupported() const { return true; } -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString RWObj_ConfigurationNode::GetFormat() const +//================================================================================================= + +TCollection_AsciiString DEOBJ_ConfigurationNode::GetFormat() const { return TCollection_AsciiString("OBJ"); } -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString RWObj_ConfigurationNode::GetVendor() const +//================================================================================================= + +TCollection_AsciiString DEOBJ_ConfigurationNode::GetVendor() const { return TCollection_AsciiString("OCC"); } -//======================================================================= -// function : GetExtensions -// purpose : -//======================================================================= -TColStd_ListOfAsciiString RWObj_ConfigurationNode::GetExtensions() const +//================================================================================================= + +TColStd_ListOfAsciiString DEOBJ_ConfigurationNode::GetExtensions() const { TColStd_ListOfAsciiString anExt; anExt.Append("obj"); diff --git a/src/DEOBJ/DEOBJ_ConfigurationNode.hxx b/src/DEOBJ/DEOBJ_ConfigurationNode.hxx new file mode 100644 index 0000000000..2a950a2700 --- /dev/null +++ b/src/DEOBJ/DEOBJ_ConfigurationNode.hxx @@ -0,0 +1,102 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEOBJ_ConfigurationNode_HeaderFile +#define _DEOBJ_ConfigurationNode_HeaderFile + +#include +#include + +//! The purpose of this class is to configure the transfer process for OBJ format +//! Stores the necessary settings for DEOBJ_Provider. +//! Configures and creates special provider to transfer OBJ files. +//! +//! Nodes grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "OBJ" +//! The supported CAD extension is ".obj" +//! The import process is supported. +//! The export process is supported. +class DEOBJ_ConfigurationNode : public DE_ConfigurationNode +{ + DEFINE_STANDARD_RTTIEXT(DEOBJ_ConfigurationNode, DE_ConfigurationNode) +public: + //! Initializes all field by default + Standard_EXPORT DEOBJ_ConfigurationNode(); + + //! Copies values of all fields + //! @param[in] theNode object to copy + Standard_EXPORT DEOBJ_ConfigurationNode(const Handle(DEOBJ_ConfigurationNode)& theNode); + + //! Updates values according the resource + //! @param[in] theResource input resource to use + //! @return true if theResource loading has ended correctly + Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) + Standard_OVERRIDE; + + //! Writes configuration to the string + //! @return result resource string + Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; + + //! Copies values of all fields + //! @return new object with the same field values + Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; + + //! Creates new provider for the own format + //! @return new created provider + Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; + +public: + //! Checks the import supporting + //! @return true if import is supported + Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; + + //! Checks the export supporting + //! @return true if export is supported + Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; + + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; + + //! Gets list of supported file extensions + //! @return list of extensions + Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; + +public: + struct RWObj_InternalSection + { + // Common + // clang-format off + double FileLengthUnit = 1.; //!< File length units to convert from while reading the file, defined as scale factor for m (meters) + RWMesh_CoordinateSystem SystemCS = RWMesh_CoordinateSystem_Zup; //!< System origin coordinate system to perform conversion into during read + RWMesh_CoordinateSystem FileCS = RWMesh_CoordinateSystem_Yup; //!< File origin coordinate system to perform conversion during read + // Reading + bool ReadSinglePrecision = false; //!< Flag for reading vertex data with single or double floating point precision + bool ReadCreateShapes = false; //!< Flag for create a single triangulation + TCollection_AsciiString ReadRootPrefix; //!< Root folder for generating root labels names + bool ReadFillDoc = true; //!< Flag for fill document from shape sequence + bool ReadFillIncomplete = true; //!< Flag for fill the document with partially retrieved data even if reader has failed with error + // clang-format on + int ReadMemoryLimitMiB = -1; //!< Memory usage limit + // Writing + TCollection_AsciiString WriteComment; //!< Export special comment + TCollection_AsciiString WriteAuthor; //!< Author of exported file name + } InternalParameters; +}; + +#endif // _DEOBJ_ConfigurationNode_HeaderFile diff --git a/src/RWObj/RWObj_Provider.cxx b/src/DEOBJ/DEOBJ_Provider.cxx similarity index 50% rename from src/RWObj/RWObj_Provider.cxx rename to src/DEOBJ/DEOBJ_Provider.cxx index 8b1885fcb3..0660c5f24a 100644 --- a/src/RWObj/RWObj_Provider.cxx +++ b/src/DEOBJ/DEOBJ_Provider.cxx @@ -11,81 +11,71 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include #include -#include +#include #include #include #include -#include #include +#include + +IMPLEMENT_STANDARD_RTTIEXT(DEOBJ_Provider, DE_Provider) + +//================================================================================================= + +DEOBJ_Provider::DEOBJ_Provider() {} + +//================================================================================================= -IMPLEMENT_STANDARD_RTTIEXT(RWObj_Provider, DE_Provider) - -//======================================================================= -// function : RWObj_Provider -// purpose : -//======================================================================= -RWObj_Provider::RWObj_Provider() -{} - -//======================================================================= -// function : RWObj_Provider -// purpose : -//======================================================================= -RWObj_Provider::RWObj_Provider(const Handle(DE_ConfigurationNode)& theNode) - :DE_Provider(theNode) -{} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool RWObj_Provider::Read(const TCollection_AsciiString& thePath, +DEOBJ_Provider::DEOBJ_Provider(const Handle(DE_ConfigurationNode)& theNode) + : DE_Provider(theNode) +{ +} + +//================================================================================================= + +bool DEOBJ_Provider::Read(const TCollection_AsciiString& thePath, const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) { (void)theWS; return Read(thePath, theDocument, theProgress); } -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWObj_Provider::Write(const TCollection_AsciiString& thePath, +//================================================================================================= + +bool DEOBJ_Provider::Write(const TCollection_AsciiString& thePath, const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) { (void)theWS; return Write(thePath, theDocument, theProgress); } -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool RWObj_Provider::Read(const TCollection_AsciiString& thePath, +//================================================================================================= + +bool DEOBJ_Provider::Read(const TCollection_AsciiString& thePath, const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) + const Message_ProgressRange& theProgress) { if (theDocument.IsNull()) { - Message::SendFail() << "Error in the RWObj_Provider during reading the file " << - thePath << "\t: theDocument shouldn't be null"; + Message::SendFail() << "Error in the DEOBJ_Provider during reading the file " << thePath + << "\t: theDocument shouldn't be null"; return false; } - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(RWObj_ConfigurationNode))) + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEOBJ_ConfigurationNode))) { - Message::SendFail() << "Error in the RWObj_ConfigurationNode during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; + Message::SendFail() << "Error in the DEOBJ_ConfigurationNode during reading the file " + << thePath << "\t: Incorrect or empty Configuration Node"; return false; } - Handle(RWObj_ConfigurationNode) aNode = Handle(RWObj_ConfigurationNode)::DownCast(GetNode()); - RWObj_CafReader aReader; + Handle(DEOBJ_ConfigurationNode) aNode = Handle(DEOBJ_ConfigurationNode)::DownCast(GetNode()); + RWObj_CafReader aReader; aReader.SetSinglePrecision(aNode->InternalParameters.ReadSinglePrecision); aReader.SetSystemLengthUnit(aNode->GlobalParameters.LengthUnit / 1000); aReader.SetSystemCoordinateSystem(aNode->InternalParameters.SystemCS); @@ -96,28 +86,29 @@ bool RWObj_Provider::Read(const TCollection_AsciiString& thePath, aReader.SetMemoryLimitMiB(aNode->InternalParameters.ReadMemoryLimitMiB); if (!aReader.Perform(thePath, theProgress)) { - Message::SendFail() << "Error in the RWObj_ConfigurationNode during reading the file " << thePath; + Message::SendFail() << "Error in the DEOBJ_ConfigurationNode during reading the file " + << thePath; return false; } - XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter); + XCAFDoc_DocumentTool::SetLengthUnit(theDocument, + aNode->GlobalParameters.LengthUnit, + UnitsMethods_LengthUnit_Millimeter); return true; } -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWObj_Provider::Write(const TCollection_AsciiString& thePath, +//================================================================================================= + +bool DEOBJ_Provider::Write(const TCollection_AsciiString& thePath, const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) + const Message_ProgressRange& theProgress) { - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(RWObj_ConfigurationNode))) + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEOBJ_ConfigurationNode))) { - Message::SendFail() << "Error in the RWObj_ConfigurationNode during writing the file " << - thePath << "\t: Incorrect or empty Configuration Node"; + Message::SendFail() << "Error in the DEOBJ_ConfigurationNode during writing the file " + << thePath << "\t: Incorrect or empty Configuration Node"; return false; } - Handle(RWObj_ConfigurationNode) aNode = Handle(RWObj_ConfigurationNode)::DownCast(GetNode()); + Handle(DEOBJ_ConfigurationNode) aNode = Handle(DEOBJ_ConfigurationNode)::DownCast(GetNode()); TColStd_IndexedDataMapOfStringString aFileInfo; if (!aNode->InternalParameters.WriteAuthor.IsEmpty()) @@ -130,16 +121,19 @@ bool RWObj_Provider::Write(const TCollection_AsciiString& thePath, } RWMesh_CoordinateSystemConverter aConverter; - Standard_Real aScaleFactorMM = 1.; - if (XCAFDoc_DocumentTool::GetLengthUnit(theDocument, aScaleFactorMM, UnitsMethods_LengthUnit_Millimeter)) + Standard_Real aScaleFactorMM = 1.; + if (XCAFDoc_DocumentTool::GetLengthUnit(theDocument, + aScaleFactorMM, + UnitsMethods_LengthUnit_Millimeter)) { aConverter.SetInputLengthUnit(aScaleFactorMM / 1000.); } else { aConverter.SetInputLengthUnit(aNode->GlobalParameters.SystemUnit / 1000.); - Message::SendWarning() << "Warning in the RWObj_Provider during writing the file " << - thePath << "\t: The document has no information on Units. Using global parameter as initial Unit."; + Message::SendWarning() + << "Warning in the DEOBJ_Provider during writing the file " << thePath + << "\t: The document has no information on Units. Using global parameter as initial Unit."; } aConverter.SetInputCoordinateSystem(aNode->InternalParameters.SystemCS); aConverter.SetOutputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000.); @@ -149,53 +143,48 @@ bool RWObj_Provider::Write(const TCollection_AsciiString& thePath, aWriter.SetCoordinateSystemConverter(aConverter); if (!aWriter.Perform(theDocument, aFileInfo, theProgress)) { - Message::SendFail() << "Error in the RWObj_ConfigurationNode during writing the file " << thePath; + Message::SendFail() << "Error in the DEOBJ_ConfigurationNode during writing the file " + << thePath; return false; } return true; } -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool RWObj_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, +//================================================================================================= + +bool DEOBJ_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) + const Message_ProgressRange& theProgress) { (void)theWS; return Read(thePath, theShape, theProgress); } -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWObj_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, +//================================================================================================= + +bool DEOBJ_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) + const Message_ProgressRange& theProgress) { (void)theWS; return Write(thePath, theShape, theProgress); } -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool RWObj_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) +//================================================================================================= + +bool DEOBJ_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) { - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(RWObj_ConfigurationNode))) + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEOBJ_ConfigurationNode))) { - Message::SendFail() << "Error in the RWObj_ConfigurationNode during writing the file " << - thePath << "\t: Incorrect or empty Configuration Node"; + Message::SendFail() << "Error in the DEOBJ_ConfigurationNode during writing the file " + << thePath << "\t: Incorrect or empty Configuration Node"; return false; } - Handle(RWObj_ConfigurationNode) aNode = Handle(RWObj_ConfigurationNode)::DownCast(GetNode()); + Handle(DEOBJ_ConfigurationNode) aNode = Handle(DEOBJ_ConfigurationNode)::DownCast(GetNode()); RWMesh_CoordinateSystemConverter aConverter; aConverter.SetOutputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000); aConverter.SetOutputCoordinateSystem(aNode->InternalParameters.SystemCS); @@ -210,46 +199,41 @@ bool RWObj_Provider::Read(const TCollection_AsciiString& thePath, aSimpleReader.SetMemoryLimit(aNode->InternalParameters.ReadMemoryLimitMiB); if (!aSimpleReader.Read(thePath, theProgress)) { - Message::SendFail() << "Error in the RWObj_ConfigurationNode during reading the file " << thePath; + Message::SendFail() << "Error in the DEOBJ_ConfigurationNode during reading the file " + << thePath; return false; } Handle(Poly_Triangulation) aTriangulation = aSimpleReader.GetTriangulation(); - TopoDS_Face aFace; - BRep_Builder aBuiler; + TopoDS_Face aFace; + BRep_Builder aBuiler; aBuiler.MakeFace(aFace); aBuiler.UpdateFace(aFace, aTriangulation); theShape = aFace; return true; } -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWObj_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) +//================================================================================================= + +bool DEOBJ_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) { - Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF"); + Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF"); Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main()); aShTool->AddShape(theShape); return Write(thePath, aDoc, theProgress); } -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString RWObj_Provider::GetFormat() const +//================================================================================================= + +TCollection_AsciiString DEOBJ_Provider::GetFormat() const { return TCollection_AsciiString("OBJ"); } -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString RWObj_Provider::GetVendor() const +//================================================================================================= + +TCollection_AsciiString DEOBJ_Provider::GetVendor() const { return TCollection_AsciiString("OCC"); } diff --git a/src/DEOBJ/DEOBJ_Provider.hxx b/src/DEOBJ/DEOBJ_Provider.hxx new file mode 100644 index 0000000000..e6d84fefb7 --- /dev/null +++ b/src/DEOBJ/DEOBJ_Provider.hxx @@ -0,0 +1,141 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEOBJ_Provider_HeaderFile +#define _DEOBJ_Provider_HeaderFile + +#include + +//! The class to transfer OBJ files. +//! Reads and Writes any OBJ files into/from OCCT. +//! Each operation needs configuration node. +//! +//! Providers grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "OBJ" +//! The import process is supported. +//! The export process is supported. +class DEOBJ_Provider : public DE_Provider +{ +public: + DEFINE_STANDARD_RTTIEXT(DEOBJ_Provider, DE_Provider) + +public: + //! Default constructor + //! Configure translation process with global configuration + Standard_EXPORT DEOBJ_Provider(); + + //! Configure translation process + //! @param[in] theNode object to copy + Standard_EXPORT DEOBJ_Provider(const Handle(DE_ConfigurationNode)& theNode); + +public: + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + +public: + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; +}; + +#endif // _DEOBJ_Provider_HeaderFile diff --git a/src/DEOBJ/FILES b/src/DEOBJ/FILES new file mode 100644 index 0000000000..3b03e8c055 --- /dev/null +++ b/src/DEOBJ/FILES @@ -0,0 +1,4 @@ +DEOBJ_ConfigurationNode.cxx +DEOBJ_ConfigurationNode.hxx +DEOBJ_Provider.cxx +DEOBJ_Provider.hxx diff --git a/src/RWPly/RWPly_ConfigurationNode.cxx b/src/DEPLY/DEPLY_ConfigurationNode.cxx similarity index 63% rename from src/RWPly/RWPly_ConfigurationNode.cxx rename to src/DEPLY/DEPLY_ConfigurationNode.cxx index d9983072a4..0c48f2f4d4 100644 --- a/src/RWPly/RWPly_ConfigurationNode.cxx +++ b/src/DEPLY/DEPLY_ConfigurationNode.cxx @@ -11,58 +11,60 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include +#include #include #include #include -#include -IMPLEMENT_STANDARD_RTTIEXT(RWPly_ConfigurationNode, DE_ConfigurationNode) +IMPLEMENT_STANDARD_RTTIEXT(DEPLY_ConfigurationNode, DE_ConfigurationNode) namespace { - static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() - { - static const TCollection_AsciiString aScope = "provider"; - return aScope; - } +static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() +{ + static const TCollection_AsciiString aScope = "provider"; + return aScope; +} + +// Wrapper to auto-load DE component +DE_PluginHolder THE_OCCT_PLY_COMPONENT_PLUGIN; +} // namespace - // Wrapper to auto-load DE component - DE_PluginHolder THE_OCCT_PLY_COMPONENT_PLUGIN; +//================================================================================================= + +DEPLY_ConfigurationNode::DEPLY_ConfigurationNode() + : DE_ConfigurationNode() +{ } -//======================================================================= -// function : RWPly_ConfigurationNode -// purpose : -//======================================================================= -RWPly_ConfigurationNode::RWPly_ConfigurationNode() : - DE_ConfigurationNode() -{} - -//======================================================================= -// function : RWPly_ConfigurationNode -// purpose : -//======================================================================= -RWPly_ConfigurationNode::RWPly_ConfigurationNode(const Handle(RWPly_ConfigurationNode)& theNode) - :DE_ConfigurationNode(theNode) +//================================================================================================= + +DEPLY_ConfigurationNode::DEPLY_ConfigurationNode(const Handle(DEPLY_ConfigurationNode)& theNode) + : DE_ConfigurationNode(theNode) { InternalParameters = theNode->InternalParameters; } -//======================================================================= -// function : Load -// purpose : -//======================================================================= -bool RWPly_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) +//================================================================================================= + +bool DEPLY_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) { - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); - InternalParameters.FileLengthUnit = + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); + InternalParameters.FileLengthUnit = theResource->RealVal("file.length.unit", InternalParameters.FileLengthUnit, aScope); - InternalParameters.SystemCS = - (RWMesh_CoordinateSystem)(theResource->IntegerVal("system.cs", (int)InternalParameters.SystemCS, aScope) % 2); - InternalParameters.FileCS = - (RWMesh_CoordinateSystem)(theResource->IntegerVal("file.cs", (int)InternalParameters.SystemCS, aScope) % 2); + InternalParameters.SystemCS = + (RWMesh_CoordinateSystem)(theResource->IntegerVal("system.cs", + (int)InternalParameters.SystemCS, + aScope) + % 2); + InternalParameters.FileCS = + (RWMesh_CoordinateSystem)(theResource->IntegerVal("file.cs", + (int)InternalParameters.SystemCS, + aScope) + % 2); InternalParameters.WriteNormals = theResource->BooleanVal("write.normals", InternalParameters.WriteNormals, aScope); @@ -81,23 +83,24 @@ bool RWPly_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theRes return Standard_True; } -//======================================================================= -// function : Save -// purpose : -//======================================================================= -TCollection_AsciiString RWPly_ConfigurationNode::Save() const +//================================================================================================= + +TCollection_AsciiString DEPLY_ConfigurationNode::Save() const { TCollection_AsciiString aResult; aResult += "!*****************************************************************************\n"; - aResult = aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; + aResult = + aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; aResult += "!\n"; aResult += "!Common parameters:\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!File length units to convert from while reading the file, defined as scale factor for m (meters)\n"; + aResult += "!File length units to convert from while reading the file, defined as scale factor " + "for m (meters)\n"; aResult += "!Default value: 1.0(MM)\n"; aResult += aScope + "file.length.unit :\t " + InternalParameters.FileLengthUnit + "\n"; aResult += "!\n"; @@ -150,13 +153,15 @@ TCollection_AsciiString RWPly_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Export special comment\n"; - aResult += "!Default value: ""(empty). Available values: \n"; + aResult += "!Default value: " + "(empty). Available values: \n"; aResult += aScope + "write.comment :\t " + InternalParameters.WriteComment + "\n"; aResult += "!\n"; aResult += "!\n"; aResult += "!Author of exported file name\n"; - aResult += "!Default value: ""(empty). Available values: \n"; + aResult += "!Default value: " + "(empty). Available values: \n"; aResult += aScope + "write.author :\t " + InternalParameters.WriteAuthor + "\n"; aResult += "!\n"; @@ -164,76 +169,60 @@ TCollection_AsciiString RWPly_ConfigurationNode::Save() const return aResult; } -//======================================================================= -// function : Copy -// purpose : -//======================================================================= -Handle(DE_ConfigurationNode) RWPly_ConfigurationNode::Copy() const +//================================================================================================= + +Handle(DE_ConfigurationNode) DEPLY_ConfigurationNode::Copy() const { - return new RWPly_ConfigurationNode(*this); + return new DEPLY_ConfigurationNode(*this); } -//======================================================================= -// function : BuildProvider -// purpose : -//======================================================================= -Handle(DE_Provider) RWPly_ConfigurationNode::BuildProvider() +//================================================================================================= + +Handle(DE_Provider) DEPLY_ConfigurationNode::BuildProvider() { - return new RWPly_Provider(this); + return new DEPLY_Provider(this); } -//======================================================================= -// function : IsImportSupported -// purpose : -//======================================================================= -bool RWPly_ConfigurationNode::IsImportSupported() const +//================================================================================================= + +bool DEPLY_ConfigurationNode::IsImportSupported() const { return Standard_False; } -//======================================================================= -// function : IsExportSupported -// purpose : -//======================================================================= -bool RWPly_ConfigurationNode::IsExportSupported() const +//================================================================================================= + +bool DEPLY_ConfigurationNode::IsExportSupported() const { return Standard_True; } -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString RWPly_ConfigurationNode::GetFormat() const +//================================================================================================= + +TCollection_AsciiString DEPLY_ConfigurationNode::GetFormat() const { return TCollection_AsciiString("PLY"); } -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString RWPly_ConfigurationNode::GetVendor() const +//================================================================================================= + +TCollection_AsciiString DEPLY_ConfigurationNode::GetVendor() const { return TCollection_AsciiString("OCC"); } -//======================================================================= -// function : GetExtensions -// purpose : -//======================================================================= -TColStd_ListOfAsciiString RWPly_ConfigurationNode::GetExtensions() const +//================================================================================================= + +TColStd_ListOfAsciiString DEPLY_ConfigurationNode::GetExtensions() const { TColStd_ListOfAsciiString anExt; anExt.Append("ply"); return anExt; } -//======================================================================= -// function : CheckContent -// purpose : -//======================================================================= -bool RWPly_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const +//================================================================================================= + +bool DEPLY_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const { if (theBuffer.IsNull() || theBuffer->Size() < 4) { diff --git a/src/DEPLY/DEPLY_ConfigurationNode.hxx b/src/DEPLY/DEPLY_ConfigurationNode.hxx new file mode 100644 index 0000000000..b9079996f3 --- /dev/null +++ b/src/DEPLY/DEPLY_ConfigurationNode.hxx @@ -0,0 +1,109 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEPLY_ConfigurationNode_HeaderFile +#define _DEPLY_ConfigurationNode_HeaderFile + +#include +#include +#include + +class DE_ConfigurationContext; + +//! The purpose of this class is to configure the transfer process for PLY format +//! Stores the necessary settings for DEPLY_Provider. +//! Configures and creates special provider to transfer PLY files. +//! +//! Nodes grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "PLY" +//! The supported CAD extension is ".ply" +//! The import process isn't supported. +//! The export process is supported. +class DEPLY_ConfigurationNode : public DE_ConfigurationNode +{ + DEFINE_STANDARD_RTTIEXT(DEPLY_ConfigurationNode, DE_ConfigurationNode) +public: + //! Initializes all field by default + Standard_EXPORT DEPLY_ConfigurationNode(); + + //! Copies values of all fields + //! @param[in] theNode object to copy + Standard_EXPORT DEPLY_ConfigurationNode(const Handle(DEPLY_ConfigurationNode)& theNode); + + //! Updates values according the resource + //! @param[in] theResource input resource to use + //! @return true if theResource loading has ended correctly + Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) + Standard_OVERRIDE; + + //! Writes configuration to the string + //! @return result resource string + Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; + + //! Copies values of all fields + //! @return new object with the same field values + Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; + + //! Creates new provider for the own format + //! @return new created provider + Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; + +public: + //! Checks the import supporting + //! @return true if import is supported + Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; + + //! Checks the export supporting + //! @return true if export is supported + Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; + + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; + + //! Gets list of supported file extensions + //! @return list of extensions + Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; + + //! Checks the file content to verify a format + //! @param[in] theBuffer read stream buffer to check content + //! @return Standard_True if file is supported by a current provider + Standard_EXPORT virtual bool CheckContent(const Handle(NCollection_Buffer)& theBuffer) const + Standard_OVERRIDE; + +public: + struct RWPly_InternalSection + { + // Common + // clang-format off + double FileLengthUnit = 1.; //!< File length units to convert from while reading the file, defined as scale factor for m (meters) + RWMesh_CoordinateSystem SystemCS = RWMesh_CoordinateSystem_Zup; //!< System origin coordinate system to perform conversion into during read + RWMesh_CoordinateSystem FileCS = RWMesh_CoordinateSystem_Yup; //!< File origin coordinate system to perform conversion during read + // Writing + bool WriteNormals = true; //!< Flag for write normals + bool WriteColors = true; //!< Flag for write colors + bool WriteTexCoords = false; //!< Flag for write UV / texture coordinates + bool WritePartId = true; //!< Flag for write part Id as element attribute + bool WriteFaceId = false; //!< Flag for write face Id as element attribute. Cannot be combined with HasPartId + // clang-format on + TCollection_AsciiString WriteComment; //!< Export special comment + TCollection_AsciiString WriteAuthor; //!< Author of exported file name + } InternalParameters; +}; + +#endif // _DEPLY_ConfigurationNode_HeaderFile diff --git a/src/RWPly/RWPly_Provider.cxx b/src/DEPLY/DEPLY_Provider.cxx similarity index 56% rename from src/RWPly/RWPly_Provider.cxx rename to src/DEPLY/DEPLY_Provider.cxx index bdabd37376..7317c3b6bf 100644 --- a/src/RWPly/RWPly_Provider.cxx +++ b/src/DEPLY/DEPLY_Provider.cxx @@ -11,67 +11,59 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include #include +#include #include #include -#include -#include #include +#include #include #include -#include #include +#include #include -IMPLEMENT_STANDARD_RTTIEXT(RWPly_Provider, DE_Provider) - -//======================================================================= -// function : RWPly_Provider -// purpose : -//======================================================================= -RWPly_Provider::RWPly_Provider() -{} - -//======================================================================= -// function : RWPly_Provider -// purpose : -//======================================================================= -RWPly_Provider::RWPly_Provider(const Handle(DE_ConfigurationNode)& theNode) - :DE_Provider(theNode) -{} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWPly_Provider::Write(const TCollection_AsciiString& thePath, +IMPLEMENT_STANDARD_RTTIEXT(DEPLY_Provider, DE_Provider) + +//================================================================================================= + +DEPLY_Provider::DEPLY_Provider() {} + +//================================================================================================= + +DEPLY_Provider::DEPLY_Provider(const Handle(DE_ConfigurationNode)& theNode) + : DE_Provider(theNode) +{ +} + +//================================================================================================= + +bool DEPLY_Provider::Write(const TCollection_AsciiString& thePath, const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) { (void)theWS; return Write(thePath, theDocument, theProgress); } -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWPly_Provider::Write(const TCollection_AsciiString& thePath, +//================================================================================================= + +bool DEPLY_Provider::Write(const TCollection_AsciiString& thePath, const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) + const Message_ProgressRange& theProgress) { - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(RWPly_ConfigurationNode))) + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEPLY_ConfigurationNode))) { - Message::SendFail() << "Error in the RWPly_Provider during writing the file " << - thePath << "\t: Incorrect or empty Configuration Node"; + Message::SendFail() << "Error in the DEPLY_Provider during writing the file " << thePath + << "\t: Incorrect or empty Configuration Node"; return false; } - Handle(RWPly_ConfigurationNode) aNode = Handle(RWPly_ConfigurationNode)::DownCast(GetNode()); + Handle(DEPLY_ConfigurationNode) aNode = Handle(DEPLY_ConfigurationNode)::DownCast(GetNode()); - TDF_LabelSequence aRootLabels; + TDF_LabelSequence aRootLabels; Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); aShapeTool->GetFreeShapes(aRootLabels); if (aRootLabels.IsEmpty()) @@ -89,7 +81,7 @@ bool RWPly_Provider::Write(const TCollection_AsciiString& thePath, aFileInfo.Add("Comments", aNode->InternalParameters.WriteComment); } RWMesh_CoordinateSystemConverter aConverter; - Standard_Real aScaleFactorM = 1.; + Standard_Real aScaleFactorM = 1.; if (XCAFDoc_DocumentTool::GetLengthUnit(theDocument, aScaleFactorM)) { aConverter.SetInputLengthUnit(aScaleFactorM); @@ -97,8 +89,9 @@ bool RWPly_Provider::Write(const TCollection_AsciiString& thePath, else { aConverter.SetInputLengthUnit(aNode->GlobalParameters.SystemUnit / 1000.); - Message::SendWarning() << "Warning in the RWPly_Provider during writing the file " << - thePath << "\t: The document has no information on Units. Using global parameter as initial Unit."; + Message::SendWarning() + << "Warning in the DEPLY_Provider during writing the file " << thePath + << "\t: The document has no information on Units. Using global parameter as initial Unit."; } aConverter.SetInputCoordinateSystem(aNode->InternalParameters.SystemCS); aConverter.SetOutputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000.); @@ -112,55 +105,47 @@ bool RWPly_Provider::Write(const TCollection_AsciiString& thePath, aPlyCtx.SetFaceId(aNode->InternalParameters.WriteFaceId); if (!aPlyCtx.Perform(theDocument, aFileInfo, theProgress)) { - Message::SendFail() << "Error in the RWPly_Provider during writing the file " - << thePath << "\t: Cannot perform the document"; + Message::SendFail() << "Error in the DEPLY_Provider during writing the file " << thePath + << "\t: Cannot perform the document"; return false; } return true; } -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWPly_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, +//================================================================================================= + +bool DEPLY_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) + const Message_ProgressRange& theProgress) { (void)theWS; return Write(thePath, theShape, theProgress); } -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWPly_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) +//================================================================================================= + +bool DEPLY_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) { - Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF"); + Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF"); Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main()); aShTool->AddShape(theShape); return Write(thePath, aDoc, theProgress); } -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString RWPly_Provider::GetFormat() const +//================================================================================================= + +TCollection_AsciiString DEPLY_Provider::GetFormat() const { return TCollection_AsciiString("PLY"); } -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString RWPly_Provider::GetVendor() const +//================================================================================================= + +TCollection_AsciiString DEPLY_Provider::GetVendor() const { return TCollection_AsciiString("OCC"); } diff --git a/src/DEPLY/DEPLY_Provider.hxx b/src/DEPLY/DEPLY_Provider.hxx new file mode 100644 index 0000000000..6870d3c047 --- /dev/null +++ b/src/DEPLY/DEPLY_Provider.hxx @@ -0,0 +1,97 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEPLY_Provider_HeaderFile +#define _DEPLY_Provider_HeaderFile + +#include + +//! The class to transfer PLY files. +//! Writes any PLY files from OCCT. +//! Each operation needs configuration node. +//! +//! Providers grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "PLY" +//! The import process isn't supported. +//! The export process is supported. +class DEPLY_Provider : public DE_Provider +{ +public: + DEFINE_STANDARD_RTTIEXT(DEPLY_Provider, DE_Provider) + +public: + //! Default constructor + //! Configure translation process with global configuration + Standard_EXPORT DEPLY_Provider(); + + //! Configure translation process + //! @param[in] theNode object to copy + Standard_EXPORT DEPLY_Provider(const Handle(DE_ConfigurationNode)& theNode); + +public: + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + +public: + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; +}; + +#endif // _DEPLY_Provider_HeaderFile diff --git a/src/DEPLY/FILES b/src/DEPLY/FILES new file mode 100644 index 0000000000..4aee3cca68 --- /dev/null +++ b/src/DEPLY/FILES @@ -0,0 +1,4 @@ +DEPLY_ConfigurationNode.cxx +DEPLY_ConfigurationNode.hxx +DEPLY_Provider.cxx +DEPLY_Provider.hxx diff --git a/src/STEPCAFControl/STEPCAFControl_ConfigurationNode.cxx b/src/DESTEP/DESTEP_ConfigurationNode.cxx similarity index 63% rename from src/STEPCAFControl/STEPCAFControl_ConfigurationNode.cxx rename to src/DESTEP/DESTEP_ConfigurationNode.cxx index 702a06193b..1963515398 100644 --- a/src/STEPCAFControl/STEPCAFControl_ConfigurationNode.cxx +++ b/src/DESTEP/DESTEP_ConfigurationNode.cxx @@ -11,70 +11,81 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include +#include #include #include #include -#include -IMPLEMENT_STANDARD_RTTIEXT(STEPCAFControl_ConfigurationNode, DE_ConfigurationNode) +IMPLEMENT_STANDARD_RTTIEXT(DESTEP_ConfigurationNode, DE_ConfigurationNode) namespace { - static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() - { - static const TCollection_AsciiString aScope = "provider"; - return aScope; - } +static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() +{ + static const TCollection_AsciiString aScope = "provider"; + return aScope; +} + +// Wrapper to auto-load DE component +DE_PluginHolder THE_OCCT_STEP_COMPONENT_PLUGIN; +} // namespace - // Wrapper to auto-load DE component - DE_PluginHolder THE_OCCT_STEP_COMPONENT_PLUGIN; +//================================================================================================= + +DESTEP_ConfigurationNode::DESTEP_ConfigurationNode() + : DE_ConfigurationNode() +{ } -//======================================================================= -// function : STEPCAFControl_ConfigurationNode -// purpose : -//======================================================================= -STEPCAFControl_ConfigurationNode::STEPCAFControl_ConfigurationNode() : - DE_ConfigurationNode() -{} - -//======================================================================= -// function : STEPCAFControl_ConfigurationNode -// purpose : -//======================================================================= -STEPCAFControl_ConfigurationNode::STEPCAFControl_ConfigurationNode(const Handle(STEPCAFControl_ConfigurationNode)& theNode) - :DE_ConfigurationNode(theNode), - InternalParameters(theNode->InternalParameters) -{} - -//======================================================================= -// function : Load -// purpose : -//======================================================================= -bool STEPCAFControl_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) +//================================================================================================= + +DESTEP_ConfigurationNode::DESTEP_ConfigurationNode(const Handle(DESTEP_ConfigurationNode)& theNode) + : DE_ConfigurationNode(theNode), + InternalParameters(theNode->InternalParameters) { - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); +} + +//================================================================================================= - InternalParameters.ReadBSplineContinuity = (StepData_ConfParameters::ReadMode_BSplineContinuity) - theResource->IntegerVal("read.iges.bspline.continuity", InternalParameters.ReadBSplineContinuity, aScope); - InternalParameters.ReadPrecisionMode = (StepData_ConfParameters::ReadMode_Precision) - theResource->IntegerVal("read.precision.mode", InternalParameters.ReadPrecisionMode, aScope); +bool DESTEP_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) +{ + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); + + InternalParameters.ReadBSplineContinuity = + (StepData_ConfParameters::ReadMode_BSplineContinuity)theResource->IntegerVal( + "read.iges.bspline.continuity", + InternalParameters.ReadBSplineContinuity, + aScope); + InternalParameters.ReadPrecisionMode = + (StepData_ConfParameters::ReadMode_Precision) + theResource->IntegerVal("read.precision.mode", InternalParameters.ReadPrecisionMode, aScope); InternalParameters.ReadPrecisionVal = theResource->RealVal("read.precision.val", InternalParameters.ReadPrecisionVal, aScope); - InternalParameters.ReadMaxPrecisionMode = (StepData_ConfParameters::ReadMode_MaxPrecision) - theResource->IntegerVal("read.maxprecision.mode", InternalParameters.ReadMaxPrecisionMode, aScope); + InternalParameters.ReadMaxPrecisionMode = + (StepData_ConfParameters::ReadMode_MaxPrecision)theResource->IntegerVal( + "read.maxprecision.mode", + InternalParameters.ReadMaxPrecisionMode, + aScope); InternalParameters.ReadMaxPrecisionVal = theResource->RealVal("read.maxprecision.val", InternalParameters.ReadMaxPrecisionVal, aScope); InternalParameters.ReadSameParamMode = - theResource->BooleanVal("read.stdsameparameter.mode", InternalParameters.ReadSameParamMode, aScope); - InternalParameters.ReadSurfaceCurveMode = (StepData_ConfParameters::ReadMode_SurfaceCurve) - theResource->IntegerVal("read.surfacecurve.mode", InternalParameters.ReadSurfaceCurveMode, aScope); + theResource->BooleanVal("read.stdsameparameter.mode", + InternalParameters.ReadSameParamMode, + aScope); + InternalParameters.ReadSurfaceCurveMode = + (StepData_ConfParameters::ReadMode_SurfaceCurve)theResource->IntegerVal( + "read.surfacecurve.mode", + InternalParameters.ReadSurfaceCurveMode, + aScope); InternalParameters.EncodeRegAngle = theResource->RealVal("read.encoderegularity.angle", InternalParameters.EncodeRegAngle, aScope); - InternalParameters.AngleUnit = (StepData_ConfParameters::AngleUnitMode) - theResource->IntegerVal("angleunit.mode", InternalParameters.AngleUnit, aScope); + InternalParameters.AngleUnit = + (StepData_ConfParameters::AngleUnitMode)theResource->IntegerVal("angleunit.mode", + InternalParameters.AngleUnit, + aScope); InternalParameters.ReadResourceName = theResource->StringVal("read.resource.name", InternalParameters.ReadResourceName, aScope); @@ -82,24 +93,36 @@ bool STEPCAFControl_ConfigurationNode::Load(const Handle(DE_ConfigurationContext theResource->StringVal("read.sequence", InternalParameters.ReadSequence, aScope); InternalParameters.ReadProductMode = theResource->BooleanVal("read.product.mode", InternalParameters.ReadProductMode, aScope); - InternalParameters.ReadProductContext = (StepData_ConfParameters::ReadMode_ProductContext) - theResource->IntegerVal("read.product.context", InternalParameters.ReadProductContext, aScope); - InternalParameters.ReadShapeRepr = (StepData_ConfParameters::ReadMode_ShapeRepr) - theResource->IntegerVal("read.shape.repr", InternalParameters.ReadShapeRepr, aScope); - InternalParameters.ReadTessellated = (StepData_ConfParameters::RWMode_Tessellated) - theResource->IntegerVal("read.tessellated", InternalParameters.ReadTessellated, aScope); - InternalParameters.ReadAssemblyLevel = (StepData_ConfParameters::ReadMode_AssemblyLevel) - theResource->IntegerVal("read.assembly.level", InternalParameters.ReadAssemblyLevel, aScope); + InternalParameters.ReadProductContext = + (StepData_ConfParameters::ReadMode_ProductContext)theResource->IntegerVal( + "read.product.context", + InternalParameters.ReadProductContext, + aScope); + InternalParameters.ReadShapeRepr = + (StepData_ConfParameters::ReadMode_ShapeRepr) + theResource->IntegerVal("read.shape.repr", InternalParameters.ReadShapeRepr, aScope); + InternalParameters.ReadTessellated = + (StepData_ConfParameters::RWMode_Tessellated) + theResource->IntegerVal("read.tessellated", InternalParameters.ReadTessellated, aScope); + InternalParameters.ReadAssemblyLevel = + (StepData_ConfParameters::ReadMode_AssemblyLevel) + theResource->IntegerVal("read.assembly.level", InternalParameters.ReadAssemblyLevel, aScope); InternalParameters.ReadRelationship = theResource->BooleanVal("read.shape.relationship", InternalParameters.ReadRelationship, aScope); InternalParameters.ReadShapeAspect = theResource->BooleanVal("read.shape.aspect", InternalParameters.ReadShapeAspect, aScope); InternalParameters.ReadConstrRelation = - theResource->BooleanVal("read.constructivegeom.relationship", InternalParameters.ReadConstrRelation, aScope); + theResource->BooleanVal("read.constructivegeom.relationship", + InternalParameters.ReadConstrRelation, + aScope); InternalParameters.ReadSubshapeNames = - theResource->BooleanVal("read.stepcaf.subshapes.name", InternalParameters.ReadSubshapeNames, aScope); - InternalParameters.ReadCodePage = (Resource_FormatType) - theResource->IntegerVal("read.codepage", InternalParameters.ReadCodePage, aScope); + theResource->BooleanVal("read.stepcaf.subshapes.name", + InternalParameters.ReadSubshapeNames, + aScope); + InternalParameters.ReadCodePage = + (Resource_FormatType)theResource->IntegerVal("read.codepage", + InternalParameters.ReadCodePage, + aScope); InternalParameters.ReadNonmanifold = theResource->BooleanVal("read.nonmanifold", InternalParameters.ReadNonmanifold, aScope); InternalParameters.ReadIdeas = @@ -107,7 +130,9 @@ bool STEPCAFControl_ConfigurationNode::Load(const Handle(DE_ConfigurationContext InternalParameters.ReadAllShapes = theResource->BooleanVal("read.all.shapes", InternalParameters.ReadAllShapes, aScope); InternalParameters.ReadRootTransformation = - theResource->BooleanVal("read.root.transformation", InternalParameters.ReadRootTransformation, aScope); + theResource->BooleanVal("read.root.transformation", + InternalParameters.ReadRootTransformation, + aScope); InternalParameters.ReadColor = theResource->BooleanVal("read.color", InternalParameters.ReadColor, aScope); InternalParameters.ReadName = @@ -119,30 +144,43 @@ bool STEPCAFControl_ConfigurationNode::Load(const Handle(DE_ConfigurationContext InternalParameters.ReadMetadata = theResource->BooleanVal("read.metadata", InternalParameters.ReadMetadata, aScope); - InternalParameters.WritePrecisionMode = (StepData_ConfParameters::WriteMode_PrecisionMode) - theResource->IntegerVal("write.precision.mode", InternalParameters.WritePrecisionMode, aScope); + InternalParameters.WritePrecisionMode = + (StepData_ConfParameters::WriteMode_PrecisionMode)theResource->IntegerVal( + "write.precision.mode", + InternalParameters.WritePrecisionMode, + aScope); InternalParameters.WritePrecisionVal = theResource->RealVal("write.precision.val", InternalParameters.WritePrecisionVal, aScope); - InternalParameters.WriteAssembly = (StepData_ConfParameters::WriteMode_Assembly) - theResource->IntegerVal("write.assembly", InternalParameters.WriteAssembly, aScope); - InternalParameters.WriteSchema = (StepData_ConfParameters::WriteMode_StepSchema) - theResource->IntegerVal("write.schema", InternalParameters.WriteSchema, aScope); - InternalParameters.WriteTessellated = (StepData_ConfParameters::RWMode_Tessellated) - theResource->IntegerVal("write.tessellated", InternalParameters.WriteTessellated, aScope); + InternalParameters.WriteAssembly = + (StepData_ConfParameters::WriteMode_Assembly) + theResource->IntegerVal("write.assembly", InternalParameters.WriteAssembly, aScope); + InternalParameters.WriteSchema = + (StepData_ConfParameters::WriteMode_StepSchema) + theResource->IntegerVal("write.schema", InternalParameters.WriteSchema, aScope); + InternalParameters.WriteTessellated = + (StepData_ConfParameters::RWMode_Tessellated) + theResource->IntegerVal("write.tessellated", InternalParameters.WriteTessellated, aScope); InternalParameters.WriteProductName = theResource->StringVal("write.product.name", InternalParameters.WriteProductName, aScope); InternalParameters.WriteSurfaceCurMode = - theResource->BooleanVal("write.surfacecurve.mode", InternalParameters.WriteSurfaceCurMode, aScope); - InternalParameters.WriteUnit = (UnitsMethods_LengthUnit) - theResource->IntegerVal("write.unit", InternalParameters.WriteUnit, aScope); + theResource->BooleanVal("write.surfacecurve.mode", + InternalParameters.WriteSurfaceCurMode, + aScope); + InternalParameters.WriteUnit = + (UnitsMethods_LengthUnit)theResource->IntegerVal("write.unit", + InternalParameters.WriteUnit, + aScope); InternalParameters.WriteResourceName = theResource->StringVal("write.resource.name", InternalParameters.WriteResourceName, aScope); InternalParameters.WriteSequence = theResource->StringVal("write.sequence", InternalParameters.WriteSequence, aScope); - InternalParameters.WriteVertexMode = (StepData_ConfParameters::WriteMode_VertexMode) - theResource->IntegerVal("write.vertex.mode", InternalParameters.WriteVertexMode, aScope); + InternalParameters.WriteVertexMode = + (StepData_ConfParameters::WriteMode_VertexMode) + theResource->IntegerVal("write.vertex.mode", InternalParameters.WriteVertexMode, aScope); InternalParameters.WriteSubshapeNames = - theResource->BooleanVal("write.stepcaf.subshapes.name", InternalParameters.WriteSubshapeNames, aScope); + theResource->BooleanVal("write.stepcaf.subshapes.name", + InternalParameters.WriteSubshapeNames, + aScope); InternalParameters.WriteColor = theResource->BooleanVal("write.color", InternalParameters.WriteColor, aScope); InternalParameters.WriteName = @@ -151,22 +189,24 @@ bool STEPCAFControl_ConfigurationNode::Load(const Handle(DE_ConfigurationContext theResource->BooleanVal("write.layer", InternalParameters.WriteLayer, aScope); InternalParameters.WriteProps = theResource->BooleanVal("write.props", InternalParameters.WriteProps, aScope); - InternalParameters.WriteModelType = (STEPControl_StepModelType) - theResource->IntegerVal("write.model.type", InternalParameters.WriteModelType, aScope); + InternalParameters.WriteModelType = + (STEPControl_StepModelType)theResource->IntegerVal("write.model.type", + InternalParameters.WriteModelType, + aScope); return true; } -//======================================================================= -// function : Save -// purpose : -//======================================================================= -TCollection_AsciiString STEPCAFControl_ConfigurationNode::Save() const +//================================================================================================= + +TCollection_AsciiString DESTEP_ConfigurationNode::Save() const { TCollection_AsciiString aResult; aResult += "!*****************************************************************************\n"; - aResult = aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; + aResult = + aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; aResult += "!\n"; aResult += "!Common parameters:\n"; @@ -176,7 +216,8 @@ TCollection_AsciiString STEPCAFControl_ConfigurationNode::Save() const aResult += "!Manages the continuity of BSpline curves (IGES entities 106, 112 and 126) "; aResult += "after translation to Open CASCADE Technology\n"; aResult += "!Default value: 1. Available values: 0, 1, 2\n"; - aResult += aScope + "read.iges.bspline.continuity :\t " + InternalParameters.ReadBSplineContinuity + "\n"; + aResult += + aScope + "read.iges.bspline.continuity :\t " + InternalParameters.ReadBSplineContinuity + "\n"; aResult += "!\n"; aResult += "!\n"; @@ -194,12 +235,15 @@ TCollection_AsciiString STEPCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Defines the mode of applying the maximum allowed tolerance\n"; - aResult += "!Default value: \"Preferred\"(0). Available values: \"Preferred\"(0), \"Forced\"(1)\n"; - aResult += aScope + "read.maxprecision.mode :\t " + InternalParameters.ReadMaxPrecisionMode + "\n"; + aResult += + "!Default value: \"Preferred\"(0). Available values: \"Preferred\"(0), \"Forced\"(1)\n"; + aResult += + aScope + "read.maxprecision.mode :\t " + InternalParameters.ReadMaxPrecisionMode + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!Defines the maximum allowable tolerance (in internal units, which are specified in xstep.cascade.unit)"; + aResult += "!Defines the maximum allowable tolerance (in internal units, which are specified in " + "xstep.cascade.unit)"; aResult += " of the shape\n"; aResult += "!Default value: 1. Available values: any real positive (non null) value\n"; aResult += aScope + "read.maxprecision.val :\t " + InternalParameters.ReadMaxPrecisionVal + "\n"; @@ -208,22 +252,28 @@ TCollection_AsciiString STEPCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Defines the using of BRepLib::SameParameter\n"; aResult += "!Default value: \"Off\"(0). Available values: \"Off\"(0), \"On\"(1)\n"; - aResult += aScope + "read.stdsameparameter.mode :\t " + InternalParameters.ReadSameParamMode + "\n"; + aResult += + aScope + "read.stdsameparameter.mode :\t " + InternalParameters.ReadSameParamMode + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!Preference for the computation of curves in case of 2D/3D inconsistency in an entity "; + aResult += + "!Preference for the computation of curves in case of 2D/3D inconsistency in an entity "; aResult += "which has both 2D and 3D representations.\n"; - aResult += "!Default value: \"Default\"(0). Available values: \"Default\"(0), \"2DUse_Preferred\"(2), "; + aResult += + "!Default value: \"Default\"(0). Available values: \"Default\"(0), \"2DUse_Preferred\"(2), "; aResult += "\"2DUse_Forced\"(-2), \"3DUse_Preferred\"(3), \"3DUse_Forced\"(-3)\n"; - aResult += aScope + "read.surfacecurve.mode :\t " + InternalParameters.ReadSurfaceCurveMode + "\n"; + aResult += + aScope + "read.surfacecurve.mode :\t " + InternalParameters.ReadSurfaceCurveMode + "\n"; aResult += "!\n"; aResult += "!\n"; aResult += "!This parameter is used within the BRepLib::EncodeRegularity() function "; aResult += "which is called for a shape read "; - aResult += "from an IGES or a STEP file at the end of translation process.This function sets the regularity flag of"; - aResult += " an edge in a shell when this edge is shared by two faces.This flag shows the continuity, "; + aResult += "from an IGES or a STEP file at the end of translation process.This function sets the " + "regularity flag of"; + aResult += + " an edge in a shell when this edge is shared by two faces.This flag shows the continuity, "; aResult += "which these two faces are connected with at that edge.\n"; aResult += "!Default value (in degrees): 0.57295779513. Available values: \n"; aResult += aScope + "read.encoderegularity.angle :\t " + InternalParameters.EncodeRegAngle + "\n"; @@ -252,23 +302,29 @@ TCollection_AsciiString STEPCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!\n"; - aResult += "!Defines the approach used for selection of top-level STEP entities for translation, "; + aResult += + "!Defines the approach used for selection of top-level STEP entities for translation, "; aResult += "and for recognition of assembly structures\n"; aResult += "!Default value: 1(\"ON\"). Available values: 0(\"OFF\"), 1(\"ON\")\n"; aResult += aScope + "read.product.mode :\t " + InternalParameters.ReadProductMode + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!When reading AP 209 STEP files, allows selecting either only 'design' or 'analysis', "; + aResult += + "!When reading AP 209 STEP files, allows selecting either only 'design' or 'analysis', "; aResult += "or both types of products for translation\n"; - aResult += "!Default value: 1(\"all\"). Available values: 1(\"all\"), 2(\"design\"), 3(\"analysis\")\n"; + aResult += + "!Default value: 1(\"all\"). Available values: 1(\"all\"), 2(\"design\"), 3(\"analysis\")\n"; aResult += aScope + "read.product.context :\t " + InternalParameters.ReadProductContext + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!Specifies preferred type of representation of the shape of the product, in case if a STEP file contains"; - aResult += " more than one representation(i.e.multiple PRODUCT_DEFINITION_SHAPE entities) for a single product\n"; - aResult += "!Default value: 1(\"All\"). Available values: 1(\"All\"), 2(\"ABSR\"), 3(\"MSSR\"), 4(\"GBSSR\"), "; + aResult += "!Specifies preferred type of representation of the shape of the product, in case if " + "a STEP file contains"; + aResult += " more than one representation(i.e.multiple PRODUCT_DEFINITION_SHAPE entities) for a " + "single product\n"; + aResult += "!Default value: 1(\"All\"). Available values: 1(\"All\"), 2(\"ABSR\"), 3(\"MSSR\"), " + "4(\"GBSSR\"), "; aResult += "5(\"FBSR\"), 6(\"EBWSR\"), 7(\"GBWSR\")\n"; aResult += aScope + "read.shape.repr :\t " + InternalParameters.ReadShapeRepr + "\n"; aResult += "!\n"; @@ -287,40 +343,52 @@ TCollection_AsciiString STEPCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!\n"; - aResult += "!Defines whether shapes associated with the main SHAPE_DEFINITION_REPRESENTATION entity"; + aResult += + "!Defines whether shapes associated with the main SHAPE_DEFINITION_REPRESENTATION entity"; aResult += "of the product via SHAPE_REPRESENTATIONSHIP_RELATION should be translated\n"; aResult += "!Default value: 1(\"ON\"). Available values: 0(\"OFF\"), 1(\"ON\")\n"; aResult += aScope + "read.shape.relationship :\t " + InternalParameters.ReadRelationship + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!Defines whether shapes associated with the PRODUCT_DEFINITION_SHAPE entity of the product "; + aResult += + "!Defines whether shapes associated with the PRODUCT_DEFINITION_SHAPE entity of the product "; aResult += "via SHAPE_ASPECT should be translated.\n"; aResult += "!Default value: 1(\"ON\"). Available values: 0(\"OFF\"), 1(\"ON\")\n"; aResult += aScope + "read.shape.aspect :\t " + InternalParameters.ReadShapeAspect + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!Boolean flag regulating translation of \"CONSTRUCTIVE_GEOMETRY_REPRESENTATION_RELATIONSHIP\" "; + aResult += "!Boolean flag regulating translation of " + "\"CONSTRUCTIVE_GEOMETRY_REPRESENTATION_RELATIONSHIP\" "; aResult += "entities that define position of constructive geometry entities contained in "; - aResult += "\"CONSTRUCTIVE_GEOMETRY_REPRESENTATION\" with respect to the main representation of the shape (product).\n"; + aResult += "\"CONSTRUCTIVE_GEOMETRY_REPRESENTATION\" with respect to the main representation of " + "the shape (product).\n"; aResult += "!Default value: 0(\"OFF\"). Available values: 0(\"OFF\"), 1(\"ON\")\n"; - aResult += aScope + "read.constructivegeom.relationship :\t " + InternalParameters.ReadConstrRelation + "\n"; + aResult += aScope + "read.constructivegeom.relationship :\t " + + InternalParameters.ReadConstrRelation + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!Indicates whether to read sub-shape names from 'Name' attributes of STEP Representation Items\n"; + aResult += "!Indicates whether to read sub-shape names from 'Name' attributes of STEP " + "Representation Items\n"; aResult += "!Default value: 0(\"OFF\"). Available values: 0(\"OFF\"), 1(\"ON\")\n"; - aResult += aScope + "read.stepcaf.subshapes.name :\t " + InternalParameters.ReadSubshapeNames + "\n"; + aResult += + aScope + "read.stepcaf.subshapes.name :\t " + InternalParameters.ReadSubshapeNames + "\n"; aResult += "!\n"; aResult += "!\n"; aResult += "!STEP file encoding for names translation\n"; - aResult += "!Default value: 4(\"UTF8\"). Available values: 0(\"SJIS\"), 1(\"EUC\"), 2(\"NoConversion\"), "; - aResult += "3(\"GB\"), 4(\"UTF8\"), 5(\"SystemLocale\"), 6(\"CP1250\"), 7(\"CP1251\"), 8(\"CP1252\"), "; - aResult += "9(\"CP1253\"), 10(\"CP1254\"), 11(\"CP1255\"), 12(\"CP1256\"), 13(\"CP1257\"), 14(\"CP1258\"), "; - aResult += "15(\"iso8859-1\"), 16(\"iso8859-2\"), 17(\"iso8859-3\"), 18(\"iso8859-4\"), 19(\"iso8859-5\"), "; - aResult += "20(\"iso8859-6\"), 21(\"iso8859-7\"), 22(\"iso8859-8\"), 23(\"iso8859-9\"), 24(\"CP850\")\n"; + aResult += + "!Default value: 4(\"UTF8\"). Available values: 0(\"SJIS\"), 1(\"EUC\"), 2(\"NoConversion\"), "; + aResult += + "3(\"GB\"), 4(\"UTF8\"), 5(\"SystemLocale\"), 6(\"CP1250\"), 7(\"CP1251\"), 8(\"CP1252\"), "; + aResult += "9(\"CP1253\"), 10(\"CP1254\"), 11(\"CP1255\"), 12(\"CP1256\"), 13(\"CP1257\"), " + "14(\"CP1258\"), "; + aResult += "15(\"iso8859-1\"), 16(\"iso8859-2\"), 17(\"iso8859-3\"), 18(\"iso8859-4\"), " + "19(\"iso8859-5\"), "; + aResult += + "20(\"iso8859-6\"), 21(\"iso8859-7\"), 22(\"iso8859-8\"), 23(\"iso8859-9\"), 24(\"CP850\")\n"; aResult += aScope + "read.codepage :\t " + InternalParameters.ReadCodePage + "\n"; aResult += "!\n"; @@ -343,9 +411,11 @@ TCollection_AsciiString STEPCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!\n"; - aResult += "!Mode to variate apply or not transformation placed in the root shape representation.\n"; + aResult += + "!Mode to variate apply or not transformation placed in the root shape representation.\n"; aResult += "!Default value: 1(\"ON\"). Available values: 0(\"OFF\"), 1(\"ON\")\n"; - aResult += aScope + "read.root.transformation :\t " + InternalParameters.ReadRootTransformation + "\n"; + aResult += + aScope + "read.root.transformation :\t " + InternalParameters.ReadRootTransformation + "\n"; aResult += "!\n"; aResult += "!\n"; @@ -367,13 +437,15 @@ TCollection_AsciiString STEPCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!\n"; - aResult += "!Setting up the read.props parameter which is used to indicate read Validation properties or not\n"; + aResult += "!Setting up the read.props parameter which is used to indicate read Validation " + "properties or not\n"; aResult += "!Default value: +. Available values: \"-\", \"+\"\n"; aResult += aScope + "read.props :\t " + InternalParameters.ReadProps + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!Setting up the read.metadata parameter which is used to indicate read Metadata or not\n"; + aResult += + "!Setting up the read.metadata parameter which is used to indicate read Metadata or not\n"; aResult += "!Default value: 1(\"ON\"). Available values: 0(\"OFF\"), 1(\"ON\")\n"; aResult += aScope + "read.metadata :\t " + InternalParameters.ReadMetadata + "\n"; aResult += "!\n"; @@ -403,7 +475,8 @@ TCollection_AsciiString STEPCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!Defines the version of schema used for the output STEP file\n"; - aResult += "!Default value: 1 or AP214CD. Available values: 1 or AP214CD, 2 or AP214DIS, 3 or AP203, "; + aResult += + "!Default value: 1 or AP214CD. Available values: 1 or AP214CD, 2 or AP214DIS, 3 or AP203, "; aResult += "4 or AP214IS, 5 or AP242DIS\n"; aResult += aScope + "write.schema :\t " + InternalParameters.WriteSchema + "\n"; aResult += "!\n"; @@ -415,20 +488,25 @@ TCollection_AsciiString STEPCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!\n"; - aResult += "!Defines the text string that will be used for field 'name' of PRODUCT entities written to the STEP file\n"; - aResult += "!Default value: OCCT STEP translator (current OCCT version number). Available values: \n"; + aResult += "!Defines the text string that will be used for field 'name' of PRODUCT entities " + "written to the STEP file\n"; + aResult += "!Default value: OCCT STEP translator (current OCCT version number). Available " + "values: \n"; aResult += aScope + "write.product.name :\t " + InternalParameters.WriteProductName + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!This parameter indicates whether parametric curves should be written into the STEP file\n"; + aResult += + "!This parameter indicates whether parametric curves should be written into the STEP file\n"; aResult += "!Default value: 1(\"ON\"). Available values: 0(\"OFF\"), 1(\"ON\")\n"; - aResult += aScope + "write.surfacecurve.mode :\t " + InternalParameters.WriteSurfaceCurMode + "\n"; + aResult += + aScope + "write.surfacecurve.mode :\t " + InternalParameters.WriteSurfaceCurMode + "\n"; aResult += "!\n"; aResult += "!\n"; aResult += "!Defines a unit in which the STEP file should be written.\n"; - aResult += "!Default value: MM(2). Available values: \"INCH\"(1), \"MM\"(2), \"??\"(3), \"FT\"(4), \"MI\"(5), "; + aResult += "!Default value: MM(2). Available values: \"INCH\"(1), \"MM\"(2), \"??\"(3), " + "\"FT\"(4), \"MI\"(5), "; aResult += "\"M\"(6), \"KM\"(7), \"MIL\"(8), \"UM\"(9), \"CM\"(10), \"UIN\"(11)\n"; aResult += aScope + "write.unit :\t " + InternalParameters.WriteUnit + "\n"; aResult += "!\n"; @@ -447,14 +525,17 @@ TCollection_AsciiString STEPCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!This parameter indicates which of free vertices writing mode is switch on\n"; - aResult += "!Default value: 0(\"One Compound\"). Available values: 0(\"One Compound\"), 1(\"Signle Vertex\")\n"; + aResult += "!Default value: 0(\"One Compound\"). Available values: 0(\"One Compound\"), " + "1(\"Signle Vertex\")\n"; aResult += aScope + "write.vertex.mode :\t " + InternalParameters.WriteVertexMode + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!Indicates whether to write sub-shape names to 'Name' attributes of STEP Representation Items\n"; + aResult += "!Indicates whether to write sub-shape names to 'Name' attributes of STEP " + "Representation Items\n"; aResult += "!Default value: 0(\"OFF\"). Available values: 0(\"OFF\"), 1(\"ON\")\n"; - aResult += aScope + "write.stepcaf.subshapes.name :\t " + InternalParameters.WriteSubshapeNames + "\n"; + aResult += + aScope + "write.stepcaf.subshapes.name :\t " + InternalParameters.WriteSubshapeNames + "\n"; aResult += "!\n"; aResult += "!\n"; @@ -470,19 +551,22 @@ TCollection_AsciiString STEPCAFControl_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!\n"; - aResult += "!Setting up the write.layer parameter which is used to indicate write Layers or not\n"; + aResult += + "!Setting up the write.layer parameter which is used to indicate write Layers or not\n"; aResult += "!Default value: +. Available values: \"-\", \"+\"\n"; aResult += aScope + "write.layer :\t " + InternalParameters.WriteLayer + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!Setting up the write.props parameter which is used to indicate write Validation properties or not\n"; + aResult += "!Setting up the write.props parameter which is used to indicate write Validation " + "properties or not\n"; aResult += "!Default value: +. Available values: \"-\", \"+\"\n"; aResult += aScope + "write.props :\t " + InternalParameters.WriteProps + "\n"; aResult += "!\n"; aResult += "!\n"; - aResult += "!Setting up the Model Type which gives you the choice of translation mode for an Open CASCADE shape that "; + aResult += "!Setting up the Model Type which gives you the choice of translation mode for an " + "Open CASCADE shape that "; aResult += "is being translated to STEP\n"; aResult += "!Default value: 0. Available values: 0, 1, 2, 3, 4\n"; aResult += aScope + "write.model.type :\t " + InternalParameters.WriteModelType + "\n"; @@ -493,65 +577,51 @@ TCollection_AsciiString STEPCAFControl_ConfigurationNode::Save() const return aResult; } -//======================================================================= -// function : Copy -// purpose : -//======================================================================= -Handle(DE_ConfigurationNode) STEPCAFControl_ConfigurationNode::Copy() const +//================================================================================================= + +Handle(DE_ConfigurationNode) DESTEP_ConfigurationNode::Copy() const { - return new STEPCAFControl_ConfigurationNode(*this); + return new DESTEP_ConfigurationNode(*this); } -//======================================================================= -// function : BuildProvider -// purpose : -//======================================================================= -Handle(DE_Provider) STEPCAFControl_ConfigurationNode::BuildProvider() +//================================================================================================= + +Handle(DE_Provider) DESTEP_ConfigurationNode::BuildProvider() { - return new STEPCAFControl_Provider(this); + return new DESTEP_Provider(this); } -//======================================================================= -// function : IsImportSupported -// purpose : -//======================================================================= -bool STEPCAFControl_ConfigurationNode::IsImportSupported() const +//================================================================================================= + +bool DESTEP_ConfigurationNode::IsImportSupported() const { return true; } -//======================================================================= -// function : IsExportSupported -// purpose : -//======================================================================= -bool STEPCAFControl_ConfigurationNode::IsExportSupported() const +//================================================================================================= + +bool DESTEP_ConfigurationNode::IsExportSupported() const { return true; } -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString STEPCAFControl_ConfigurationNode::GetFormat() const +//================================================================================================= + +TCollection_AsciiString DESTEP_ConfigurationNode::GetFormat() const { return TCollection_AsciiString("STEP"); } -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString STEPCAFControl_ConfigurationNode::GetVendor() const +//================================================================================================= + +TCollection_AsciiString DESTEP_ConfigurationNode::GetVendor() const { return TCollection_AsciiString("OCC"); } -//======================================================================= -// function : GetExtensions -// purpose : -//======================================================================= -TColStd_ListOfAsciiString STEPCAFControl_ConfigurationNode::GetExtensions() const +//================================================================================================= + +TColStd_ListOfAsciiString DESTEP_ConfigurationNode::GetExtensions() const { TColStd_ListOfAsciiString anExt; anExt.Append("stp"); @@ -560,11 +630,9 @@ TColStd_ListOfAsciiString STEPCAFControl_ConfigurationNode::GetExtensions() cons return anExt; } -//======================================================================= -// function : CheckContent -// purpose : -//======================================================================= -bool STEPCAFControl_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const +//================================================================================================= + +bool DESTEP_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const { if (theBuffer.IsNull() || theBuffer->Size() < 100) { diff --git a/src/DESTEP/DESTEP_ConfigurationNode.hxx b/src/DESTEP/DESTEP_ConfigurationNode.hxx new file mode 100644 index 0000000000..055bc90d1a --- /dev/null +++ b/src/DESTEP/DESTEP_ConfigurationNode.hxx @@ -0,0 +1,93 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DESTEP_ConfigurationNode_HeaderFile +#define _DESTEP_ConfigurationNode_HeaderFile + +#include +#include +#include +#include +#include + +//! The purpose of this class is to configure the transfer process for STEP format +//! Stores the necessary settings for DESTEP_Provider. +//! Configures and creates special provider to transfer STEP files. +//! +//! Nodes grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "STEP" +//! The supported CAD extensions are ".stp", ".step", ".stpz" +//! The import process is supported. +//! The export process is supported. +class DESTEP_ConfigurationNode : public DE_ConfigurationNode +{ + DEFINE_STANDARD_RTTIEXT(DESTEP_ConfigurationNode, DE_ConfigurationNode) +public: + //! Initializes all field by default + Standard_EXPORT DESTEP_ConfigurationNode(); + + //! Copies values of all fields + //! @param[in] theNode object to copy + Standard_EXPORT DESTEP_ConfigurationNode(const Handle(DESTEP_ConfigurationNode)& theNode); + + //! Updates values according the resource + //! @param[in] theResource input resource to use + //! @return true if theResource loading has ended correctly + Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) + Standard_OVERRIDE; + + //! Writes configuration to the string + //! @return result resource string + Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; + + //! Copies values of all fields + //! @return new object with the same field values + Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; + + //! Creates new provider for the own format + //! @return new created provider + Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; + +public: + //! Checks the import supporting + //! @return true if import is supported + Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; + + //! Checks the export supporting + //! @return true if export is supported + Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; + + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; + + //! Gets list of supported file extensions + //! @return list of extensions + Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; + + //! Checks the file content to verify a format + //! @param[in] theBuffer read stream buffer to check content + //! @return Standard_True if file is supported by a current provider + Standard_EXPORT virtual bool CheckContent(const Handle(NCollection_Buffer)& theBuffer) const + Standard_OVERRIDE; + +public: + StepData_ConfParameters InternalParameters; +}; + +#endif // _DESTEP_ConfigurationNode_HeaderFile diff --git a/src/DESTEP/DESTEP_Provider.cxx b/src/DESTEP/DESTEP_Provider.cxx new file mode 100644 index 0000000000..1856c271f3 --- /dev/null +++ b/src/DESTEP/DESTEP_Provider.cxx @@ -0,0 +1,332 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(DESTEP_Provider, DE_Provider) + +//================================================================================================= + +DESTEP_Provider::DESTEP_Provider() {} + +//================================================================================================= + +DESTEP_Provider::DESTEP_Provider(const Handle(DE_ConfigurationNode)& theNode) + : DE_Provider(theNode) +{ +} + +//================================================================================================= + +bool DESTEP_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + if (theDocument.IsNull()) + { + Message::SendFail() << "Error in the DESTEP_Provider during reading the file " << thePath + << "\t: theDocument shouldn't be null"; + return false; + } + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DESTEP_ConfigurationNode))) + { + Message::SendFail() << "Error in the DESTEP_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DESTEP_ConfigurationNode) aNode = Handle(DESTEP_ConfigurationNode)::DownCast(GetNode()); + personizeWS(theWS); + XCAFDoc_DocumentTool::SetLengthUnit(theDocument, + aNode->GlobalParameters.LengthUnit, + UnitsMethods_LengthUnit_Millimeter); + STEPCAFControl_Reader aReader; + aReader.Init(theWS); + aReader.SetColorMode(aNode->InternalParameters.ReadColor); + aReader.SetNameMode(aNode->InternalParameters.ReadName); + aReader.SetLayerMode(aNode->InternalParameters.ReadLayer); + aReader.SetPropsMode(aNode->InternalParameters.ReadProps); + aReader.SetMetaMode(aNode->InternalParameters.ReadMetadata); + + IFSelect_ReturnStatus aReadStat = IFSelect_RetVoid; + StepData_ConfParameters aParams = aNode->InternalParameters; + aReadStat = aReader.ReadFile(thePath.ToCString(), aParams); + if (aReadStat != IFSelect_RetDone) + { + Message::SendFail() << "Error in the DESTEP_Provider during reading the file " << thePath + << "\t: abandon"; + return false; + } + + if (!aReader.Transfer(theDocument, theProgress)) + { + Message::SendFail() << "Error in the DESTEP_Provider during reading the file " << thePath + << "\t: Cannot read any relevant data from the STEP file"; + return false; + } + return true; +} + +//================================================================================================= + +bool DESTEP_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DESTEP_ConfigurationNode))) + { + Message::SendFail() << "Error in the DESTEP_Provider during writing the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DESTEP_ConfigurationNode) aNode = Handle(DESTEP_ConfigurationNode)::DownCast(GetNode()); + personizeWS(theWS); + STEPCAFControl_Writer aWriter; + aWriter.Init(theWS); + Handle(StepData_StepModel) aModel = + Handle(StepData_StepModel)::DownCast(aWriter.Writer().WS()->Model()); + STEPControl_StepModelType aMode = + static_cast(aNode->InternalParameters.WriteModelType); + aWriter.SetColorMode(aNode->InternalParameters.WriteColor); + aWriter.SetNameMode(aNode->InternalParameters.WriteName); + aWriter.SetLayerMode(aNode->InternalParameters.WriteLayer); + aWriter.SetPropsMode(aNode->InternalParameters.WriteProps); + StepData_ConfParameters aParams = aNode->InternalParameters; + Standard_Real aScaleFactorMM = 1.; + if (XCAFDoc_DocumentTool::GetLengthUnit(theDocument, + aScaleFactorMM, + UnitsMethods_LengthUnit_Millimeter)) + { + aModel->SetLocalLengthUnit(aScaleFactorMM); + } + else + { + aModel->SetLocalLengthUnit(aNode->GlobalParameters.SystemUnit); + Message::SendWarning() + << "Warning in the DESTEP_Provider during writing the file " << thePath + << "\t: The document has no information on Units. Using global parameter as initial Unit."; + } + UnitsMethods_LengthUnit aTargetUnit = + UnitsMethods::GetLengthUnitByFactorValue(aNode->GlobalParameters.LengthUnit, + UnitsMethods_LengthUnit_Millimeter); + aParams.WriteUnit = aTargetUnit; + aModel->SetWriteLengthUnit(aNode->GlobalParameters.LengthUnit); + TDF_Label aLabel; + if (!aWriter.Transfer(theDocument, aParams, aMode, 0, theProgress)) + { + Message::SendFail() << "Error in the DESTEP_Provider during writing the file " << thePath + << "\t: The document cannot be translated or gives no result"; + return false; + } + IFSelect_ReturnStatus aStatus = aWriter.Write(thePath.ToCString()); + switch (aStatus) + { + case IFSelect_RetVoid: { + Message::SendFail() << "Error in the DESTEP_Provider during writing the file " << thePath + << "\t: No file written"; + return false; + ; + } + case IFSelect_RetDone: { + break; + } + default: { + Message::SendFail() << "Error in the DESTEP_Provider during writing the file " << thePath + << "\t: Error on writing file"; + return false; + } + } + return true; +} + +//================================================================================================= + +bool DESTEP_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); + return Read(thePath, theDocument, aWS, theProgress); +} + +//================================================================================================= + +bool DESTEP_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); + return Write(thePath, theDocument, aWS, theProgress); +} + +//================================================================================================= + +bool DESTEP_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theProgress; + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DESTEP_ConfigurationNode))) + { + Message::SendFail() << "Error in the DESTEP_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DESTEP_ConfigurationNode) aNode = Handle(DESTEP_ConfigurationNode)::DownCast(GetNode()); + personizeWS(theWS); + STEPControl_Reader aReader; + aReader.SetWS(theWS); + IFSelect_ReturnStatus aReadstat = IFSelect_RetVoid; + StepData_ConfParameters aParams = aNode->InternalParameters; + aReadstat = aReader.ReadFile(thePath.ToCString(), aParams); + Handle(StepData_StepModel) aModel = aReader.StepModel(); + if (aReadstat != IFSelect_RetDone) + { + Message::SendFail() << "Error in the DESTEP_Provider during reading the file " << thePath + << "\t: abandon, no model loaded"; + return false; + } + aModel->SetLocalLengthUnit(aNode->GlobalParameters.LengthUnit); + if (aReader.TransferRoots() <= 0) + { + Message::SendFail() << "Error in the DESTEP_Provider during reading the file " << thePath + << "\t:Cannot read any relevant data from the STEP file"; + return false; + } + theShape = aReader.OneShape(); + return true; +} + +//================================================================================================= + +bool DESTEP_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DESTEP_ConfigurationNode))) + { + Message::SendFail() << "Error in the DESTEP_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DESTEP_ConfigurationNode) aNode = Handle(DESTEP_ConfigurationNode)::DownCast(GetNode()); + + personizeWS(theWS); + STEPControl_Writer aWriter; + aWriter.SetWS(theWS); + IFSelect_ReturnStatus aWritestat = IFSelect_RetVoid; + Handle(StepData_StepModel) aModel = aWriter.Model(); + ; + StepData_ConfParameters aParams = aNode->InternalParameters; + aModel->SetLocalLengthUnit(aNode->GlobalParameters.SystemUnit); + UnitsMethods_LengthUnit aTargetUnit = + UnitsMethods::GetLengthUnitByFactorValue(aNode->GlobalParameters.LengthUnit, + UnitsMethods_LengthUnit_Millimeter); + aParams.WriteUnit = aTargetUnit; + if (aTargetUnit == UnitsMethods_LengthUnit_Undefined) + { + aModel->SetWriteLengthUnit(1.0); + Message::SendWarning() + << "Custom units are not supported by STEP format, but LengthUnit global parameter doesn't " + "fit any predefined unit. Units will be scaled to Millimeters"; + } + else + { + aModel->SetWriteLengthUnit(aNode->GlobalParameters.LengthUnit); + } + aWritestat = aWriter.Transfer(theShape, + aNode->InternalParameters.WriteModelType, + aParams, + true, + theProgress); + if (aWritestat != IFSelect_RetDone) + { + Message::SendFail() << "Error in the DESTEP_Provider during reading the file " << thePath + << "\t: abandon, no model loaded"; + return false; + } + if (aWriter.Write(thePath.ToCString()) != IFSelect_RetDone) + { + Message::SendFail() << "DESTEP_Provider: Error on writing file"; + return false; + } + return true; +} + +//================================================================================================= + +bool DESTEP_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); + return Read(thePath, theShape, aWS, theProgress); +} + +//================================================================================================= + +bool DESTEP_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); + return Write(thePath, theShape, aWS, theProgress); +} + +//================================================================================================= + +TCollection_AsciiString DESTEP_Provider::GetFormat() const +{ + return TCollection_AsciiString("STEP"); +} + +//================================================================================================= + +TCollection_AsciiString DESTEP_Provider::GetVendor() const +{ + return TCollection_AsciiString("OCC"); +} + +//================================================================================================= + +void DESTEP_Provider::personizeWS(Handle(XSControl_WorkSession)& theWS) +{ + if (theWS.IsNull()) + { + Message::SendWarning() << "Warning: DESTEP_Provider :" + << " Null work session, use internal temporary session"; + theWS = new XSControl_WorkSession(); + } + Handle(STEPCAFControl_Controller) aCntrl = + Handle(STEPCAFControl_Controller)::DownCast(theWS->NormAdaptor()); + if (aCntrl.IsNull()) + { + STEPCAFControl_Controller::Init(); + theWS->SelectNorm("STEP"); + } +} diff --git a/src/DESTEP/DESTEP_Provider.hxx b/src/DESTEP/DESTEP_Provider.hxx new file mode 100644 index 0000000000..c049d75b3f --- /dev/null +++ b/src/DESTEP/DESTEP_Provider.hxx @@ -0,0 +1,148 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DESTEP_Provider_HeaderFile +#define _DESTEP_Provider_HeaderFile + +#include +#include + +//! The class to transfer STEP files. +//! Reads and Writes any STEP files into/from OCCT. +//! Each operation needs configuration node. +//! +//! Providers grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "STEP" +//! The import process is supported. +//! The export process is supported. +class DESTEP_Provider : public DE_Provider +{ +public: + DEFINE_STANDARD_RTTIEXT(DESTEP_Provider, DE_Provider) + +public: + //! Default constructor + //! Configure translation process with global configuration + Standard_EXPORT DESTEP_Provider(); + + //! Configure translation process + //! @param[in] theNode object to copy + Standard_EXPORT DESTEP_Provider(const Handle(DE_ConfigurationNode)& theNode); + +public: + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + +public: + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; + +private: + //! Personizes work session with current format. + //! Creates new temporary session if current session is null + //! @param[in] theWS current work session + void personizeWS(Handle(XSControl_WorkSession)& theWS); +}; + +#endif // _DESTEP_Provider_HeaderFile diff --git a/src/DESTEP/FILES b/src/DESTEP/FILES new file mode 100644 index 0000000000..3b3c6b86c1 --- /dev/null +++ b/src/DESTEP/FILES @@ -0,0 +1,4 @@ +DESTEP_ConfigurationNode.cxx +DESTEP_ConfigurationNode.hxx +DESTEP_Provider.cxx +DESTEP_Provider.hxx diff --git a/src/RWStl/RWStl_ConfigurationNode.cxx b/src/DESTL/DESTL_ConfigurationNode.cxx similarity index 53% rename from src/RWStl/RWStl_ConfigurationNode.cxx rename to src/DESTL/DESTL_ConfigurationNode.cxx index 09f4173d5e..107aa782b6 100644 --- a/src/RWStl/RWStl_ConfigurationNode.cxx +++ b/src/DESTL/DESTL_ConfigurationNode.cxx @@ -11,72 +11,68 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include +#include #include #include #include -#include -IMPLEMENT_STANDARD_RTTIEXT(RWStl_ConfigurationNode, DE_ConfigurationNode) +IMPLEMENT_STANDARD_RTTIEXT(DESTL_ConfigurationNode, DE_ConfigurationNode) namespace { - static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() - { - static const TCollection_AsciiString aScope = "provider"; - return aScope; - } +static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() +{ + static const TCollection_AsciiString aScope = "provider"; + return aScope; +} + +// Wrapper to auto-load DE component +DE_PluginHolder THE_OCCT_STL_COMPONENT_PLUGIN; +} // namespace - // Wrapper to auto-load DE component - DE_PluginHolder THE_OCCT_STL_COMPONENT_PLUGIN; +//================================================================================================= + +DESTL_ConfigurationNode::DESTL_ConfigurationNode() + : DE_ConfigurationNode() +{ } -//======================================================================= -// function : STEPCAFControl_ConfigurationNode -// purpose : -//======================================================================= -RWStl_ConfigurationNode::RWStl_ConfigurationNode() : - DE_ConfigurationNode() -{} - -//======================================================================= -// function : STEPCAFControl_ConfigurationNode -// purpose : -//======================================================================= -RWStl_ConfigurationNode::RWStl_ConfigurationNode(const Handle(RWStl_ConfigurationNode)& theNode) - :DE_ConfigurationNode(theNode) +//================================================================================================= + +DESTL_ConfigurationNode::DESTL_ConfigurationNode(const Handle(DESTL_ConfigurationNode)& theNode) + : DE_ConfigurationNode(theNode) { InternalParameters = theNode->InternalParameters; } -//======================================================================= -// function : Load -// purpose : -//======================================================================= -bool RWStl_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) +//================================================================================================= + +bool DESTL_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) { - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); - InternalParameters.ReadMergeAngle = + InternalParameters.ReadMergeAngle = theResource->RealVal("read.merge.angle", InternalParameters.ReadMergeAngle, aScope); - InternalParameters.ReadBRep = + InternalParameters.ReadBRep = theResource->BooleanVal("read.brep", InternalParameters.ReadBRep, aScope); - InternalParameters.WriteAscii = + InternalParameters.WriteAscii = theResource->BooleanVal("write.ascii", InternalParameters.WriteAscii, aScope); return true; } -//======================================================================= -// function : Save -// purpose : -//======================================================================= -TCollection_AsciiString RWStl_ConfigurationNode::Save() const +//================================================================================================= + +TCollection_AsciiString DESTL_ConfigurationNode::Save() const { TCollection_AsciiString aResult; aResult += "!*****************************************************************************\n"; - aResult = aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; + aResult = + aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; aResult += "!\n"; aResult += "!Read parameters:\n"; @@ -108,76 +104,60 @@ TCollection_AsciiString RWStl_ConfigurationNode::Save() const return aResult; } -//======================================================================= -// function : Copy -// purpose : -//======================================================================= -Handle(DE_ConfigurationNode) RWStl_ConfigurationNode::Copy() const +//================================================================================================= + +Handle(DE_ConfigurationNode) DESTL_ConfigurationNode::Copy() const { - return new RWStl_ConfigurationNode(*this); + return new DESTL_ConfigurationNode(*this); } -//======================================================================= -// function : BuildProvider -// purpose : -//======================================================================= -Handle(DE_Provider) RWStl_ConfigurationNode::BuildProvider() +//================================================================================================= + +Handle(DE_Provider) DESTL_ConfigurationNode::BuildProvider() { - return new RWStl_Provider(this); + return new DESTL_Provider(this); } -//======================================================================= -// function : IsImportSupported -// purpose : -//======================================================================= -bool RWStl_ConfigurationNode::IsImportSupported() const +//================================================================================================= + +bool DESTL_ConfigurationNode::IsImportSupported() const { return true; } -//======================================================================= -// function : IsExportSupported -// purpose : -//======================================================================= -bool RWStl_ConfigurationNode::IsExportSupported() const +//================================================================================================= + +bool DESTL_ConfigurationNode::IsExportSupported() const { return true; } -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString RWStl_ConfigurationNode::GetFormat() const +//================================================================================================= + +TCollection_AsciiString DESTL_ConfigurationNode::GetFormat() const { return TCollection_AsciiString("STL"); } -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString RWStl_ConfigurationNode::GetVendor() const +//================================================================================================= + +TCollection_AsciiString DESTL_ConfigurationNode::GetVendor() const { return TCollection_AsciiString("OCC"); } -//======================================================================= -// function : GetExtensions -// purpose : -//======================================================================= -TColStd_ListOfAsciiString RWStl_ConfigurationNode::GetExtensions() const +//================================================================================================= + +TColStd_ListOfAsciiString DESTL_ConfigurationNode::GetExtensions() const { TColStd_ListOfAsciiString anExt; anExt.Append("stl"); return anExt; } -//======================================================================= -// function : CheckContent -// purpose : -//======================================================================= -bool RWStl_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const +//================================================================================================= + +bool DESTL_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const { if (theBuffer.IsNull() || theBuffer->Size() < 7) { diff --git a/src/DESTL/DESTL_ConfigurationNode.hxx b/src/DESTL/DESTL_ConfigurationNode.hxx new file mode 100644 index 0000000000..c252dc031e --- /dev/null +++ b/src/DESTL/DESTL_ConfigurationNode.hxx @@ -0,0 +1,98 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DESTL_ConfigurationNode_HeaderFile +#define _DESTL_ConfigurationNode_HeaderFile + +#include + +//! The purpose of this class is to configure the transfer process for STL format +//! Stores the necessary settings for DESTL_Provider. +//! Configures and creates special provider to transfer STL files. +//! +//! Nodes grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "STL" +//! The supported CAD extension is ".stl" +//! The import process is supported. +//! The export process is supported. +class DESTL_ConfigurationNode : public DE_ConfigurationNode +{ + DEFINE_STANDARD_RTTIEXT(DESTL_ConfigurationNode, DE_ConfigurationNode) +public: + //! Initializes all field by default + Standard_EXPORT DESTL_ConfigurationNode(); + + //! Copies values of all fields + //! @param[in] theNode object to copy + Standard_EXPORT DESTL_ConfigurationNode(const Handle(DESTL_ConfigurationNode)& theNode); + + //! Updates values according the resource + //! @param[in] theResource input resource to use + //! @return true if theResource loading has ended correctly + Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) + Standard_OVERRIDE; + + //! Writes configuration to the string + //! @return result resource string + Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; + + //! Copies values of all fields + //! @return new object with the same field values + Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; + + //! Creates new provider for the own format + //! @return new created provider + Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; + +public: + //! Checks the import supporting + //! @return true if import is supported + Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; + + //! Checks the export supporting + //! @return true if export is supported + Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; + + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; + + //! Gets list of supported file extensions + //! @return list of extensions + Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; + + //! Checks the file content to verify a format + //! @param[in] theBuffer read stream buffer to check content + //! @return Standard_True if file is supported by a current provider + Standard_EXPORT virtual bool CheckContent(const Handle(NCollection_Buffer)& theBuffer) const + Standard_OVERRIDE; + +public: + struct RWStl_InternalSection + { + // Read + double ReadMergeAngle = 90.; //!< Input merge angle value + bool ReadBRep = false; //!< Setting up Boundary Representation flag + + // Write + bool WriteAscii = true; //!< Setting up writing mode (Ascii or Binary) + + } InternalParameters; +}; + +#endif // _DESTL_ConfigurationNode_HeaderFile diff --git a/src/DESTL/DESTL_Provider.cxx b/src/DESTL/DESTL_Provider.cxx new file mode 100644 index 0000000000..a99bf85905 --- /dev/null +++ b/src/DESTL/DESTL_Provider.cxx @@ -0,0 +1,242 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(DESTL_Provider, DE_Provider) + +//================================================================================================= + +DESTL_Provider::DESTL_Provider() {} + +//================================================================================================= + +DESTL_Provider::DESTL_Provider(const Handle(DE_ConfigurationNode)& theNode) + : DE_Provider(theNode) +{ +} + +//================================================================================================= + +bool DESTL_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Read(thePath, theDocument, theProgress); +} + +//================================================================================================= + +bool DESTL_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Write(thePath, theDocument, theProgress); +} + +//================================================================================================= + +bool DESTL_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + if (theDocument.IsNull()) + { + Message::SendFail() << "Error in the DESTL_Provider during reading the file " << thePath + << "\t: theDocument shouldn't be null"; + return false; + } + TopoDS_Shape aShape; + if (!Read(thePath, aShape, theProgress)) + { + return false; + } + Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); + aShapeTool->AddShape(aShape); + return true; +} + +//================================================================================================= + +bool DESTL_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + TopoDS_Shape aShape; + TDF_LabelSequence aLabels; + Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); + aSTool->GetFreeShapes(aLabels); + if (aLabels.Length() <= 0) + { + Message::SendFail() << "Error in the DESTL_Provider during writing the file " << thePath + << "\t: Document contain no shapes"; + return false; + } + + Handle(DESTL_ConfigurationNode) aNode = Handle(DESTL_ConfigurationNode)::DownCast(GetNode()); + if (aNode->GlobalParameters.LengthUnit != 1.0) + { + Message::SendWarning() + << "Warning in the DESTL_Provider during writing the file " << thePath + << "\t: Target Units for writing were changed, but current format doesn't support scaling"; + } + + if (aLabels.Length() == 1) + { + aShape = aSTool->GetShape(aLabels.Value(1)); + } + else + { + TopoDS_Compound aComp; + BRep_Builder aBuilder; + aBuilder.MakeCompound(aComp); + for (Standard_Integer anIndex = 1; anIndex <= aLabels.Length(); anIndex++) + { + TopoDS_Shape aS = aSTool->GetShape(aLabels.Value(anIndex)); + aBuilder.Add(aComp, aS); + } + aShape = aComp; + } + return Write(thePath, aShape, theProgress); +} + +//================================================================================================= + +bool DESTL_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Read(thePath, theShape, theProgress); +} + +//================================================================================================= + +bool DESTL_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Write(thePath, theShape, theProgress); +} + +//================================================================================================= + +bool DESTL_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + Message::SendWarning() + << "OCCT Stl reader does not support model scaling according to custom length unit"; + if (!GetNode()->IsKind(STANDARD_TYPE(DESTL_ConfigurationNode))) + { + Message::SendFail() << "Error in the DESTL_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return true; + } + Handle(DESTL_ConfigurationNode) aNode = Handle(DESTL_ConfigurationNode)::DownCast(GetNode()); + double aMergeAngle = aNode->InternalParameters.ReadMergeAngle * M_PI / 180.0; + if (aMergeAngle != M_PI_2) + { + if (aMergeAngle < 0.0 || aMergeAngle > M_PI_2) + { + Message::SendFail() << "Error in the DESTL_Provider during reading the file " << thePath + << "\t: The merge angle is out of the valid range"; + return false; + } + } + if (!aNode->InternalParameters.ReadBRep) + { + Handle(Poly_Triangulation) aTriangulation = + RWStl::ReadFile(thePath.ToCString(), aMergeAngle, theProgress); + + TopoDS_Face aFace; + BRep_Builder aB; + aB.MakeFace(aFace); + aB.UpdateFace(aFace, aTriangulation); + theShape = aFace; + } + else + { + Standard_DISABLE_DEPRECATION_WARNINGS if (!StlAPI::Read(theShape, thePath.ToCString())) + { + Message::SendFail() << "Error in the DESTL_Provider during reading the file " << thePath; + return false; + } + Standard_ENABLE_DEPRECATION_WARNINGS + } + return true; +} + +//================================================================================================= + +bool DESTL_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + Message::SendWarning() + << "OCCT Stl writer does not support model scaling according to custom length unit"; + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DESTL_ConfigurationNode))) + { + Message::SendFail() << "Error in the DESTL_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DESTL_ConfigurationNode) aNode = Handle(DESTL_ConfigurationNode)::DownCast(GetNode()); + if (aNode->GlobalParameters.LengthUnit != 1.0) + { + Message::SendWarning() + << "Warning in the DESTL_Provider during writing the file " << thePath + << "\t: Target Units for writing were changed, but current format doesn't support scaling"; + } + + StlAPI_Writer aWriter; + aWriter.ASCIIMode() = aNode->InternalParameters.WriteAscii; + if (!aWriter.Write(theShape, thePath.ToCString(), theProgress)) + { + Message::SendFail() << "Error in the DESTL_Provider during reading the file " << thePath + << "\t: Mesh writing has been failed"; + return false; + } + return true; +} + +//================================================================================================= + +TCollection_AsciiString DESTL_Provider::GetFormat() const +{ + return TCollection_AsciiString("STL"); +} + +//================================================================================================= + +TCollection_AsciiString DESTL_Provider::GetVendor() const +{ + return TCollection_AsciiString("OCC"); +} diff --git a/src/DESTL/DESTL_Provider.hxx b/src/DESTL/DESTL_Provider.hxx new file mode 100644 index 0000000000..a955195e22 --- /dev/null +++ b/src/DESTL/DESTL_Provider.hxx @@ -0,0 +1,136 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DESTL_Provider_HeaderFile +#define _DESTL_Provider_HeaderFile + +#include + +//! The class to transfer STL files. +//! Reads and Writes any STL files into/from OCCT. +//! Each operation needs configuration node. +//! +//! Providers grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "STL" +//! The import process is supported. +//! The export process is supported. +class DESTL_Provider : public DE_Provider +{ +public: + DEFINE_STANDARD_RTTIEXT(DESTL_Provider, DE_Provider) + +public: + + //! Default constructor + //! Configure translation process with global configuration + Standard_EXPORT DESTL_Provider(); + + //! Configure translation process + //! @param[in] theNode object to copy + Standard_EXPORT DESTL_Provider(const Handle(DE_ConfigurationNode)& theNode); + +public: + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual Standard_Boolean Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual Standard_Boolean Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual Standard_Boolean Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual Standard_Boolean Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual Standard_Boolean Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual Standard_Boolean Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual Standard_Boolean Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual Standard_Boolean Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + +public: + + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; +}; + +#endif // _DESTL_Provider_HeaderFile diff --git a/src/DESTL/FILES b/src/DESTL/FILES new file mode 100644 index 0000000000..4854b5ec6e --- /dev/null +++ b/src/DESTL/FILES @@ -0,0 +1,4 @@ +DESTL_ConfigurationNode.cxx +DESTL_ConfigurationNode.hxx +DESTL_Provider.cxx +DESTL_Provider.hxx diff --git a/src/DEVRML/DEVRML_ConfigurationNode.cxx b/src/DEVRML/DEVRML_ConfigurationNode.cxx new file mode 100644 index 0000000000..eb03f3fd18 --- /dev/null +++ b/src/DEVRML/DEVRML_ConfigurationNode.cxx @@ -0,0 +1,195 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(DEVRML_ConfigurationNode, DE_ConfigurationNode) + +namespace +{ +static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() +{ + static const TCollection_AsciiString aScope = "provider"; + return aScope; +} + +// Wrapper to auto-load DE component +DE_PluginHolder THE_OCCT_VRML_COMPONENT_PLUGIN; +} // namespace + +//================================================================================================= + +DEVRML_ConfigurationNode::DEVRML_ConfigurationNode() + : DE_ConfigurationNode() +{ +} + +//================================================================================================= + +DEVRML_ConfigurationNode::DEVRML_ConfigurationNode(const Handle(DEVRML_ConfigurationNode)& theNode) + : DE_ConfigurationNode(theNode) +{ + InternalParameters = theNode->InternalParameters; +} + +//================================================================================================= + +bool DEVRML_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) +{ + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); + + InternalParameters.ReadFileUnit = + theResource->RealVal("read.file.unit", InternalParameters.ReadFileUnit, aScope); + InternalParameters.ReadFileCoordinateSys = + (RWMesh_CoordinateSystem)theResource->IntegerVal("read.file.coordinate.system", + InternalParameters.ReadFileCoordinateSys, + aScope); + InternalParameters.ReadSystemCoordinateSys = + (RWMesh_CoordinateSystem)theResource->IntegerVal("read.system.coordinate.system", + InternalParameters.ReadSystemCoordinateSys, + aScope); + InternalParameters.ReadFillIncomplete = + theResource->BooleanVal("read.fill.incomplete", InternalParameters.ReadFillIncomplete, aScope); + + InternalParameters.WriterVersion = + (WriteMode_WriterVersion)theResource->IntegerVal("writer.version", + InternalParameters.WriterVersion, + aScope); + InternalParameters.WriteRepresentationType = + (WriteMode_RepresentationType)theResource->IntegerVal( + "write.representation.type", + InternalParameters.WriteRepresentationType, + aScope); + + return true; +} + +//================================================================================================= + +TCollection_AsciiString DEVRML_ConfigurationNode::Save() const +{ + TCollection_AsciiString aResult; + aResult += "!*****************************************************************************\n"; + aResult = + aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; + + aResult += "!\n"; + aResult += "!Read parameters:\n"; + aResult += "!\n"; + + aResult += "!\n"; + aResult += "!Set (override) file length units to convert from while reading the file, defined as " + "scale factor for m (meters).\n"; + aResult += "!Default value: 1. Available values: positive double\n"; + aResult += aScope + "read.file.unit :\t " + InternalParameters.ReadFileUnit + "\n"; + aResult += "!\n"; + + aResult += "!\n"; + aResult += "!Set (override) file origin coordinate system to perform conversion during read.\n"; + aResult += "!Default value: Yup (1). { Zup (0) | Yup (1) }\n"; + aResult += + aScope + "read.file.coordinate.system :\t " + InternalParameters.ReadFileCoordinateSys + "\n"; + aResult += "!\n"; + + aResult += "!\n"; + aResult += "!Set system origin coordinate system to perform conversion into during read.\n"; + aResult += "!Default value: Zup (0). Available values: { Zup (0) | Yup (1) }\n"; + aResult += aScope + "read.system.coordinate.system :\t " + + InternalParameters.ReadSystemCoordinateSys + "\n"; + aResult += "!\n"; + + aResult += "!\n"; + aResult += "!Set flag allowing partially read file content to be put into the XDE document.\n"; + aResult += "!Default value: 1(\"ON\"). Available values: 0(\"OFF\"), 1(\"ON\")\n"; + aResult += aScope + "read.fill.incomplete :\t " + InternalParameters.ReadFillIncomplete + "\n"; + aResult += "!\n"; + + aResult += "!\n"; + aResult += "!Write parameters:\n"; + aResult += "!\n"; + + aResult += "!\n"; + aResult += "!Setting up writer version.\n"; + aResult += "!Default value: 2. Available values: 1, 2\n"; + aResult += aScope + "writer.version :\t " + InternalParameters.WriterVersion + "\n"; + aResult += "!\n"; + + aResult += "!\n"; + aResult += "!Setting up representation\n"; + aResult += "!Default value: 1. Available values: 0(shaded), 1(wireframe), 2(both).\n"; + aResult += + aScope + "write.representation.type :\t " + InternalParameters.WriteRepresentationType + "\n"; + aResult += "!\n"; + + aResult += "!*****************************************************************************\n"; + return aResult; +} + +//================================================================================================= + +Handle(DE_ConfigurationNode) DEVRML_ConfigurationNode::Copy() const +{ + return new DEVRML_ConfigurationNode(*this); +} + +//================================================================================================= + +Handle(DE_Provider) DEVRML_ConfigurationNode::BuildProvider() +{ + return new DEVRML_Provider(this); +} + +//================================================================================================= + +bool DEVRML_ConfigurationNode::IsImportSupported() const +{ + return true; +} + +//================================================================================================= + +bool DEVRML_ConfigurationNode::IsExportSupported() const +{ + return true; +} + +//================================================================================================= + +TCollection_AsciiString DEVRML_ConfigurationNode::GetFormat() const +{ + return TCollection_AsciiString("VRML"); +} + +//================================================================================================= + +TCollection_AsciiString DEVRML_ConfigurationNode::GetVendor() const +{ + return TCollection_AsciiString("OCC"); +} + +//================================================================================================= + +TColStd_ListOfAsciiString DEVRML_ConfigurationNode::GetExtensions() const +{ + TColStd_ListOfAsciiString anExt; + anExt.Append("vrml"); + anExt.Append("wrl"); + return anExt; +} diff --git a/src/DEVRML/DEVRML_ConfigurationNode.hxx b/src/DEVRML/DEVRML_ConfigurationNode.hxx new file mode 100644 index 0000000000..6371244d6f --- /dev/null +++ b/src/DEVRML/DEVRML_ConfigurationNode.hxx @@ -0,0 +1,111 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEVRML_ConfigurationNode_HeaderFile +#define _DEVRML_ConfigurationNode_HeaderFile + +#include +#include + +//! The purpose of this class is to configure the transfer process for VRML format +//! Stores the necessary settings for DEVRML_Provider. +//! Configures and creates special provider to transfer VRML files. +//! +//! Nodes grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "VRML" +//! The supported CAD extensions are ".vrml", ".wrl" +//! The import process is supported. +//! The export process is supported. +class DEVRML_ConfigurationNode : public DE_ConfigurationNode +{ + DEFINE_STANDARD_RTTIEXT(DEVRML_ConfigurationNode, DE_ConfigurationNode) +public: + //! Initializes all field by default + Standard_EXPORT DEVRML_ConfigurationNode(); + + //! Copies values of all fields + //! @param[in] theNode object to copy + Standard_EXPORT DEVRML_ConfigurationNode(const Handle(DEVRML_ConfigurationNode)& theNode); + + //! Updates values according the resource + //! @param[in] theResource input resource to use + //! @return true if theResource loading has ended correctly + Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) + Standard_OVERRIDE; + + //! Writes configuration to the string + //! @return result resource string + Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; + + //! Copies values of all fields + //! @return new object with the same field values + Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; + + //! Creates new provider for the own format + //! @return new created provider + Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; + +public: + //! Checks the import supporting + //! @return true if import is supported + Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; + + //! Checks the export supporting + //! @return true if export is supported + Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; + + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; + + //! Gets list of supported file extensions + //! @return list of extensions + Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; + +public: + enum WriteMode_WriterVersion + { + WriteMode_WriterVersion_1 = 1, + WriteMode_WriterVersion_2 + }; + + enum WriteMode_RepresentationType + { + WriteMode_RepresentationType_Shaded = 0, + WriteMode_RepresentationType_Wireframe, + WriteMode_RepresentationType_Both + }; + + struct Vrml_InternalSection + { + // Read + // clang-format off + double ReadFileUnit = 1.; // + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(DEVRML_Provider, DE_Provider) + +//================================================================================================= + +DEVRML_Provider::DEVRML_Provider() {} + +//================================================================================================= + +DEVRML_Provider::DEVRML_Provider(const Handle(DE_ConfigurationNode)& theNode) + : DE_Provider(theNode) +{ +} + +//================================================================================================= + +bool DEVRML_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Read(thePath, theDocument, theProgress); +} + +//================================================================================================= + +bool DEVRML_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Write(thePath, theDocument, theProgress); +} + +//================================================================================================= + +bool DEVRML_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + if (theDocument.IsNull()) + { + Message::SendFail() << "Error in the DEVRML_Provider during reading the file " << thePath + << "\t: theDocument shouldn't be null"; + return false; + } + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEVRML_ConfigurationNode))) + { + Message::SendFail() << "Error in the DEVRML_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DEVRML_ConfigurationNode) aNode = Handle(DEVRML_ConfigurationNode)::DownCast(GetNode()); + + VrmlAPI_CafReader aVrmlReader; + aVrmlReader.SetDocument(theDocument); + aVrmlReader.SetFileLengthUnit(aNode->InternalParameters.ReadFileUnit); + aVrmlReader.SetSystemLengthUnit(aNode->GlobalParameters.LengthUnit); + aVrmlReader.SetFileCoordinateSystem(aNode->InternalParameters.ReadFileCoordinateSys); + aVrmlReader.SetSystemCoordinateSystem(aNode->InternalParameters.ReadSystemCoordinateSys); + aVrmlReader.SetFillIncompleteDocument(aNode->InternalParameters.ReadFillIncomplete); + + XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->InternalParameters.ReadFileUnit); + + if (!aVrmlReader.Perform(thePath, theProgress)) + { + if (aVrmlReader.ExtraStatus() != RWMesh_CafReaderStatusEx_Partial) + { + Message::SendFail() << "Error in the DEVRML_Provider during reading the file '" << thePath + << "'"; + return false; + } + Message::SendWarning() + << "Warning in the DEVRML_Provider during reading the file: file has been read paratially " + << "(due to unexpected EOF, syntax error, memory limit) '" << thePath << "'"; + } + return true; +} + +//================================================================================================= + +bool DEVRML_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + (void)theProgress; + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEVRML_ConfigurationNode))) + { + Message::SendFail() << "Error in the DEVRML_Provider during writing the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DEVRML_ConfigurationNode) aNode = Handle(DEVRML_ConfigurationNode)::DownCast(GetNode()); + + VrmlAPI_Writer aWriter; + aWriter.SetRepresentation( + static_cast(aNode->InternalParameters.WriteRepresentationType)); + Standard_Real aScaling = 1.; + Standard_Real aScaleFactorMM = 1.; + if (XCAFDoc_DocumentTool::GetLengthUnit(theDocument, + aScaleFactorMM, + UnitsMethods_LengthUnit_Millimeter)) + { + aScaling = aScaleFactorMM / aNode->GlobalParameters.LengthUnit; + } + else + { + aScaling = aNode->GlobalParameters.SystemUnit / aNode->GlobalParameters.LengthUnit; + Message::SendWarning() + << "Warning in the DEVRML_Provider during writing the file " << thePath + << "\t: The document has no information on Units. Using global parameter as initial Unit."; + } + if (!aWriter.WriteDoc(theDocument, thePath.ToCString(), aScaling)) + { + Message::SendFail() << "Error in the DEVRML_Provider during wtiting the file " << thePath + << "\t: File was not written"; + return false; + } + + return true; +} + +//================================================================================================= + +bool DEVRML_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Read(thePath, theShape, theProgress); +} + +//================================================================================================= + +bool DEVRML_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Write(thePath, theShape, theProgress); +} + +//================================================================================================= + +bool DEVRML_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + (void)theProgress; + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEVRML_ConfigurationNode))) + { + Message::SendFail() << "Error in the DEVRML_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DEVRML_ConfigurationNode) aNode = Handle(DEVRML_ConfigurationNode)::DownCast(GetNode()); + + TopoDS_Shape aShape; + VrmlData_DataMapOfShapeAppearance aShapeAppMap; + + std::filebuf aFic; + std::istream aStream(&aFic); + + if (aFic.open(thePath.ToCString(), std::ios::in)) + { + // Get path of the VRML file. + OSD_Path aPath(thePath.ToCString()); + TCollection_AsciiString aVrmlDir("."); + TCollection_AsciiString aDisk = aPath.Disk(); + TCollection_AsciiString aTrek = aPath.Trek(); + if (!aTrek.IsEmpty()) + { + if (!aDisk.IsEmpty()) + { + aVrmlDir = aDisk; + } + else + { + aVrmlDir.Clear(); + } + aTrek.ChangeAll('|', '/'); + aVrmlDir += aTrek; + } + + VrmlData_Scene aScene; + aScene.SetLinearScale(aNode->GlobalParameters.LengthUnit); + + aScene.SetVrmlDir(aVrmlDir); + aScene << aStream; + const char* aStr = 0L; + switch (aScene.Status()) + { + case VrmlData_StatusOK: { + aShape = aScene.GetShape(aShapeAppMap); + break; + } + case VrmlData_EmptyData: + aStr = "EmptyData"; + break; + case VrmlData_UnrecoverableError: + aStr = "UnrecoverableError"; + break; + case VrmlData_GeneralError: + aStr = "GeneralError"; + break; + case VrmlData_EndOfFile: + aStr = "EndOfFile"; + break; + case VrmlData_NotVrmlFile: + aStr = "NotVrmlFile"; + break; + case VrmlData_CannotOpenFile: + aStr = "CannotOpenFile"; + break; + case VrmlData_VrmlFormatError: + aStr = "VrmlFormatError"; + break; + case VrmlData_NumericInputError: + aStr = "NumericInputError"; + break; + case VrmlData_IrrelevantNumber: + aStr = "IrrelevantNumber"; + break; + case VrmlData_BooleanInputError: + aStr = "BooleanInputError"; + break; + case VrmlData_StringInputError: + aStr = "StringInputError"; + break; + case VrmlData_NodeNameUnknown: + aStr = "NodeNameUnknown"; + break; + case VrmlData_NonPositiveSize: + aStr = "NonPositiveSize"; + break; + case VrmlData_ReadUnknownNode: + aStr = "ReadUnknownNode"; + break; + case VrmlData_NonSupportedFeature: + aStr = "NonSupportedFeature"; + break; + case VrmlData_OutputStreamUndefined: + aStr = "OutputStreamUndefined"; + break; + case VrmlData_NotImplemented: + aStr = "NotImplemented"; + break; + default: + break; + } + if (aStr) + { + Message::SendFail() << "Error in the DEVRML_Provider during reading the file " << thePath + << "\t: ++ VRML Error: " << aStr << " in line " << aScene.GetLineError(); + return false; + } + else + { + theShape = aShape; + } + } + else + { + Message::SendFail() << "Error in the DEVRML_Provider during reading the file " << thePath + << "\t: cannot open file"; + return false; + } + return true; +} + +//================================================================================================= + +bool DEVRML_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF"); + Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main()); + aShTool->AddShape(theShape); + return Write(thePath, aDoc, theProgress); +} + +//================================================================================================= + +TCollection_AsciiString DEVRML_Provider::GetFormat() const +{ + return TCollection_AsciiString("VRML"); +} + +//================================================================================================= + +TCollection_AsciiString DEVRML_Provider::GetVendor() const +{ + return TCollection_AsciiString("OCC"); +} diff --git a/src/DEVRML/DEVRML_Provider.hxx b/src/DEVRML/DEVRML_Provider.hxx new file mode 100644 index 0000000000..df250af8f1 --- /dev/null +++ b/src/DEVRML/DEVRML_Provider.hxx @@ -0,0 +1,141 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEVRML_Provider_HeaderFile +#define _DEVRML_Provider_HeaderFile + +#include + +//! The class to transfer VRML files. +//! Reads and Writes any VRML files into/from OCCT. +//! Each operation needs configuration node. +//! +//! Providers grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "VRML" +//! The import process is supported. +//! The export process is supported. +class DEVRML_Provider : public DE_Provider +{ +public: + DEFINE_STANDARD_RTTIEXT(DEVRML_Provider, DE_Provider) + +public: + //! Default constructor + //! Configure translation process with global configuration + Standard_EXPORT DEVRML_Provider(); + + //! Configure translation process + //! @param[in] theNode object to copy + Standard_EXPORT DEVRML_Provider(const Handle(DE_ConfigurationNode)& theNode); + +public: + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + +public: + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; +}; + +#endif // _DEVRML_Provider_HeaderFile diff --git a/src/DEVRML/FILES b/src/DEVRML/FILES new file mode 100644 index 0000000000..505a3a39ec --- /dev/null +++ b/src/DEVRML/FILES @@ -0,0 +1,4 @@ +DEVRML_ConfigurationNode.cxx +DEVRML_ConfigurationNode.hxx +DEVRML_Provider.cxx +DEVRML_Provider.hxx diff --git a/src/DEXCAFCascade/DEXCAFCascade_ConfigurationNode.cxx b/src/DEXCAF/DEXCAF_ConfigurationNode.cxx similarity index 50% rename from src/DEXCAFCascade/DEXCAFCascade_ConfigurationNode.cxx rename to src/DEXCAF/DEXCAF_ConfigurationNode.cxx index d0e5e2669d..3ba0cd7072 100644 --- a/src/DEXCAFCascade/DEXCAFCascade_ConfigurationNode.cxx +++ b/src/DEXCAF/DEXCAF_ConfigurationNode.cxx @@ -11,71 +11,69 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include +#include #include #include -#include #include -IMPLEMENT_STANDARD_RTTIEXT(DEXCAFCascade_ConfigurationNode, DE_ConfigurationNode) +IMPLEMENT_STANDARD_RTTIEXT(DEXCAF_ConfigurationNode, DE_ConfigurationNode) namespace { - static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() - { - static const TCollection_AsciiString aScope = "provider"; - return aScope; - } +static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() +{ + static const TCollection_AsciiString aScope = "provider"; + return aScope; +} + +// Wrapper to auto-load DE component +DE_PluginHolder THE_OCCT_XCAF_COMPONENT_PLUGIN; +} // namespace - // Wrapper to auto-load DE component - DE_PluginHolder THE_OCCT_XCAF_COMPONENT_PLUGIN; +//================================================================================================= + +DEXCAF_ConfigurationNode::DEXCAF_ConfigurationNode() + : DE_ConfigurationNode() +{ } -//======================================================================= -// function : DEXCAFCascade_ConfigurationNode -// purpose : -//======================================================================= -DEXCAFCascade_ConfigurationNode::DEXCAFCascade_ConfigurationNode() : - DE_ConfigurationNode() -{} - -//======================================================================= -// function : DEXCAFCascade_ConfigurationNode -// purpose : -//======================================================================= -DEXCAFCascade_ConfigurationNode::DEXCAFCascade_ConfigurationNode(const Handle(DEXCAFCascade_ConfigurationNode)& theNode) - :DE_ConfigurationNode(theNode) +//================================================================================================= + +DEXCAF_ConfigurationNode::DEXCAF_ConfigurationNode(const Handle(DEXCAF_ConfigurationNode)& theNode) + : DE_ConfigurationNode(theNode) { InternalParameters = theNode->InternalParameters; } -//======================================================================= -// function : Load -// purpose : -//======================================================================= -bool DEXCAFCascade_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) +//================================================================================================= + +bool DEXCAF_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) { - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); - InternalParameters.ReadAppendMode = (PCDM_ReaderFilter::AppendMode) - theResource->IntegerVal("read.append.mode", InternalParameters.ReadAppendMode, aScope); + InternalParameters.ReadAppendMode = + (PCDM_ReaderFilter::AppendMode)theResource->IntegerVal("read.append.mode", + InternalParameters.ReadAppendMode, + aScope); theResource->GetStringSeq("read.skip.values", InternalParameters.ReadSkipValues, aScope); theResource->GetStringSeq("read.values", InternalParameters.ReadValues, aScope); return true; } -//======================================================================= -// function : Save -// purpose : -//======================================================================= -TCollection_AsciiString DEXCAFCascade_ConfigurationNode::Save() const +//================================================================================================= + +TCollection_AsciiString DEXCAF_ConfigurationNode::Save() const { TCollection_AsciiString aResult; aResult += "!*****************************************************************************\n"; - aResult = aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; + aResult = + aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; + TCollection_AsciiString aScope = + THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; aResult += "!\n"; aResult += "!Read parameters:\n"; @@ -93,7 +91,8 @@ TCollection_AsciiString DEXCAFCascade_ConfigurationNode::Save() const aResult += "!Overwrites the existing attributes by the loaded ones"; aResult += "!Default value: empty. Available values: {sequence}\n"; aResult += aScope + "read.skip.values :\t "; - for (TColStd_ListOfAsciiString::Iterator anIt(InternalParameters.ReadSkipValues); anIt.More(); anIt.Next()) + for (TColStd_ListOfAsciiString::Iterator anIt(InternalParameters.ReadSkipValues); anIt.More(); + anIt.Next()) { aResult += anIt.Value() + " "; } @@ -101,10 +100,12 @@ TCollection_AsciiString DEXCAFCascade_ConfigurationNode::Save() const aResult += "!\n"; aResult += "!1) Adds sub-tree path like \"0:2\""; - aResult += "2) Adds attribute to read by typename. Disables the skipped attributes added. (there shouldn't be '0' after -read)\n"; + aResult += "2) Adds attribute to read by typename. Disables the skipped attributes added. (there " + "shouldn't be '0' after -read)\n"; aResult += "!Default value: empty. Available values: {sequence}\n"; aResult += aScope + "read.values :\t "; - for (TColStd_ListOfAsciiString::Iterator anIt(InternalParameters.ReadValues); anIt.More(); anIt.Next()) + for (TColStd_ListOfAsciiString::Iterator anIt(InternalParameters.ReadValues); anIt.More(); + anIt.Next()) { aResult += anIt.Value() + " "; } @@ -114,76 +115,60 @@ TCollection_AsciiString DEXCAFCascade_ConfigurationNode::Save() const return aResult; } -//======================================================================= -// function : Copy -// purpose : -//======================================================================= -Handle(DE_ConfigurationNode) DEXCAFCascade_ConfigurationNode::Copy() const +//================================================================================================= + +Handle(DE_ConfigurationNode) DEXCAF_ConfigurationNode::Copy() const { - return new DEXCAFCascade_ConfigurationNode(*this); + return new DEXCAF_ConfigurationNode(*this); } -//======================================================================= -// function : BuildProvider -// purpose : -//======================================================================= -Handle(DE_Provider) DEXCAFCascade_ConfigurationNode::BuildProvider() +//================================================================================================= + +Handle(DE_Provider) DEXCAF_ConfigurationNode::BuildProvider() { - return new DEXCAFCascade_Provider (this); + return new DEXCAF_Provider(this); } -//======================================================================= -// function : IsImportSupported -// purpose : -//======================================================================= -bool DEXCAFCascade_ConfigurationNode::IsImportSupported() const +//================================================================================================= + +bool DEXCAF_ConfigurationNode::IsImportSupported() const { return true; } -//======================================================================= -// function : IsExportSupported -// purpose : -//======================================================================= -bool DEXCAFCascade_ConfigurationNode::IsExportSupported() const +//================================================================================================= + +bool DEXCAF_ConfigurationNode::IsExportSupported() const { return true; } -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString DEXCAFCascade_ConfigurationNode::GetFormat() const +//================================================================================================= + +TCollection_AsciiString DEXCAF_ConfigurationNode::GetFormat() const { return TCollection_AsciiString("XCAF"); } -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString DEXCAFCascade_ConfigurationNode::GetVendor() const +//================================================================================================= + +TCollection_AsciiString DEXCAF_ConfigurationNode::GetVendor() const { return TCollection_AsciiString("OCC"); } -//======================================================================= -// function : GetExtensions -// purpose : -//======================================================================= -TColStd_ListOfAsciiString DEXCAFCascade_ConfigurationNode::GetExtensions() const +//================================================================================================= + +TColStd_ListOfAsciiString DEXCAF_ConfigurationNode::GetExtensions() const { TColStd_ListOfAsciiString anExt; anExt.Append("xbf"); return anExt; } -//======================================================================= -// function : CheckContent -// purpose : -//======================================================================= -bool DEXCAFCascade_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const +//================================================================================================= + +bool DEXCAF_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const { if (theBuffer.IsNull() || theBuffer->Size() < 8) { diff --git a/src/DEXCAF/DEXCAF_ConfigurationNode.hxx b/src/DEXCAF/DEXCAF_ConfigurationNode.hxx new file mode 100644 index 0000000000..aaca3a0758 --- /dev/null +++ b/src/DEXCAF/DEXCAF_ConfigurationNode.hxx @@ -0,0 +1,100 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEXCAF_ConfigurationNode_HeaderFile +#define _DEXCAF_ConfigurationNode_HeaderFile + +#include +#include +#include + +//! The purpose of this class is to configure the transfer process for XDE Documents +//! Stores the necessary settings for DEXCAF_Provider. +//! Configures and creates special provider to transfer XDE Documents. +//! +//! Nodes grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "XCAF" +//! The supported CAD extension is ".xbf" +//! The import process is supported. +//! The export process is supported. +class DEXCAF_ConfigurationNode : public DE_ConfigurationNode +{ + DEFINE_STANDARD_RTTIEXT(DEXCAF_ConfigurationNode, DE_ConfigurationNode) +public: + //! Initializes all field by default + Standard_EXPORT DEXCAF_ConfigurationNode(); + + //! Copies values of all fields + //! @param[in] theNode object to copy + Standard_EXPORT DEXCAF_ConfigurationNode(const Handle(DEXCAF_ConfigurationNode)& theNode); + + //! Updates values according the resource + //! @param[in] theResource input resource to use + //! @return true if theResource loading has ended correctly + Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) + Standard_OVERRIDE; + + //! Writes configuration to the string + //! @return result resource string + Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; + + //! Copies values of all fields + //! @return new object with the same field values + Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; + + //! Creates new provider for the own format + //! @return new created provider + Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; + +public: + //! Checks the import supporting + //! @return true if import is supported + Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; + + //! Checks the export supporting + //! @return true if export is supported + Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; + + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; + + //! Gets list of supported file extensions + //! @return list of extensions + Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; + + //! Checks the file content to verify a format + //! @param[in] theBuffer read stream buffer to check content + //! @return Standard_True if file is supported by a current provider + Standard_EXPORT virtual bool CheckContent(const Handle(NCollection_Buffer)& theBuffer) const + Standard_OVERRIDE; + +public: + struct XCAFDoc_InternalSection + { + // Read + // clang-format off + PCDM_ReaderFilter::AppendMode ReadAppendMode = PCDM_ReaderFilter::AppendMode::AppendMode_Forbid; //!< Setting up the append mode + TColStd_ListOfAsciiString ReadSkipValues; //!< Overwrites the existing attributes by the loaded ones + TColStd_ListOfAsciiString ReadValues; //!< Adds sub-tree path or adds attribute to read by typename + // clang-format on + + } InternalParameters; +}; + +#endif // _DEXCAF_ConfigurationNode_HeaderFile diff --git a/src/DEXCAF/DEXCAF_Provider.cxx b/src/DEXCAF/DEXCAF_Provider.cxx new file mode 100644 index 0000000000..668b9b14bd --- /dev/null +++ b/src/DEXCAF/DEXCAF_Provider.cxx @@ -0,0 +1,297 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(DEXCAF_Provider, DE_Provider) + +//================================================================================================= + +DEXCAF_Provider::DEXCAF_Provider() {} + +//================================================================================================= + +DEXCAF_Provider::DEXCAF_Provider(const Handle(DE_ConfigurationNode)& theNode) + : DE_Provider(theNode) +{ +} + +//================================================================================================= + +bool DEXCAF_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Read(thePath, theDocument, theProgress); +} + +//================================================================================================= + +bool DEXCAF_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Write(thePath, theDocument, theProgress); +} + +//================================================================================================= + +bool DEXCAF_Provider::Read(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + if (theDocument.IsNull()) + { + Message::SendFail() << "Error in the DEXCAF_Provider during reading the file " << thePath + << "\t: theDocument shouldn't be null"; + return false; + } + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEXCAF_ConfigurationNode))) + { + Message::SendFail() << "Error in the DEXCAF_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(DEXCAF_ConfigurationNode) aNode = Handle(DEXCAF_ConfigurationNode)::DownCast(GetNode()); + Handle(TDocStd_Document) aDocument; + Handle(TDocStd_Application) anApp = new TDocStd_Application(); + BinDrivers::DefineFormat(anApp); + BinLDrivers::DefineFormat(anApp); + BinTObjDrivers::DefineFormat(anApp); + BinXCAFDrivers::DefineFormat(anApp); + StdDrivers::DefineFormat(anApp); + StdLDrivers::DefineFormat(anApp); + XmlDrivers::DefineFormat(anApp); + XmlLDrivers::DefineFormat(anApp); + XmlTObjDrivers::DefineFormat(anApp); + XmlXCAFDrivers::DefineFormat(anApp); + Handle(PCDM_ReaderFilter) aFilter = + new PCDM_ReaderFilter(aNode->InternalParameters.ReadAppendMode); + for (TColStd_ListOfAsciiString::Iterator anIt(aNode->InternalParameters.ReadSkipValues); + anIt.More(); + anIt.Next()) + { + aFilter->AddSkipped(anIt.Value()); + } + for (TColStd_ListOfAsciiString::Iterator anIt(aNode->InternalParameters.ReadValues); anIt.More(); + anIt.Next()) + { + if (anIt.Value().StartsWith("0")) + { + aFilter->AddPath(anIt.Value()); + } + else + { + aFilter->AddRead(anIt.Value()); + } + } + + if (anApp->Open(thePath, aDocument, aFilter, theProgress) != PCDM_RS_OK) + { + Message::SendFail() << "Error in the DEXCAF_Provider during reading the file : " << thePath + << "\t: Cannot open XDE document"; + return false; + } + theDocument->SetData(aDocument->GetData()); + return true; +} + +//================================================================================================= + +bool DEXCAF_Provider::Write(const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress) +{ + Handle(TDocStd_Application) anApp = new TDocStd_Application(); + BinXCAFDrivers::DefineFormat(anApp); + + Handle(DEXCAF_ConfigurationNode) aNode = Handle(DEXCAF_ConfigurationNode)::DownCast(GetNode()); + if (aNode->GlobalParameters.LengthUnit != 1.0) + { + Message::SendWarning() + << "Warning in the DEXCAF_Provider during writing the file " << thePath + << "\t: Target Units for writing were changed, but current format doesn't support scaling"; + } + + PCDM_StoreStatus aStatus = PCDM_SS_Doc_IsNull; + if (!thePath.IsEmpty()) + { + aStatus = anApp->SaveAs(theDocument, thePath, theProgress); + } + else if (!theDocument->IsSaved()) + { + Message::SendFail() << "Storage error in the DEXCAF_Provider during writing the file " + << thePath << "\t: Storage error : this document has never been saved"; + return false; + } + else + { + aStatus = anApp->Save(theDocument, theProgress); + } + + switch (aStatus) + { + case PCDM_SS_OK: + return true; + case PCDM_SS_DriverFailure: + Message::SendFail() << "Error in the DEXCAF_Provider during writing the file : " << thePath + << "\t: Storage error : driver failure"; + break; + case PCDM_SS_WriteFailure: + Message::SendFail() << "Error in the DEXCAF_Provider during the writing the file : " + << thePath << "\t: Storage error : write failure"; + break; + case PCDM_SS_Failure: + Message::SendFail() << "Error in the DEXCAF_Provider during writing the file : " << thePath + << "\t: Storage error : general failure"; + break; + case PCDM_SS_Doc_IsNull: + Message::SendFail() << "Error in the DEXCAF_Provider during writing the file : " << thePath + << "\t: Storage error :: document is NULL"; + break; + case PCDM_SS_No_Obj: + Message::SendFail() << "Error in the DEXCAF_Provider during writing the file : " << thePath + << "\t: Storage error : no object"; + break; + case PCDM_SS_Info_Section_Error: + Message::SendFail() << "Error in the DEXCAF_Provider during writing the file : " << thePath + << "\t: Storage error : section error"; + break; + case PCDM_SS_UserBreak: + Message::SendFail() << "Error in the DEXCAF_Provider during writing the file : " << thePath + << "\t: Storage error : user break"; + break; + case PCDM_SS_UnrecognizedFormat: + Message::SendFail() << "Error in the DEXCAF_Provider during writing the file : " << thePath + << "\t: Storage error : unrecognized document storage format : " + << theDocument->StorageFormat(); + break; + } + return false; +} + +//================================================================================================= + +bool DEXCAF_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Read(thePath, theShape, theProgress); +} + +//================================================================================================= + +bool DEXCAF_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress) +{ + (void)theWS; + return Write(thePath, theShape, theProgress); +} + +//================================================================================================= + +bool DEXCAF_Provider::Read(const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEXCAF_ConfigurationNode))) + { + Message::SendFail() << "Error in the DEXCAF_Provider during reading the file " << thePath + << "\t: Incorrect or empty Configuration Node"; + return false; + } + Handle(TDocStd_Document) aDocument; + Handle(TDocStd_Application) anApp = new TDocStd_Application(); + BinXCAFDrivers::DefineFormat(anApp); + anApp->NewDocument("BinXCAF", aDocument); + Read(thePath, aDocument, theProgress); + TDF_LabelSequence aLabels; + Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(aDocument->Main()); + aSTool->GetFreeShapes(aLabels); + if (aLabels.Length() <= 0) + { + Message::SendFail() << "Error in the DEXCAF_Provider during reading the file : " << thePath + << "\t: Document contain no shapes"; + return false; + } + + if (aLabels.Length() == 1) + { + theShape = aSTool->GetShape(aLabels.Value(1)); + } + else + { + TopoDS_Compound aComp; + BRep_Builder aBuilder; + aBuilder.MakeCompound(aComp); + for (Standard_Integer anIndex = 1; anIndex <= aLabels.Length(); anIndex++) + { + TopoDS_Shape aS = aSTool->GetShape(aLabels.Value(anIndex)); + aBuilder.Add(aComp, aS); + } + theShape = aComp; + } + return true; +} + +//================================================================================================= + +bool DEXCAF_Provider::Write(const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress) +{ + Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF"); + Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main()); + aShTool->AddShape(theShape); + return Write(thePath, aDoc, theProgress); +} + +//================================================================================================= + +TCollection_AsciiString DEXCAF_Provider::GetFormat() const +{ + return TCollection_AsciiString("XCAF"); +} + +//================================================================================================= + +TCollection_AsciiString DEXCAF_Provider::GetVendor() const +{ + return TCollection_AsciiString("OCC"); +} diff --git a/src/DEXCAF/DEXCAF_Provider.hxx b/src/DEXCAF/DEXCAF_Provider.hxx new file mode 100644 index 0000000000..62f95b3995 --- /dev/null +++ b/src/DEXCAF/DEXCAF_Provider.hxx @@ -0,0 +1,141 @@ +// Copyright (c) 2022 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _DEXCAF_Provider_HeaderFile +#define _DEXCAF_Provider_HeaderFile + +#include + +//! The class to transfer XCAF Documents. +//! Reads and Writes any XDE Document files into/from OCCT. +//! Each operation needs configuration node. +//! +//! Providers grouped by Vendor name and Format type. +//! The Vendor name is "OCC" +//! The Format type is "XCAF" +//! The import process is supported. +//! The export process is supported. +class DEXCAF_Provider : public DE_Provider +{ +public: + DEFINE_STANDARD_RTTIEXT(DEXCAF_Provider, DE_Provider) + +public: + //! Default constructor + //! Configure translation process with global configuration + Standard_EXPORT DEXCAF_Provider(); + + //! Configure translation process + //! @param[in] theNode object to copy + Standard_EXPORT DEXCAF_Provider(const Handle(DE_ConfigurationNode)& theNode); + +public: + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theDocument document to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theDocument document to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const Handle(TDocStd_Document)& theDocument, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theWS current work session + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + Handle(XSControl_WorkSession)& theWS, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Reads a CAD file, according internal configuration + //! @param[in] thePath path to the import CAD file + //! @param[out] theShape shape to save result + //! @param[in] theProgress progress indicator + //! @return true if Read operation has ended correctly + Standard_EXPORT virtual bool Read( + const TCollection_AsciiString& thePath, + TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + + //! Writes a CAD file, according internal configuration + //! @param[in] thePath path to the export CAD file + //! @param[out] theShape shape to export + //! @param[in] theProgress progress indicator + //! @return true if Write operation has ended correctly + Standard_EXPORT virtual bool Write( + const TCollection_AsciiString& thePath, + const TopoDS_Shape& theShape, + const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; + +public: + //! Gets CAD format name of associated provider + //! @return provider CAD format + Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; + + //! Gets provider's vendor name of associated provider + //! @return provider's vendor name + Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; +}; + +#endif // _DEXCAF_Provider_HeaderFile diff --git a/src/DEXCAF/FILES b/src/DEXCAF/FILES new file mode 100644 index 0000000000..cab1192c84 --- /dev/null +++ b/src/DEXCAF/FILES @@ -0,0 +1,4 @@ +DEXCAF_ConfigurationNode.cxx +DEXCAF_ConfigurationNode.hxx +DEXCAF_Provider.cxx +DEXCAF_Provider.hxx diff --git a/src/DEXCAFCascade/DEXCAFCascade_ConfigurationNode.hxx b/src/DEXCAFCascade/DEXCAFCascade_ConfigurationNode.hxx index a434f73464..0877648aa3 100644 --- a/src/DEXCAFCascade/DEXCAFCascade_ConfigurationNode.hxx +++ b/src/DEXCAFCascade/DEXCAFCascade_ConfigurationNode.hxx @@ -14,88 +14,9 @@ #ifndef _DEXCAFCascade_ConfigurationNode_HeaderFile #define _DEXCAFCascade_ConfigurationNode_HeaderFile -#include -#include -#include +#include -//! The purpose of this class is to configure the transfer process for XDE Documents -//! Stores the necessary settings for DEXCAFCascade_Provider. -//! Configures and creates special provider to transfer XDE Documents. -//! -//! Nodes grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "XCAF" -//! The supported CAD extension is ".xbf" -//! The import process is supported. -//! The export process is supported. -class DEXCAFCascade_ConfigurationNode : public DE_ConfigurationNode -{ - DEFINE_STANDARD_RTTIEXT(DEXCAFCascade_ConfigurationNode, DE_ConfigurationNode) -public: - - //! Initializes all field by default - Standard_EXPORT DEXCAFCascade_ConfigurationNode(); - - //! Copies values of all fields - //! @param[in] theNode object to copy - Standard_EXPORT DEXCAFCascade_ConfigurationNode(const Handle(DEXCAFCascade_ConfigurationNode)& theNode); - - //! Updates values according the resource - //! @param[in] theResource input resource to use - //! @return true if theResource loading has ended correctly - Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) Standard_OVERRIDE; - - //! Writes configuration to the string - //! @return result resource string - Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; - - //! Copies values of all fields - //! @return new object with the same field values - Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; - - - //! Creates new provider for the own format - //! @return new created provider - Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; - -public: - - //! Checks the import supporting - //! @return true if import is supported - Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; - - //! Checks the export supporting - //! @return true if export is supported - Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; - - //! Gets list of supported file extensions - //! @return list of extensions - Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; - - //! Checks the file content to verify a format - //! @param[in] theBuffer read stream buffer to check content - //! @return Standard_True if file is supported by a current provider - Standard_EXPORT virtual bool CheckContent(const Handle(NCollection_Buffer)& theBuffer) const Standard_OVERRIDE; - -public: - struct XCAFDoc_InternalSection - { - // Read -// clang-format off - PCDM_ReaderFilter::AppendMode ReadAppendMode = PCDM_ReaderFilter::AppendMode::AppendMode_Forbid; //!< Setting up the append mode - TColStd_ListOfAsciiString ReadSkipValues; //!< Overwrites the existing attributes by the loaded ones - TColStd_ListOfAsciiString ReadValues; //!< Adds sub-tree path or adds attribute to read by typename -// clang-format on - - } InternalParameters; -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DEXCAF_ConfigurationNode DEXCAFCascade_ConfigurationNode; #endif // _DEXCAFCascade_ConfigurationNode_HeaderFile diff --git a/src/DEXCAFCascade/DEXCAFCascade_Provider.cxx b/src/DEXCAFCascade/DEXCAFCascade_Provider.cxx deleted file mode 100644 index 6b8908580c..0000000000 --- a/src/DEXCAFCascade/DEXCAFCascade_Provider.cxx +++ /dev/null @@ -1,316 +0,0 @@ -// Copyright (c) 2022 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -IMPLEMENT_STANDARD_RTTIEXT(DEXCAFCascade_Provider, DE_Provider) - - -//======================================================================= -// function : DEXCAFCascade_Provider -// purpose : -//======================================================================= -DEXCAFCascade_Provider::DEXCAFCascade_Provider() -{} - -//======================================================================= -// function : DEXCAFCascade_Provider -// purpose : -//======================================================================= -DEXCAFCascade_Provider::DEXCAFCascade_Provider(const Handle(DE_ConfigurationNode)& theNode) - :DE_Provider(theNode) -{} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool DEXCAFCascade_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Read(thePath, theDocument, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool DEXCAFCascade_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Write(thePath, theDocument, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool DEXCAFCascade_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - if (theDocument.IsNull()) - { - Message::SendFail() << "Error in the DEXCAFCascade_Provider during reading the file " << - thePath << "\t: theDocument shouldn't be null"; - return false; - } - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEXCAFCascade_ConfigurationNode))) - { - Message::SendFail() << "Error in the DEXCAFCascade_Provider during reading the file " << thePath - << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(DEXCAFCascade_ConfigurationNode) aNode = Handle(DEXCAFCascade_ConfigurationNode)::DownCast(GetNode()); - Handle(TDocStd_Document) aDocument; - Handle(TDocStd_Application) anApp = new TDocStd_Application(); - BinDrivers::DefineFormat(anApp); - BinLDrivers::DefineFormat(anApp); - BinTObjDrivers::DefineFormat(anApp); - BinXCAFDrivers::DefineFormat(anApp); - StdDrivers::DefineFormat(anApp); - StdLDrivers::DefineFormat(anApp); - XmlDrivers::DefineFormat(anApp); - XmlLDrivers::DefineFormat(anApp); - XmlTObjDrivers::DefineFormat(anApp); - XmlXCAFDrivers::DefineFormat(anApp); - Handle(PCDM_ReaderFilter) aFilter = new PCDM_ReaderFilter(aNode->InternalParameters.ReadAppendMode); - for (TColStd_ListOfAsciiString::Iterator anIt(aNode->InternalParameters.ReadSkipValues); anIt.More(); anIt.Next()) - { - aFilter->AddSkipped(anIt.Value()); - } - for (TColStd_ListOfAsciiString::Iterator anIt(aNode->InternalParameters.ReadValues); anIt.More(); anIt.Next()) - { - if (anIt.Value().StartsWith("0")) - { - aFilter->AddPath(anIt.Value()); - } - else - { - aFilter->AddRead(anIt.Value()); - } - } - - if (anApp->Open(thePath, aDocument, aFilter, theProgress) != PCDM_RS_OK) - { - Message::SendFail() << "Error in the DEXCAFCascade_Provider during reading the file : " << thePath - << "\t: Cannot open XDE document"; - return false; - } - theDocument->SetData(aDocument->GetData()); - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool DEXCAFCascade_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - Handle(TDocStd_Application) anApp = new TDocStd_Application(); - BinXCAFDrivers::DefineFormat(anApp); - - Handle(DEXCAFCascade_ConfigurationNode) aNode = Handle(DEXCAFCascade_ConfigurationNode)::DownCast(GetNode()); - if (aNode->GlobalParameters.LengthUnit != 1.0) - { - Message::SendWarning() << "Warning in the DEXCAFCascade_Provider during writing the file " << - thePath << "\t: Target Units for writing were changed, but current format doesn't support scaling"; - } - - PCDM_StoreStatus aStatus = PCDM_SS_Doc_IsNull; - if (!thePath.IsEmpty()) - { - aStatus = anApp->SaveAs(theDocument, thePath, theProgress); - } - else if (!theDocument->IsSaved()) - { - Message::SendFail() << "Storage error in the DEXCAFCascade_Provider during writing the file " << - thePath << "\t: Storage error : this document has never been saved"; - return false; - } - else - { - aStatus = anApp->Save(theDocument, theProgress); - } - - switch (aStatus) - { - case PCDM_SS_OK: - return true; - case PCDM_SS_DriverFailure: - Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath - << "\t: Storage error : driver failure"; - break; - case PCDM_SS_WriteFailure: - Message::SendFail() << "Error in the DEXCAFCascade_Provider during the writing the file : " << thePath - << "\t: Storage error : write failure"; - break; - case PCDM_SS_Failure: - Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath - << "\t: Storage error : general failure"; - break; - case PCDM_SS_Doc_IsNull: - Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath - << "\t: Storage error :: document is NULL"; - break; - case PCDM_SS_No_Obj: - Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath - << "\t: Storage error : no object"; - break; - case PCDM_SS_Info_Section_Error: - Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath - << "\t: Storage error : section error"; - break; - case PCDM_SS_UserBreak: - Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath - << "\t: Storage error : user break"; - break; - case PCDM_SS_UnrecognizedFormat: - Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath - << "\t: Storage error : unrecognized document storage format : " << theDocument->StorageFormat(); - break; - } - return false; -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool DEXCAFCascade_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Read(thePath, theShape, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool DEXCAFCascade_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Write(thePath, theShape, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool DEXCAFCascade_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEXCAFCascade_ConfigurationNode))) - { - Message::SendFail() << "Error in the DEXCAFCascade_Provider during reading the file " << thePath - << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(TDocStd_Document) aDocument; - Handle(TDocStd_Application) anApp = new TDocStd_Application(); - BinXCAFDrivers::DefineFormat(anApp); - anApp->NewDocument("BinXCAF", aDocument); - Read(thePath, aDocument, theProgress); - TDF_LabelSequence aLabels; - Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(aDocument->Main()); - aSTool->GetFreeShapes(aLabels); - if (aLabels.Length() <= 0) - { - Message::SendFail() << "Error in the DEXCAFCascade_Provider during reading the file : " << thePath - << "\t: Document contain no shapes"; - return false; - } - - if (aLabels.Length() == 1) - { - theShape = aSTool->GetShape(aLabels.Value(1)); - } - else - { - TopoDS_Compound aComp; - BRep_Builder aBuilder; - aBuilder.MakeCompound(aComp); - for (Standard_Integer anIndex = 1; anIndex <= aLabels.Length(); anIndex++) - { - TopoDS_Shape aS = aSTool->GetShape(aLabels.Value(anIndex)); - aBuilder.Add(aComp, aS); - } - theShape = aComp; - } - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool DEXCAFCascade_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF"); - Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main()); - aShTool->AddShape(theShape); - return Write(thePath, aDoc, theProgress); -} - -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString DEXCAFCascade_Provider::GetFormat() const -{ - return TCollection_AsciiString("XCAF"); -} - -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString DEXCAFCascade_Provider::GetVendor() const -{ - return TCollection_AsciiString("OCC"); -} diff --git a/src/DEXCAFCascade/DEXCAFCascade_Provider.hxx b/src/DEXCAFCascade/DEXCAFCascade_Provider.hxx index f49c99f9ec..4630f92fcf 100644 --- a/src/DEXCAFCascade/DEXCAFCascade_Provider.hxx +++ b/src/DEXCAFCascade/DEXCAFCascade_Provider.hxx @@ -14,123 +14,9 @@ #ifndef _DEXCAFCascade_Provider_HeaderFile #define _DEXCAFCascade_Provider_HeaderFile -#include +#include -//! The class to transfer XCAF Documents. -//! Reads and Writes any XDE Document files into/from OCCT. -//! Each operation needs configuration node. -//! -//! Providers grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "XCAF" -//! The import process is supported. -//! The export process is supported. -class DEXCAFCascade_Provider : public DE_Provider -{ -public: - DEFINE_STANDARD_RTTIEXT(DEXCAFCascade_Provider, DE_Provider) - -public: - - //! Default constructor - //! Configure translation process with global configuration - Standard_EXPORT DEXCAFCascade_Provider(); - - //! Configure translation process - //! @param[in] theNode object to copy - Standard_EXPORT DEXCAFCascade_Provider(const Handle(DE_ConfigurationNode)& theNode); - -public: - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - -public: - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DEXCAF_Provider DEXCAFCascade_Provider; #endif // _DEXCAFCascade_Provider_HeaderFile diff --git a/src/DEXCAFCascade/FILES b/src/DEXCAFCascade/FILES index db5917e692..2576fed40c 100644 --- a/src/DEXCAFCascade/FILES +++ b/src/DEXCAFCascade/FILES @@ -1,4 +1,2 @@ -DEXCAFCascade_ConfigurationNode.cxx DEXCAFCascade_ConfigurationNode.hxx -DEXCAFCascade_Provider.cxx DEXCAFCascade_Provider.hxx diff --git a/src/IGESCAFControl/FILES b/src/IGESCAFControl/FILES index 7d61e6a979..97d2b372fe 100644 --- a/src/IGESCAFControl/FILES +++ b/src/IGESCAFControl/FILES @@ -1,8 +1,6 @@ IGESCAFControl.cxx IGESCAFControl.hxx -IGESCAFControl_ConfigurationNode.cxx IGESCAFControl_ConfigurationNode.hxx -IGESCAFControl_Provider.cxx IGESCAFControl_Provider.hxx IGESCAFControl_Reader.cxx IGESCAFControl_Reader.hxx diff --git a/src/IGESCAFControl/IGESCAFControl_ConfigurationNode.hxx b/src/IGESCAFControl/IGESCAFControl_ConfigurationNode.hxx index 2c4fd64994..eae686e6d2 100644 --- a/src/IGESCAFControl/IGESCAFControl_ConfigurationNode.hxx +++ b/src/IGESCAFControl/IGESCAFControl_ConfigurationNode.hxx @@ -14,166 +14,9 @@ #ifndef _IGESCAFControl_ConfigurationNode_HeaderFile #define _IGESCAFControl_ConfigurationNode_HeaderFile -#include -#include +#include -//! The purpose of this class is to configure the transfer process for IGES format -//! Stores the necessary settings for IGESCAFControl_Provider. -//! Configures and creates special provider to transfer IGES files. -//! -//! Nodes grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "IGES" -//! The supported CAD extensions are ".igs", ".iges" -//! The import process is supported. -//! The export process is supported. -class IGESCAFControl_ConfigurationNode : public DE_ConfigurationNode -{ - DEFINE_STANDARD_RTTIEXT(IGESCAFControl_ConfigurationNode, DE_ConfigurationNode) -public: - - //! Initializes all fields by default - Standard_EXPORT IGESCAFControl_ConfigurationNode(); - - //! Copies values of all fields - //! @param[in] theNode object to copy - Standard_EXPORT IGESCAFControl_ConfigurationNode(const Handle(IGESCAFControl_ConfigurationNode)& theNode); - - //! Updates values according the resource - //! @param[in] theResource input resource to use - //! @return true if theResource loading has ended correctly - Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) Standard_OVERRIDE; - - //! Writes configuration to the string - //! @return result resource string - Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; - - //! Copies values of all fields - //! @return new object with the same field values - Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; - - - //! Creates new provider for the own format - //! @return new created provider - Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; - -public: - - //! Checks the import supporting - //! @return true if import is supported - Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; - - //! Checks the export supporting - //! @return true if export is supported - Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; - - //! Gets list of supported file extensions - //! @return list of extensions - Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; - - //! Checks the file content to verify a format - //! @param[in] theBuffer read stream buffer to check content - //! @return Standard_True if file is supported by a current provider - Standard_EXPORT virtual bool CheckContent(const Handle(NCollection_Buffer)& theBuffer) const Standard_OVERRIDE; - -public: - - enum ReadMode_BSplineContinuity - { - ReadMode_BSplineContinuity_C0 = 0, - ReadMode_BSplineContinuity_C1, - ReadMode_BSplineContinuity_C2 - }; - enum ReadMode_Precision - { - ReadMode_Precision_File = 0, - ReadMode_Precision_User - }; - enum ReadMode_MaxPrecision - { - ReadMode_MaxPrecision_Preferred = 0, - ReadMode_MaxPrecision_Forced - }; - enum ReadMode_SurfaceCurve - { - ReadMode_SurfaceCurve_Default = 0, - ReadMode_SurfaceCurve_2DUse_Preferred = 2, - ReadMode_SurfaceCurve_2DUse_Forced = -2, - ReadMode_SurfaceCurve_3DUse_Preferred = 3, - ReadMode_SurfaceCurve_3DUse_Forced = -3 - }; - enum WriteMode_BRep - { - WriteMode_BRep_Faces = 0, - WriteMode_BRep_BRep - }; - enum WriteMode_ConvertSurface - { - WriteMode_ConvertSurface_Off = 0, - WriteMode_ConvertSurface_On - }; - enum WriteMode_PrecisionMode - { - WriteMode_PrecisionMode_Least = -1, - WriteMode_PrecisionMode_Average = 0, - WriteMode_PrecisionMode_Greatest = 1, - WriteMode_PrecisionMode_Session = 2 - }; - enum WriteMode_PlaneMode - { - WriteMode_PlaneMode_Plane = 0, - WriteMode_PlaneMode_BSpline - }; - struct IGESCAFControl_InternalSection - { - // Common -// clang-format off - ReadMode_BSplineContinuity ReadBSplineContinuity = ReadMode_BSplineContinuity_C1; // - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -IMPLEMENT_STANDARD_RTTIEXT(IGESCAFControl_Provider, DE_Provider) - -//======================================================================= -// function : IGESCAFControl_Provider -// purpose : -//======================================================================= -IGESCAFControl_Provider::IGESCAFControl_Provider() -{} - -//======================================================================= -// function : IGESCAFControl_Provider -// purpose : -//======================================================================= -IGESCAFControl_Provider::IGESCAFControl_Provider(const Handle(DE_ConfigurationNode)& theNode) - : DE_Provider(theNode) -{} - -//======================================================================= -// function : personizeWS -// purpose : -//======================================================================= -void IGESCAFControl_Provider::personizeWS(Handle(XSControl_WorkSession)& theWS) -{ - if (theWS.IsNull()) - { - Message::SendWarning() << "Warning: IGESCAFControl_Provider :" - << " Null work session, use internal temporary session"; - theWS = new XSControl_WorkSession(); - } - Handle(IGESControl_Controller) aCntrl = Handle(IGESControl_Controller)::DownCast(theWS->NormAdaptor()); - if (aCntrl.IsNull()) - { - IGESControl_Controller::Init(); - theWS->SelectNorm("IGES"); - } -} - -//======================================================================= -// function : initStatic -// purpose : -//======================================================================= -void IGESCAFControl_Provider::initStatic(const Handle(DE_ConfigurationNode)& theNode) -{ - Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(theNode); - IGESData::Init(); - - // Get previous values - myOldValues.ReadBSplineContinuity = (IGESCAFControl_ConfigurationNode::ReadMode_BSplineContinuity)Interface_Static::IVal("read.iges.bspline.continuity"); - myOldValues.ReadPrecisionMode = (IGESCAFControl_ConfigurationNode::ReadMode_Precision)Interface_Static::IVal("read.precision.mode"); - myOldValues.ReadPrecisionVal = Interface_Static::RVal("read.precision.val"); - myOldValues.ReadMaxPrecisionMode = (IGESCAFControl_ConfigurationNode::ReadMode_MaxPrecision)Interface_Static::IVal("read.maxprecision.mode"); - myOldValues.ReadMaxPrecisionVal = Interface_Static::RVal("read.maxprecision.val"); - myOldValues.ReadSameParamMode = Interface_Static::IVal("read.stdsameparameter.mode") == 1; - myOldValues.ReadSurfaceCurveMode = (IGESCAFControl_ConfigurationNode::ReadMode_SurfaceCurve)Interface_Static::IVal("read.surfacecurve.mode"); - myOldValues.EncodeRegAngle = Interface_Static::RVal("read.encoderegularity.angle") * 180.0 / M_PI; - - myOldValues.ReadApproxd1 = Interface_Static::IVal("read.iges.bspline.approxd1.mode") == 1; - myOldValues.ReadResourceName = Interface_Static::CVal("read.iges.resource.name"); - myOldValues.ReadSequence = Interface_Static::CVal("read.iges.sequence"); - myOldValues.ReadFaultyEntities = Interface_Static::IVal("read.iges.faulty.entities") == 1; - myOldValues.ReadOnlyVisible = Interface_Static::IVal("read.iges.onlyvisible") == 1; - - myOldValues.WriteBRepMode = (IGESCAFControl_ConfigurationNode::WriteMode_BRep)Interface_Static::IVal("write.iges.brep.mode"); - myOldValues.WriteConvertSurfaceMode = (IGESCAFControl_ConfigurationNode::WriteMode_ConvertSurface)Interface_Static::IVal("write.convertsurface.mode"); - myOldValues.WriteHeaderAuthor = Interface_Static::CVal("write.iges.header.author"); - myOldValues.WriteHeaderCompany = Interface_Static::CVal("write.iges.header.company"); - myOldValues.WriteHeaderProduct = Interface_Static::CVal("write.iges.header.product"); - myOldValues.WriteHeaderReciever = Interface_Static::CVal("write.iges.header.receiver"); - myOldValues.WriteResourceName = Interface_Static::CVal("write.iges.resource.name"); - myOldValues.WriteSequence = Interface_Static::CVal("write.iges.sequence"); - myOldValues.WritePrecisionMode = (IGESCAFControl_ConfigurationNode::WriteMode_PrecisionMode)Interface_Static::IVal("write.precision.mode"); - myOldValues.WritePrecisionVal = Interface_Static::RVal("write.precision.val"); - myOldValues.WritePlaneMode = (IGESCAFControl_ConfigurationNode::WriteMode_PlaneMode)Interface_Static::IVal("write.iges.plane.mode"); - myOldValues.WriteOffsetMode = Interface_Static::IVal("write.iges.offset.mode") == 1; - - myOldLengthUnit = Interface_Static::IVal("xstep.cascade.unit"); - - // Set new values - UnitsMethods::SetCasCadeLengthUnit(aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter); - TCollection_AsciiString aStrUnit(UnitsMethods::DumpLengthUnit(aNode->GlobalParameters.LengthUnit)); - aStrUnit.UpperCase(); - Interface_Static::SetCVal("xstep.cascade.unit", aStrUnit.ToCString()); - setStatic(aNode->InternalParameters); -} - -//======================================================================= -// function : setStatic -// purpose : -//======================================================================= -void IGESCAFControl_Provider::setStatic(const IGESCAFControl_ConfigurationNode::IGESCAFControl_InternalSection& theParameter) -{ - Interface_Static::SetIVal("read.iges.bspline.continuity", theParameter.ReadBSplineContinuity); - Interface_Static::SetIVal("read.precision.mode", theParameter.ReadPrecisionMode); - Interface_Static::SetRVal("read.precision.val", theParameter.ReadPrecisionVal); - Interface_Static::SetIVal("read.maxprecision.mode", theParameter.ReadMaxPrecisionMode); - Interface_Static::SetRVal("read.maxprecision.val", theParameter.ReadMaxPrecisionVal); - Interface_Static::SetIVal("read.stdsameparameter.mode", theParameter.ReadSameParamMode); - Interface_Static::SetIVal("read.surfacecurve.mode", theParameter.ReadSurfaceCurveMode); - Interface_Static::SetRVal("read.encoderegularity.angle", theParameter.EncodeRegAngle * M_PI / 180.0); - - Interface_Static::SetIVal("read.iges.bspline.approxd1.mode", theParameter.ReadApproxd1); - Interface_Static::SetCVal("read.iges.resource.name", theParameter.ReadResourceName.ToCString()); - Interface_Static::SetCVal("read.iges.sequence", theParameter.ReadSequence.ToCString()); - Interface_Static::SetIVal("read.iges.faulty.entities", theParameter.ReadFaultyEntities); - Interface_Static::SetIVal("read.iges.onlyvisible", theParameter.ReadOnlyVisible); - - Interface_Static::SetIVal("write.iges.brep.mode", theParameter.WriteBRepMode); - Interface_Static::SetIVal("write.convertsurface.mode", theParameter.WriteConvertSurfaceMode); - Interface_Static::SetCVal("write.iges.header.author", theParameter.WriteHeaderAuthor.ToCString()); - Interface_Static::SetCVal("write.iges.header.company", theParameter.WriteHeaderCompany.ToCString()); - Interface_Static::SetCVal("write.iges.header.product", theParameter.WriteHeaderProduct.ToCString()); - Interface_Static::SetCVal("write.iges.header.receiver", theParameter.WriteHeaderReciever.ToCString()); - Interface_Static::SetCVal("write.iges.resource.name", theParameter.WriteResourceName.ToCString()); - Interface_Static::SetCVal("write.iges.sequence", theParameter.WriteSequence.ToCString()); - Interface_Static::SetIVal("write.precision.mode", theParameter.WritePrecisionMode); - Interface_Static::SetRVal("write.precision.val", theParameter.WritePrecisionVal); - Interface_Static::SetIVal("write.iges.plane.mode", theParameter.WritePlaneMode); - Interface_Static::SetIVal("write.iges.offset.mode", theParameter.WriteOffsetMode); -} - -//======================================================================= -// function : resetStatic -// purpose : -//======================================================================= -void IGESCAFControl_Provider::resetStatic() -{ - Interface_Static::SetIVal("xstep.cascade.unit", myOldLengthUnit); - UnitsMethods::SetCasCadeLengthUnit(myOldLengthUnit); - setStatic(myOldValues); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool IGESCAFControl_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - if (theDocument.IsNull()) - { - Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " << - thePath << "\t: theDocument shouldn't be null"; - return false; - } - if (!GetNode()->IsKind(STANDARD_TYPE(IGESCAFControl_ConfigurationNode))) - { - Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode()); - personizeWS(theWS); - initStatic(aNode); - XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter); - IGESCAFControl_Reader aReader; - aReader.SetWS(theWS); - - aReader.SetReadVisible(aNode->InternalParameters.ReadOnlyVisible); - - aReader.SetColorMode(aNode->InternalParameters.ReadColor); - aReader.SetNameMode(aNode->InternalParameters.ReadName); - aReader.SetLayerMode(aNode->InternalParameters.ReadLayer); - - IFSelect_ReturnStatus aReadStat = IFSelect_RetVoid; - aReadStat = aReader.ReadFile(thePath.ToCString()); - if (aReadStat != IFSelect_RetDone) - { - Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " << - thePath << "\t: abandon, no model loaded"; - resetStatic(); - return false; - } - - if (!aReader.Transfer(theDocument, theProgress)) - { - Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " << - thePath << "\t: Cannot read any relevant data from the IGES file"; - resetStatic(); - return false; - } - resetStatic(); - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool IGESCAFControl_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - if (!GetNode()->IsKind(STANDARD_TYPE(IGESCAFControl_ConfigurationNode))) - { - Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode()); - personizeWS(theWS); - initStatic(aNode); - Standard_Integer aFlag = IGESData_BasicEditor::GetFlagByValue(aNode->GlobalParameters.LengthUnit); - IGESCAFControl_Writer aWriter(theWS, (aFlag > 0) ? IGESData_BasicEditor::UnitFlagName(aFlag) : "MM"); - IGESData_GlobalSection aGS = aWriter.Model()->GlobalSection(); - Standard_Real aScaleFactorMM = 1.; - Standard_Boolean aHasUnits = XCAFDoc_DocumentTool::GetLengthUnit(theDocument, aScaleFactorMM, UnitsMethods_LengthUnit_Millimeter); - if (aHasUnits) - { - aGS.SetCascadeUnit(aScaleFactorMM); - } - else - { - aGS.SetCascadeUnit(aNode->GlobalParameters.SystemUnit); - Message::SendWarning() << "Warning in the IGESCAFControl_Provider during writing the file " << - thePath << "\t: The document has no information on Units. Using global parameter as initial Unit."; - } - if (aFlag == 0) - { - aGS.SetScale(aNode->GlobalParameters.LengthUnit); - } - aWriter.Model()->SetGlobalSection(aGS); - aWriter.SetColorMode(aNode->InternalParameters.WriteColor); - aWriter.SetNameMode(aNode->InternalParameters.WriteName); - aWriter.SetLayerMode(aNode->InternalParameters.WriteLayer); - - if (!aWriter.Transfer(theDocument, theProgress)) - { - Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " << - thePath << "\t: The document cannot be translated or gives no result"; - resetStatic(); - return false; - } - if (!aWriter.Write(thePath.ToCString())) - { - Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " << - thePath << "\t: Write failed"; - resetStatic(); - return false; - } - resetStatic(); - return true; -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool IGESCAFControl_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); - return Read(thePath, theDocument, aWS, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool IGESCAFControl_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); - return Write(thePath, theDocument, aWS, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool IGESCAFControl_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theProgress; - if (!GetNode()->IsKind(STANDARD_TYPE(IGESCAFControl_ConfigurationNode))) - { - Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode()); - initStatic(aNode); - personizeWS(theWS); - IGESControl_Reader aReader; - aReader.SetWS(theWS); - aReader.SetReadVisible(aNode->InternalParameters.ReadOnlyVisible); - IFSelect_ReturnStatus aReadStat = IFSelect_RetVoid; - aReadStat = aReader.ReadFile(thePath.ToCString()); - if (aReadStat != IFSelect_RetDone) - { - Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " << - thePath << "\t: Could not read file, no model loaded"; - resetStatic(); - return false; - } - if (aReader.TransferRoots() <= 0) - { - Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " << - thePath << "\t: Cannot read any relevant data from the IGES file"; - resetStatic(); - return false; - } - theShape = aReader.OneShape(); - resetStatic(); - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool IGESCAFControl_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - (void)theProgress; - if (!GetNode()->IsKind(STANDARD_TYPE(IGESCAFControl_ConfigurationNode))) - { - Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode()); - initStatic(aNode); - Standard_Integer aFlag = IGESData_BasicEditor::GetFlagByValue(aNode->GlobalParameters.LengthUnit); - IGESControl_Writer aWriter((aFlag > 0) ? IGESData_BasicEditor::UnitFlagName(aFlag) : "MM", - aNode->InternalParameters.WriteBRepMode); - IGESData_GlobalSection aGS = aWriter.Model()->GlobalSection(); - aGS.SetCascadeUnit(aNode->GlobalParameters.SystemUnit); - if (!aFlag) - { - aGS.SetScale(aNode->GlobalParameters.LengthUnit); - } - aWriter.Model()->SetGlobalSection(aGS); - Standard_Boolean aIsOk = aWriter.AddShape(theShape); - if (!aIsOk) - { - Message::SendFail() << "IGESCAFControl_Provider: Shape not written"; - resetStatic(); - return false; - } - - if (!(aWriter.Write(thePath.ToCString()))) - { - Message::SendFail() << "IGESCAFControl_Provider: Error on writing file " << thePath; - resetStatic(); - return false; - } - resetStatic(); - return true; -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool IGESCAFControl_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); - return Read(thePath, theShape, aWS, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool IGESCAFControl_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); - return Write(thePath, theShape, aWS, theProgress); -} - -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString IGESCAFControl_Provider::GetFormat() const -{ - return TCollection_AsciiString("IGES"); -} - -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString IGESCAFControl_Provider::GetVendor() const -{ - return TCollection_AsciiString("OCC"); -} diff --git a/src/IGESCAFControl/IGESCAFControl_Provider.hxx b/src/IGESCAFControl/IGESCAFControl_Provider.hxx index b483064333..f7991c4c26 100644 --- a/src/IGESCAFControl/IGESCAFControl_Provider.hxx +++ b/src/IGESCAFControl/IGESCAFControl_Provider.hxx @@ -14,144 +14,9 @@ #ifndef _IGESCAFControl_Provider_HeaderFile #define _IGESCAFControl_Provider_HeaderFile -#include -#include +#include -//! The class to transfer IGES files. -//! Reads and Writes any IGES files into/from OCCT. -//! Each operation needs configuration node. -//! -//! Providers grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "IGES" -//! The import process is supported. -//! The export process is supported. -class IGESCAFControl_Provider : public DE_Provider -{ -public: - DEFINE_STANDARD_RTTIEXT(IGESCAFControl_Provider, DE_Provider) - -public: - - //! Default constructor - //! Configure translation process with global configuration - Standard_EXPORT IGESCAFControl_Provider(); - - //! Configure translation process - //! @param[in] theNode object to copy - Standard_EXPORT IGESCAFControl_Provider(const Handle(DE_ConfigurationNode)& theNode); - -public: - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - -public: - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; - -private: - - //! Personizes work session with current format. - //! Creates new temporary session if current session is null - //! @param[in] theWS current work session - void personizeWS(Handle(XSControl_WorkSession)& theWS); - - //! Initialize static variables - void initStatic(const Handle(DE_ConfigurationNode)& theNode); - - //! Initialize static variables - void setStatic(const IGESCAFControl_ConfigurationNode::IGESCAFControl_InternalSection& theParameter); - - //! Reset used interface static variables - void resetStatic(); - - IGESCAFControl_ConfigurationNode::IGESCAFControl_InternalSection myOldValues; - int myOldLengthUnit = 1; - -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DEIGES_Provider IGESCAFControl_Provider; #endif // _IGESCAFControl_Provider_HeaderFile diff --git a/src/RWGltf/FILES b/src/RWGltf/FILES index fc24654adf..dda31cfa12 100644 --- a/src/RWGltf/FILES +++ b/src/RWGltf/FILES @@ -2,7 +2,6 @@ RWGltf_CafReader.cxx RWGltf_CafReader.hxx RWGltf_CafWriter.cxx RWGltf_CafWriter.hxx -RWGltf_ConfigurationNode.cxx RWGltf_ConfigurationNode.hxx RWGltf_DracoParameters.hxx RWGltf_GltfAccessor.hxx @@ -26,7 +25,6 @@ RWGltf_GltfRootElement.hxx RWGltf_GltfSceneNodeMap.hxx RWGltf_MaterialCommon.hxx RWGltf_MaterialMetallicRoughness.hxx -RWGltf_Provider.cxx RWGltf_Provider.hxx RWGltf_TriangulationReader.cxx RWGltf_TriangulationReader.hxx diff --git a/src/RWGltf/RWGltf_ConfigurationNode.hxx b/src/RWGltf/RWGltf_ConfigurationNode.hxx index 0faa3c6930..44f902b5ba 100644 --- a/src/RWGltf/RWGltf_ConfigurationNode.hxx +++ b/src/RWGltf/RWGltf_ConfigurationNode.hxx @@ -14,106 +14,9 @@ #ifndef _RWGltf_ConfigurationNode_HeaderFile #define _RWGltf_ConfigurationNode_HeaderFile -#include -#include -#include -#include +#include -//! The purpose of this class is to configure the transfer process for glTF format -//! Stores the necessary settings for RWGltf_Provider. -//! Configures and creates special provider to transfer glTF files. -//! -//! Nodes grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "GLTF" -//! The supported CAD extensions are ".gltf", ".glb" -//! The import process is supported. -//! The export process is supported. -class RWGltf_ConfigurationNode : public DE_ConfigurationNode -{ - DEFINE_STANDARD_RTTIEXT(RWGltf_ConfigurationNode, DE_ConfigurationNode) -public: - - //! Initializes all field by default - Standard_EXPORT RWGltf_ConfigurationNode(); - - //! Copies values of all fields - //! @param[in] theNode object to copy - Standard_EXPORT RWGltf_ConfigurationNode(const Handle(RWGltf_ConfigurationNode)& theNode); - - //! Updates values according the resource - //! @param[in] theResource input resource to use - //! @return true if theResource loading has ended correctly - Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) Standard_OVERRIDE; - - //! Writes configuration to the string - //! @return result resource string - Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; - - //! Copies values of all fields - //! @return new object with the same field values - Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; - - //! Creates new provider for the own format - //! @return new created provider - Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; - -public: - - //! Checks the import supporting - //! @return true if import is supported - Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; - - //! Checks the export supporting - //! @return true if export is supported - Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; - - //! Gets list of supported file extensions - //! @return list of extensions - Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; - -public: - struct RWGltf_InternalSection - { - // Common -// clang-format off - double FileLengthUnit = 1.; //!< File length units to convert from while reading the file, defined as scale factor for m (meters) - RWMesh_CoordinateSystem SystemCS = RWMesh_CoordinateSystem_Zup; //!< System origin coordinate system to perform conversion into during read - RWMesh_CoordinateSystem FileCS = RWMesh_CoordinateSystem_Yup; //!< File origin coordinate system to perform conversion during read - // Reading - bool ReadSinglePrecision = true; //!< Flag for reading vertex data with single or double floating point precision - bool ReadCreateShapes = false; //!< Flag for create a single triangulation - TCollection_AsciiString ReadRootPrefix; //!< Root folder for generating root labels names - bool ReadFillDoc = true; //!< Flag for fill document from shape sequence - bool ReadFillIncomplete = true; //!< Flag for fill the document with partially retrieved data even if reader has failed with error - int ReadMemoryLimitMiB = -1; //!< Memory usage limit - bool ReadParallel = false; //!< Flag to use multithreading - bool ReadSkipEmptyNodes = true; //!< Flag to ignore nodes without Geometry - bool ReadLoadAllScenes = false; //!< Flag to load all scenes in the document - bool ReadUseMeshNameAsFallback = true; //!< Flag to use Mesh name in case if Node name is empty - bool ReadSkipLateDataLoading = false; //!< Flag to skip triangulation loading - bool ReadKeepLateData = true;//!< Flag to keep information about deferred storage to load/unload triangulation later - bool ReadPrintDebugMessages = false; //!< Flag to print additional debug information - // Writing - TCollection_AsciiString WriteComment; //!< Export special comment - TCollection_AsciiString WriteAuthor; //!< Author of exported file name - RWGltf_WriterTrsfFormat WriteTrsfFormat = RWGltf_WriterTrsfFormat_Compact; //!< Transformation format to write into glTF file - RWMesh_NameFormat WriteNodeNameFormat = RWMesh_NameFormat_InstanceOrProduct; //!< Name format for exporting Nodes - RWMesh_NameFormat WriteMeshNameFormat = RWMesh_NameFormat_Product; //!< Name format for exporting Meshes - bool WriteForcedUVExport = false; //!< Export UV coordinates even if there are no mapped texture - bool WriteEmbedTexturesInGlb = true; //!< Flag to write image textures into GLB file - bool WriteMergeFaces = false; //!< Flag to merge faces within a single part - bool WriteSplitIndices16 = false; //!< Flag to prefer keeping 16-bit indexes while merging face -// clang-format on - } InternalParameters; -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DEGLTF_ConfigurationNode RWGltf_ConfigurationNode; #endif // _RWGltf_ConfigurationNode_HeaderFile diff --git a/src/RWGltf/RWGltf_Provider.cxx b/src/RWGltf/RWGltf_Provider.cxx deleted file mode 100644 index 77c527d53c..0000000000 --- a/src/RWGltf/RWGltf_Provider.cxx +++ /dev/null @@ -1,269 +0,0 @@ -// Copyright (c) 2022 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include -#include - -namespace -{ - //======================================================================= - // function : SetReaderParameters - // purpose : - //======================================================================= - static void SetReaderParameters(RWGltf_CafReader& theReader, const Handle(RWGltf_ConfigurationNode)& theNode) - { - theReader.SetDoublePrecision(!theNode->InternalParameters.ReadSinglePrecision); - theReader.SetSystemLengthUnit(theNode->GlobalParameters.LengthUnit / 1000); - theReader.SetSystemCoordinateSystem(theNode->InternalParameters.SystemCS); - theReader.SetFileLengthUnit(theNode->InternalParameters.FileLengthUnit); - theReader.SetFileCoordinateSystem(theNode->InternalParameters.FileCS); - theReader.SetRootPrefix(theNode->InternalParameters.ReadRootPrefix); - theReader.SetMemoryLimitMiB(theNode->InternalParameters.ReadMemoryLimitMiB); - - theReader.SetParallel(theNode->InternalParameters.ReadParallel); - theReader.SetSkipEmptyNodes(theNode->InternalParameters.ReadSkipEmptyNodes); - theReader.SetLoadAllScenes(theNode->InternalParameters.ReadLoadAllScenes); - theReader.SetMeshNameAsFallback(theNode->InternalParameters.ReadUseMeshNameAsFallback); - theReader.SetToSkipLateDataLoading(theNode->InternalParameters.ReadSkipLateDataLoading); - theReader.SetToKeepLateData(theNode->InternalParameters.ReadKeepLateData); - theReader.SetToPrintDebugMessages(theNode->InternalParameters.ReadPrintDebugMessages); - } -} - -IMPLEMENT_STANDARD_RTTIEXT(RWGltf_Provider, DE_Provider) - -//======================================================================= -// function : RWGltf_Provider -// purpose : -//======================================================================= -RWGltf_Provider::RWGltf_Provider() -{} - -//======================================================================= -// function : RWGltf_Provider -// purpose : -//======================================================================= -RWGltf_Provider::RWGltf_Provider(const Handle(DE_ConfigurationNode)& theNode) - :DE_Provider(theNode) -{} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool RWGltf_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Read(thePath, theDocument, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWGltf_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Write(thePath, theDocument, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool RWGltf_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - if (theDocument.IsNull()) - { - Message::SendFail() << "Error in the RWGltf_Provider during reading the file " << - thePath << "\t: theDocument shouldn't be null"; - return false; - } - if (GetNode().IsNull() || (!GetNode().IsNull() && !GetNode()->IsKind(STANDARD_TYPE(RWGltf_ConfigurationNode)))) - { - Message::SendFail() << "Error in the RWGltf_Provider during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(RWGltf_ConfigurationNode) aNode = Handle(RWGltf_ConfigurationNode)::DownCast(GetNode()); - RWGltf_CafReader aReader; - aReader.SetDocument(theDocument); - SetReaderParameters(aReader, aNode); - XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter); - if (!aReader.Perform(thePath, theProgress)) - { - Message::SendFail() << "Error in the RWGltf_Provider during reading the file " << thePath; - return false; - } - - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWGltf_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(RWGltf_ConfigurationNode))) - { - Message::SendFail() << "Error in the RWGltf_Provider during writing the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(RWGltf_ConfigurationNode) aNode = Handle(RWGltf_ConfigurationNode)::DownCast(GetNode()); - - RWMesh_CoordinateSystemConverter aConverter; - Standard_Real aScaleFactorM = 1.; - if (!XCAFDoc_DocumentTool::GetLengthUnit(theDocument, aScaleFactorM)) - { - aConverter.SetInputLengthUnit(aNode->GlobalParameters.SystemUnit / 1000.); - Message::SendWarning() << "Warning in the RWGltf_Provider during writing the file " << - thePath << "\t: The document has no information on Units. Using global parameter as initial Unit."; - } - aConverter.SetInputCoordinateSystem(aNode->InternalParameters.SystemCS); - if (aNode->GlobalParameters.LengthUnit != 1000.) - { - Message::SendWarning() << "Warning in the RWGltf_Provider during writing the file " << - thePath << "\t: Target format doesn't support custom units. Model will be scaled to Meters"; - } - aConverter.SetOutputLengthUnit(1.); // gltf units always Meters - aConverter.SetOutputCoordinateSystem(aNode->InternalParameters.FileCS); - - TColStd_IndexedDataMapOfStringString aFileInfo; - if (!aNode->InternalParameters.WriteAuthor.IsEmpty()) - { - aFileInfo.Add("Author", aNode->InternalParameters.WriteAuthor); - } - if (!aNode->InternalParameters.WriteComment.IsEmpty()) - { - aFileInfo.Add("Comments", aNode->InternalParameters.WriteComment); - } - - TCollection_AsciiString anExt = thePath; - anExt.LowerCase(); - RWGltf_CafWriter aWriter(thePath, anExt.EndsWith(".glb")); - aWriter.SetCoordinateSystemConverter(aConverter); - aWriter.SetTransformationFormat(aNode->InternalParameters.WriteTrsfFormat); - aWriter.SetNodeNameFormat(aNode->InternalParameters.WriteNodeNameFormat); - aWriter.SetMeshNameFormat(aNode->InternalParameters.WriteMeshNameFormat); - aWriter.SetForcedUVExport(aNode->InternalParameters.WriteForcedUVExport); - aWriter.SetToEmbedTexturesInGlb(aNode->InternalParameters.WriteEmbedTexturesInGlb); - aWriter.SetMergeFaces(aNode->InternalParameters.WriteMergeFaces); - aWriter.SetSplitIndices16(aNode->InternalParameters.WriteSplitIndices16); - if (!aWriter.Perform(theDocument, aFileInfo, theProgress)) - { - Message::SendFail() << "Error in the RWGltf_Provider during writing the file " << thePath; - return false; - } - return true; -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool RWGltf_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Read(thePath, theShape, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWGltf_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Write(thePath, theShape, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool RWGltf_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(RWGltf_ConfigurationNode))) - { - Message::SendFail() << "Error in the RWGltf_Provider during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(RWGltf_ConfigurationNode) aNode = Handle(RWGltf_ConfigurationNode)::DownCast(GetNode()); - RWGltf_CafReader aReader; - SetReaderParameters(aReader, aNode); - if (!aReader.Perform(thePath, theProgress)) - { - Message::SendFail() << "Error in the RWGltf_Provider during reading the file " << thePath; - return false; - } - theShape = aReader.SingleShape(); - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWGltf_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF"); - Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main()); - aShTool->AddShape(theShape); - return Write(thePath, aDoc, theProgress); -} - -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString RWGltf_Provider::GetFormat() const -{ - return TCollection_AsciiString("GLTF"); -} - -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString RWGltf_Provider::GetVendor() const -{ - return TCollection_AsciiString("OCC"); -} diff --git a/src/RWGltf/RWGltf_Provider.hxx b/src/RWGltf/RWGltf_Provider.hxx index 10c8e53b72..04d74d35ac 100644 --- a/src/RWGltf/RWGltf_Provider.hxx +++ b/src/RWGltf/RWGltf_Provider.hxx @@ -14,126 +14,9 @@ #ifndef _RWGltf_Provider_HeaderFile #define _RWGltf_Provider_HeaderFile -#include -#include -#include +#include -//! The class to transfer glTF files. -//! Reads and Writes any glTF files into/from OCCT. -//! Each operation needs configuration node. -//! -//! Providers grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "GLTF" -//! The import process is supported. -//! The export process is supported. -class RWGltf_Provider : public DE_Provider -{ -public: - DEFINE_STANDARD_RTTIEXT(RWGltf_Provider, DE_Provider) - -public: - - //! Default constructor - //! Configure translation process with global configuration - Standard_EXPORT RWGltf_Provider(); - - //! Configure translation process - //! @param[in] theNode object to copy - Standard_EXPORT RWGltf_Provider(const Handle(DE_ConfigurationNode)& theNode); - -public: - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - -public: - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; - -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DEGLTF_Provider RWGltf_Provider; #endif // _RWGltf_Provider_HeaderFile diff --git a/src/RWObj/FILES b/src/RWObj/FILES index 9d6ca70c83..ec7301bbf4 100644 --- a/src/RWObj/FILES +++ b/src/RWObj/FILES @@ -4,7 +4,6 @@ RWObj_CafReader.cxx RWObj_CafReader.hxx RWObj_CafWriter.cxx RWObj_CafWriter.hxx -RWObj_ConfigurationNode.cxx RWObj_ConfigurationNode.hxx RWObj_Material.hxx RWObj_MtlReader.cxx @@ -13,7 +12,6 @@ RWObj_ObjMaterialMap.cxx RWObj_ObjMaterialMap.hxx RWObj_ObjWriterContext.cxx RWObj_ObjWriterContext.hxx -RWObj_Provider.cxx RWObj_Provider.hxx RWObj_Reader.cxx RWObj_Reader.hxx diff --git a/src/RWObj/RWObj_ConfigurationNode.hxx b/src/RWObj/RWObj_ConfigurationNode.hxx index 41d7625213..04e5bcda42 100644 --- a/src/RWObj/RWObj_ConfigurationNode.hxx +++ b/src/RWObj/RWObj_ConfigurationNode.hxx @@ -14,90 +14,9 @@ #ifndef _RWObj_ConfigurationNode_HeaderFile #define _RWObj_ConfigurationNode_HeaderFile -#include -#include +#include -//! The purpose of this class is to configure the transfer process for OBJ format -//! Stores the necessary settings for RWObj_Provider. -//! Configures and creates special provider to transfer OBJ files. -//! -//! Nodes grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "OBJ" -//! The supported CAD extension is ".obj" -//! The import process is supported. -//! The export process is supported. -class RWObj_ConfigurationNode : public DE_ConfigurationNode -{ - DEFINE_STANDARD_RTTIEXT(RWObj_ConfigurationNode, DE_ConfigurationNode) -public: - - //! Initializes all field by default - Standard_EXPORT RWObj_ConfigurationNode(); - - //! Copies values of all fields - //! @param[in] theNode object to copy - Standard_EXPORT RWObj_ConfigurationNode(const Handle(RWObj_ConfigurationNode)& theNode); - - //! Updates values according the resource - //! @param[in] theResource input resource to use - //! @return true if theResource loading has ended correctly - Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) Standard_OVERRIDE; - - //! Writes configuration to the string - //! @return result resource string - Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; - - //! Copies values of all fields - //! @return new object with the same field values - Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; - - //! Creates new provider for the own format - //! @return new created provider - Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; - -public: - - //! Checks the import supporting - //! @return true if import is supported - Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; - - //! Checks the export supporting - //! @return true if export is supported - Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; - - //! Gets list of supported file extensions - //! @return list of extensions - Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; - -public: - struct RWObj_InternalSection - { - // Common -// clang-format off - double FileLengthUnit = 1.; //!< File length units to convert from while reading the file, defined as scale factor for m (meters) - RWMesh_CoordinateSystem SystemCS = RWMesh_CoordinateSystem_Zup; //!< System origin coordinate system to perform conversion into during read - RWMesh_CoordinateSystem FileCS = RWMesh_CoordinateSystem_Yup; //!< File origin coordinate system to perform conversion during read - // Reading - bool ReadSinglePrecision = false; //!< Flag for reading vertex data with single or double floating point precision - bool ReadCreateShapes = false; //!< Flag for create a single triangulation - TCollection_AsciiString ReadRootPrefix; //!< Root folder for generating root labels names - bool ReadFillDoc = true; //!< Flag for fill document from shape sequence - bool ReadFillIncomplete = true; //!< Flag for fill the document with partially retrieved data even if reader has failed with error -// clang-format on - int ReadMemoryLimitMiB = -1; //!< Memory usage limit - // Writing - TCollection_AsciiString WriteComment; //!< Export special comment - TCollection_AsciiString WriteAuthor; //!< Author of exported file name - } InternalParameters; -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DEOBJ_ConfigurationNode RWObj_ConfigurationNode; #endif // _RWObj_ConfigurationNode_HeaderFile diff --git a/src/RWObj/RWObj_Provider.hxx b/src/RWObj/RWObj_Provider.hxx index 1b19b12a7c..f93cd2736d 100644 --- a/src/RWObj/RWObj_Provider.hxx +++ b/src/RWObj/RWObj_Provider.hxx @@ -14,123 +14,9 @@ #ifndef _RWObj_Provider_HeaderFile #define _RWObj_Provider_HeaderFile -#include +#include -//! The class to transfer OBJ files. -//! Reads and Writes any OBJ files into/from OCCT. -//! Each operation needs configuration node. -//! -//! Providers grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "OBJ" -//! The import process is supported. -//! The export process is supported. -class RWObj_Provider : public DE_Provider -{ -public: - DEFINE_STANDARD_RTTIEXT(RWObj_Provider, DE_Provider) - -public: - - //! Default constructor - //! Configure translation process with global configuration - Standard_EXPORT RWObj_Provider(); - - //! Configure translation process - //! @param[in] theNode object to copy - Standard_EXPORT RWObj_Provider(const Handle(DE_ConfigurationNode)& theNode); - -public: - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - -public: - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DEOBJ_Provider RWObj_Provider; #endif // _RWObj_Provider_HeaderFile diff --git a/src/RWPly/FILES b/src/RWPly/FILES index 032af79a92..fe3176ef01 100644 --- a/src/RWPly/FILES +++ b/src/RWPly/FILES @@ -1,8 +1,6 @@ RWPly_CafWriter.cxx RWPly_CafWriter.hxx -RWPly_ConfigurationNode.cxx RWPly_ConfigurationNode.hxx RWPly_PlyWriterContext.cxx RWPly_PlyWriterContext.hxx -RWPly_Provider.cxx RWPly_Provider.hxx diff --git a/src/RWPly/RWPly_ConfigurationNode.hxx b/src/RWPly/RWPly_ConfigurationNode.hxx index b26702680f..1bd3314553 100644 --- a/src/RWPly/RWPly_ConfigurationNode.hxx +++ b/src/RWPly/RWPly_ConfigurationNode.hxx @@ -14,96 +14,9 @@ #ifndef _RWPly_ConfigurationNode_HeaderFile #define _RWPly_ConfigurationNode_HeaderFile -#include -#include -#include +#include -class DE_ConfigurationContext; - -//! The purpose of this class is to configure the transfer process for PLY format -//! Stores the necessary settings for RWPly_Provider. -//! Configures and creates special provider to transfer PLY files. -//! -//! Nodes grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "PLY" -//! The supported CAD extension is ".ply" -//! The import process isn't supported. -//! The export process is supported. -class RWPly_ConfigurationNode : public DE_ConfigurationNode -{ - DEFINE_STANDARD_RTTIEXT(RWPly_ConfigurationNode, DE_ConfigurationNode) -public: - - //! Initializes all field by default - Standard_EXPORT RWPly_ConfigurationNode(); - - //! Copies values of all fields - //! @param[in] theNode object to copy - Standard_EXPORT RWPly_ConfigurationNode(const Handle(RWPly_ConfigurationNode)& theNode); - - //! Updates values according the resource - //! @param[in] theResource input resource to use - //! @return true if theResource loading has ended correctly - Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) Standard_OVERRIDE; - - //! Writes configuration to the string - //! @return result resource string - Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; - - //! Copies values of all fields - //! @return new object with the same field values - Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; - - //! Creates new provider for the own format - //! @return new created provider - Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; - -public: - - //! Checks the import supporting - //! @return true if import is supported - Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; - - //! Checks the export supporting - //! @return true if export is supported - Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; - - //! Gets list of supported file extensions - //! @return list of extensions - Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; - - //! Checks the file content to verify a format - //! @param[in] theBuffer read stream buffer to check content - //! @return Standard_True if file is supported by a current provider - Standard_EXPORT virtual bool CheckContent(const Handle(NCollection_Buffer)& theBuffer) const Standard_OVERRIDE; - -public: - struct RWPly_InternalSection - { - // Common -// clang-format off - double FileLengthUnit = 1.; //!< File length units to convert from while reading the file, defined as scale factor for m (meters) - RWMesh_CoordinateSystem SystemCS = RWMesh_CoordinateSystem_Zup; //!< System origin coordinate system to perform conversion into during read - RWMesh_CoordinateSystem FileCS = RWMesh_CoordinateSystem_Yup; //!< File origin coordinate system to perform conversion during read - // Writing - bool WriteNormals = true; //!< Flag for write normals - bool WriteColors = true; //!< Flag for write colors - bool WriteTexCoords = false; //!< Flag for write UV / texture coordinates - bool WritePartId = true; //!< Flag for write part Id as element attribute - bool WriteFaceId = false; //!< Flag for write face Id as element attribute. Cannot be combined with HasPartId -// clang-format on - TCollection_AsciiString WriteComment; //!< Export special comment - TCollection_AsciiString WriteAuthor; //!< Author of exported file name - } InternalParameters; -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DEPLY_ConfigurationNode RWPly_ConfigurationNode; #endif // _RWPly_ConfigurationNode_HeaderFile diff --git a/src/RWPly/RWPly_Provider.hxx b/src/RWPly/RWPly_Provider.hxx index c5765a8197..8326cc7deb 100644 --- a/src/RWPly/RWPly_Provider.hxx +++ b/src/RWPly/RWPly_Provider.hxx @@ -14,83 +14,9 @@ #ifndef _RWPly_Provider_HeaderFile #define _RWPly_Provider_HeaderFile -#include +#include -//! The class to transfer PLY files. -//! Writes any PLY files from OCCT. -//! Each operation needs configuration node. -//! -//! Providers grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "PLY" -//! The import process isn't supported. -//! The export process is supported. -class RWPly_Provider : public DE_Provider -{ -public: - DEFINE_STANDARD_RTTIEXT(RWPly_Provider, DE_Provider) - -public: - - //! Default constructor - //! Configure translation process with global configuration - Standard_EXPORT RWPly_Provider(); - - //! Configure translation process - //! @param[in] theNode object to copy - Standard_EXPORT RWPly_Provider(const Handle(DE_ConfigurationNode)& theNode); - -public: - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - -public: - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DEPLY_Provider RWPly_Provider; #endif // _RWPly_Provider_HeaderFile diff --git a/src/RWStl/FILES b/src/RWStl/FILES index 5f5d999434..0740d81abd 100644 --- a/src/RWStl/FILES +++ b/src/RWStl/FILES @@ -2,7 +2,5 @@ RWStl.cxx RWStl.hxx RWStl_Reader.cxx RWStl_Reader.hxx -RWStl_ConfigurationNode.cxx RWStl_ConfigurationNode.hxx -RWStl_Provider.cxx RWStl_Provider.hxx diff --git a/src/RWStl/RWStl_ConfigurationNode.hxx b/src/RWStl/RWStl_ConfigurationNode.hxx index b1e33d7ee2..8e48fa0da5 100644 --- a/src/RWStl/RWStl_ConfigurationNode.hxx +++ b/src/RWStl/RWStl_ConfigurationNode.hxx @@ -14,86 +14,9 @@ #ifndef _RWStl_ConfigurationNode_HeaderFile #define _RWStl_ConfigurationNode_HeaderFile -#include +#include -//! The purpose of this class is to configure the transfer process for STL format -//! Stores the necessary settings for RWStl_Provider. -//! Configures and creates special provider to transfer STL files. -//! -//! Nodes grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "STL" -//! The supported CAD extension is ".stl" -//! The import process is supported. -//! The export process is supported. -class RWStl_ConfigurationNode : public DE_ConfigurationNode -{ - DEFINE_STANDARD_RTTIEXT(RWStl_ConfigurationNode, DE_ConfigurationNode) -public: - - //! Initializes all field by default - Standard_EXPORT RWStl_ConfigurationNode(); - - //! Copies values of all fields - //! @param[in] theNode object to copy - Standard_EXPORT RWStl_ConfigurationNode(const Handle(RWStl_ConfigurationNode)& theNode); - - //! Updates values according the resource - //! @param[in] theResource input resource to use - //! @return true if theResource loading has ended correctly - Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) Standard_OVERRIDE; - - //! Writes configuration to the string - //! @return result resource string - Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; - - //! Copies values of all fields - //! @return new object with the same field values - Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; - - - //! Creates new provider for the own format - //! @return new created provider - Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; - -public: - - //! Checks the import supporting - //! @return true if import is supported - Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; - - //! Checks the export supporting - //! @return true if export is supported - Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; - - //! Gets list of supported file extensions - //! @return list of extensions - Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; - - //! Checks the file content to verify a format - //! @param[in] theBuffer read stream buffer to check content - //! @return Standard_True if file is supported by a current provider - Standard_EXPORT virtual bool CheckContent(const Handle(NCollection_Buffer)& theBuffer) const Standard_OVERRIDE; - -public: - struct RWStl_InternalSection - { - // Read - double ReadMergeAngle = 90.; //!< Input merge angle value - bool ReadBRep = false; //!< Setting up Boundary Representation flag - - // Write - bool WriteAscii = true; //!< Setting up writing mode (Ascii or Binary) - - } InternalParameters; -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DESTL_ConfigurationNode RWStl_ConfigurationNode; #endif // _RWStl_ConfigurationNode_HeaderFile diff --git a/src/RWStl/RWStl_Provider.cxx b/src/RWStl/RWStl_Provider.cxx deleted file mode 100644 index 8fa8dd281e..0000000000 --- a/src/RWStl/RWStl_Provider.cxx +++ /dev/null @@ -1,262 +0,0 @@ -// Copyright (c) 2022 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -IMPLEMENT_STANDARD_RTTIEXT(RWStl_Provider, DE_Provider) - -//======================================================================= -// function : RWStl_Provider -// purpose : -//======================================================================= -RWStl_Provider::RWStl_Provider() -{} - -//======================================================================= -// function : RWStl_Provider -// purpose : -//======================================================================= -RWStl_Provider::RWStl_Provider(const Handle(DE_ConfigurationNode)& theNode) - :DE_Provider(theNode) -{} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool RWStl_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Read(thePath, theDocument, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWStl_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Write(thePath, theDocument, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool RWStl_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - if (theDocument.IsNull()) - { - Message::SendFail() << "Error in the RWStl_Provider during reading the file " << - thePath << "\t: theDocument shouldn't be null"; - return false; - } - TopoDS_Shape aShape; - if (!Read(thePath, aShape, theProgress)) - { - return false; - } - Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); - aShapeTool->AddShape(aShape); - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWStl_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - TopoDS_Shape aShape; - TDF_LabelSequence aLabels; - Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); - aSTool->GetFreeShapes(aLabels); - if (aLabels.Length() <= 0) - { - Message::SendFail() << "Error in the RWStl_Provider during writing the file " << - thePath << "\t: Document contain no shapes"; - return false; - } - - Handle(RWStl_ConfigurationNode) aNode = Handle(RWStl_ConfigurationNode)::DownCast(GetNode()); - if (aNode->GlobalParameters.LengthUnit != 1.0) - { - Message::SendWarning() << "Warning in the RWStl_Provider during writing the file " << - thePath << "\t: Target Units for writing were changed, but current format doesn't support scaling"; - } - - if (aLabels.Length() == 1) - { - aShape = aSTool->GetShape(aLabels.Value(1)); - } - else - { - TopoDS_Compound aComp; - BRep_Builder aBuilder; - aBuilder.MakeCompound(aComp); - for (Standard_Integer anIndex = 1; anIndex <= aLabels.Length(); anIndex++) - { - TopoDS_Shape aS = aSTool->GetShape(aLabels.Value(anIndex)); - aBuilder.Add(aComp, aS); - } - aShape = aComp; - } - return Write(thePath, aShape, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool RWStl_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Read(thePath, theShape, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWStl_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Write(thePath, theShape, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool RWStl_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - Message::SendWarning() << "OCCT Stl reader does not support model scaling according to custom length unit"; - if (!GetNode()->IsKind(STANDARD_TYPE(RWStl_ConfigurationNode))) - { - Message::SendFail() << "Error in the RWStl_Provider during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return true; - } - Handle(RWStl_ConfigurationNode) aNode = Handle(RWStl_ConfigurationNode)::DownCast(GetNode()); - double aMergeAngle = aNode->InternalParameters.ReadMergeAngle * M_PI / 180.0; - if(aMergeAngle != M_PI_2) - { - if (aMergeAngle < 0.0 || aMergeAngle > M_PI_2) - { - Message::SendFail() << "Error in the RWStl_Provider during reading the file " << - thePath << "\t: The merge angle is out of the valid range"; - return false; - } - } - if (!aNode->InternalParameters.ReadBRep) - { - Handle(Poly_Triangulation) aTriangulation = RWStl::ReadFile(thePath.ToCString(), aMergeAngle, theProgress); - - TopoDS_Face aFace; - BRep_Builder aB; - aB.MakeFace(aFace); - aB.UpdateFace(aFace, aTriangulation); - theShape = aFace; - } - else - { - Standard_DISABLE_DEPRECATION_WARNINGS - if (!StlAPI::Read(theShape, thePath.ToCString())) - { - Message::SendFail() << "Error in the RWStl_Provider during reading the file " << thePath; - return false; - } - Standard_ENABLE_DEPRECATION_WARNINGS - } - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool RWStl_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - Message::SendWarning() << "OCCT Stl writer does not support model scaling according to custom length unit"; - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(RWStl_ConfigurationNode))) - { - Message::SendFail() << "Error in the RWStl_Provider during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(RWStl_ConfigurationNode) aNode = Handle(RWStl_ConfigurationNode)::DownCast(GetNode()); - if (aNode->GlobalParameters.LengthUnit != 1.0) - { - Message::SendWarning() << "Warning in the RWStl_Provider during writing the file " << - thePath << "\t: Target Units for writing were changed, but current format doesn't support scaling"; - } - - StlAPI_Writer aWriter; - aWriter.ASCIIMode() = aNode->InternalParameters.WriteAscii; - if (!aWriter.Write(theShape, thePath.ToCString(), theProgress)) - { - Message::SendFail() << "Error in the RWStl_Provider during reading the file " << - thePath << "\t: Mesh writing has been failed"; - return false; - } - return true; -} - -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString RWStl_Provider::GetFormat() const -{ - return TCollection_AsciiString("STL"); -} - -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString RWStl_Provider::GetVendor() const -{ - return TCollection_AsciiString("OCC"); -} diff --git a/src/RWStl/RWStl_Provider.hxx b/src/RWStl/RWStl_Provider.hxx index 971f7da247..f34478803a 100644 --- a/src/RWStl/RWStl_Provider.hxx +++ b/src/RWStl/RWStl_Provider.hxx @@ -14,123 +14,9 @@ #ifndef _RWStl_Provider_HeaderFile #define _RWStl_Provider_HeaderFile -#include +#include -//! The class to transfer STL files. -//! Reads and Writes any STL files into/from OCCT. -//! Each operation needs configuration node. -//! -//! Providers grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "STL" -//! The import process is supported. -//! The export process is supported. -class RWStl_Provider : public DE_Provider -{ -public: - DEFINE_STANDARD_RTTIEXT(RWStl_Provider, DE_Provider) - -public: - - //! Default constructor - //! Configure translation process with global configuration - Standard_EXPORT RWStl_Provider(); - - //! Configure translation process - //! @param[in] theNode object to copy - Standard_EXPORT RWStl_Provider(const Handle(DE_ConfigurationNode)& theNode); - -public: - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual Standard_Boolean Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual Standard_Boolean Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual Standard_Boolean Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual Standard_Boolean Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual Standard_Boolean Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual Standard_Boolean Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual Standard_Boolean Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual Standard_Boolean Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - -public: - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DESTL_Provider RWStl_Provider; #endif // _RWStl_Provider_HeaderFile diff --git a/src/STEPCAFControl/FILES b/src/STEPCAFControl/FILES index 350216d38f..9efc5d0fab 100644 --- a/src/STEPCAFControl/FILES +++ b/src/STEPCAFControl/FILES @@ -1,6 +1,5 @@ STEPCAFControl_ActorWrite.cxx STEPCAFControl_ActorWrite.hxx -STEPCAFControl_ConfigurationNode.cxx STEPCAFControl_ConfigurationNode.hxx STEPCAFControl_Controller.cxx STEPCAFControl_Controller.hxx @@ -21,7 +20,6 @@ STEPCAFControl_ExternFile.hxx STEPCAFControl_ExternFile.lxx STEPCAFControl_GDTProperty.hxx STEPCAFControl_GDTProperty.cxx -STEPCAFControl_Provider.cxx STEPCAFControl_Provider.hxx STEPCAFControl_Reader.cxx STEPCAFControl_Reader.hxx diff --git a/src/STEPCAFControl/STEPCAFControl_ConfigurationNode.hxx b/src/STEPCAFControl/STEPCAFControl_ConfigurationNode.hxx index 0611154dbd..57f13fefca 100644 --- a/src/STEPCAFControl/STEPCAFControl_ConfigurationNode.hxx +++ b/src/STEPCAFControl/STEPCAFControl_ConfigurationNode.hxx @@ -14,82 +14,9 @@ #ifndef _STEPCAFControl_ConfigurationNode_HeaderFile #define _STEPCAFControl_ConfigurationNode_HeaderFile -#include -#include -#include -#include -#include +#include -//! The purpose of this class is to configure the transfer process for STEP format -//! Stores the necessary settings for STEPCAFControl_Provider. -//! Configures and creates special provider to transfer STEP files. -//! -//! Nodes grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "STEP" -//! The supported CAD extensions are ".stp", ".step", ".stpz" -//! The import process is supported. -//! The export process is supported. -class STEPCAFControl_ConfigurationNode : public DE_ConfigurationNode -{ - DEFINE_STANDARD_RTTIEXT(STEPCAFControl_ConfigurationNode, DE_ConfigurationNode) -public: - - //! Initializes all field by default - Standard_EXPORT STEPCAFControl_ConfigurationNode(); - - //! Copies values of all fields - //! @param[in] theNode object to copy - Standard_EXPORT STEPCAFControl_ConfigurationNode(const Handle(STEPCAFControl_ConfigurationNode)& theNode); - - //! Updates values according the resource - //! @param[in] theResource input resource to use - //! @return true if theResource loading has ended correctly - Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) Standard_OVERRIDE; - - //! Writes configuration to the string - //! @return result resource string - Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; - - //! Copies values of all fields - //! @return new object with the same field values - Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; - - - //! Creates new provider for the own format - //! @return new created provider - Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; - -public: - - //! Checks the import supporting - //! @return true if import is supported - Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; - - //! Checks the export supporting - //! @return true if export is supported - Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; - - //! Gets list of supported file extensions - //! @return list of extensions - Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; - - //! Checks the file content to verify a format - //! @param[in] theBuffer read stream buffer to check content - //! @return Standard_True if file is supported by a current provider - Standard_EXPORT virtual bool CheckContent(const Handle(NCollection_Buffer)& theBuffer) const Standard_OVERRIDE; - -public: - - StepData_ConfParameters InternalParameters; -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DESTEP_ConfigurationNode STEPCAFControl_ConfigurationNode; #endif // _STEPCAFControl_ConfigurationNode_HeaderFile diff --git a/src/STEPCAFControl/STEPCAFControl_Provider.cxx b/src/STEPCAFControl/STEPCAFControl_Provider.cxx deleted file mode 100644 index 127db75e1a..0000000000 --- a/src/STEPCAFControl/STEPCAFControl_Provider.cxx +++ /dev/null @@ -1,342 +0,0 @@ -// Copyright (c) 2022 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -IMPLEMENT_STANDARD_RTTIEXT(STEPCAFControl_Provider, DE_Provider) - -//======================================================================= -// function : STEPCAFControl_Provider -// purpose : -//======================================================================= -STEPCAFControl_Provider::STEPCAFControl_Provider() -{} - -//======================================================================= -// function : STEPCAFControl_Provider -// purpose : -//======================================================================= -STEPCAFControl_Provider::STEPCAFControl_Provider(const Handle(DE_ConfigurationNode)& theNode) - :DE_Provider(theNode) -{} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool STEPCAFControl_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - if (theDocument.IsNull()) - { - Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " << - thePath << "\t: theDocument shouldn't be null"; - return false; - } - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(STEPCAFControl_ConfigurationNode))) - { - Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode()); - personizeWS(theWS); - XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter); - STEPCAFControl_Reader aReader; - aReader.Init(theWS); - aReader.SetColorMode(aNode->InternalParameters.ReadColor); - aReader.SetNameMode(aNode->InternalParameters.ReadName); - aReader.SetLayerMode(aNode->InternalParameters.ReadLayer); - aReader.SetPropsMode(aNode->InternalParameters.ReadProps); - aReader.SetMetaMode(aNode->InternalParameters.ReadMetadata); - - IFSelect_ReturnStatus aReadStat = IFSelect_RetVoid; - StepData_ConfParameters aParams = aNode->InternalParameters; - aReadStat = aReader.ReadFile(thePath.ToCString(), aParams); - if (aReadStat != IFSelect_RetDone) - { - Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " << - thePath << "\t: abandon"; - return false; - } - - if (!aReader.Transfer(theDocument, theProgress)) - { - Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " << - thePath << "\t: Cannot read any relevant data from the STEP file"; - return false; - } - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool STEPCAFControl_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(STEPCAFControl_ConfigurationNode))) - { - Message::SendFail() << "Error in the STEPCAFControl_Provider during writing the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode()); - personizeWS(theWS); - STEPCAFControl_Writer aWriter; - aWriter.Init(theWS); - Handle(StepData_StepModel) aModel = Handle(StepData_StepModel)::DownCast(aWriter.Writer().WS()->Model()); - STEPControl_StepModelType aMode = - static_cast(aNode->InternalParameters.WriteModelType); - aWriter.SetColorMode(aNode->InternalParameters.WriteColor); - aWriter.SetNameMode(aNode->InternalParameters.WriteName); - aWriter.SetLayerMode(aNode->InternalParameters.WriteLayer); - aWriter.SetPropsMode(aNode->InternalParameters.WriteProps); - StepData_ConfParameters aParams = aNode->InternalParameters; - Standard_Real aScaleFactorMM = 1.; - if (XCAFDoc_DocumentTool::GetLengthUnit(theDocument, aScaleFactorMM, UnitsMethods_LengthUnit_Millimeter)) - { - aModel->SetLocalLengthUnit(aScaleFactorMM); - } - else - { - aModel->SetLocalLengthUnit(aNode->GlobalParameters.SystemUnit); - Message::SendWarning() << "Warning in the STEPCAFControl_Provider during writing the file " << - thePath << "\t: The document has no information on Units. Using global parameter as initial Unit."; - } - UnitsMethods_LengthUnit aTargetUnit = UnitsMethods::GetLengthUnitByFactorValue(aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter); - aParams.WriteUnit = aTargetUnit; - aModel->SetWriteLengthUnit(aNode->GlobalParameters.LengthUnit); - TDF_Label aLabel; - if (!aWriter.Transfer(theDocument, aParams, aMode, 0, theProgress)) - { - Message::SendFail() << "Error in the STEPCAFControl_Provider during writing the file " << - thePath << "\t: The document cannot be translated or gives no result"; - return false; - } - IFSelect_ReturnStatus aStatus = aWriter.Write(thePath.ToCString()); - switch (aStatus) - { - case IFSelect_RetVoid: - { - Message::SendFail() << "Error in the STEPCAFControl_Provider during writing the file " << - thePath << "\t: No file written"; - return false;; - } - case IFSelect_RetDone: - { - break; - } - default: - { - Message::SendFail() << "Error in the STEPCAFControl_Provider during writing the file " << - thePath << "\t: Error on writing file"; - return false; - } - } - return true; -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool STEPCAFControl_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); - return Read(thePath, theDocument, aWS, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool STEPCAFControl_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); - return Write(thePath, theDocument, aWS, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool STEPCAFControl_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theProgress; - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(STEPCAFControl_ConfigurationNode))) - { - Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode()); - personizeWS(theWS); - STEPControl_Reader aReader; - aReader.SetWS(theWS); - IFSelect_ReturnStatus aReadstat = IFSelect_RetVoid; - StepData_ConfParameters aParams = aNode->InternalParameters; - aReadstat = aReader.ReadFile(thePath.ToCString(), aParams); - Handle(StepData_StepModel) aModel = aReader.StepModel(); - if (aReadstat != IFSelect_RetDone) - { - Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " << - thePath << "\t: abandon, no model loaded"; - return false; - } - aModel->SetLocalLengthUnit(aNode->GlobalParameters.LengthUnit); - if (aReader.TransferRoots() <= 0) - { - Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " << - thePath << "\t:Cannot read any relevant data from the STEP file"; - return false; - } - theShape = aReader.OneShape(); - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool STEPCAFControl_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(STEPCAFControl_ConfigurationNode))) - { - Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode()); - - personizeWS(theWS); - STEPControl_Writer aWriter; - aWriter.SetWS(theWS); - IFSelect_ReturnStatus aWritestat = IFSelect_RetVoid; - Handle(StepData_StepModel) aModel = aWriter.Model();; - StepData_ConfParameters aParams = aNode->InternalParameters; - aModel->SetLocalLengthUnit(aNode->GlobalParameters.SystemUnit); - UnitsMethods_LengthUnit aTargetUnit = UnitsMethods::GetLengthUnitByFactorValue(aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter); - aParams.WriteUnit = aTargetUnit; - if (aTargetUnit == UnitsMethods_LengthUnit_Undefined) - { - aModel->SetWriteLengthUnit(1.0); - Message::SendWarning() << "Custom units are not supported by STEP format, but LengthUnit global parameter doesn't fit any predefined unit. Units will be scaled to Millimeters"; - } - else - { - aModel->SetWriteLengthUnit(aNode->GlobalParameters.LengthUnit); - } - aWritestat = aWriter.Transfer(theShape, aNode->InternalParameters.WriteModelType, aParams, true, theProgress); - if (aWritestat != IFSelect_RetDone) - { - Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " << - thePath << "\t: abandon, no model loaded"; - return false; - } - if (aWriter.Write(thePath.ToCString()) != IFSelect_RetDone) - { - Message::SendFail() << "STEPCAFControl_Provider: Error on writing file"; - return false; - } - return true; -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool STEPCAFControl_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); - return Read(thePath, theShape, aWS, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool STEPCAFControl_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession(); - return Write(thePath, theShape, aWS, theProgress); -} - -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString STEPCAFControl_Provider::GetFormat() const -{ - return TCollection_AsciiString("STEP"); -} - -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString STEPCAFControl_Provider::GetVendor() const -{ - return TCollection_AsciiString("OCC"); -} - -//======================================================================= -// function : personizeWS -// purpose : -//======================================================================= -void STEPCAFControl_Provider::personizeWS(Handle(XSControl_WorkSession)& theWS) -{ - if (theWS.IsNull()) - { - Message::SendWarning() << "Warning: STEPCAFControl_Provider :" - << " Null work session, use internal temporary session"; - theWS = new XSControl_WorkSession(); - } - Handle(STEPCAFControl_Controller) aCntrl = Handle(STEPCAFControl_Controller)::DownCast(theWS->NormAdaptor()); - if (aCntrl.IsNull()) - { - STEPCAFControl_Controller::Init(); - theWS->SelectNorm("STEP"); - } -} diff --git a/src/STEPCAFControl/STEPCAFControl_Provider.hxx b/src/STEPCAFControl/STEPCAFControl_Provider.hxx index 59a475ce95..d6f28b46d5 100644 --- a/src/STEPCAFControl/STEPCAFControl_Provider.hxx +++ b/src/STEPCAFControl/STEPCAFControl_Provider.hxx @@ -14,132 +14,9 @@ #ifndef _STEPCAFControl_Provider_HeaderFile #define _STEPCAFControl_Provider_HeaderFile -#include -#include +#include -//! The class to transfer STEP files. -//! Reads and Writes any STEP files into/from OCCT. -//! Each operation needs configuration node. -//! -//! Providers grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "STEP" -//! The import process is supported. -//! The export process is supported. -class STEPCAFControl_Provider : public DE_Provider -{ -public: - DEFINE_STANDARD_RTTIEXT(STEPCAFControl_Provider, DE_Provider) - -public: - - //! Default constructor - //! Configure translation process with global configuration - Standard_EXPORT STEPCAFControl_Provider(); - - //! Configure translation process - //! @param[in] theNode object to copy - Standard_EXPORT STEPCAFControl_Provider(const Handle(DE_ConfigurationNode)& theNode); - -public: - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - -public: - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; - - private: - - //! Personizes work session with current format. - //! Creates new temporary session if current session is null - //! @param[in] theWS current work session - void personizeWS(Handle(XSControl_WorkSession)& theWS); - -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DESTEP_Provider STEPCAFControl_Provider; #endif // _STEPCAFControl_Provider_HeaderFile diff --git a/src/TKDECascade/PACKAGES b/src/TKDECascade/PACKAGES index 128e6b273b..3d12a682bd 100644 --- a/src/TKDECascade/PACKAGES +++ b/src/TKDECascade/PACKAGES @@ -1,2 +1,4 @@ DEBRepCascade DEXCAFCascade +DEBREP +DEXCAF diff --git a/src/TKDEGLTF/PACKAGES b/src/TKDEGLTF/PACKAGES index 7758e9e783..2c3e8742ae 100644 --- a/src/TKDEGLTF/PACKAGES +++ b/src/TKDEGLTF/PACKAGES @@ -1 +1,2 @@ RWGltf +DEGLTF \ No newline at end of file diff --git a/src/TKDEIGES/PACKAGES b/src/TKDEIGES/PACKAGES index d697b0bc3b..4f065759c1 100644 --- a/src/TKDEIGES/PACKAGES +++ b/src/TKDEIGES/PACKAGES @@ -17,3 +17,4 @@ Geom2dToIGES BRepToIGES BRepToIGESBRep IGESControl +DEIGES diff --git a/src/TKDEOBJ/PACKAGES b/src/TKDEOBJ/PACKAGES index d7824f29c4..b1713f695d 100644 --- a/src/TKDEOBJ/PACKAGES +++ b/src/TKDEOBJ/PACKAGES @@ -1 +1,2 @@ RWObj +DEOBJ diff --git a/src/TKDEPLY/PACKAGES b/src/TKDEPLY/PACKAGES index 228128af6d..f1fd46f5a5 100644 --- a/src/TKDEPLY/PACKAGES +++ b/src/TKDEPLY/PACKAGES @@ -1 +1,2 @@ RWPly +DEPLY diff --git a/src/TKDESTEP/PACKAGES b/src/TKDESTEP/PACKAGES index 58b4ee81ab..90b6790235 100644 --- a/src/TKDESTEP/PACKAGES +++ b/src/TKDESTEP/PACKAGES @@ -37,4 +37,5 @@ StepData StepFile RWHeaderSection APIHeaderSection -HeaderSection \ No newline at end of file +HeaderSection +DESTEP diff --git a/src/TKDESTL/PACKAGES b/src/TKDESTL/PACKAGES index ba06cc7ee4..3d2139b203 100644 --- a/src/TKDESTL/PACKAGES +++ b/src/TKDESTL/PACKAGES @@ -1,2 +1,3 @@ StlAPI RWStl +DESTL diff --git a/src/TKDEVRML/PACKAGES b/src/TKDEVRML/PACKAGES index 05ba201e23..a2bdcb7bfd 100644 --- a/src/TKDEVRML/PACKAGES +++ b/src/TKDEVRML/PACKAGES @@ -2,3 +2,4 @@ VrmlConverter VrmlAPI Vrml VrmlData +DEVRML diff --git a/src/Vrml/FILES b/src/Vrml/FILES index d0db5dc099..2f91b88988 100644 --- a/src/Vrml/FILES +++ b/src/Vrml/FILES @@ -6,7 +6,6 @@ Vrml_AsciiTextJustification.hxx Vrml_Cone.cxx Vrml_Cone.hxx Vrml_ConeParts.hxx -Vrml_ConfigurationNode.cxx Vrml_ConfigurationNode.hxx Vrml_Coordinate3.cxx Vrml_Coordinate3.hxx @@ -53,7 +52,6 @@ Vrml_PointLight.cxx Vrml_PointLight.hxx Vrml_PointSet.cxx Vrml_PointSet.hxx -Vrml_Provider.cxx Vrml_Provider.hxx Vrml_Rotation.cxx Vrml_Rotation.hxx diff --git a/src/Vrml/Vrml_ConfigurationNode.cxx b/src/Vrml/Vrml_ConfigurationNode.cxx deleted file mode 100644 index 0e50f82368..0000000000 --- a/src/Vrml/Vrml_ConfigurationNode.cxx +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (c) 2022 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include - -IMPLEMENT_STANDARD_RTTIEXT(Vrml_ConfigurationNode, DE_ConfigurationNode) - -namespace -{ - static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE() - { - static const TCollection_AsciiString aScope = "provider"; - return aScope; - } - - // Wrapper to auto-load DE component - DE_PluginHolder THE_OCCT_VRML_COMPONENT_PLUGIN; -} - -//======================================================================= -// function : STEPCAFControl_ConfigurationNode -// purpose : -//======================================================================= -Vrml_ConfigurationNode::Vrml_ConfigurationNode() : - DE_ConfigurationNode() -{} - -//======================================================================= -// function : STEPCAFControl_ConfigurationNode -// purpose : -//======================================================================= -Vrml_ConfigurationNode::Vrml_ConfigurationNode(const Handle(Vrml_ConfigurationNode)& theNode) - :DE_ConfigurationNode(theNode) -{ - InternalParameters = theNode->InternalParameters; -} - -//======================================================================= -// function : Load -// purpose : -//======================================================================= -bool Vrml_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource) -{ - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor(); - - InternalParameters.ReadFileUnit = - theResource->RealVal("read.file.unit", InternalParameters.ReadFileUnit, aScope); - InternalParameters.ReadFileCoordinateSys = (RWMesh_CoordinateSystem) - theResource->IntegerVal("read.file.coordinate.system", InternalParameters.ReadFileCoordinateSys, aScope); - InternalParameters.ReadSystemCoordinateSys = (RWMesh_CoordinateSystem) - theResource->IntegerVal("read.system.coordinate.system", InternalParameters.ReadSystemCoordinateSys, aScope); - InternalParameters.ReadFillIncomplete = - theResource->BooleanVal("read.fill.incomplete", InternalParameters.ReadFillIncomplete, aScope); - - InternalParameters.WriterVersion = (WriteMode_WriterVersion) - theResource->IntegerVal("writer.version", InternalParameters.WriterVersion, aScope); - InternalParameters.WriteRepresentationType = (WriteMode_RepresentationType) - theResource->IntegerVal("write.representation.type", InternalParameters.WriteRepresentationType, aScope); - - return true; -} - -//======================================================================= -// function : Save -// purpose : -//======================================================================= -TCollection_AsciiString Vrml_ConfigurationNode::Save() const -{ - TCollection_AsciiString aResult; - aResult += "!*****************************************************************************\n"; - aResult = aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n"; - TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + "."; - - aResult += "!\n"; - aResult += "!Read parameters:\n"; - aResult += "!\n"; - - aResult += "!\n"; - aResult += "!Set (override) file length units to convert from while reading the file, defined as scale factor for m (meters).\n"; - aResult += "!Default value: 1. Available values: positive double\n"; - aResult += aScope + "read.file.unit :\t " + InternalParameters.ReadFileUnit + "\n"; - aResult += "!\n"; - - aResult += "!\n"; - aResult += "!Set (override) file origin coordinate system to perform conversion during read.\n"; - aResult += "!Default value: Yup (1). { Zup (0) | Yup (1) }\n"; - aResult += aScope + "read.file.coordinate.system :\t " + InternalParameters.ReadFileCoordinateSys + "\n"; - aResult += "!\n"; - - aResult += "!\n"; - aResult += "!Set system origin coordinate system to perform conversion into during read.\n"; - aResult += "!Default value: Zup (0). Available values: { Zup (0) | Yup (1) }\n"; - aResult += aScope + "read.system.coordinate.system :\t " + InternalParameters.ReadSystemCoordinateSys + "\n"; - aResult += "!\n"; - - aResult += "!\n"; - aResult += "!Set flag allowing partially read file content to be put into the XDE document.\n"; - aResult += "!Default value: 1(\"ON\"). Available values: 0(\"OFF\"), 1(\"ON\")\n"; - aResult += aScope + "read.fill.incomplete :\t " + InternalParameters.ReadFillIncomplete + "\n"; - aResult += "!\n"; - - aResult += "!\n"; - aResult += "!Write parameters:\n"; - aResult += "!\n"; - - aResult += "!\n"; - aResult += "!Setting up writer version.\n"; - aResult += "!Default value: 2. Available values: 1, 2\n"; - aResult += aScope + "writer.version :\t " + InternalParameters.WriterVersion + "\n"; - aResult += "!\n"; - - aResult += "!\n"; - aResult += "!Setting up representation\n"; - aResult += "!Default value: 1. Available values: 0(shaded), 1(wireframe), 2(both).\n"; - aResult += aScope + "write.representation.type :\t " + InternalParameters.WriteRepresentationType + "\n"; - aResult += "!\n"; - - aResult += "!*****************************************************************************\n"; - return aResult; -} - -//======================================================================= -// function : Copy -// purpose : -//======================================================================= -Handle(DE_ConfigurationNode) Vrml_ConfigurationNode::Copy() const -{ - return new Vrml_ConfigurationNode(*this); -} - -//======================================================================= -// function : BuildProvider -// purpose : -//======================================================================= -Handle(DE_Provider) Vrml_ConfigurationNode::BuildProvider() -{ - return new Vrml_Provider(this); -} - -//======================================================================= -// function : IsImportSupported -// purpose : -//======================================================================= -bool Vrml_ConfigurationNode::IsImportSupported() const -{ - return true; -} - -//======================================================================= -// function : IsExportSupported -// purpose : -//======================================================================= -bool Vrml_ConfigurationNode::IsExportSupported() const -{ - return true; -} - -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString Vrml_ConfigurationNode::GetFormat() const -{ - return TCollection_AsciiString("VRML"); -} - -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString Vrml_ConfigurationNode::GetVendor() const -{ - return TCollection_AsciiString("OCC"); -} - -//======================================================================= -// function : GetExtensions -// purpose : -//======================================================================= -TColStd_ListOfAsciiString Vrml_ConfigurationNode::GetExtensions() const -{ - TColStd_ListOfAsciiString anExt; - anExt.Append("vrml"); - anExt.Append("wrl"); - return anExt; -} diff --git a/src/Vrml/Vrml_ConfigurationNode.hxx b/src/Vrml/Vrml_ConfigurationNode.hxx index 2745802812..d0fd408191 100644 --- a/src/Vrml/Vrml_ConfigurationNode.hxx +++ b/src/Vrml/Vrml_ConfigurationNode.hxx @@ -14,99 +14,9 @@ #ifndef _Vrml_ConfigurationNode_HeaderFile #define _Vrml_ConfigurationNode_HeaderFile -#include -#include +#include -//! The purpose of this class is to configure the transfer process for VRML format -//! Stores the necessary settings for Vrml_Provider. -//! Configures and creates special provider to transfer VRML files. -//! -//! Nodes grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "VRML" -//! The supported CAD extensions are ".vrml", ".wrl" -//! The import process is supported. -//! The export process is supported. -class Vrml_ConfigurationNode : public DE_ConfigurationNode -{ - DEFINE_STANDARD_RTTIEXT(Vrml_ConfigurationNode, DE_ConfigurationNode) -public: - - //! Initializes all field by default - Standard_EXPORT Vrml_ConfigurationNode(); - - //! Copies values of all fields - //! @param[in] theNode object to copy - Standard_EXPORT Vrml_ConfigurationNode(const Handle(Vrml_ConfigurationNode)& theNode); - - //! Updates values according the resource - //! @param[in] theResource input resource to use - //! @return true if theResource loading has ended correctly - Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) Standard_OVERRIDE; - - //! Writes configuration to the string - //! @return result resource string - Standard_EXPORT virtual TCollection_AsciiString Save() const Standard_OVERRIDE; - - //! Copies values of all fields - //! @return new object with the same field values - Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const Standard_OVERRIDE; - - - //! Creates new provider for the own format - //! @return new created provider - Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() Standard_OVERRIDE; - -public: - - //! Checks the import supporting - //! @return true if import is supported - Standard_EXPORT virtual bool IsImportSupported() const Standard_OVERRIDE; - - //! Checks the export supporting - //! @return true if export is supported - Standard_EXPORT virtual bool IsExportSupported() const Standard_OVERRIDE; - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; - - //! Gets list of supported file extensions - //! @return list of extensions - Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const Standard_OVERRIDE; - -public: - enum WriteMode_WriterVersion - { - WriteMode_WriterVersion_1 = 1, - WriteMode_WriterVersion_2 - }; - enum WriteMode_RepresentationType - { - WriteMode_RepresentationType_Shaded = 0, - WriteMode_RepresentationType_Wireframe, - WriteMode_RepresentationType_Both - }; - - struct Vrml_InternalSection - { - // Read -// clang-format off - double ReadFileUnit = 1.; // - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -IMPLEMENT_STANDARD_RTTIEXT(Vrml_Provider, DE_Provider) - -//======================================================================= -// function : Vrml_Provider -// purpose : -//======================================================================= -Vrml_Provider::Vrml_Provider() -{} - -//======================================================================= -// function : Vrml_Provider -// purpose : -//======================================================================= -Vrml_Provider::Vrml_Provider(const Handle(DE_ConfigurationNode)& theNode) - :DE_Provider(theNode) -{} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool Vrml_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Read(thePath, theDocument, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool Vrml_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Write(thePath, theDocument, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool Vrml_Provider::Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - if (theDocument.IsNull()) - { - Message::SendFail() << "Error in the Vrml_Provider during reading the file " << - thePath << "\t: theDocument shouldn't be null"; - return false; - } - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(Vrml_ConfigurationNode))) - { - Message::SendFail() << "Error in the Vrml_Provider during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(Vrml_ConfigurationNode) aNode = Handle(Vrml_ConfigurationNode)::DownCast(GetNode()); - - VrmlAPI_CafReader aVrmlReader; - aVrmlReader.SetDocument(theDocument); - aVrmlReader.SetFileLengthUnit(aNode->InternalParameters.ReadFileUnit); - aVrmlReader.SetSystemLengthUnit(aNode->GlobalParameters.LengthUnit); - aVrmlReader.SetFileCoordinateSystem(aNode->InternalParameters.ReadFileCoordinateSys); - aVrmlReader.SetSystemCoordinateSystem(aNode->InternalParameters.ReadSystemCoordinateSys); - aVrmlReader.SetFillIncompleteDocument(aNode->InternalParameters.ReadFillIncomplete); - - XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->InternalParameters.ReadFileUnit); - - if (!aVrmlReader.Perform(thePath, theProgress)) - { - if (aVrmlReader.ExtraStatus() != RWMesh_CafReaderStatusEx_Partial) - { - Message::SendFail() << "Error in the Vrml_Provider during reading the file '" << thePath << "'"; - return false; - } - Message::SendWarning() << "Warning in the Vrml_Provider during reading the file: file has been read paratially " << - "(due to unexpected EOF, syntax error, memory limit) '" << thePath << "'"; - } - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool Vrml_Provider::Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress) -{ - (void)theProgress; - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(Vrml_ConfigurationNode))) - { - Message::SendFail() << "Error in the Vrml_Provider during writing the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(Vrml_ConfigurationNode) aNode = Handle(Vrml_ConfigurationNode)::DownCast(GetNode()); - - VrmlAPI_Writer aWriter; - aWriter.SetRepresentation(static_cast(aNode->InternalParameters.WriteRepresentationType)); - Standard_Real aScaling = 1.; - Standard_Real aScaleFactorMM = 1.; - if (XCAFDoc_DocumentTool::GetLengthUnit(theDocument, aScaleFactorMM, UnitsMethods_LengthUnit_Millimeter)) - { - aScaling = aScaleFactorMM / aNode->GlobalParameters.LengthUnit; - } - else - { - aScaling = aNode->GlobalParameters.SystemUnit / aNode->GlobalParameters.LengthUnit; - Message::SendWarning() << "Warning in the Vrml_Provider during writing the file " << - thePath << "\t: The document has no information on Units. Using global parameter as initial Unit."; - } - if (!aWriter.WriteDoc(theDocument, thePath.ToCString(), aScaling)) - { - Message::SendFail() << "Error in the Vrml_Provider during wtiting the file " << - thePath << "\t: File was not written"; - return false; - } - - return true; -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool Vrml_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Read(thePath, theShape, theProgress); -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool Vrml_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress) -{ - (void)theWS; - return Write(thePath, theShape, theProgress); -} - -//======================================================================= -// function : Read -// purpose : -//======================================================================= -bool Vrml_Provider::Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - (void)theProgress; - if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(Vrml_ConfigurationNode))) - { - Message::SendFail() << "Error in the Vrml_Provider during reading the file " << - thePath << "\t: Incorrect or empty Configuration Node"; - return false; - } - Handle(Vrml_ConfigurationNode) aNode = Handle(Vrml_ConfigurationNode)::DownCast(GetNode()); - - TopoDS_Shape aShape; - VrmlData_DataMapOfShapeAppearance aShapeAppMap; - - std::filebuf aFic; - std::istream aStream(&aFic); - - if (aFic.open(thePath.ToCString(), std::ios::in)) - { - // Get path of the VRML file. - OSD_Path aPath(thePath.ToCString()); - TCollection_AsciiString aVrmlDir("."); - TCollection_AsciiString aDisk = aPath.Disk(); - TCollection_AsciiString aTrek = aPath.Trek(); - if (!aTrek.IsEmpty()) - { - if (!aDisk.IsEmpty()) - { - aVrmlDir = aDisk; - } - else - { - aVrmlDir.Clear(); - } - aTrek.ChangeAll('|', '/'); - aVrmlDir += aTrek; - } - - VrmlData_Scene aScene; - aScene.SetLinearScale(aNode->GlobalParameters.LengthUnit); - - aScene.SetVrmlDir(aVrmlDir); - aScene << aStream; - const char* aStr = 0L; - switch (aScene.Status()) - { - case VrmlData_StatusOK: - { - aShape = aScene.GetShape(aShapeAppMap); - break; - } - case VrmlData_EmptyData: aStr = "EmptyData"; break; - case VrmlData_UnrecoverableError: aStr = "UnrecoverableError"; break; - case VrmlData_GeneralError: aStr = "GeneralError"; break; - case VrmlData_EndOfFile: aStr = "EndOfFile"; break; - case VrmlData_NotVrmlFile: aStr = "NotVrmlFile"; break; - case VrmlData_CannotOpenFile: aStr = "CannotOpenFile"; break; - case VrmlData_VrmlFormatError: aStr = "VrmlFormatError"; break; - case VrmlData_NumericInputError: aStr = "NumericInputError"; break; - case VrmlData_IrrelevantNumber: aStr = "IrrelevantNumber"; break; - case VrmlData_BooleanInputError: aStr = "BooleanInputError"; break; - case VrmlData_StringInputError: aStr = "StringInputError"; break; - case VrmlData_NodeNameUnknown: aStr = "NodeNameUnknown"; break; - case VrmlData_NonPositiveSize: aStr = "NonPositiveSize"; break; - case VrmlData_ReadUnknownNode: aStr = "ReadUnknownNode"; break; - case VrmlData_NonSupportedFeature: aStr = "NonSupportedFeature"; break; - case VrmlData_OutputStreamUndefined:aStr = "OutputStreamUndefined"; break; - case VrmlData_NotImplemented: aStr = "NotImplemented"; break; - default: - break; - } - if (aStr) - { - Message::SendFail() << "Error in the Vrml_Provider during reading the file " << - thePath << "\t: ++ VRML Error: " << aStr << " in line " << aScene.GetLineError(); - return false; - } - else - { - theShape = aShape; - } - } - else - { - Message::SendFail() << "Error in the Vrml_Provider during reading the file " << - thePath << "\t: cannot open file"; - return false; - } - return true; -} - -//======================================================================= -// function : Write -// purpose : -//======================================================================= -bool Vrml_Provider::Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress) -{ - Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF"); - Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main()); - aShTool->AddShape(theShape); - return Write(thePath, aDoc, theProgress); -} - -//======================================================================= -// function : GetFormat -// purpose : -//======================================================================= -TCollection_AsciiString Vrml_Provider::GetFormat() const -{ - return TCollection_AsciiString("VRML"); -} - -//======================================================================= -// function : GetVendor -// purpose : -//======================================================================= -TCollection_AsciiString Vrml_Provider::GetVendor() const -{ - return TCollection_AsciiString("OCC"); -} diff --git a/src/Vrml/Vrml_Provider.hxx b/src/Vrml/Vrml_Provider.hxx index ea99a08770..17cd82cc6f 100644 --- a/src/Vrml/Vrml_Provider.hxx +++ b/src/Vrml/Vrml_Provider.hxx @@ -14,123 +14,9 @@ #ifndef _Vrml_Provider_HeaderFile #define _Vrml_Provider_HeaderFile -#include +#include -//! The class to transfer VRML files. -//! Reads and Writes any VRML files into/from OCCT. -//! Each operation needs configuration node. -//! -//! Providers grouped by Vendor name and Format type. -//! The Vendor name is "OCC" -//! The Format type is "VRML" -//! The import process is supported. -//! The export process is supported. -class Vrml_Provider : public DE_Provider -{ -public: - DEFINE_STANDARD_RTTIEXT(Vrml_Provider, DE_Provider) - -public: - - //! Default constructor - //! Configure translation process with global configuration - Standard_EXPORT Vrml_Provider(); - - //! Configure translation process - //! @param[in] theNode object to copy - Standard_EXPORT Vrml_Provider(const Handle(DE_ConfigurationNode)& theNode); - -public: - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theDocument document to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theDocument document to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const Handle(TDocStd_Document)& theDocument, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theWS current work session - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - Handle(XSControl_WorkSession)& theWS, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Reads a CAD file, according internal configuration - //! @param[in] thePath path to the import CAD file - //! @param[out] theShape shape to save result - //! @param[in] theProgress progress indicator - //! @return true if Read operation has ended correctly - Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath, - TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - - //! Writes a CAD file, according internal configuration - //! @param[in] thePath path to the export CAD file - //! @param[out] theShape shape to export - //! @param[in] theProgress progress indicator - //! @return true if Write operation has ended correctly - Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath, - const TopoDS_Shape& theShape, - const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE; - -public: - - //! Gets CAD format name of associated provider - //! @return provider CAD format - Standard_EXPORT virtual TCollection_AsciiString GetFormat() const Standard_OVERRIDE; - - //! Gets provider's vendor name of associated provider - //! @return provider's vendor name - Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; -}; +Standard_DEPRECATED("Deprecated alias to moved class") +typedef DEVRML_Provider Vrml_Provider; #endif // _Vrml_Provider_HeaderFile diff --git a/src/XDEDRAW/XDEDRAW.cxx b/src/XDEDRAW/XDEDRAW.cxx index 5d0773b054..9b674f698b 100644 --- a/src/XDEDRAW/XDEDRAW.cxx +++ b/src/XDEDRAW/XDEDRAW.cxx @@ -25,22 +25,22 @@ #include #include #include -#include -#include +#include +#include #include #include #include #include -#include +#include #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include -#include +#include #include #include #include @@ -79,7 +79,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/XSDRAWDE/XSDRAWDE.cxx b/src/XSDRAWDE/XSDRAWDE.cxx index a05a99e5f9..b0e999f63b 100644 --- a/src/XSDRAWDE/XSDRAWDE.cxx +++ b/src/XSDRAWDE/XSDRAWDE.cxx @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include @@ -423,7 +423,7 @@ void XSDRAWDE::Factory(Draw_Interpretor& theDI) XSDRAW::LoadDraw(theDI); // Workaround to force load TKDECascade lib - DEBRepCascade_ConfigurationNode aTmpObj; + DEBREP_ConfigurationNode aTmpObj; (void)aTmpObj; } -- 2.39.5