1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-29 14:00:49 +03:00

// update code style and error messages on each providers

// fixed problems with IGES provider
This commit is contained in:
dpasukhi
2023-01-04 15:14:18 +00:00
parent 669c9841b2
commit 93a6d4548d
7 changed files with 235 additions and 166 deletions

View File

@@ -53,8 +53,8 @@ bool DEBRepCascade_Provider::Read(const TCollection_AsciiString& thePath,
(void)theWS; (void)theWS;
if (theDocument.IsNull()) if (theDocument.IsNull())
{ {
Message::SendFail() << "Error in the DEBRepCascade_Provider during reading the file " << Message::SendFail() << "Error: DEBRepCascade_Provider : "
thePath << "\t: theDocument shouldn't be null"; << "Null document";
return false; return false;
} }
TopoDS_Shape aShape; TopoDS_Shape aShape;
@@ -62,7 +62,8 @@ bool DEBRepCascade_Provider::Read(const TCollection_AsciiString& thePath,
{ {
return false; return false;
} }
Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); Handle(XCAFDoc_ShapeTool) aShTool =
XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
aShTool->AddShape(aShape); aShTool->AddShape(aShape);
return true; return true;
} }
@@ -79,12 +80,13 @@ bool DEBRepCascade_Provider::Write(const TCollection_AsciiString& thePath,
(void)theWS; (void)theWS;
TopoDS_Shape aShape; TopoDS_Shape aShape;
TDF_LabelSequence aLabels; TDF_LabelSequence aLabels;
Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); Handle(XCAFDoc_ShapeTool) aSTool =
XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
aSTool->GetFreeShapes(aLabels); aSTool->GetFreeShapes(aLabels);
if (aLabels.Length() <= 0) if (aLabels.Length() <= 0)
{ {
Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << Message::SendFail() << "Error: DEBRepCascade_Provider : "
thePath << "\t: Document contain no shapes"; << "Incorrect or empty Configuration Node";
return false; return false;
} }
@@ -120,46 +122,42 @@ bool DEBRepCascade_Provider::Read(const TCollection_AsciiString& thePath,
bool isBinaryFormat = true; bool isBinaryFormat = true;
{ {
// probe file header to recognize format // probe file header to recognize format
const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); const Handle(OSD_FileSystem)& aFileSystem =
std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream(thePath, std::ios::in | std::ios::binary); OSD_FileSystem::DefaultFileSystem();
std::shared_ptr<std::istream> aFile =
aFileSystem->OpenIStream(thePath, std::ios::in | std::ios::binary);
if (aFile.get() == NULL) if (aFile.get() == NULL)
{ {
Message::SendFail() << "Error in the DEBRepCascade_Provider during reading the file " << Message::SendFail() << "Error: DEBRepCascade_Provider : ["
thePath << "\t: Cannot read the file"; << thePath << "] : Cannot open the file";
return false; return false;
} }
char aStringBuf[255] = {}; char aStringBuf[255] = {};
aFile->read(aStringBuf, 255); aFile->read(aStringBuf, 255);
if (aFile->fail()) if (aFile->fail())
{ {
Message::SendFail() << "Error in the DEBRepCascade_Provider during reading the file " << Message::SendFail() << "Error: DEBRepCascade_Provider : ["
thePath << "\t: Cannot read the file"; << thePath << "] : Cannot open the file";
return false; return false;
} }
isBinaryFormat = !(::strncmp(aStringBuf, "DBRep_DrawableShape", 19) == 0); isBinaryFormat = !(::strncmp(aStringBuf, "DBRep_DrawableShape", 19) == 0);
} }
Standard_Boolean aReadStatus = Standard_True;
if (isBinaryFormat) if (isBinaryFormat)
{ {
if (!BinTools::Read(theShape, thePath.ToCString(), theProgress)) aReadStatus = BinTools::Read(theShape, thePath.ToCString(), theProgress);
{
Message::SendFail() << "Error in the DEBRepCascade_Provider during reading the file " <<
thePath << "\t: Cannot read from the file";
return false;
}
} }
else else
{ {
if (!BRepTools::Read(theShape, thePath.ToCString(), BRep_Builder(), theProgress)) aReadStatus =
{ 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;
}
} }
if (!aReadStatus)
return true; {
Message::SendFail() << "Error: DEBRepCascade_Provider : ["
<< thePath << "] : Cannot read data from the file";
}
return aReadStatus;
} }
//======================================================================= //=======================================================================
@@ -172,59 +170,69 @@ bool DEBRepCascade_Provider::Write(const TCollection_AsciiString& thePath,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
(void)theWS; (void)theWS;
if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(DEBRepCascade_ConfigurationNode))) if (GetNode().IsNull() ||
!GetNode()->IsKind(STANDARD_TYPE(DEBRepCascade_ConfigurationNode)))
{ {
Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << Message::SendFail() << "Error: DEBRepCascade_Provider : "
thePath << "\t: Incorrect or empty Configuration Node"; << "Incorrect or empty Configuration Node";
return false; 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.WriteBinary)
{ {
if (aNode->InternalParameters.WriteVersionBin > static_cast<BinTools_FormatVersion>(BinTools_FormatVersion_UPPER) || if (aNode->InternalParameters.WriteVersionBin >
aNode->InternalParameters.WriteVersionBin < static_cast<BinTools_FormatVersion>(BinTools_FormatVersion_LOWER)) 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 " << Message::SendFail() << "Error: DEBRepCascade_Provider : ["
thePath << "\t: Unknown format version"; << thePath << "] : Unknown format version";
return false; return false;
} }
if (aNode->InternalParameters.WriteNormals && if (aNode->InternalParameters.WriteNormals &&
aNode->InternalParameters.WriteVersionBin < BinTools_FormatVersion_VERSION_4) aNode->InternalParameters.WriteVersionBin < BinTools_FormatVersion_VERSION_4)
{ {
Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << Message::SendFail() << "Error: DEBRepCascade_Provider : ["
thePath << "\t: Vertex normals require binary format version 4 or later"; << thePath << "] : Vertex normals require binary format version 4 or later";
return false; return false;
} }
if (!BinTools::Write(theShape, thePath.ToCString(), aNode->InternalParameters.WriteTriangles, if (!BinTools::Write(theShape, thePath.ToCString(),
aNode->InternalParameters.WriteNormals, aNode->InternalParameters.WriteVersionBin, theProgress)) aNode->InternalParameters.WriteTriangles,
aNode->InternalParameters.WriteNormals,
aNode->InternalParameters.WriteVersionBin, theProgress))
{ {
Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << Message::SendFail() << "Error: DEBRepCascade_Provider : ["
thePath << "\t: Cannot write the file"; << thePath << "] : Cannot write the file";
return false; return false;
} }
} }
else else
{ {
if (aNode->InternalParameters.WriteVersionAscii > static_cast<TopTools_FormatVersion>(TopTools_FormatVersion_UPPER) || if (aNode->InternalParameters.WriteVersionAscii >
aNode->InternalParameters.WriteVersionAscii < static_cast<TopTools_FormatVersion>(TopTools_FormatVersion_LOWER)) 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 " << Message::SendFail() << "Error: DEBRepCascade_Provider : ["
thePath << "\t: Unknown format version"; << thePath << "] : Unknown format version";
return false; return false;
} }
if (aNode->InternalParameters.WriteNormals && if (aNode->InternalParameters.WriteNormals &&
aNode->InternalParameters.WriteVersionAscii < TopTools_FormatVersion_VERSION_3) aNode->InternalParameters.WriteVersionAscii < TopTools_FormatVersion_VERSION_3)
{ {
Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << Message::SendFail() << "Error: DEBRepCascade_Provider : ["
thePath << "\t: Error: vertex normals require ascii format version 3 or later"; << thePath << "] : Vertex normals require ascii format version 3 or later";
return false; return false;
} }
if (!BRepTools::Write(theShape, thePath.ToCString(), aNode->InternalParameters.WriteTriangles, if (!BRepTools::Write(theShape, thePath.ToCString(),
aNode->InternalParameters.WriteNormals, aNode->InternalParameters.WriteVersionAscii, theProgress)) aNode->InternalParameters.WriteTriangles,
aNode->InternalParameters.WriteNormals,
aNode->InternalParameters.WriteVersionAscii, theProgress))
{ {
Message::SendFail() << "Error in the DEBRepCascade_Provider during writing the file " << Message::SendFail() << "Error: DEBRepCascade_Provider : ["
thePath << "\t: Cannot write the file"; << thePath << "] : Cannot write the file";
return false; return false;
} }
} }

View File

@@ -61,17 +61,19 @@ bool DEXCAFCascade_Provider::Read(const TCollection_AsciiString& thePath,
(void)theWS; (void)theWS;
if (theDocument.IsNull()) if (theDocument.IsNull())
{ {
Message::SendFail() << "Error in the DEXCAFCascade_Provider during reading the file " << Message::SendFail() << "Error: DEXCAFCascade_Provider : "
thePath << "\t: theDocument shouldn't be null"; << "Null document";
return false; 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 Message::SendFail() << "Error: DEXCAFCascade_Provider : "
<< "\t: Incorrect or empty Configuration Node"; << "Incorrect or empty Configuration Node";
return false; 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_Document) aDocument;
Handle(TDocStd_Application) anApp = new TDocStd_Application(); Handle(TDocStd_Application) anApp = new TDocStd_Application();
BinDrivers::DefineFormat(anApp); BinDrivers::DefineFormat(anApp);
@@ -84,12 +86,15 @@ bool DEXCAFCascade_Provider::Read(const TCollection_AsciiString& thePath,
XmlLDrivers::DefineFormat(anApp); XmlLDrivers::DefineFormat(anApp);
XmlTObjDrivers::DefineFormat(anApp); XmlTObjDrivers::DefineFormat(anApp);
XmlXCAFDrivers::DefineFormat(anApp); XmlXCAFDrivers::DefineFormat(anApp);
Handle(PCDM_ReaderFilter) aFilter = new PCDM_ReaderFilter(aNode->InternalParameters.ReadAppendMode); Handle(PCDM_ReaderFilter) aFilter =
for (TColStd_ListOfAsciiString::Iterator anIt(aNode->InternalParameters.ReadSkipValues); anIt.More(); anIt.Next()) new PCDM_ReaderFilter(aNode->InternalParameters.ReadAppendMode);
for (TColStd_ListOfAsciiString::Iterator anIt(aNode->InternalParameters.ReadSkipValues);
anIt.More(); anIt.Next())
{ {
aFilter->AddSkipped(anIt.Value()); 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 (anIt.Value().StartsWith("0"))
{ {
@@ -103,8 +108,8 @@ bool DEXCAFCascade_Provider::Read(const TCollection_AsciiString& thePath,
if (anApp->Open(thePath, aDocument, aFilter, theProgress) != PCDM_RS_OK) if (anApp->Open(thePath, aDocument, aFilter, theProgress) != PCDM_RS_OK)
{ {
Message::SendFail() << "Error in the DEXCAFCascade_Provider during reading the file : " << thePath Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
<< "\t: Cannot open XDE document"; thePath << "] : Cannot open XDE document";
return false; return false;
} }
theDocument->SetData(aDocument->GetData()); theDocument->SetData(aDocument->GetData());
@@ -130,50 +135,50 @@ bool DEXCAFCascade_Provider::Write(const TCollection_AsciiString& thePath,
} }
else if (!theDocument->IsSaved()) else if (!theDocument->IsSaved())
{ {
Message::SendFail() << "Storage error in the DEXCAFCascade_Provider during writing the file " << Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
thePath << "\t: Storage error : this document has never been saved"; thePath << "] : Storage error : Document has never been saved";
return false; return false;
} }
else else
{ {
aStatus = anApp->Save(theDocument, theProgress); aStatus = anApp->Save(theDocument, theProgress);
} }
switch (aStatus) switch (aStatus)
{ {
case PCDM_SS_OK: case PCDM_SS_OK:
return true; return true;
case PCDM_SS_DriverFailure: case PCDM_SS_DriverFailure:
Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
<< "\t: Storage error : driver failure"; thePath << "] : Storage error : driver failure";
break; break;
case PCDM_SS_WriteFailure: case PCDM_SS_WriteFailure:
Message::SendFail() << "Error in the DEXCAFCascade_Provider during the writing the file : " << thePath Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
<< "\t: Storage error : write failure"; thePath << "] : Storage error : write failure";
break; break;
case PCDM_SS_Failure: case PCDM_SS_Failure:
Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
<< "\t: Storage error : general failure"; thePath << "] : Storage error : general failure";
break; break;
case PCDM_SS_Doc_IsNull: case PCDM_SS_Doc_IsNull:
Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
<< "\t: Storage error :: document is NULL"; thePath << "] : Storage error : document is NULL";
break; break;
case PCDM_SS_No_Obj: case PCDM_SS_No_Obj:
Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
<< "\t: Storage error : no object"; thePath << "] : Storage error : no object";
break; break;
case PCDM_SS_Info_Section_Error: case PCDM_SS_Info_Section_Error:
Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
<< "\t: Storage error : section error"; thePath << "] : Storage error : section error";
break; break;
case PCDM_SS_UserBreak: case PCDM_SS_UserBreak:
Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
<< "\t: Storage error : user break"; thePath << "] : Storage error : user break";
break; break;
case PCDM_SS_UnrecognizedFormat: case PCDM_SS_UnrecognizedFormat:
Message::SendFail() << "Error in the DEXCAFCascade_Provider during writing the file : " << thePath Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
<< "\t: Storage error : unrecognized document storage format : " << theDocument->StorageFormat(); thePath << "] : Storage error : unrecognized document storage format : "
<< theDocument->StorageFormat();
break; break;
} }
return false; return false;
@@ -189,10 +194,11 @@ bool DEXCAFCascade_Provider::Read(const TCollection_AsciiString& thePath,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
(void)theWS; (void)theWS;
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 Message::SendFail() << "Error: DEXCAFCascade_Provider : "
<< "\t: Incorrect or empty Configuration Node"; << "Incorrect or empty Configuration Node";
return false; return false;
} }
Handle(TDocStd_Document) aDocument; Handle(TDocStd_Document) aDocument;
@@ -205,8 +211,8 @@ bool DEXCAFCascade_Provider::Read(const TCollection_AsciiString& thePath,
aSTool->GetFreeShapes(aLabels); aSTool->GetFreeShapes(aLabels);
if (aLabels.Length() <= 0) if (aLabels.Length() <= 0)
{ {
Message::SendFail() << "Error in the DEXCAFCascade_Provider during reading the file : " << thePath Message::SendFail() << "Error: DEXCAFCascade_Provider : [" <<
<< "\t: Document contain no shapes"; thePath << "] : Storage error : Document contain no shapes";
return false; return false;
} }

View File

@@ -141,13 +141,12 @@ void IGESCAFControl_Provider::initStatic(const Handle(DE_ConfigurationNode)& the
myOldValues.WriteOffsetMode = myOldValues.WriteOffsetMode =
Interface_Static::IVal("write.iges.offset.mode") == 1; Interface_Static::IVal("write.iges.offset.mode") == 1;
myOldGlobalValues.LengthUnit = Interface_Static::IVal("xstep.cascade.unit"); myOldGlobalValues.LengthUnit = 0.001 *
UnitsMethods::GetLengthFactorValue(Interface_Static::IVal("xstep.cascade.unit"));
// Set new values // Set new values
UnitsMethods::SetCasCadeLengthUnit(aNode->GlobalParameters.LengthUnit,
UnitsMethods_LengthUnit_Millimeter);
TCollection_AsciiString aStrUnit( TCollection_AsciiString aStrUnit(
UnitsMethods::DumpLengthUnit(aNode->GlobalParameters.LengthUnit)); UnitsMethods::DumpLengthUnit(aNode->GlobalParameters.LengthUnit,
UnitsMethods_LengthUnit_Meter));
aStrUnit.UpperCase(); aStrUnit.UpperCase();
Interface_Static::SetCVal("xstep.cascade.unit", aStrUnit.ToCString()); Interface_Static::SetCVal("xstep.cascade.unit", aStrUnit.ToCString());
setStatic(aNode->InternalParameters); setStatic(aNode->InternalParameters);
@@ -225,8 +224,12 @@ void IGESCAFControl_Provider::resetStatic()
{ {
return; return;
} }
Interface_Static::SetIVal("xstep.cascade.unit", myOldGlobalValues.LengthUnit); // Set new values
UnitsMethods::SetCasCadeLengthUnit(myOldGlobalValues.LengthUnit); TCollection_AsciiString aStrUnit(
UnitsMethods::DumpLengthUnit(myOldGlobalValues.LengthUnit,
UnitsMethods_LengthUnit_Meter));
aStrUnit.UpperCase();
Interface_Static::SetCVal("xstep.cascade.unit", aStrUnit.ToCString());
setStatic(myOldValues); setStatic(myOldValues);
} }
@@ -326,10 +329,28 @@ bool IGESCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
initStatic(aNode); initStatic(aNode);
personizeWS(theWS); personizeWS(theWS);
XCAFDoc_DocumentTool::SetLengthUnit(theDocument, TCollection_AsciiString aUnit(
aNode->InternalParameters.WriteUnit, UnitsMethods::DumpLengthUnit(aNode->InternalParameters.WriteUnit));
UnitsMethods_LengthUnit_Millimeter); aUnit.UpperCase();
IGESCAFControl_Writer aWriter(theWS, Standard_True); IGESCAFControl_Writer aWriter(theWS, Standard_True);
if (aNode->InternalParameters.WriteUnit > UnitsMethods_LengthUnit_Undefined &&
aNode->InternalParameters.WriteUnit <= UnitsMethods_LengthUnit_Microinch)
{
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.SetColorMode(aNode->InternalParameters.WriteColor);
aWriter.SetNameMode(aNode->InternalParameters.WriteName); aWriter.SetNameMode(aNode->InternalParameters.WriteName);
aWriter.SetLayerMode(aNode->InternalParameters.WriteLayer); aWriter.SetLayerMode(aNode->InternalParameters.WriteLayer);

View File

@@ -26,7 +26,8 @@ namespace
// function : SetReaderParameters // function : SetReaderParameters
// purpose : // 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.SetDoublePrecision(!theNode->InternalParameters.ReadSinglePrecision);
theReader.SetSystemLengthUnit(theNode->GlobalParameters.LengthUnit / 1000); theReader.SetSystemLengthUnit(theNode->GlobalParameters.LengthUnit / 1000);
@@ -75,24 +76,29 @@ bool RWGltf_Provider::Read(const TCollection_AsciiString& thePath,
(void)theWS; (void)theWS;
if (theDocument.IsNull()) if (theDocument.IsNull())
{ {
Message::SendFail() << "Error in the RWGltf_Provider during reading the file " << Message::SendFail() << "Error: RWGltf_Provider : "
thePath << "\t: theDocument shouldn't be null"; << "Null document";
return false; 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 " << Message::SendFail() << "Error: RWGltf_Provider : "
thePath << "\t: Incorrect or empty Configuration Node"; << "Incorrect or empty Configuration Node";
return false; return false;
} }
Handle(RWGltf_ConfigurationNode) aNode = Handle(RWGltf_ConfigurationNode)::DownCast(GetNode()); Handle(RWGltf_ConfigurationNode) aNode =
Handle(RWGltf_ConfigurationNode)::DownCast(GetNode());
RWGltf_CafReader aReader; RWGltf_CafReader aReader;
aReader.SetDocument(theDocument); aReader.SetDocument(theDocument);
SetReaderParameters(aReader, aNode); 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)) 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; return false;
} }
@@ -109,13 +115,15 @@ bool RWGltf_Provider::Write(const TCollection_AsciiString& thePath,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
(void)theWS; (void)theWS;
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 writing the file " << Message::SendFail() << "Error: RWGltf_Provider : "
thePath << "\t: Incorrect or empty Configuration Node"; << "Incorrect or empty Configuration Node";
return false; return false;
} }
Handle(RWGltf_ConfigurationNode) aNode = Handle(RWGltf_ConfigurationNode)::DownCast(GetNode()); Handle(RWGltf_ConfigurationNode) aNode =
Handle(RWGltf_ConfigurationNode)::DownCast(GetNode());
RWMesh_CoordinateSystemConverter aConverter; RWMesh_CoordinateSystemConverter aConverter;
aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000); aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
@@ -146,7 +154,8 @@ bool RWGltf_Provider::Write(const TCollection_AsciiString& thePath,
aWriter.SetSplitIndices16(aNode->InternalParameters.WriteSplitIndices16); aWriter.SetSplitIndices16(aNode->InternalParameters.WriteSplitIndices16);
if (!aWriter.Perform(theDocument, aFileInfo, theProgress)) 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 false;
} }
return true; return true;
@@ -162,18 +171,21 @@ bool RWGltf_Provider::Read(const TCollection_AsciiString& thePath,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
(void)theWS; (void)theWS;
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 " << Message::SendFail() << "Error: RWGltf_Provider : "
thePath << "\t: Incorrect or empty Configuration Node"; << "Incorrect or empty Configuration Node";
return false; return false;
} }
Handle(RWGltf_ConfigurationNode) aNode = Handle(RWGltf_ConfigurationNode)::DownCast(GetNode()); Handle(RWGltf_ConfigurationNode) aNode =
Handle(RWGltf_ConfigurationNode)::DownCast(GetNode());
RWGltf_CafReader aReader; RWGltf_CafReader aReader;
SetReaderParameters(aReader, aNode); SetReaderParameters(aReader, aNode);
if (!aReader.Perform(thePath, theProgress)) 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; return false;
} }
theShape = aReader.SingleShape(); theShape = aReader.SingleShape();

