1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-03 17:56:21 +03:00

0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files

Implementing DE_Wrapper and its formats
This commit is contained in:
atychini 2022-02-16 13:22:23 +03:00 committed by afokin
parent b1970c8a47
commit 6d1a049be7
141 changed files with 12406 additions and 277 deletions

View File

@ -3,5 +3,5 @@ ModelingData TKG2d TKG3d TKGeomBase TKBRep
ModelingAlgorithms TKGeomAlgo TKTopAlgo TKPrim TKBO TKBool TKHLR TKFillet TKOffset TKFeat TKMesh TKXMesh TKShHealing
Visualization TKService TKV3d TKOpenGl TKOpenGles TKMeshVS TKIVtk TKD3DHost
ApplicationFramework TKCDF TKLCAF TKCAF TKBinL TKXmlL TKBin TKXml TKStdL TKStd TKTObj TKBinTObj TKXmlTObj TKVCAF
DataExchange TKXSBase TKSTEPBase TKSTEPAttr TKSTEP209 TKSTEP TKIGES TKXCAF TKXDEIGES TKXDESTEP TKSTL TKVRML TKXmlXCAF TKBinXCAF TKRWMesh
DataExchange TKXDE TKXSBase TKSTEPBase TKSTEPAttr TKSTEP209 TKSTEP TKIGES TKXCAF TKXDEIGES TKXDESTEP TKSTL TKVRML TKXmlXCAF TKBinXCAF TKRWMesh TKXDECascade
Draw TKDraw TKTopTest TKOpenGlTest TKOpenGlesTest TKD3DHostTest TKViewerTest TKXSDRAW TKDCAF TKXDEDRAW TKTObjDRAW TKQADraw TKIVtkDraw DRAWEXE

View File

@ -384,6 +384,8 @@ t TKSTEPBase
t TKSTL
t TKVRML
t TKXCAF
t TKXDE
t TKXDECascade
t TKXDEIGES
t TKXDESTEP
t TKXSBase
@ -394,6 +396,9 @@ n DBRep
n DDF
n DDataStd
n DDocStd
n DE
n DEXCAFCascade
n DEBRepCascade
n DNaming
n DPrsStd
n Draw

View File

@ -0,0 +1,429 @@
// 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 <DE_ConfigurationContext.hxx>
#include <Message.hxx>
#include <OSD_File.hxx>
#include <OSD_StreamBuffer.hxx>
#include <OSD_Path.hxx>
#include <OSD_Protection.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_HAsciiString.hxx>
IMPLEMENT_STANDARD_RTTIEXT(DE_ConfigurationContext, Standard_Transient)
enum DE_ConfigurationContext_KindOfLine
{
DE_ConfigurationContext_KindOfLine_End,
DE_ConfigurationContext_KindOfLine_Empty,
DE_ConfigurationContext_KindOfLine_Comment,
DE_ConfigurationContext_KindOfLine_Resource,
DE_ConfigurationContext_KindOfLine_Error
};
namespace
{
//=======================================================================
//function : GetLine
//purpose :
//=======================================================================
static Standard_Boolean GetLine(OSD_File& theFile, TCollection_AsciiString& theLine)
{
TCollection_AsciiString aBuffer;
Standard_Integer aBufSize = 10;
Standard_Integer aLen;
theLine.Clear();
do
{
theFile.ReadLine(aBuffer, aBufSize, aLen);
theLine += aBuffer;
if (theFile.IsAtEnd())
{
if (!theLine.Length())
{
return Standard_False;
}
else
{
theLine += "\n";
}
}
} while (theLine.Value(theLine.Length()) != '\n');
return Standard_True;
}
//=======================================================================
//function : WhatKindOfLine
//purpose :
//=======================================================================
static DE_ConfigurationContext_KindOfLine WhatKindOfLine(const TCollection_AsciiString& theLine,
TCollection_AsciiString& theToken1,
TCollection_AsciiString& theToken2)
{
static const TCollection_AsciiString aWhiteSpace = " \t\r\n";
Standard_Integer aPos1 = 0, aPos2 = 0, aPos = 0;
TCollection_AsciiString aLine(theLine);
aLine.LeftAdjust();
aLine.RightAdjust();
if (!aLine.EndsWith(':') && (!aLine.EndsWith(' ') || !aLine.EndsWith('\t') || !aLine.EndsWith('\n')))
{
aLine.InsertAfter(aLine.Length(), " ");
}
if (aLine.Value(1) == '!')
{
return DE_ConfigurationContext_KindOfLine_Comment;
}
aPos1 = aLine.FirstLocationNotInSet(aWhiteSpace, 1, aLine.Length());
if (aLine.Value(aPos1) == '\n')
{
return DE_ConfigurationContext_KindOfLine_Empty;
}
aPos2 = aLine.Location(1, ':', aPos1, aLine.Length());
if (aPos2 == 0 || aPos1 == aPos2)
{
return DE_ConfigurationContext_KindOfLine_Error;
}
for (aPos = aPos2 - 1; aLine.Value(aPos) == '\t' || aLine.Value(aPos) == ' '; aPos--);
theToken1 = aLine.SubString(aPos1, aPos);
if(aPos2 != aLine.Length())
{
aPos2++;
}
aPos = aLine.FirstLocationNotInSet(aWhiteSpace, aPos2, aLine.Length());
if (aPos != 0)
{
if (aLine.Value(aPos) == '\\')
{
switch (aLine.Value(aPos + 1))
{
case '\\':
case ' ':
case '\t':
aPos++;
break;
}
}
}
if (aPos == aLine.Length() || aPos == 0)
{
theToken2.Clear();
}
else
{
aLine.Remove(1, aPos - 1);
aLine.Remove(aLine.Length());
theToken2 = aLine;
}
return DE_ConfigurationContext_KindOfLine_Resource;
}
//=======================================================================
//function : MakeName
//purpose :
//=======================================================================
static TCollection_AsciiString MakeName(const TCollection_AsciiString& theScope,
const TCollection_AsciiString& theParam)
{
TCollection_AsciiString aStr(theScope);
if (!aStr.IsEmpty())
{
aStr += '.';
}
aStr += theParam;
return aStr;
}
}
//=======================================================================
//function : DE_ConfigurationContext
//purpose :
//=======================================================================
DE_ConfigurationContext::DE_ConfigurationContext()
{}
//=======================================================================
//function : Load
//purpose :
//=======================================================================
Standard_Boolean DE_ConfigurationContext::Load(const TCollection_AsciiString& theConfiguration)
{
OSD_Path aPath = theConfiguration;
OSD_File aFile(aPath);
if (!aFile.Exists())
{
if (!LoadStr(theConfiguration))
{
return false;
}
}
else
{
if (!LoadFile(theConfiguration))
{
return false;
}
}
return true;
}
//=======================================================================
//function : LoadFile
//purpose :
//=======================================================================
Standard_Boolean DE_ConfigurationContext::LoadFile(const TCollection_AsciiString& theFile)
{
myResource.Clear();
OSD_Path aPath(theFile);
OSD_File aFile = aPath;
TCollection_AsciiString FileName = aPath.Name();
aFile.Open(OSD_ReadOnly, OSD_Protection());
if (aFile.Failed())
{
Message::SendFail("Error: DE Context loading is stopped. Can't open the file");
return Standard_True;
}
TCollection_AsciiString aLine;
while (GetLine(aFile, aLine))
{
if (!load(aLine))
{
Message::SendFail() << "Error: DE Context loading is stopped. Syntax error: " << aLine;
return Standard_False;
}
}
return Standard_True;
}
//=======================================================================
//function : LoadStr
//purpose :
//=======================================================================
Standard_Boolean DE_ConfigurationContext::LoadStr(const TCollection_AsciiString& theResource)
{
myResource.Clear();
TCollection_AsciiString aLine = "";
const Standard_Integer aLength = theResource.Length();
for (Standard_Integer anInd = 1; anInd <= aLength; anInd++)
{
const Standard_Character aChar = theResource.Value(anInd);
if (aChar != '\n')
aLine += aChar;
if ((aChar == '\n' || anInd == aLength) && !aLine.IsEmpty())
{
if (!load(aLine))
{
Message::SendFail() << "Error: DE Context loading is stopped. Syntax error: " << aLine;
return Standard_False;
}
aLine.Clear();
}
}
return Standard_True;
}
//=======================================================================
//function : IsParamSet
//purpose :
//=======================================================================
Standard_Boolean DE_ConfigurationContext::IsParamSet(const TCollection_AsciiString& theParam,
const TCollection_AsciiString& theScope) const
{
TCollection_AsciiString aResource(MakeName(theScope, theParam));
return myResource.IsBound(aResource);
}
//=======================================================================
//function : RealVal
//purpose :
//=======================================================================
Standard_Real DE_ConfigurationContext::RealVal(const TCollection_AsciiString& theParam,
const Standard_Real theDefValue,
const TCollection_AsciiString& theScope) const
{
Standard_Real aVal = 0.;
return GetReal(theParam, aVal, theScope) ? aVal : theDefValue;
}
//=======================================================================
//function : IntegerVal
//purpose :
//=======================================================================
Standard_Integer DE_ConfigurationContext::IntegerVal(const TCollection_AsciiString& theParam,
const Standard_Integer theDefValue,
const TCollection_AsciiString& theScope) const
{
Standard_Integer aVal = 0;
return GetInteger(theParam, aVal, theScope) ? aVal : theDefValue;
}
//=======================================================================
//function : BooleanVal
//purpose :
//=======================================================================
Standard_Boolean DE_ConfigurationContext::BooleanVal(const TCollection_AsciiString& theParam,
const Standard_Boolean theDefValue,
const TCollection_AsciiString& theScope) const
{
Standard_Boolean aVal = Standard_False;
return GetBoolean(theParam, aVal, theScope) ? aVal : theDefValue;
}
//=======================================================================
//function : StringVal
//purpose :
//=======================================================================
TCollection_AsciiString DE_ConfigurationContext::StringVal(const TCollection_AsciiString& theParam,
const TCollection_AsciiString& theDefValue,
const TCollection_AsciiString& theScope) const
{
TCollection_AsciiString aVal = "";
return GetString(theParam, aVal, theScope) ? aVal : theDefValue;
}
//=======================================================================
//function : GetReal
//purpose :
//=======================================================================
Standard_Boolean DE_ConfigurationContext::GetReal(const TCollection_AsciiString& theParam,
Standard_Real& theValue,
const TCollection_AsciiString& theScope) const
{
TCollection_AsciiString aStr;
if (!GetString(theParam, aStr, theScope))
{
return Standard_False;
}
if (aStr.IsRealValue())
{
theValue = aStr.RealValue();
return Standard_True;
}
return Standard_False;
}
//=======================================================================
//function : GetInteger
//purpose :
//=======================================================================
Standard_Boolean DE_ConfigurationContext::GetInteger(const TCollection_AsciiString& theParam,
Standard_Integer& theValue,
const TCollection_AsciiString& theScope) const
{
TCollection_AsciiString aStr;
if (!GetString(theParam, aStr, theScope))
{
return Standard_False;
}
if (aStr.IsIntegerValue())
{
theValue = aStr.IntegerValue();
return Standard_True;
}
return Standard_False;
}
//=======================================================================
//function : GetBoolean
//purpose :
//=======================================================================
Standard_Boolean DE_ConfigurationContext::GetBoolean(const TCollection_AsciiString& theParam,
Standard_Boolean& theValue,
const TCollection_AsciiString& theScope) const
{
TCollection_AsciiString aStr;
if (!GetString(theParam, aStr, theScope))
{
return Standard_False;
}
if (aStr.IsIntegerValue())
{
theValue = aStr.IntegerValue() != 0;
return Standard_True;
}
return Standard_False;
}
//=======================================================================
//function : GetString
//purpose :
//=======================================================================
Standard_Boolean DE_ConfigurationContext::GetString(const TCollection_AsciiString& theParam,
TCollection_AsciiString& theStr,
const TCollection_AsciiString& theScope) const
{
TCollection_AsciiString aResource = MakeName(theScope, theParam);
return myResource.Find(aResource, theStr);
}
//=======================================================================
//function : GetStringSeq
//purpose :
//=======================================================================
Standard_Boolean DE_ConfigurationContext::GetStringSeq(const TCollection_AsciiString& theParam,
TColStd_ListOfAsciiString& theValue,
const TCollection_AsciiString& theScope) const
{
TCollection_AsciiString aStr;
if (!GetString(theParam, aStr, theScope))
{
return Standard_False;
}
theValue.Clear();
TCollection_AsciiString anElem;
const Standard_Integer aLength = aStr.Length();
for (Standard_Integer anInd = 1; anInd <= aLength; anInd++)
{
const Standard_Character aChar = aStr.Value(anInd);
anElem += aChar;
if ((aChar == ' ' || anInd == aLength) && !anElem.IsEmpty())
{
anElem.RightAdjust();
anElem.LeftAdjust();
theValue.Append(anElem);
anElem.Clear();
}
}
return Standard_True;
}
//=======================================================================
//function : load
//purpose :
//=======================================================================
Standard_Boolean DE_ConfigurationContext::load(const TCollection_AsciiString& theResourceLine)
{
if (theResourceLine.IsEmpty())
{
return Standard_False;
}
TCollection_AsciiString aToken1, aToken2;
DE_ConfigurationContext_KindOfLine aKind = WhatKindOfLine(theResourceLine, aToken1, aToken2);
switch (aKind)
{
case DE_ConfigurationContext_KindOfLine_End:
case DE_ConfigurationContext_KindOfLine_Comment:
case DE_ConfigurationContext_KindOfLine_Empty:
break;
case DE_ConfigurationContext_KindOfLine_Resource:
myResource.Bind(aToken1, aToken2);
break;
case DE_ConfigurationContext_KindOfLine_Error:
break;
}
return Standard_True;
}

View File

@ -0,0 +1,159 @@
// 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 _DE_ConfigurationContext_HeaderFile
#define _DE_ConfigurationContext_HeaderFile
#include <NCollection_DataMap.hxx>
#include <TColStd_ListOfAsciiString.hxx>
typedef NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString, TCollection_AsciiString> DE_ResourceMap;
//! Provides convenient interface to resource file
//! Allows loading of the resource file and getting attributes'
//! values starting from some scope, for example
//! if scope is defined as "ToV4" and requested parameter
//! is "exec.op", value of "ToV4.exec.op" parameter from
//! the resource file will be returned
class DE_ConfigurationContext : public Standard_Transient
{
public:
DEFINE_STANDARD_RTTIEXT(DE_ConfigurationContext, Standard_Transient)
//! Creates an empty tool
Standard_EXPORT DE_ConfigurationContext();
//! Import the custom configuration
//! Save all parameters with their values.
//! @param[in] theConfiguration path to configuration file or string value
//! @return true in case of success, false otherwise
Standard_EXPORT Standard_Boolean Load(const TCollection_AsciiString& theConfiguration);
//! Import the resource file.
//! Save all parameters with their values.
//! @param[in] theFile path to the resource file
//! @return true in case of success, false otherwise
Standard_EXPORT Standard_Boolean LoadFile(const TCollection_AsciiString& theFile);
//! Import the resource string.
//! Save all parameters with their values.
//! @param[in] theResource string with resource content
//! @return true in case of success, false otherwise
Standard_EXPORT Standard_Boolean LoadStr(const TCollection_AsciiString& theResource);
//! Checks for existing the parameter name
//! @param[in] theParam complex parameter name
//! @param[in] theScope base parameter name
//! @return Standard_True if parameter is defined in the resource file
Standard_EXPORT Standard_Boolean IsParamSet(const TCollection_AsciiString& theParam,
const TCollection_AsciiString& theScope = "") const;
//! Gets value of parameter as being of specific type
//! @param[in] theParam complex parameter name
//! @param[out] theValue value to get by parameter
//! @param[in] theScope base parameter name
//! @return Standard_False if parameter is not defined or has a wrong type
Standard_EXPORT Standard_Boolean GetReal(const TCollection_AsciiString& theParam,
Standard_Real& theValue,
const TCollection_AsciiString& theScope = "") const;
//! Gets value of parameter as being of specific type
//! @param[in] theParam complex parameter name
//! @param[out] theValue value to get by parameter
//! @param[in] theScope base parameter name
//! @return Standard_False if parameter is not defined or has a wrong type
Standard_EXPORT Standard_Boolean GetInteger(const TCollection_AsciiString& theParam,
Standard_Integer& theValue,
const TCollection_AsciiString& theScope = "") const;
//! Gets value of parameter as being of specific type
//! @param[in] theParam complex parameter name
//! @param[out] theValue value to get by parameter
//! @param[in] theScope base parameter name
//! @return Standard_False if parameter is not defined or has a wrong type
Standard_EXPORT Standard_Boolean GetBoolean(const TCollection_AsciiString& theParam,
Standard_Boolean& theValue,
const TCollection_AsciiString& theScope = "") const;
//! Gets value of parameter as being of specific type
//! @param[in] theParam complex parameter name
//! @param[out] theValue value to get by parameter
//! @param[in] theScope base parameter name
//! @return Standard_False if parameter is not defined or has a wrong type
Standard_EXPORT Standard_Boolean GetString(const TCollection_AsciiString& theParam,
TCollection_AsciiString& theValue,
const TCollection_AsciiString& theScope = "") const;
//! Gets value of parameter as being of specific type
//! @param[in] theParam complex parameter name
//! @param[out] theValue value to get by parameter
//! @param[in] theScope base parameter name
//! @return Standard_False if parameter is not defined or has a wrong type
Standard_EXPORT Standard_Boolean GetStringSeq(const TCollection_AsciiString& theParam,
TColStd_ListOfAsciiString& theValue,
const TCollection_AsciiString& theScope = "") const;
//! Gets value of parameter as being of specific type
//! @param[in] theParam complex parameter name
//! @param[in] theDefValue value by default if param is not found or has wrong type
//! @param[in] theScope base parameter name
//! @return specific type value
Standard_EXPORT Standard_Real RealVal(const TCollection_AsciiString& theParam,
const Standard_Real theDefValue,
const TCollection_AsciiString& theScope = "") const;
//! Gets value of parameter as being of specific type
//! @param[in] theParam complex parameter name
//! @param[in] theDefValue value by default if param is not found or has wrong type
//! @param[in] theScope base parameter name
//! @return specific type value
Standard_EXPORT Standard_Integer IntegerVal(const TCollection_AsciiString& theParam,
const Standard_Integer theDefValue,
const TCollection_AsciiString& theScope = "") const;
//! Gets value of parameter as being of specific type
//! @param[in] theParam complex parameter name
//! @param[in] theDefValue value by default if param is not found or has wrong type
//! @param[in] theScope base parameter name
//! @return specific type value
Standard_EXPORT Standard_Boolean BooleanVal(const TCollection_AsciiString& theParam,
const Standard_Boolean theDefValue,
const TCollection_AsciiString& theScope = "") const;
//! Gets value of parameter as being of specific type
//! @param[in] theParam complex parameter name
//! @param[in] theDefValue value by default if param is not found or has wrong type
//! @param[in] theScope base parameter name
//! @return specific type value
Standard_EXPORT TCollection_AsciiString StringVal(const TCollection_AsciiString& theParam,
const TCollection_AsciiString& theDefValue,
const TCollection_AsciiString& theScope = "") const;
//! Gets internal resource map
//! @return map with resource value
Standard_EXPORT const DE_ResourceMap& GetInternalMap() const { return myResource; }
protected:
//! Update the resource with param value from the line
//! @paramp[in] theResourceLine line contains the parameter
//! @return true if theResourceLine has loaded correctly
Standard_Boolean load(const TCollection_AsciiString& theResourceLine);
private:
DE_ResourceMap myResource; //!< Internal parameters map
};
#endif // _DE_ConfigurationContext_HeaderFile

View File

@ -0,0 +1,149 @@
// 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 <DE_ConfigurationNode.hxx>
#include <DE_Provider.hxx>
#include <DE_Wrapper.hxx>
#include <DE_ConfigurationContext.hxx>
#include <Message.hxx>
#include <OSD_File.hxx>
#include <OSD_Path.hxx>
#include <OSD_Protection.hxx>
IMPLEMENT_STANDARD_RTTIEXT(DE_ConfigurationNode, Standard_Transient)
//=======================================================================
// function : DE_ConfigurationNode
// purpose :
//=======================================================================
DE_ConfigurationNode::DE_ConfigurationNode() :
myIsEnabled(Standard_True)
{}
//=======================================================================
// function : DE_ConfigurationNode
// purpose :
//=======================================================================
DE_ConfigurationNode::DE_ConfigurationNode(const Handle(DE_ConfigurationNode)& theConfigurationNode)
{
GlobalParameters = theConfigurationNode->GlobalParameters;
myIsEnabled = theConfigurationNode->IsEnabled();
}
//=======================================================================
// function : Load
// purpose :
//=======================================================================
bool DE_ConfigurationNode::Load(const TCollection_AsciiString& theResourcePath)
{
Handle(DE_ConfigurationContext) aResource = new DE_ConfigurationContext();
aResource->LoadFile(theResourcePath);
return Load(aResource);
}
//=======================================================================
// function : Save
// purpose :
//=======================================================================
bool DE_ConfigurationNode::Save(const TCollection_AsciiString& theResourcePath) const
{
OSD_Path aPath = theResourcePath;
OSD_File aFile(aPath);
OSD_Protection aProt;
{
try
{
OCC_CATCH_SIGNALS
aFile.Build(OSD_ReadWrite, aProt);
}
catch (Standard_Failure const&)
{
Message::SendFail() << "Error: Configuration writing process was stopped. Can't build file.";
return false;
}
}
if (aFile.Failed())
{
Message::SendFail() << "Error: Configuration writing process was stopped. Can't build file.";
return false;
}
TCollection_AsciiString aResConfiguration = Save();
aFile.Write(aResConfiguration, aResConfiguration.Length());
aFile.Close();
return true;
}
//=======================================================================
// function : UpdateLoad
// purpose :
//=======================================================================
bool DE_ConfigurationNode::UpdateLoad()
{
return true;
}
//=======================================================================
// function : IsImportSupported
// purpose :
//=======================================================================
bool DE_ConfigurationNode::IsImportSupported() const
{
return false;
}
//=======================================================================
// function : IsExportSupported
// purpose :
//=======================================================================
bool DE_ConfigurationNode::IsExportSupported() const
{
return false;
}
//=======================================================================
// function : CheckForSupport
// purpose :
//=======================================================================
bool DE_ConfigurationNode::CheckExtension(const TCollection_AsciiString& theExtension) const
{
TCollection_AsciiString anExtension(theExtension);
if (anExtension.IsEmpty())
{
return false;
}
if (anExtension.Value(1) == '.')
{
anExtension.Remove(1);
}
const TColStd_ListOfAsciiString& anExtensions = GetExtensions();
for (TColStd_ListOfAsciiString::Iterator anIter(anExtensions);
anIter.More(); anIter.Next())
{
if (TCollection_AsciiString::IsSameString(anIter.Value(), anExtension, Standard_False))
{
return true;
}
}
return false;
}
//=======================================================================
// function : CheckForSupport
// purpose :
//=======================================================================
bool DE_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const
{
(void)theBuffer;
return false;
}

View File

@ -0,0 +1,154 @@
// 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 _DE_ConfigurationNode_HeaderFile
#define _DE_ConfigurationNode_HeaderFile
#include <TColStd_ListOfAsciiString.hxx>
class DE_ConfigurationContext;
class DE_Provider;
class NCollection_Buffer;
//! Base class to work with CAD transfer properties.
//! Stores the necessary settings for a single Provider type.
//! Configures and creates special provider to transfer CAD files.
//!
//! Nodes are grouped by Vendor's name and Format type.
//! The Vendor name is not defined by default.
//! The Format type is not defined by default.
//! The supported CAD extensions are not defined by default.
//! The import process is not supported.
//! The export process is not supported.
//!
//! The algorithm for standalone transfer operation:
//! 1) Create new empty Node object
//! 2) Configure the current Node
//! 2.1) Use the external resource file to configure (::Load)
//! 2.2) Change the internal parameters directly:
//! 2.2.1) Change field values of "GlobalParameters"
//! 2.2.2) Change field values of "InternalParameters"
//! 3) Create one-time transfer provider (::BuildProvider)
//! 4) Initiate the transfer process:
//! 4.1) Import (if "::IsImportSupported: returns TRUE)
//! 4.1.1) Validate the support of input format (::CheckContent or ::CheckExtension)
//! 4.1.2) Use created provider's "::Read" method
//! 4.2) Export (if "::IsExportSupported: returns TRUE)
//! 4.2.1) Use created provider's "::Write" method
//! 5) Check the provider's output
class DE_ConfigurationNode : public Standard_Transient
{
DEFINE_STANDARD_RTTIEXT(DE_ConfigurationNode, Standard_Transient)
public:
//! Initializes all field by default
Standard_EXPORT DE_ConfigurationNode();
//! Copies values of all fields
//! @param[in] theConfigurationNode object to copy
Standard_EXPORT DE_ConfigurationNode(const Handle(DE_ConfigurationNode)& theConfigurationNode);
//! Updates values according the resource file
//! @param[in] theResourcePath file path to resource
//! @return True if Load was successful
Standard_EXPORT virtual bool Load(const TCollection_AsciiString& theResourcePath = "");
//! Updates values according the resource
//! @param[in] theResource input resource to use
//! @return True if Load was successful
Standard_EXPORT virtual bool Load(const Handle(DE_ConfigurationContext)& theResource) = 0;
//! Writes configuration to the resource file
//! @param[in] theResourcePath file path to resource
//! @return True if Save was successful
Standard_EXPORT bool Save(const TCollection_AsciiString& theResourcePath) const;
//! Writes configuration to the string
//! @return result resource string
Standard_EXPORT virtual TCollection_AsciiString Save() const = 0;
//! Creates new provider for the own format
//! @return new created provider
Standard_EXPORT virtual Handle(DE_Provider) BuildProvider() = 0;
//! Copies values of all fields
//! @return new object with the same field values
Standard_EXPORT virtual Handle(DE_ConfigurationNode) Copy() const = 0;
//! Update loading status. Checking for the license.
//! @return Standard_True, if node can be used
Standard_EXPORT virtual bool UpdateLoad();
public:
//! Checks the import supporting
//! @return Standard_True if import is support
Standard_EXPORT virtual bool IsImportSupported() const;
//! Checks the export supporting
//! @return Standard_True if export is support
Standard_EXPORT virtual bool IsExportSupported() const;
//! Gets CAD format name of associated provider
//! @return provider CAD format
Standard_EXPORT virtual TCollection_AsciiString GetFormat() const = 0;
//! Gets provider's vendor name of associated provider
//! @return provider's vendor name
Standard_EXPORT virtual TCollection_AsciiString GetVendor() const = 0;
//! Gets list of supported file extensions
//! @return list of extensions
Standard_EXPORT virtual TColStd_ListOfAsciiString GetExtensions() const = 0;
//! Checks the file extension to verify a format
//! @param[in] theExtension input file extension
//! @return Standard_True if file is supported by a current provider
Standard_EXPORT virtual bool CheckExtension(const TCollection_AsciiString& theExtension) const;
//! 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;
public:
//! Gets the provider loading status
//! @return Standard_True if the load is correct
Standard_Boolean IsEnabled() const
{
return myIsEnabled;
}
//! Sets the provider loading status
//! @param[in] theIsLoaded input load status
void SetEnabled(const Standard_Boolean theIsLoaded)
{
myIsEnabled = theIsLoaded;
}
public:
//!< Internal parameters for transfer process
struct DE_SectionGlobal
{
Standard_Real LengthUnit = 1.0; //!< Scale length unit value from MM, default 1.0 (MM)
} GlobalParameters;
private:
Standard_Boolean myIsEnabled; //!< Flag to use a current provider for Read or Write process via DE_Wrapper
};
#endif // _DE_ConfigurationNode_HeaderFile

