return GetString(theParam, aVal, theScope) ? aVal : theDefValue;
}
+//=======================================================================
+//function : StringSeqVal
+//purpose :
+//=======================================================================
+TColStd_ListOfAsciiString DE_ConfigurationContext::StringSeqVal(const TCollection_AsciiString& theParam,
+ const TColStd_ListOfAsciiString& theDefValue,
+ const TCollection_AsciiString& theScope) const
+{
+ TColStd_ListOfAsciiString aVal;
+ return GetStringSeq(theParam, aVal, theScope) ? aVal : theDefValue;
+}
+
//=======================================================================
//function : GetReal
//purpose :
const TCollection_AsciiString& 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 TColStd_ListOfAsciiString StringSeqVal(const TCollection_AsciiString& theParam,
+ const TColStd_ListOfAsciiString& theDefValue,
+ const TCollection_AsciiString& theScope = "") const;
+
//! Gets internal resource map
//! @return map with resource value
Standard_EXPORT const DE_ResourceMap& GetInternalMap() const { return myResource; }
return false;
}
+//=======================================================================
+// function : IsExportSupported
+// purpose :
+//=======================================================================
+bool DE_ConfigurationNode::IsStreamSupported() const
+{
+ return false;
+}
+
//=======================================================================
// function : CheckForSupport
// purpose :
//! @return Standard_True if export is support
Standard_EXPORT virtual bool IsExportSupported() const;
+ //! Checks the stream for import/export supporting
+ //! @return Standard_True if stream is support
+ Standard_EXPORT virtual bool IsStreamSupported() const;
+
//! Gets CAD format name of associated provider
//! @return provider CAD format
Standard_EXPORT virtual TCollection_AsciiString GetFormat() const = 0;
//! Gets the provider loading status
//! @return Standard_True if the load is correct
- Standard_Boolean IsEnabled() const
- {
- return myIsEnabled;
- }
+ 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;
- }
+ void SetEnabled(const Standard_Boolean theIsLoaded) { myIsEnabled = theIsLoaded; }
public:
(void)theWS;
(void)theProgress;
Message::SendFail() << "Error: provider " << GetFormat() <<
- " " << GetVendor() <<" doesn't support read operation";
+ " " << GetVendor() << " doesn't support read operation";
return Standard_False;
}
//=======================================================================
-// function : Write
+// function : Read
// purpose :
//=======================================================================
-Standard_Boolean DE_Provider::Write(const TCollection_AsciiString& thePath,
- const Handle(TDocStd_Document)& theDocument,
- Handle(XSControl_WorkSession)& theWS,
- const Message_ProgressRange& theProgress)
+bool DE_Provider::Read(std::istream& theIStream,
+ const Handle(TDocStd_Document)& theDocument,
+ const TCollection_AsciiString theName,
+ Handle(XSControl_WorkSession)& theWS,
+ const Message_ProgressRange& theProgress)
{
- (void)thePath;
+ (void)theIStream;
(void)theDocument;
(void)theWS;
(void)theProgress;
Message::SendFail() << "Error: provider " << GetFormat() <<
- " " << GetVendor() << " doesn't support write operation";
+ " " << GetVendor() << " doesn't support stream read operation";
return Standard_False;
}
//=======================================================================
-// function : Read
+// function : Write
// purpose :
//=======================================================================
-Standard_Boolean DE_Provider::Read(const TCollection_AsciiString& thePath,
- const Handle(TDocStd_Document)& theDocument,
- const Message_ProgressRange& theProgress)
+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 read operation";
+ " " << GetVendor() << " doesn't support write 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)
+bool DE_Provider::Write(std::ostream& theOStream,
+ const Handle(TDocStd_Document)& theDocument,
+ Handle(XSControl_WorkSession)& theWS,
+ const Message_ProgressRange& theProgress)
{
- (void)thePath;
+ (void)theOStream;
(void)theDocument;
+ (void)theWS;
(void)theProgress;
Message::SendFail() << "Error: provider " << GetFormat() <<
- " " << GetVendor() << " doesn't support write operation";
+ " " << GetVendor() << " doesn't support stream write operation";
return Standard_False;
}
}
//=======================================================================
-// function : Write
+// function : Read
// purpose :
//=======================================================================
-Standard_Boolean DE_Provider::Write(const TCollection_AsciiString& thePath,
- const TopoDS_Shape& theShape,
- Handle(XSControl_WorkSession)& theWS,
- const Message_ProgressRange& theProgress)
+bool DE_Provider::Read(std::istream& theIStream,
+ TopoDS_Shape& theShape,
+ const TCollection_AsciiString theName,
+ Handle(XSControl_WorkSession)& theWS,
+ const Message_ProgressRange& theProgress)
{
- (void)thePath;
+ (void)theIStream;
(void)theShape;
(void)theWS;
(void)theProgress;
Message::SendFail() << "Error: provider " << GetFormat() <<
- " " << GetVendor() << " doesn't support write operation";
+ " " << GetVendor() << " doesn't support stream read operation";
return Standard_False;
}
//=======================================================================
-// function : Read
+// function : Write
// purpose :
//=======================================================================
-Standard_Boolean DE_Provider::Read(const TCollection_AsciiString& thePath,
- TopoDS_Shape& theShape,
- const Message_ProgressRange& theProgress)
+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 read operation";
+ " " << GetVendor() << " doesn't support write operation";
return Standard_False;
}
// function : Write
// purpose :
//=======================================================================
-Standard_Boolean DE_Provider::Write(const TCollection_AsciiString& thePath,
- const TopoDS_Shape& theShape,
- const Message_ProgressRange& theProgress)
+bool DE_Provider::Write(std::ostream& theOStream,
+ const TopoDS_Shape& theShape,
+ Handle(XSControl_WorkSession)& theWS,
+ const Message_ProgressRange& theProgress)
{
- (void)thePath;
+ (void)theOStream;
(void)theShape;
+ (void)theWS;
(void)theProgress;
Message::SendFail() << "Error: provider " << GetFormat() <<
- " " << GetVendor() << " doesn't support write operation";
+ " " << GetVendor() << " doesn't support stream write operation";
return Standard_False;
}
//! @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());
+ Standard_EXPORT virtual bool Read(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] theIStream stream to import CAD data
+ //! @param[out] theDocument document to save result
+ //! @paramp[in] theName name of CAD file, can be empty
+ //! @param[in] theWS current work session
+ //! @param theProgress[in] progress indicator
+ //! @return true if Read operation has ended correctly
+ Standard_EXPORT virtual bool Read(std::istream& theIStream,
+ const Handle(TDocStd_Document)& theDocument,
+ const TCollection_AsciiString theName,
+ 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[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());
+ Standard_EXPORT virtual bool Write(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[in] theOStream stream to export CAD data
//! @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,
- const Message_ProgressRange& theProgress = Message_ProgressRange());
+ //! @return true if Write operation has ended correctly
+ Standard_EXPORT virtual bool Write(std::ostream& theOStream,
+ 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[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());
+ Standard_EXPORT virtual bool Read(const TCollection_AsciiString& thePath,
+ TopoDS_Shape& theShape,
+ Handle(XSControl_WorkSession)& theWS,
+ const Message_ProgressRange& theProgress = Message_ProgressRange());
+
+ //! Reads a CAD file, according internal configuration
+ //! @param[in] theIStream stream to the CAD file
+ //! @param[out] theShape shape to save result
+ //! @paramp[in] theName name of CAD file, can be empty
+ //! @param[in] theWS current work session
+ //! @param theProgress[in] progress indicator
+ //! @return true if Read operation has ended correctly
+ Standard_EXPORT virtual bool Read(std::istream& theIStream,
+ TopoDS_Shape& theShape,
+ const TCollection_AsciiString theName,
+ 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[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());
+ Standard_EXPORT virtual bool Write(const TCollection_AsciiString& thePath,
+ const 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[in] theOStream stream to export CAD data
//! @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,
- const Message_ProgressRange& theProgress = Message_ProgressRange());
+ //! @return true if Write operation has ended correctly
+ Standard_EXPORT virtual bool Write(std::ostream& theOStream,
+ const TopoDS_Shape& theShape,
+ Handle(XSControl_WorkSession)& theWS,
+ const Message_ProgressRange& theProgress = Message_ProgressRange());
public:
//! Gets internal configuration node
//! @return configuration node object
- Handle(DE_ConfigurationNode) GetNode() const
- {
- return myNode;
- }
+ 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;
- }
+ void SetNode(const Handle(DE_ConfigurationNode)& theNode) { myNode = theNode; }
private:
{
static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE()
{
- static const TCollection_AsciiString aScope ("global");
+ static const TCollection_AsciiString aScope("global");
return aScope;
}
{
return Standard_False;
}
- if (theWS.IsNull())
- {
- return Read(thePath, theDocument, theProgress);
- }
Handle(DE_Provider) aProvider;
if (!FindProvider(thePath, Standard_True, aProvider))
{
{
return Standard_False;
}
- if (theWS.IsNull())
- {
- return Write(thePath, theDocument, theProgress);
- }
Handle(DE_Provider) aProvider;
if (!FindProvider(thePath, Standard_False, aProvider))
{
return aProvider->Write(thePath, theDocument, theWS, theProgress);
}
-//=======================================================================
-// function : Read
-// purpose :
-//=======================================================================
-Standard_Boolean DE_Wrapper::Read(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_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 :
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))
{
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 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 :
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,
- 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 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
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
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())
+ if (theDocument.IsNull())
{
- Message::SendFail() << "Error in the DEBRepCascade_Provider during reading the file " <<
- thePath << "\t: theDocument shouldn't be null";
+ Message::SendFail() << "Error: DEBRepCascade_Provider : "
+ << "Null document";
return false;
}
TopoDS_Shape aShape;
- if (!Read(thePath, aShape, theProgress))
+ if (!Read(thePath, aShape, theWS, theProgress))
{
return false;
}
- Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
+ Handle(XCAFDoc_ShapeTool) aShTool =
+ XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
aShTool->AddShape(aShape);
return true;
}
//=======================================================================
bool DEBRepCascade_Provider::Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
+ Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
+ (void)theWS;
TopoDS_Shape aShape;
TDF_LabelSequence aLabels;
- Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
+ 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";
+ Message::SendFail() << "Error: DEBRepCascade_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
}
aShape = aComp;
}
- return Write(thePath, aShape, theProgress);
+ return Write(thePath, aShape, theWS, theProgress);
}
//=======================================================================
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);
+ 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";
+ Message::SendFail() << "Error: DEBRepCascade_Provider : ["
+ << thePath << "] : Cannot open 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";
+ Message::SendFail() << "Error: DEBRepCascade_Provider : ["
+ << thePath << "] : Cannot open the file";
return false;
}
isBinaryFormat = !(::strncmp(aStringBuf, "DBRep_DrawableShape", 19) == 0);
}
-
+ Standard_Boolean aReadStatus = Standard_True;
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;
- }
+ aReadStatus = BinTools::Read(theShape, thePath.ToCString(), theProgress);
}
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;
- }
+ aReadStatus =
+ BRepTools::Read(theShape, thePath.ToCString(), BRep_Builder(), theProgress);
}
-
- return true;
+ if (!aReadStatus)
+ {
+ Message::SendFail() << "Error: DEBRepCascade_Provider : ["
+ << thePath << "] : Cannot read data from the file";
+ }
+ return aReadStatus;
}
//=======================================================================
//=======================================================================
bool DEBRepCascade_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(DEBRepCascade_ConfigurationNode)))
+ (void)theWS;
+ 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";
+ Message::SendFail() << "Error: DEBRepCascade_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(DEBRepCascade_ConfigurationNode) aNode = Handle(DEBRepCascade_ConfigurationNode)::DownCast(GetNode());
+ 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))
+ 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";
+ Message::SendFail() << "Error: DEBRepCascade_Provider : ["
+ << thePath << "] : Unknown format version";
return false;
}
- if (aNode->InternalParameters.WriteNormals &&
+ 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";
+ Message::SendFail() << "Error: DEBRepCascade_Provider : ["
+ << thePath << "] : 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))
+ 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";
+ Message::SendFail() << "Error: DEBRepCascade_Provider : ["
+ << thePath << "] : 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))
+ 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";
+ Message::SendFail() << "Error: DEBRepCascade_Provider : ["
+ << thePath << "] : 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";
+ Message::SendFail() << "Error: DEBRepCascade_Provider : ["
+ << thePath << "] : 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))
+ 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";
+ Message::SendFail() << "Error: DEBRepCascade_Provider : ["
+ << thePath << "] : Cannot write the file";
return false;
}
}
-
return true;
}
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
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
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";
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : "
+ << "Null document";
return false;
}
- if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEXCAFCascade_ConfigurationNode)))
+ 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";
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(DEXCAFCascade_ConfigurationNode) aNode = Handle(DEXCAFCascade_ConfigurationNode)::DownCast(GetNode());
+ Handle(DEXCAFCascade_ConfigurationNode) aNode =
+ Handle(DEXCAFCascade_ConfigurationNode)::DownCast(GetNode());
Handle(TDocStd_Document) aDocument;
Handle(TDocStd_Application) anApp = new TDocStd_Application();
BinDrivers::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())
+ 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())
+ for (TColStd_ListOfAsciiString::Iterator anIt(aNode->InternalParameters.ReadValues);
+ anIt.More(); anIt.Next())
{
if (anIt.Value().StartsWith("0"))
{
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";
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
+ thePath << "] : Cannot open XDE document";
return false;
}
theDocument->SetData(aDocument->GetData());
//=======================================================================
bool DEXCAFCascade_Provider::Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
+ Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
+ (void)theWS;
Handle(TDocStd_Application) anApp = new TDocStd_Application();
BinXCAFDrivers::DefineFormat(anApp);
PCDM_StoreStatus aStatus = PCDM_SS_Doc_IsNull;
}
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";
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
+ thePath << "] : Storage error : 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";
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
+ thePath << "] : 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";
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
+ thePath << "] : 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";
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
+ thePath << "] : 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";
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
+ thePath << "] : 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";
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
+ thePath << "] : 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";
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
+ thePath << "] : 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";
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
+ thePath << "] : 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();
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
+ thePath << "] : Storage error : unrecognized document storage format : "
+ << theDocument->StorageFormat();
break;
}
return false;
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)))
+ 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";
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : "
+ << "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);
+ Read(thePath, aDocument, theWS, 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";
+ Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
+ thePath << "] : Storage error : Document contain no shapes";
return false;
}
//=======================================================================
bool DEXCAFCascade_Provider::Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape,
+ Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
+ (void)theWS;
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);
+ return Write(thePath, aDoc, theWS, theProgress);
}
//=======================================================================
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
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
#include <IGESCAFControl_Provider.hxx>
#include <BinXCAFDrivers.hxx>
+#include <IGESControl_Controller.hxx>
#include <IGESCAFControl_ConfigurationNode.hxx>
#include <IGESCAFControl_Reader.hxx>
#include <IGESCAFControl_Writer.hxx>
#include <Interface_Static.hxx>
#include <Message.hxx>
#include <XCAFDoc_DocumentTool.hxx>
+#include <XSControl_WorkSession.hxx>
#include <UnitsMethods.hxx>
IMPLEMENT_STANDARD_RTTIEXT(IGESCAFControl_Provider, DE_Provider)
: DE_Provider(theNode)
{}
+//=======================================================================
+// function : STEPCAFControl_Provider
+// purpose :
+//=======================================================================
+void IGESCAFControl_Provider::personizeWS(Handle(XSControl_WorkSession)& theWS)
+{
+ if (theWS.IsNull())
+ {
+ Message::SendWarning() << "Warning: IGESCAFControl_Provider :"
+ << " Null work session, use internal temporary session";
+ theWS = new XSControl_WorkSession();
+ }
+ Handle(IGESControl_Controller) aCntrl =
+ Handle(IGESControl_Controller)::DownCast(theWS->NormAdaptor());
+ if (aCntrl.IsNull())
+ {
+ theWS->SelectNorm("IGES");
+ }
+}
+
//=======================================================================
// function : initStatic
// purpose :
//=======================================================================
void IGESCAFControl_Provider::initStatic(const Handle(DE_ConfigurationNode)& theNode)
{
- Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(theNode);
+ Handle(IGESCAFControl_ConfigurationNode) aNode =
+ Handle(IGESCAFControl_ConfigurationNode)::DownCast(theNode);
IGESData::Init();
-
+ if (!myToUpdateStaticParameters)
+ {
+ return;
+ }
// Get previous values
- myOldValues.ReadBSplineContinuity = (IGESCAFControl_ConfigurationNode::ReadMode_BSplineContinuity)Interface_Static::IVal("read.iges.bspline.continuity");
- myOldValues.ReadPrecisionMode = (IGESCAFControl_ConfigurationNode::ReadMode_Precision)Interface_Static::IVal("read.precision.mode");
- myOldValues.ReadPrecisionVal = Interface_Static::RVal("read.precision.val");
- myOldValues.ReadMaxPrecisionMode = (IGESCAFControl_ConfigurationNode::ReadMode_MaxPrecision)Interface_Static::IVal("read.maxprecision.mode");
- myOldValues.ReadMaxPrecisionVal = Interface_Static::RVal("read.maxprecision.val");
- myOldValues.ReadSameParamMode = Interface_Static::IVal("read.stdsameparameter.mode") == 1;
- myOldValues.ReadSurfaceCurveMode = (IGESCAFControl_ConfigurationNode::ReadMode_SurfaceCurve)Interface_Static::IVal("read.surfacecurve.mode");
- myOldValues.EncodeRegAngle = Interface_Static::RVal("read.encoderegularity.angle") * 180.0 / M_PI;
-
- myOldValues.ReadApproxd1 = Interface_Static::IVal("read.iges.bspline.approxd1.mode") == 1;
- myOldValues.ReadResourceName = Interface_Static::CVal("read.iges.resource.name");
- myOldValues.ReadSequence = Interface_Static::CVal("read.iges.sequence");
- myOldValues.ReadFaultyEntities = Interface_Static::IVal("read.iges.faulty.entities") == 1;
- myOldValues.ReadOnlyVisible = Interface_Static::IVal("read.iges.onlyvisible") == 1;
-
- myOldValues.WriteBRepMode = (IGESCAFControl_ConfigurationNode::WriteMode_BRep)Interface_Static::IVal("write.iges.brep.mode");
- myOldValues.WriteConvertSurfaceMode = (IGESCAFControl_ConfigurationNode::WriteMode_ConvertSurface)Interface_Static::IVal("write.convertsurface.mode");
- myOldValues.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");
-
+ myOldValues.ReadBSplineContinuity =
+ (IGESCAFControl_ConfigurationNode::ReadMode_BSplineContinuity)
+ Interface_Static::IVal("read.iges.bspline.continuity");
+ myOldValues.ReadPrecisionMode =
+ (IGESCAFControl_ConfigurationNode::ReadMode_Precision)
+ Interface_Static::IVal("read.precision.mode");
+ myOldValues.ReadPrecisionVal =
+ Interface_Static::RVal("read.precision.val");
+ myOldValues.ReadMaxPrecisionMode =
+ (IGESCAFControl_ConfigurationNode::ReadMode_MaxPrecision)
+ Interface_Static::IVal("read.maxprecision.mode");
+ myOldValues.ReadMaxPrecisionVal =
+ Interface_Static::RVal("read.maxprecision.val");
+ myOldValues.ReadSameParamMode =
+ Interface_Static::IVal("read.stdsameparameter.mode") == 1;
+ myOldValues.ReadSurfaceCurveMode =
+ (IGESCAFControl_ConfigurationNode::ReadMode_SurfaceCurve)
+ Interface_Static::IVal("read.surfacecurve.mode");
+ myOldValues.EncodeRegAngle =
+ Interface_Static::RVal("read.encoderegularity.angle") * 180.0 / M_PI;
+
+ myOldValues.ReadApproxd1 =
+ Interface_Static::IVal("read.iges.bspline.approxd1.mode") == 1;
+ myOldValues.ReadResourceName =
+ Interface_Static::CVal("read.iges.resource.name");
+ myOldValues.ReadSequence =
+ Interface_Static::CVal("read.iges.sequence");
+ myOldValues.ReadFaultyEntities =
+ Interface_Static::IVal("read.iges.faulty.entities") == 1;
+ myOldValues.ReadOnlyVisible =
+ Interface_Static::IVal("read.iges.onlyvisible") == 1;
+
+ myOldValues.WriteBRepMode =
+ (IGESCAFControl_ConfigurationNode::WriteMode_BRep)
+ Interface_Static::IVal("write.iges.brep.mode");
+ myOldValues.WriteConvertSurfaceMode =
+ (IGESCAFControl_ConfigurationNode::WriteMode_ConvertSurface)
+ Interface_Static::IVal("write.convertsurface.mode");
+ myOldValues.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;
+
+ myOldGlobalValues.LengthUnit = 0.001 *
+ UnitsMethods::GetLengthFactorValue(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));
+ TCollection_AsciiString aStrUnit(
+ UnitsMethods::DumpLengthUnit(aNode->GlobalParameters.LengthUnit));
aStrUnit.UpperCase();
Interface_Static::SetCVal("xstep.cascade.unit", aStrUnit.ToCString());
+ UnitsMethods::SetCasCadeLengthUnit(aNode->GlobalParameters.LengthUnit);
setStatic(aNode->InternalParameters);
}
//=======================================================================
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);
+ 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);
}
//=======================================================================
//=======================================================================
void IGESCAFControl_Provider::resetStatic()
{
- Interface_Static::SetIVal("xstep.cascade.unit", myOldLengthUnit);
- UnitsMethods::SetCasCadeLengthUnit(myOldLengthUnit);
+ if (!myToUpdateStaticParameters)
+ {
+ return;
+ }
+ // Set new values
+ TCollection_AsciiString aStrUnit(
+ UnitsMethods::DumpLengthUnit(myOldGlobalValues.LengthUnit,
+ UnitsMethods_LengthUnit_Meter));
+ aStrUnit.UpperCase();
+ Interface_Static::SetCVal("xstep.cascade.unit", aStrUnit.ToCString());
setStatic(myOldValues);
}
{
if (theDocument.IsNull())
{
- Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " <<
- thePath << "\t: theDocument shouldn't be null";
+ Message::SendFail() << "Error: IGESCAFControl_Provider : "
+ << "Null document";
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";
+ Message::SendFail() << "Error: IGESCAFControl_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode());
+ 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())
+ personizeWS(theWS);
+ XCAFDoc_DocumentTool::SetLengthUnit(theDocument,
+ aNode->GlobalParameters.LengthUnit,
+ UnitsMethods_LengthUnit_Millimeter);
+ const Standard_Boolean toUseLoaded = thePath == ".";
+ TCollection_AsciiString aFile;
+ if (toUseLoaded)
{
- aReader.SetWS(theWS);
+ aFile = theWS->LoadedFile();
+ Message::SendInfo() << "Model taken from the IGES session : "
+ << aFile;
}
-
+ else
+ {
+ aFile = thePath;
+ Message::SendInfo() << "File IGES to read : "
+ << aFile;
+ }
+ IGESCAFControl_Reader aReader(theWS, !toUseLoaded);
aReader.SetReadVisible(aNode->InternalParameters.ReadOnlyVisible);
-
aReader.SetColorMode(aNode->InternalParameters.ReadColor);
aReader.SetNameMode(aNode->InternalParameters.ReadName);
aReader.SetLayerMode(aNode->InternalParameters.ReadLayer);
-
+ Handle(IGESData_IGESModel) aModel = aReader.IGESModel();
+ if (aModel.IsNull())
+ {
+ aModel = Handle(IGESData_IGESModel)::DownCast(theWS->NewModel());
+ }
+ aModel->ClearHeader();
+ aModel->ChangeGlobalSection().SetCascadeUnit(aNode->GlobalParameters.LengthUnit);
IFSelect_ReturnStatus aReadStat = IFSelect_RetVoid;
- aReadStat = aReader.ReadFile(thePath.ToCString());
+ if (!toUseLoaded)
+ {
+ aReadStat = aReader.ReadFile(thePath.ToCString());
+ }
+ else if (theWS->NbStartingEntities() > 0)
+ {
+ aReadStat = IFSelect_RetDone;
+ }
if (aReadStat != IFSelect_RetDone)
{
- Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " <<
- thePath << "\t: abandon, no model loaded";
+ Message::SendFail() << "Error: IGESCAFControl_Provider : ["
+ << aFile << "] : 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";
+ Message::SendFail() << "Error: IGESCAFControl_Provider : [" <<
+ aFile << "] : Cannot read any relevant data from the IGES file";
resetStatic();
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";
+ Message::SendFail() << "Error: IGESCAFControl_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode());
+ 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())
+ personizeWS(theWS);
+ TCollection_AsciiString aUnit(
+ UnitsMethods::DumpLengthUnit(aNode->InternalParameters.WriteUnit));
+ aUnit.UpperCase();
+
+ IGESCAFControl_Writer aWriter(theWS, Standard_True);
+ if (aNode->InternalParameters.WriteUnit > UnitsMethods_LengthUnit_Undefined &&
+ aNode->InternalParameters.WriteUnit <= UnitsMethods_LengthUnit_Microinch)
{
- aWriter = IGESCAFControl_Writer(theWS);
+ Handle(IGESData_IGESModel) aModel = aWriter.Model();
+ IGESData_GlobalSection aGSesction = aModel->GlobalSection();
+ Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(
+ IGESData_BasicEditor::UnitFlagName(aNode->InternalParameters.WriteUnit));
+ if (aGSesction.UnitFlag() == 3)
+ {
+ aGSesction.SetUnitName(aName);
+ }
+ else if (aGSesction.UnitFlag() > 0)
+ {
+ aGSesction.SetUnitFlag(aNode->InternalParameters.WriteUnit);
+ }
+ aModel->SetGlobalSection(aGSesction);
}
aWriter.SetColorMode(aNode->InternalParameters.WriteColor);
aWriter.SetNameMode(aNode->InternalParameters.WriteName);
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";
+ Message::SendFail() << "Error: IGESCAFControl_Provider : "
+ << "The document cannot be translated or gives no result";
resetStatic();
return false;
}
+ if (thePath == ".")
+ {
+ resetStatic();
+ Message::SendInfo() << "Document has been translated into the session";
+ return true;
+ }
if (!aWriter.Write(thePath.ToCString()))
{
- Message::SendFail() << "Error in the IGESCAFControl_Provider during reading the file " <<
- thePath << "\t: Write failed";
+ Message::SendFail() << "Error: IGESCAFControl_Provider : [" <<
+ thePath << "] : Write failed";
resetStatic();
return false;
}
+ Message::SendInfo() << "IGES file [" << thePath << "] Successfully written";
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 :
(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";
+ Message::SendFail() << "Error: IGESCAFControl_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode());
+ Handle(IGESCAFControl_ConfigurationNode) aNode =
+ Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode());
initStatic(aNode);
+ personizeWS(theWS);
IGESControl_Reader aReader;
- if (!theWS.IsNull())
+ aReader.SetWS(theWS);
+ Handle(IGESData_IGESModel) aModel = aReader.IGESModel();
+ if (aModel.IsNull())
{
- aReader.SetWS(theWS);
+ aModel = Handle(IGESData_IGESModel)::DownCast(theWS->NewModel());
}
+ aModel->ClearHeader();
+ aModel->ChangeGlobalSection().SetCascadeUnit(aNode->GlobalParameters.LengthUnit);
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";
+ Message::SendFail() << "Error: IGESCAFControl_Provider : [" <<
+ thePath << "] : 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";
+ Message::SendFail() << "Error: IGESCAFControl_Provider : [" <<
+ thePath << "] : Cannot read any relevant data from the IGES file";
resetStatic();
return false;
}
(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";
+ Message::SendFail() << "Error: IGESCAFControl_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode());
+ Handle(IGESCAFControl_ConfigurationNode) aNode =
+ Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode());
initStatic(aNode);
- TCollection_AsciiString aUnit(UnitsMethods::DumpLengthUnit(aNode->InternalParameters.WriteUnit));
+ 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";
+ Message::SendFail() << "Error: IGESCAFControl_Provider : "
+ << "Can't translate shape to IGES model";
resetStatic();
return false;
}
if (!(aWriter.Write(thePath.ToCString())))
{
- Message::SendFail() << "IGESCAFControl_Provider: Error on writing file " << thePath;
+ Message::SendFail() << "Error: IGESCAFControl_Provider : "
+ << "Can't write IGES file" << thePath;
resetStatic();
return false;
}
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 :
#define _IGESCAFControl_Provider_HeaderFile
#include <DE_Provider.hxx>
+#include <DE_ConfigurationNode.hxx>
#include <IGESCAFControl_ConfigurationNode.hxx>
//! The class to transfer IGES files.
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
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's vendor name
Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE;
+public:
+
+ //! Sets parameter to update static parameter, that true by default
+ void SetToUpdateStaticParameters(const bool theToUpdate) { myToUpdateStaticParameters = theToUpdate; }
+
+ //! Gets parameter to update static parameter, that true by default
+ bool ToUpdateStaticParameters() const { return myToUpdateStaticParameters; }
+
private:
+ //! Personizes work session with current format.
+ //! Creates new temporary session if current session is null
+ //! @param[in] theWS current work session
+ void personizeWS(Handle(XSControl_WorkSession)& theWS);
+
//! Initialize static variables
void initStatic(const Handle(DE_ConfigurationNode)& theNode);
//! Reset used interface static variables
void resetStatic();
- IGESCAFControl_ConfigurationNode::IGESCAFControl_InternalSection myOldValues;
- int myOldLengthUnit = 1;
+private:
+
+ bool myToUpdateStaticParameters = true; //!< Flag to updating static parameters
+ IGESCAFControl_ConfigurationNode::IGESCAFControl_InternalSection myOldValues; //!< Container to save previous static parameters
+ IGESCAFControl_ConfigurationNode::DE_SectionGlobal myOldGlobalValues; //!< Container to save previous static parameters
};
{
TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor();
- InternalParameters.FileLengthUnit =
+ InternalParameters.FileLengthUnit =
theResource->RealVal("file.length.unit", InternalParameters.FileLengthUnit, aScope);
InternalParameters.SystemCS = (RWMesh_CoordinateSystem)
(theResource->IntegerVal("system.cs", (int)InternalParameters.SystemCS, aScope) % 2);
InternalParameters.FileCS = (RWMesh_CoordinateSystem)
(theResource->IntegerVal("file.cs", (int)InternalParameters.SystemCS, aScope) % 2);
- InternalParameters.ReadSinglePrecision =
+ InternalParameters.ReadSinglePrecision =
theResource->BooleanVal("read.single.precision", InternalParameters.ReadSinglePrecision, aScope);
- InternalParameters.ReadCreateShapes =
+ InternalParameters.ReadCreateShapes =
theResource->BooleanVal("read.create.shapes", InternalParameters.ReadCreateShapes, aScope);
- InternalParameters.ReadRootPrefix =
+ InternalParameters.ReadRootPrefix =
theResource->StringVal("read.root.prefix", InternalParameters.ReadRootPrefix, aScope);
- InternalParameters.ReadFillDoc =
+ InternalParameters.ReadFillDoc =
theResource->BooleanVal("read.fill.doc", InternalParameters.ReadFillDoc, aScope);
- InternalParameters.ReadFillIncomplete =
+ InternalParameters.ReadFillIncomplete =
theResource->BooleanVal("read.fill.incomplete", InternalParameters.ReadFillIncomplete, aScope);
- InternalParameters.ReadMemoryLimitMiB =
+ InternalParameters.ReadMemoryLimitMiB =
theResource->IntegerVal("read.memory.limit.mib", InternalParameters.ReadMemoryLimitMiB, aScope);
- InternalParameters.ReadParallel =
+ InternalParameters.ReadParallel =
theResource->BooleanVal("read.parallel", InternalParameters.ReadParallel, aScope);
- InternalParameters.ReadSkipEmptyNodes =
+ InternalParameters.ReadSkipEmptyNodes =
theResource->BooleanVal("read.skip.empty.nodes", InternalParameters.ReadSkipEmptyNodes, aScope);
- InternalParameters.ReadLoadAllScenes =
+ InternalParameters.ReadLoadAllScenes =
theResource->BooleanVal("read.load.all.scenes", InternalParameters.ReadLoadAllScenes, aScope);
- InternalParameters.ReadUseMeshNameAsFallback =
+ InternalParameters.ReadUseMeshNameAsFallback =
theResource->BooleanVal("read.use.mesh.name.as.fallback", InternalParameters.ReadUseMeshNameAsFallback, aScope);
- InternalParameters.ReadSkipLateDataLoading =
+ InternalParameters.ReadSkipLateDataLoading =
theResource->BooleanVal("read.skip.late.data.loading", InternalParameters.ReadSkipLateDataLoading, aScope);
- InternalParameters.ReadKeepLateData =
+ InternalParameters.ReadKeepLateData =
theResource->BooleanVal("read.keep.late.data", InternalParameters.ReadKeepLateData, aScope);
- InternalParameters.ReadPrintDebugMessages =
+ InternalParameters.ReadPrintDebugMessages =
theResource->BooleanVal("read.print.debug.message", InternalParameters.ReadPrintDebugMessages, aScope);
- InternalParameters.WriteComment =
+ InternalParameters.WriteComment =
theResource->StringVal("write.comment", InternalParameters.WriteComment, aScope);
- InternalParameters.WriteAuthor =
+ InternalParameters.WriteAuthor =
theResource->StringVal("write.author", InternalParameters.WriteAuthor, aScope);
InternalParameters.WriteTrsfFormat = (RWGltf_WriterTrsfFormat)
(theResource->IntegerVal("write.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 =
+
+ // Draco parameters
+ InternalParameters.WriteDracoParameters.DracoCompression =
+ theResource->BooleanVal("write.draco.compression",
+ InternalParameters.WriteDracoParameters.DracoCompression, aScope);
+ InternalParameters.WriteDracoParameters.CompressionLevel =
+ theResource->IntegerVal("write.draco.level",
+ InternalParameters.WriteDracoParameters.CompressionLevel, aScope);
+ InternalParameters.WriteDracoParameters.QuantizePositionBits =
+ theResource->IntegerVal("write.draco.position.bits",
+ InternalParameters.WriteDracoParameters.QuantizePositionBits, aScope);
+ InternalParameters.WriteDracoParameters.QuantizeNormalBits =
+ theResource->IntegerVal("write.draco.normal.bits",
+ InternalParameters.WriteDracoParameters.QuantizeNormalBits, aScope);
+ InternalParameters.WriteDracoParameters.QuantizeTexcoordBits =
+ theResource->IntegerVal("write.draco.texture.bits",
+ InternalParameters.WriteDracoParameters.QuantizeTexcoordBits, aScope);
+ InternalParameters.WriteDracoParameters.QuantizeColorBits =
+ theResource->IntegerVal("write.draco.color.bits",
+ InternalParameters.WriteDracoParameters.QuantizeColorBits, aScope);
+ InternalParameters.WriteDracoParameters.QuantizeGenericBits =
+ theResource->IntegerVal("write.draco.generic.bits",
+ InternalParameters.WriteDracoParameters.QuantizeGenericBits, aScope);
+ InternalParameters.WriteDracoParameters.UnifiedQuantization =
+ theResource->BooleanVal("write.draco.unified.quantization",
+ InternalParameters.WriteDracoParameters.UnifiedQuantization, aScope);
+
+ InternalParameters.WriteForcedUVExport =
theResource->BooleanVal("write.forced.uv.export", InternalParameters.WriteForcedUVExport, aScope);
- InternalParameters.WriteEmbedTexturesInGlb =
+ InternalParameters.WriteEmbedTexturesInGlb =
theResource->BooleanVal("write.embed.textures.in.glb", InternalParameters.WriteEmbedTexturesInGlb, aScope);
- InternalParameters.WriteMergeFaces =
+ InternalParameters.WriteMergeFaces =
theResource->BooleanVal("write.merge.faces", InternalParameters.WriteMergeFaces, aScope);
- InternalParameters.WriteSplitIndices16 =
+ InternalParameters.WriteSplitIndices16 =
theResource->BooleanVal("write.split.indices16", InternalParameters.WriteSplitIndices16, aScope);
+ InternalParameters.WriteParallel =
+ theResource->BooleanVal("write.parallel", InternalParameters.WriteParallel, aScope);
return true;
}
aResult += aScope + "write.mesh.name.format :\t " + InternalParameters.WriteMeshNameFormat + "\n";
aResult += "!\n";
+ // Draco parameters
+ aResult += "!\n";
+ aResult += "!Flag to use Draco compression. If it is TRUE, compression is used\n";
+ aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
+ aResult += aScope + "write.draco.compression :\t " +
+ InternalParameters.WriteDracoParameters.DracoCompression + "\n";
+ aResult += "!\n";
+
+ aResult += "!\n";
+ aResult += "!Draco compression level\n";
+ aResult += "!Default value: 7. Available values: [0-10]\n";
+ aResult += aScope + "write.draco.level :\t " +
+ InternalParameters.WriteDracoParameters.CompressionLevel + "\n";
+ aResult += "!\n";
+
+ aResult += "!\n";
+ aResult += "!Quantization bits for position attribute\n";
+ aResult += "!Default value: 14. Available values: any positive value\n";
+ aResult += aScope + "write.draco.position.bits :\t " +
+ InternalParameters.WriteDracoParameters.QuantizePositionBits + "\n";
+ aResult += "!\n";
+
+ aResult += "!\n";
+ aResult += "!Quantization bits for normal attribute\n";
+ aResult += "!Default value: 10. Available values: any positive value\n";
+ aResult += aScope + "write.draco.normal.bits :\t " +
+ InternalParameters.WriteDracoParameters.QuantizeNormalBits + "\n";
+ aResult += "!\n";
+
+ aResult += "!\n";
+ aResult += "!Quantization bits for texture coordinate attribute\n";
+ aResult += "!Default value: 12. Available values: any positive value\n";
+ aResult += aScope + "write.draco.texture.bits :\t " +
+ InternalParameters.WriteDracoParameters.QuantizeTexcoordBits + "\n";
+ aResult += "!\n";
+
+ aResult += "!\n";
+ aResult += "!Quantization bits for color attributes\n";
+ aResult += "!Default value: 8. Available values: any positive value\n";
+ aResult += aScope + "write.draco.color.bits :\t " +
+ InternalParameters.WriteDracoParameters.QuantizeColorBits + "\n";
+ aResult += "!\n";
+
+ aResult += "!\n";
+ aResult += "!Quantization bits for skinning and custom attributes\n";
+ aResult += "!Default value: 12. Available values: any positive value\n";
+ aResult += aScope + "write.draco.generic.bits :\t " +
+ InternalParameters.WriteDracoParameters.QuantizeGenericBits + "\n";
+ aResult += "!\n";
+
+ aResult += "!\n";
+ aResult += "!Quantize positions of all primitives using the same quantization grid\n";
+ aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
+ aResult += aScope + "write.draco.unified.quantization :\t " +
+ InternalParameters.WriteDracoParameters.UnifiedQuantization + "\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.split.indices16 :\t " + InternalParameters.WriteSplitIndices16 + "\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 + "write.parallel :\t " + InternalParameters.WriteParallel + "\n";
+ aResult += "!\n";
+
aResult += "!*****************************************************************************\n";
return aResult;
}
#include <DE_ConfigurationNode.hxx>
#include <RWMesh_CoordinateSystem.hxx>
+#include <RWGltf_DracoParameters.hxx>
#include <RWGltf_WriterTrsfFormat.hxx>
#include <RWMesh_NameFormat.hxx>
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
+ RWGltf_DracoParameters WriteDracoParameters; //!< Defines draco compression parameters
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
+ bool WriteParallel = false; //!< Flag to use multithreading
} InternalParameters;
};
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_DocumentTool.hxx>
-namespace
+namespace
{
//=======================================================================
// function : SetReaderParameters
// purpose :
//=======================================================================
- static void SetReaderParameters(RWGltf_CafReader& theReader, const Handle(RWGltf_ConfigurationNode) theNode)
+ static void SetReaderParameters(RWGltf_CafReader& theReader,
+ const Handle(RWGltf_ConfigurationNode) theNode)
{
theReader.SetDoublePrecision(!theNode->InternalParameters.ReadSinglePrecision);
theReader.SetSystemLengthUnit(theNode->GlobalParameters.LengthUnit / 1000);
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";
+ Message::SendFail() << "Error: RWGltf_Provider : "
+ << "Null document";
return false;
}
- if (GetNode().IsNull() || (!GetNode().IsNull() && !GetNode()->IsKind(STANDARD_TYPE(RWGltf_ConfigurationNode))))
+ 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";
+ Message::SendFail() << "Error: RWGltf_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(RWGltf_ConfigurationNode) aNode = Handle(RWGltf_ConfigurationNode)::DownCast(GetNode());
+ 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);
+ 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;
+ Message::SendFail() << "Error: RWGltf_Provider : [" <<
+ thePath << "] : Cannot read any relevant data from the GLTF file";
return false;
}
-
+ myExternalFiles = aReader.ExternalFiles();
+ myMetadata = aReader.Metadata();
return true;
}
//=======================================================================
bool RWGltf_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(RWGltf_ConfigurationNode)))
+ (void)theWS;
+ 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";
+ Message::SendFail() << "Error: RWGltf_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(RWGltf_ConfigurationNode) aNode = Handle(RWGltf_ConfigurationNode)::DownCast(GetNode());
+ Handle(RWGltf_ConfigurationNode) aNode =
+ Handle(RWGltf_ConfigurationNode)::DownCast(GetNode());
RWMesh_CoordinateSystemConverter aConverter;
aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
anExt.LowerCase();
RWGltf_CafWriter aWriter(thePath, anExt.EndsWith(".glb"));
aWriter.SetCoordinateSystemConverter(aConverter);
+ aWriter.SetCompressionParameters(aNode->InternalParameters.WriteDracoParameters);
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.SetParallel(aNode->InternalParameters.WriteParallel);
aWriter.SetSplitIndices16(aNode->InternalParameters.WriteSplitIndices16);
if (!aWriter.Perform(theDocument, aFileInfo, theProgress))
{
- Message::SendFail() << "Error in the RWGltf_Provider during writing the file " << thePath;
+ Message::SendFail() << "Error: RWGltf_Provider : [" <<
+ thePath << "] : Cannot write any relevant data to the GLTF file";
return false;
}
return true;
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)))
+ 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";
+ Message::SendFail() << "Error: RWGltf_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(RWGltf_ConfigurationNode) aNode = Handle(RWGltf_ConfigurationNode)::DownCast(GetNode());
+ 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;
+ Message::SendFail() << "Error: RWGltf_Provider : [" <<
+ thePath << "] : Cannot read any relevant data from the GLTF file";
return false;
}
theShape = aReader.SingleShape();
+ myExternalFiles = aReader.ExternalFiles();
+ myMetadata = aReader.Metadata();
return true;
}
//=======================================================================
bool RWGltf_Provider::Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape,
+ Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
+ (void)theWS;
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);
+ return Write(thePath, aDoc, theWS, theProgress);
}
//=======================================================================
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
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's vendor name
Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE;
+public:
+
+ //!
+ const TColStd_IndexedDataMapOfStringString& GetMetadata() const { return myMetadata; }
+
+ //!
+ const NCollection_IndexedMap<TCollection_AsciiString>& GetExternalFiles() const { return myExternalFiles; }
+
+private:
+
+ TColStd_IndexedDataMapOfStringString myMetadata; //!<
+ NCollection_IndexedMap<TCollection_AsciiString> myExternalFiles; //!<
};
#endif // _RWGltf_Provider_HeaderFile
theResource->BooleanVal("read.single.precision", InternalParameters.ReadSinglePrecision, aScope);
InternalParameters.ReadCreateShapes =
theResource->BooleanVal("read.create.shapes", InternalParameters.ReadCreateShapes, aScope);
+ InternalParameters.ReadCreateSingle =
+ theResource->BooleanVal("read.create.single", InternalParameters.ReadCreateSingle, aScope);
InternalParameters.ReadRootPrefix =
theResource->StringVal("read.root.prefix", InternalParameters.ReadRootPrefix, aScope);
InternalParameters.ReadFillDoc =
aResult += "!\n";
aResult += "!\n";
- aResult += "!Flag for create a single triangulation\n";
+ aResult += "!Flag for create shapes in shape reading case\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 += "!Flag for create shapes in shape reading case\n";
+ aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
+ aResult += aScope + "read.create.single :\t " + InternalParameters.ReadCreateSingle + "\n";
+ aResult += "!\n";
+
aResult += "!\n";
aResult += "!Root folder for generating root labels names\n";
aResult += "!Default value: ""(empty). Available values: <path>\n";
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
+ bool ReadCreateShapes = false; //!< Flag for create shapes in shape reading case
+ bool ReadCreateSingle = false; //!< Flag for create a single triangulation in shape reading case
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
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";
+ Message::SendFail() << "Error: RWObj_Provider : "
+ << "Null document";
return false;
}
- if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(RWObj_ConfigurationNode)))
+ 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";
+ Message::SendFail() << "Error: RWObj_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(RWObj_ConfigurationNode) aNode = Handle(RWObj_ConfigurationNode)::DownCast(GetNode());
+ Handle(RWObj_ConfigurationNode) aNode =
+ Handle(RWObj_ConfigurationNode)::DownCast(GetNode());
RWObj_CafReader aReader;
aReader.SetSinglePrecision(aNode->InternalParameters.ReadSinglePrecision);
aReader.SetSystemLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
aReader.SetMemoryLimitMiB(aNode->InternalParameters.ReadMemoryLimitMiB);
if (!aReader.Perform(thePath, theProgress))
{
- Message::SendFail() << "Error in the RWObj_ConfigurationNode during reading the file " << thePath;
+ Message::SendFail() << "Error: RWObj_Provider : [" <<
+ thePath << "] : Cannot read any relevant data from the Obj file";
return false;
}
- XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter);
+ myExternalFiles = aReader.ExternalFiles();
return true;
}
//=======================================================================
bool RWObj_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(RWObj_ConfigurationNode)))
+ (void)theWS;
+ 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";
+ Message::SendFail() << "Error: RWObj_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(RWObj_ConfigurationNode) aNode = Handle(RWObj_ConfigurationNode)::DownCast(GetNode());
+ Handle(RWObj_ConfigurationNode) aNode =
+ Handle(RWObj_ConfigurationNode)::DownCast(GetNode());
TColStd_IndexedDataMapOfStringString aFileInfo;
if (!aNode->InternalParameters.WriteAuthor.IsEmpty())
{
aFileInfo.Add("Comments", aNode->InternalParameters.WriteComment);
}
-
RWMesh_CoordinateSystemConverter aConverter;
aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
aConverter.SetInputCoordinateSystem(aNode->InternalParameters.SystemCS);
aWriter.SetCoordinateSystemConverter(aConverter);
if (!aWriter.Perform(theDocument, aFileInfo, theProgress))
{
- Message::SendFail() << "Error in the RWObj_ConfigurationNode during writing the file " << thePath;
+ Message::SendFail() << "Error: RWObj_Provider : [" <<
+ thePath << "] : Cannot write any relevant data to the Obj file";
return false;
}
return true;
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)))
+ 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";
+ Message::SendFail() << "Error: RWObj_Provider : "
+ << "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))
+ Handle(RWObj_ConfigurationNode) aNode =
+ Handle(RWObj_ConfigurationNode)::DownCast(GetNode());
+ if (aNode->InternalParameters.ReadCreateSingle)
{
- Message::SendFail() << "Error in the RWObj_ConfigurationNode during reading the file " << thePath;
+ 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: RWObj_Provider : [" <<
+ thePath << "] : Cannot read any relevant data from the Obj file";
+ return false;
+ }
+ Handle(Poly_Triangulation) aTriangulation = aSimpleReader.GetTriangulation();
+ TopoDS_Face aFace;
+ BRep_Builder aBuiler;
+ aBuiler.MakeFace(aFace);
+ aBuiler.UpdateFace(aFace, aTriangulation);
+ theShape = aFace;
+ myExternalFiles = aSimpleReader.ExternalFiles();
+ return true;
+ }
+ 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.SetRootPrefix(aNode->InternalParameters.ReadRootPrefix);
+ aReader.SetMemoryLimitMiB(aNode->InternalParameters.ReadMemoryLimitMiB);
+ if (!aReader.Perform(thePath, theProgress))
+ {
+ Message::SendFail() << "Error: RWObj_Provider : [" <<
+ thePath << "] : Cannot read any relevant data from the Obj file";
return false;
}
- Handle(Poly_Triangulation) aTriangulation = aSimpleReader.GetTriangulation();
- TopoDS_Face aFace;
- BRep_Builder aBuiler;
- aBuiler.MakeFace(aFace);
- aBuiler.UpdateFace(aFace, aTriangulation);
- theShape = aFace;
+ theShape = aReader.SingleShape();
+ myExternalFiles = aReader.ExternalFiles();
return true;
}
//=======================================================================
bool RWObj_Provider::Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape,
+ Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
+ (void)theWS;
Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF");
- Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
+ Handle(XCAFDoc_ShapeTool) aShTool =
+ XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
aShTool->AddShape(theShape);
- return Write(thePath, aDoc, theProgress);
+ return Write(thePath, aDoc, theWS, theProgress);
}
//=======================================================================
#include <DE_Provider.hxx>
+#include <NCollection_IndexedMap.hxx>
+
//! The class to transfer OBJ files.
//! Reads and Writes any OBJ files into/from OCCT.
//! Each operation needs configuration node.
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
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
//! Gets provider's vendor name of associated provider
//! @return provider's vendor name
Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE;
+
+public:
+
+ //!
+ const NCollection_IndexedMap<TCollection_AsciiString>& GetExternalFiles() const { return myExternalFiles; }
+
+private:
+
+ NCollection_IndexedMap<TCollection_AsciiString> myExternalFiles; //!<
};
#endif // _RWObj_Provider_HeaderFile
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)))
+ 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";
+ Message::SendFail() << "Error: RWPly_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(RWPly_ConfigurationNode) aNode = Handle(RWPly_ConfigurationNode)::DownCast(GetNode());
+ Handle(RWPly_ConfigurationNode) aNode =
+ Handle(RWPly_ConfigurationNode)::DownCast(GetNode());
TDF_LabelSequence aRootLabels;
- Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
+ Handle(XCAFDoc_ShapeTool) aShapeTool =
+ XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
aShapeTool->GetFreeShapes(aRootLabels);
if (aRootLabels.IsEmpty())
{
return Standard_True;
}
-
TColStd_IndexedDataMapOfStringString aFileInfo;
if (!aNode->InternalParameters.WriteAuthor.IsEmpty())
{
aPlyCtx.SetFaceId(aNode->InternalParameters.WriteFaceId);
if (!aPlyCtx.Perform(theDocument, aFileInfo, theProgress))
{
- Message::SendFail() << "Error in the RWPly_Provider during writing the file "
- << thePath << "\t: Cannot perform the document";
+ Message::SendFail() << "Error: RWObj_Provider : [" <<
+ thePath << "] : Cannot write any relevant data to the Ply file";
return false;
}
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);
+ return Write(thePath, aDoc, theWS, theProgress);
}
//=======================================================================
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
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
InternalParameters.ReadMergeAngle =
theResource->RealVal("read.merge.angle", InternalParameters.ReadMergeAngle, aScope);
- InternalParameters.ReadBRep =
- theResource->BooleanVal("read.brep", InternalParameters.ReadBRep, aScope);
+ InternalParameters.ReadShapeType = (ReadMode_ShapeType)
+ theResource->IntegerVal("read.brep", InternalParameters.ReadShapeType, aScope);
InternalParameters.WriteAscii =
theResource->BooleanVal("write.ascii", InternalParameters.WriteAscii, aScope);
return true;
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 += "!Defines result type of transferred shape\n";
+ aResult += "!Default value: 1(SingleMesh). Available values: 0(MultiMesh), 1(SingleMesh), 2(CompShape)\n";
+ aResult += aScope + "read.brep :\t " + InternalParameters.ReadShapeType + "\n";
aResult += "!\n";
aResult += "!\n";
Standard_EXPORT virtual bool CheckContent(const Handle(NCollection_Buffer)& theBuffer) const Standard_OVERRIDE;
public:
+ enum ReadMode_ShapeType
+ {
+ ReadMode_ShapeType_MultiMesh = 0,
+ ReadMode_ShapeType_SingleMesh,
+ ReadMode_ShapeType_CompShape,
+ };
struct RWStl_InternalSection
{
// Read
double ReadMergeAngle = 90.; //!< Input merge angle value
- bool ReadBRep = false; //!< Setting up Boundary Representation flag
+ ReadMode_ShapeType ReadShapeType = ReadMode_ShapeType_SingleMesh; //!< Defines result type of transferred shape
// Write
bool WriteAscii = true; //!< Setting up writing mode (Ascii or Binary)
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";
+ Message::SendFail() << "Error: RWStl_Provider : "
+ << "Null document";
return false;
}
TopoDS_Shape aShape;
- if (!Read(thePath, aShape, theProgress))
+ if (!Read(thePath, aShape, theWS, theProgress))
{
return false;
}
- Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
+ Handle(XCAFDoc_ShapeTool) aShapeTool =
+ XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
aShapeTool->AddShape(aShape);
return true;
}
//=======================================================================
bool RWStl_Provider::Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
+ Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
+ (void)theWS;
TopoDS_Shape aShape;
TDF_LabelSequence aLabels;
- Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
+ 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";
+ Message::SendFail() << "Error: RWStl_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
}
aShape = aComp;
}
- return Write(thePath, aShape, theProgress);
+ return Write(thePath, aShape, theWS, theProgress);
}
//=======================================================================
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";
+ 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;
+ Message::SendFail() << "Error: RWStl_Provider : "
+ << "Incorrect or empty Configuration Node";
+ return false;
}
- Handle(RWStl_ConfigurationNode) aNode = Handle(RWStl_ConfigurationNode)::DownCast(GetNode());
+ 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)
{
- 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;
- }
+ Message::SendFail() << "Error: RWStl_Provider : ["
+ << aMergeAngle << "] The merge angle is out of the valid range";
+ return false;
}
- if (!aNode->InternalParameters.ReadBRep)
+ switch (aNode->InternalParameters.ReadShapeType)
{
- Handle(Poly_Triangulation) aTriangulation = RWStl::ReadFile(thePath.ToCString(), aMergeAngle, theProgress);
+ case(RWStl_ConfigurationNode::ReadMode_ShapeType_MultiMesh):
+ {
+ NCollection_Sequence<Handle(Poly_Triangulation)> aTriangList;
+ // Read STL file to the triangulation list.
+ RWStl::ReadFile(thePath.ToCString(), aMergeAngle, aTriangList, theProgress);
+ BRep_Builder aB;
+ TopoDS_Face aFace;
+ if (aTriangList.Size() == 1)
+ {
+ aB.MakeFace(aFace);
+ aB.UpdateFace(aFace, aTriangList.First());
+ theShape = aFace;
+ }
+ else
+ {
+ TopoDS_Compound aCmp;
+ for (NCollection_Sequence<Handle(Poly_Triangulation)>::Iterator anIt(aTriangList);
+ anIt.More(); anIt.Next())
+ {
+ if (aCmp.IsNull())
+ {
+ aB.MakeCompound(aCmp);
+ }
+ if (aFace.IsNull())
+ {
+ aB.MakeFace(aFace);
+ }
+ aB.UpdateFace(aFace, anIt.Value());
+ aB.Add(aCmp, aFace);
+ }
+ theShape = aCmp;
+ }
+ break;
+ }
+ case(RWStl_ConfigurationNode::ReadMode_ShapeType_SingleMesh):
+ {
+ // Read STL file to the triangulation.
+ 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()))
+ if (!aTriangulation.IsNull())
{
- Message::SendFail() << "Error in the RWStl_Provider during reading the file " << thePath;
- return false;
+ TopoDS_Face aFace;
+ BRep_Builder aB;
+ aB.MakeFace(aFace);
+ aB.UpdateFace(aFace, aTriangulation);
+ theShape = aFace;
}
- Standard_ENABLE_DEPRECATION_WARNINGS
+ break;
+ }
+ case(RWStl_ConfigurationNode::ReadMode_ShapeType_CompShape):
+ {
+ Standard_DISABLE_DEPRECATION_WARNINGS
+ StlAPI::Read(theShape, thePath.ToCString());
+ Standard_ENABLE_DEPRECATION_WARNINGS
+ break;
+ }
+ }
+ if (theShape.IsNull())
+ {
+ Message::SendFail() << "Error: RWStl_Provider : [" <<
+ thePath << "] : Cannot read any relevant data from the STL file";
+ return false;
}
return true;
}
//=======================================================================
bool RWStl_Provider::Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape,
+ Handle(XSControl_WorkSession)& theWS,
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)))
+ (void)theWS;
+ 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";
+ Message::SendFail() << "Error: RWStl_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(RWStl_ConfigurationNode) aNode = Handle(RWStl_ConfigurationNode)::DownCast(GetNode());
+ 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";
+ Message::SendFail() << "Error: RWStl_Provider : [" <<
+ thePath << "] : Mesh writing has been failed";
return false;
}
return true;
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
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
theResource->IntegerVal("write.unit", InternalParameters.WriteUnit, aScope);
InternalParameters.WriteResourceName =
theResource->StringVal("write.resource.name", InternalParameters.WriteResourceName, aScope);
+ InternalParameters.WriteMultiPrefix =
+ theResource->StringVal("write.multi.prefix", InternalParameters.WriteMultiPrefix, aScope);
InternalParameters.WriteSequence =
theResource->StringVal("write.sequence", InternalParameters.WriteSequence, aScope);
+ InternalParameters.WriteLabels =
+ theResource->StringSeqVal("write.labels", InternalParameters.WriteLabels, aScope);
InternalParameters.WriteVertexMode = (WriteMode_VertexMode)
theResource->IntegerVal("write.vertex.mode", InternalParameters.WriteVertexMode, aScope);
InternalParameters.WriteSubshapeNames =
aResult += aScope + "write.resource.name :\t " + InternalParameters.WriteResourceName + "\n";
aResult += "!\n";
+ aResult += "!\n";
+ aResult += "!Defines prefix for names of external files, if empty do not make multifile\n";
+ aResult += "!Default value: empty. Available values: <string>\n";
+ aResult += aScope + "write.multi.prefix :\t " + InternalParameters.WriteMultiPrefix + "\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 += "!Defines list of shape labels to export, if empty import full document\n";
+ aResult += "!Default value: empty. Available values: sequense of label entries\n";
+ aResult += aScope + "write.labels :\t ";
+ for (TColStd_ListOfAsciiString::Iterator anIter(InternalParameters.WriteLabels);
+ anIter.More(); anIter.Next())
+ {
+ aResult += anIter.Value();
+ aResult += " ";
+ }
+ aResult += "\n!\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";
#include <DE_ConfigurationNode.hxx>
#include <STEPControl_StepModelType.hxx>
#include <Resource_FormatType.hxx>
+#include <TColStd_SequenceOfAsciiString.hxx>
#include <UnitsMethods_LengthUnit.hxx>
//! The purpose of this class is to configure the transfer process for STEP format
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 WriteMultiPrefix; //<! Defines prefix for names of external files, if empty do not make multifile
TCollection_AsciiString WriteSequence = "ToSTEP"; //<! Defines the name of the sequence of operators to write
+ TColStd_ListOfAsciiString WriteLabels; //<! Defines list of shape labels to export, if empty import full document
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
#include <BinXCAFDrivers.hxx>
#include <Interface_Static.hxx>
#include <Message.hxx>
+#include <STEPControl_Controller.hxx>
#include <StepData_StepModel.hxx>
+#include <STEPControl_ActorWrite.hxx>
#include <STEPCAFControl_ConfigurationNode.hxx>
#include <STEPCAFControl_Controller.hxx>
#include <STEPCAFControl_Reader.hxx>
#include <STEPCAFControl_Writer.hxx>
+#include <TDocStd_Document.hxx>
+#include <TDataStd_Name.hxx>
+#include <TDF_Tool.hxx>
#include <XCAFDoc_DocumentTool.hxx>
+#include <XSControl_WorkSession.hxx>
#include <UnitsMethods.hxx>
IMPLEMENT_STANDARD_RTTIEXT(STEPCAFControl_Provider, DE_Provider)
:DE_Provider(theNode)
{}
+//=======================================================================
+// function : STEPCAFControl_Provider
+// purpose :
+//=======================================================================
+void STEPCAFControl_Provider::personizeWS(Handle(XSControl_WorkSession)& theWS)
+{
+ if (theWS.IsNull())
+ {
+ Message::SendWarning() << "Warning: STEPCAFControl_Provider :"
+ << " Null work session, use internal temporary session";
+ theWS = new XSControl_WorkSession();
+ }
+ Handle(STEPControl_Controller) aCntrl =
+ Handle(STEPControl_Controller)::DownCast(theWS->NormAdaptor());
+ if (aCntrl.IsNull())
+ {
+ theWS->SelectNorm("STEP");
+ }
+}
+
//=======================================================================
// function : initStatic
// purpose :
//=======================================================================
void STEPCAFControl_Provider::initStatic(const Handle(DE_ConfigurationNode)& theNode)
{
- Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(theNode);
+ Handle(STEPCAFControl_ConfigurationNode) aNode =
+ Handle(STEPCAFControl_ConfigurationNode)::DownCast(theNode);
STEPCAFControl_Controller::Init();
-
+ if (!myToUpdateStaticParameters)
+ {
+ return;
+ }
// 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.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.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;
+ 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);
//=======================================================================
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::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::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);
+ 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);
}
//=======================================================================
//=======================================================================
void STEPCAFControl_Provider::resetStatic()
{
+ if (!myToUpdateStaticParameters)
+ {
+ return;
+ }
setStatic(myOldValues);
}
{
if (theDocument.IsNull())
{
- Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " <<
- thePath << "\t: theDocument shouldn't be null";
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Null document";
return false;
}
- if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(STEPCAFControl_ConfigurationNode)))
+ 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";
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
+ 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())
+ personizeWS(theWS);
+ XCAFDoc_DocumentTool::SetLengthUnit(theDocument,
+ aNode->GlobalParameters.LengthUnit,
+ UnitsMethods_LengthUnit_Millimeter);
+ const Standard_Boolean toUseLoaded = thePath == ".";
+ TCollection_AsciiString aFile;
+ if (toUseLoaded)
+ {
+ aFile = theWS->LoadedFile();
+ Message::SendInfo() << "Model taken from the STEP session : "
+ << aFile;
+ }
+ else
{
- aReader.Init(theWS);
+ aFile = thePath;
+ Message::SendInfo() << "File STEP to read : "
+ << aFile;
}
+ STEPCAFControl_Reader aReader(theWS, !toUseLoaded);
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 (!toUseLoaded)
+ {
+ aReadStat = aReader.ReadFile(thePath.ToCString());
+ }
+ else if (theWS->NbStartingEntities() > 0)
+ {
+ aReadStat = IFSelect_RetDone;
+ }
if (aReadStat != IFSelect_RetDone)
{
- Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " <<
- thePath << "\t: abandon";
+ Message::SendFail() << "Error: STEPCAFControl_Provider : ["
+ << aFile << "] : abandon, no model loaded";
resetStatic();
return false;
}
+ if (!aReader.Transfer(theDocument, theProgress))
+ {
+ Message::SendFail() << "Error: STEPCAFControl_Provider : [" <<
+ aFile << "] : Cannot read any relevant data from the STEP file";
+ resetStatic();
+ return false;
+ }
+ resetStatic();
+ myProcessedExtFiles = aReader.ExternFiles();
+ return true;
+}
+
+
+//=======================================================================
+// function : Read
+// purpose :
+//=======================================================================
+bool STEPCAFControl_Provider::Read(std::istream& theIStream,
+ const Handle(TDocStd_Document)& theDocument,
+ const TCollection_AsciiString theName,
+ Handle(XSControl_WorkSession)& theWS,
+ const Message_ProgressRange& theProgress)
+{
+ if (theDocument.IsNull())
+ {
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Null document";
+ return false;
+ }
+ if (GetNode().IsNull() ||
+ !GetNode()->IsKind(STANDARD_TYPE(STEPCAFControl_ConfigurationNode)))
+ {
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Incorrect or empty Configuration Node";
+ return false;
+ }
+ Handle(STEPCAFControl_ConfigurationNode) aNode =
+ Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
+ initStatic(aNode);
+ personizeWS(theWS);
+ XCAFDoc_DocumentTool::SetLengthUnit(theDocument,
+ aNode->GlobalParameters.LengthUnit,
+ UnitsMethods_LengthUnit_Millimeter);
+ Message::SendInfo() << "Model taken from the STEP stream";
+ STEPCAFControl_Reader aReader(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.ReadStream(theName.ToCString(), theIStream);
+ if (aReadStat != IFSelect_RetDone)
+ {
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Abandon, no model loaded via stream";
+ 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";
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Cannot read any relevant data from the STEP file";
resetStatic();
return false;
}
resetStatic();
+ myProcessedExtFiles = aReader.ExternFiles();
return true;
}
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
- if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(STEPCAFControl_ConfigurationNode)))
+ 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";
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
+ Handle(STEPCAFControl_ConfigurationNode) aNode =
+ Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
initStatic(aNode);
-
- XCAFDoc_DocumentTool::SetLengthUnit(theDocument,
- UnitsMethods::GetLengthUnitScale(aNode->InternalParameters.WriteUnit, UnitsMethods_LengthUnit_Millimeter),
+ 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);
+ personizeWS(theWS);
+ STEPCAFControl_Writer aWriter(theWS, Standard_True);
+ 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))
+ TDF_LabelSequence aLabels;
+ TCollection_AsciiString aLabelsString;
+ for (TColStd_ListOfAsciiString::Iterator anIter(aNode->InternalParameters.WriteLabels);
+ anIter.More(); anIter.Next())
+ {
+ const TCollection_AsciiString& aValue = anIter.Value();
+ TDF_Label aLabel;
+ TDF_Tool::Label(theDocument->Main().Data(), aValue, aLabel, Standard_False);
+ if (aLabel.IsNull())
+ {
+ Message::SendFail() << "Error: No label for entry '" << aValue << "'";
+ return false;
+ }
+ if (!aLabelsString.IsEmpty())
+ {
+ aLabelsString += " ";
+ }
+ aLabelsString += aValue;
+ aLabels.Append(aLabel);
+ }
+ TCollection_ExtendedString aDocName;
+ Handle(TDataStd_Name) aNameAttr;
+ if (theDocument->GetData()->Root().FindAttribute(TDataStd_Name::GetID(), aNameAttr))
+ {
+ aDocName = aNameAttr->Get();
+ }
+ Standard_Boolean aTransferStatus = Standard_True;
+ Standard_CString aMultiFilePrefix = !aNode->InternalParameters.WriteMultiPrefix.IsEmpty() ?
+ aNode->InternalParameters.WriteMultiPrefix.ToCString() : nullptr;
+ Message::SendInfo() << "Writing STEP file "
+ << thePath;
+ if (aLabels.IsEmpty())
{
- Message::SendFail() << "Error in the STEPCAFControl_Provider during writing the file " <<
- thePath << "\t: The document cannot be translated or gives no result";
+ Message::SendInfo() << "Translating labels "
+ << aLabelsString << " of document " << aDocName << " to STEP";
+ aTransferStatus = aWriter.Transfer(theDocument, aMode, aMultiFilePrefix, theProgress);
+ }
+ else
+ {
+ Message::SendInfo() << "Translating document "
+ << aDocName << " to STEP";
+ aTransferStatus = aWriter.Transfer(aLabels, aMode, aMultiFilePrefix, theProgress);
+ }
+ if (!aTransferStatus)
+ {
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "The document cannot be translated or gives no result";
resetStatic();
return false;
}
- IFSelect_ReturnStatus aStatus = aWriter.Write(thePath.ToCString());
- switch (aStatus)
+ if (thePath == ".")
{
- 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:
+ resetStatic();
+ Message::SendInfo() << "Document has been translated into the session";
+ return true;
+ }
+ if (aWriter.Write(thePath.ToCString()) != IFSelect_RetDone)
+ {
+ Message::SendFail() << "Error: STEPCAFControl_Provider : [" <<
+ thePath << "] : Write failed";
+ resetStatic();
+ return false;
+ }
+ Message::SendInfo() << "STEP file [" << thePath << "] Successfully written";
+ resetStatic();
+ myProcessedExtFiles = aWriter.ExternFiles();
+ return true;
+}
+
+//=======================================================================
+// function : Write
+// purpose :
+//=======================================================================
+bool STEPCAFControl_Provider::Write(std::ostream& theOStream,
+ 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: STEPCAFControl_Provider : "
+ << "Incorrect or empty Configuration Node";
+ return false;
+ }
+ Handle(STEPCAFControl_ConfigurationNode) aNode =
+ Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
+ initStatic(aNode);
+ personizeWS(theWS);
+ STEPCAFControl_Writer aWriter(theWS, Standard_True);
+ 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);
+ Handle(StepData_StepModel) aModel = aWriter.ChangeWriter().Model();
+ aModel->SetWriteLengthUnit(UnitsMethods::GetLengthUnitScale(
+ aNode->InternalParameters.WriteUnit,
+ UnitsMethods_LengthUnit_Millimeter));
+ TDF_LabelSequence aLabels;
+ TCollection_AsciiString aLabelsString;
+ for (TColStd_ListOfAsciiString::Iterator anIter(aNode->InternalParameters.WriteLabels);
+ anIter.More(); anIter.Next())
+ {
+ const TCollection_AsciiString& aValue = anIter.Value();
+ TDF_Label aLabel;
+ TDF_Tool::Label(theDocument->Main().Data(), aValue, aLabel, Standard_False);
+ if (aLabel.IsNull())
{
- break;
+ Message::SendFail() << "Error: No label for entry '" << aValue << "'";
+ return false;
}
- default:
+ if (!aLabelsString.IsEmpty())
{
- Message::SendFail() << "Error in the STEPCAFControl_Provider during writing the file " <<
- thePath << "\t: Error on writing file";
- resetStatic();
- return false;
+ aLabelsString += " ";
}
+ aLabelsString += aValue;
+ aLabels.Append(aLabel);
}
+ TCollection_ExtendedString aDocName;
+ Handle(TDataStd_Name) aNameAttr;
+ if (theDocument->GetData()->Root().FindAttribute(TDataStd_Name::GetID(), aNameAttr))
+ {
+ aDocName = aNameAttr->Get();
+ }
+ Standard_Boolean aTransferStatus = Standard_True;
+ Standard_CString aMultiFilePrefix = !aNode->InternalParameters.WriteMultiPrefix.IsEmpty() ?
+ aNode->InternalParameters.WriteMultiPrefix.ToCString() : nullptr;
+ Message::SendInfo() << "Writing STEP file to stream";
+ if (aLabels.IsEmpty())
+ {
+ Message::SendInfo() << "Translating labels "
+ << aLabelsString << " of document " << aDocName << " to STEP";
+ aTransferStatus = aWriter.Transfer(theDocument, aMode, aMultiFilePrefix, theProgress);
+ }
+ else
+ {
+ Message::SendInfo() << "Translating document "
+ << aDocName << " to STEP";
+ aTransferStatus = aWriter.Transfer(aLabels, aMode, aMultiFilePrefix, theProgress);
+ }
+ if (!aTransferStatus)
+ {
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "The document cannot be translated or gives no result";
+ resetStatic();
+ return false;
+ }
+ if (aWriter.WriteStream(theOStream) != IFSelect_RetDone)
+ {
+ Message::SendFail() << "Error: STEPCAFControl_Provider : Write to stream failed";
+ resetStatic();
+ return false;
+ }
+ Message::SendInfo() << "STEP file to stream successfully written";
resetStatic();
+ myProcessedExtFiles = aWriter.ExternFiles();
return true;
}
// purpose :
//=======================================================================
bool STEPCAFControl_Provider::Read(const TCollection_AsciiString& thePath,
- const Handle(TDocStd_Document)& theDocument,
+ TopoDS_Shape& theShape,
+ Handle(XSControl_WorkSession)& theWS,
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);
+ (void)theProgress;
+ if (GetNode().IsNull() ||
+ !GetNode()->IsKind(STANDARD_TYPE(STEPCAFControl_ConfigurationNode)))
+ {
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Incorrect or empty Configuration Node";
+ return false;
+ }
+ Handle(STEPCAFControl_ConfigurationNode) aNode =
+ Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
+ initStatic(aNode);
+ personizeWS(theWS);
+ STEPControl_Reader aReader(theWS);
+ if (aReader.ReadFile(thePath.ToCString()) != IFSelect_RetDone)
+ {
+ Message::SendFail() << "Error: STEPCAFControl_Provider : ["
+ << thePath << "] : 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: STEPCAFControl_Provider : [" <<
+ thePath << "] : Cannot read any relevant data from the STEP file";
+ resetStatic();
+ return false;
+ }
+ theShape = aReader.OneShape();
+ resetStatic();
+ return true;
}
//=======================================================================
// function : Read
// purpose :
//=======================================================================
-bool STEPCAFControl_Provider::Read(const TCollection_AsciiString& thePath,
+bool STEPCAFControl_Provider::Read(std::istream& theIStream,
TopoDS_Shape& theShape,
+ const TCollection_AsciiString theName,
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
(void)theProgress;
- if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(STEPCAFControl_ConfigurationNode)))
+ 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";
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
+ 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)
+ personizeWS(theWS);
+ STEPControl_Reader aReader(theWS);
+ if (aReader.ReadStream(theName.ToCString(), theIStream) != IFSelect_RetDone)
{
- Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " <<
- thePath << "\t: abandon, no model loaded";
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Abandon, no model loaded from STEP stream";
resetStatic();
return false;
}
aModel->SetLocalLengthUnit(aNode->GlobalParameters.LengthUnit);
if (aReader.TransferRoots() <= 0)
{
- Message::SendFail() << "Error in the STEPCAFControl_Provider during reading the file " <<
- thePath << "\t:Cannot read any relevant data from the STEP file";
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Cannot read any relevant data from the STEP stream";
resetStatic();
return false;
}
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
- if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(STEPCAFControl_ConfigurationNode)))
+ 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";
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Incorrect or empty Configuration Node";
return false;
}
- Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
+ Handle(STEPCAFControl_ConfigurationNode) aNode =
+ Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
initStatic(aNode);
- STEPControl_Writer aWriter;
- if(!theWS.IsNull())
+ personizeWS(theWS);
+ STEPControl_Writer aWriter(theWS, Standard_True);
+ Handle(StepData_StepModel) aModel = aWriter.Model();
+ Standard_Integer aNbEntities = (aModel.IsNull() ? 0 : aModel->NbEntities());
+ aModel->SetWriteLengthUnit(UnitsMethods::GetLengthUnitScale(
+ aNode->InternalParameters.WriteUnit,
+ UnitsMethods_LengthUnit_Millimeter));
+ IFSelect_ReturnStatus aWritestat =
+ aWriter.Transfer(theShape, aNode->InternalParameters.WriteModelType, true, theProgress);
+ if (aNbEntities > 0)
{
- aWriter.SetWS(theWS);
+ Message::SendTrace() << "STEPCAFControl_Provider : Model not empty before transferring";
}
- 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";
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Can't translate shape to STEP model";
resetStatic();
return false;
}
+ if (thePath == ".")
+ {
+ resetStatic();
+ Message::SendInfo() << "Step model has been translated into the session";
+ return true;
+ }
if (aWriter.Write(thePath.ToCString()) != IFSelect_RetDone)
{
- Message::SendFail() << "STEPCAFControl_Provider: Error on writing file";
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Can't write STEP file " << thePath;
resetStatic();
return false;
}
return true;
}
-//=======================================================================
-// function : Read
-// purpose :
-//=======================================================================
-bool STEPCAFControl_Provider::Read(const TCollection_AsciiString& thePath,
- TopoDS_Shape& theShape,
- const Message_ProgressRange& theProgress)
-{
- Handle(XSControl_WorkSession) aWS;
- return Read(thePath, theShape, aWS, theProgress);
-}
-
//=======================================================================
// function : Write
// purpose :
//=======================================================================
-bool STEPCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
+bool STEPCAFControl_Provider::Write(std::ostream& theOStream,
const TopoDS_Shape& theShape,
+ Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
- Handle(XSControl_WorkSession) aWS;
- return Write(thePath, theShape, aWS, theProgress);
+ if (GetNode().IsNull() ||
+ !GetNode()->IsKind(STANDARD_TYPE(STEPCAFControl_ConfigurationNode)))
+ {
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Incorrect or empty Configuration Node";
+ return false;
+ }
+ Handle(STEPCAFControl_ConfigurationNode) aNode =
+ Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
+ initStatic(aNode);
+
+ personizeWS(theWS);
+ STEPControl_Writer aWriter(theWS, Standard_True);
+ Handle(StepData_StepModel) aModel = aWriter.Model();
+ Standard_Integer aNbEntities = (aModel.IsNull() ? 0 : aModel->NbEntities());
+ aModel->SetWriteLengthUnit(UnitsMethods::GetLengthUnitScale(
+ aNode->InternalParameters.WriteUnit,
+ UnitsMethods_LengthUnit_Millimeter));
+ IFSelect_ReturnStatus aWritestat =
+ aWriter.Transfer(theShape, aNode->InternalParameters.WriteModelType, true, theProgress);
+ if (aNbEntities > 0)
+ {
+ Message::SendTrace() << "STEPCAFControl_Provider : Model not empty before transferring";
+ }
+ if (aWritestat != IFSelect_RetDone)
+ {
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Can't translate shape to STEP model";
+ resetStatic();
+ return false;
+ }
+ if (aWriter.WriteStream(theOStream) != IFSelect_RetDone)
+ {
+ Message::SendFail() << "Error: STEPCAFControl_Provider : "
+ << "Can't write STEP to stream";
+ resetStatic();
+ return false;
+ }
+ resetStatic();
+ return true;
}
//=======================================================================
#include <DE_Provider.hxx>
#include <STEPCAFControl_ConfigurationNode.hxx>
+#include <STEPCAFControl_ExternFile.hxx>
//! The class to transfer STEP files.
//! Reads and Writes any STEP files into/from OCCT.
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE;
+ //! Reads a CAD file, according internal configuration
+ //! @param[in] theIStream stream to import STEP data
+ //! @param[out] theDocument document to save result
+ //! @paramp[in] theName name of step file, can be empty
+ //! @param[in] theWS current work session
+ //! @param theProgress[in] progress indicator
+ //! @return true if Read operation has ended correctly
+ Standard_EXPORT virtual bool Read(std::istream& theIStream,
+ const Handle(TDocStd_Document)& theDocument,
+ const TCollection_AsciiString theName,
+ 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
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[in] theOStream stream to export STEP data
//! @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,
+ Standard_EXPORT virtual bool Write(std::ostream& theOStream,
const Handle(TDocStd_Document)& theDocument,
- const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE;
+ 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
Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE;
+ //! Reads a CAD file, according internal configuration
+ //! @param[in] theIStream stream to the step file
+ //! @param[out] theShape shape to save result
+ //! @paramp[in] theName name of step file, can be empty
+ //! @param[in] theWS current work session
+ //! @param theProgress[in] progress indicator
+ //! @return true if Read operation has ended correctly
+ Standard_EXPORT virtual bool Read(std::istream& theIStream,
+ TopoDS_Shape& theShape,
+ const TCollection_AsciiString theName,
+ 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
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[in] theOStream stream to export STEP data
//! @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,
+ Standard_EXPORT virtual bool Write(std::ostream& theOStream,
const TopoDS_Shape& theShape,
- const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE;
+ Handle(XSControl_WorkSession)& theWS,
+ const Message_ProgressRange& theProgress = Message_ProgressRange());
public:
//! @return provider's vendor name
Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE;
- private:
+public:
+
+ //! Sets parameter to update static parameter, that true by default
+ void SetToUpdateStaticParameters(const bool theToUpdate) { myToUpdateStaticParameters = theToUpdate; }
+
+ //! Gets parameter to update static parameter, that true by default
+ bool ToUpdateStaticParameters() const { return myToUpdateStaticParameters; }
+
+public:
+
+ //! Gets external files used in the last read or write process.
+ //! Processed only on multifile setting up
+ NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> GetExternalFiles() const
+ {
+ return myProcessedExtFiles;
+ }
+
+private:
+
+ //! Personizes work session with current format.
+ //! Creates new temporary session if current session is null
+ //! @param[in] theWS current work session
+ void personizeWS(Handle(XSControl_WorkSession)& theWS);
+
+ //! Initialize static variables
+ void initStatic(const Handle(DE_ConfigurationNode)& theNode);
- //! Initialize static variables
- void initStatic(const Handle(DE_ConfigurationNode)& theNode);
+ //! Initialize static variables
+ void setStatic(const STEPCAFControl_ConfigurationNode::STEPCAFControl_InternalSection theParameter);
- //! Initialize static variables
- void setStatic(const STEPCAFControl_ConfigurationNode::STEPCAFControl_InternalSection theParameter);
+ //! Reset used interface static variables
+ void resetStatic();
- //! Reset used interface static variables
- void resetStatic();
+private:
- STEPCAFControl_ConfigurationNode::STEPCAFControl_InternalSection myOldValues;
+ bool myToUpdateStaticParameters = true; //!< Flag to updating static parameters
+ STEPCAFControl_ConfigurationNode::STEPCAFControl_InternalSection myOldValues; //!< Container to save previous static parameters
+ NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> myProcessedExtFiles; //!< External files from the last operation
};
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 " <<
//=======================================================================
bool Vrml_Provider::Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument,
+ Handle(XSControl_WorkSession)& theWS,
const Message_ProgressRange& theProgress)
{
+ (void)theWS;
(void)theProgress;
if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(Vrml_ConfigurationNode)))
{
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)))
{
//=======================================================================
bool Vrml_Provider::Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape,
+ Handle(XSControl_WorkSession)& theWS,
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);
+ return Write(thePath, aDoc, theWS, theProgress);
}
//=======================================================================
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
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
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
+#include <XDEDRAW_Common.hxx>
+
+#include <DBRep.hxx>
+#include <DDF.hxx>
#include <DDocStd.hxx>
#include <DDocStd_DrawDocument.hxx>
#include <DE_ConfigurationContext.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_ProgressIndicator.hxx>
-#include <Message.hxx>
#include <IFSelect_SessionPilot.hxx>
-#include <IGESCAFControl_Reader.hxx>
-#include <IGESCAFControl_Writer.hxx>
-#include <IGESControl_Controller.hxx>
+#include <IGESCAFControl_Provider.hxx>
#include <Interface_Macros.hxx>
+#include <Interface_Static.hxx>
+#include <Message.hxx>
#include <OSD_OpenFile.hxx>
#include <OSD_Path.hxx>
+#include <STEPCAFControl_ConfigurationNode.hxx>
#include <STEPCAFControl_ExternFile.hxx>
-#include <STEPCAFControl_Reader.hxx>
-#include <STEPCAFControl_Writer.hxx>
-#include <STEPControl_Controller.hxx>
+#include <STEPCAFControl_Provider.hxx>
#include <TDF_Data.hxx>
+#include <TDF_Tool.hxx>
#include <TDocStd_Application.hxx>
#include <TDocStd_Document.hxx>
-#include <XDEDRAW_Common.hxx>
+#include <TopoDS_Shape.hxx>
+#include <UnitsAPI.hxx>
+#include <UnitsMethods.hxx>
+#include <Vrml_ConfigurationNode.hxx>
+#include <Vrml_Provider.hxx>
+#include <XCAFDoc_DocumentTool.hxx>
+#include <XCAFDoc_Editor.hxx>
+#include <XCAFDoc_ShapeTool.hxx>
#include <XSAlgo.hxx>
#include <XSAlgo_AlgoContainer.hxx>
#include <XSControl_WorkSession.hxx>
#include <XSDRAW.hxx>
#include <XSDRAW_Vars.hxx>
-#include <VrmlAPI_CafReader.hxx>
-#include <VrmlAPI_Writer.hxx>
-#include <DDF.hxx>
-#include <DBRep.hxx>
-#include <XCAFDoc_DocumentTool.hxx>
-#include <XCAFDoc_ShapeTool.hxx>
-#include <XCAFDoc_Editor.hxx>
-#include <TDF_Tool.hxx>
-#include <TopoDS_Shape.hxx>
-#include <Interface_Static.hxx>
-#include <UnitsAPI.hxx>
-#include <UnitsMethods.hxx>
-
-#include <stdio.h>
-
-//============================================================
-// Support for several models in DRAW
-//============================================================
-static NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> thedictws;
-
-//=======================================================================
-//function : parseCoordinateSystem
-//purpose : Parse RWMesh_CoordinateSystem enumeration.
-//=======================================================================
-static bool parseCoordinateSystem(const char* theArg,
- RWMesh_CoordinateSystem& theSystem)
+namespace
{
- TCollection_AsciiString aCSStr(theArg);
- aCSStr.LowerCase();
- if (aCSStr == "zup")
- {
- theSystem = RWMesh_CoordinateSystem_Zup;
+ //============================================================
+ // Support for several models in DRAW
+ //============================================================
+ static NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> thedictws;
+
+ //=======================================================================
+ //function : GetLengthUnit
+ //purpose :
+ //=======================================================================
+ Standard_Real getLengthUnit(const Handle(TDocStd_Document)& theDoc = nullptr)
+ {
+ if (!theDoc.IsNull())
+ {
+ Standard_Real aUnit = 1.;
+ if (XCAFDoc_DocumentTool::GetLengthUnit(theDoc, aUnit,
+ UnitsMethods_LengthUnit_Millimeter))
+ {
+ return aUnit;
+ }
+ }
+ XSAlgo::AlgoContainer()->PrepareForTransfer();
+ return UnitsMethods::GetCasCadeLengthUnit();
}
- else if (aCSStr == "yup")
+
+ //=======================================================================
+ //function : parseCoordinateSystem
+ //purpose : Parse RWMesh_CoordinateSystem enumeration.
+ //=======================================================================
+ static bool parseCoordinateSystem(const char* theArg,
+ RWMesh_CoordinateSystem& theSystem)
{
- theSystem = RWMesh_CoordinateSystem_Yup;
+ TCollection_AsciiString aCSStr(theArg);
+ aCSStr.LowerCase();
+ if (aCSStr == "zup")
+ {
+ theSystem = RWMesh_CoordinateSystem_Zup;
+ }
+ else if (aCSStr == "yup")
+ {
+ theSystem = RWMesh_CoordinateSystem_Yup;
+ }
+ else
+ {
+ return Standard_False;
+ }
+ return Standard_True;
}
- else
+
+ //=======================================================================
+ //function : SetCurrentWS
+ //purpose :
+ //=======================================================================
+ static Standard_Boolean ClearDicWS()
{
- return Standard_False;
+ thedictws.Clear();
+ return Standard_True;
}
- return Standard_True;
-}
-
-static Standard_Boolean ClearDicWS()
-{
- thedictws.Clear();
- return Standard_True;
-}
-
-static void AddWS(TCollection_AsciiString filename,
- const Handle(XSControl_WorkSession)& WS)
-{
- WS->SetVars(new XSDRAW_Vars); // support of DRAW variables
- thedictws.Bind(filename, WS);
-}
-
-static Standard_Boolean FillDicWS(NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& dicFile)
-{
- ClearDicWS();
- if (dicFile.IsEmpty())
+ //=======================================================================
+ //function : SetCurrentWS
+ //purpose :
+ //=======================================================================
+ static void AddWS(TCollection_AsciiString theFileName,
+ const Handle(XSControl_WorkSession)& theWS)
{
- return Standard_False;
+ theWS->SetVars(new XSDRAW_Vars); // support of DRAW variables
+ thedictws.Bind(theFileName, theWS);
}
- Handle(STEPCAFControl_ExternFile) EF;
- NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>::Iterator DicEFIt(dicFile);
- for (; DicEFIt.More(); DicEFIt.Next())
+
+ //=======================================================================
+ //function : SetCurrentWS
+ //purpose :
+ //=======================================================================
+ static Standard_Boolean FillDicWS(NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& theDicFile)
{
- TCollection_AsciiString filename = DicEFIt.Key();
- EF = DicEFIt.Value();
- AddWS(filename, EF->GetWS());
+ ClearDicWS();
+ if (theDicFile.IsEmpty())
+ {
+ return Standard_False;
+ }
+ Handle(STEPCAFControl_ExternFile) anEF;
+ NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>::Iterator aDicEFIt(theDicFile);
+ for (; aDicEFIt.More(); aDicEFIt.Next())
+ {
+ TCollection_AsciiString aFileName = aDicEFIt.Key();
+ anEF = aDicEFIt.Value();
+ AddWS(aFileName, anEF->GetWS());
+ }
+ return Standard_True;
}
- return Standard_True;
-}
-
-static Standard_Boolean SetCurrentWS(TCollection_AsciiString filename)
-{
- if (!thedictws.IsBound(filename)) return Standard_False;
- Handle(XSControl_WorkSession) CurrentWS =
- Handle(XSControl_WorkSession)::DownCast(thedictws.ChangeFind(filename));
- XSDRAW::Pilot()->SetSession(CurrentWS);
- return Standard_True;
+ //=======================================================================
+ //function : SetCurrentWS
+ //purpose :
+ //=======================================================================
+ static Standard_Boolean SetCurrentWS(TCollection_AsciiString theFileName)
+ {
+ if (!thedictws.IsBound(theFileName))
+ return Standard_False;
+ Handle(XSControl_WorkSession) CurrentWS =
+ Handle(XSControl_WorkSession)::DownCast(thedictws.ChangeFind(theFileName));
+ XSDRAW::Pilot()->SetSession(CurrentWS);
+ return Standard_True;
+ }
}
-
//=======================================================================
//function : SetCurWS
//purpose : Set current file if many files are read
//function : ReadIges
//purpose : Read IGES to DECAF document
//=======================================================================
-
-static Standard_Integer ReadIges(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer ReadIges(Draw_Interpretor& theDI,
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
{
- if (argc < 3)
+ if (theNbArgs < 3)
{
- di << "Use: " << argv[0] << " Doc filename [mode]: read IGES file to a document\n";
+ theDI << "Use: " << theArgVec[0] << " Doc filename [mode]: read IGES file to a document\n";
return 0;
}
-
- DeclareAndCast(IGESControl_Controller, ctl, XSDRAW::Controller());
- if (ctl.IsNull()) XSDRAW::SetNorm("IGES");
-
- TCollection_AsciiString fnom, rnom;
- Standard_Boolean modfic = XSDRAW::FileAndVar(argv[2], argv[1], "IGES", fnom, rnom);
- if (modfic) di << " File IGES to read : " << fnom.ToCString() << "\n";
- else di << " Model taken from the session : " << fnom.ToCString() << "\n";
- // di<<" -- Names of variables BREP-DRAW prefixed by : "<<rnom<<"\n";
-
- IGESCAFControl_Reader reader(XSDRAW::Session(), modfic);
+ Handle(IGESCAFControl_ConfigurationNode) aNode =
+ new IGESCAFControl_ConfigurationNode();
Standard_Integer onlyvisible = Interface_Static::IVal("read.iges.onlyvisible");
- reader.SetReadVisible(onlyvisible == 1);
-
- if (argc == 4)
+ aNode->InternalParameters.ReadOnlyVisible = onlyvisible == 1;
+ if (theNbArgs == 4)
{
- Standard_Boolean mode = Standard_True;
- for (Standard_Integer i = 0; argv[3][i]; i++)
- switch (argv[3][i])
+ Standard_Boolean aMode = Standard_True;
+ for (Standard_Integer i = 0; theArgVec[3][i]; i++)
+ switch (theArgVec[3][i])
{
- case '-': mode = Standard_False; break;
- case '+': mode = Standard_True; break;
- case 'c': reader.SetColorMode(mode); break;
- case 'n': reader.SetNameMode(mode); break;
- case 'l': reader.SetLayerMode(mode); break;
+ case '-': aMode = Standard_False; break;
+ case '+': aMode = Standard_True; break;
+ case 'c': aNode->InternalParameters.ReadColor = aMode; break;
+ case 'n': aNode->InternalParameters.ReadName = aMode; break;
+ case 'l': aNode->InternalParameters.ReadLayer = aMode; break;
}
}
-
- Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di);
- Message_ProgressScope aRootScope(aProgress->Start(), "IGES import", modfic ? 2 : 1);
-
- IFSelect_ReturnStatus readstat = IFSelect_RetVoid;
- if (modfic)
- {
- Message_ProgressScope aReadScope(aRootScope.Next(), "File reading", 1);
- aReadScope.Show();
- readstat = reader.ReadFile(fnom.ToCString());
- }
- else if (XSDRAW::Session()->NbStartingEntities() > 0)
- {
- readstat = IFSelect_RetDone;
- }
- if (readstat != IFSelect_RetDone)
- {
- if (modfic)
- {
- di << "Could not read file " << fnom.ToCString() << " , abandon\n";
- }
- else
- {
- di << "No model loaded\n";
- }
- return 1;
- }
-
- Handle(TDocStd_Document) doc;
- if (!DDocStd::GetDocument(argv[1], doc, Standard_False))
- {
- Handle(TDocStd_Application) A = DDocStd::GetApplication();
- A->NewDocument("BinXCAF", doc);
- TDataStd_Name::Set(doc->GetData()->Root(), argv[1]);
- Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc);
- Draw::Set(argv[1], DD);
- // di << "Document saved with name " << argv[1];
- }
- if (!reader.Transfer(doc, aRootScope.Next()))
+ Handle(TDocStd_Document) aDoc;
+ if (!DDocStd::GetDocument(theArgVec[1], aDoc, Standard_False))
{
- di << "Cannot read any relevant data from the IGES file\n";
+ Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
+ anApp->NewDocument("BinXCAF", aDoc);
+ TDataStd_Name::Set(aDoc->GetData()->Root(), theArgVec[1]);
+ Handle(DDocStd_DrawDocument) aDrawD = new DDocStd_DrawDocument(aDoc);
+ Draw::Set(theArgVec[1], aDrawD);
+ }
+ aNode->GlobalParameters.LengthUnit = getLengthUnit(aDoc);
+ Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI);
+ Handle(IGESCAFControl_Provider) aProvider =
+ new IGESCAFControl_Provider(aNode);
+ aProvider->SetToUpdateStaticParameters(false);
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ if (!aProvider->Read(theArgVec[2], aDoc, aWS, aProgress->Start()))
+ {
+ theDI << "Error: Can't read IGES file\n";
return 1;
}
-
- // Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc);
- // Draw::Set(argv[1],DD);
- di << "Document saved with name " << argv[1];
-
+ Message::SendInfo() << "Document saved with name " << theArgVec[1];
return 0;
}
//function : WriteIges
//purpose : Write DECAF document to IGES
//=======================================================================
-
-static Standard_Integer WriteIges(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+//=======================================================================
+static Standard_Integer WriteIges(Draw_Interpretor& theDI,
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
{
- if (argc < 3)
+ if (theNbArgs < 3)
{
- di << "Use: " << argv[0] << " Doc filename [mode]: write document to IGES file\n";
+ theDI << "Use: " << theArgVec[0] << " Doc filename [mode]: write document to IGES file\n";
return 0;
}
-
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if (Doc.IsNull())
+ Handle(IGESCAFControl_ConfigurationNode) aNode =
+ new IGESCAFControl_ConfigurationNode();
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument(theArgVec[1], aDoc);
+ if (aDoc.IsNull())
{
- di << argv[1] << " is not a document\n";
+ theDI << theArgVec[1] << " is not a document\n";
return 1;
}
-
- XSDRAW::SetNorm("IGES");
-
- TCollection_AsciiString fnom, rnom;
- const Standard_Boolean modfic = XSDRAW::FileAndVar(argv[2], argv[1], "IGES", fnom, rnom);
-
- // IGESControl_Writer ICW (Interface_Static::CVal("write.iges.unit"),
- // Interface_Static::IVal("write.iges.brep.mode"));
-
- Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di);
- Message_ProgressScope aRootScope(aProgress->Start(), "IGES export", modfic ? 2 : 1);
-
- IGESCAFControl_Writer writer(XSDRAW::Session(), Standard_True);
- if (argc == 4)
+ if (theNbArgs == 4)
{
- Standard_Boolean mode = Standard_True;
- for (Standard_Integer i = 0; argv[3][i]; i++)
- switch (argv[3][i])
+ Standard_Boolean aMode = Standard_True;
+ for (Standard_Integer i = 0; theArgVec[3][i]; i++)
+ switch (theArgVec[3][i])
{
- case '-': mode = Standard_False; break;
- case '+': mode = Standard_True; break;
- case 'c': writer.SetColorMode(mode); break;
- case 'n': writer.SetNameMode(mode); break;
- case 'l': writer.SetLayerMode(mode); break;
+ case '-': aMode = Standard_False; break;
+ case '+': aMode = Standard_True; break;
+ case 'c': aNode->InternalParameters.WriteColor = aMode; break;
+ case 'n': aNode->InternalParameters.WriteName = aMode; break;
+ case 'l': aNode->InternalParameters.WriteLayer = aMode; break;
}
}
- writer.Transfer(Doc, aRootScope.Next());
-
- if (modfic)
+ aNode->GlobalParameters.LengthUnit = getLengthUnit(aDoc);
+ Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI);
+ Handle(IGESCAFControl_Provider) aProvider =
+ new IGESCAFControl_Provider(aNode);
+ aProvider->SetToUpdateStaticParameters(false);
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ const TCollection_AsciiString aPath = theArgVec[2];
+ if (!aProvider->Write(aPath, aDoc, aWS, aProgress->Start()))
{
- Message_ProgressScope aWriteScope(aRootScope.Next(), "File writing", 1);
- aWriteScope.Show();
- di << "Writing IGES model to file " << argv[2] << "\n";
- if (writer.Write(argv[2]))
- {
- di << " Write OK\n";
- }
- else
- {
- di << " Write failed\n";
- }
- }
- else
- {
- di << "Document has been translated into the session";
+ theDI << "Error: Can't write IGES file\n";
+ return 1;
}
return 0;
}
//function : ReadStep
//purpose : Read STEP file to DECAF document
//=======================================================================
-static Standard_Integer ReadStep(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer ReadStep(Draw_Interpretor& theDI,
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
{
- DeclareAndCast(STEPControl_Controller, ctl, XSDRAW::Controller());
- if (ctl.IsNull())
- {
- XSDRAW::SetNorm ("STEP");
- }
-
Standard_CString aDocName = NULL;
TCollection_AsciiString aFilePath, aModeStr;
- bool toTestStream = false;
- for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
+ bool aToTestStream = false;
+ for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
- TCollection_AsciiString anArgCase(argv[anArgIter]);
+ TCollection_AsciiString anArgCase(theArgVec[anArgIter]);
anArgCase.LowerCase();
if (anArgCase == "-stream")
{
- toTestStream = true;
+ aToTestStream = true;
}
else if (aDocName == NULL)
{
- aDocName = argv[anArgIter];
+ aDocName = theArgVec[anArgIter];
}
else if (aFilePath.IsEmpty())
{
- aFilePath = argv[anArgIter];
+ aFilePath = theArgVec[anArgIter];
}
else if (aModeStr.IsEmpty())
{
- aModeStr = argv[anArgIter];
+ aModeStr = theArgVec[anArgIter];
}
else
{
- Message::SendFail() << "Syntax error at '" << argv[anArgIter] << "'";
+ theDI << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
-
- TCollection_AsciiString aFileName, anOldVarName;
- Standard_Boolean isFileMode = XSDRAW::FileAndVar (aFilePath.ToCString(), aDocName, "STEP", aFileName, anOldVarName);
- if (isFileMode) di << " File STEP to read : " << aFileName << "\n";
- else di << " Model taken from the session : " << aFileName << "\n";
- // di<<" -- Names of variables BREP-DRAW prefixed by : "<<rnom<<"\n";
-
- STEPCAFControl_Reader aReader (XSDRAW::Session(), isFileMode);
+ Handle(STEPCAFControl_ConfigurationNode) aNode =
+ new STEPCAFControl_ConfigurationNode();
if (!aModeStr.IsEmpty())
{
Standard_Boolean aMode = Standard_True;
- for (Standard_Integer i = 1; aModeStr.Value (i); ++i)
+ for (Standard_Integer i = 1; aModeStr.Value(i); ++i)
{
- switch (aModeStr.Value (i))
+ switch (aModeStr.Value(i))
{
- case '-' : aMode = Standard_False; break;
- case '+' : aMode = Standard_True; break;
- case 'c' : aReader.SetColorMode (aMode); break;
- case 'n' : aReader.SetNameMode (aMode); break;
- case 'l' : aReader.SetLayerMode (aMode); break;
- case 'v' : aReader.SetPropsMode (aMode); break;
+ case '-': aMode = Standard_False; break;
+ case '+': aMode = Standard_True; break;
+ case 'c': aNode->InternalParameters.WriteColor = aMode; break;
+ case 'n': aNode->InternalParameters.WriteName = aMode; break;
+ case 'l': aNode->InternalParameters.WriteLayer = aMode; break;
+ case 'v': aNode->InternalParameters.WriteProps = aMode; break;
default:
{
- Message::SendFail() << "Syntax error at '" << aModeStr << "'\n";
+ theDI << "Syntax error at '" << aModeStr << "'\n";
return 1;
}
}
}
}
-
- Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di);
- Message_ProgressScope aRootScope (aProgress->Start(), "STEP import", isFileMode ? 2 : 1);
-
- IFSelect_ReturnStatus aReadStat = IFSelect_RetVoid;
- if (isFileMode)
- {
- Message_ProgressScope aReadScope (aRootScope.Next(), "File reading", 1);
- aReadScope.Show();
- if (toTestStream)
- {
- std::ifstream aStream;
- OSD_OpenStream (aStream, aFileName.ToCString(), std::ios::in | std::ios::binary);
- TCollection_AsciiString aFolder, aFileNameShort;
- OSD_Path::FolderAndFileFromPath (aFileName, aFolder, aFileNameShort);
- aReadStat = aReader.ReadStream (aFileNameShort.ToCString(), aStream);
- }
- else
- {
- aReadStat = aReader.ReadFile (aFileName.ToCString());
- }
- }
- else if (XSDRAW::Session()->NbStartingEntities() > 0)
- {
- aReadStat = IFSelect_RetDone;
- }
- if (aReadStat != IFSelect_RetDone)
- {
- if (isFileMode)
- {
- di << "Could not read file " << aFileName << " , abandon\n";
- }
- else
- {
- di << "No model loaded\n";
- }
- return 1;
- }
-
Handle(TDocStd_Document) aDoc;
- if (!DDocStd::GetDocument (aDocName, aDoc, Standard_False))
+ if (!DDocStd::GetDocument(aDocName, aDoc, Standard_False))
{
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
anApp->NewDocument("BinXCAF", aDoc);
- TDataStd_Name::Set (aDoc->GetData()->Root(), aDocName);
- Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument (aDoc);
- Draw::Set (aDocName, aDrawDoc);
- // di << "Document saved with name " << aDocName;
+ TDataStd_Name::Set(aDoc->GetData()->Root(), aDocName);
+ Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument(aDoc);
+ Draw::Set(aDocName, aDrawDoc);
+ }
+ aNode->GlobalParameters.LengthUnit = getLengthUnit(aDoc);
+ Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI);
+ Handle(STEPCAFControl_Provider) aProvider =
+ new STEPCAFControl_Provider(aNode);
+ aProvider->SetToUpdateStaticParameters(false);
+ Standard_Boolean aReadStat = Standard_False;
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ if (aToTestStream)
+ {
+ std::ifstream aStream;
+ OSD_OpenStream(aStream, aFilePath.ToCString(), std::ios::in | std::ios::binary);
+ aReadStat =
+ aProvider->Read(aStream, aDoc, aFilePath, aWS, aProgress->Start());
+ }
+ else
+ {
+ aReadStat =
+ aProvider->Read(aFilePath, aDoc, aWS, aProgress->Start());
}
- if (!aReader.Transfer (aDoc, aRootScope.Next()))
+ if (!aReadStat)
{
- di << "Cannot read any relevant data from the STEP file\n";
+ theDI << "Cannot read any relevant data from the STEP file\n";
return 1;
}
+ Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument(aDoc);
+ Draw::Set(aDocName, aDrawDoc);
+ Message::SendInfo() << "Document saved with name " << aDocName;
- Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument (aDoc);
- Draw::Set (aDocName, aDrawDoc);
- di << "Document saved with name " << aDocName;
-
- NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> aDicFile = aReader.ExternFiles();
- FillDicWS (aDicFile);
- AddWS (aFileName, XSDRAW::Session());
+ NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> aDicFile = aProvider->GetExternalFiles();
+ FillDicWS(aDicFile);
+ AddWS(aFilePath, XSDRAW::Session());
return 0;
}
//function : WriteStep
//purpose : Write DECAF document to STEP
//=======================================================================
-static Standard_Integer WriteStep(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer WriteStep(Draw_Interpretor& theDI,
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
{
- DeclareAndCast(STEPControl_Controller,ctl,XSDRAW::Controller());
- if (ctl.IsNull())
- {
- XSDRAW::SetNorm ("STEP");
- }
- STEPCAFControl_Writer aWriter (XSDRAW::Session(), Standard_True);
-
Handle(TDocStd_Document) aDoc;
TCollection_AsciiString aDocName, aFilePath;
- STEPControl_StepModelType aMode = STEPControl_AsIs;
- bool hasModeArg = false, toTestStream = false;
- TCollection_AsciiString aMultiFilePrefix, aLabelName;
+ Handle(STEPCAFControl_ConfigurationNode) aNode =
+ new STEPCAFControl_ConfigurationNode();
+ bool aHasModeArg = false, aToTestStream = false;
TDF_Label aLabel;
- for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
+ for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
- TCollection_AsciiString anArgCase (argv[anArgIter]);
+ TCollection_AsciiString anArgCase(theArgVec[anArgIter]);
anArgCase.LowerCase();
if (anArgCase == "-stream")
{
- toTestStream = true;
+ aToTestStream = true;
}
else if (aDocName.IsEmpty())
{
- Standard_CString aDocNameStr = argv[anArgIter];
- DDocStd::GetDocument (aDocNameStr, aDoc);
+ Standard_CString aDocNameStr = theArgVec[anArgIter];
+ DDocStd::GetDocument(aDocNameStr, aDoc);
if (aDoc.IsNull())
{
- di << "Syntax error: '" << argv[anArgIter] << "' is not a document";
+ theDI << "Syntax error: '" << theArgVec[anArgIter] << "' is not a document\n";
return 1;
}
aDocName = aDocNameStr;
}
else if (aFilePath.IsEmpty())
{
- aFilePath = argv[anArgIter];
+ aFilePath = theArgVec[anArgIter];
}
- else if (!hasModeArg)
+ else if (!aHasModeArg)
{
- hasModeArg = true;
- switch (anArgCase.Value (1))
+ aHasModeArg = true;
+ Standard_Boolean aIsWriteType = Standard_True;
+ switch (anArgCase.Value(1))
{
case 'a':
- case '0': aMode = STEPControl_AsIs; break;
+ case '0': aNode->InternalParameters.WriteModelType = STEPControl_AsIs; break;
case 'f':
- case '1': aMode = STEPControl_FacetedBrep; break;
+ case '1': aNode->InternalParameters.WriteModelType = STEPControl_FacetedBrep; break;
case 's':
- case '2': aMode = STEPControl_ShellBasedSurfaceModel; break;
+ case '2': aNode->InternalParameters.WriteModelType = STEPControl_ShellBasedSurfaceModel; break;
case 'm':
- case '3': aMode = STEPControl_ManifoldSolidBrep; break;
+ case '3': aNode->InternalParameters.WriteModelType = STEPControl_ManifoldSolidBrep; break;
case 'w':
- case '4': aMode = STEPControl_GeometricCurveSet; break;
+ case '4': aNode->InternalParameters.WriteModelType = STEPControl_GeometricCurveSet; break;
default:
{
- di << "Syntax error: mode '" << argv[anArgIter] << "' is incorrect [give fsmw]";
- return 1;
+ aIsWriteType = Standard_False;
}
}
- Standard_Boolean wrmode = Standard_True;
+ Standard_Boolean aWrMode = Standard_True;
+ Standard_Boolean aIsAttrType = Standard_True;
for (Standard_Integer i = 1; i <= anArgCase.Length(); ++i)
{
- switch (anArgCase.Value (i))
+ switch (anArgCase.Value(i))
{
- case '-' : wrmode = Standard_False; break;
- case '+' : wrmode = Standard_True; break;
- case 'c' : aWriter.SetColorMode (wrmode); break;
- case 'n' : aWriter.SetNameMode (wrmode); break;
- case 'l' : aWriter.SetLayerMode (wrmode); break;
- case 'v' : aWriter.SetPropsMode (wrmode); break;
+ case '-': aWrMode = Standard_False; break;
+ case '+': aWrMode = Standard_True; break;
+ case 'c': aNode->InternalParameters.WriteColor = aWrMode; break;
+ case 'n': aNode->InternalParameters.WriteName = aWrMode; break;
+ case 'l': aNode->InternalParameters.WriteLayer = aWrMode; break;
+ case 'v': aNode->InternalParameters.WriteProps = aWrMode; break;
+ default:
+ {
+ aIsAttrType = Standard_False;
+ }
}
}
+ if (!aIsAttrType && !aIsWriteType)
+ {
+ theDI << "Syntax error: mode '" << anArgCase << "' is incorrect mode\n";
+ return 1;
+ }
}
- else if (aMultiFilePrefix.IsEmpty()
- && anArgCase.Search (":") == -1)
+ else if (aNode->InternalParameters.WriteMultiPrefix.IsEmpty()
+ && anArgCase.Search(":") == -1)
{
- aMultiFilePrefix = argv[anArgIter];
+ aNode->InternalParameters.WriteMultiPrefix = theArgVec[anArgIter];
}
else if (aLabel.IsNull())
{
- if (!DDF::FindLabel (aDoc->Main().Data(), argv[anArgIter], aLabel)
- || aLabel.IsNull())
- {
- di << "Syntax error: No label for entry '" << argv[anArgIter] << "'";
- return 1;
- }
- aLabelName = argv[anArgIter];
+ aNode->InternalParameters.WriteLabels.Append(theArgVec[anArgIter]);
}
else
{
- di << "Syntax error: unknown argument '" << argv[anArgIter] << "'";
+ theDI << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aFilePath.IsEmpty())
{
- di << "Syntax error: wrong number of arguments";
+ theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
-
- TCollection_AsciiString aFileName, anOldVarName;
- const Standard_Boolean isFileMode = XSDRAW::FileAndVar (aFilePath.ToCString(), aDocName.ToCString(), "STEP", aFileName, anOldVarName);
-
- Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di);
- Message_ProgressScope aRootScope (aProgress->Start(), "STEP export", isFileMode ? 2 : 1);
- if (!aLabel.IsNull())
- {
- di << "Translating label " << aLabelName << " of document " << aDocName << " to STEP\n";
- if (!aWriter.Transfer (aLabel, aMode,
- !aMultiFilePrefix.IsEmpty() ? aMultiFilePrefix.ToCString() : NULL,
- aRootScope.Next()))
- {
- di << "Error: the label of document cannot be translated or gives no result";
- return 1;
- }
- }
- else
- {
- di << "Translating document " << aDocName << " to STEP\n";
- if (!aWriter.Transfer (aDoc, aMode,
- !aMultiFilePrefix.IsEmpty() ? aMultiFilePrefix.ToCString() : NULL,
- aRootScope.Next()))
- {
- di << "Error: The document cannot be translated or gives no result\n";
- }
- }
-
- if (!isFileMode)
- {
- di << "Document has been translated into the session";
- return 0;
- }
-
- Message_ProgressScope aWriteScope (aRootScope.Next(), "File writing", 1);
- aWriteScope.Show();
- di << "Writing STEP file " << aFilePath << "\n";
-
- IFSelect_ReturnStatus aStat = IFSelect_RetVoid;
- if (toTestStream)
+ aNode->GlobalParameters.LengthUnit = getLengthUnit(aDoc);
+ Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI);
+ Handle(STEPCAFControl_Provider) aProvider =
+ new STEPCAFControl_Provider(aNode);
+ aProvider->SetToUpdateStaticParameters(false);
+ Standard_Boolean aReadStat = Standard_False;
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ if (aToTestStream)
{
std::ofstream aStream;
- OSD_OpenStream (aStream, aFilePath, std::ios::out | std::ios::binary);
- aStat = aWriter.WriteStream (aStream);
- aStream.close();
- if (!aStream.good()
- && aStat == IFSelect_RetDone)
- {
- aStat = IFSelect_RetFail;
- }
+ OSD_OpenStream(aStream, aFilePath, std::ios::out | std::ios::binary);
+ aReadStat =
+ aProvider->Write(aStream, aDoc, aWS, aProgress->Start());
}
else
{
- aStat = aWriter.Write (aFilePath.ToCString());
+ aReadStat =
+ aProvider->Write(aFilePath, aDoc, aWS, aProgress->Start());
}
-
- switch (aStat)
+ if (!aReadStat)
{
- case IFSelect_RetVoid:
- {
- di << "Error: no file written";
- break;
- }
- case IFSelect_RetDone:
- {
- di << "File " << aFilePath << " written\n";
-
- NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> aDicFile = aWriter.ExternFiles();
- FillDicWS (aDicFile);
- AddWS (aFilePath, XSDRAW::Session());
- break;
- }
- default:
- {
- di << "Error on writing file";
- break;
- }
+ theDI << "Cannot write any relevant data to the STEP file\n";
+ return 1;
}
+ NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> aDicFile = aProvider->GetExternalFiles();
+ FillDicWS(aDicFile);
+ AddWS(aFilePath, XSDRAW::Session());
return 0;
}
//purpose :
//=======================================================================
static Standard_Integer ReadVrml(Draw_Interpretor& theDI,
- Standard_Integer theArgc,
- const char** theArgv)
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
{
- if(theArgc < 3)
+ if (theNbArgs < 3)
{
- theDI.PrintHelp(theArgv[0]);
+ theDI.PrintHelp(theArgVec[0]);
return 1;
}
-
+ Handle(Vrml_ConfigurationNode) aNode =
+ new Vrml_ConfigurationNode();
Handle(TDocStd_Document) aDoc;
- Standard_Real aFileUnitFactor = 1.0;
- RWMesh_CoordinateSystem aFileCoordSys = RWMesh_CoordinateSystem_Yup, aSystemCoordSys = RWMesh_CoordinateSystem_Zup;
Standard_Boolean toUseExistingDoc = Standard_False;
- Standard_Boolean toFillIncomplete = Standard_True;
Standard_CString aDocName = NULL;
TCollection_AsciiString aFilePath;
-
- for(Standard_Integer anArgIt = 1; anArgIt < theArgc; anArgIt++)
+ aNode->GlobalParameters.LengthUnit = getLengthUnit(aDoc);
+ for (Standard_Integer anArgIt = 1; anArgIt < theNbArgs; anArgIt++)
{
- TCollection_AsciiString anArg(theArgv[anArgIt]);
+ TCollection_AsciiString anArg(theArgVec[anArgIt]);
anArg.LowerCase();
- if(anArgIt + 1 < theArgc && anArg == "-fileunit")
+ if (anArgIt + 1 < theNbArgs && anArg == "-fileunit")
{
- const TCollection_AsciiString aUnitStr(theArgv[++anArgIt]);
- aFileUnitFactor = UnitsAPI::AnyToSI(1.0, aUnitStr.ToCString());
- if (aFileUnitFactor <= 0.0)
+ const TCollection_AsciiString aUnitStr(theArgVec[++anArgIt]);
+ aNode->InternalParameters.ReadFileUnit = UnitsAPI::AnyToSI(1.0, aUnitStr.ToCString());
+ if (aNode->InternalParameters.ReadFileUnit <= 0.0)
{
- Message::SendFail() << "Error: wrong length unit '" << aUnitStr << "'";
+ theDI << "Error: wrong length unit '" << aUnitStr << "'\n";
return 1;
}
}
- else if (anArgIt + 1 < theArgc && anArg == "-filecoordsys")
+ else if (anArgIt + 1 < theNbArgs && anArg == "-filecoordsys")
{
- if (!parseCoordinateSystem(theArgv[++anArgIt], aFileCoordSys))
+ if (!parseCoordinateSystem(theArgVec[++anArgIt], aNode->InternalParameters.ReadFileCoordinateSys))
{
- Message::SendFail() << "Error: unknown coordinate system '" << theArgv[anArgIt] << "'";
+ theDI << "Error: unknown coordinate system '" << theArgVec[anArgIt] << "'\n";
return 1;
}
}
- else if (anArgIt + 1 < theArgc && anArg == "-systemcoordsys")
+ else if (anArgIt + 1 < theNbArgs && anArg == "-systemcoordsys")
{
- if (!parseCoordinateSystem(theArgv[++anArgIt], aSystemCoordSys))
+ if (!parseCoordinateSystem(theArgVec[++anArgIt], aNode->InternalParameters.ReadSystemCoordinateSys))
{
- Message::SendFail() << "Error: unknown coordinate system '" << theArgv[anArgIt] << "'";
+ theDI << "Error: unknown coordinate system '" << theArgVec[anArgIt] << "'\n";
return 1;
}
}
else if (anArg == "-fillincomplete")
{
- toFillIncomplete = true;
- if (anArgIt + 1 < theArgc && Draw::ParseOnOff(theArgv[anArgIt + 1], toFillIncomplete))
+ aNode->InternalParameters.ReadFillIncomplete = true;
+ if (anArgIt + 1 < theNbArgs &&
+ Draw::ParseOnOff(theArgVec[anArgIt + 1], aNode->InternalParameters.ReadFillIncomplete))
{
++anArgIt;
}
}
else if (aDocName == nullptr)
{
- aDocName = theArgv[anArgIt];
+ aDocName = theArgVec[anArgIt];
DDocStd::GetDocument(aDocName, aDoc, Standard_False);
}
- else if(aFilePath.IsEmpty())
+ else if (aFilePath.IsEmpty())
{
- aFilePath = theArgv[anArgIt];
+ aFilePath = theArgVec[anArgIt];
}
else
{
- Message::SendFail() << "Syntax error at '" << theArgv[anArgIt] << "'";
+ theDI << "Syntax error at '" << theArgVec[anArgIt] << "'\n";
return 1;
}
}
if (aFilePath.IsEmpty() || aDocName == nullptr)
{
- Message::SendFail() << "Syntax error: wrong number of arguments";
+ theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
-
+
if (aDoc.IsNull())
{
- if(toUseExistingDoc)
+ if (toUseExistingDoc)
{
- Message::SendFail() << "Error: document with name " << aDocName << " does not exist";
+ theDI << "Error: document with name " << aDocName << " does not exist\n";
return 1;
}
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
}
else if (!toUseExistingDoc)
{
- Message::SendFail() << "Error: document with name " << aDocName << " already exists\n";
+ theDI << "Error: document with name " << aDocName << " already exists\n";
return 1;
}
-
- Standard_Real aScaleFactor = 1.;
- if (!XCAFDoc_DocumentTool::GetLengthUnit(aDoc, aScaleFactor))
- {
- XSAlgo::AlgoContainer()->PrepareForTransfer();
- aScaleFactor = UnitsMethods::GetCasCadeLengthUnit();
- }
-
- VrmlAPI_CafReader aVrmlReader;
- aVrmlReader.SetDocument(aDoc);
- aVrmlReader.SetFileLengthUnit(aFileUnitFactor);
- aVrmlReader.SetSystemLengthUnit(aScaleFactor);
- aVrmlReader.SetFileCoordinateSystem(aFileCoordSys);
- aVrmlReader.SetSystemCoordinateSystem(aSystemCoordSys);
- aVrmlReader.SetFillIncompleteDocument(toFillIncomplete);
-
+ Handle(Vrml_Provider) aProvider =
+ new Vrml_Provider(aNode);
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
- if (!aVrmlReader.Perform(aFilePath, aProgress->Start()))
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ if (!aProvider->Read(aFilePath, aDoc, aWS, aProgress->Start()))
{
- if (aVrmlReader.ExtraStatus() != RWMesh_CafReaderStatusEx_Partial)
- {
- Message::SendFail() << "Error: file reading failed '" << aFilePath << "'";
- return 1;
- }
- Message::SendWarning() <<
- "Warning: file has been read paratially (due to unexpected EOF, syntax error, memory limit) " << aFilePath;
+ theDI << "Error: file reading failed '" << aFilePath << "'\n";
+ return 1;
}
-
TDataStd_Name::Set(aDoc->GetData()->Root(), aDocName);
Handle(DDocStd_DrawDocument) aDD = new DDocStd_DrawDocument(aDoc);
Draw::Set(aDocName, aDD);
-
return 0;
}
//function : WriteVrml
//purpose : Write DECAF document to Vrml
//=======================================================================
-
-static Standard_Integer WriteVrml(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer WriteVrml(Draw_Interpretor& theDI,
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
{
- if (argc < 3)
+ if (theNbArgs < 3)
{
- di << "Use: " << argv[0] << " Doc filename: write document to Vrml file\n";
+ theDI << "Use: " << theArgVec[0] << " Doc filename: write document to Vrml file\n";
return 0;
}
Handle(TDocStd_Document) aDoc;
- DDocStd::GetDocument(argv[1], aDoc);
+ DDocStd::GetDocument(theArgVec[1], aDoc);
if (aDoc.IsNull())
{
- di << argv[1] << " is not a document\n";
+ theDI << theArgVec[1] << " is not a document\n";
return 1;
}
- if (argc < 3 || argc > 5)
+ if (theNbArgs < 3 || theNbArgs > 5)
{
- di << "wrong number of parameters\n";
+ theDI << "wrong number of parameters\n";
return 0;
}
+ Handle(Vrml_ConfigurationNode) aNode =
+ new Vrml_ConfigurationNode();
+ aNode->GlobalParameters.LengthUnit = getLengthUnit(aDoc);
+ Handle(Vrml_Provider) aProvider =
+ new Vrml_Provider(aNode);
- VrmlAPI_Writer writer;
- writer.SetRepresentation(VrmlAPI_ShadedRepresentation);
- Standard_Real aScaleFactorM = 1.;
- if (!XCAFDoc_DocumentTool::GetLengthUnit(aDoc, aScaleFactorM))
- {
- XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
- aScaleFactorM = UnitsMethods::GetCasCadeLengthUnit(UnitsMethods_LengthUnit_Meter);
- }
- if (!writer.WriteDoc(aDoc, argv[2], aScaleFactorM))
+ Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ if (!aProvider->Write(theArgVec[2], aDoc, aWS, aProgress->Start()))
{
- di << "Error: File " << argv[2] << " was not written\n";
+ theDI << "Error: file writing failed '" << theArgVec[2] << "'\n";
+ return 1;
}
-
return 0;
}
//=======================================================================
//function : DumpConfiguration
-//purpose :
+//purpose :
//=======================================================================
static Standard_Integer DumpConfiguration(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
}
else if (!isHandleFormat && !isHandleVendors)
{
- Message::SendFail() << "Syntax error at argument '" << theArgVec[anArgIter] << "'\n";
+ theDI << "Syntax error at argument '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
Standard_Boolean aStat = Standard_True;
if (!aPath.IsEmpty())
{
- aStat = aConf->Save(aPath, aIsRecursive, aFormats ,aVendors);
+ aStat = aConf->Save(aPath, aIsRecursive, aFormats, aVendors);
}
else
{
//=======================================================================
//function : CompareConfiguration
-//purpose :
+//purpose :
//=======================================================================
static Standard_Integer CompareConfiguration(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
Handle(DE_ConfigurationContext) aResourceFirst = new DE_ConfigurationContext();
if (!aResourceFirst->Load(theArgVec[1]))
{
- Message::SendFail() << "Error: Can't load first configuration";
+ theDI << "Error: Can't load first configuration\n";
return 1;
}
Handle(DE_ConfigurationContext) aResourceSecond = new DE_ConfigurationContext();
if (!aResourceSecond->Load(theArgVec[2]))
{
- Message::SendFail() << "Error: Can't load second configuration";
+ theDI << "Error: Can't load second configuration\n";
return 1;
}
const DE_ResourceMap& aResourceMapFirst = aResourceFirst->GetInternalMap();
TCollection_AsciiString aMessage;
if (aResourceMapFirst.Extent() != aResourceMapSecond.Extent() || anDiffers > 0)
{
- Message::SendFail() << "Error: Configurations are not same : " << " Differs count : " << anDiffers << " Count of first's scopes : " << aResourceMapFirst.Extent()
- << " Count of second's scopes : " << aResourceMapSecond.Extent();
+ theDI << "Error: Configurations are not same : " << " Differs count : "
+ << anDiffers << " Count of first's scopes : " << aResourceMapFirst.Extent()
+ << " Count of second's scopes : " << aResourceMapSecond.Extent() << "\n";
return 1;
}
return 0;
//=======================================================================
//function : LoadConfiguration
-//purpose :
+//purpose :
//=======================================================================
static Standard_Integer LoadConfiguration(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
if (!(anArg == "-recursive") ||
!Draw::ParseOnOff(theArgVec[3], aIsRecursive))
{
- Message::SendFail() << "Syntax error at argument '" << theArgVec[3] << "'";
+ theDI << "Syntax error at argument '" << theArgVec[3] << "'\n";
return 1;
}
}
if (!aConf->Load(aString, aIsRecursive))
{
- Message::SendFail() << "Error: configuration is incorrect";
+ theDI << "Error: configuration is incorrect\n";
return 1;
}
return 0;
//=======================================================================
//function : ReadFile
-//purpose :
+//purpose :
//=======================================================================
static Standard_Integer ReadFile(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
{
aDocShapeName = theArgVec[anArgIter];
Standard_CString aNameVar = aDocShapeName.ToCString();
- if(!isNoDoc)
+ if (!isNoDoc)
{
DDocStd::GetDocument(aNameVar, aDoc, Standard_False);
}
}
else
{
- Message::SendFail() << "Syntax error at argument '" << theArgVec[anArgIter] << "'";
+ theDI << "Syntax error at argument '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aDocShapeName.IsEmpty() || aFilePath.IsEmpty())
{
- Message::SendFail() << "Syntax error: wrong number of arguments";
+ theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
if (aDoc.IsNull() && !isNoDoc)
if (aStat)
{
TopoDS_Shape aShape;
- aStat = isNoDoc ? aConf->Read(aFilePath, aShape) : aConf->Read(aFilePath, aDoc);
- if(isNoDoc && aStat)
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ aStat = isNoDoc ? aConf->Read(aFilePath, aShape, aWS) : aConf->Read(aFilePath, aDoc, aWS);
+ if (isNoDoc && aStat)
{
DBRep::Set(aDocShapeName.ToCString(), aShape);
}
//=======================================================================
//function : WriteFile
-//purpose :
+//purpose :
//=======================================================================
static Standard_Integer WriteFile(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
}
else
{
- Message::SendFail() << "Syntax error at argument '" << theArgVec[anArgIter] << "'";
+ theDI << "Syntax error at argument '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aDocShapeName.IsEmpty() || aFilePath.IsEmpty())
{
- Message::SendFail() << "Syntax error: wrong number of arguments";
+ theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
if (aDoc.IsNull() && !isNoDoc)
{
- Message::SendFail() << "Error: incorrect document";
+ theDI << "Error: incorrect document\n";
+ return 1;
}
Handle(DE_Wrapper) aConf = DE_Wrapper::GlobalWrapper()->Copy();
Standard_Boolean aStat = Standard_True;
{
aStat = aConf->Load(aConfString);
}
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (aStat)
{
- if(isNoDoc)
+ if (isNoDoc)
{
TopoDS_Shape aShape = DBRep::Get(aDocShapeName);
- if(aShape.IsNull())
+ if (aShape.IsNull())
{
- Message::SendFail() << "Error: incorrect shape";
+ theDI << "Error: incorrect shape " << aDocShapeName << "\n";
return 1;
}
- aStat = aConf->Write(aFilePath, aShape);
+ aStat = aConf->Write(aFilePath, aShape, aWS);
}
else
{
- aStat = aConf->Write(aFilePath, aDoc);
+ aStat = aConf->Write(aFilePath, aDoc, aWS);
}
}
if (!aStat)
#include <Quantity_HArray1OfColor.hxx>
#include <Quantity_NameOfColor.hxx>
#include <RWGltf_DracoParameters.hxx>
-#include <RWGltf_CafReader.hxx>
-#include <RWGltf_CafWriter.hxx>
+#include <RWGltf_Provider.hxx>
#include <RWMesh_FaceIterator.hxx>
-#include <RWStl.hxx>
-#include <RWObj.hxx>
-#include <RWObj_CafReader.hxx>
-#include <RWObj_CafWriter.hxx>
-#include <RWPly_CafWriter.hxx>
+#include <RWObj_ConfigurationNode.hxx>
+#include <RWObj_Provider.hxx>
+#include <RWPly_ConfigurationNode.hxx>
#include <RWPly_PlyWriterContext.hxx>
-#include <SelectMgr_SelectionManager.hxx>
-#include <Standard_ErrorHandler.hxx>
-#include <StdSelect_ViewerSelector3d.hxx>
-#include <StlAPI.hxx>
-#include <StlAPI_Writer.hxx>
+#include <RWPly_Provider.hxx>
+#include <RWStl.hxx>
+#include <RWStl_ConfigurationNode.hxx>
+#include <RWStl_Provider.hxx>
#include <TColgp_SequenceOfXYZ.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <UnitsMethods.hxx>
#include <V3d_View.hxx>
#include <ViewerTest.hxx>
-#include <VrmlAPI.hxx>
#include <VrmlAPI_Writer.hxx>
#include <VrmlData_DataMapOfShapeAppearance.hxx>
#include <VrmlData_Scene.hxx>
-#include <VrmlData_ShapeConvert.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFPrs_DocumentExplorer.hxx>
#include <XSDRAWSTLVRML_DataSource3D.hxx>
#include <XSDRAWSTLVRML_DrawableMesh.hxx>
-#ifndef _STDIO_H
-#include <stdio.h>
-#endif
-
-extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
- const Handle(AIS_InteractiveObject)& theAISObj,
- Standard_Boolean theReplaceIfExists = Standard_True);
+extern Standard_Boolean VDisplayAISObject(const TCollection_AsciiString& theName,
+ const Handle(AIS_InteractiveObject)& theAISObj,
+ Standard_Boolean theReplaceIfExists = Standard_True);
-//! Parse RWMesh_NameFormat enumeration.
-static bool parseNameFormat (const char* theArg,
- RWMesh_NameFormat& theFormat)
+namespace
{
- TCollection_AsciiString aName (theArg);
- aName.LowerCase();
- if (aName == "empty")
- {
- theFormat = RWMesh_NameFormat_Empty;
- }
- else if (aName == "product"
- || aName == "prod")
- {
- theFormat = RWMesh_NameFormat_Product;
- }
- else if (aName == "instance"
- || aName == "inst")
- {
- theFormat = RWMesh_NameFormat_Instance;
- }
- else if (aName == "instanceorproduct"
- || aName == "instance||product"
- || aName == "instance|product"
- || aName == "instorprod"
- || aName == "inst||prod"
- || aName == "inst|prod")
- {
- theFormat = RWMesh_NameFormat_InstanceOrProduct;
- }
- else if (aName == "productorinstance"
- || aName == "product||instance"
- || aName == "product|instance"
- || aName == "prodorinst"
- || aName == "prod||inst"
- || aName == "prod|inst")
+ //=======================================================================
+ //function : GetLengthUnit
+ //purpose :
+ //=======================================================================
+ Standard_Real getLengthUnit(const Handle(TDocStd_Document)& theDoc = nullptr)
{
- theFormat = RWMesh_NameFormat_ProductOrInstance;
- }
- else if (aName == "productandinstance"
- || aName == "prodandinst"
- || aName == "product&instance"
- || aName == "prod&inst")
- {
- theFormat = RWMesh_NameFormat_ProductAndInstance;
- }
- else if (aName == "productandinstanceandocaf"
- || aName == "verbose"
- || aName == "debug")
- {
- theFormat = RWMesh_NameFormat_ProductAndInstanceAndOcaf;
- }
- else
- {
- return false;
+ if (!theDoc.IsNull())
+ {
+ Standard_Real aUnit = 1.;
+ if (XCAFDoc_DocumentTool::GetLengthUnit(theDoc, aUnit,
+ UnitsMethods_LengthUnit_Millimeter))
+ {
+ return aUnit;
+ }
+ }
+ XSAlgo::AlgoContainer()->PrepareForTransfer();
+ return UnitsMethods::GetCasCadeLengthUnit();
}
- return true;
-}
-//! Parse RWMesh_CoordinateSystem enumeration.
-static bool parseCoordinateSystem (const char* theArg,
- RWMesh_CoordinateSystem& theSystem)
-{
- TCollection_AsciiString aCSStr (theArg);
- aCSStr.LowerCase();
- if (aCSStr == "zup")
- {
- theSystem = RWMesh_CoordinateSystem_Zup;
- }
- else if (aCSStr == "yup")
+ //=============================================================================
+ //function : parseNameFormat
+ //purpose : Parse RWMesh_NameFormat enumeration.
+ //=============================================================================
+ static bool parseNameFormat(const char* theArg,
+ RWMesh_NameFormat& theFormat)
{
- theSystem = RWMesh_CoordinateSystem_Yup;
+ TCollection_AsciiString aName(theArg);
+ aName.LowerCase();
+ if (aName == "empty")
+ {
+ theFormat = RWMesh_NameFormat_Empty;
+ }
+ else if (aName == "product"
+ || aName == "prod")
+ {
+ theFormat = RWMesh_NameFormat_Product;
+ }
+ else if (aName == "instance"
+ || aName == "inst")
+ {
+ theFormat = RWMesh_NameFormat_Instance;
+ }
+ else if (aName == "instanceorproduct"
+ || aName == "instance||product"
+ || aName == "instance|product"
+ || aName == "instorprod"
+ || aName == "inst||prod"
+ || aName == "inst|prod")
+ {
+ theFormat = RWMesh_NameFormat_InstanceOrProduct;
+ }
+ else if (aName == "productorinstance"
+ || aName == "product||instance"
+ || aName == "product|instance"
+ || aName == "prodorinst"
+ || aName == "prod||inst"
+ || aName == "prod|inst")
+ {
+ theFormat = RWMesh_NameFormat_ProductOrInstance;
+ }
+ else if (aName == "productandinstance"
+ || aName == "prodandinst"
+ || aName == "product&instance"
+ || aName == "prod&inst")
+ {
+ theFormat = RWMesh_NameFormat_ProductAndInstance;
+ }
+ else if (aName == "productandinstanceandocaf"
+ || aName == "verbose"
+ || aName == "debug")
+ {
+ theFormat = RWMesh_NameFormat_ProductAndInstanceAndOcaf;
+ }
+ else
+ {
+ return false;
+ }
+ return true;
}
- else
+
+ //=============================================================================
+ //function : parseCoordinateSystem
+ //purpose : Parse RWMesh_CoordinateSystem enumeration.
+ //=============================================================================
+ static bool parseCoordinateSystem(const char* theArg,
+ RWMesh_CoordinateSystem& theSystem)
{
- return Standard_False;
+ TCollection_AsciiString aCSStr(theArg);
+ aCSStr.LowerCase();
+ if (aCSStr == "zup")
+ {
+ theSystem = RWMesh_CoordinateSystem_Zup;
+ }
+ else if (aCSStr == "yup")
+ {
+ theSystem = RWMesh_CoordinateSystem_Yup;
+ }
+ else
+ {
+ return Standard_False;
+ }
+ return Standard_True;
}
- return Standard_True;
}
//=============================================================================
//function : ReadGltf
//purpose : Reads glTF file
//=============================================================================
-static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
- Standard_Integer theNbArgs,
- const char** theArgVec)
+static Standard_Integer ReadGltf(Draw_Interpretor& theDI,
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
{
TCollection_AsciiString aDestName, aFilePath;
+ Handle(RWGltf_ConfigurationNode) aNode =
+ new RWGltf_ConfigurationNode();
Standard_Boolean toUseExistingDoc = Standard_False;
- Standard_Boolean toListExternalFiles = Standard_False;
- Standard_Boolean isParallel = Standard_False;
- Standard_Boolean isDoublePrec = Standard_False;
- Standard_Boolean toSkipLateDataLoading = Standard_False;
- Standard_Boolean toKeepLateData = Standard_True;
- Standard_Boolean toPrintDebugInfo = Standard_False;
- Standard_Boolean toLoadAllScenes = Standard_False;
Standard_Boolean toPrintAssetInfo = Standard_False;
+ Standard_Boolean toListExternalFiles = Standard_False;
Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "readgltf");
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
- TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
+ TCollection_AsciiString anArgCase(theArgVec[anArgIter]);
anArgCase.LowerCase();
if (!isNoDoc
- && (anArgCase == "-nocreate"
- || anArgCase == "-nocreatedoc"))
+ && (anArgCase == "-nocreate"
+ || anArgCase == "-nocreatedoc"))
{
- toUseExistingDoc = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
+ toUseExistingDoc = Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-parallel")
{
- isParallel = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.ReadParallel =
+ Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-doubleprec"
- || anArgCase == "-doubleprecision"
- || anArgCase == "-singleprec"
- || anArgCase == "-singleprecision")
+ || anArgCase == "-doubleprecision"
+ || anArgCase == "-singleprec"
+ || anArgCase == "-singleprecision")
{
- isDoublePrec = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
- if (anArgCase.StartsWith ("-single"))
+ aNode->InternalParameters.ReadSinglePrecision =
+ !Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
+ if (anArgCase.StartsWith("-single"))
{
- isDoublePrec = !isDoublePrec;
+ aNode->InternalParameters.ReadSinglePrecision =
+ Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
}
else if (anArgCase == "-skiplateloading")
{
- toSkipLateDataLoading = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.ReadSkipLateDataLoading =
+ Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-keeplate")
{
- toKeepLateData = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.ReadKeepLateData =
+ Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-allscenes")
{
- toLoadAllScenes = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.ReadLoadAllScenes =
+ Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-toprintinfo"
- || anArgCase == "-toprintdebuginfo")
+ || anArgCase == "-toprintdebuginfo")
{
- toPrintDebugInfo = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.ReadPrintDebugMessages =
+ Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-listexternalfiles"
- || anArgCase == "-listexternals"
- || anArgCase == "-listexternal"
- || anArgCase == "-external"
- || anArgCase == "-externalfiles")
+ || anArgCase == "-listexternals"
+ || anArgCase == "-listexternal"
+ || anArgCase == "-external"
+ || anArgCase == "-externalfiles")
{
- toListExternalFiles = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
+ toListExternalFiles = Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-assetinfo"
- || anArgCase == "-metadata")
+ || anArgCase == "-metadata")
{
- toPrintAssetInfo = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
+ toPrintAssetInfo = Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (aDestName.IsEmpty())
{
}
else
{
- Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
+ theDI << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
- if (aFilePath.IsEmpty() && !aDestName.IsEmpty())
- {
- if (toListExternalFiles || toPrintAssetInfo)
- {
- std::swap (aFilePath, aDestName);
- }
- }
- if (aFilePath.IsEmpty())
+ if (aFilePath.IsEmpty() || aDestName.IsEmpty())
{
- Message::SendFail() << "Syntax error: wrong number of arguments";
+ theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
- Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
+ Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
Handle(TDocStd_Document) aDoc;
if (!aDestName.IsEmpty()
- && !isNoDoc)
+ && !isNoDoc)
{
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
Standard_CString aNameVar = aDestName.ToCString();
- DDocStd::GetDocument (aNameVar, aDoc, Standard_False);
+ DDocStd::GetDocument(aNameVar, aDoc, Standard_False);
if (aDoc.IsNull())
{
if (toUseExistingDoc)
{
- Message::SendFail() << "Error: document with name " << aDestName << " does not exist";
+ theDI << "Error: document with name " << aDestName << " does not exist\n";
return 1;
}
- anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
+ anApp->NewDocument(TCollection_ExtendedString("BinXCAF"), aDoc);
}
else if (!toUseExistingDoc)
{
- Message::SendFail() << "Error: document with name " << aDestName << " already exists";
+ theDI << "Error: document with name " << aDestName << " already exists\n";
return 1;
}
}
- Standard_Real aScaleFactorM = 1.;
- if (!XCAFDoc_DocumentTool::GetLengthUnit(aDoc, aScaleFactorM, UnitsMethods_LengthUnit_Meter))
- {
- XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
- aScaleFactorM = UnitsMethods::GetCasCadeLengthUnit(UnitsMethods_LengthUnit_Meter);
- }
-
- RWGltf_CafReader aReader;
- aReader.SetSystemLengthUnit (aScaleFactorM);
- aReader.SetSystemCoordinateSystem (RWMesh_CoordinateSystem_Zup);
- aReader.SetDocument (aDoc);
- aReader.SetParallel (isParallel);
- aReader.SetDoublePrecision (isDoublePrec);
- aReader.SetToSkipLateDataLoading (toSkipLateDataLoading);
- aReader.SetToKeepLateData (toKeepLateData);
- aReader.SetToPrintDebugMessages (toPrintDebugInfo);
- aReader.SetLoadAllScenes (toLoadAllScenes);
- if (aDestName.IsEmpty())
+ aNode->GlobalParameters.LengthUnit = getLengthUnit(aDoc);
+ Handle(RWGltf_Provider) aProvider =
+ new RWGltf_Provider(aNode);
+ Standard_Boolean aReadStat = Standard_False;
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ if (isNoDoc)
{
- aReader.ProbeHeader (aFilePath);
+ TopoDS_Shape aResShape;
+ aReadStat = aProvider->Read(aFilePath, aResShape, aWS, aProgress->Start());
+ if (aReadStat)
+ {
+ DBRep::Set(aDestName.ToCString(), aResShape);
+ }
}
else
{
- aReader.Perform (aFilePath, aProgress->Start());
- if (isNoDoc)
- {
- DBRep::Set (aDestName.ToCString(), aReader.SingleShape());
- }
- else
+ aReadStat = aProvider->Read(aFilePath, aDoc, aWS, aProgress->Start());
+ if (aReadStat)
{
- Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument (aDoc);
- TDataStd_Name::Set (aDoc->GetData()->Root(), aDestName);
- Draw::Set (aDestName.ToCString(), aDrawDoc);
+ Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument(aDoc);
+ TDataStd_Name::Set(aDoc->GetData()->Root(), aDestName);
+ Draw::Set(aDestName.ToCString(), aDrawDoc);
}
}
-
+ if (!aReadStat)
+ {
+ theDI << "Cannot read any relevant data from the GLTF file\n";
+ return 1;
+ }
bool isFirstLine = true;
if (toPrintAssetInfo)
{
- for (TColStd_IndexedDataMapOfStringString::Iterator aKeyIter (aReader.Metadata()); aKeyIter.More(); aKeyIter.Next())
+ for (TColStd_IndexedDataMapOfStringString::Iterator aKeyIter(aProvider->GetMetadata()); aKeyIter.More(); aKeyIter.Next())
{
if (!isFirstLine)
{
{
theDI << "\n";
}
- for (NCollection_IndexedMap<TCollection_AsciiString>::Iterator aFileIter (aReader.ExternalFiles()); aFileIter.More(); aFileIter.Next())
+ for (NCollection_IndexedMap<TCollection_AsciiString>::Iterator aFileIter(aProvider->GetExternalFiles()); aFileIter.More(); aFileIter.Next())
{
theDI << "\"" << aFileIter.Value() << "\" ";
}
}
-
return 0;
}
//function : WriteGltf
//purpose : Writes glTF file
//=============================================================================
-static Standard_Integer WriteGltf (Draw_Interpretor& theDI,
- Standard_Integer theNbArgs,
- const char** theArgVec)
+static Standard_Integer WriteGltf(Draw_Interpretor& theDI,
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
{
TCollection_AsciiString aGltfFilePath;
Handle(TDocStd_Document) aDoc;
+ TopoDS_Shape aShape;
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
- TColStd_IndexedDataMapOfStringString aFileInfo;
- RWGltf_WriterTrsfFormat aTrsfFormat = RWGltf_WriterTrsfFormat_Compact;
- RWMesh_CoordinateSystem aSystemCoordSys = RWMesh_CoordinateSystem_Zup;
- bool toForceUVExport = false, toEmbedTexturesInGlb = true;
- bool toMergeFaces = false, toSplitIndices16 = false;
- bool isParallel = false;
- RWMesh_NameFormat aNodeNameFormat = RWMesh_NameFormat_InstanceOrProduct;
- RWMesh_NameFormat aMeshNameFormat = RWMesh_NameFormat_Product;
- RWGltf_DracoParameters aDracoParameters;
+ Handle(RWGltf_ConfigurationNode) aNode =
+ new RWGltf_ConfigurationNode();
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
- TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
+ TCollection_AsciiString anArgCase(theArgVec[anArgIter]);
anArgCase.LowerCase();
if (anArgCase == "-comments"
- && anArgIter + 1 < theNbArgs)
+ && anArgIter + 1 < theNbArgs)
{
- aFileInfo.Add ("Comments", theArgVec[++anArgIter]);
+ aNode->InternalParameters.WriteComment = theArgVec[++anArgIter];
}
else if (anArgCase == "-author"
- && anArgIter + 1 < theNbArgs)
+ && anArgIter + 1 < theNbArgs)
{
- aFileInfo.Add ("Author", theArgVec[++anArgIter]);
+ aNode->InternalParameters.WriteAuthor = theArgVec[++anArgIter];
}
else if (anArgCase == "-forceuvexport"
- || anArgCase == "-forceuv")
+ || anArgCase == "-forceuv")
{
- toForceUVExport = true;
+ aNode->InternalParameters.WriteForcedUVExport = true;
if (anArgIter + 1 < theNbArgs
- && Draw::ParseOnOff (theArgVec[anArgIter + 1], toForceUVExport))
+ && Draw::ParseOnOff(theArgVec[anArgIter + 1], aNode->InternalParameters.WriteForcedUVExport))
{
++anArgIter;
}
}
else if (anArgCase == "-mergefaces")
{
- toMergeFaces = true;
+ aNode->InternalParameters.WriteMergeFaces = true;
if (anArgIter + 1 < theNbArgs
- && Draw::ParseOnOff (theArgVec[anArgIter + 1], toMergeFaces))
+ && Draw::ParseOnOff(theArgVec[anArgIter + 1], aNode->InternalParameters.WriteMergeFaces))
{
++anArgIter;
}
}
else if (anArgCase == "-splitindices16"
- || anArgCase == "-splitindexes16"
- || anArgCase == "-splitindices"
- || anArgCase == "-splitindexes"
- || anArgCase == "-splitind")
+ || anArgCase == "-splitindexes16"
+ || anArgCase == "-splitindices"
+ || anArgCase == "-splitindexes"
+ || anArgCase == "-splitind")
{
- toSplitIndices16 = true;
+ aNode->InternalParameters.WriteSplitIndices16 = true;
if (anArgIter + 1 < theNbArgs
- && Draw::ParseOnOff (theArgVec[anArgIter + 1], toSplitIndices16))
+ && Draw::ParseOnOff(theArgVec[anArgIter + 1], aNode->InternalParameters.WriteSplitIndices16))
{
++anArgIter;
}
}
else if (anArgIter + 1 < theNbArgs
- && (anArgCase == "-systemcoordinatesystem"
- || anArgCase == "-systemcoordsystem"
- || anArgCase == "-systemcoordsys"
- || anArgCase == "-syscoordsys"))
+ && (anArgCase == "-systemcoordinatesystem"
+ || anArgCase == "-systemcoordsystem"
+ || anArgCase == "-systemcoordsys"
+ || anArgCase == "-syscoordsys"))
{
- if (!parseCoordinateSystem (theArgVec[++anArgIter], aSystemCoordSys))
+ if (!parseCoordinateSystem(theArgVec[++anArgIter], aNode->InternalParameters.SystemCS))
{
- Message::SendFail() << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'";
+ theDI << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
else if (anArgCase == "-trsfformat"
- && anArgIter + 1 < theNbArgs)
+ && anArgIter + 1 < theNbArgs)
{
- TCollection_AsciiString aTrsfStr (theArgVec[++anArgIter]);
+ TCollection_AsciiString aTrsfStr(theArgVec[++anArgIter]);
aTrsfStr.LowerCase();
if (aTrsfStr == "compact")
{
- aTrsfFormat = RWGltf_WriterTrsfFormat_Compact;
+ aNode->InternalParameters.WriteTrsfFormat = RWGltf_WriterTrsfFormat_Compact;
}
else if (aTrsfStr == "mat4")
{
- aTrsfFormat = RWGltf_WriterTrsfFormat_Mat4;
+ aNode->InternalParameters.WriteTrsfFormat = RWGltf_WriterTrsfFormat_Mat4;
}
else if (aTrsfStr == "trs")
{
- aTrsfFormat = RWGltf_WriterTrsfFormat_TRS;
+ aNode->InternalParameters.WriteTrsfFormat = RWGltf_WriterTrsfFormat_TRS;
}
else
{
- Message::SendFail() << "Syntax error at '" << anArgCase << "'";
+ theDI << "Syntax error at '" << anArgCase << "'\n";
return 1;
}
}
else if (anArgCase == "-nodenameformat"
- || anArgCase == "-nodename")
+ || anArgCase == "-nodename")
{
++anArgIter;
if (anArgIter >= theNbArgs
- || !parseNameFormat (theArgVec[anArgIter], aNodeNameFormat))
+ || !parseNameFormat(theArgVec[anArgIter], aNode->InternalParameters.WriteNodeNameFormat))
{
- Message::SendFail() << "Syntax error at '" << anArgCase << "'";
+ theDI << "Syntax error at '" << anArgCase << "'\n";
return 1;
}
}
else if (anArgCase == "-meshnameformat"
- || anArgCase == "-meshname")
+ || anArgCase == "-meshname")
{
++anArgIter;
if (anArgIter >= theNbArgs
- || !parseNameFormat (theArgVec[anArgIter], aMeshNameFormat))
+ || !parseNameFormat(theArgVec[anArgIter], aNode->InternalParameters.WriteMeshNameFormat))
{
- Message::SendFail() << "Syntax error at '" << anArgCase << "'";
+ theDI << "Syntax error at '" << anArgCase << "'\n";
return 1;
}
}
- else if (aDoc.IsNull())
+ else if (aDoc.IsNull() && aShape.IsNull())
{
Standard_CString aNameVar = theArgVec[anArgIter];
- DDocStd::GetDocument (aNameVar, aDoc, false);
+ DDocStd::GetDocument(aNameVar, aDoc, false);
if (aDoc.IsNull())
{
- TopoDS_Shape aShape = DBRep::Get (aNameVar);
+ aShape = DBRep::Get(aNameVar);
if (aShape.IsNull())
{
- Message::SendFail() << "Syntax error: '" << aNameVar << "' is not a shape nor document";
+ theDI << "Syntax error: '" << aNameVar << "' is not a shape nor document\n";
return 1;
}
-
- anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
- Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
- // auto-naming doesn't generate meaningful instance names
- //aShapeTool->SetAutoNaming (false);
- aNodeNameFormat = RWMesh_NameFormat_Product;
- aShapeTool->AddShape (aShape);
+ aNode->InternalParameters.WriteNodeNameFormat = RWMesh_NameFormat_Product;
}
}
else if (aGltfFilePath.IsEmpty())
}
else if (anArgCase == "-texturesSeparate")
{
- toEmbedTexturesInGlb = false;
+ aNode->InternalParameters.WriteEmbedTexturesInGlb = false;
}
else if (anArgCase == "-draco")
{
- aDracoParameters.DracoCompression = Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.WriteDracoParameters.DracoCompression =
+ Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-compressionlevel" && (anArgIter + 1) < theNbArgs
- && Draw::ParseInteger(theArgVec[anArgIter + 1], aDracoParameters.CompressionLevel))
+ && Draw::ParseInteger(theArgVec[anArgIter + 1],
+ aNode->InternalParameters.WriteDracoParameters.CompressionLevel))
{
++anArgIter;
}
else if (anArgCase == "-quantizepositionbits" && (anArgIter + 1) < theNbArgs
- && Draw::ParseInteger(theArgVec[anArgIter + 1], aDracoParameters.QuantizePositionBits))
+ && Draw::ParseInteger(theArgVec[anArgIter + 1],
+ aNode->InternalParameters.WriteDracoParameters.QuantizePositionBits))
{
++anArgIter;
}
else if (anArgCase == "-quantizenormalbits" && (anArgIter + 1) < theNbArgs
- && Draw::ParseInteger(theArgVec[anArgIter + 1], aDracoParameters.QuantizeNormalBits))
+ && Draw::ParseInteger(theArgVec[anArgIter + 1],
+ aNode->InternalParameters.WriteDracoParameters.QuantizeNormalBits))
{
++anArgIter;
}
else if (anArgCase == "-quantizetexcoordbits" && (anArgIter + 1) < theNbArgs
- && Draw::ParseInteger(theArgVec[anArgIter + 1], aDracoParameters.QuantizeTexcoordBits))
+ && Draw::ParseInteger(theArgVec[anArgIter + 1],
+ aNode->InternalParameters.WriteDracoParameters.QuantizeTexcoordBits))
{
++anArgIter;
}
else if (anArgCase == "-quantizecolorbits" && (anArgIter + 1) < theNbArgs
- && Draw::ParseInteger(theArgVec[anArgIter + 1], aDracoParameters.QuantizeColorBits))
+ && Draw::ParseInteger(theArgVec[anArgIter + 1],
+ aNode->InternalParameters.WriteDracoParameters.QuantizeColorBits))
{
++anArgIter;
}
else if (anArgCase == "-quantizegenericbits" && (anArgIter + 1) < theNbArgs
- && Draw::ParseInteger(theArgVec[anArgIter + 1], aDracoParameters.QuantizeGenericBits))
+ && Draw::ParseInteger(theArgVec[anArgIter + 1],
+ aNode->InternalParameters.WriteDracoParameters.QuantizeGenericBits))
{
++anArgIter;
}
else if (anArgCase == "-unifiedquantization")
{
- aDracoParameters.UnifiedQuantization = Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.WriteDracoParameters.UnifiedQuantization =
+ Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-parallel")
{
- isParallel = Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.WriteParallel =
+ Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else
{
- Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
+ theDI << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aGltfFilePath.IsEmpty())
{
- Message::SendFail() << "Syntax error: wrong number of arguments";
+ theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
- Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
+ Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
TCollection_AsciiString anExt = aGltfFilePath;
anExt.LowerCase();
- Standard_Real aScaleFactorM = 1.;
- if (!XCAFDoc_DocumentTool::GetLengthUnit(aDoc, aScaleFactorM, UnitsMethods_LengthUnit_Meter))
- {
- XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
- aScaleFactorM = UnitsMethods::GetCasCadeLengthUnit(UnitsMethods_LengthUnit_Meter);
- }
-
- RWGltf_CafWriter aWriter (aGltfFilePath, anExt.EndsWith (".glb"));
- aWriter.SetTransformationFormat (aTrsfFormat);
- aWriter.SetNodeNameFormat (aNodeNameFormat);
- aWriter.SetMeshNameFormat (aMeshNameFormat);
- aWriter.SetForcedUVExport (toForceUVExport);
- aWriter.SetToEmbedTexturesInGlb (toEmbedTexturesInGlb);
- aWriter.SetMergeFaces (toMergeFaces);
- aWriter.SetSplitIndices16 (toSplitIndices16);
- aWriter.SetParallel(isParallel);
- aWriter.SetCompressionParameters(aDracoParameters);
- aWriter.ChangeCoordinateSystemConverter().SetInputLengthUnit (aScaleFactorM);
- aWriter.ChangeCoordinateSystemConverter().SetInputCoordinateSystem (aSystemCoordSys);
- aWriter.Perform (aDoc, aFileInfo, aProgress->Start());
+ aNode->GlobalParameters.LengthUnit = getLengthUnit(aDoc);
+ Handle(RWGltf_Provider) aProvider =
+ new RWGltf_Provider(aNode);
+ Standard_Boolean aWriteStat = Standard_False;
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ if (!aDoc.IsNull())
+ {
+ aWriteStat = aProvider->Write(aGltfFilePath, aDoc, aWS, aProgress->Start());
+ }
+ else if (!aShape.IsNull())
+ {
+ aWriteStat = aProvider->Write(aGltfFilePath, aShape, aWS, aProgress->Start());
+ }
+ if (!aWriteStat)
+ {
+ theDI << "Cannot write any relevant data to the GLTF file\n";
+ return 1;
+ }
return 0;
}
-static Standard_Integer writestl
-(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+//=============================================================================
+//function : writestl
+//purpose :
+//=============================================================================
+static Standard_Integer writestl(Draw_Interpretor& theDI,
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
{
- if (argc < 3 || argc > 4) {
- di << "Use: " << argv[0]
- << " shape file [ascii/binary (0/1) : 1 by default]\n";
- } else {
- TopoDS_Shape aShape = DBRep::Get(argv[1]);
- Standard_Boolean isASCIIMode = Standard_False;
- if (argc == 4) {
- isASCIIMode = (Draw::Atoi(argv[3]) == 0);
- }
- StlAPI_Writer aWriter;
- aWriter.ASCIIMode() = isASCIIMode;
- Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di);
- Standard_Boolean isOK = aWriter.Write (aShape, argv[2], aProgress->Start());
- if (!isOK)
- di << "** Error **: Mesh writing has been failed.\n";
+ if (theNbArgs < 3 || theNbArgs > 4)
+ {
+ theDI << "Use: " << theArgVec[0]
+ << " shape file [ascii/binary (0/1) : 1 by default]\n";
+ return 1;
+ }
+ TopoDS_Shape aShape = DBRep::Get(theArgVec[1]);
+ Standard_Boolean isASCIIMode = Standard_False;
+ if (theNbArgs == 4)
+ {
+ isASCIIMode = (Draw::Atoi(theArgVec[3]) == 0);
+ }
+ Handle(RWStl_ConfigurationNode) aNode = new RWStl_ConfigurationNode();
+ aNode->GlobalParameters.LengthUnit = getLengthUnit();
+ Handle(RWStl_Provider) aProvider = new RWStl_Provider(aNode);
+ aNode->InternalParameters.WriteAscii = isASCIIMode;
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI);
+ if (!aProvider->Write(theArgVec[2], aShape, aWS, aProgress->Start()))
+ {
+ theDI << "Error: Mesh writing has been failed.\n";
}
return 0;
}
const char** theArgv)
{
TCollection_AsciiString aShapeName, aFilePath;
- bool toCreateCompOfTris = false;
- bool anIsMulti = false;
- double aMergeAngle = M_PI / 2.0;
+ Handle(RWStl_ConfigurationNode) aNode = new RWStl_ConfigurationNode();
+ aNode->GlobalParameters.LengthUnit = getLengthUnit();
for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
{
- TCollection_AsciiString anArg (theArgv[anArgIter]);
+ TCollection_AsciiString anArg(theArgv[anArgIter]);
anArg.LowerCase();
if (aShapeName.IsEmpty())
{
}
else if (anArg == "-brep")
{
- toCreateCompOfTris = true;
+ Standard_Boolean toCreateCompOfTris = Standard_True;
if (anArgIter + 1 < theArgc
- && Draw::ParseOnOff (theArgv[anArgIter + 1], toCreateCompOfTris))
+ && Draw::ParseOnOff(theArgv[anArgIter + 1], toCreateCompOfTris))
{
++anArgIter;
}
+ if (toCreateCompOfTris)
+ {
+ aNode->InternalParameters.ReadShapeType =
+ RWStl_ConfigurationNode::ReadMode_ShapeType_CompShape;
+ }
}
else if (anArg == "-multi")
{
- anIsMulti = true;
+ Standard_Boolean anIsMulti = Standard_True;
if (anArgIter + 1 < theArgc
- && Draw::ParseOnOff (theArgv[anArgIter + 1], anIsMulti))
+ && Draw::ParseOnOff(theArgv[anArgIter + 1], anIsMulti))
{
++anArgIter;
}
+ if (anIsMulti)
+ {
+ aNode->InternalParameters.ReadShapeType =
+ RWStl_ConfigurationNode::ReadMode_ShapeType_MultiMesh;
+ }
}
else if (anArg == "-mergeangle"
- || anArg == "-smoothangle"
- || anArg == "-nomergeangle"
- || anArg == "-nosmoothangle")
+ || anArg == "-smoothangle"
+ || anArg == "-nomergeangle"
+ || anArg == "-nosmoothangle")
{
- if (anArg.StartsWith ("-no"))
+ if (anArg.StartsWith("-no"))
{
- aMergeAngle = M_PI / 2.0;
+ aNode->InternalParameters.ReadMergeAngle = M_PI / 2.0;
}
else
{
- aMergeAngle = M_PI / 4.0;
+ aNode->InternalParameters.ReadMergeAngle = M_PI / 4.0;
if (anArgIter + 1 < theArgc
- && Draw::ParseReal (theArgv[anArgIter + 1], aMergeAngle))
+ && Draw::ParseReal(theArgv[anArgIter + 1], aNode->InternalParameters.ReadMergeAngle))
{
- if (aMergeAngle < 0.0 || aMergeAngle > 90.0)
+ if (aNode->InternalParameters.ReadMergeAngle < 0.0 ||
+ aNode->InternalParameters.ReadMergeAngle > 90.0)
{
theDI << "Syntax error: angle should be within [0,90] range";
return 1;
}
-
++anArgIter;
- aMergeAngle = aMergeAngle * M_PI / 180.0;
}
}
}
else
{
- Message::SendFail() << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'";
+ theDI << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
return 1;
}
}
if (aFilePath.IsEmpty())
{
- Message::SendFail() << "Syntax error: not enough arguments";
+ theDI << "Syntax error: not enough arguments\n";
return 1;
}
-
+ Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
+ Handle(RWStl_Provider) aProvider = new RWStl_Provider(aNode);
TopoDS_Shape aShape;
- if (!toCreateCompOfTris)
- {
- Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI,1);
- if(anIsMulti)
- {
- NCollection_Sequence<Handle(Poly_Triangulation)> aTriangList;
- // Read STL file to the triangulation list.
- RWStl::ReadFile(aFilePath.ToCString(),aMergeAngle,aTriangList,aProgress->Start());
- BRep_Builder aB;
- TopoDS_Face aFace;
- if (aTriangList.Size() == 1)
- {
- aB.MakeFace (aFace);
- aB.UpdateFace (aFace,aTriangList.First());
- aShape = aFace;
- }
- else
- {
- TopoDS_Compound aCmp;
- aB.MakeCompound (aCmp);
-
- NCollection_Sequence<Handle(Poly_Triangulation)>::Iterator anIt (aTriangList);
- for (; anIt.More(); anIt.Next())
- {
- aB.MakeFace (aFace);
- aB.UpdateFace (aFace,anIt.Value());
- aB.Add (aCmp,aFace);
- }
- aShape = aCmp;
- }
- }
- else
- {
- // Read STL file to the triangulation.
- Handle(Poly_Triangulation) aTriangulation = RWStl::ReadFile (aFilePath.ToCString(),aMergeAngle,aProgress->Start());
-
- TopoDS_Face aFace;
- BRep_Builder aB;
- aB.MakeFace (aFace);
- aB.UpdateFace (aFace,aTriangulation);
- aShape = aFace;
- }
- }
- else
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ if (!aProvider->Read(aFilePath, aShape, aWS, aProgress->Start()))
{
- Standard_DISABLE_DEPRECATION_WARNINGS
- StlAPI::Read(aShape, aFilePath.ToCString());
- Standard_ENABLE_DEPRECATION_WARNINGS
+ theDI << "Cannot read any relevant data from the STL file\n";
+ return 1;
}
- DBRep::Set (aShapeName.ToCString(), aShape);
+ DBRep::Set(aShapeName.ToCString(), aShape);
return 0;
}
//function : ReadObj
//purpose : Reads OBJ file
//=============================================================================
-static Standard_Integer ReadObj (Draw_Interpretor& theDI,
- Standard_Integer theNbArgs,
- const char** theArgVec)
+static Standard_Integer ReadObj(Draw_Interpretor& theDI,
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
{
TCollection_AsciiString aDestName, aFilePath;
+ Handle(RWObj_ConfigurationNode) aNode = new RWObj_ConfigurationNode();
+ aNode->GlobalParameters.LengthUnit = getLengthUnit();
Standard_Boolean toUseExistingDoc = Standard_False;
- Standard_Real aFileUnitFactor = -1.0;
- RWMesh_CoordinateSystem aResultCoordSys = RWMesh_CoordinateSystem_Zup, aFileCoordSys = RWMesh_CoordinateSystem_Yup;
- Standard_Boolean toListExternalFiles = Standard_False, isSingleFace = Standard_False, isSinglePrecision = Standard_False;
+ Standard_Boolean toListExternalFiles = Standard_False;
Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "readobj");
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
- TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
+ TCollection_AsciiString anArgCase(theArgVec[anArgIter]);
anArgCase.LowerCase();
if (anArgIter + 1 < theNbArgs
- && (anArgCase == "-unit"
- || anArgCase == "-units"
- || anArgCase == "-fileunit"
- || anArgCase == "-fileunits"))
- {
- const TCollection_AsciiString aUnitStr (theArgVec[++anArgIter]);
- aFileUnitFactor = UnitsAPI::AnyToSI (1.0, aUnitStr.ToCString());
- if (aFileUnitFactor <= 0.0)
+ && (anArgCase == "-unit"
+ || anArgCase == "-units"
+ || anArgCase == "-fileunit"
+ || anArgCase == "-fileunits"))
+ {
+ const TCollection_AsciiString aUnitStr(theArgVec[++anArgIter]);
+ aNode->InternalParameters.FileLengthUnit = UnitsAPI::AnyToSI(1.0, aUnitStr.ToCString());
+ if (aNode->InternalParameters.FileLengthUnit <= 0.0)
{
- Message::SendFail() << "Syntax error: wrong length unit '" << aUnitStr << "'";
+ theDI << "Syntax error: wrong length unit '" << aUnitStr << "'\n";
return 1;
}
}
else if (anArgIter + 1 < theNbArgs
- && (anArgCase == "-filecoordinatesystem"
- || anArgCase == "-filecoordsystem"
- || anArgCase == "-filecoordsys"))
+ && (anArgCase == "-filecoordinatesystem"
+ || anArgCase == "-filecoordsystem"
+ || anArgCase == "-filecoordsys"))
{
- if (!parseCoordinateSystem (theArgVec[++anArgIter], aFileCoordSys))
+ if (!parseCoordinateSystem(theArgVec[++anArgIter], aNode->InternalParameters.FileCS))
{
- Message::SendFail() << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'";
+ theDI << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
else if (anArgIter + 1 < theNbArgs
- && (anArgCase == "-resultcoordinatesystem"
- || anArgCase == "-resultcoordsystem"
- || anArgCase == "-resultcoordsys"
- || anArgCase == "-rescoordsys"))
+ && (anArgCase == "-resultcoordinatesystem"
+ || anArgCase == "-resultcoordsystem"
+ || anArgCase == "-resultcoordsys"
+ || anArgCase == "-rescoordsys"))
{
- if (!parseCoordinateSystem (theArgVec[++anArgIter], aResultCoordSys))
+ if (!parseCoordinateSystem(theArgVec[++anArgIter], aNode->InternalParameters.SystemCS))
{
- Message::SendFail() << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'";
+ theDI << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
else if (anArgCase == "-singleprecision"
- || anArgCase == "-singleprec")
+ || anArgCase == "-singleprec")
{
- isSinglePrecision = Standard_True;
+ aNode->InternalParameters.ReadSinglePrecision = Standard_True;
if (anArgIter + 1 < theNbArgs
- && Draw::ParseOnOff (theArgVec[anArgIter + 1], isSinglePrecision))
+ && Draw::ParseOnOff(theArgVec[anArgIter + 1],
+ aNode->InternalParameters.ReadSinglePrecision))
{
++anArgIter;
}
}
else if (isNoDoc
- && (anArgCase == "-singleface"
- || anArgCase == "-singletriangulation"))
+ && (anArgCase == "-singleface"
+ || anArgCase == "-singletriangulation"))
{
- isSingleFace = Standard_True;
+ aNode->InternalParameters.ReadCreateSingle = Standard_True;
}
else if (!isNoDoc
- && (anArgCase == "-nocreate"
- || anArgCase == "-nocreatedoc"))
+ && (anArgCase == "-nocreate"
+ || anArgCase == "-nocreatedoc"))
{
toUseExistingDoc = Standard_True;
if (anArgIter + 1 < theNbArgs
- && Draw::ParseOnOff (theArgVec[anArgIter + 1], toUseExistingDoc))
+ && Draw::ParseOnOff(theArgVec[anArgIter + 1], toUseExistingDoc))
{
++anArgIter;
}
}
else
{
- Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
+ theDI << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aFilePath.IsEmpty())
{
- Message::SendFail() << "Syntax error: wrong number of arguments";
+ theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
-
- Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
Handle(TDocStd_Document) aDoc;
- if (!isNoDoc
- && !toListExternalFiles)
+ if (!isNoDoc)
{
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
Standard_CString aNameVar = aDestName.ToCString();
- DDocStd::GetDocument (aNameVar, aDoc, Standard_False);
+ DDocStd::GetDocument(aNameVar, aDoc, Standard_False);
if (aDoc.IsNull())
{
if (toUseExistingDoc)
{
- Message::SendFail() << "Error: document with name " << aDestName << " does not exist";
+ theDI << "Error: document with name " << aDestName << " does not exist\n";
return 1;
}
- anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
+ anApp->NewDocument(TCollection_ExtendedString("BinXCAF"), aDoc);
}
else if (!toUseExistingDoc)
{
- Message::SendFail() << "Error: document with name " << aDestName << " already exists";
+ theDI << "Error: document with name " << aDestName << " already exists\n";
return 1;
}
}
- Standard_Real aScaleFactorM = 1.;
- if (!XCAFDoc_DocumentTool::GetLengthUnit(aDoc, aScaleFactorM, UnitsMethods_LengthUnit_Meter))
+ Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
+ Handle(RWObj_Provider) aProvider = new RWObj_Provider(aNode);
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ Standard_Boolean aReadStat = Standard_False;
+ if (isNoDoc)
{
- XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
- aScaleFactorM = UnitsMethods::GetCasCadeLengthUnit(UnitsMethods_LengthUnit_Meter);
- }
-
- RWObj_CafReader aReader;
- aReader.SetSinglePrecision (isSinglePrecision);
- aReader.SetSystemLengthUnit (aScaleFactorM);
- aReader.SetSystemCoordinateSystem (aResultCoordSys);
- aReader.SetFileLengthUnit (aFileUnitFactor);
- aReader.SetFileCoordinateSystem (aFileCoordSys);
- aReader.SetDocument (aDoc);
- if (isSingleFace)
- {
- RWObj_TriangulationReader aSimpleReader;
- aSimpleReader.SetSinglePrecision (isSinglePrecision);
- aSimpleReader.SetCreateShapes (Standard_False);
- aSimpleReader.SetTransformation (aReader.CoordinateSystemConverter());
- aSimpleReader.Read (aFilePath.ToCString(), aProgress->Start());
-
- Handle(Poly_Triangulation) aTriangulation = aSimpleReader.GetTriangulation();
- TopoDS_Face aFace;
- BRep_Builder aBuiler;
- aBuiler.MakeFace (aFace);
- aBuiler.UpdateFace (aFace, aTriangulation);
- DBRep::Set (aDestName.ToCString(), aFace);
- return 0;
- }
-
- if (toListExternalFiles)
- {
- aReader.ProbeHeader (aFilePath);
- for (NCollection_IndexedMap<TCollection_AsciiString>::Iterator aFileIter (aReader.ExternalFiles()); aFileIter.More(); aFileIter.Next())
+ TopoDS_Shape aShape;
+ aReadStat = aProvider->Read(aFilePath, aShape, aWS, aProgress->Start());
+ if (aReadStat)
{
- theDI << "\"" << aFileIter.Value() << "\" ";
+ DBRep::Set(aDestName.ToCString(), aShape);
}
}
else
{
- aReader.Perform (aFilePath, aProgress->Start());
- if (isNoDoc)
+ aReadStat = aProvider->Read(aFilePath, aDoc, aWS, aProgress->Start());
+ if (aReadStat)
{
- DBRep::Set (aDestName.ToCString(), aReader.SingleShape());
+ Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument(aDoc);
+ TDataStd_Name::Set(aDoc->GetData()->Root(), aDestName);
+ Draw::Set(aDestName.ToCString(), aDrawDoc);
}
- else
+ }
+ if (!aReadStat)
+ {
+ theDI << "Cannot read any relevant data from the Obj file\n";
+ return 1;
+ }
+
+ if (toListExternalFiles)
+ {
+ for (NCollection_IndexedMap<TCollection_AsciiString>::Iterator aFileIter(aProvider->GetExternalFiles()); aFileIter.More(); aFileIter.Next())
{
- Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument (aDoc);
- TDataStd_Name::Set (aDoc->GetData()->Root(), aDestName);
- Draw::Set (aDestName.ToCString(), aDrawDoc);
+ theDI << "\"" << aFileIter.Value() << "\" ";
}
}
return 0;
//function : WriteObj
//purpose : Writes OBJ file
//=============================================================================
-static Standard_Integer WriteObj (Draw_Interpretor& theDI,
- Standard_Integer theNbArgs,
- const char** theArgVec)
+static Standard_Integer WriteObj(Draw_Interpretor& theDI,
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
{
TCollection_AsciiString anObjFilePath;
Handle(TDocStd_Document) aDoc;
+ TopoDS_Shape aShape;
+ Handle(RWObj_ConfigurationNode) aNode = new RWObj_ConfigurationNode();
+ aNode->GlobalParameters.LengthUnit = getLengthUnit();
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
- TColStd_IndexedDataMapOfStringString aFileInfo;
- Standard_Real aFileUnitFactor = -1.0;
- RWMesh_CoordinateSystem aSystemCoordSys = RWMesh_CoordinateSystem_Zup, aFileCoordSys = RWMesh_CoordinateSystem_Yup;
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
- TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
+ TCollection_AsciiString anArgCase(theArgVec[anArgIter]);
anArgCase.LowerCase();
- if (anArgIter + 1 < theNbArgs
- && (anArgCase == "-unit"
- || anArgCase == "-units"
- || anArgCase == "-fileunit"
- || anArgCase == "-fileunits"))
- {
- const TCollection_AsciiString aUnitStr (theArgVec[++anArgIter]);
- aFileUnitFactor = UnitsAPI::AnyToSI (1.0, aUnitStr.ToCString());
- if (aFileUnitFactor <= 0.0)
+ if (anArgIter + 1 < theNbArgs
+ && (anArgCase == "-unit"
+ || anArgCase == "-units"
+ || anArgCase == "-fileunit"
+ || anArgCase == "-fileunits"))
+ {
+ const TCollection_AsciiString aUnitStr(theArgVec[++anArgIter]);
+ aNode->InternalParameters.FileLengthUnit = UnitsAPI::AnyToSI(1.0, aUnitStr.ToCString());
+ if (aNode->InternalParameters.FileLengthUnit <= 0.0)
{
- Message::SendFail() << "Syntax error: wrong length unit '" << aUnitStr << "'";
+ theDI << "Syntax error: wrong length unit '" << aUnitStr << "'\n";
return 1;
}
}
else if (anArgIter + 1 < theNbArgs
- && (anArgCase == "-filecoordinatesystem"
- || anArgCase == "-filecoordsystem"
- || anArgCase == "-filecoordsys"))
+ && (anArgCase == "-filecoordinatesystem"
+ || anArgCase == "-filecoordsystem"
+ || anArgCase == "-filecoordsys"))
{
- if (!parseCoordinateSystem (theArgVec[++anArgIter], aFileCoordSys))
+ if (!parseCoordinateSystem(theArgVec[++anArgIter], aNode->InternalParameters.FileCS))
{
- Message::SendFail() << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'";
+ theDI << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
else if (anArgIter + 1 < theNbArgs
- && (anArgCase == "-systemcoordinatesystem"
- || anArgCase == "-systemcoordsystem"
- || anArgCase == "-systemcoordsys"
- || anArgCase == "-syscoordsys"))
+ && (anArgCase == "-systemcoordinatesystem"
+ || anArgCase == "-systemcoordsystem"
+ || anArgCase == "-systemcoordsys"
+ || anArgCase == "-syscoordsys"))
{
- if (!parseCoordinateSystem (theArgVec[++anArgIter], aSystemCoordSys))
+ if (!parseCoordinateSystem(theArgVec[++anArgIter], aNode->InternalParameters.SystemCS))
{
- Message::SendFail() << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'";
+ theDI << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
else if (anArgCase == "-comments"
- && anArgIter + 1 < theNbArgs)
+ && anArgIter + 1 < theNbArgs)
{
- aFileInfo.Add ("Comments", theArgVec[++anArgIter]);
+ aNode->InternalParameters.WriteComment = theArgVec[++anArgIter];
}
else if (anArgCase == "-author"
- && anArgIter + 1 < theNbArgs)
+ && anArgIter + 1 < theNbArgs)
{
- aFileInfo.Add ("Author", theArgVec[++anArgIter]);
+ aNode->InternalParameters.WriteAuthor = theArgVec[++anArgIter];
}
- else if (aDoc.IsNull())
+ else if (aDoc.IsNull() && aShape.IsNull())
{
Standard_CString aNameVar = theArgVec[anArgIter];
- DDocStd::GetDocument (aNameVar, aDoc, false);
+ DDocStd::GetDocument(aNameVar, aDoc, false);
if (aDoc.IsNull())
{
- TopoDS_Shape aShape = DBRep::Get (aNameVar);
+ aShape = DBRep::Get(aNameVar);
if (aShape.IsNull())
{
- Message::SendFail() << "Syntax error: '" << aNameVar << "' is not a shape nor document";
+ theDI << "Syntax error: '" << aNameVar << "' is not a shape nor document\n";
return 1;
}
-
- anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
- Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
- aShapeTool->AddShape (aShape);
}
}
else if (anObjFilePath.IsEmpty())
}
else
{
- Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
+ theDI << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (anObjFilePath.IsEmpty())
{
- Message::SendFail() << "Syntax error: wrong number of arguments";
+ theDI << "Syntax error: wrong number of arguments\n";
+ return 1;
+ }
+ Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
+ Handle(RWObj_Provider) aProvider = new RWObj_Provider(aNode);
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ Standard_Boolean aWriteStatus = Standard_False;
+ if (aDoc.IsNull())
+ {
+ aWriteStatus = aProvider->Write(theArgVec[2], aShape, aWS, aProgress->Start());
+ }
+ else
+ {
+ aWriteStatus = aProvider->Write(theArgVec[2], aDoc, aWS, aProgress->Start());
+ }
+ if (!aWriteStatus)
+ {
+ theDI << "Error: Mesh writing has been failed\n";
return 1;
}
-
- Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
-
- const Standard_Real aSystemUnitFactor = UnitsMethods::GetCasCadeLengthUnit() * 0.001;
- RWObj_CafWriter aWriter (anObjFilePath);
- aWriter.ChangeCoordinateSystemConverter().SetInputLengthUnit (aSystemUnitFactor);
- aWriter.ChangeCoordinateSystemConverter().SetInputCoordinateSystem (aSystemCoordSys);
- aWriter.ChangeCoordinateSystemConverter().SetOutputLengthUnit (aFileUnitFactor);
- aWriter.ChangeCoordinateSystemConverter().SetOutputCoordinateSystem (aFileCoordSys);
- aWriter.Perform (aDoc, aFileInfo, aProgress->Start());
return 0;
}
static Standard_Integer writevrml
(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- if (argc < 3 || argc > 5)
+ if (argc < 3 || argc > 5)
{
di << "wrong number of parameters\n";
return 0;
switch (aType)
{
- case 0: writer.SetRepresentation(VrmlAPI_ShadedRepresentation); break;
- case 1: writer.SetRepresentation(VrmlAPI_WireFrameRepresentation); break;
- case 2: writer.SetRepresentation(VrmlAPI_BothRepresentation); break;
+ case 0: writer.SetRepresentation(VrmlAPI_ShadedRepresentation); break;
+ case 1: writer.SetRepresentation(VrmlAPI_WireFrameRepresentation); break;
+ case 2: writer.SetRepresentation(VrmlAPI_BothRepresentation); break;
}
if (!writer.Write(aShape, argv[2], aVersion))
{
if (!Quantity_Color::ColorFromName (argv[anIdx], aColor))
{
- Message::SendFail() << "Syntax error at " << aParam;
+ di << "Syntax error at " << aParam;
return 1;
}
}
}
//=======================================================================
-//function : writeply
+//function : WritePly
//purpose : write PLY file
//=======================================================================
-static Standard_Integer WritePly (Draw_Interpretor& theDI,
- Standard_Integer theNbArgs,
- const char** theArgVec)
+static Standard_Integer WritePly(Draw_Interpretor& theDI,
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
{
Handle(TDocStd_Document) aDoc;
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
TCollection_AsciiString aShapeName, aFileName;
-
+ Handle(RWPly_ConfigurationNode) aNode = new RWPly_ConfigurationNode();
Standard_Real aDist = 0.0;
Standard_Real aDens = Precision::Infinite();
- Standard_Real aTol = Precision::Confusion();
- bool hasColors = true, hasNormals = true, hasTexCoords = false, hasPartId = true, hasFaceId = false;
+ Standard_Real aTol = Precision::Confusion();
bool isPntSet = false, isDensityPoints = false;
- TColStd_IndexedDataMapOfStringString aFileInfo;
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
- TCollection_AsciiString anArg (theArgVec[anArgIter]);
+ TCollection_AsciiString anArg(theArgVec[anArgIter]);
anArg.LowerCase();
if (anArg == "-normal")
{
- hasNormals = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.WriteNormals =
+ Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArg == "-nonormal")
{
- hasNormals = !Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.WriteNormals =
+ !Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArg == "-color"
- || anArg == "-nocolor"
- || anArg == "-colors"
- || anArg == "-nocolors")
+ || anArg == "-nocolor"
+ || anArg == "-colors"
+ || anArg == "-nocolors")
{
- hasColors = Draw::ParseOnOffNoIterator (theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.WriteColors =
+ Draw::ParseOnOffNoIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArg == "-uv"
- || anArg == "-nouv")
+ || anArg == "-nouv")
{
- hasTexCoords = Draw::ParseOnOffNoIterator (theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.WriteTexCoords =
+ Draw::ParseOnOffNoIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArg == "-partid")
{
- hasPartId = Draw::ParseOnOffNoIterator (theNbArgs, theArgVec, anArgIter);
- hasFaceId = hasFaceId && !hasPartId;
+ aNode->InternalParameters.WritePartId =
+ Draw::ParseOnOffNoIterator(theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.WriteFaceId =
+ aNode->InternalParameters.WriteFaceId &&
+ !aNode->InternalParameters.WritePartId;
}
else if (anArg == "-surfid"
- || anArg == "-surfaceid"
- || anArg == "-faceid")
+ || anArg == "-surfaceid"
+ || anArg == "-faceid")
{
- hasFaceId = Draw::ParseOnOffNoIterator (theNbArgs, theArgVec, anArgIter);
- hasPartId = hasPartId && !hasFaceId;
+ aNode->InternalParameters.WriteFaceId =
+ Draw::ParseOnOffNoIterator(theNbArgs, theArgVec, anArgIter);
+ aNode->InternalParameters.WritePartId =
+ aNode->InternalParameters.WritePartId &&
+ !aNode->InternalParameters.WriteFaceId;
}
else if (anArg == "-pntset"
- || anArg == "-pntcloud"
- || anArg == "-pointset"
- || anArg == "-pointcloud"
- || anArg == "-cloud"
- || anArg == "-points")
+ || anArg == "-pntcloud"
+ || anArg == "-pointset"
+ || anArg == "-pointcloud"
+ || anArg == "-cloud"
+ || anArg == "-points")
{
- isPntSet = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
+ isPntSet = Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if ((anArg == "-dist"
- || anArg == "-distance")
- && anArgIter + 1 < theNbArgs
- && Draw::ParseReal (theArgVec[anArgIter + 1], aDist))
+ || anArg == "-distance")
+ && anArgIter + 1 < theNbArgs
+ && Draw::ParseReal(theArgVec[anArgIter + 1], aDist))
{
++anArgIter;
isPntSet = true;
if (aDist < 0.0)
{
- theDI << "Syntax error: -distance value should be >= 0.0";
+ theDI << "Syntax error: -distance value should be >= 0.0\n";
return 1;
}
- aDist = Max (aDist, Precision::Confusion());
+ aDist = Max(aDist, Precision::Confusion());
}
else if ((anArg == "-dens"
- || anArg == "-density")
- && anArgIter + 1 < theNbArgs
- && Draw::ParseReal (theArgVec[anArgIter + 1], aDens))
+ || anArg == "-density")
+ && anArgIter + 1 < theNbArgs
+ && Draw::ParseReal(theArgVec[anArgIter + 1], aDens))
{
++anArgIter;
isDensityPoints = Standard_True;
isPntSet = true;
if (aDens <= 0.0)
{
- theDI << "Syntax error: -density value should be > 0.0";
+ theDI << "Syntax error: -density value should be > 0.0\n";
return 1;
}
}
else if ((anArg == "-tol"
- || anArg == "-tolerance")
- && anArgIter + 1 < theNbArgs
- && Draw::ParseReal (theArgVec[anArgIter + 1], aTol))
+ || anArg == "-tolerance")
+ && anArgIter + 1 < theNbArgs
+ && Draw::ParseReal(theArgVec[anArgIter + 1], aTol))
{
++anArgIter;
isPntSet = true;
if (aTol < Precision::Confusion())
{
- theDI << "Syntax error: -tol value should be >= " << Precision::Confusion();
+ theDI << "Syntax error: -tol value should be >= "
+ << Precision::Confusion() << "\n";
return 1;
}
}
else if (anArg == "-comments"
- && anArgIter + 1 < theNbArgs)
+ && anArgIter + 1 < theNbArgs)
{
- aFileInfo.Add ("Comments", theArgVec[++anArgIter]);
+ aNode->InternalParameters.WriteComment = theArgVec[++anArgIter];
}
else if (anArg == "-author"
- && anArgIter + 1 < theNbArgs)
+ && anArgIter + 1 < theNbArgs)
{
- aFileInfo.Add ("Author", theArgVec[++anArgIter]);
+ aNode->InternalParameters.WriteAuthor = theArgVec[++anArgIter];
}
else if (aDoc.IsNull())
{
}
Standard_CString aNameVar = theArgVec[anArgIter];
- DDocStd::GetDocument (aNameVar, aDoc, false);
+ DDocStd::GetDocument(aNameVar, aDoc, false);
if (aDoc.IsNull())
{
- TopoDS_Shape aShape = DBRep::Get (aNameVar);
+ TopoDS_Shape aShape = DBRep::Get(aNameVar);
if (!aShape.IsNull())
{
- anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
- Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
- aShapeTool->AddShape (aShape);
+ anApp->NewDocument(TCollection_ExtendedString("BinXCAF"), aDoc);
+ Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
+ aShapeTool->AddShape(aShape);
}
}
}
}
else
{
- theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
+ theDI << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aDoc.IsNull()
- && !aShapeName.IsEmpty())
+ && !aShapeName.IsEmpty())
{
- theDI << "Syntax error: '" << aShapeName << "' is not a shape nor document";
+ theDI << "Syntax error: '" << aShapeName << "' is not a shape nor document\n";
return 1;
}
else if (aDoc.IsNull()
- || aFileName.IsEmpty())
- {
- theDI << "Syntax error: wrong number of arguments";
- return 1;
- }
-
- TDF_LabelSequence aRootLabels;
- Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
- aShapeTool->GetFreeShapes (aRootLabels);
- if (aRootLabels.IsEmpty())
+ || aFileName.IsEmpty())
{
- theDI << "Error: empty document";
+ theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
+ aNode->GlobalParameters.LengthUnit = getLengthUnit(aDoc);
if (isPntSet)
{
+ TDF_LabelSequence aRootLabels;
+ Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
+ aShapeTool->GetFreeShapes(aRootLabels);
+ if (aRootLabels.IsEmpty())
+ {
+ theDI << "Error: empty document\n";
+ return 1;
+ }
class PointCloudPlyWriter : public BRepLib_PointCloudShape, public RWPly_PlyWriterContext
{
public:
- PointCloudPlyWriter (Standard_Real theTol)
- : BRepLib_PointCloudShape (TopoDS_Shape(), theTol) {}
+ PointCloudPlyWriter(Standard_Real theTol)
+ : BRepLib_PointCloudShape(TopoDS_Shape(), theTol)
+ {}
- void AddFaceColor (const TopoDS_Shape& theFace, const Graphic3d_Vec4ub& theColor)
- { myFaceColor.Bind (theFace, theColor); }
+ 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)
+ 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);
+ 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 (aTol);
- aPlyCtx.SetNormals (hasNormals);
- aPlyCtx.SetColors (hasColors);
- aPlyCtx.SetTexCoords (hasTexCoords);
+ PointCloudPlyWriter aPlyCtx(aTol);
+ 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 (aDoc, aRootLabels, XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes);
+ BRep_Builder().MakeCompound(aComp);
+ for (XCAFPrs_DocumentExplorer aDocExplorer(aDoc, 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())
+ 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);
+ 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));
+ 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.AddFaceColor(aFaceIter.Face(), aColorVec);
}
}
- aPlyCtx.SetShape (aComp);
+ aPlyCtx.SetShape(aComp);
Standard_Integer aNbPoints = isDensityPoints
- ? aPlyCtx.NbPointsByDensity (aDens)
- : aPlyCtx.NbPointsByTriangulation();
+ ? aPlyCtx.NbPointsByDensity(aDens)
+ : aPlyCtx.NbPointsByTriangulation();
if (aNbPoints <= 0)
{
- theDI << "Error: unable to generate points";
- return 0;
+ theDI << "Error: unable to generate points\n";
+ return 1;
}
- if (!aPlyCtx.Open (aFileName)
- || !aPlyCtx.WriteHeader (aNbPoints, 0, TColStd_IndexedDataMapOfStringString()))
+ if (!aPlyCtx.Open(aFileName)
+ || !aPlyCtx.WriteHeader(aNbPoints, 0, TColStd_IndexedDataMapOfStringString()))
{
- theDI << "Error: unable to create file '" << aFileName << "'";
- return 0;
+ theDI << "Error: unable to create file '" << aFileName << "'\n";
+ return 1;
}
Standard_Boolean isDone = isDensityPoints
- ? aPlyCtx.GeneratePointsByDensity (aDens)
- : aPlyCtx.GeneratePointsByTriangulation();
+ ? aPlyCtx.GeneratePointsByDensity(aDens)
+ : aPlyCtx.GeneratePointsByTriangulation();
if (!isDone)
{
- theDI << "Error: Point cloud was not generated in file '" << aFileName << "'";
+ theDI << "Error: Point cloud was not generated in file '" << aFileName << "'\n";
+ return 1;
}
else if (!aPlyCtx.Close())
{
- theDI << "Error: Point cloud file '" << aFileName << "' was not written";
+ theDI << "Error: Point cloud file '" << aFileName << "' was not written\n";
+ return 1;
}
else
{
- theDI << aNbPoints;
+ theDI << aNbPoints << "\n";
}
}
else
{
- Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
- RWPly_CafWriter aPlyCtx (aFileName);
- aPlyCtx.SetNormals (hasNormals);
- aPlyCtx.SetColors (hasColors);
- aPlyCtx.SetTexCoords (hasTexCoords);
- aPlyCtx.SetPartId (hasPartId);
- aPlyCtx.SetFaceId (hasFaceId);
- aPlyCtx.Perform (aDoc, aFileInfo, aProgress->Start());
+ Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
+ Handle(RWPly_Provider) aProvider = new RWPly_Provider(aNode);
+ Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
+ if (!aProvider->Write(theArgVec[2], aDoc, aWS, aProgress->Start()))
+ {
+ theDI << "Error: file writing failed '" << theArgVec[2] << "'\n";
+ return 1;
+ }
}
return 0;
}
puts "0030691: test glTF reader on standard sample models"
puts "========"
-ReadGltf D [locate_data_file bug30691_DamagedHelmet.gltf]
-
-set anAssetInfo [ReadGltf [locate_data_file bug30691_DamagedHelmet.gltf] -assetInfo]
+set anAssetInfo [ReadGltf D [locate_data_file bug30691_DamagedHelmet.gltf] -assetInfo]
if { "$anAssetInfo" != "generator: Khronos Blender glTF 2.0 exporter" } { puts "Error: unexpected asset info" }
XGetOneShape s D
fconfigure $fd -translation crlf
puts $fd "solid \nendsolid"
close $fd
-readstl res_zero_ascii_dos ${imagedir}/${casename}_zero_ascii_dos.stl -brep
+puts "REQUIRED ALL: Error: RWStl_Provider :"
+catch {
+ if {[readstl res_zero_ascii_dos ${imagedir}/${casename}_zero_ascii_dos.stl -brep]} {
+ puts "Error: empty file should be marked as invalid input file"
+ }
+}
puts "\n#======================================================================"
puts "# Ascii file with no facets, LF"
fconfigure $fd -translation lf
puts $fd "solid \nendsolid"
close $fd
-readstl res_zero_ascii_unix ${imagedir}/${casename}_zero_ascii_unix.stl -brep
+catch {
+ if {[readstl res_zero_ascii_unix ${imagedir}/${casename}_zero_ascii_unix.stl -brep] != 1} {
+ puts "Error: empty file should be marked as invalid input file"
+ }
+}
puts "\n#======================================================================"
puts "# Binary file with single facet"
fconfigure $fd -translation binary
puts -nonewline $fd "stl [string repeat { } 76][binary format i 0]"
close $fd
-readstl res_zero_binary ${imagedir}/${casename}_zero_binary.stl -brep
+catch {
+ if {[readstl res_zero_binary ${imagedir}/${casename}_zero_binary.stl -brep] != 1} {
+ puts "Error: empty file should be marked as invalid input file"
+ }
+}
puts "\n#======================================================================"
puts "# Empty file"
puts "REQUIRED ALL: Error: premature end of file"
set fd [open ${imagedir}/${casename}_empty.stl w]
close $fd
-readstl res_empty ${imagedir}/${casename}_empty.stl -brep
+catch {
+ if {[readstl res_empty ${imagedir}/${casename}_empty.stl -brep] != 1} {
+ puts "Error: empty file should be marked as invalid input file"
+ }
+}
provider.STEP.OCC.write.surfacecurve.mode : 1
provider.STEP.OCC.write.unit : 2
provider.STEP.OCC.write.resource.name : STEP
+provider.STEP.OCC.write.multi.prefix :
provider.STEP.OCC.write.sequence : ToSTEP
+provider.STEP.OCC.write.labels :
provider.STEP.OCC.write.vertex.mode : 0
provider.STEP.OCC.write.stepcaf.subshapes.name : 0
provider.STEP.OCC.write.color : 1
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.read.brep : 1
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.create.single : 0
provider.OBJ.OCC.read.root.prefix :
provider.OBJ.OCC.read.fill.doc : 1
provider.OBJ.OCC.read.fill.incomplete : 1
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.draco.compression : 0
+provider.GLTF.OCC.write.draco.level : 7
+provider.GLTF.OCC.write.draco.position.bits : 14
+provider.GLTF.OCC.write.draco.normal.bits : 10
+provider.GLTF.OCC.write.draco.texture.bits : 12
+provider.GLTF.OCC.write.draco.color.bits : 8
+provider.GLTF.OCC.write.draco.generic.bits : 12
+provider.GLTF.OCC.write.draco.unified.quantization : 0
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.GLTF.OCC.write.parallel : 0
provider.BREP.OCC.write.binary : 1
provider.BREP.OCC.write.version.binary : 4
provider.BREP.OCC.write.version.ascii : 3
provider.STEP.OCC.write.surfacecurve.mode : 1
provider.STEP.OCC.write.unit : 2
provider.STEP.OCC.write.resource.name : STEP
+provider.STEP.OCC.write.multi.prefix :
provider.STEP.OCC.write.sequence : ToSTEP
+provider.STEP.OCC.write.labels :
provider.STEP.OCC.write.vertex.mode : 0
provider.STEP.OCC.write.stepcaf.subshapes.name : 0
provider.STEP.OCC.write.color : 1
}
XGetOneShape S7 D7
-array set areas {0 11995.4 1 0.0119954 2 47916.8 3 11979.2 4 0.0479168 5 0.0119792 6 47916.8 7 18.5678}
+array set areas {0 11995.4 1 0.0119954 2 11979.2 3 11979.2 4 11979.2 5 0.0119792 6 11979.2 7 18.5678}
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
puts "OK : Reading is correct"
}
-array set areas {0 1.21752e+07 1 1.21752e+07 2 1.21752e+13 3 1.21752e+07 4 1.21752e+13 5 1.21752e+07}
+array set areas {0 1.21752e+13 1 1.21752e+07 2 1.21752e+13 3 1.21752e+07 4 1.21752e+13 5 1.21752e+07}
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
}
XGetOneShape S7 D7
-array set areas {0 1.21752e+07 1 12.1752 2 1.21752e+07 3 1.21752e+07 4 12.1752 5 12.1752 6 1.21752e+07 7 1.21773e-05}
+array set areas {0 1.21752e+13 1 12.1752 2 1.21752e+13 3 1.21752e+13 4 12.1752 5 12.1752 6 1.21752e+13 7 1.21773e-05}
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