View File

@@ -51,17 +51,19 @@ bool RWObj_Provider::Read(const TCollection_AsciiString& thePath,
(void)theWS; (void)theWS;
if (theDocument.IsNull()) if (theDocument.IsNull())
{ {
Message::SendFail() << "Error in the RWObj_Provider during reading the file " << Message::SendFail() << "Error: RWObj_Provider : "
thePath << "\t: theDocument shouldn't be null"; << "Null document";
return false; 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 " << Message::SendFail() << "Error: RWObj_Provider : "
thePath << "\t: Incorrect or empty Configuration Node"; << "Incorrect or empty Configuration Node";
return false; return false;
} }
Handle(RWObj_ConfigurationNode) aNode = Handle(RWObj_ConfigurationNode)::DownCast(GetNode()); Handle(RWObj_ConfigurationNode) aNode =
Handle(RWObj_ConfigurationNode)::DownCast(GetNode());
RWObj_CafReader aReader; RWObj_CafReader aReader;
aReader.SetSinglePrecision(aNode->InternalParameters.ReadSinglePrecision); aReader.SetSinglePrecision(aNode->InternalParameters.ReadSinglePrecision);
aReader.SetSystemLengthUnit(aNode->GlobalParameters.LengthUnit / 1000); aReader.SetSystemLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
@@ -73,10 +75,13 @@ bool RWObj_Provider::Read(const TCollection_AsciiString& thePath,
aReader.SetMemoryLimitMiB(aNode->InternalParameters.ReadMemoryLimitMiB); aReader.SetMemoryLimitMiB(aNode->InternalParameters.ReadMemoryLimitMiB);
if (!aReader.Perform(thePath, theProgress)) 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; return false;
} }
XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter); XCAFDoc_DocumentTool::SetLengthUnit(theDocument,
aNode->GlobalParameters.LengthUnit,
UnitsMethods_LengthUnit_Millimeter);
return true; return true;
} }
@@ -90,13 +95,15 @@ bool RWObj_Provider::Write(const TCollection_AsciiString& thePath,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
(void)theWS; (void)theWS;
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 " << Message::SendFail() << "Error: RWObj_Provider : "
thePath << "\t: Incorrect or empty Configuration Node"; << "Incorrect or empty Configuration Node";
return false; return false;
} }
Handle(RWObj_ConfigurationNode) aNode = Handle(RWObj_ConfigurationNode)::DownCast(GetNode()); Handle(RWObj_ConfigurationNode) aNode =
Handle(RWObj_ConfigurationNode)::DownCast(GetNode());
TColStd_IndexedDataMapOfStringString aFileInfo; TColStd_IndexedDataMapOfStringString aFileInfo;
if (!aNode->InternalParameters.WriteAuthor.IsEmpty()) if (!aNode->InternalParameters.WriteAuthor.IsEmpty())
@@ -107,7 +114,6 @@ bool RWObj_Provider::Write(const TCollection_AsciiString& thePath,
{ {
aFileInfo.Add("Comments", aNode->InternalParameters.WriteComment); aFileInfo.Add("Comments", aNode->InternalParameters.WriteComment);
} }
RWMesh_CoordinateSystemConverter aConverter; RWMesh_CoordinateSystemConverter aConverter;
aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000); aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
aConverter.SetInputCoordinateSystem(aNode->InternalParameters.SystemCS); aConverter.SetInputCoordinateSystem(aNode->InternalParameters.SystemCS);
@@ -118,7 +124,8 @@ bool RWObj_Provider::Write(const TCollection_AsciiString& thePath,
aWriter.SetCoordinateSystemConverter(aConverter); aWriter.SetCoordinateSystemConverter(aConverter);
if (!aWriter.Perform(theDocument, aFileInfo, theProgress)) 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 false;
} }
return true; return true;
@@ -134,13 +141,15 @@ bool RWObj_Provider::Read(const TCollection_AsciiString& thePath,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
(void)theWS; (void)theWS;
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 " << Message::SendFail() << "Error: RWObj_Provider : "
thePath << "\t: Incorrect or empty Configuration Node"; << "Incorrect or empty Configuration Node";
return false; return false;
} }
Handle(RWObj_ConfigurationNode) aNode = Handle(RWObj_ConfigurationNode)::DownCast(GetNode()); Handle(RWObj_ConfigurationNode) aNode =
Handle(RWObj_ConfigurationNode)::DownCast(GetNode());
RWMesh_CoordinateSystemConverter aConverter; RWMesh_CoordinateSystemConverter aConverter;
aConverter.SetOutputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000); aConverter.SetOutputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
aConverter.SetOutputCoordinateSystem(aNode->InternalParameters.SystemCS); aConverter.SetOutputCoordinateSystem(aNode->InternalParameters.SystemCS);
@@ -155,7 +164,8 @@ bool RWObj_Provider::Read(const TCollection_AsciiString& thePath,
aSimpleReader.SetMemoryLimit(aNode->InternalParameters.ReadMemoryLimitMiB); aSimpleReader.SetMemoryLimit(aNode->InternalParameters.ReadMemoryLimitMiB);
if (!aSimpleReader.Read(thePath, theProgress)) if (!aSimpleReader.Read(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; return false;
} }
Handle(Poly_Triangulation) aTriangulation = aSimpleReader.GetTriangulation(); Handle(Poly_Triangulation) aTriangulation = aSimpleReader.GetTriangulation();
@@ -178,7 +188,8 @@ bool RWObj_Provider::Write(const TCollection_AsciiString& thePath,
{ {
(void)theWS; (void)theWS;
Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF"); Handle(TDocStd_Document) aDoc = new TDocStd_Document("BinXCAF");
Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main()); Handle(XCAFDoc_ShapeTool) aShTool =
XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
aShTool->AddShape(theShape); aShTool->AddShape(theShape);
return Write(thePath, aDoc, theWS, theProgress); return Write(thePath, aDoc, theWS, theProgress);
} }

View File

@@ -52,22 +52,24 @@ bool RWPly_Provider::Write(const TCollection_AsciiString& thePath,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
(void)theWS; (void)theWS;
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 " << Message::SendFail() << "Error: RWPly_Provider : "
thePath << "\t: Incorrect or empty Configuration Node"; << "Incorrect or empty Configuration Node";
return false; return false;
} }
Handle(RWPly_ConfigurationNode) aNode = Handle(RWPly_ConfigurationNode)::DownCast(GetNode()); Handle(RWPly_ConfigurationNode) aNode =
Handle(RWPly_ConfigurationNode)::DownCast(GetNode());
TDF_LabelSequence aRootLabels; TDF_LabelSequence aRootLabels;
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); Handle(XCAFDoc_ShapeTool) aShapeTool =
XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
aShapeTool->GetFreeShapes(aRootLabels); aShapeTool->GetFreeShapes(aRootLabels);
if (aRootLabels.IsEmpty()) if (aRootLabels.IsEmpty())
{ {
return Standard_True; return Standard_True;
} }
TColStd_IndexedDataMapOfStringString aFileInfo; TColStd_IndexedDataMapOfStringString aFileInfo;
if (!aNode->InternalParameters.WriteAuthor.IsEmpty()) if (!aNode->InternalParameters.WriteAuthor.IsEmpty())
{ {
@@ -91,8 +93,8 @@ bool RWPly_Provider::Write(const TCollection_AsciiString& thePath,
aPlyCtx.SetFaceId(aNode->InternalParameters.WriteFaceId); aPlyCtx.SetFaceId(aNode->InternalParameters.WriteFaceId);
if (!aPlyCtx.Perform(theDocument, aFileInfo, theProgress)) if (!aPlyCtx.Perform(theDocument, aFileInfo, theProgress))
{ {
Message::SendFail() << "Error in the RWPly_Provider during writing the file " Message::SendFail() << "Error: RWObj_Provider : [" <<
<< thePath << "\t: Cannot perform the document"; thePath << "] : Cannot write any relevant data to the Ply file";
return false; return false;
} }

View File

@@ -53,8 +53,8 @@ bool RWStl_Provider::Read(const TCollection_AsciiString& thePath,
(void)theWS; (void)theWS;
if (theDocument.IsNull()) if (theDocument.IsNull())
{ {
Message::SendFail() << "Error in the RWStl_Provider during reading the file " << Message::SendFail() << "Error: RWStl_Provider : "
thePath << "\t: theDocument shouldn't be null"; << "Null document";
return false; return false;
} }
TopoDS_Shape aShape; TopoDS_Shape aShape;
@@ -62,7 +62,8 @@ bool RWStl_Provider::Read(const TCollection_AsciiString& thePath,
{ {
return false; return false;
} }
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); Handle(XCAFDoc_ShapeTool) aShapeTool =
XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
aShapeTool->AddShape(aShape); aShapeTool->AddShape(aShape);
return true; return true;
} }
@@ -79,12 +80,13 @@ bool RWStl_Provider::Write(const TCollection_AsciiString& thePath,
(void)theWS; (void)theWS;
TopoDS_Shape aShape; TopoDS_Shape aShape;
TDF_LabelSequence aLabels; TDF_LabelSequence aLabels;
Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDocument->Main()); Handle(XCAFDoc_ShapeTool) aSTool =
XCAFDoc_DocumentTool::ShapeTool(theDocument->Main());
aSTool->GetFreeShapes(aLabels); aSTool->GetFreeShapes(aLabels);
if (aLabels.Length() <= 0) if (aLabels.Length() <= 0)
{ {
Message::SendFail() << "Error in the RWStl_Provider during writing the file " << Message::SendFail() << "Error: RWStl_Provider : "
thePath << "\t: Document contain no shapes"; << "Incorrect or empty Configuration Node";
return false; return false;
} }
@@ -117,27 +119,30 @@ bool RWStl_Provider::Read(const TCollection_AsciiString& thePath,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
(void)theWS; (void)theWS;
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))) if (!GetNode()->IsKind(STANDARD_TYPE(RWStl_ConfigurationNode)))
{ {
Message::SendFail() << "Error in the RWStl_Provider during reading the file " << Message::SendFail() << "Error: RWStl_Provider : "
thePath << "\t: Incorrect or empty Configuration Node"; << "Incorrect or empty Configuration Node";
return true; 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; double aMergeAngle = aNode->InternalParameters.ReadMergeAngle * M_PI / 180.0;
if (aMergeAngle != M_PI_2) 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 " << Message::SendFail() << "Error: RWStl_Provider : ["
thePath << "\t: The merge angle is out of the valid range"; << aMergeAngle << "] The merge angle is out of the valid range";
return false; return false;
} }
} }
if (!aNode->InternalParameters.ReadBRep) if (!aNode->InternalParameters.ReadBRep)
{ {
Handle(Poly_Triangulation) aTriangulation = RWStl::ReadFile(thePath.ToCString(), aMergeAngle, theProgress); Handle(Poly_Triangulation) aTriangulation =
RWStl::ReadFile(thePath.ToCString(), aMergeAngle, theProgress);
TopoDS_Face aFace; TopoDS_Face aFace;
BRep_Builder aB; BRep_Builder aB;
@@ -150,7 +155,8 @@ bool RWStl_Provider::Read(const TCollection_AsciiString& thePath,
Standard_DISABLE_DEPRECATION_WARNINGS Standard_DISABLE_DEPRECATION_WARNINGS
if (!StlAPI::Read(theShape, thePath.ToCString())) if (!StlAPI::Read(theShape, thePath.ToCString()))
{ {
Message::SendFail() << "Error in the RWStl_Provider during reading the file " << thePath; Message::SendFail() << "Error: RWStl_Provider : [" <<
thePath << "] : Cannot read any relevant data from the STL file";
return false; return false;
} }
Standard_ENABLE_DEPRECATION_WARNINGS Standard_ENABLE_DEPRECATION_WARNINGS
@@ -168,21 +174,24 @@ bool RWStl_Provider::Write(const TCollection_AsciiString& thePath,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
(void)theWS; (void)theWS;
Message::SendWarning() << "OCCT Stl writer does not support model scaling according to custom length unit"; Message::SendWarning() <<
if (GetNode().IsNull() || !GetNode()->IsKind(STANDARD_TYPE(RWStl_ConfigurationNode))) "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 " << Message::SendFail() << "Error: RWStl_Provider : "
thePath << "\t: Incorrect or empty Configuration Node"; << "Incorrect or empty Configuration Node";
return false; return false;
} }
Handle(RWStl_ConfigurationNode) aNode = Handle(RWStl_ConfigurationNode)::DownCast(GetNode()); Handle(RWStl_ConfigurationNode) aNode =
Handle(RWStl_ConfigurationNode)::DownCast(GetNode());
StlAPI_Writer aWriter; StlAPI_Writer aWriter;
aWriter.ASCIIMode() = aNode->InternalParameters.WriteAscii; aWriter.ASCIIMode() = aNode->InternalParameters.WriteAscii;
if (!aWriter.Write(theShape, thePath.ToCString(), theProgress)) if (!aWriter.Write(theShape, thePath.ToCString(), theProgress))
{ {
Message::SendFail() << "Error in the RWStl_Provider during reading the file " << Message::SendFail() << "Error: RWStl_Provider : [" <<
thePath << "\t: Mesh writing has been failed"; thePath << "] : Mesh writing has been failed";
return false; return false;
} }
return true; return true;