170
src/DE/DE_Provider.cxx Normal file
View File

@ -0,0 +1,170 @@
// 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 <DE_Provider.hxx>
#include <DE_ConfigurationNode.hxx>
#include <Message.hxx>
IMPLEMENT_STANDARD_RTTIEXT(DE_Provider, Standard_Transient)
//=======================================================================
// function : DE_Provider
// purpose :
//=======================================================================
DE_Provider::DE_Provider()
{}
//=======================================================================
// function : DE_Provider
// purpose :
//=======================================================================
DE_Provider::DE_Provider(const Handle(DE_ConfigurationNode)& theNode)
:myNode(theNode)
{}
//=======================================================================
// function : Read
// purpose :
//=======================================================================
Standard_Boolean DE_Provider::Read(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
(void)thePath;
(void)theDocument;
(void)theWS;
(void)theProgress;
Message::SendFail() << "Error: provider " << GetFormat() <<
" " << GetVendor() <<" doesn't support read operation";
return Standard_False;
}
//=======================================================================
// function : Write
// purpose :
//=======================================================================
Standard_Boolean DE_Provider::Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
(void)thePath;
(void)theDocument;
(void)theWS;
(void)theProgress;
Message::SendFail() << "Error: provider " << GetFormat() <<
" " << GetVendor() << " doesn't support write operation";
return Standard_False;
}
//=======================================================================
// function : Read
// purpose :
//=======================================================================
Standard_Boolean DE_Provider::Read(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress)
{
(void)thePath;
(void)theDocument;
(void)theProgress;
Message::SendFail() << "Error: provider " << GetFormat() <<
" " << GetVendor() << " doesn't support read operation";
return Standard_False;
}
//=======================================================================
// function : Write
// purpose :
//=======================================================================
Standard_Boolean DE_Provider::Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress)
{
(void)thePath;
(void)theDocument;
(void)theProgress;
Message::SendFail() << "Error: provider " << GetFormat() <<
" " << GetVendor() << " doesn't support write operation";
return Standard_False;
}
//=======================================================================
// function : Read
// purpose :
//=======================================================================
Standard_Boolean DE_Provider::Read(const TCollection_AsciiString& thePath,
TopoDS_Shape& theShape,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
(void)thePath;
(void)theShape;
(void)theWS;
(void)theProgress;
Message::SendFail() << "Error: provider " << GetFormat() <<
" " << GetVendor() << " doesn't support read operation";
return Standard_False;
}
//=======================================================================
// function : Write
// purpose :
//=======================================================================
Standard_Boolean DE_Provider::Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
(void)thePath;
(void)theShape;
(void)theWS;
(void)theProgress;
Message::SendFail() << "Error: provider " << GetFormat() <<
" " << GetVendor() << " doesn't support write operation";
return Standard_False;
}
//=======================================================================
// function : Read
// purpose :
//=======================================================================
Standard_Boolean DE_Provider::Read(const TCollection_AsciiString& thePath,
TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress)
{
(void)thePath;
(void)theShape;
(void)theProgress;
Message::SendFail() << "Error: provider " << GetFormat() <<
" " << GetVendor() << " doesn't support read operation";
return Standard_False;
}
//=======================================================================
// function : Write
// purpose :
//=======================================================================
Standard_Boolean DE_Provider::Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress)
{
(void)thePath;
(void)theShape;
(void)theProgress;
Message::SendFail() << "Error: provider " << GetFormat() <<
" " << GetVendor() << " doesn't support write operation";
return Standard_False;
}

167
src/DE/DE_Provider.hxx Normal file
View File

@ -0,0 +1,167 @@
// 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 _DE_Provider_HeaderFile
#define _DE_Provider_HeaderFile
#include <Message_ProgressRange.hxx>
class DE_ConfigurationNode;
class TopoDS_Shape;
class XSControl_WorkSession;
class TDocStd_Document;
//! Base class to make transfer process.
//! Reads or Writes specialized CAD files into/from OCCT.
//! Each operation needs the Configuration Node.
//!
//! Providers are grouped by Vendor's name and Format type.
//! The Vendor name is not defined by default.
//! The Format type is not defined by default.
//! The import process is not supported.
//! The export process is not supported.
//!
//! The algorithm for standalone transfer operation:
//! 1) Create new empty Provider object
//! 2) Configure the current object by special Configuration Node (::SetNode)
//! 3) Initiate the transfer process:
//! 3.1) Call the required Read method (if Read methods are implemented)
//! 3.2) Call the required Write method (if Write methods are implemented)
//! 4) Validate the output values
class DE_Provider : public Standard_Transient
{
public:
DEFINE_STANDARD_RTTIEXT(DE_Provider, Standard_Transient)
public:
//! Default constructor
//! Configure translation process with global configuration
Standard_EXPORT DE_Provider();
//! Configure translation process
//! @param[in] theNode object to copy
Standard_EXPORT DE_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 theProgress[in] progress indicator
//! @return True if Read was successful
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());
//! 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 theProgress[in] progress indicator
//! @return True if Write was successful
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());
//! Reads a CAD file, according internal configuration
//! @param[in] thePath path to the import CAD file
//! @param[out] theDocument document to save result
//! @param theProgress[in] progress indicator
//! @return True if Read was successful
Standard_EXPORT virtual Standard_Boolean Read(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Writes a CAD file, according internal configuration
//! @param[in] thePath path to the export CAD file
//! @param[out] theDocument document to export
//! @param theProgress[in] progress indicator
//! @return True if Write was successful
Standard_EXPORT virtual Standard_Boolean Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! 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 theProgress[in] progress indicator
//! @return True if Read was successful
Standard_EXPORT virtual Standard_Boolean Read(const TCollection_AsciiString& thePath,
TopoDS_Shape& theShape,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! 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 theProgress[in] progress indicator
//! @return True if Write was successful
Standard_EXPORT virtual Standard_Boolean Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Reads a CAD file, according internal configuration
//! @param[in] thePath path to the import CAD file
//! @param[out] theShape shape to save result
//! @param theProgress[in] progress indicator
//! @return True if Read was successful
Standard_EXPORT virtual Standard_Boolean Read(const TCollection_AsciiString& thePath,
TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Writes a CAD file, according internal configuration
//! @param[in] thePath path to the export CAD file
//! @param[out] theShape shape to export
//! @param theProgress[in] progress indicator
//! @return True if Write was successful
Standard_EXPORT virtual Standard_Boolean Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress = Message_ProgressRange());
public:
//! Gets CAD format name of associated provider
//! @return provider CAD format
Standard_EXPORT virtual TCollection_AsciiString GetFormat() const = 0;
//! Gets provider's vendor name of associated provider
//! @return provider's vendor name
Standard_EXPORT virtual TCollection_AsciiString GetVendor() const = 0;
//! Gets internal configuration node
//! @return configuration node object
Handle(DE_ConfigurationNode) GetNode() const
{
return myNode;
}
//! Sets internal configuration node
//! @param[in] theNode configuration node to set
void SetNode(const Handle(DE_ConfigurationNode)& theNode)
{
myNode = theNode;
}
private:
Handle(DE_ConfigurationNode) myNode; //!< Internal configuration for the own format
};
#endif // _DE_Provider_HeaderFile

540
src/DE/DE_Wrapper.cxx Normal file
View File

@ -0,0 +1,540 @@
// 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 <DE_Wrapper.hxx>
#include <DE_ConfigurationContext.hxx>
#include <DE_ConfigurationNode.hxx>
#include <DE_Provider.hxx>
#include <Message_ProgressRange.hxx>
#include <NCollection_Buffer.hxx>
#include <OSD_File.hxx>
#include <OSD_Path.hxx>
#include <OSD_FileSystem.hxx>
#include <OSD_Protection.hxx>
#include <Standard_ErrorHandler.hxx>
#include <TopoDS_Shape.hxx>
IMPLEMENT_STANDARD_RTTIEXT(DE_Wrapper, Standard_Transient)
static const TCollection_AsciiString THE_CONFIGURATION_SCOPE = "global";
//=======================================================================
// function : DE_Wrapper
// purpose :
//=======================================================================
DE_Wrapper::DE_Wrapper()
{}
//=======================================================================
// function : DE_Wrapper
// purpose :
//=======================================================================
DE_Wrapper::DE_Wrapper(const Handle(DE_Wrapper)& theWrapper)
: DE_Wrapper()
{
if (theWrapper.IsNull())
{
return;
}
GlobalParameters = theWrapper->GlobalParameters;
for (DE_ConfigurationFormatMap::Iterator aFormatIter(theWrapper->Nodes());
aFormatIter.More(); aFormatIter.Next())
{
for (DE_ConfigurationVendorMap::Iterator aVendorIter(aFormatIter.Value());
aVendorIter.More(); aVendorIter.Next())
{
Bind(aVendorIter.Value());
}
}
}
//=======================================================================
// function : GlobalWrapper
// purpose :
//=======================================================================
Handle(DE_Wrapper) DE_Wrapper::GlobalWrapper()
{
static const Handle(DE_Wrapper)& aConfiguration = new DE_Wrapper();
return aConfiguration;
}
//=======================================================================
// function : Read
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::Read(const TCollection_AsciiString& thePath,
Handle(TDocStd_Document)& theDocument,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
if (theDocument.IsNull())
{
return Standard_False;
}
if (theWS.IsNull())
{
return Read(thePath, theDocument, theProgress);
}
Handle(DE_Provider) aProvider;
if (!findProvider(thePath, Standard_True, aProvider))
{
return Standard_False;
}
return aProvider->Read(thePath, theDocument, theWS, theProgress);
}
//=======================================================================
// function : Write
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
if (theDocument.IsNull())
{
return Standard_False;
}
if (theWS.IsNull())
{
return Write(thePath, theDocument, theProgress);
}
Handle(DE_Provider) aProvider;
if (!findProvider(thePath, Standard_False, aProvider))
{
return Standard_False;
}
return aProvider->Write(thePath, theDocument, theWS, theProgress);
}
//=======================================================================
// function : Read
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::Read(const TCollection_AsciiString& thePath,
Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress)
{
if (theDocument.IsNull())
{
return Standard_False;
}
Handle(DE_Provider) aProvider;
if (!findProvider(thePath, Standard_True, aProvider))
{
return Standard_False;
}
return aProvider->Read(thePath, theDocument, theProgress);
}
//=======================================================================
// function : Write
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress)
{
if (theDocument.IsNull())
{
return Standard_False;
}
Handle(DE_Provider) aProvider;
if (!findProvider(thePath, Standard_False, aProvider))
{
return Standard_False;
}
return aProvider->Write(thePath, theDocument, theProgress);
}
//=======================================================================
// function : Read
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::Read(const TCollection_AsciiString& thePath,
TopoDS_Shape& theShape,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
if (theWS.IsNull())
{
return Read(thePath, theShape, theProgress);
}
Handle(DE_Provider) aProvider;
if (!findProvider(thePath, Standard_True, aProvider))
{
return Standard_False;
}
return aProvider->Read(thePath, theShape, theWS, theProgress);
}
//=======================================================================
// function : Write
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
if (theWS.IsNull())
{
return Write(thePath, theShape, theProgress);
}
Handle(DE_Provider) aProvider;
if (!findProvider(thePath, Standard_False, aProvider))
{
return Standard_False;
}
return aProvider->Write(thePath, theShape, theWS, theProgress);
}
//=======================================================================
// function : Read
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::Read(const TCollection_AsciiString& thePath,
TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress)
{
Handle(DE_Provider) aProvider;
if (!findProvider(thePath, Standard_True, aProvider))
{
return Standard_False;
}
return aProvider->Read(thePath, theShape, theProgress);
}
//=======================================================================
// function : Write
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress)
{
Handle(DE_Provider) aProvider;
if (!findProvider(thePath, Standard_False, aProvider))
{
return Standard_False;
}
return aProvider->Write(thePath, theShape, theProgress);
}
//=======================================================================
// function : Load
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::Load(const TCollection_AsciiString& theResource,
const Standard_Boolean theIsRecursive)
{
Handle(DE_ConfigurationContext) aResource = new DE_ConfigurationContext();
aResource->Load(theResource);
return Load(aResource, theIsRecursive);
}
//=======================================================================
// function : Load
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::Load(const Handle(DE_ConfigurationContext)& theResource,
const Standard_Boolean theIsRecursive)
{
GlobalParameters.LengthUnit = theResource->RealVal("general.length.unit", GlobalParameters.LengthUnit, THE_CONFIGURATION_SCOPE);
if (theIsRecursive)
{
for (DE_ConfigurationFormatMap::Iterator aFormatIter(myConfiguration);
aFormatIter.More(); aFormatIter.Next())
{
for (DE_ConfigurationVendorMap::Iterator aVendorIter(aFormatIter.Value());
aVendorIter.More(); aVendorIter.Next())
{
aVendorIter.Value()->Load(theResource);
}
}
sort(theResource);
}
return Standard_True;
}
//=======================================================================
// function : Save
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::Save(const TCollection_AsciiString& theResourcePath,
const Standard_Boolean theIsRecursive,
const TColStd_ListOfAsciiString& theFormats,
const TColStd_ListOfAsciiString& theVendors)
{
OSD_Path aPath = theResourcePath;
OSD_File aFile(aPath);
OSD_Protection aProt;
{
try
{
OCC_CATCH_SIGNALS
aFile.Build(OSD_ReadWrite, aProt);
}
catch (Standard_Failure const&)
{
return Standard_False;
}
}
if (aFile.Failed())
{
return Standard_False;
}
TCollection_AsciiString aResConfiguration = Save(theIsRecursive, theFormats, theVendors);
aFile.Write(aResConfiguration, aResConfiguration.Length());
aFile.Close();
return Standard_True;
}
//=======================================================================
// function : Save
// purpose :
//=======================================================================
TCollection_AsciiString DE_Wrapper::Save(const Standard_Boolean theIsRecursive,
const TColStd_ListOfAsciiString& theFormats,
const TColStd_ListOfAsciiString& theVendors)
{
TCollection_AsciiString aResult;
aResult += "!Description of the config file for DE toolkit\n";
aResult += "!*****************************************************************************\n";
aResult += "!\n";
aResult += "!Format of the file is compliant with the standard Open CASCADE resource files\n";
aResult += "!Each key defines a sequence of either further keys.\n";
aResult += "!Keys can be nested down to an arbitrary level.\n";
aResult += "!\n";
aResult += "!*****************************************************************************\n";
aResult += "!DE_Wrapper\n";
aResult += "!Priority vendor list. For every CAD format set indexed list of vendors\n";
for (DE_ConfigurationFormatMap::Iterator aFormatIter(myConfiguration);
aFormatIter.More(); aFormatIter.Next())
{
const TCollection_AsciiString& aFormat = aFormatIter.Key();
aResult += THE_CONFIGURATION_SCOPE + '.' + "priority" + '.' + aFormat + " :\t ";
for (DE_ConfigurationVendorMap::Iterator aVendorIter(aFormatIter.Value());
aVendorIter.More(); aVendorIter.Next())
{
const TCollection_AsciiString& aVendorName = aVendorIter.Value()->GetVendor();
aResult += aVendorName + " ";
}
aResult += "\n";
}
aResult += "!Global parameters. Used for all providers\n";
aResult += "!Length scale unit value. Should be more the 0. Default value: 1.0(MM)\n";
aResult += THE_CONFIGURATION_SCOPE + ".general.length.unit :\t " + GlobalParameters.LengthUnit + "\n";
if (theIsRecursive)
{
for (DE_ConfigurationFormatMap::Iterator aFormatIter(myConfiguration);
aFormatIter.More(); aFormatIter.Next())
{
if (!theFormats.IsEmpty() && !theFormats.Contains(aFormatIter.Key()))
{
continue;
}
for (DE_ConfigurationVendorMap::Iterator aVendorIter(aFormatIter.Value());
aVendorIter.More(); aVendorIter.Next())
{
if (!theVendors.IsEmpty() && !theVendors.Contains(aVendorIter.Key()))
{
continue;
}
aResult += "!\n";
aResult += aVendorIter.Value()->Save();
aResult += "!\n";
}
}
}
aResult += "!*****************************************************************************\n";
return aResult;
}
//=======================================================================
// function : Bind
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::Bind(const Handle(DE_ConfigurationNode)& theNode)
{
if (theNode.IsNull())
{
return Standard_False;
}
const TCollection_AsciiString aFileFormat = theNode->GetFormat();
const TCollection_AsciiString aVendorName = theNode->GetVendor();
DE_ConfigurationVendorMap* aVendorMap = myConfiguration.ChangeSeek(aFileFormat);
if (aVendorMap == NULL)
{
DE_ConfigurationVendorMap aTmpVendorMap;
aVendorMap = myConfiguration.Bound(aFileFormat, aTmpVendorMap);
}
return aVendorMap->Add(aVendorName, theNode) > 0;
}
//=======================================================================
// function : Find
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::Find(const TCollection_AsciiString& theFormat,
const TCollection_AsciiString& theVendor,
Handle(DE_ConfigurationNode)& theNode) const
{
const DE_ConfigurationVendorMap* aVendorMap = myConfiguration.Seek(theFormat);
return aVendorMap != nullptr && aVendorMap->FindFromKey(theVendor, theNode);
}
//=======================================================================
// function : ChangePriority
// purpose :
//=======================================================================
void DE_Wrapper::ChangePriority(const TCollection_AsciiString& theFormat,
const TColStd_ListOfAsciiString& theVendorPriority,
const Standard_Boolean theToDisable)
{
DE_ConfigurationVendorMap aVendorMap;
if (!myConfiguration.Find(theFormat, aVendorMap))
{
return;
}
DE_ConfigurationVendorMap aNewVendorMap;
// Sets according to the input priority
for (TColStd_ListOfAsciiString::Iterator aPriorIter(theVendorPriority);
aPriorIter.More(); aPriorIter.Next())
{
const TCollection_AsciiString& aVendorName = aPriorIter.Value();
Handle(DE_ConfigurationNode) aNode;
if (aVendorMap.FindFromKey(aVendorName, aNode))
{
aNode->SetEnabled(Standard_True);
aNode->UpdateLoad();
aNewVendorMap.Add(aVendorName, aNode);
}
}
// Sets not used elements
for (DE_ConfigurationVendorMap::Iterator aVendorIter(aVendorMap);
aVendorIter.More(); aVendorIter.Next())
{
const TCollection_AsciiString& aVendorName = aVendorIter.Key();
if (!theVendorPriority.Contains(aVendorName))
{
Handle(DE_ConfigurationNode) aNode = aVendorIter.Value();
if (theToDisable)
{
aNode->SetEnabled(Standard_False);
}
aNewVendorMap.Add(aVendorName, aNode);
}
}
myConfiguration.Bind(theFormat, aNewVendorMap);
}
//=======================================================================
// function : ChangePriority
// purpose :
//=======================================================================
void DE_Wrapper::ChangePriority(const TColStd_ListOfAsciiString& theVendorPriority,
const Standard_Boolean theToDisable)
{
for (DE_ConfigurationFormatMap::Iterator aFormatIter(myConfiguration);
aFormatIter.More(); aFormatIter.Next())
{
ChangePriority(aFormatIter.Key(), theVendorPriority, theToDisable);
}
}
//=======================================================================
// function : Nodes
// purpose :
//=======================================================================
const DE_ConfigurationFormatMap& DE_Wrapper::Nodes() const
{
return myConfiguration;
}
//=======================================================================
// function : Copy
// purpose :
//=======================================================================
Handle(DE_Wrapper) DE_Wrapper::Copy() const
{
return new DE_Wrapper(*this);
}
//=======================================================================
// function : findProvider
// purpose :
//=======================================================================
Standard_Boolean DE_Wrapper::findProvider(const TCollection_AsciiString& thePath,
const Standard_Boolean theToImport,
Handle(DE_Provider)& theProvider) const
{
Handle(NCollection_Buffer) aBuffer;
if (theToImport)
{
const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream(thePath, std::ios::in | std::ios::binary);
if (aStream.get() != nullptr)
{
aBuffer = new NCollection_Buffer(NCollection_BaseAllocator::CommonBaseAllocator(), 2048);
aStream->read((char*)aBuffer->ChangeData(), 2048);
aBuffer->ChangeData()[2047] = '\0';
}
}
OSD_Path aPath(thePath);
const TCollection_AsciiString anExtr = aPath.Extension();
for (DE_ConfigurationFormatMap::Iterator aFormatIter(myConfiguration);
aFormatIter.More(); aFormatIter.Next())
{
for (DE_ConfigurationVendorMap::Iterator aVendorIter(aFormatIter.Value());
aVendorIter.More(); aVendorIter.Next())
{
const Handle(DE_ConfigurationNode)& aNode = aVendorIter.Value();
if (aNode->IsEnabled() &&
((theToImport && aNode->IsImportSupported()) ||
(!theToImport && aNode->IsExportSupported())) &&
(aNode->CheckExtension(anExtr) ||
(theToImport && aNode->CheckContent(aBuffer))))
{
theProvider = aNode->BuildProvider();
aNode->GlobalParameters = GlobalParameters;
theProvider->SetNode(aNode);
return Standard_True;
}
}
}
return Standard_False;
}
//=======================================================================
// function : sort
// purpose :
//=======================================================================
void DE_Wrapper::sort(const Handle(DE_ConfigurationContext)& theResource)
{
const TCollection_AsciiString aScope(THE_CONFIGURATION_SCOPE + '.' + "priority");
NCollection_List<Handle(DE_ConfigurationNode)> aVendors;
for (DE_ConfigurationFormatMap::Iterator aFormatIter(myConfiguration);
aFormatIter.More(); aFormatIter.Next())
{
TColStd_ListOfAsciiString aVendorPriority;
if (!theResource->GetStringSeq(aFormatIter.Key(), aVendorPriority, aScope))
{
continue;
}
ChangePriority(aFormatIter.Key(), aVendorPriority, Standard_True);
}
}

249
src/DE/DE_Wrapper.hxx Normal file
View File

@ -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.
#ifndef _DE_Wrapper_HeaderFile
#define _DE_Wrapper_HeaderFile
#include <Message_ProgressRange.hxx>
#include <DE_ConfigurationNode.hxx>
#include <NCollection_IndexedDataMap.hxx>
#include <NCollection_DataMap.hxx>
#include <TColStd_ListOfAsciiString.hxx>
class TopoDS_Shape;
class XSControl_WorkSession;
class TDocStd_Document;
typedef NCollection_IndexedDataMap<TCollection_AsciiString, Handle(DE_ConfigurationNode), TCollection_AsciiString> DE_ConfigurationVendorMap;
typedef NCollection_DataMap<TCollection_AsciiString, DE_ConfigurationVendorMap, TCollection_AsciiString> DE_ConfigurationFormatMap;
//! The main class for working with CAD file exchange.
//! Loads and Saves special CAD transfer property.
//! Consolidates all supported Formats and Vendors.
//! Automatically recognizes CAD format and uses the preferred existed Vendor.
//! Note:
//! If Vendor's format is not binded, the configuration loading doesn't affect on its property.
//!
//! Nodes are grouped by Vendor's name and Format's type.
//! The Vendors may have the same supported CAD formats.
//! Use a Vendor's priority for transfer operations.
//!
//! The algorithm for standalone transfer operation:
//! 1) Work with global wrapper directly or make deep copy and work with it
//! 2) Update the supported vendors and formats
//! 2.1) Create and initialize specialized configuration node of the required format and Vendor.
//! 2.2) Bind the created node to the internal map(::Bind)
//! 3) Configure the transfer property by resource string or file (::Load)
//! 3.1) Configuration can disable or enable some Vendors and formats
//! 3.2) Configuration can change the priority of Vendors
//! 4) Initiate the transfer process by calling "::Write" or "::Read" methods
//! 5) Validate the transfer process output
class DE_Wrapper : public Standard_Transient
{
DEFINE_STANDARD_RTTIEXT(DE_Wrapper, Standard_Transient)
public:
//! Initializes all field by default
Standard_EXPORT DE_Wrapper();
//! Copies values of all fields
//! @param[in] theWrapper object to copy
Standard_EXPORT DE_Wrapper(const Handle(DE_Wrapper)& theWrapper);
//! Gets global configuration singleton
//! @return point to global configuration
Standard_EXPORT static Handle(DE_Wrapper) GlobalWrapper();
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 theProgress[in] progress indicator
//! @return true if Read operation has ended correctly
Standard_EXPORT Standard_Boolean Read(const TCollection_AsciiString& thePath,
Handle(TDocStd_Document)& theDocument,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! 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 theProgress[in] progress indicator
//! @return true if Write operation has ended correctly
Standard_EXPORT Standard_Boolean Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Reads a CAD file, according internal configuration
//! @param[in] thePath path to the import CAD file
//! @param[out] theDocument document to save result
//! @param theProgress[in] progress indicator
//! @return true if Read operation has ended correctly
Standard_EXPORT Standard_Boolean Read(const TCollection_AsciiString& thePath,
Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Writes a CAD file, according internal configuration
//! @param[in] thePath path to the export CAD file
//! @param[out] theDocument document to export
//! @param theProgress[in] progress indicator
//! @return true if Write operation has ended correctly
Standard_EXPORT Standard_Boolean Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! 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 theProgress[in] progress indicator
//! @return true if Read operation has ended correctly
Standard_EXPORT Standard_Boolean Read(const TCollection_AsciiString& thePath,
TopoDS_Shape& theShape,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! 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 theProgress[in] progress indicator
//! @return true if Write operation has ended correctly
Standard_EXPORT Standard_Boolean Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Reads a CAD file, according internal configuration
//! @param[in] thePath path to the import CAD file
//! @param[out] theShape shape to save result
//! @param theProgress[in] progress indicator
//! @return true if Read operation has ended correctly
Standard_EXPORT Standard_Boolean Read(const TCollection_AsciiString& thePath,
TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Writes a CAD file, according internal configuration
//! @param[in] thePath path to the export CAD file
//! @param[out] theShape shape to export
//! @param theProgress[in] progress indicator
//! @return true if Write operation has ended correctly
Standard_EXPORT Standard_Boolean Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress = Message_ProgressRange());
public:
//! Updates values according the resource file
//! @param[in] theResource file path to resource or resource value
//! @param[in] theIsRecursive flag to update all nodes
//! @return true if theResource has loaded correctly
Standard_EXPORT Standard_Boolean Load(const TCollection_AsciiString& theResource = "",
const Standard_Boolean theIsRecursive = Standard_True);
//! Updates values according the resource
//! @param[in] theResource input resource to use
//! @param[in] theIsRecursive flag to update all nodes
//! @return true if theResource has loaded correctly
Standard_EXPORT Standard_Boolean Load(const Handle(DE_ConfigurationContext)& theResource,
const Standard_Boolean theIsRecursive = Standard_True);
//! Writes configuration to the resource file
//! @param[in] theResourcePath file path to resource
//! @param[in] theIsRecursive flag to write values of all nodes
//! @param[in] theFormats list of formats to save. If empty, saves all available
//! @param[in] theVendors list of providers to save. If empty, saves all available
//! @return true if the Configuration has saved correctly
Standard_EXPORT Standard_Boolean Save(const TCollection_AsciiString& theResourcePath,
const Standard_Boolean theIsRecursive = Standard_True,
const TColStd_ListOfAsciiString& theFormats = TColStd_ListOfAsciiString(),
const TColStd_ListOfAsciiString& theVendors = TColStd_ListOfAsciiString());
//! Writes configuration to the string
//! @param[in] theIsRecursive flag to write values of all nodes
//! @param[in] theFormats list of formats to save. If empty, saves all available
//! @param[in] theVendors list of providers to save. If empty, saves all available
//! @return result resource string
Standard_EXPORT TCollection_AsciiString Save(const Standard_Boolean theIsRecursive = Standard_True,
const TColStd_ListOfAsciiString& theFormats = TColStd_ListOfAsciiString(),
const TColStd_ListOfAsciiString& theVendors = TColStd_ListOfAsciiString());
//! Creates new node copy and adds to the map
//! @param[in] theNode input node to copy
//! @return Standard_True if binded
Standard_EXPORT Standard_Boolean Bind(const Handle(DE_ConfigurationNode)& theNode);
//! Finds a node associated with input format and vendor
//! @param[in] theFormat input node CAD format
//! @param[in] theVendor input node vendor name
//! @param[out] theNode output node
//! @return Standard_True if the node is found
Standard_EXPORT Standard_Boolean Find(const TCollection_AsciiString& theFormat,
const TCollection_AsciiString& theVendor,
Handle(DE_ConfigurationNode)& theNode) const;
//! Changes provider priority to one format if it exists
//! @param[in] theFormat input node CAD format
//! @param[in] theVendorPriority priority of work with vendors
//! @param[in] theToDisable flag for disabling nodes that are not included in the priority
Standard_EXPORT void ChangePriority(const TCollection_AsciiString& theFormat,
const TColStd_ListOfAsciiString& theVendorPriority,
const Standard_Boolean theToDisable = Standard_False);
//! Changes provider priority to all loaded nodes
//! @param[in] theVendorPriority priority of work with vendors
//! @param[in] theToDisable flag for disabling nodes that are not included in the priority
Standard_EXPORT void ChangePriority(const TColStd_ListOfAsciiString& theVendorPriority,
const Standard_Boolean theToDisable = Standard_False);
//! Gets format map, contains vendor map with nodes
//! @return internal map of formats
Standard_EXPORT const DE_ConfigurationFormatMap& Nodes() const;
//! Copies values of all fields
//! @return new object with the same field values
Standard_EXPORT Handle(DE_Wrapper) Copy() const;
protected:
//! Sorts the vendors according to the priority to work
//! Formats omitted from the resource are not modified
//! Vendors omitted from the format scope are disabled
//! @param[in] theResource resource to get priority
void sort(const Handle(DE_ConfigurationContext)& theResource);
//! Find available provider from the configuration.
//! If there are several providers, choose the one with the highest priority.
//! @param[in] thePath path to the CAD file
//! @param[in] theToImport flag to finds for import. Standard_True-import, Standard_False-export
//! @param[out] theProvider created new provider
//! @return Standard_True if provider found and created
Standard_Boolean findProvider(const TCollection_AsciiString& thePath,
const Standard_Boolean theToImport,
Handle(DE_Provider)& theProvider) const;
public:
DE_ConfigurationNode::DE_SectionGlobal GlobalParameters; //!< Internal parameters for the all translators
private:
DE_ConfigurationFormatMap myConfiguration; //!< Internal map of formats
};
#endif // _DE_Wrapper_HeaderFile

8
src/DE/FILES Normal file
View File

@ -0,0 +1,8 @@
DE_ConfigurationContext.cxx
DE_ConfigurationContext.hxx
DE_ConfigurationNode.cxx
DE_ConfigurationNode.hxx
DE_Provider.cxx
DE_Provider.hxx
DE_Wrapper.cxx
DE_Wrapper.hxx

View File

@ -0,0 +1,199 @@
// 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 <DEBRepCascade_ConfigurationNode.hxx>
#include <DE_ConfigurationContext.hxx>
#include <DEBRepCascade_Provider.hxx>
#include <NCollection_Buffer.hxx>
IMPLEMENT_STANDARD_RTTIEXT(DEBRepCascade_ConfigurationNode, DE_ConfigurationNode)
static const TCollection_AsciiString THE_CONFIGURATION_SCOPE = "provider";
//=======================================================================
// function : DEBRepCascade_ConfigurationNode
// purpose :
//=======================================================================
DEBRepCascade_ConfigurationNode::DEBRepCascade_ConfigurationNode() :
DE_ConfigurationNode()
{
UpdateLoad();
}
//=======================================================================
// function : DEBRepCascade_ConfigurationNode
// purpose :
//=======================================================================
DEBRepCascade_ConfigurationNode::DEBRepCascade_ConfigurationNode(const Handle(DEBRepCascade_ConfigurationNode)& theNode)
:DE_ConfigurationNode(theNode)
{
InternalParameters = theNode->InternalParameters;
UpdateLoad();
}
//=======================================================================
// function : Load
// purpose :
//=======================================================================
bool DEBRepCascade_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource)
{
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);
InternalParameters.WriteVersionAscii =
(TopTools_FormatVersion)theResource->IntegerVal("write.version.ascii", InternalParameters.WriteVersionAscii, aScope);
InternalParameters.WriteTriangles =
theResource->BooleanVal("write.triangles", InternalParameters.WriteTriangles, aScope);
InternalParameters.WriteNormals =
theResource->BooleanVal("write.normals", InternalParameters.WriteNormals, aScope);
return true;
}
//=======================================================================
// function : Save
// purpose :
//=======================================================================
TCollection_AsciiString DEBRepCascade_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 += "!Write parameters:\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines the binary file format\n";
aResult += "!Default value: 1. Available values: 0(\"off\"), 1(\"on\")\n";
aResult += aScope + "write.binary :\t " + InternalParameters.WriteBinary + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines the format version for the binary format writing\n";
aResult += "!Default value: 4. Available values: 1, 2, 3, 4\n";
aResult += aScope + "write.version.binary :\t " + InternalParameters.WriteVersionBin + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines the format version for the ASCII format writing\n";
aResult += "!Default value: 3. Available values: 1, 2, 3\n";
aResult += aScope + "write.version.ascii :\t " + InternalParameters.WriteVersionAscii + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines the flag for storing shape with(without) triangles\n";
aResult += "!Default value: 1. Available values: 0(\"off\"), 1(\"on\")\n";
aResult += aScope + "write.triangles :\t " + InternalParameters.WriteTriangles + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines the flag for storing shape with(without) normals\n";
aResult += "!Default value: 1. Available values: 0(\"off\"), 1(\"on\")\n";
aResult += aScope + "write.normals :\t " + InternalParameters.WriteNormals + "\n";
aResult += "!\n";
aResult += "!*****************************************************************************\n";
return aResult;
}
//=======================================================================
// function : Copy
// purpose :
//=======================================================================
Handle(DE_ConfigurationNode) DEBRepCascade_ConfigurationNode::Copy() const
{
return new DEBRepCascade_ConfigurationNode(*this);
}
//=======================================================================
// function : BuildProvider
// purpose :
//=======================================================================
Handle(DE_Provider) DEBRepCascade_ConfigurationNode::BuildProvider()
{
return new DEBRepCascade_Provider(this);
}
//=======================================================================
// function : IsImportSupported
// purpose :
//=======================================================================
bool DEBRepCascade_ConfigurationNode::IsImportSupported() const
{
return true;
}
//=======================================================================
// function : IsExportSupported
// purpose :
//=======================================================================
bool DEBRepCascade_ConfigurationNode::IsExportSupported() const
{
return true;
}
//=======================================================================
// function : GetFormat
// purpose :
//=======================================================================
TCollection_AsciiString DEBRepCascade_ConfigurationNode::GetFormat() const
{
return TCollection_AsciiString("BREP");
}
//=======================================================================
// function : GetVendor
// purpose :
//=======================================================================
TCollection_AsciiString DEBRepCascade_ConfigurationNode::GetVendor() const
{
return TCollection_AsciiString("OCC");
}
//=======================================================================
// function : GetExtensions
// purpose :
//=======================================================================
TColStd_ListOfAsciiString DEBRepCascade_ConfigurationNode::GetExtensions() const
{
TColStd_ListOfAsciiString anExt;
anExt.Append("brep");
return anExt;
}
//=======================================================================
// function : CheckContent
// purpose :
//=======================================================================
bool DEBRepCascade_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"))
{
return true;
}
return false;
}

View File

@ -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 _DEBRepCascade_ConfigurationNode_HeaderFile
#define _DEBRepCascade_ConfigurationNode_HeaderFile
#include <DE_ConfigurationNode.hxx>
#include <BinTools_FormatVersion.hxx>
#include <TopTools_FormatVersion.hxx>
//! 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
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
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 // _DEBRepCascade_ConfigurationNode_HeaderFile

View File

@ -0,0 +1,295 @@
// 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 <DEBRepCascade_Provider.hxx>
#include <BinTools.hxx>
#include <BinXCAFDrivers.hxx>
#include <BRep_Builder.hxx>
#include <BRepTools.hxx>
#include <DEBRepCascade_ConfigurationNode.hxx>
#include <Message.hxx>
#include <OSD_FileSystem.hxx>
#include <TDocStd_Document.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_DocumentTool.hxx>
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;
}
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<std::istream> 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->InternalParameters.WriteBinary)
{
if (aNode->InternalParameters.WriteVersionBin > static_cast<BinTools_FormatVersion>(BinTools_FormatVersion_UPPER) ||
aNode->InternalParameters.WriteVersionBin < static_cast<BinTools_FormatVersion>(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>(TopTools_FormatVersion_UPPER) ||
aNode->InternalParameters.WriteVersionAscii < static_cast<TopTools_FormatVersion>(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");
}

View File

@ -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 _DEBRepCascade_Provider_HeaderFile
#define _DEBRepCascade_Provider_HeaderFile
#include <DE_Provider.hxx>
//! 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 // _DEBRepCascade_Provider_HeaderFile

4
src/DEBRepCascade/FILES Normal file
View File

@ -0,0 +1,4 @@
DEBRepCascade_ConfigurationNode.cxx
DEBRepCascade_ConfigurationNode.hxx
DEBRepCascade_Provider.cxx
DEBRepCascade_Provider.hxx

View File

@ -0,0 +1,190 @@
// 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 <DEXCAFCascade_ConfigurationNode.hxx>
#include <DE_ConfigurationContext.hxx>
#include <DEXCAFCascade_Provider.hxx>
#include <NCollection_Buffer.hxx>
IMPLEMENT_STANDARD_RTTIEXT(DEXCAFCascade_ConfigurationNode, DE_ConfigurationNode)
static const TCollection_AsciiString THE_CONFIGURATION_SCOPE = "provider";
//=======================================================================
// function : DEXCAFCascade_ConfigurationNode
// purpose :
//=======================================================================
DEXCAFCascade_ConfigurationNode::DEXCAFCascade_ConfigurationNode() :
DE_ConfigurationNode()
{
UpdateLoad();
}
//=======================================================================
// function : DEXCAFCascade_ConfigurationNode
// purpose :
//=======================================================================
DEXCAFCascade_ConfigurationNode::DEXCAFCascade_ConfigurationNode(const Handle(DEXCAFCascade_ConfigurationNode)& theNode)
:DE_ConfigurationNode(theNode)
{
InternalParameters = theNode->InternalParameters;
UpdateLoad();
}
//=======================================================================
// function : Load
// purpose :
//=======================================================================
bool DEXCAFCascade_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource)
{
TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE + "." + GetFormat() + "." + GetVendor();
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 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 += "!Don't allow append (when the value = 0, it is the default value), ";
aResult += "keeps existing attributes, reads only new ones(when the value = 1), ";
aResult += "overwrites the existing attributes by the loaded ones(when the value = 2)\n";
aResult += "!Default value: 0. Available values: 0, 1, 2\n";
aResult += aScope + "read.append.mode :\t " + InternalParameters.ReadAppendMode + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Overwrites the existing attributes by the loaded ones";
aResult += "!Default value: empty. Available values: {sequence<string>}\n";
aResult += aScope + "read.skip.values :\t ";
for (TColStd_ListOfAsciiString::Iterator anIt(InternalParameters.ReadSkipValues); anIt.More(); anIt.Next())
{
aResult += anIt.Value() + " ";
}
aResult += "\n!\n";
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 += "!Default value: empty. Available values: {sequence<string>}\n";
aResult += aScope + "read.values :\t ";
for (TColStd_ListOfAsciiString::Iterator anIt(InternalParameters.ReadValues); anIt.More(); anIt.Next())
{
aResult += anIt.Value() + " ";
}
aResult += "\n!\n";
aResult += "!*****************************************************************************\n";
return aResult;
}
//=======================================================================
// function : Copy
// purpose :
//=======================================================================
Handle(DE_ConfigurationNode) DEXCAFCascade_ConfigurationNode::Copy() const
{
return new DEXCAFCascade_ConfigurationNode(*this);
}
//=======================================================================
// function : BuildProvider
// purpose :
//=======================================================================
Handle(DE_Provider) DEXCAFCascade_ConfigurationNode::BuildProvider()
{
return new DEXCAFCascade_Provider();
}
//=======================================================================
// function : IsImportSupported
// purpose :
//=======================================================================
bool DEXCAFCascade_ConfigurationNode::IsImportSupported() const
{
return true;
}
//=======================================================================
// function : IsExportSupported
// purpose :
//=======================================================================
bool DEXCAFCascade_ConfigurationNode::IsExportSupported() const
{
return true;
}
//=======================================================================
// function : GetFormat
// purpose :
//=======================================================================
TCollection_AsciiString DEXCAFCascade_ConfigurationNode::GetFormat() const
{
return TCollection_AsciiString("XCAF");
}
//=======================================================================
// function : GetVendor
// purpose :
//=======================================================================
TCollection_AsciiString DEXCAFCascade_ConfigurationNode::GetVendor() const
{
return TCollection_AsciiString("OCC");
}
//=======================================================================
// function : GetExtensions
// purpose :
//=======================================================================
TColStd_ListOfAsciiString DEXCAFCascade_ConfigurationNode::GetExtensions() const
{
TColStd_ListOfAsciiString anExt;
anExt.Append("xbf");
return anExt;
}
//=======================================================================
// function : CheckContent
// purpose :
//=======================================================================
bool DEXCAFCascade_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const
{
if (theBuffer.IsNull() || theBuffer->Size() < 8)
{
return false;
}
const char* aBytes = (const char*)theBuffer->Data();
if (!::strncmp(aBytes, "BINFILE", 7))
{
return true;
}
return false;
}

View File

@ -0,0 +1,99 @@
// 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 _DEXCAFCascade_ConfigurationNode_HeaderFile
#define _DEXCAFCascade_ConfigurationNode_HeaderFile
#include <DE_ConfigurationNode.hxx>
#include <PCDM_ReaderFilter.hxx>
#include <TColStd_ListOfAsciiString.hxx>
//! 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
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
} InternalParameters;
};
#endif // _DEXCAFCascade_ConfigurationNode_HeaderFile

View File

@ -0,0 +1,308 @@
// 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 <DEXCAFCascade_Provider.hxx>
#include <BinDrivers.hxx>
#include <BinLDrivers.hxx>
#include <BinTObjDrivers.hxx>
#include <BinXCAFDrivers.hxx>
#include <StdDrivers.hxx>
#include <StdLDrivers.hxx>
#include <XmlDrivers.hxx>
#include <XmlLDrivers.hxx>
#include <XmlTObjDrivers.hxx>
#include <XmlXCAFDrivers.hxx>
#include <BRep_Builder.hxx>
#include <DEXCAFCascade_ConfigurationNode.hxx>
#include <Message.hxx>
#include <TDocStd_Application.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
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);
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");
}

View File

@ -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 _DEXCAFCascade_Provider_HeaderFile
#define _DEXCAFCascade_Provider_HeaderFile
#include <DE_Provider.hxx>
//! 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 // _DEXCAFCascade_Provider_HeaderFile

4
src/DEXCAFCascade/FILES Normal file
View File

@ -0,0 +1,4 @@
DEXCAFCascade_ConfigurationNode.cxx
DEXCAFCascade_ConfigurationNode.hxx
DEXCAFCascade_Provider.cxx
DEXCAFCascade_Provider.hxx

View File

@ -1,5 +1,9 @@
IGESCAFControl.cxx
IGESCAFControl.hxx
IGESCAFControl_ConfigurationNode.cxx
IGESCAFControl_ConfigurationNode.hxx
IGESCAFControl_Provider.cxx
IGESCAFControl_Provider.hxx
IGESCAFControl_Reader.cxx
IGESCAFControl_Reader.hxx
IGESCAFControl_Writer.cxx

View File

@ -0,0 +1,450 @@
// 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 <IGESCAFControl_ConfigurationNode.hxx>
#include <DE_ConfigurationContext.hxx>
#include <IGESCAFControl_Provider.hxx>
#include <NCollection_Buffer.hxx>
IMPLEMENT_STANDARD_RTTIEXT(IGESCAFControl_ConfigurationNode, DE_ConfigurationNode)
static const TCollection_AsciiString THE_CONFIGURATION_SCOPE = "provider";
//=======================================================================
// function : IGESCAFControl_ConfigurationNode
// purpose :
//=======================================================================
IGESCAFControl_ConfigurationNode::IGESCAFControl_ConfigurationNode() :
DE_ConfigurationNode()
{
UpdateLoad();
}
//=======================================================================
// function : IGESCAFControl_ConfigurationNode
// purpose :
//=======================================================================
IGESCAFControl_ConfigurationNode::IGESCAFControl_ConfigurationNode(const Handle(IGESCAFControl_ConfigurationNode)& theNode)
:DE_ConfigurationNode(theNode)
{
InternalParameters = theNode->InternalParameters;
UpdateLoad();
}
//=======================================================================
// 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);
InternalParameters.ReadPrecisionVal =
theResource->RealVal("read.precision.val", InternalParameters.ReadPrecisionVal, 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.EncodeRegAngle =
theResource->RealVal("read.encoderegularity.angle", InternalParameters.EncodeRegAngle, aScope);
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 =
theResource->BooleanVal("read.fau_lty.entities", InternalParameters.ReadFaultyEntities, aScope);
InternalParameters.ReadOnlyVisible =
theResource->BooleanVal("read.onlyvisible", InternalParameters.ReadOnlyVisible, aScope);
InternalParameters.ReadColor =
theResource->BooleanVal("read.color", InternalParameters.ReadColor, aScope);
InternalParameters.ReadName =
theResource->BooleanVal("read.name", InternalParameters.ReadName, aScope);
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.WriteUnit = (UnitsMethods_LengthUnit)
theResource->IntegerVal("write.unit", InternalParameters.WriteUnit, aScope);
InternalParameters.WriteHeaderAuthor =
theResource->StringVal("write.header.author", InternalParameters.WriteHeaderAuthor, aScope);
InternalParameters.WriteHeaderCompany =
theResource->StringVal("write.header.company", InternalParameters.WriteHeaderCompany, aScope);
InternalParameters.WriteHeaderProduct =
theResource->StringVal("write.header.product", InternalParameters.WriteHeaderProduct, aScope);
InternalParameters.WriteHeaderReciever =
theResource->StringVal("write.header.receiver", InternalParameters.WriteHeaderReciever, aScope);
InternalParameters.WriteResourceName =
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.WritePrecisionVal =
theResource->RealVal("write.precision.val", InternalParameters.WritePrecisionVal, aScope);
InternalParameters.WritePlaneMode = (WriteMode_PlaneMode)
theResource->IntegerVal("write.plane.mode", InternalParameters.WritePlaneMode, aScope);
InternalParameters.WriteOffsetMode =
theResource->BooleanVal("write.offset", InternalParameters.WriteOffsetMode, aScope);
InternalParameters.WriteColor =
theResource->BooleanVal("write.color", InternalParameters.WriteColor, aScope);
InternalParameters.WriteName =
theResource->BooleanVal("write.name", InternalParameters.WriteName, aScope);
InternalParameters.WriteLayer =
theResource->BooleanVal("write.layer", InternalParameters.WriteLayer, aScope);
return true;
}
//=======================================================================
// function : Save
// purpose :
//=======================================================================
TCollection_AsciiString IGESCAFControl_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 += "!Common parameters:\n";
aResult += "!\n";
aResult += "!\n";
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 += "!\n";
aResult += "!\n";
aResult += "!Reads the precision mode value\n";
aResult += "!Default value: \"File\"(0). Available values: \"File\"(0), \"User\"(1)\n";
aResult += aScope + "read.precision.mode :\t " + InternalParameters.ReadPrecisionMode + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!This parameter gives the precision for shape construction when the ";
aResult += "read.precision.mode parameter value is 1\n";
aResult += "!Default value: 0.0001. Available values: any real positive (non null) value\n";
aResult += aScope + "read.precision.val :\t " + InternalParameters.ReadPrecisionVal + "\n";
aResult += "!\n";
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 += "!\n";
aResult += "!\n";
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";
aResult += "!\n";
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 += "!\n";
aResult += "!\n";
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 += "\"2DUse_Forced\"(-2), \"3DUse_Preferred\"(3), \"3DUse_Forced\"(-3)\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 += "which these two faces are connected with at that edge.\n";
aResult += "!Default value (in degrees): 0.57295779513. Available values: <double>\n";
aResult += aScope + "read.encoderegularity.angle :\t " + InternalParameters.EncodeRegAngle + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Read parameters:\n";
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 += "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";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines the name of the resource file\n";
aResult += "!Default value: \"IGES\". Available values: <string>\n";
aResult += aScope + "read.resource.name :\t " + InternalParameters.ReadResourceName + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines the name of the sequence of operators\n";
aResult += "!Default value: \"FromIGES\". Available values: <string>\n";
aResult += aScope + "read.sequence :\t " + InternalParameters.ReadSequence + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Parameter for reading fa-iled entities\n";
aResult += "!Default value: \"Off\"(0). Available values: \"Off\"(0), \"On\"(1)\n";
aResult += aScope + "read.fau_lty.entities :\t " + InternalParameters.ReadFaultyEntities + "\n";
aResult += "!\n";
aResult += "!\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";
aResult += "!\n";
aResult += "!Setting up the ColorMode parameter which is used to indicate read Colors or not\n";
aResult += "!Default value: 1. Available values: 0, 1\n";
aResult += aScope + "read.color :\t " + InternalParameters.ReadColor + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Setting up the NameMode parameter which is used to indicate read Names or not\n";
aResult += "!Default value: 1. Available values: 0, 1\n";
aResult += aScope + "read.name :\t " + InternalParameters.ReadName + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Setting up the LayerMode parameter which is used to indicate read Layers or not\n";
aResult += "!Default value: 1. Available values: 0, 1\n";
aResult += aScope + "read.layer :\t " + InternalParameters.ReadLayer + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Write parameters:\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag to define entities type to write\n";
aResult += "!Default value: \"Faces\"(0). Available values: \"Faces\"(0), \"BRep\"(1)\n";
aResult += aScope + "write.brep.mode :\t " + InternalParameters.WriteBRepMode + "\n";
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 += "!Default value: \"Off\"(0). Available values: \"Off\"(0), \"On\"(1)\n";
aResult += aScope + "write.convertsurface.mode :\t " + InternalParameters.WriteConvertSurfaceMode + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Allows choosing the unit. The default unit for Open CASCADE Technology is \"MM\" (millimeter).";
aResult += "You can choose to write a file into any unit accepted by IGES\n";
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";
aResult += "!\n";
aResult += "!Gives the name of the author of the file\n";
aResult += "!Default value: {System name of the user}. Available values: <string>\n";
aResult += aScope + "write.header.author :\t " + InternalParameters.WriteHeaderAuthor + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Gives the name of the sending company\n";
aResult += "!Default value: ""(empty). Available values: <string>\n";
aResult += aScope + "write.header.company :\t " + InternalParameters.WriteHeaderCompany + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Gives the name of the sending product\n";
aResult += "!Default value: \"CAS.CADE IGES processor Vx.x\"";
aResult += "(where x.x means the current version of Open CASCADE Technology)";
aResult += "Available values : <string>\n";
aResult += aScope + "write.header.product :\t " + InternalParameters.WriteHeaderProduct + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Gives the name of the receiving company\n";
aResult += "!Default value: ""(empty). Available values: <string>\n";
aResult += aScope + "write.header.receiver :\t " + InternalParameters.WriteHeaderReciever + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines the name of the resource file\n";
aResult += "!Default value: \"IGES\". Available values: <string>\n";
aResult += aScope + "write.resource.name :\t " + InternalParameters.WriteResourceName + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines the name of the sequence of operators\n";
aResult += "!Default value: \"To\". Available values: <string>\n";
aResult += aScope + "write.sequence :\t " + InternalParameters.WriteSequence + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Specifies the mode of writing the resolution value into the IGES file\n";
aResult += "!Default value: Average(0). Available values: \"Least\"(-1), \"Average\"(0), ";
aResult += "\"Greatest\"(1), \"Session\"(2)\n";
aResult += aScope + "write.precision.mode :\t " + InternalParameters.WritePrecisionMode + "\n";
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 += "!Default value: 0.0001. Available values: any real positive (non null) value\n";
aResult += aScope + "write.precision.val :\t " + InternalParameters.WritePrecisionVal + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Writing planes mode\n";
aResult += "!Default value: \"Plane\"(0). Available values: \"Plane\"(0), \"BSpline\"(1)\n";
aResult += aScope + "write.plane.mode :\t " + InternalParameters.WritePlaneMode + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Writing offset curves like BSplines\n";
aResult += "!Default value: \"Off\"(0). Available values: \"Off\"(0), \"On\"(1)\n";
aResult += aScope + "write.offset :\t " + InternalParameters.WriteOffsetMode + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Setting up the ColorMode parameter which is used to indicate write Colors or not\n";
aResult += "!Default value: 1. Available values: 0, 1\n";
aResult += aScope + "write.color :\t " + InternalParameters.WriteColor + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Setting up the NameMode parameter which is used to indicate write Names or not\n";
aResult += "!Default value: 1. Available values: 0, 1\n";
aResult += aScope + "write.name :\t " + InternalParameters.WriteName + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Setting up the LayerMode parameter which is used to indicate write Layers or not\n";
aResult += "!Default value: 1. Available values: 0, 1\n";
aResult += aScope + "write.layer :\t " + InternalParameters.WriteLayer + "\n";
aResult += "!\n";
aResult += "!*****************************************************************************\n";
return aResult;
}
//=======================================================================
// function : Copy
// purpose :
//=======================================================================
Handle(DE_ConfigurationNode) IGESCAFControl_ConfigurationNode::Copy() const
{
return new IGESCAFControl_ConfigurationNode(*this);
}
//=======================================================================
// function : BuildProvider
// purpose :
//=======================================================================
Handle(DE_Provider) IGESCAFControl_ConfigurationNode::BuildProvider()
{
return new IGESCAFControl_Provider(this);
}
//=======================================================================
// function : IsImportSupported
// purpose :
//=======================================================================
bool IGESCAFControl_ConfigurationNode::IsImportSupported() const
{
return true;
}
//=======================================================================
// function : IsExportSupported
// purpose :
//=======================================================================
bool IGESCAFControl_ConfigurationNode::IsExportSupported() const
{
return true;
}
//=======================================================================
// function : GetFormat
// purpose :
//=======================================================================
TCollection_AsciiString IGESCAFControl_ConfigurationNode::GetFormat() const
{
return TCollection_AsciiString("IGES");
}
//=======================================================================
// function : GetVendor
// purpose :
//=======================================================================
TCollection_AsciiString IGESCAFControl_ConfigurationNode::GetVendor() const
{
return TCollection_AsciiString("OCC");
}
//=======================================================================
// function : GetExtensions
// purpose :
//=======================================================================
TColStd_ListOfAsciiString IGESCAFControl_ConfigurationNode::GetExtensions() const
{
TColStd_ListOfAsciiString anExt;
anExt.Append("igs");
anExt.Append("iges");
return anExt;
}
//=======================================================================
// function : CheckContent
// purpose :
//=======================================================================
bool IGESCAFControl_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const
{
if (theBuffer.IsNull() || theBuffer->Size() < 83)
{
return false;
}
const char* aBytes = (const char*)theBuffer->Data();
if (aBytes[72] == 'S')
{
const char* aPtr = aBytes + 73;
while (aPtr < aBytes + 80 && (*aPtr == ' ' || *aPtr == '0'))
{
aPtr++;
}
if (*aPtr == '1' && !::isalnum((unsigned char)*++aPtr))
{
return true;
}
}
return false;
}

View File

@ -0,0 +1,178 @@
// 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 _IGESCAFControl_ConfigurationNode_HeaderFile
#define _IGESCAFControl_ConfigurationNode_HeaderFile
#include <DE_ConfigurationNode.hxx>
#include <UnitsMethods_LengthUnit.hxx>
//! 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
ReadMode_BSplineContinuity ReadBSplineContinuity = ReadMode_BSplineContinuity_C1; //<! Manages the continuity of BSpline curves
ReadMode_Precision ReadPrecisionMode = ReadMode_Precision_File; //<! Reads the precision mode value
double ReadPrecisionVal = 0.0001; //<! ReadMode_Precision for shape construction (if enabled user mode)
ReadMode_MaxPrecision ReadMaxPrecisionMode = ReadMode_MaxPrecision_Preferred; //<! Defines the mode of applying the maximum allowed tolerance
double ReadMaxPrecisionVal = 1; //<! Defines the maximum allowable tolerance
bool ReadSameParamMode = false; //<! Defines the using of BRepLib::SameParameter
ReadMode_SurfaceCurve ReadSurfaceCurveMode = ReadMode_SurfaceCurve_Default; //<! reference for the computation of curves in case of 2D/3D
double EncodeRegAngle = 0.57295779513; //<! Continuity which these two faces are connected with at that edge
//Read
bool ReadApproxd1 = false; //<! Flag to split bspline curves of degree 1
TCollection_AsciiString ReadResourceName = "IGES"; //<! Defines the name of the resource file to read
TCollection_AsciiString ReadSequence = "FromIGES"; //<! Defines the name of the sequence of operators to read
bool ReadFaultyEntities = false; //<! Parameter for reading failed entities
bool ReadOnlyVisible = false; //<! Parameter for reading invisible entities
bool ReadColor = true; //<! ColorMode is used to indicate read Colors or not
bool ReadName = true; //<! NameMode is used to indicate read Name or not
bool ReadLayer = true; //<! LayerMode is used to indicate read Layers or not
// Write
WriteMode_BRep WriteBRepMode = WriteMode_BRep_Faces; //<! Flag to define entities type to write
WriteMode_ConvertSurface WriteConvertSurfaceMode = WriteMode_ConvertSurface_Off; //<! Flag to convert surface to elementary
UnitsMethods_LengthUnit WriteUnit = UnitsMethods_LengthUnit_Millimeter; //<! Define unit to write IGES file
TCollection_AsciiString WriteHeaderAuthor; //<! Name of the author of the file
TCollection_AsciiString WriteHeaderCompany; //<! Name of the sending company
TCollection_AsciiString WriteHeaderProduct; //<! Name of the sending product
TCollection_AsciiString WriteHeaderReciever; //<! Name of the receiving company
TCollection_AsciiString WriteResourceName = "IGES"; //<! Defines the name of the resource file to write
TCollection_AsciiString WriteSequence = "ToIGES"; //<! Defines the name of the sequence of operators to write
WriteMode_PrecisionMode WritePrecisionMode = WriteMode_PrecisionMode_Average; //<! Specifies the mode of writing the resolution value into the IGES file
double WritePrecisionVal = 0.0001; //<! Resolution value for an IGES file when WriteMode_PrecisionMode is Greatest
WriteMode_PlaneMode WritePlaneMode = WriteMode_PlaneMode_Plane; //<! Flag to convert plane to the BSline
bool WriteOffsetMode = false; //<! Writing offset curves like BSplines
bool WriteColor = true; //<! ColorMode is used to indicate write Colors or not
bool WriteName = true; //<! NameMode is used to indicate write Name or not
bool WriteLayer = true; //<! LayerMode is used to indicate write Layers or not
} InternalParameters;
};
#endif // _IGESCAFControl_ConfigurationNode_HeaderFile

View File

@ -0,0 +1,394 @@
// 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 <IGESCAFControl_Provider.hxx>
#include <BinXCAFDrivers.hxx>
#include <IGESCAFControl_ConfigurationNode.hxx>
#include <IGESCAFControl_Reader.hxx>
#include <IGESCAFControl_Writer.hxx>
#include <IGESData.hxx>
#include <IGESData_IGESModel.hxx>
#include <Interface_Static.hxx>
#include <Message.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <UnitsMethods.hxx>
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 : 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");
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.WriteUnit = (UnitsMethods_LengthUnit)Interface_Static::IVal("write.iges.unit");
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::SetIVal("write.iges.unit", theParameter.WriteUnit);
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());
initStatic(aNode);
XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter);
IGESCAFControl_Reader aReader;
if (!theWS.IsNull())
{
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());
initStatic(aNode);
XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->InternalParameters.WriteUnit, UnitsMethods_LengthUnit_Millimeter);
IGESCAFControl_Writer aWriter;
if (!theWS.IsNull())
{
aWriter = IGESCAFControl_Writer(theWS);
}
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;
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;
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);
IGESControl_Reader aReader;
if (!theWS.IsNull())
{
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);
TCollection_AsciiString aUnit(UnitsMethods::DumpLengthUnit(aNode->InternalParameters.WriteUnit));
aUnit.UpperCase();
IGESControl_Writer aWriter(aUnit.ToCString(),
aNode->InternalParameters.WriteBRepMode);
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;
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;
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");
}

View File

@ -0,0 +1,152 @@
// 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 _IGESCAFControl_Provider_HeaderFile
#define _IGESCAFControl_Provider_HeaderFile
#include <DE_Provider.hxx>
#include <IGESCAFControl_ConfigurationNode.hxx>
//! 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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:
//! 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;
};
#endif // _IGESCAFControl_Provider_HeaderFile

View File

@ -147,7 +147,7 @@ static void AddCompositeShape (const Handle(XCAFDoc_ShapeTool)& theSTool,
//function : Transfer
//purpose : basic working method
//=======================================================================
Standard_Boolean IGESCAFControl_Reader::Transfer (Handle(TDocStd_Document) &doc,
Standard_Boolean IGESCAFControl_Reader::Transfer (const Handle(TDocStd_Document) &doc,
const Message_ProgressRange& theProgress)
{
// read all shapes
@ -349,7 +349,7 @@ Standard_Boolean IGESCAFControl_Reader::Transfer (Handle(TDocStd_Document) &doc,
//=======================================================================
Standard_Boolean IGESCAFControl_Reader::Perform (const Standard_CString filename,
Handle(TDocStd_Document) &doc,
const Handle(TDocStd_Document) &doc,
const Message_ProgressRange& theProgress)
{
if ( ReadFile ( filename ) != IFSelect_RetDone ) return Standard_False;

View File

@ -68,18 +68,18 @@ class IGESCAFControl_Reader : public IGESControl_Reader
//! Translates currently loaded IGES file into the document
//! Returns True if succeeded, and False in case of fail
Standard_EXPORT Standard_Boolean Transfer (Handle(TDocStd_Document)& theDoc,
Standard_EXPORT Standard_Boolean Transfer (const Handle(TDocStd_Document)& theDoc,
const Message_ProgressRange& theProgress = Message_ProgressRange());
Standard_Boolean Perform (const TCollection_AsciiString& theFileName,
Handle(TDocStd_Document)& theDoc,
const Handle(TDocStd_Document)& theDoc,
const Message_ProgressRange& theProgress = Message_ProgressRange())
{ return Perform (theFileName.ToCString(), theDoc, theProgress); }
//! Translate IGES file given by filename into the document
//! Return True if succeeded, and False in case of fail
Standard_EXPORT Standard_Boolean Perform (const Standard_CString theFileName,
Handle(TDocStd_Document)& theDoc,
const Handle(TDocStd_Document)& theDoc,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Set ColorMode for indicate read Colors or not.

View File

@ -1,3 +1,9 @@
RWGltf_CafReader.cxx
RWGltf_CafReader.hxx
RWGltf_CafWriter.cxx
RWGltf_CafWriter.hxx
RWGltf_ConfigurationNode.cxx
RWGltf_ConfigurationNode.hxx
RWGltf_GltfAccessor.hxx
RWGltf_GltfAccessorCompType.hxx
RWGltf_GltfAccessorLayout.hxx
@ -6,23 +12,21 @@ RWGltf_GltfArrayType.hxx
RWGltf_GltfBufferView.hxx
RWGltf_GltfBufferViewTarget.hxx
RWGltf_GltfFace.hxx
RWGltf_GltfJsonParser.cxx
RWGltf_GltfJsonParser.hxx
RWGltf_GltfLatePrimitiveArray.cxx
RWGltf_GltfLatePrimitiveArray.hxx
RWGltf_GltfMaterialMap.cxx
RWGltf_GltfMaterialMap.hxx
RWGltf_GltfOStreamWriter.hxx
RWGltf_GltfPrimArrayData.hxx
RWGltf_GltfPrimitiveMode.hxx
RWGltf_GltfRootElement.hxx
RWGltf_GltfSceneNodeMap.hxx
RWGltf_MaterialCommon.hxx
RWGltf_MaterialMetallicRoughness.hxx
RWGltf_CafReader.cxx
RWGltf_CafReader.hxx
RWGltf_CafWriter.cxx
RWGltf_CafWriter.hxx
RWGltf_GltfMaterialMap.cxx
RWGltf_GltfMaterialMap.hxx
RWGltf_GltfJsonParser.cxx
RWGltf_GltfJsonParser.hxx
RWGltf_GltfOStreamWriter.hxx
RWGltf_GltfSceneNodeMap.hxx
RWGltf_Provider.cxx
RWGltf_Provider.hxx
RWGltf_TriangulationReader.cxx
RWGltf_TriangulationReader.hxx
RWGltf_WriterTrsfFormat.hxx

View File

@ -0,0 +1,349 @@
// 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 <RWGltf_ConfigurationNode.hxx>
#include <DE_ConfigurationContext.hxx>
#include <RWGltf_Provider.hxx>
IMPLEMENT_STANDARD_RTTIEXT(RWGltf_ConfigurationNode, DE_ConfigurationNode)
static const TCollection_AsciiString THE_CONFIGURATION_SCOPE = "provider";
//=======================================================================
// function : RWGltf_ConfigurationNode
// purpose :
//=======================================================================
RWGltf_ConfigurationNode::RWGltf_ConfigurationNode() :
DE_ConfigurationNode()
{
UpdateLoad();
}
//=======================================================================
// function : RWGltf_ConfigurationNode
// purpose :
//=======================================================================
RWGltf_ConfigurationNode::RWGltf_ConfigurationNode(const Handle(RWGltf_ConfigurationNode)& theNode)
:DE_ConfigurationNode(theNode)
{
InternalParameters = theNode->InternalParameters;
UpdateLoad();
}
//=======================================================================
// function : Load
// purpose :
//=======================================================================
bool RWGltf_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource)
{
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 =
theResource->BooleanVal("read.create.shapes", InternalParameters.ReadCreateShapes, aScope);
InternalParameters.ReadRootPrefix =
theResource->StringVal("read.root.prefix", InternalParameters.ReadRootPrefix, aScope);
InternalParameters.ReadFillDoc =
theResource->BooleanVal("read.fill.doc", InternalParameters.ReadFillDoc, aScope);
InternalParameters.ReadFillIncomplete =
theResource->BooleanVal("read.fill.incomplete", InternalParameters.ReadFillIncomplete, aScope);
InternalParameters.ReadMemoryLimitMiB =
theResource->IntegerVal("read.memory.limit.mib", InternalParameters.ReadMemoryLimitMiB, aScope);
InternalParameters.ReadParallel =
theResource->BooleanVal("read.parallel", InternalParameters.ReadParallel, aScope);
InternalParameters.ReadSkipEmptyNodes =
theResource->BooleanVal("read.skip.empty.nodes", InternalParameters.ReadSkipEmptyNodes, aScope);
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 =
theResource->BooleanVal("read.keep.late.data", InternalParameters.ReadKeepLateData, aScope);
InternalParameters.ReadPrintDebugMessages =
theResource->BooleanVal("read.print.debug.message", InternalParameters.ReadPrintDebugMessages, aScope);
InternalParameters.WriteComment =
theResource->StringVal("write.comment", InternalParameters.WriteComment, aScope);
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 =
theResource->BooleanVal("write.merge.faces", InternalParameters.WriteMergeFaces, aScope);
InternalParameters.WriteSplitIndices16 =
theResource->BooleanVal("write.split.indices16", InternalParameters.WriteSplitIndices16, aScope);
return true;
}
//=======================================================================
// function : Save
// purpose :
//=======================================================================
TCollection_AsciiString RWGltf_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 += "!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 += "!Default value: 1.0(M)\n";
aResult += aScope + "file.length.unit :\t " + InternalParameters.FileLengthUnit + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!System origin coordinate system to perform conversion into during read\n";
aResult += "!Default value: 0(Zup). Available values: 0(Zup), 1(Yup)\n";
aResult += aScope + "system.cs :\t " + InternalParameters.SystemCS + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!File origin coordinate system to perform conversion during read\n";
aResult += "!Default value: 1(Yup). Available values: 0(Zup), 1(Yup)\n";
aResult += aScope + "file.cs :\t " + InternalParameters.FileCS + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Read parameters:\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag for reading vertex data with single or double floating point precision\n";
aResult += "!Default value: 1(true). Available values: 0(false), 1(true)\n";
aResult += aScope + "read.single.precision :\t " + InternalParameters.ReadSinglePrecision + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag for create a single triangulation\n";
aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
aResult += aScope + "read.create.shapes :\t " + InternalParameters.ReadCreateShapes + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Root folder for generating root labels names\n";
aResult += "!Default value: ""(empty). Available values: <path>\n";
aResult += aScope + "read.root.prefix :\t " + InternalParameters.ReadRootPrefix + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag for fill document from shape sequence\n";
aResult += "!Default value: 1(true). Available values: 0(false), 1(true)\n";
aResult += aScope + "read.fill.doc :\t " + InternalParameters.ReadFillDoc + "\n";
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 += "!Default value: 1(true). Available values: 0(false), 1(true)\n";
aResult += aScope + "read.fill.incomplete :\t " + InternalParameters.ReadFillIncomplete + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Memory usage limit(MiB)\n";
aResult += "!Default value: -1(no limit). Available values: -1(no limit), any positive value\n";
aResult += aScope + "read.memory.limit.mib :\t " + InternalParameters.ReadMemoryLimitMiB + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag to use multithreading\n";
aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
aResult += aScope + "read.parallel :\t " + InternalParameters.ReadParallel + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag to ignore nodes without Geometry\n";
aResult += "!Default value: 1(true). Available values: 0(false), 1(true)\n";
aResult += aScope + "read.skip.empty.nodes :\t " + InternalParameters.ReadSkipEmptyNodes + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag to load all scenes in the document\n";
aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
aResult += aScope + "read.load.all.scenes :\t " + InternalParameters.ReadLoadAllScenes + "\n";
aResult += "!\n";
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 += "!\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 += "!\n";
aResult += "!\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";
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 += "!\n";
aResult += "!\n";
aResult += "!Write parameters:\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Export special comment\n";
aResult += "!Default value: ""(empty). Available values: <string>\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: <string>\n";
aResult += aScope + "write.author :\t " + InternalParameters.WriteAuthor + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Transformation format to write into glTF file\n";
aResult += "!Default value: 0(Compact). Available values: 0(Compact), 1(Mat4), 2(TRS)\n";
aResult += aScope + "write.trsf.format :\t " + InternalParameters.WriteTrsfFormat + "\n";
aResult += "!\n";
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 += 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 += aScope + "write.mesh.name.format :\t " + InternalParameters.WriteMeshNameFormat + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Export UV coordinates even if there are no mapped texture\n";
aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
aResult += aScope + "write.forced.uv.export :\t " + InternalParameters.WriteForcedUVExport + "\n";
aResult += "!\n";
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 += "!\n";
aResult += "!\n";
aResult += "!Flag to merge faces within a single part\n";
aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
aResult += aScope + "write.merge.faces :\t " + InternalParameters.WriteMergeFaces + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag to prefer keeping 16-bit indexes while merging face\n";
aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
aResult += aScope + "write.split.indices16 :\t " + InternalParameters.WriteSplitIndices16 + "\n";
aResult += "!\n";
aResult += "!*****************************************************************************\n";
return aResult;
}
//=======================================================================
// function : Copy
// purpose :
//=======================================================================
Handle(DE_ConfigurationNode) RWGltf_ConfigurationNode::Copy() const
{
return new RWGltf_ConfigurationNode(*this);
}
//=======================================================================
// function : BuildProvider
// purpose :
//=======================================================================
Handle(DE_Provider) RWGltf_ConfigurationNode::BuildProvider()
{
return new RWGltf_Provider(this);
}
//=======================================================================
// function : IsImportSupported
// purpose :
//=======================================================================
bool RWGltf_ConfigurationNode::IsImportSupported() const
{
return true;
}
//=======================================================================
// function : IsExportSupported
// purpose :
//=======================================================================
bool RWGltf_ConfigurationNode::IsExportSupported() const
{
return true;
}
//=======================================================================
// function : GetFormat
// purpose :
//=======================================================================
TCollection_AsciiString RWGltf_ConfigurationNode::GetFormat() const
{
return TCollection_AsciiString("GLTF");
}
//=======================================================================
// function : GetVendor
// purpose :
//=======================================================================
TCollection_AsciiString RWGltf_ConfigurationNode::GetVendor() const
{
return TCollection_AsciiString("OCC");
}
//=======================================================================
// function : GetExtensions
// purpose :
//=======================================================================
TColStd_ListOfAsciiString RWGltf_ConfigurationNode::GetExtensions() const
{
TColStd_ListOfAsciiString anExt;
anExt.Append("gltf");
anExt.Append("glb");
return anExt;
}

View File

@ -0,0 +1,117 @@
// 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 _RWGltf_ConfigurationNode_HeaderFile
#define _RWGltf_ConfigurationNode_HeaderFile
#include <DE_ConfigurationNode.hxx>
#include <RWMesh_CoordinateSystem.hxx>
#include <RWGltf_WriterTrsfFormat.hxx>
#include <RWMesh_NameFormat.hxx>
//! 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
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
} InternalParameters;
};
#endif // _RWGltf_ConfigurationNode_HeaderFile

View File

@ -0,0 +1,259 @@
// 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 <RWGltf_Provider.hxx>
#include <BinXCAFDrivers.hxx>
#include <Message.hxx>
#include <RWGltf_CafWriter.hxx>
#include <TDocStd_Document.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_DocumentTool.hxx>
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;
aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
aConverter.SetInputCoordinateSystem(aNode->InternalParameters.SystemCS);
aConverter.SetOutputLengthUnit(aNode->InternalParameters.FileLengthUnit);
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");
}

View File

@ -0,0 +1,139 @@
// 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 _RWGltf_Provider_HeaderFile
#define _RWGltf_Provider_HeaderFile
#include <DE_Provider.hxx>
#include <RWGltf_CafReader.hxx>
#include <RWGltf_ConfigurationNode.hxx>
//! 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 // _RWGltf_Provider_HeaderFile

View File

@ -1,10 +1,10 @@
RWMesh.cxx
RWMesh.hxx
RWMesh_CafReader.cxx
RWMesh_CafReader.hxx
RWMesh_CoordinateSystem.hxx
RWMesh_CoordinateSystemConverter.cxx
RWMesh_CoordinateSystemConverter.hxx
RWMesh_CafReader.cxx
RWMesh_CafReader.hxx
RWMesh_FaceIterator.cxx
RWMesh_FaceIterator.hxx
RWMesh_MaterialMap.cxx

View File

@ -4,6 +4,8 @@ RWObj_CafReader.cxx
RWObj_CafReader.hxx
RWObj_CafWriter.cxx
RWObj_CafWriter.hxx
RWObj_ConfigurationNode.cxx
RWObj_ConfigurationNode.hxx
RWObj_Material.hxx
RWObj_MtlReader.cxx
RWObj_MtlReader.hxx
@ -11,6 +13,8 @@ RWObj_ObjMaterialMap.cxx
RWObj_ObjMaterialMap.hxx
RWObj_ObjWriterContext.cxx
RWObj_ObjWriterContext.hxx
RWObj_Provider.cxx
RWObj_Provider.hxx
RWObj_Reader.cxx
RWObj_Reader.hxx
RWObj_SubMesh.hxx

View File

@ -0,0 +1,234 @@
// 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 <RWObj_ConfigurationNode.hxx>
#include <DE_ConfigurationContext.hxx>
#include <RWObj_Provider.hxx>
IMPLEMENT_STANDARD_RTTIEXT(RWObj_ConfigurationNode, DE_ConfigurationNode)
static const TCollection_AsciiString THE_CONFIGURATION_SCOPE = "provider";
//=======================================================================
// function : RWObj_ConfigurationNode
// purpose :
//=======================================================================
RWObj_ConfigurationNode::RWObj_ConfigurationNode() :
DE_ConfigurationNode()
{
UpdateLoad();
}
//=======================================================================
// function : RWObj_ConfigurationNode
// purpose :
//=======================================================================
RWObj_ConfigurationNode::RWObj_ConfigurationNode(const Handle(RWObj_ConfigurationNode)& theNode)
:DE_ConfigurationNode(theNode)
{
InternalParameters = theNode->InternalParameters;
UpdateLoad();
}
//=======================================================================
// function : Load
// purpose :
//=======================================================================
bool RWObj_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource)
{
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 =
theResource->BooleanVal("read.create.shapes", InternalParameters.ReadCreateShapes, aScope);
InternalParameters.ReadRootPrefix =
theResource->StringVal("read.root.prefix", InternalParameters.ReadRootPrefix, aScope);
InternalParameters.ReadFillDoc =
theResource->BooleanVal("read.fill.doc", InternalParameters.ReadFillDoc, aScope);
InternalParameters.ReadFillIncomplete =
theResource->BooleanVal("read.fill.incomplete", InternalParameters.ReadFillIncomplete, aScope);
InternalParameters.ReadMemoryLimitMiB =
theResource->IntegerVal("read.memory.limit.mib", InternalParameters.ReadMemoryLimitMiB, aScope);
InternalParameters.WriteComment =
theResource->StringVal("write.comment", InternalParameters.WriteComment, aScope);
InternalParameters.WriteAuthor =
theResource->StringVal("write.author", InternalParameters.WriteAuthor, aScope);
return true;
}
//=======================================================================
// function : Save
// purpose :
//=======================================================================
TCollection_AsciiString RWObj_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 += "!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 += "!Default value: 1.0(M)\n";
aResult += aScope + "file.length.unit :\t " + InternalParameters.FileLengthUnit + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!System origin coordinate system to perform conversion into during read\n";
aResult += "!Default value: 0(Zup). Available values: 0(Zup), 1(Yup)\n";
aResult += aScope + "system.cs :\t " + InternalParameters.SystemCS + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!File origin coordinate system to perform conversion during read\n";
aResult += "!Default value: 1(Yup). Available values: 0(Zup), 1(Yup)\n";
aResult += aScope + "file.cs :\t " + InternalParameters.FileCS + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Read parameters:\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag for reading vertex data with single or double floating point precision\n";
aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
aResult += aScope + "read.single.precision :\t " + InternalParameters.ReadSinglePrecision + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag for create a single triangulation\n";
aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
aResult += aScope + "read.create.shapes :\t " + InternalParameters.ReadCreateShapes + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Root folder for generating root labels names\n";
aResult += "!Default value: ""(empty). Available values: <path>\n";
aResult += aScope + "read.root.prefix :\t " + InternalParameters.ReadRootPrefix + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag for fill document from shape sequence\n";
aResult += "!Default value: 1(true). Available values: 0(false), 1(true)\n";
aResult += aScope + "read.fill.doc :\t " + InternalParameters.ReadFillDoc + "\n";
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 += "!Default value: 1(true). Available values: 0(false), 1(true)\n";
aResult += aScope + "read.fill.incomplete :\t " + InternalParameters.ReadFillIncomplete + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Memory usage limit(MiB)\n";
aResult += "!Default value: -1(no limit). Available values: -1(no limit), any positive value\n";
aResult += aScope + "read.memory.limit.mib :\t " + InternalParameters.ReadMemoryLimitMiB + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Write parameters:\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Export special comment\n";
aResult += "!Default value: ""(empty). Available values: <string>\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: <string>\n";
aResult += aScope + "write.author :\t " + InternalParameters.WriteAuthor + "\n";
aResult += "!\n";
aResult += "!*****************************************************************************\n";
return aResult;
}
//=======================================================================
// function : Copy
// purpose :
//=======================================================================
Handle(DE_ConfigurationNode) RWObj_ConfigurationNode::Copy() const
{
return new RWObj_ConfigurationNode(*this);
}
//=======================================================================
// function : BuildProvider
// purpose :
//=======================================================================
Handle(DE_Provider) RWObj_ConfigurationNode::BuildProvider()
{
return new RWObj_Provider(this);
}
//=======================================================================
// function : IsImportSupported
// purpose :
//=======================================================================
bool RWObj_ConfigurationNode::IsImportSupported() const
{
return true;
}
//=======================================================================
// function : IsExportSupported
// purpose :
//=======================================================================
bool RWObj_ConfigurationNode::IsExportSupported() const
{
return true;
}
//=======================================================================
// function : GetFormat
// purpose :
//=======================================================================
TCollection_AsciiString RWObj_ConfigurationNode::GetFormat() const
{
return TCollection_AsciiString("OBJ");
}
//=======================================================================
// function : GetVendor
// purpose :
//=======================================================================
TCollection_AsciiString RWObj_ConfigurationNode::GetVendor() const
{
return TCollection_AsciiString("OCC");
}
//=======================================================================
// function : GetExtensions
// purpose :
//=======================================================================
TColStd_ListOfAsciiString RWObj_ConfigurationNode::GetExtensions() const
{
TColStd_ListOfAsciiString anExt;
anExt.Append("obj");
return anExt;
}

View File

@ -0,0 +1,101 @@
// 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 _RWObj_ConfigurationNode_HeaderFile
#define _RWObj_ConfigurationNode_HeaderFile
#include <DE_ConfigurationNode.hxx>
#include <RWMesh_CoordinateSystem.hxx>
//! 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
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
int ReadMemoryLimitMiB = -1; //!< Memory usage limit
// Writing
TCollection_AsciiString WriteComment; //!< Export special comment
TCollection_AsciiString WriteAuthor; //!< Author of exported file name
} InternalParameters;
};
#endif // _RWObj_ConfigurationNode_HeaderFile

View File

@ -0,0 +1,246 @@
// 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 <RWObj_Provider.hxx>
#include <BinXCAFDrivers.hxx>
#include <BRep_Builder.hxx>
#include <RWObj_ConfigurationNode.hxx>
#include <RWObj_CafReader.hxx>
#include <RWObj_CafWriter.hxx>
#include <TDocStd_Document.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_DocumentTool.hxx>
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,
const Handle(TDocStd_Document)& theDocument,
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,
const Handle(TDocStd_Document)& theDocument,
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,
const Handle(TDocStd_Document)& theDocument,
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";
return false;
}
if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(RWObj_ConfigurationNode)))
{
Message::SendFail() << "Error in the RWObj_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;
aReader.SetSinglePrecision(aNode->InternalParameters.ReadSinglePrecision);
aReader.SetSystemLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
aReader.SetSystemCoordinateSystem(aNode->InternalParameters.SystemCS);
aReader.SetFileLengthUnit(aNode->InternalParameters.FileLengthUnit);
aReader.SetFileCoordinateSystem(aNode->InternalParameters.FileCS);
aReader.SetDocument(theDocument);
aReader.SetRootPrefix(aNode->InternalParameters.ReadRootPrefix);
aReader.SetMemoryLimitMiB(aNode->InternalParameters.ReadMemoryLimitMiB);
if (!aReader.Perform(thePath, theProgress))
{
Message::SendFail() << "Error in the RWObj_ConfigurationNode during reading the file " << thePath;
return false;
}
XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter);
return true;
}
//=======================================================================
// function : Write
// purpose :
//=======================================================================
bool RWObj_Provider::Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress)
{
if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(RWObj_ConfigurationNode)))
{
Message::SendFail() << "Error in the RWObj_ConfigurationNode during writing the file " <<
thePath << "\t: Incorrect or empty Configuration Node";
return false;
}
Handle(RWObj_ConfigurationNode) aNode = Handle(RWObj_ConfigurationNode)::DownCast(GetNode());
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);
}
RWMesh_CoordinateSystemConverter aConverter;
aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
aConverter.SetInputCoordinateSystem(aNode->InternalParameters.SystemCS);
aConverter.SetOutputLengthUnit(aNode->InternalParameters.FileLengthUnit);
aConverter.SetOutputCoordinateSystem(aNode->InternalParameters.FileCS);
RWObj_CafWriter aWriter(thePath);
aWriter.SetCoordinateSystemConverter(aConverter);
if (!aWriter.Perform(theDocument, aFileInfo, theProgress))
{
Message::SendFail() << "Error in the RWObj_ConfigurationNode during writing the file " << thePath;
return false;
}
return true;
}
//=======================================================================
// function : Read
// purpose :
//=======================================================================
bool RWObj_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 RWObj_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 RWObj_Provider::Read(const TCollection_AsciiString& thePath,
TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress)
{
if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(RWObj_ConfigurationNode)))
{
Message::SendFail() << "Error in the RWObj_ConfigurationNode during writing the file " <<
thePath << "\t: Incorrect or empty Configuration Node";
return false;
}
Handle(RWObj_ConfigurationNode) aNode = Handle(RWObj_ConfigurationNode)::DownCast(GetNode());
RWMesh_CoordinateSystemConverter aConverter;
aConverter.SetOutputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
aConverter.SetOutputCoordinateSystem(aNode->InternalParameters.SystemCS);
aConverter.SetInputLengthUnit(aNode->InternalParameters.FileLengthUnit);
aConverter.SetInputCoordinateSystem(aNode->InternalParameters.FileCS);
RWObj_TriangulationReader aSimpleReader;
aSimpleReader.SetTransformation(aConverter);
aSimpleReader.SetSinglePrecision(aNode->InternalParameters.ReadSinglePrecision);
aSimpleReader.SetCreateShapes(aNode->InternalParameters.ReadCreateShapes);
aSimpleReader.SetSinglePrecision(aNode->InternalParameters.ReadSinglePrecision);
aSimpleReader.SetMemoryLimit(aNode->InternalParameters.ReadMemoryLimitMiB);
if (!aSimpleReader.Read(thePath, theProgress))
{
Message::SendFail() << "Error in the RWObj_ConfigurationNode during reading the file " << thePath;
return false;
}
Handle(Poly_Triangulation) aTriangulation = aSimpleReader.GetTriangulation();
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)
{
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
{
return TCollection_AsciiString("OBJ");
}
//=======================================================================
// function : GetVendor
// purpose :
//=======================================================================
TCollection_AsciiString RWObj_Provider::GetVendor() const
{
return TCollection_AsciiString("OCC");
}

View File

@ -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 _RWObj_Provider_HeaderFile
#define _RWObj_Provider_HeaderFile
#include <DE_Provider.hxx>
//! 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 // _RWObj_Provider_HeaderFile

View File

@ -1,4 +1,8 @@
RWPly_CafWriter.cxx
RWPly_CafWriter.hxx
RWPly_ConfigurationNode.cxx
RWPly_ConfigurationNode.hxx
RWPly_PlyWriterContext.cxx
RWPly_PlyWriterContext.hxx
RWPly_Provider.cxx
RWPly_Provider.hxx

View File

@ -0,0 +1,272 @@
// 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 <RWPly_ConfigurationNode.hxx>
#include <DE_ConfigurationContext.hxx>
#include <NCollection_Buffer.hxx>
#include <RWPly_Provider.hxx>
IMPLEMENT_STANDARD_RTTIEXT(RWPly_ConfigurationNode, DE_ConfigurationNode)
static const TCollection_AsciiString THE_CONFIGURATION_SCOPE = "provider";
//=======================================================================
// function : RWPly_ConfigurationNode
// purpose :
//=======================================================================
RWPly_ConfigurationNode::RWPly_ConfigurationNode() :
DE_ConfigurationNode()
{
UpdateLoad();
}
//=======================================================================
// function : RWPly_ConfigurationNode
// purpose :
//=======================================================================
RWPly_ConfigurationNode::RWPly_ConfigurationNode(const Handle(RWPly_ConfigurationNode)& theNode)
:DE_ConfigurationNode(theNode)
{
InternalParameters = theNode->InternalParameters;
UpdateLoad();
}
//=======================================================================
// function : Load
// purpose :
//=======================================================================
bool RWPly_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource)
{
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.WritePntSet =
theResource->BooleanVal("write.pnt.set", InternalParameters.WritePntSet, aScope);
InternalParameters.WriteDistance =
theResource->RealVal("write.distance", InternalParameters.WriteDistance, aScope);
InternalParameters.WriteDensity =
theResource->RealVal("write.density", InternalParameters.WriteDensity, aScope);
InternalParameters.WriteTolerance =
theResource->RealVal("write.tolerance", InternalParameters.WriteTolerance, aScope);
InternalParameters.WriteNormals =
theResource->BooleanVal("write.normals", InternalParameters.WriteNormals, aScope);
InternalParameters.WriteColors =
theResource->BooleanVal("write.colors", InternalParameters.WriteColors, aScope);
InternalParameters.WriteTexCoords =
theResource->BooleanVal("write.tex.coords", InternalParameters.WriteTexCoords, aScope);
InternalParameters.WritePartId =
theResource->BooleanVal("write.part.id", InternalParameters.WritePartId, aScope);
InternalParameters.WriteFaceId =
theResource->BooleanVal("write.face.id", InternalParameters.WriteFaceId, aScope);
InternalParameters.WriteComment =
theResource->StringVal("write.comment", InternalParameters.WriteComment, aScope);
InternalParameters.WriteAuthor =
theResource->StringVal("write.author", InternalParameters.WriteAuthor, aScope);
return Standard_True;
}
//=======================================================================
// function : Save
// purpose :
//=======================================================================
TCollection_AsciiString RWPly_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 += "!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 += "!Default value: 1.0(MM)\n";
aResult += aScope + "file.length.unit :\t " + InternalParameters.FileLengthUnit + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!System origin coordinate system to perform conversion into during read\n";
aResult += "!Default value: 0(Zup). Available values: 0(Zup), 1(Yup)\n";
aResult += aScope + "system.cs :\t " + InternalParameters.SystemCS + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!File origin coordinate system to perform conversion during read\n";
aResult += "!Default value: 1(Yup). Available values: 0(Zup), 1(Yup)\n";
aResult += aScope + "file.cs :\t " + InternalParameters.FileCS + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Write parameters:\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag for write point cloud instead without triangulation indices\n";
aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
aResult += aScope + "write.pnt.set :\t " + InternalParameters.WritePntSet + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Distance from shape into the range [0, Value]\n";
aResult += "!Default value: 0. Available values: [0, Value]\n";
aResult += aScope + "write.distance :\t " + InternalParameters.WriteDistance + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Density of points to generate randomly on surface\n";
aResult += "!Default value: 2.e+100. Available values: [0, inf]\n";
aResult += aScope + "write.density :\t " + InternalParameters.WriteDensity + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Internal tolerance\n";
aResult += "!Default value: 1.e-7. Available values: [0, inf]\n";
aResult += aScope + "write.tolerance :\t " + InternalParameters.WriteTolerance + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag for write normals\n";
aResult += "!Default value: 1(true). Available values: 0(false), 1(true)\n";
aResult += aScope + "write.normals :\t " + InternalParameters.WriteNormals + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag for write colors\n";
aResult += "!Default value: 1(true). Available values: 0(false), 1(true)\n";
aResult += aScope + "write.colors :\t " + InternalParameters.WriteColors + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag for write UV / texture coordinates\n";
aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
aResult += aScope + "write.tex.coords :\t " + InternalParameters.WriteTexCoords + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag for write part Id as element attribute\n";
aResult += "!Default value: 1(true). Available values: 0(false), 1(true)\n";
aResult += aScope + "write.part.id :\t " + InternalParameters.WritePartId + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Flag for write face Id as element attribute. Cannot be combined with HasPartId\n";
aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
aResult += aScope + "write.face.id :\t " + InternalParameters.WriteFaceId + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Export special comment\n";
aResult += "!Default value: ""(empty). Available values: <string>\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: <string>\n";
aResult += aScope + "write.author :\t " + InternalParameters.WriteAuthor + "\n";
aResult += "!\n";
aResult += "!*****************************************************************************\n";
return aResult;
}
//=======================================================================
// function : Copy
// purpose :
//=======================================================================
Handle(DE_ConfigurationNode) RWPly_ConfigurationNode::Copy() const
{
return new RWPly_ConfigurationNode(*this);
}
//=======================================================================
// function : BuildProvider
// purpose :
//=======================================================================
Handle(DE_Provider) RWPly_ConfigurationNode::BuildProvider()
{
return new RWPly_Provider(this);
}
//=======================================================================
// function : IsImportSupported
// purpose :
//=======================================================================
bool RWPly_ConfigurationNode::IsImportSupported() const
{
return Standard_False;
}
//=======================================================================
// function : IsExportSupported
// purpose :
//=======================================================================
bool RWPly_ConfigurationNode::IsExportSupported() const
{
return Standard_True;
}
//=======================================================================
// function : GetFormat
// purpose :
//=======================================================================
TCollection_AsciiString RWPly_ConfigurationNode::GetFormat() const
{
return TCollection_AsciiString("PLY");
}
//=======================================================================
// function : GetVendor
// purpose :
//=======================================================================
TCollection_AsciiString RWPly_ConfigurationNode::GetVendor() const
{
return TCollection_AsciiString("OCC");
}
//=======================================================================
// function : GetExtensions
// purpose :
//=======================================================================
TColStd_ListOfAsciiString RWPly_ConfigurationNode::GetExtensions() const
{
TColStd_ListOfAsciiString anExt;
anExt.Append("ply");
return anExt;
}
//=======================================================================
// function : CheckContent
// purpose :
//=======================================================================
bool RWPly_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const
{
if (theBuffer.IsNull() || theBuffer->Size() < 4)
{
return false;
}
const char* aBytes = (const char*)theBuffer->Data();
if (!::strncmp(aBytes, "ply", 3) && ::isspace(aBytes[3]))
{
return true;
}
return false;
}

View File

@ -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 _RWPly_ConfigurationNode_HeaderFile
#define _RWPly_ConfigurationNode_HeaderFile
#include <DE_ConfigurationNode.hxx>
#include <Precision.hxx>
#include <RWMesh_CoordinateSystem.hxx>
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
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 WritePntSet = false; //!< Flag for write point cloud instead without triangulation indices
double WriteDistance = 0.0; //!< Distance from shape into the range [0, Value]
double WriteDensity = Precision::Infinite(); //!< Density of points to generate randomly on surface
double WriteTolerance = Precision::Confusion(); //!< Internal tolerance
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
TCollection_AsciiString WriteComment; //!< Export special comment
TCollection_AsciiString WriteAuthor; //!< Author of exported file name
} InternalParameters;
};
#endif // _RWPly_ConfigurationNode_HeaderFile

View File

@ -0,0 +1,245 @@
// 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 <RWPly_Provider.hxx>
#include <BRep_Builder.hxx>
#include <BRepLib_PointCloudShape.hxx>
#include <DE_Wrapper.hxx>
#include <Message.hxx>
#include <RWPly_ConfigurationNode.hxx>
#include <RWPly_CafWriter.hxx>
#include <RWMesh_FaceIterator.hxx>
#include <RWPly_PlyWriterContext.hxx>
#include <TDocStd_Document.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFPrs_DocumentExplorer.hxx>
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,
const Handle(TDocStd_Document)& theDocument,
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,
const Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress)
{
if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(RWPly_ConfigurationNode)))
{
Message::SendFail() << "Error in the RWPly_Provider during writing the file " <<
thePath << "\t: Incorrect or empty Configuration Node";
return false;
}
Handle(RWPly_ConfigurationNode) aNode = Handle(RWPly_ConfigurationNode)::DownCast(GetNode());
TDF_LabelSequence aRootLabels;
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
aShapeTool->GetFreeShapes(aRootLabels);
if (aRootLabels.IsEmpty())
{
return Standard_True;
}
if (aNode->InternalParameters.WritePntSet)
{
class PointCloudPlyWriter : public BRepLib_PointCloudShape, public RWPly_PlyWriterContext
{
public:
PointCloudPlyWriter(Standard_Real theTol)
: BRepLib_PointCloudShape(TopoDS_Shape(), theTol)
{}
void AddFaceColor(const TopoDS_Shape& theFace, const Graphic3d_Vec4ub& theColor)
{
myFaceColor.Bind(theFace, theColor);
}
protected:
virtual void addPoint(const gp_Pnt& thePoint,
const gp_Vec& theNorm,
const gp_Pnt2d& theUV,
const TopoDS_Shape& theFace)
{
Graphic3d_Vec4ub aColor;
myFaceColor.Find(theFace, aColor);
RWPly_PlyWriterContext::WriteVertex(thePoint,
Graphic3d_Vec3((float)theNorm.X(), (float)theNorm.Y(), (float)theNorm.Z()),
Graphic3d_Vec2((float)theUV.X(), (float)theUV.Y()),
aColor);
}
private:
NCollection_DataMap<TopoDS_Shape, Graphic3d_Vec4ub> myFaceColor;
};
PointCloudPlyWriter aPlyCtx(aNode->InternalParameters.WriteTolerance);
aPlyCtx.SetNormals(aNode->InternalParameters.WriteNormals);
aPlyCtx.SetColors(aNode->InternalParameters.WriteColors);
aPlyCtx.SetTexCoords(aNode->InternalParameters.WriteTexCoords);
TopoDS_Compound aComp;
BRep_Builder().MakeCompound(aComp);
for (XCAFPrs_DocumentExplorer aDocExplorer(theDocument, aRootLabels, XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes);
aDocExplorer.More(); aDocExplorer.Next())
{
const XCAFPrs_DocumentNode& aDocNode = aDocExplorer.Current();
for (RWMesh_FaceIterator aFaceIter(aDocNode.RefLabel, aDocNode.Location, true, aDocNode.Style); aFaceIter.More(); aFaceIter.Next())
{
BRep_Builder().Add(aComp, aFaceIter.Face());
Graphic3d_Vec4ub aColorVec(255);
if (aFaceIter.HasFaceColor())
{
Graphic3d_Vec4 aColorF = aFaceIter.FaceColor();
aColorVec.SetValues((unsigned char)int(aColorF.r() * 255.0f),
(unsigned char)int(aColorF.g() * 255.0f),
(unsigned char)int(aColorF.b() * 255.0f),
(unsigned char)int(aColorF.a() * 255.0f));
}
aPlyCtx.AddFaceColor(aFaceIter.Face(), aColorVec);
}
}
aPlyCtx.SetShape(aComp);
Standard_Integer aNbPoints = aNode->InternalParameters.WriteDensity > 0
? aPlyCtx.NbPointsByDensity(aNode->InternalParameters.WriteDensity)
: aPlyCtx.NbPointsByTriangulation();
if (aNbPoints <= 0)
{
Message::SendFail() << "Error in the RWPly_Provider during writing the file " <<
thePath << "\t: Incorrect number of points";
return false;
}
if (!aPlyCtx.Open(thePath)
|| !aPlyCtx.WriteHeader(aNbPoints, 0, TColStd_IndexedDataMapOfStringString()))
{
Message::SendFail() << "Error in the RWPly_Provider during writing the file " << thePath;
return false;
}
Standard_Boolean isDone = aNode->InternalParameters.WriteDensity > 0
? aPlyCtx.GeneratePointsByDensity(aNode->InternalParameters.WriteDensity)
: aPlyCtx.GeneratePointsByTriangulation();
if (!isDone)
{
Message::SendFail() << "Error in the RWPly_Provider during writing the file "
<< thePath << "\t: Error during generating point process";
return false;
}
}
else
{
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);
}
RWMesh_CoordinateSystemConverter aConverter;
aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
aConverter.SetInputCoordinateSystem(aNode->InternalParameters.SystemCS);
aConverter.SetOutputLengthUnit(aNode->InternalParameters.FileLengthUnit);
aConverter.SetOutputCoordinateSystem(aNode->InternalParameters.FileCS);
RWPly_CafWriter aPlyCtx(thePath);
aPlyCtx.SetNormals(aNode->InternalParameters.WriteNormals);
aPlyCtx.SetColors(aNode->InternalParameters.WriteColors);
aPlyCtx.SetTexCoords(aNode->InternalParameters.WriteTexCoords);
aPlyCtx.SetPartId(aNode->InternalParameters.WritePartId);
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";
return false;
}
}
return true;
}
//=======================================================================
// function : Write
// purpose :
//=======================================================================
bool RWPly_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 : Write
// purpose :
//=======================================================================
bool RWPly_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 RWPly_Provider::GetFormat() const
{
return TCollection_AsciiString("PLY");
}
//=======================================================================
// function : GetVendor
// purpose :
//=======================================================================
TCollection_AsciiString RWPly_Provider::GetVendor() const
{
return TCollection_AsciiString("OCC");
}

View File

@ -0,0 +1,96 @@
// 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 _RWPly_Provider_HeaderFile
#define _RWPly_Provider_HeaderFile
#include <DE_Provider.hxx>
//! 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 // _RWPly_Provider_HeaderFile

View File

@ -2,3 +2,7 @@ RWStl.cxx
RWStl.hxx
RWStl_Reader.cxx
RWStl_Reader.hxx
RWStl_ConfigurationNode.cxx
RWStl_ConfigurationNode.hxx
RWStl_Provider.cxx
RWStl_Provider.hxx

View File

@ -0,0 +1,185 @@
// 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 <RWStl_ConfigurationNode.hxx>
#include <DE_ConfigurationContext.hxx>
#include <NCollection_Buffer.hxx>
#include <RWStl_Provider.hxx>
IMPLEMENT_STANDARD_RTTIEXT(RWStl_ConfigurationNode, DE_ConfigurationNode)
static const TCollection_AsciiString THE_CONFIGURATION_SCOPE = "provider";
//=======================================================================
// function : STEPCAFControl_ConfigurationNode
// purpose :
//=======================================================================
RWStl_ConfigurationNode::RWStl_ConfigurationNode() :
DE_ConfigurationNode()
{
UpdateLoad();
}
//=======================================================================
// function : STEPCAFControl_ConfigurationNode
// purpose :
//=======================================================================
RWStl_ConfigurationNode::RWStl_ConfigurationNode(const Handle(RWStl_ConfigurationNode)& theNode)
:DE_ConfigurationNode(theNode)
{
InternalParameters = theNode->InternalParameters;
UpdateLoad();
}
//=======================================================================
// function : Load
// purpose :
//=======================================================================
bool RWStl_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource)
{
TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE + "." + GetFormat() + "." + GetVendor();
InternalParameters.ReadMergeAngle =
theResource->RealVal("read.merge.angle", InternalParameters.ReadMergeAngle, aScope);
InternalParameters.ReadBRep =
theResource->BooleanVal("read.brep", InternalParameters.ReadBRep, aScope);
InternalParameters.WriteAscii =
theResource->BooleanVal("write.ascii", InternalParameters.WriteAscii, aScope);
return true;
}
//=======================================================================
// function : Save
// purpose :
//=======================================================================
TCollection_AsciiString RWStl_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 += "!Input merge angle value\n";
aResult += "!Default value (in degrees): 90.0. Angle should be within [0.0, 90.0] range\n";
aResult += aScope + "read.merge.angle :\t " + InternalParameters.ReadMergeAngle + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Setting up Boundary Representation flag\n";
aResult += "!Default value: false. Available values: \"on\", \"off\"\n";
aResult += aScope + "read.brep :\t " + InternalParameters.ReadBRep + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Write parameters:\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Setting up writing mode (Ascii or Binary)\n";
aResult += "!Default value: 1(Binary). Available values: 0(Ascii), 1(Binary)\n";
aResult += aScope + "write.ascii :\t " + InternalParameters.WriteAscii + "\n";
aResult += "!\n";
aResult += "!*****************************************************************************\n";
return aResult;
}
//=======================================================================
// function : Copy
// purpose :
//=======================================================================
Handle(DE_ConfigurationNode) RWStl_ConfigurationNode::Copy() const
{
return new RWStl_ConfigurationNode(*this);
}
//=======================================================================
// function : BuildProvider
// purpose :
//=======================================================================
Handle(DE_Provider) RWStl_ConfigurationNode::BuildProvider()
{
return new RWStl_Provider(this);
}
//=======================================================================
// function : IsImportSupported
// purpose :
//=======================================================================
bool RWStl_ConfigurationNode::IsImportSupported() const
{
return true;
}
//=======================================================================
// function : IsExportSupported
// purpose :
//=======================================================================
bool RWStl_ConfigurationNode::IsExportSupported() const
{
return true;
}
//=======================================================================
// function : GetFormat
// purpose :
//=======================================================================
TCollection_AsciiString RWStl_ConfigurationNode::GetFormat() const
{
return TCollection_AsciiString("STL");
}
//=======================================================================
// function : GetVendor
// purpose :
//=======================================================================
TCollection_AsciiString RWStl_ConfigurationNode::GetVendor() const
{
return TCollection_AsciiString("OCC");
}
//=======================================================================
// function : GetExtensions
// purpose :
//=======================================================================
TColStd_ListOfAsciiString RWStl_ConfigurationNode::GetExtensions() const
{
TColStd_ListOfAsciiString anExt;
anExt.Append("stl");
return anExt;
}
//=======================================================================
// function : CheckContent
// purpose :
//=======================================================================
bool RWStl_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const
{
if (theBuffer.IsNull() || theBuffer->Size() < 7)
{
return false;
}
const char* aBytes = (const char*)theBuffer->Data();
if (!(::strncmp(aBytes, "solid", 5) || ::strncmp(aBytes, "SOLID", 5)) && isspace(aBytes[5]))
{
return true;
}
// binary STL has no header for identification - format can be detected only by file extension
return false;
}

View File

@ -0,0 +1,99 @@
// 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 _RWStl_ConfigurationNode_HeaderFile
#define _RWStl_ConfigurationNode_HeaderFile
#include <DE_ConfigurationNode.hxx>
//! 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;
};
#endif // _RWStl_ConfigurationNode_HeaderFile

View File

@ -0,0 +1,251 @@
// 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 <RWStl_Provider.hxx>
#include <BinXCAFDrivers.hxx>
#include <BRep_Builder.hxx>
#include <Message.hxx>
#include <RWStl.hxx>
#include <RWStl_ConfigurationNode.hxx>
#include <StlAPI.hxx>
#include <StlAPI_Writer.hxx>
#include <TDocStd_Document.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_DocumentTool.hxx>
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;
}
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());
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");
}

View File

@ -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 _RWStl_Provider_HeaderFile
#define _RWStl_Provider_HeaderFile
#include <DE_Provider.hxx>
//! 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 // _RWStl_Provider_HeaderFile

View File

@ -1,5 +1,7 @@
STEPCAFControl_ActorWrite.cxx
STEPCAFControl_ActorWrite.hxx
STEPCAFControl_ConfigurationNode.cxx
STEPCAFControl_ConfigurationNode.hxx
STEPCAFControl_Controller.cxx
STEPCAFControl_Controller.hxx
STEPCAFControl_DataMapIteratorOfDataMapOfLabelExternFile.hxx
@ -17,9 +19,11 @@ STEPCAFControl_DataMapOfShapeSDR.hxx
STEPCAFControl_ExternFile.cxx
STEPCAFControl_ExternFile.hxx
STEPCAFControl_ExternFile.lxx
STEPCAFControl_GDTProperty.hxx
STEPCAFControl_GDTProperty.cxx
STEPCAFControl_Provider.cxx
STEPCAFControl_Provider.hxx
STEPCAFControl_Reader.cxx
STEPCAFControl_Reader.hxx
STEPCAFControl_Writer.cxx
STEPCAFControl_Writer.hxx
STEPCAFControl_GDTProperty.hxx
STEPCAFControl_GDTProperty.cxx

View File

@ -0,0 +1,573 @@
// 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 <STEPCAFControl_ConfigurationNode.hxx>
#include <DE_ConfigurationContext.hxx>
#include <NCollection_Buffer.hxx>
#include <STEPCAFControl_Provider.hxx>
IMPLEMENT_STANDARD_RTTIEXT(STEPCAFControl_ConfigurationNode, DE_ConfigurationNode)
static const TCollection_AsciiString THE_CONFIGURATION_SCOPE = "provider";
//=======================================================================
// function : STEPCAFControl_ConfigurationNode
// purpose :
//=======================================================================
STEPCAFControl_ConfigurationNode::STEPCAFControl_ConfigurationNode() :
DE_ConfigurationNode()
{
UpdateLoad();
}
//=======================================================================
// function : STEPCAFControl_ConfigurationNode
// purpose :
//=======================================================================
STEPCAFControl_ConfigurationNode::STEPCAFControl_ConfigurationNode(const Handle(STEPCAFControl_ConfigurationNode)& theNode)
:DE_ConfigurationNode(theNode),
InternalParameters(theNode->InternalParameters)
{
UpdateLoad();
}
//=======================================================================
// function : Load
// purpose :
//=======================================================================
bool STEPCAFControl_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.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.EncodeRegAngle =
theResource->RealVal("read.encoderegularity.angle", InternalParameters.EncodeRegAngle, aScope);
InternalParameters.AngleUnit = (AngleUnitMode)
theResource->IntegerVal("angleunit.mode", InternalParameters.AngleUnit, aScope);
InternalParameters.ReadResourceName =
theResource->StringVal("read.resource.name", InternalParameters.ReadResourceName, aScope);
InternalParameters.ReadSequence =
theResource->StringVal("read.sequence", InternalParameters.ReadSequence, aScope);
InternalParameters.ReadProductMode =
theResource->BooleanVal("read.product.mode", InternalParameters.ReadProductMode, aScope);
InternalParameters.ReadProductContext = (ReadMode_ProductContext)
theResource->IntegerVal("read.product.context", InternalParameters.ReadProductContext, aScope);
InternalParameters.ReadShapeRepr = (ReadMode_ShapeRepr)
theResource->IntegerVal("read.shape.repr", InternalParameters.ReadShapeRepr, aScope);
InternalParameters.ReadTessellated = (RWMode_Tessellated)
theResource->IntegerVal("read.tessellated", InternalParameters.ReadTessellated, aScope);
InternalParameters.ReadAssemblyLevel = (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);
InternalParameters.ReadSubshapeNames =
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 =
theResource->BooleanVal("read.ideas", InternalParameters.ReadIdeas, aScope);
InternalParameters.ReadAllShapes =
theResource->BooleanVal("read.all.shapes", InternalParameters.ReadAllShapes, aScope);
InternalParameters.ReadRootTransformation =
theResource->BooleanVal("read.root.transformation", InternalParameters.ReadRootTransformation, aScope);
InternalParameters.ReadColor =
theResource->BooleanVal("read.color", InternalParameters.ReadColor, aScope);
InternalParameters.ReadName =
theResource->BooleanVal("read.name", InternalParameters.ReadName, aScope);
InternalParameters.ReadLayer =
theResource->BooleanVal("read.layer", InternalParameters.ReadLayer, aScope);
InternalParameters.ReadProps =
theResource->BooleanVal("read.props", InternalParameters.ReadProps, aScope);
InternalParameters.WritePrecisionMode = (WriteMode_PrecisionMode)
theResource->IntegerVal("write.precision.mode", InternalParameters.WritePrecisionMode, aScope);
InternalParameters.WritePrecisionVal =
theResource->RealVal("write.precision.val", InternalParameters.WritePrecisionVal, aScope);
InternalParameters.WriteAssembly = (WriteMode_Assembly)
theResource->IntegerVal("write.assembly", InternalParameters.WriteAssembly, aScope);
InternalParameters.WriteSchema = (WriteMode_StepSchema)
theResource->IntegerVal("write.schema", InternalParameters.WriteSchema, aScope);
InternalParameters.WriteTessellated = (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);
InternalParameters.WriteResourceName =
theResource->StringVal("write.resource.name", InternalParameters.WriteResourceName, aScope);
InternalParameters.WriteSequence =
theResource->StringVal("write.sequence", InternalParameters.WriteSequence, aScope);
InternalParameters.WriteVertexMode = (WriteMode_VertexMode)
theResource->IntegerVal("write.vertex.mode", InternalParameters.WriteVertexMode, aScope);
InternalParameters.WriteSubshapeNames =
theResource->BooleanVal("write.stepcaf.subshapes.name", InternalParameters.WriteSubshapeNames, aScope);
InternalParameters.WriteColor =
theResource->BooleanVal("write.color", InternalParameters.WriteColor, aScope);
InternalParameters.WriteName =
theResource->BooleanVal("write.name", InternalParameters.WriteName, aScope);
InternalParameters.WriteLayer =
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);
return true;
}
//=======================================================================
// function : Save
// purpose :
//=======================================================================
TCollection_AsciiString STEPCAFControl_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 += "!Common parameters:\n";
aResult += "!\n";
aResult += "!\n";
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 += "!\n";
aResult += "!\n";
aResult += "!Reads the precision mode value\n";
aResult += "!Default value: \"File\"(0). Available values: \"File\"(0), \"User\"(1)\n";
aResult += aScope + "read.precision.mode :\t " + InternalParameters.ReadPrecisionMode + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!This parameter gives the precision for shape construction when the ";
aResult += "read.precision.mode parameter value is 1\n";
aResult += "!Default value: 0.0001. Available values: any real positive (non null) value\n";
aResult += aScope + "read.precision.val :\t " + InternalParameters.ReadPrecisionVal + "\n";
aResult += "!\n";
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 += "!\n";
aResult += "!\n";
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";
aResult += "!\n";
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 += "!\n";
aResult += "!\n";
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 += "\"2DUse_Forced\"(-2), \"3DUse_Preferred\"(3), \"3DUse_Forced\"(-3)\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 += "which these two faces are connected with at that edge.\n";
aResult += "!Default value (in degrees): 0.57295779513. Available values: <double>\n";
aResult += aScope + "read.encoderegularity.angle :\t " + InternalParameters.EncodeRegAngle + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Indicates what angle units should be used when a STEP file is read\n";
aResult += "!Default value: \"File\"(0). Available values: \"File\"(0), \"Rad\"(1), \"Deg\"(2)\n";
aResult += aScope + "angleunit.mode :\t " + InternalParameters.AngleUnit + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Read Parameters:\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines the name of the resource file\n";
aResult += "!Default value: \"STEP\". Available values: <string>\n";
aResult += aScope + "read.resource.name :\t " + InternalParameters.ReadResourceName + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines name of the sequence of operators\n";
aResult += "!Default value: \"FromSTEP\". Available values: <string>\n";
aResult += aScope + "read.sequence :\t " + InternalParameters.ReadSequence + "\n";
aResult += "!\n";
aResult += "!\n";
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 += "or both types of products for translation\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 += "5(\"FBSR\"), 6(\"EBWSR\"), 7(\"GBWSR\")\n";
aResult += aScope + "read.shape.repr :\t " + InternalParameters.ReadShapeRepr + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines whether tessellated shapes should be translated";
aResult += "!Default value: 1(\"On\"). Available values: 0(\"OFF\"), 2(\"OnNoBRep\")\n";
aResult += aScope + "read.tessellated :\t " + InternalParameters.ReadTessellated + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Specifies which data should be read for the products found in the STEP file\n";
aResult += "!Default value: 1(\"All\"). Available values: 1(\"All\"), 2(\"assembly\"),";
aResult += "3(\"structure\"), 4(\"shape\")\n";
aResult += aScope + "read.assembly.level :\t " + InternalParameters.ReadAssemblyLevel + "\n";
aResult += "!\n";
aResult += "!\n";
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 += "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 += "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 += "!Default value: 0(\"OFF\"). Available values: 0(\"OFF\"), 1(\"ON\")\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 += "!Default value: 0(\"OFF\"). Available values: 0(\"OFF\"), 1(\"ON\")\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 += aScope + "read.codepage :\t " + InternalParameters.ReadCodePage + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Non-manifold topology reading\n";
aResult += "!Default value: 0(\"OFF\"). Available values: 0(\"OFF\"), 1(\"ON\")\n";
aResult += aScope + "read.nonmanifold :\t " + InternalParameters.ReadNonmanifold + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!I-Deas-like STEP processing\n";
aResult += "!Default value: 0(\"OFF\"). Available values: 0(\"OFF\"), 1(\"ON\")\n";
aResult += aScope + "read.ideas :\t " + InternalParameters.ReadIdeas + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Parameter to read all top level solids and shells\n";
aResult += "!Default value: 0(\"OFF\"). Available values: 0(\"OFF\"), 1(\"ON\")\n";
aResult += aScope + "read.all.shapes :\t " + InternalParameters.ReadAllShapes + "\n";
aResult += "!\n";
aResult += "!\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 += "!\n";
aResult += "!\n";
aResult += "!Setting up the read.colo parameter which is used to indicate read Colors or not\n";
aResult += "!Default value: +. Available values: \"-\", \"+\"\n";
aResult += aScope + "read.color :\t " + InternalParameters.ReadColor + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Setting up the read.name parameter which is used to indicate read Names or not\n";
aResult += "!Default value: +. Available values: \"-\", \"+\"\n";
aResult += aScope + "read.name :\t " + InternalParameters.ReadName + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Setting up the read.layer parameter which is used to indicate read Layers or not\n";
aResult += "!Default value: +. Available values: \"-\", \"+\"\n";
aResult += aScope + "read.layer :\t " + InternalParameters.ReadLayer + "\n";
aResult += "!\n";
aResult += "!\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 += "!Write Parameters:\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Writes the precision value\n";
aResult += "!Default value: \"Average\"(0). Available values: \"Least\"(-1), \"Average\"(0), ";
aResult += "\"Greatest\"(1), \"Session\"(2)\n";
aResult += aScope + "write.precision.mode :\t " + InternalParameters.WritePrecisionMode + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!A user-defined precision value\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";
aResult += "!\n";
aResult += "!Writing assembly mode\n";
aResult += "!Default value: 0(\"Off\"). Available values: 0(\"Off\"), 1(\"On\"), 2(\"Auto\")\n";
aResult += aScope + "write.assembly :\t " + InternalParameters.WriteAssembly + "\n";
aResult += "!\n";
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 += "4 or AP214IS, 5 or AP242DIS\n";
aResult += aScope + "write.schema :\t " + InternalParameters.WriteSchema + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines whether tessellated shapes should be translated";
aResult += "!Default value: 2(\"OnNoBRep\"). Available values: 0(\"OFF\"), 1(\"On\")\n";
aResult += aScope + "write.tessellated :\t " + InternalParameters.WriteTessellated + "\n";
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: <string>\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 += "!Default value: 1(\"ON\"). Available values: 0(\"OFF\"), 1(\"ON\")\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 += "\"M\"(6), \"KM\"(7), \"MIL\"(8), \"UM\"(9), \"CM\"(10), \"UIN\"(11)\n";
aResult += aScope + "write.unit :\t " + InternalParameters.WriteUnit + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines the name of the resource file\n";
aResult += "!Default value: \"STEP\". Available values: <string>\n";
aResult += aScope + "write.resource.name :\t " + InternalParameters.WriteResourceName + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Defines name of the sequence of operators\n";
aResult += "!Default value: \"ToSTEP\". Available values: <string>\n";
aResult += aScope + "write.sequence :\t " + InternalParameters.WriteSequence + "\n";
aResult += "!\n";
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 += 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 += "!Default value: 0(\"OFF\"). Available values: 0(\"OFF\"), 1(\"ON\")\n";
aResult += aScope + "write.stepcaf.subshapes.name :\t " + InternalParameters.WriteSubshapeNames + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Setting up the write.colo parameter which is used to indicate write Colors or not\n";
aResult += "!Default value: +. Available values: \"-\", \"+\"\n";
aResult += aScope + "write.color :\t " + InternalParameters.WriteColor + "\n";
aResult += "!\n";
aResult += "!\n";
aResult += "!Setting up the write.name parameter which is used to indicate write Names or not\n";
aResult += "!Default value: +. Available values: \"-\", \"+\"\n";
aResult += aScope + "write.name :\t " + InternalParameters.WriteName + "\n";
aResult += "!\n";
aResult += "!\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 += "!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 += "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";
aResult += "!\n";
aResult += "!*****************************************************************************\n";
return aResult;
}
//=======================================================================
// function : Copy
// purpose :
//=======================================================================
Handle(DE_ConfigurationNode) STEPCAFControl_ConfigurationNode::Copy() const
{
return new STEPCAFControl_ConfigurationNode(*this);
}
//=======================================================================
// function : BuildProvider
// purpose :
//=======================================================================
Handle(DE_Provider) STEPCAFControl_ConfigurationNode::BuildProvider()
{
return new STEPCAFControl_Provider(this);
}
//=======================================================================
// function : IsImportSupported
// purpose :
//=======================================================================
bool STEPCAFControl_ConfigurationNode::IsImportSupported() const
{
return true;
}
//=======================================================================
// function : IsExportSupported
// purpose :
//=======================================================================
bool STEPCAFControl_ConfigurationNode::IsExportSupported() const
{
return true;
}
//=======================================================================
// function : GetFormat
// purpose :
//=======================================================================
TCollection_AsciiString STEPCAFControl_ConfigurationNode::GetFormat() const
{
return TCollection_AsciiString("STEP");
}
//=======================================================================
// function : GetVendor
// purpose :
//=======================================================================
TCollection_AsciiString STEPCAFControl_ConfigurationNode::GetVendor() const
{
return TCollection_AsciiString("OCC");
}
//=======================================================================
// function : GetExtensions
// purpose :
//=======================================================================
TColStd_ListOfAsciiString STEPCAFControl_ConfigurationNode::GetExtensions() const
{
TColStd_ListOfAsciiString anExt;
anExt.Append("stp");
anExt.Append("step");
anExt.Append("stpz");
return anExt;
}
//=======================================================================
// function : CheckContent
// purpose :
//=======================================================================
bool STEPCAFControl_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const
{
if (theBuffer.IsNull() || theBuffer->Size() < 100)
{
return false;
}
const char* aBytes = (const char*)theBuffer->Data();
if (::strstr(aBytes, "IFC"))
{
return false;
}
if (::strstr(aBytes, "ISO-10303-21"))
{
// Double-check by presence of "FILE_SHEMA" statement
const char* aPtr = ::strstr(aBytes, "FILE_SCHEMA");
if (aPtr)
{
return true;
}
}
return false;
}

View File

@ -0,0 +1,234 @@
// 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 _STEPCAFControl_ConfigurationNode_HeaderFile
#define _STEPCAFControl_ConfigurationNode_HeaderFile
#include <DE_ConfigurationNode.hxx>
#include <STEPControl_StepModelType.hxx>
#include <Resource_FormatType.hxx>
#include <UnitsMethods_LengthUnit.hxx>
//! 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:
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 AngleUnitMode
{
AngleUnitMode_File = 0,
AngleUnitMode_Rad,
AngleUnitMode_Deg
};
enum ReadMode_ProductContext
{
ReadMode_ProductContext_All = 1,
ReadMode_ProductContext_Design,
ReadMode_ProductContext_Analysis
};
enum ReadMode_ShapeRepr
{
ReadMode_ShapeRepr_All = 1,
ReadMode_ShapeRepr_ABSR,
ReadMode_ShapeRepr_MSSR,
ReadMode_ShapeRepr_GBSSR,
ReadMode_ShapeRepr_FBSR,
ReadMode_ShapeRepr_EBWSR,
ReadMode_ShapeRepr_GBWSR
};
enum ReadMode_AssemblyLevel
{
ReadMode_AssemblyLevel_All = 1,
ReadMode_AssemblyLevel_Assembly,
ReadMode_AssemblyLevel_Structure,
ReadMode_AssemblyLevel_Shape
};
enum RWMode_Tessellated
{
RWMode_Tessellated_Off = 0,
RWMode_Tessellated_On,
RWMode_Tessellated_OnNoBRep
};
enum WriteMode_PrecisionMode
{
WriteMode_PrecisionMode_Least = -1,
WriteMode_PrecisionMode_Average = 0,
WriteMode_PrecisionMode_Greatest = 1,
WriteMode_PrecisionMode_Session = 2
};
enum WriteMode_Assembly
{
WriteMode_Assembly_Off = 0,
WriteMode_Assembly_On,
WriteMode_Assembly_Auto
};
enum WriteMode_StepSchema
{
WriteMode_StepSchema_AP214CD = 1,
WriteMode_StepSchema_AP214DIS,
WriteMode_StepSchema_AP203,
WriteMode_StepSchema_AP214IS,
WriteMode_StepSchema_AP242DIS
};
enum WriteMode_VertexMode
{
WriteMode_VertexMode_OneCompound = 0,
WriteMode_VertexMode_SingleVertex
};
struct STEPCAFControl_InternalSection
{
// Common
ReadMode_BSplineContinuity ReadBSplineContinuity = ReadMode_BSplineContinuity_C1; //<! Manages the continuity of BSpline curves
ReadMode_Precision ReadPrecisionMode = ReadMode_Precision_File; //<! Reads the precision mode value
double ReadPrecisionVal = 0.0001; //<! ReadMode_Precision for shape construction (if enabled user mode)
ReadMode_MaxPrecision ReadMaxPrecisionMode = ReadMode_MaxPrecision_Preferred; //<! Defines the mode of applying the maximum allowed tolerance
double ReadMaxPrecisionVal = 1; //<! Defines the maximum allowable tolerance
bool ReadSameParamMode = false; //<! Defines the using of BRepLib::SameParameter
ReadMode_SurfaceCurve ReadSurfaceCurveMode = ReadMode_SurfaceCurve_Default; //<! Reference for the computation of curves in case of 2D/3D
double EncodeRegAngle = 0.57295779513; //<! Continuity which these two faces are connected with at that edge
AngleUnitMode AngleUnit = AngleUnitMode_File; //<! Indicates what angle units should be used when a STEP file is read
// Read
TCollection_AsciiString ReadResourceName = "STEP"; //<! Defines the name of the resource file to read
TCollection_AsciiString ReadSequence = "FromSTEP"; //<! Defines the name of the sequence of operators to read
bool ReadProductMode = true; //<! Defines the approach used for selection of top-level STEP entities for translation, and for recognition of assembly structures
ReadMode_ProductContext ReadProductContext = ReadMode_ProductContext_All; //<! When reading AP 209 STEP files, allows selecting either only 'design' or 'analysis', or both types of products for translation
ReadMode_ShapeRepr ReadShapeRepr = ReadMode_ShapeRepr_All; //<! Specifies preferred type of representation of the shape of the product
RWMode_Tessellated ReadTessellated = RWMode_Tessellated_On; //!< Defines whether tessellated shapes should be translated
ReadMode_AssemblyLevel ReadAssemblyLevel = ReadMode_AssemblyLevel_All; //<! Specifies which data should be read for the products found in the STEP file
bool ReadRelationship = true; //<! Defines whether shapes associated with the main SHAPE_DEFINITION_REPRESENTATION entity of the product via SHAPE_REPRESENTATIONSHIP_RELATION should be translated
bool ReadShapeAspect = true; //<! Defines whether shapes associated with the PRODUCT_DEFINITION_SHAPE entity of the product via SHAPE_ASPECT should be translated
bool ReadConstrRelation = false; //<! Flag regulating translation of "CONSTRUCTIVE_GEOMETRY_REPRESENTATION_RELATIONSHIP" entities
bool ReadSubshapeNames = false; //<! Indicates whether to read sub-shape names from 'Name' attributes of STEP Representation Items
Resource_FormatType ReadCodePage = Resource_FormatType_UTF8; //<! STEP file encoding for names translation
bool ReadNonmanifold = false; //<! Defines non-manifold topology reading
bool ReadIdeas = false; //<! Defines !I-Deas-like STEP processing
bool ReadAllShapes = false; //<! Parameter to read all top level solids and shells
bool ReadRootTransformation = true; ///<!/ Mode to variate apply or not transformation placed in the root shape representation
bool ReadColor = true; //<! ColorMode is used to indicate read Colors or not
bool ReadName = true; //<! NameMode is used to indicate read Name or not
bool ReadLayer = true; //<! LayerMode is used to indicate read Layers or not
bool ReadProps = true; //<! PropsMode is used to indicate read Validation properties or not
// Write
WriteMode_PrecisionMode WritePrecisionMode = WriteMode_PrecisionMode_Average; //<! Specifies the mode of writing the resolution value into the STEP file
double WritePrecisionVal = 0.0001; //<! Resolution value for an STEP file when WriteMode_PrecisionMode is Greatest
WriteMode_Assembly WriteAssembly = WriteMode_Assembly_Off; //<! Writing assembly mode
WriteMode_StepSchema WriteSchema = WriteMode_StepSchema_AP214CD; //<! Defines the version of schema used for the output STEP file
RWMode_Tessellated WriteTessellated = RWMode_Tessellated_OnNoBRep; //!< Defines whether tessellated shapes should be translated
TCollection_AsciiString WriteProductName; //<! Defines the text string that will be used for field 'name' of PRODUCT entities written to the STEP file
bool WriteSurfaceCurMode = true; //<! Indicates whether parametric curves (curves in parametric space of surface) should be written into the STEP file
UnitsMethods_LengthUnit WriteUnit = UnitsMethods_LengthUnit_Millimeter; //<! Defines a unit in which the STEP file should be written
TCollection_AsciiString WriteResourceName = "STEP"; //<! Defines the name of the resource file to write
TCollection_AsciiString WriteSequence = "ToSTEP"; //<! Defines the name of the sequence of operators to write
WriteMode_VertexMode WriteVertexMode = WriteMode_VertexMode_OneCompound; //<! Indicates which of free vertices writing mode is switch on
bool WriteSubshapeNames = false; //<! Indicates whether to write sub-shape names to 'Name' attributes of STEP Representation Items
bool WriteColor = true; //<! ColorMode is used to indicate write Colors or not
bool WriteName = true; //<! NameMode is used to indicate write Name or not
bool WriteLayer = true; //<! LayerMode is used to indicate write Layers or not
bool WriteProps = true; //<! PropsMode is used to indicate write Validation properties or not
STEPControl_StepModelType WriteModelType = STEPControl_AsIs; //<! Gives you the choice of translation mode for an Open CASCADE shape that is being translated to STEP
} InternalParameters;
};
#endif // _STEPCAFControl_ConfigurationNode_HeaderFile

View File

@ -0,0 +1,431 @@
// 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 <STEPCAFControl_Provider.hxx>
#include <BinXCAFDrivers.hxx>
#include <Interface_Static.hxx>
#include <Message.hxx>
#include <StepData_StepModel.hxx>
#include <STEPCAFControl_ConfigurationNode.hxx>
#include <STEPCAFControl_Controller.hxx>
#include <STEPCAFControl_Reader.hxx>
#include <STEPCAFControl_Writer.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <UnitsMethods.hxx>
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 : initStatic
// purpose :
//=======================================================================
void STEPCAFControl_Provider::initStatic(const Handle(DE_ConfigurationNode)& theNode)
{
Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(theNode);
STEPCAFControl_Controller::Init();
// Get previous values
myOldValues.ReadBSplineContinuity = (STEPCAFControl_ConfigurationNode::ReadMode_BSplineContinuity)Interface_Static::IVal("read.iges.bspline.continuity");
myOldValues.ReadPrecisionMode = (STEPCAFControl_ConfigurationNode::ReadMode_Precision)Interface_Static::IVal("read.precision.mode");
myOldValues.ReadPrecisionVal = Interface_Static::RVal("read.precision.val");
myOldValues.ReadMaxPrecisionMode = (STEPCAFControl_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 = (STEPCAFControl_ConfigurationNode::ReadMode_SurfaceCurve)Interface_Static::IVal("read.surfacecurve.mode");
myOldValues.EncodeRegAngle = Interface_Static::RVal("read.encoderegularity.angle") * 180.0 / M_PI;
myOldValues.AngleUnit = (STEPCAFControl_ConfigurationNode::AngleUnitMode)Interface_Static::IVal("step.angleunit.mode");
myOldValues.ReadResourceName = Interface_Static::CVal("read.step.resource.name");
myOldValues.ReadSequence = Interface_Static::CVal("read.step.sequence");
myOldValues.ReadProductMode = Interface_Static::IVal("read.step.product.mode") == 1;
myOldValues.ReadProductContext = (STEPCAFControl_ConfigurationNode::ReadMode_ProductContext)Interface_Static::IVal("read.step.product.context");
myOldValues.ReadShapeRepr = (STEPCAFControl_ConfigurationNode::ReadMode_ShapeRepr)Interface_Static::IVal("read.step.shape.repr");
myOldValues.ReadTessellated = (STEPCAFControl_ConfigurationNode::RWMode_Tessellated)Interface_Static::IVal("read.step.tessellated");
myOldValues.ReadAssemblyLevel = (STEPCAFControl_ConfigurationNode::ReadMode_AssemblyLevel)Interface_Static::IVal("read.step.assembly.level");
myOldValues.ReadRelationship = Interface_Static::IVal("read.step.shape.relationship") == 1;
myOldValues.ReadShapeAspect = Interface_Static::IVal("read.step.shape.aspect") == 1;
myOldValues.ReadConstrRelation = Interface_Static::IVal("read.step.constructivegeom.relationship") == 1;
myOldValues.ReadSubshapeNames = Interface_Static::IVal("read.stepcaf.subshapes.name") == 1;
myOldValues.ReadCodePage = (Resource_FormatType)Interface_Static::IVal("read.step.codepage");
myOldValues.ReadNonmanifold = Interface_Static::IVal("read.step.nonmanifold") == 1;
myOldValues.ReadIdeas = Interface_Static::IVal("read.step.ideas") == 1;
myOldValues.ReadAllShapes = Interface_Static::IVal("read.step.all.shapes") == 1;
myOldValues.ReadRootTransformation = Interface_Static::IVal("read.step.root.transformation") == 1;
myOldValues.WritePrecisionMode = (STEPCAFControl_ConfigurationNode::WriteMode_PrecisionMode)Interface_Static::IVal("write.precision.mode");
myOldValues.WritePrecisionVal = Interface_Static::RVal("write.precision.val");
myOldValues.WriteAssembly = (STEPCAFControl_ConfigurationNode::WriteMode_Assembly)Interface_Static::IVal("write.step.assembly");
myOldValues.WriteSchema = (STEPCAFControl_ConfigurationNode::WriteMode_StepSchema)Interface_Static::IVal("write.step.schema");
myOldValues.WriteTessellated = (STEPCAFControl_ConfigurationNode::RWMode_Tessellated)Interface_Static::IVal("write.step.tessellated");
myOldValues.WriteProductName = Interface_Static::CVal("write.step.product.name");
myOldValues.WriteSurfaceCurMode = Interface_Static::IVal("write.surfacecurve.mode") == 1;
myOldValues.WriteUnit = (UnitsMethods_LengthUnit)Interface_Static::IVal("write.step.unit");
myOldValues.WriteResourceName = Interface_Static::CVal("write.resource.name");
myOldValues.WriteSequence = Interface_Static::CVal("write.step.sequence");
myOldValues.WriteVertexMode = (STEPCAFControl_ConfigurationNode::WriteMode_VertexMode)Interface_Static::IVal("write.step.vertex.mode");
myOldValues.WriteSubshapeNames = Interface_Static::IVal("write.stepcaf.subshapes.name") == 1;
// Set new values
setStatic(aNode->InternalParameters);
}
//=======================================================================
// function : setStatic
// purpose :
//=======================================================================
void STEPCAFControl_Provider::setStatic(const STEPCAFControl_ConfigurationNode::STEPCAFControl_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("step.angleunit.mode", theParameter.AngleUnit);
Interface_Static::SetCVal("read.step.resource.name", theParameter.ReadResourceName.ToCString());
Interface_Static::SetCVal("read.step.sequence", theParameter.ReadSequence.ToCString());
Interface_Static::SetIVal("read.step.product.mode", theParameter.ReadProductMode);
Interface_Static::SetIVal("read.step.product.context", theParameter.ReadProductContext);
Interface_Static::SetIVal("read.step.shape.repr", theParameter.ReadShapeRepr);
Interface_Static::SetIVal("read.step.tessellated", theParameter.ReadTessellated);
Interface_Static::SetIVal("read.step.assembly.level", theParameter.ReadAssemblyLevel);
Interface_Static::SetIVal("read.step.shape.relationship", theParameter.ReadRelationship);
Interface_Static::SetIVal("read.step.shape.aspect", theParameter.ReadShapeAspect);
Interface_Static::SetIVal("read.step.constructivegeom.relationship", theParameter.ReadConstrRelation);
Interface_Static::SetIVal("read.stepcaf.subshapes.name", theParameter.ReadSubshapeNames);
Interface_Static::SetIVal("read.step.codepage", theParameter.ReadCodePage);
Interface_Static::SetIVal("read.step.nonmanifold", theParameter.ReadNonmanifold);
Interface_Static::SetIVal("read.step.ideas", theParameter.ReadIdeas);
Interface_Static::SetIVal("read.step.all.shapes", theParameter.ReadAllShapes);
Interface_Static::SetIVal("read.step.root.transformation", theParameter.ReadRootTransformation);
Interface_Static::SetIVal("write.precision.mode", theParameter.WritePrecisionMode);
Interface_Static::SetRVal("write.precision.val", theParameter.WritePrecisionVal);
Interface_Static::SetIVal("write.step.assembly", theParameter.WriteAssembly);
Interface_Static::SetIVal("write.step.schema", theParameter.WriteSchema);
Interface_Static::SetIVal("write.step.tessellated", theParameter.WriteTessellated);
Interface_Static::SetCVal("write.step.product.name", theParameter.WriteProductName.ToCString());
Interface_Static::SetIVal("write.surfacecurve.mode", theParameter.WriteSurfaceCurMode);
Interface_Static::SetIVal("write.step.unit", theParameter.WriteUnit);
Interface_Static::SetCVal("write.resource.name", theParameter.WriteResourceName.ToCString());
Interface_Static::SetCVal("write.step.sequence", theParameter.WriteSequence.ToCString());
Interface_Static::SetIVal("write.step.vertex.mode", theParameter.WriteVertexMode);
Interface_Static::SetIVal("write.stepcaf.subshapes.name", theParameter.WriteSubshapeNames);
}
//=======================================================================
// function : resetStatic
// purpose :
//=======================================================================
void STEPCAFControl_Provider::resetStatic()
{
setStatic(myOldValues);
}
//=======================================================================
// 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());
initStatic(aNode);
XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter);
STEPCAFControl_Reader aReader;
if (!theWS.IsNull())
{
aReader.Init(theWS);
}
aReader.SetColorMode(aNode->InternalParameters.ReadColor);
aReader.SetNameMode(aNode->InternalParameters.ReadName);
aReader.SetLayerMode(aNode->InternalParameters.ReadLayer);
aReader.SetPropsMode(aNode->InternalParameters.ReadProps);
IFSelect_ReturnStatus aReadStat = IFSelect_RetVoid;
aReadStat = aReader.ReadFile(thePath.ToCString());
if (aReadStat != IFSelect_RetDone)
{
Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " <<
thePath << "\t: abandon";
resetStatic();
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";
resetStatic();
return false;
}
resetStatic();
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());
initStatic(aNode);
XCAFDoc_DocumentTool::SetLengthUnit(theDocument,
UnitsMethods::GetLengthUnitScale(aNode->InternalParameters.WriteUnit, UnitsMethods_LengthUnit_Millimeter),
UnitsMethods_LengthUnit_Millimeter);
STEPCAFControl_Writer aWriter;
if (!theWS.IsNull())
{
aWriter.Init(theWS);
}
STEPControl_StepModelType aMode = static_cast<STEPControl_StepModelType>(aNode->InternalParameters.WriteModelType);
aWriter.SetColorMode(aNode->InternalParameters.WriteColor);
aWriter.SetNameMode(aNode->InternalParameters.WriteName);
aWriter.SetLayerMode(aNode->InternalParameters.WriteLayer);
aWriter.SetPropsMode(aNode->InternalParameters.WriteProps);
TDF_Label aLabel;
if (!aWriter.Transfer(theDocument, 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";
resetStatic();
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";
resetStatic();
return false;;
}
case IFSelect_RetDone:
{
break;
}
default:
{
Message::SendFail() << "Error in the STEPCAFControl_Provider during writing the file " <<
thePath << "\t: Error on writing file";
resetStatic();
return false;
}
}
resetStatic();
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;
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;
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());
initStatic(aNode);
STEPControl_Reader aReader;
if(!theWS.IsNull())
{
aReader.SetWS(theWS);
}
IFSelect_ReturnStatus aReadstat = IFSelect_RetVoid;
aReadstat = aReader.ReadFile(thePath.ToCString());
if (aReadstat != IFSelect_RetDone)
{
Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " <<
thePath << "\t: abandon, no model loaded";
resetStatic();
return false;
}
Handle(StepData_StepModel) aModel = Handle(StepData_StepModel)::DownCast(aReader.Model());
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";
resetStatic();
return false;
}
theShape = aReader.OneShape();
resetStatic();
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());
initStatic(aNode);
STEPControl_Writer aWriter;
if(!theWS.IsNull())
{
aWriter.SetWS(theWS);
}
IFSelect_ReturnStatus aWritestat = IFSelect_RetVoid;
Handle(StepData_StepModel) aModel = aWriter.Model();
aModel->SetWriteLengthUnit(UnitsMethods::GetLengthUnitScale(aNode->InternalParameters.WriteUnit, UnitsMethods_LengthUnit_Millimeter));
aWritestat = aWriter.Transfer(theShape, aNode->InternalParameters.WriteModelType, true, theProgress);
if (aWritestat != IFSelect_RetDone)
{
Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " <<
thePath << "\t: abandon, no model loaded";
resetStatic();
return false;
}
if (aWriter.Write(thePath.ToCString()) != IFSelect_RetDone)
{
Message::SendFail() << "STEPCAFControl_Provider: Error on writing file";
resetStatic();
return false;
}
resetStatic();
return true;
}
//=======================================================================
// function : Read
// purpose :
//=======================================================================
bool STEPCAFControl_Provider::Read(const TCollection_AsciiString& thePath,
TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress)
{
Handle(XSControl_WorkSession) aWS;
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;
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");
}

View File

@ -0,0 +1,151 @@
// 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 _STEPCAFControl_Provider_HeaderFile
#define _STEPCAFControl_Provider_HeaderFile
#include <DE_Provider.hxx>
#include <STEPCAFControl_ConfigurationNode.hxx>
//! 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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:
//! Initialize static variables
void initStatic(const Handle(DE_ConfigurationNode)& theNode);
//! Initialize static variables
void setStatic(const STEPCAFControl_ConfigurationNode::STEPCAFControl_InternalSection theParameter);
//! Reset used interface static variables
void resetStatic();
STEPCAFControl_ConfigurationNode::STEPCAFControl_InternalSection myOldValues;
};
#endif // _STEPCAFControl_Provider_HeaderFile

View File

@ -362,7 +362,7 @@ Standard_Integer STEPCAFControl_Reader::NbRootsForTransfer()
//=======================================================================
Standard_Boolean STEPCAFControl_Reader::TransferOneRoot (const Standard_Integer num,
Handle(TDocStd_Document) &doc,
const Handle(TDocStd_Document) &doc,
const Message_ProgressRange& theProgress)
{
TDF_LabelSequence Lseq;
@ -375,7 +375,7 @@ Standard_Boolean STEPCAFControl_Reader::TransferOneRoot (const Standard_Integer
//purpose :
//=======================================================================
Standard_Boolean STEPCAFControl_Reader::Transfer (Handle(TDocStd_Document) &doc,
Standard_Boolean STEPCAFControl_Reader::Transfer (const Handle(TDocStd_Document) &doc,
const Message_ProgressRange& theProgress)
{
TDF_LabelSequence Lseq;
@ -389,7 +389,7 @@ Standard_Boolean STEPCAFControl_Reader::Transfer (Handle(TDocStd_Document) &doc,
//=======================================================================
Standard_Boolean STEPCAFControl_Reader::Perform (const Standard_CString filename,
Handle(TDocStd_Document) &doc,
const Handle(TDocStd_Document) &doc,
const Message_ProgressRange& theProgress)
{
if (ReadFile (filename) != IFSelect_RetDone)
@ -406,7 +406,7 @@ Standard_Boolean STEPCAFControl_Reader::Perform (const Standard_CString filename
//=======================================================================
Standard_Boolean STEPCAFControl_Reader::Perform (const TCollection_AsciiString &filename,
Handle(TDocStd_Document) &doc,
const Handle(TDocStd_Document) &doc,
const Message_ProgressRange& theProgress)
{
if ( ReadFile (filename.ToCString()) != IFSelect_RetDone)
@ -507,7 +507,7 @@ void STEPCAFControl_Reader::prepareUnits(const Handle(StepData_StepModel)& theMo
Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
const Standard_Integer nroot,
Handle(TDocStd_Document) &doc,
const Handle(TDocStd_Document) &doc,
TDF_LabelSequence &Lseq,
const Standard_Boolean asOne,
const Message_ProgressRange& theProgress)
@ -828,7 +828,7 @@ TDF_Label STEPCAFControl_Reader::AddShape(const TopoDS_Shape &S,
Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile (const Standard_CString file,
const Standard_CString fullname,
Handle(TDocStd_Document)& doc,
const Handle(TDocStd_Document)& doc,
const Message_ProgressRange& theProgress)
{
// if the file is already read, associate it with SDR
@ -935,7 +935,7 @@ static void propagateColorToParts(const Handle(XCAFDoc_ShapeTool)& theSTool,
//=======================================================================
Standard_Boolean STEPCAFControl_Reader::ReadColors(const Handle(XSControl_WorkSession) &WS,
Handle(TDocStd_Document)& Doc) const
const Handle(TDocStd_Document)& Doc) const
{
STEPConstruct_Styles Styles(WS);
if (!Styles.LoadStyles()) {
@ -1183,8 +1183,8 @@ TDF_Label STEPCAFControl_Reader::FindInstance(const Handle(StepRepr_NextAssembly
//=======================================================================
Standard_Boolean STEPCAFControl_Reader::ReadNames(const Handle(XSControl_WorkSession) &WS,
Handle(TDocStd_Document)& Doc,
const STEPCAFControl_DataMapOfPDExternFile &PDFileMap) const
const Handle(TDocStd_Document)& Doc,
const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const
{
// get starting data
const Handle(Interface_InterfaceModel) &Model = WS->Model();
@ -1293,8 +1293,8 @@ static TDF_Label GetLabelFromPD(const Handle(StepBasic_ProductDefinition) &PD,
//=======================================================================
Standard_Boolean STEPCAFControl_Reader::ReadValProps(const Handle(XSControl_WorkSession) &WS,
Handle(TDocStd_Document)& Doc,
const STEPCAFControl_DataMapOfPDExternFile &PDFileMap) const
const Handle(TDocStd_Document)& Doc,
const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const
{
// get starting data
const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
@ -1425,7 +1425,7 @@ Standard_Boolean STEPCAFControl_Reader::ReadValProps(const Handle(XSControl_Work
//=======================================================================
Standard_Boolean STEPCAFControl_Reader::ReadLayers(const Handle(XSControl_WorkSession) &WS,
Handle(TDocStd_Document)& Doc) const
const Handle(TDocStd_Document)& Doc) const
{
const Handle(Interface_InterfaceModel) &Model = WS->Model();
const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
@ -1596,8 +1596,8 @@ static TDF_Label setSHUOintoDoc(const Handle(XSControl_WorkSession) &WS,
//=======================================================================
Standard_Boolean STEPCAFControl_Reader::ReadSHUOs(const Handle(XSControl_WorkSession) &WS,
Handle(TDocStd_Document)& Doc,
const STEPCAFControl_DataMapOfPDExternFile &PDFileMap) const
const Handle(TDocStd_Document)& Doc,
const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const
{
// the big part code duplication from ReadColors.
// It is possible to share this code functionality, just to decide how ???
@ -3890,7 +3890,7 @@ static void setGeomTolObjectToXCAF(const Handle(Standard_Transient)& theEnt,
//=======================================================================
Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession)& theWS,
Handle(TDocStd_Document)& theDoc)
const Handle(TDocStd_Document)& theDoc)
{
const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
const Interface_Graph& aGraph = theWS->Graph();
@ -4100,8 +4100,8 @@ static Handle(StepShape_SolidModel) FindSolidForPDS(const Handle(StepRepr_Produc
//=======================================================================
Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_WorkSession) &WS,
Handle(TDocStd_Document)& Doc,
const Handle(TColStd_HSequenceOfTransient) &SeqPDS) const
const Handle(TDocStd_Document)& Doc,
const Handle(TColStd_HSequenceOfTransient)& SeqPDS) const
{
const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
@ -4323,7 +4323,7 @@ Handle(TCollection_HAsciiString) buildClippingPlanes(const Handle(StepGeom_Geome
//function : ReadViews
//purpose :
//=======================================================================
Standard_Boolean STEPCAFControl_Reader::ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const
Standard_Boolean STEPCAFControl_Reader::ReadViews(const Handle(XSControl_WorkSession)& theWS, const Handle(TDocStd_Document)& theDoc) const
{
const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());

View File

@ -86,23 +86,23 @@ public:
//! Returns True if succeeded, and False in case of fail
//! Provided for use like single-file reader
Standard_EXPORT Standard_Boolean TransferOneRoot (const Standard_Integer num,
Handle(TDocStd_Document)& doc,
const Handle(TDocStd_Document)& doc,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Translates currently loaded STEP file into the document
//! Returns True if succeeded, and False in case of fail
//! Provided for use like single-file reader
Standard_EXPORT Standard_Boolean Transfer (Handle(TDocStd_Document)& doc,
Standard_EXPORT Standard_Boolean Transfer (const Handle(TDocStd_Document)& doc,
const Message_ProgressRange& theProgress = Message_ProgressRange());
Standard_EXPORT Standard_Boolean Perform (const TCollection_AsciiString& filename,
Handle(TDocStd_Document)& doc,
const Handle(TDocStd_Document)& doc,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Translate STEP file given by filename into the document
//! Return True if succeeded, and False in case of fail
Standard_EXPORT Standard_Boolean Perform (const Standard_CString filename,
Handle(TDocStd_Document)& doc,
const Handle(TDocStd_Document)& doc,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Returns data on external files
@ -181,7 +181,7 @@ protected:
//! them into assembly. Fills sequence of produced labels
Standard_EXPORT Standard_Boolean Transfer (STEPControl_Reader& rd,
const Standard_Integer num,
Handle(TDocStd_Document)& doc,
const Handle(TDocStd_Document)& doc,
TDF_LabelSequence& Lseq,
const Standard_Boolean asOne = Standard_False,
const Message_ProgressRange& theProgress = Message_ProgressRange());
@ -196,42 +196,42 @@ protected:
//! given name
Standard_EXPORT Handle(STEPCAFControl_ExternFile) ReadExternFile (const Standard_CString file,
const Standard_CString fullpath,
Handle(TDocStd_Document)& doc,
const Handle(TDocStd_Document)& doc,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Reads style assignments from STEP model and sets
//! corresponding color assignments in the DECAF document
Standard_EXPORT Standard_Boolean ReadColors
(const Handle(XSControl_WorkSession)& WS,
Handle(TDocStd_Document)& doc) const;
const Handle(TDocStd_Document)& doc) const;
//! Reads names of parts defined in the STEP model and
//! assigns them to corresponding labels in the DECAF document
Standard_EXPORT Standard_Boolean ReadNames (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const;
Standard_EXPORT Standard_Boolean ReadNames (const Handle(XSControl_WorkSession)& WS, const Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const;
//! Reads validation properties assigned to shapes in the STEP
//! model and assigns them to corresponding labels in the DECAF
//! document
Standard_EXPORT Standard_Boolean ReadValProps (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const;
Standard_EXPORT Standard_Boolean ReadValProps (const Handle(XSControl_WorkSession)& WS, const Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const;
//! Reads layers of parts defined in the STEP model and
//! set reference between shape and layers in the DECAF document
Standard_EXPORT Standard_Boolean ReadLayers (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc) const;
Standard_EXPORT Standard_Boolean ReadLayers (const Handle(XSControl_WorkSession)& WS, const Handle(TDocStd_Document)& doc) const;
//! Reads SHUO for instances defined in the STEP model and
//! set reference between shape instances from different assemblyes
Standard_EXPORT Standard_Boolean ReadSHUOs (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const;
Standard_EXPORT Standard_Boolean ReadSHUOs (const Handle(XSControl_WorkSession)& WS, const Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const;
//! Reads D&GT for instances defined in the STEP model and
//! set reference between shape instances from different assemblyes
Standard_EXPORT Standard_Boolean ReadGDTs (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc);
Standard_EXPORT Standard_Boolean ReadGDTs (const Handle(XSControl_WorkSession)& WS, const Handle(TDocStd_Document)& doc);
//! Reads materials for instances defined in the STEP model and
//! set reference between shape instances from different assemblyes
Standard_EXPORT Standard_Boolean ReadMaterials (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const Handle(TColStd_HSequenceOfTransient)& SeqPDS) const;
Standard_EXPORT Standard_Boolean ReadMaterials (const Handle(XSControl_WorkSession)& WS, const Handle(TDocStd_Document)& doc, const Handle(TColStd_HSequenceOfTransient)& SeqPDS) const;
//! Reads Views for instances defined in the STEP model
Standard_EXPORT Standard_Boolean ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const;
Standard_EXPORT Standard_Boolean ReadViews(const Handle(XSControl_WorkSession)& theWS, const Handle(TDocStd_Document)& theDoc) const;
//! Populates the sub-Label of the passed TDF Label with shape
//! data associated with the given STEP Representation Item,

View File

@ -216,31 +216,31 @@ STEPControl_Controller::STEPControl_Controller ()
// Note: the numbers should be consistent with Resource_FormatType enumeration
Interface_Static::Init("step", "read.step.codepage", 'e', "");
Interface_Static::Init("step", "read.step.codepage", '&', "enum 0");
Interface_Static::Init("step", "read.step.codepage", '&', "eval SJIS"); // Resource_FormatType_SJIS
Interface_Static::Init("step", "read.step.codepage", '&', "eval EUC"); // Resource_FormatType_EUC
Interface_Static::Init("step", "read.step.codepage", '&', "eval NoConversion"); // Resource_FormatType_NoConversion
Interface_Static::Init("step", "read.step.codepage", '&', "eval GB"); // Resource_FormatType_GB
Interface_Static::Init("step", "read.step.codepage", '&', "eval UTF8"); // Resource_FormatType_UTF8
Interface_Static::Init("step", "read.step.codepage", '&', "eval SystemLocale"); // Resource_FormatType_SystemLocale
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1250"); // Resource_FormatType_CP1250
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1251"); // Resource_FormatType_CP1251
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1252"); // Resource_FormatType_CP1252
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1253"); // Resource_FormatType_CP1253
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1254"); // Resource_FormatType_CP1254
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1255"); // Resource_FormatType_CP1255
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1256"); // Resource_FormatType_CP1256
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1257"); // Resource_FormatType_CP1257
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1258"); // Resource_FormatType_CP1258
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-1"); // Resource_FormatType_iso8859_1
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-2"); // Resource_FormatType_iso8859_2
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-3"); // Resource_FormatType_iso8859_3
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-4"); // Resource_FormatType_iso8859_4
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-5"); // Resource_FormatType_iso8859_5
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-6"); // Resource_FormatType_iso8859_6
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-7"); // Resource_FormatType_iso8859_7
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-8"); // Resource_FormatType_iso8859_8
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-9"); // Resource_FormatType_iso8859_9
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP850"); // Resource_FormatType_CP850
Interface_Static::Init("step", "read.step.codepage", '&', "eval SJIS"); // Resource_FormatType_SJIS 0
Interface_Static::Init("step", "read.step.codepage", '&', "eval EUC"); // Resource_FormatType_EUC 1
Interface_Static::Init("step", "read.step.codepage", '&', "eval NoConversion"); // Resource_FormatType_NoConversion 2
Interface_Static::Init("step", "read.step.codepage", '&', "eval GB"); // Resource_FormatType_GB 3
Interface_Static::Init("step", "read.step.codepage", '&', "eval UTF8"); // Resource_FormatType_UTF8 4
Interface_Static::Init("step", "read.step.codepage", '&', "eval SystemLocale"); // Resource_FormatType_SystemLocale 5
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1250"); // Resource_FormatType_CP1250 6
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1251"); // Resource_FormatType_CP1251 7
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1252"); // Resource_FormatType_CP1252 8
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1253"); // Resource_FormatType_CP1253 9
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1254"); // Resource_FormatType_CP1254 10
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1255"); // Resource_FormatType_CP1255 11
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1256"); // Resource_FormatType_CP1256 12
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1257"); // Resource_FormatType_CP1257 13
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP1258"); // Resource_FormatType_CP1258 14
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-1"); // Resource_FormatType_iso8859_1 15
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-2"); // Resource_FormatType_iso8859_2 16
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-3"); // Resource_FormatType_iso8859_3 17
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-4"); // Resource_FormatType_iso8859_4 18
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-5"); // Resource_FormatType_iso8859_5 19
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-6"); // Resource_FormatType_iso8859_6 20
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-7"); // Resource_FormatType_iso8859_7 21
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-8"); // Resource_FormatType_iso8859_8 22
Interface_Static::Init("step", "read.step.codepage", '&', "eval iso8859-9"); // Resource_FormatType_iso8859_9 23
Interface_Static::Init("step", "read.step.codepage", '&', "eval CP850"); // Resource_FormatType_CP850 24
Interface_Static::SetCVal("read.step.codepage", "UTF8");
// Tessellated geometry reading: Off by default

View File

@ -1,3 +1,4 @@
TKBinXCAF
TKernel
TKMath
TKMesh
@ -6,6 +7,7 @@ TKLCAF
TKV3d
TKBRep
TKG3d
TKXDE
TKService
CSF_RapidJSON
CSF_Draco

View File

@ -1,6 +1,10 @@
TKBinXCAF
TKXDE
TKernel
TKMath
TKBRep
TKG2d
TKG3d
TKTopAlgo
TKLCAF
TKXCAF

View File

@ -1,4 +1,6 @@
TKBinXCAF
TKBRep
TKXDE
TKTopAlgo
TKMath
TKGeomBase
@ -13,3 +15,4 @@ TKGeomAlgo
TKV3d
TKLCAF
TKXCAF
TKXSBase

3
src/TKXDE/CMakeLists.txt Normal file
View File

@ -0,0 +1,3 @@
project(TKXDE)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

1
src/TKXDE/EXTERNLIB Normal file
View File

@ -0,0 +1 @@
TKernel

2
src/TKXDE/FILES Normal file
View File

@ -0,0 +1,2 @@
EXTERNLIB
PACKAGES

1
src/TKXDE/PACKAGES Normal file
View File

@ -0,0 +1 @@
DE

View File

@ -0,0 +1,3 @@
project(TKXDECascade)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

View File

@ -0,0 +1,12 @@
TKBin
TKBinL
TKBinTObj
TKBinXCAF
TKStd
TKXml
TKXmlL
TKXmlTObj
TKXmlXCAF
TKXDE
TKernel
TKLCAF

2
src/TKXDECascade/FILES Normal file
View File

@ -0,0 +1,2 @@
EXTERNLIB
PACKAGES

View File

@ -0,0 +1,2 @@
DEBRepCascade
DEXCAFCascade

View File

@ -1,3 +1,4 @@
TKXDE
TKCDF
TKBRep
TKXCAF
@ -14,10 +15,13 @@ TKDraw
TKTopAlgo
TKLCAF
TKG3d
TKRWMesh
TKSTEPBase
TKSTEP
TKSTL
TKMesh
TKXSDRAW
TKXDECascade
TKXDEIGES
TKXDESTEP
TKDCAF

View File

@ -1,4 +1,6 @@
TKBinXCAF
TKBRep
TKXDE
TKernel
TKMath
TKXSBase

View File

@ -1,3 +1,5 @@
TKBinXCAF
TKXDE
TKBRep
TKSTEPAttr
TKernel

View File

@ -6,6 +6,8 @@ Vrml_AsciiTextJustification.hxx
Vrml_Cone.cxx
Vrml_Cone.hxx
Vrml_ConeParts.hxx
Vrml_ConfigurationNode.cxx
Vrml_ConfigurationNode.hxx
Vrml_Coordinate3.cxx
Vrml_Coordinate3.hxx
Vrml_Cube.cxx
@ -51,6 +53,8 @@ Vrml_PointLight.cxx
Vrml_PointLight.hxx
Vrml_PointSet.cxx
Vrml_PointSet.hxx
Vrml_Provider.cxx
Vrml_Provider.hxx
Vrml_Rotation.cxx
Vrml_Rotation.hxx
Vrml_Scale.cxx

View File

@ -0,0 +1,155 @@
// 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 <Vrml_ConfigurationNode.hxx>
#include <DE_ConfigurationContext.hxx>
#include <Vrml_Provider.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Vrml_ConfigurationNode, DE_ConfigurationNode)
static const TCollection_AsciiString THE_CONFIGURATION_SCOPE = "provider";
//=======================================================================
// function : STEPCAFControl_ConfigurationNode
// purpose :
//=======================================================================
Vrml_ConfigurationNode::Vrml_ConfigurationNode() :
DE_ConfigurationNode()
{
UpdateLoad();
}
//=======================================================================
// function : STEPCAFControl_ConfigurationNode
// purpose :
//=======================================================================
Vrml_ConfigurationNode::Vrml_ConfigurationNode(const Handle(Vrml_ConfigurationNode)& theNode)
:DE_ConfigurationNode(theNode)
{
InternalParameters = theNode->InternalParameters;
UpdateLoad();
}
//=======================================================================
// function : Load
// purpose :
//=======================================================================
bool Vrml_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource)
{
TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE + "." + GetFormat() + "." + GetVendor();
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 += "!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;
}

View File

@ -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 _Vrml_ConfigurationNode_HeaderFile
#define _Vrml_ConfigurationNode_HeaderFile
#include <DE_ConfigurationNode.hxx>
//! 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
{
// Write
WriteMode_WriterVersion WriterVersion = WriteMode_WriterVersion_2; //!< Setting up writer version (1/2)
WriteMode_RepresentationType WriteRepresentationType = WriteMode_RepresentationType_Wireframe; //!< Setting up representation (shaded/wireframe/both)
} InternalParameters;
};
#endif // _Vrml_ConfigurationNode_HeaderFile

285
src/Vrml/Vrml_Provider.cxx Normal file
View File

@ -0,0 +1,285 @@
// 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 <Vrml_Provider.hxx>
#include <BinXCAFDrivers.hxx>
#include <Message.hxx>
#include <OSD_Path.hxx>
#include <TDocStd_Document.hxx>
#include <VrmlAPI_Writer.hxx>
#include <VrmlData_Scene.hxx>
#include <Vrml_ConfigurationNode.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_DocumentTool.hxx>
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());
TopoDS_Shape aShape;
if(!Read(thePath, aShape, theProgress))
{
return false;
}
Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
aShTool->AddShape(aShape);
XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter);
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<VrmlAPI_RepresentationOfShape>(aNode->InternalParameters.WriteRepresentationType));
Standard_Real aScaleFactorM = aNode->GlobalParameters.LengthUnit / 1000;
if (!aWriter.WriteDoc(theDocument, thePath.ToCString(), aScaleFactorM))
{
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;
Standard_Real anOCCUnitMM = aNode->GlobalParameters.LengthUnit;
aScene.SetLinearScale(1000. / anOCCUnitMM);
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");
}

136
src/Vrml/Vrml_Provider.hxx Normal file
View File

@ -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 _Vrml_Provider_HeaderFile
#define _Vrml_Provider_HeaderFile
#include <DE_Provider.hxx>
//! 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 theProgress[in] 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 // _Vrml_Provider_HeaderFile

View File

@ -24,14 +24,23 @@
#include <DDF_Browser.hxx>
#include <DDocStd.hxx>
#include <DDocStd_DrawDocument.hxx>
#include <DE_Wrapper.hxx>
#include <DEBRepCascade_ConfigurationNode.hxx>
#include <DEXCAFCascade_ConfigurationNode.hxx>
#include <Draw.hxx>
#include <Draw_PluginMacro.hxx>
#include <Draw_ProgressIndicator.hxx>
#include <Geom_Axis2Placement.hxx>
#include <IGESCAFControl_ConfigurationNode.hxx>
#include <Prs3d_Drawer.hxx>
#include <Prs3d_LineAspect.hxx>
#include <Quantity_Color.hxx>
#include <RWStl_ConfigurationNode.hxx>
#include <RWGltf_ConfigurationNode.hxx>
#include <RWObj_ConfigurationNode.hxx>
#include <RWPly_ConfigurationNode.hxx>
#include <STEPCAFControl_Controller.hxx>
#include <STEPCAFControl_ConfigurationNode.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
#include <TCollection_HAsciiString.hxx>
@ -70,6 +79,7 @@
#include <V3d_Viewer.hxx>
#include <ViewerTest.hxx>
#include <ViewerTest_AutoUpdater.hxx>
#include <Vrml_ConfigurationNode.hxx>
#include <XCAFDoc.hxx>
#include <XCAFDoc_AssemblyIterator.hxx>
#include <XCAFDoc_AssemblyGraph.hxx>
@ -1839,6 +1849,15 @@ void XDEDRAW::Init(Draw_Interpretor& di)
XDEDRAW_Notes::InitCommands(di);
XDEDRAW_Common::InitCommands ( di );//moved from EXE
DE_Wrapper::GlobalWrapper()->Bind(new RWObj_ConfigurationNode());
DE_Wrapper::GlobalWrapper()->Bind(new RWPly_ConfigurationNode());
DE_Wrapper::GlobalWrapper()->Bind(new RWGltf_ConfigurationNode());
DE_Wrapper::GlobalWrapper()->Bind(new IGESCAFControl_ConfigurationNode());
DE_Wrapper::GlobalWrapper()->Bind(new STEPCAFControl_ConfigurationNode());
DE_Wrapper::GlobalWrapper()->Bind(new Vrml_ConfigurationNode());
DE_Wrapper::GlobalWrapper()->Bind(new DEXCAFCascade_ConfigurationNode());
DE_Wrapper::GlobalWrapper()->Bind(new RWStl_ConfigurationNode());
DE_Wrapper::GlobalWrapper()->Bind(new DEBRepCascade_ConfigurationNode());
}

File diff suppressed because it is too large Load Diff

View File

@ -1047,6 +1047,7 @@ static Standard_Integer loadvrml
}
VrmlData_Scene aScene;
XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
Standard_Real anOCCUnitMM = UnitsMethods::GetCasCadeLengthUnit();
aScene.SetLinearScale(1000. / anOCCUnitMM);

5
tests/de_wrapper/begin Normal file
View File

@ -0,0 +1,5 @@
# File: begin
pload XDE
pload OCAF
pload TOPTEST

16
tests/de_wrapper/brep/A1 Normal file
View File

@ -0,0 +1,16 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
readbrep ${filename} S_First
set file_path ${imagedir}/${casename}.brep
writebrep S_First $file_path
readfile S_Second $file_path
checknbshapes S_Second -ref [nbshapes S_First]
file delete $file_path

22
tests/de_wrapper/brep/A2 Normal file
View File

@ -0,0 +1,22 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
catch { Close D_First }
catch { Close D_Second }
readbrep ${filename} S_First
XNewDoc D_First
XAddShape D_First S_First
set file_path ${imagedir}/${casename}.brep
WriteFile D_First $file_path
readbrep ${filename} S_Second
checknbshapes S_Second -ref [nbshapes S_First]
file delete $file_path
Close D_First

20
tests/de_wrapper/brep/A3 Normal file
View File

@ -0,0 +1,20 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
catch { Close D_First }
readbrep ${filename} S_First
set file_path ${imagedir}/${casename}.brep
writefile S_First $file_path
ReadFile D_First $file_path
XGetOneShape S_Second D_First
checknbshapes S_Second -ref [nbshapes S_First]
file delete $file_path
Close D_First

16
tests/de_wrapper/brep/A4 Normal file
View File

@ -0,0 +1,16 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
readfile S_First ${filename}
set file_path ${imagedir}/${casename}.brep
writefile S_First $file_path
readfile S_Second $file_path
checknbshapes S_Second -ref [nbshapes S_First]
file delete $file_path

View File

@ -0,0 +1,3 @@
# File: begin
set filename [locate_data_file "bug24490_face_naturalrestriction_flag.brep"]

View File

@ -0,0 +1,15 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
# Checking the stability of ability to change the configuration's values
set old_conf [DumpConfiguration]
set res_conf [changeconf "1" "$old_conf"]
LoadConfiguration ${res_conf}
set new_conf [DumpConfiguration]
CompareConfiguration ${res_conf} ${new_conf}

View File

@ -0,0 +1,15 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
# Checking the stability of ability to change the configuration's values
set old_conf [DumpConfiguration]
set res_conf [changeconf "0" "$old_conf"]
LoadConfiguration ${res_conf}
set new_conf [DumpConfiguration]
CompareConfiguration ${res_conf} ${new_conf}

View File

@ -0,0 +1,164 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
# Checking the stability of the initial configuration
set ref_conf "
global.priority.STEP : OCC
global.priority.VRML : OCC
global.priority.STL : OCC
global.priority.OBJ : OCC
global.priority.GLTF : OCC
global.priority.BREP : OCC
global.priority.XCAF : OCC
global.priority.IGES : OCC
global.priority.PLY : OCC
global.general.length.unit : 1
provider.STEP.OCC.read.iges.bspline.continuity : 1
provider.STEP.OCC.read.precision.mode : 0
provider.STEP.OCC.read.precision.val : 0.0001
provider.STEP.OCC.read.maxprecision.mode : 0
provider.STEP.OCC.read.maxprecision.val : 1
provider.STEP.OCC.read.stdsameparameter.mode : 0
provider.STEP.OCC.read.surfacecurve.mode : 0
provider.STEP.OCC.read.encoderegularity.angle : 0.572958
provider.STEP.OCC.angleunit.mode : 0
provider.STEP.OCC.read.resource.name : STEP
provider.STEP.OCC.read.sequence : FromSTEP
provider.STEP.OCC.read.product.mode : 1
provider.STEP.OCC.read.product.context : 1
provider.STEP.OCC.read.shape.repr : 1
provider.STEP.OCC.read.tessellated : 1
provider.STEP.OCC.read.assembly.level : 1
provider.STEP.OCC.read.shape.relationship : 1
provider.STEP.OCC.read.shape.aspect : 1
provider.STEP.OCC.read.constructivegeom.relationship : 0
provider.STEP.OCC.read.stepcaf.subshapes.name : 0
provider.STEP.OCC.read.codepage : 4
provider.STEP.OCC.read.nonmanifold : 0
provider.STEP.OCC.read.ideas : 0
provider.STEP.OCC.read.all.shapes : 0
provider.STEP.OCC.read.root.transformation : 1
provider.STEP.OCC.read.color : 1
provider.STEP.OCC.read.name : 1
provider.STEP.OCC.read.layer : 1
provider.STEP.OCC.read.props : 1
provider.STEP.OCC.write.precision.mode : 0
provider.STEP.OCC.write.precision.val : 0.0001
provider.STEP.OCC.write.assembly : 0
provider.STEP.OCC.write.schema : 1
provider.STEP.OCC.write.tessellated : 2
provider.STEP.OCC.write.product.name :
provider.STEP.OCC.write.surfacecurve.mode : 1
provider.STEP.OCC.write.unit : 2
provider.STEP.OCC.write.resource.name : STEP
provider.STEP.OCC.write.sequence : ToSTEP
provider.STEP.OCC.write.vertex.mode : 0
provider.STEP.OCC.write.stepcaf.subshapes.name : 0
provider.STEP.OCC.write.color : 1
provider.STEP.OCC.write.name : 1
provider.STEP.OCC.write.layer : 1
provider.STEP.OCC.write.props : 1
provider.STEP.OCC.write.model.type : 0
provider.VRML.OCC.writer.version : 2
provider.VRML.OCC.write.representation.type : 1
provider.STL.OCC.read.merge.angle : 90
provider.STL.OCC.read.brep : 0
provider.STL.OCC.write.ascii : 1
provider.OBJ.OCC.file.length.unit : 1
provider.OBJ.OCC.system.cs : 0
provider.OBJ.OCC.file.cs : 1
provider.OBJ.OCC.read.single.precision : 0
provider.OBJ.OCC.read.create.shapes : 0
provider.OBJ.OCC.read.root.prefix :
provider.OBJ.OCC.read.fill.doc : 1
provider.OBJ.OCC.read.fill.incomplete : 1
provider.OBJ.OCC.read.memory.limit.mib : -1
provider.OBJ.OCC.write.comment :
provider.OBJ.OCC.write.author :
provider.GLTF.OCC.file.length.unit : 1
provider.GLTF.OCC.system.cs : 0
provider.GLTF.OCC.file.cs : 1
provider.GLTF.OCC.read.single.precision : 1
provider.GLTF.OCC.read.create.shapes : 0
provider.GLTF.OCC.read.root.prefix :
provider.GLTF.OCC.read.fill.doc : 1
provider.GLTF.OCC.read.fill.incomplete : 1
provider.GLTF.OCC.read.memory.limit.mib : -1
provider.GLTF.OCC.read.parallel : 0
provider.GLTF.OCC.read.skip.empty.nodes : 1
provider.GLTF.OCC.read.load.all.scenes : 0
provider.GLTF.OCC.read.use.mesh.name.as.fallback : 1
provider.GLTF.OCC.read.skip.late.data.loading : 0
provider.GLTF.OCC.read.keep.late.data : 1
provider.GLTF.OCC.read.print.debug.message : 0
provider.GLTF.OCC.write.comment :
provider.GLTF.OCC.write.author :
provider.GLTF.OCC.write.trsf.format : 0
provider.GLTF.OCC.write.node.name.format : 3
provider.GLTF.OCC.write.mesh.name.format : 1
provider.GLTF.OCC.write.forced.uv.export : 0
provider.GLTF.OCC.write.embed.textures.in.glb : 1
provider.GLTF.OCC.write.merge.faces : 0
provider.GLTF.OCC.write.split.indices16 : 0
provider.BREP.OCC.write.binary : 1
provider.BREP.OCC.write.version.binary : 4
provider.BREP.OCC.write.version.ascii : 3
provider.BREP.OCC.write.triangles : 1
provider.BREP.OCC.write.normals : 1
provider.XCAF.OCC.read.append.mode : 0
provider.XCAF.OCC.read.skip.values :
provider.XCAF.OCC.read.values :
provider.IGES.OCC.read.iges.bspline.continuity : 1
provider.IGES.OCC.read.precision.mode : 0
provider.IGES.OCC.read.precision.val : 0.0001
provider.IGES.OCC.read.maxprecision.mode : 0
provider.IGES.OCC.read.maxprecision.val : 1
provider.IGES.OCC.read.stdsameparameter.mode : 0
provider.IGES.OCC.read.surfacecurve.mode : 0
provider.IGES.OCC.read.encoderegularity.angle : 0.572958
provider.IGES.OCC.read.bspline.approxd1.mode : 0
provider.IGES.OCC.read.resource.name : IGES
provider.IGES.OCC.read.sequence : FromIGES
provider.IGES.OCC.read.fau_lty.entities : 0
provider.IGES.OCC.read.onlyvisible : 0
provider.IGES.OCC.read.color : 1
provider.IGES.OCC.read.name : 1
provider.IGES.OCC.read.layer : 1
provider.IGES.OCC.write.brep.mode : 0
provider.IGES.OCC.write.convertsurface.mode : 0
provider.IGES.OCC.write.unit : 2
provider.IGES.OCC.write.header.author :
provider.IGES.OCC.write.header.company :
provider.IGES.OCC.write.header.product :
provider.IGES.OCC.write.header.receiver :
provider.IGES.OCC.write.resource.name : IGES
provider.IGES.OCC.write.sequence : ToIGES
provider.IGES.OCC.write.precision.mode : 0
provider.IGES.OCC.write.precision.val : 0.0001
provider.IGES.OCC.write.plane.mode : 0
provider.IGES.OCC.write.offset : 0
provider.IGES.OCC.write.color : 1
provider.IGES.OCC.write.name : 1
provider.IGES.OCC.write.layer : 1
provider.PLY.OCC.file.length.unit : 1
provider.PLY.OCC.system.cs : 0
provider.PLY.OCC.file.cs : 1
provider.PLY.OCC.write.pnt.set : 0
provider.PLY.OCC.write.distance : 0
provider.PLY.OCC.write.density : 2e+100
provider.PLY.OCC.write.tolerance : 1e-07
provider.PLY.OCC.write.normals : 1
provider.PLY.OCC.write.colors : 1
provider.PLY.OCC.write.tex.coords : 0
provider.PLY.OCC.write.part.id : 1
provider.PLY.OCC.write.face.id : 0
provider.PLY.OCC.write.comment :
provider.PLY.OCC.write.author :
"
set dump_conf [DumpConfiguration]
CompareConfiguration $ref_conf $dump_conf

View File

@ -0,0 +1,100 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
# Checking the dumping resource for the two format only
set conf_ref "
global.priority.STEP : OCC
global.priority.VRML : OCC
global.priority.STL : OCC
global.priority.OBJ : OCC
global.priority.GLTF : OCC
global.priority.BREP : OCC
global.priority.XCAF : OCC
global.priority.IGES : OCC
global.priority.PLY : OCC
global.general.length.unit : 1
provider.STEP.OCC.read.iges.bspline.continuity : 1
provider.STEP.OCC.read.precision.mode : 0
provider.STEP.OCC.read.precision.val : 0.0001
provider.STEP.OCC.read.maxprecision.mode : 0
provider.STEP.OCC.read.maxprecision.val : 1
provider.STEP.OCC.read.stdsameparameter.mode : 0
provider.STEP.OCC.read.surfacecurve.mode : 0
provider.STEP.OCC.read.encoderegularity.angle : 0.572958
provider.STEP.OCC.angleunit.mode : 0
provider.STEP.OCC.read.resource.name : STEP
provider.STEP.OCC.read.sequence : FromSTEP
provider.STEP.OCC.read.product.mode : 1
provider.STEP.OCC.read.product.context : 1
provider.STEP.OCC.read.shape.repr : 1
provider.STEP.OCC.read.tessellated : 1
provider.STEP.OCC.read.assembly.level : 1
provider.STEP.OCC.read.shape.relationship : 1
provider.STEP.OCC.read.shape.aspect : 1
provider.STEP.OCC.read.constructivegeom.relationship : 0
provider.STEP.OCC.read.stepcaf.subshapes.name : 0
provider.STEP.OCC.read.codepage : 4
provider.STEP.OCC.read.nonmanifold : 0
provider.STEP.OCC.read.ideas : 0
provider.STEP.OCC.read.all.shapes : 0
provider.STEP.OCC.read.root.transformation : 1
provider.STEP.OCC.read.color : 1
provider.STEP.OCC.read.name : 1
provider.STEP.OCC.read.layer : 1
provider.STEP.OCC.read.props : 1
provider.STEP.OCC.write.precision.mode : 0
provider.STEP.OCC.write.precision.val : 0.0001
provider.STEP.OCC.write.assembly : 0
provider.STEP.OCC.write.schema : 1
provider.STEP.OCC.write.tessellated : 2
provider.STEP.OCC.write.product.name :
provider.STEP.OCC.write.surfacecurve.mode : 1
provider.STEP.OCC.write.unit : 2
provider.STEP.OCC.write.resource.name : STEP
provider.STEP.OCC.write.sequence : ToSTEP
provider.STEP.OCC.write.vertex.mode : 0
provider.STEP.OCC.write.stepcaf.subshapes.name : 0
provider.STEP.OCC.write.color : 1
provider.STEP.OCC.write.name : 1
provider.STEP.OCC.write.layer : 1
provider.STEP.OCC.write.props : 1
provider.STEP.OCC.write.model.type : 0
provider.IGES.OCC.read.iges.bspline.continuity : 1
provider.IGES.OCC.read.precision.mode : 0
provider.IGES.OCC.read.precision.val : 0.0001
provider.IGES.OCC.read.maxprecision.mode : 0
provider.IGES.OCC.read.maxprecision.val : 1
provider.IGES.OCC.read.stdsameparameter.mode : 0
provider.IGES.OCC.read.surfacecurve.mode : 0
provider.IGES.OCC.read.encoderegularity.angle : 0.572958
provider.IGES.OCC.read.bspline.approxd1.mode : 0
provider.IGES.OCC.read.resource.name : IGES
provider.IGES.OCC.read.sequence : FromIGES
provider.IGES.OCC.read.fau_lty.entities : 0
provider.IGES.OCC.read.onlyvisible : 0
provider.IGES.OCC.read.color : 1
provider.IGES.OCC.read.name : 1
provider.IGES.OCC.read.layer : 1
provider.IGES.OCC.write.brep.mode : 0
provider.IGES.OCC.write.convertsurface.mode : 0
provider.IGES.OCC.write.unit : 2
provider.IGES.OCC.write.header.author :
provider.IGES.OCC.write.header.company :
provider.IGES.OCC.write.header.product :
provider.IGES.OCC.write.header.receiver :
provider.IGES.OCC.write.resource.name : IGES
provider.IGES.OCC.write.sequence : ToIGES
provider.IGES.OCC.write.precision.mode : 0
provider.IGES.OCC.write.precision.val : 0.0001
provider.IGES.OCC.write.plane.mode : 0
provider.IGES.OCC.write.offset : 0
provider.IGES.OCC.write.color : 1
provider.IGES.OCC.write.name : 1
provider.IGES.OCC.write.layer : 1
"
set conf [DumpConfiguration -vendor OCC -format STEP IGES]
CompareConfiguration ${conf_ref} ${conf}

View File

@ -0,0 +1,16 @@
# File : begin
proc changeconf {value conf} {
set res ""
foreach iter [split $conf \n] {
if {![regexp {!.*} $iter]} {
if {[regexp {(provider.*:)} $iter scope]} {
append res "$scope $value \t\n"
}
if {[regexp {(global.*:)} $iter scope]} {
append res "$iter\n"
}
}
}
return $res
}

1
tests/de_wrapper/end Normal file
View File

@ -0,0 +1 @@
puts "TEST COMPLETED"

23
tests/de_wrapper/gltf/A1 Normal file
View File

@ -0,0 +1,23 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
catch { Close D_First }
catch { Close D_Second }
ReadGltf D_First ${filename}
XGetOneShape S_First D_First
set file_path ${imagedir}/${casename}.gltf
WriteGltf D_First $file_path
ReadFile D_Second $file_path
XGetOneShape S_Second D_Second
checktrinfo S_Second -ref [trinfo S_First]
file delete $file_path
Close D_First
Close D_Second

23
tests/de_wrapper/gltf/A2 Normal file
View File

@ -0,0 +1,23 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
catch { Close D_First }
catch { Close D_Second }
ReadGltf D_First ${filename}
XGetOneShape S_First D_First
set file_path ${imagedir}/${casename}.gltf
WriteFile D_First $file_path -conf "provider.GLTF.OCC.author: GLTF_AUTHOR "
ReadGltf D_Second $file_path
XGetOneShape S_Second D_Second
checktrinfo S_Second -ref [trinfo S_First]
file delete $file_path
Close D_First
Close D_Second

23
tests/de_wrapper/gltf/A3 Normal file
View File

@ -0,0 +1,23 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
catch { Close D_First }
catch { Close D_Second }
ReadGltf D_First ${filename}
XGetOneShape S_First D_First
set file_path ${imagedir}/${casename}.gltf
writefile S_First $file_path -conf "provider.GLTF.OCC.author: GLTF_AUTHOR "
ReadGltf D_Second $file_path
XGetOneShape S_Second D_Second
checktrinfo S_Second -ref [trinfo S_First]
file delete $file_path
Close D_First
Close D_Second

16
tests/de_wrapper/gltf/A4 Normal file
View File

@ -0,0 +1,16 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
readfile S_First ${filename}
set file_path ${imagedir}/${casename}.gltf
writefile S_First $file_path -conf "provider.GLTF.OCC.author: GLTF_AUTHOR "
readfile S_Second $file_path
checktrinfo S_Second -ref [trinfo S_First]
file delete $file_path

62
tests/de_wrapper/gltf/A5 Normal file
View File

@ -0,0 +1,62 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
catch { Close D2 }
catch { Close D3 }
param xstep.cascade.unit MM
if [catch {readgltf res0 $filename} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
param xstep.cascade.unit M
if [catch {readgltf res1 $filename} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
if [catch {ReadFile D2 $filename} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
XGetOneShape S2 D2
if { [XGetLengthUnit D2] != "mm" } {
puts "Error: incrorrect document's length unit"
}
XNewDoc D3
if [catch {ReadFile D3 $filename -conf "global.general.length.unit : 1000 "} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
XGetOneShape S3 D3
if { [XGetLengthUnit D3] != "m" } {
puts "Error: incrorrect document's length unit"
}
if [catch {readfile S4 $filename } catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
if [catch {readfile S5 $filename -conf "global.general.length.unit : 1000 "} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
array set areas {0 3.18785e+06 1 3.18785 2 3.18785e+06 3 3.18785 4 3.18785e+06 5 3.18785}
array set results {0 res0 1 res1 2 S2 3 S3 4 S4 5 S5}
for { set anind 0} { $anind < 6 } { incr anind } {
checkprops $results($anind) -s $areas($anind) -eps 1e-2
}
Close D2
Close D3

110
tests/de_wrapper/gltf/A6 Normal file
View File

@ -0,0 +1,110 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
catch { Close D0 }
catch { Close D1 }
catch { Close D6 }
catch { Close D7 }
pload MODELING
set write_path ${imagedir}/${casename}.gltf
param xstep.cascade.unit MM
if [catch {ReadGltf D0 $filename} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
XGetOneShape S0 D0
param xstep.cascade.unit M
if [catch {ReadGltf D1 $filename} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
XGetOneShape S1 D1
if [catch {WriteFile D0 $write_path -conf "provider.GLTF.OCC.file.length.unit : 0.001 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
}
if [catch {readfile S2 $write_path} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
if [catch {writefile S0 $write_path} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
}
if [catch {readfile S3 $write_path} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
if [catch {WriteFile D1 $write_path -conf "provider.GLTF.OCC.file.length.unit : 1 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
}
if [catch {readfile S4 $write_path -conf "global.general.length.unit : 1000 "} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
if [catch {writefile S1 $write_path} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
}
if [catch {readfile S5 $write_path} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
if [catch {WriteFile D0 $write_path -conf "provider.GLTF.OCC.file.length.unit : 0.001 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
}
if [catch {ReadFile D6 $write_path -conf "global.general.length.unit : 1 "} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
XGetOneShape S6 D6
if [catch {writefile S1 $write_path -conf "provider.GLTF.OCC.file.length.unit : 1 "} catch_result] {
puts "Error : Problem with writing file"
} else {
puts "OK : Writing is correct"
}
if [catch {ReadFile D7 $write_path -conf "global.general.length.unit : 1000 "} catch_result] {
puts "Error : Problem with reading file"
} else {
puts "OK : Reading is correct"
}
XGetOneShape S7 D7
array set areas {0 3.18785e+06 1 3.18785 2 3.18785e+06 3 3.18785e+06 4 3.18785 5 3.18785 6 3.18785e+06 7 3.18785e-06}
array set results {0 S0 1 S1 2 S2 3 S3 4 S4 5 S5 6 S6 7 S7}
for { set anind 0} { $anind < 8 } { incr anind } {
checkprops $results($anind) -s $areas($anind) -eps 1e-2
}
file delete $write_path
Close D0
Close D1
Close D6
Close D7

View File

@ -0,0 +1,3 @@
# File: begin
set filename [locate_data_file "bug31302_NormalTangentTest.gltf"]

View File

@ -0,0 +1,13 @@
# This test group is aimed to demonstrate how test cases are created,
# and test the test system itself
001 configuration
002 brep
003 gltf
004 iges
005 obj
006 ply
007 step
008 stl
009 vrml
010 xcaf

18
tests/de_wrapper/iges/A1 Normal file
View File

@ -0,0 +1,18 @@
puts "============"
puts "0032821: DEWrapper - Implementation of a common toolkit for importing and exporting CAD files"
puts "============"
puts ""
catch { Close D_First }
catch { Close D_Second }
ReadIges D_First ${filename}
XGetOneShape S_First D_First
ReadFile D_Second ${filename}
XGetOneShape S_Second D_Second
checknbshapes S_Second -ref [nbshapes S_First]
Close D_First
Close D_Second

Some files were not shown because too many files have changed in this diff Show More