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

0033300: Data Exchange, DE Wrapper - Specialize WS for each transfer process

Updated STEP and IGES to personalize own work session
This commit is contained in:
dpasukhi 2023-01-03 19:09:28 +00:00
parent 7036facf10
commit 40b80d8d66
5 changed files with 82 additions and 42 deletions

View File

@ -17,11 +17,13 @@
#include <IGESCAFControl_ConfigurationNode.hxx> #include <IGESCAFControl_ConfigurationNode.hxx>
#include <IGESCAFControl_Reader.hxx> #include <IGESCAFControl_Reader.hxx>
#include <IGESCAFControl_Writer.hxx> #include <IGESCAFControl_Writer.hxx>
#include <IGESControl_Controller.hxx>
#include <IGESData.hxx> #include <IGESData.hxx>
#include <IGESData_IGESModel.hxx> #include <IGESData_IGESModel.hxx>
#include <Interface_Static.hxx> #include <Interface_Static.hxx>
#include <Message.hxx> #include <Message.hxx>
#include <XCAFDoc_DocumentTool.hxx> #include <XCAFDoc_DocumentTool.hxx>
#include <XSControl_WorkSession.hxx>
#include <UnitsMethods.hxx> #include <UnitsMethods.hxx>
IMPLEMENT_STANDARD_RTTIEXT(IGESCAFControl_Provider, DE_Provider) IMPLEMENT_STANDARD_RTTIEXT(IGESCAFControl_Provider, DE_Provider)
@ -41,6 +43,26 @@ IGESCAFControl_Provider::IGESCAFControl_Provider(const Handle(DE_ConfigurationNo
: DE_Provider(theNode) : DE_Provider(theNode)
{} {}
//=======================================================================
// function : personizeWS
// purpose :
//=======================================================================
void IGESCAFControl_Provider::personizeWS(Handle(XSControl_WorkSession)& theWS)
{
if (theWS.IsNull())
{
Message::SendWarning() << "Warning: IGESCAFControl_Provider :"
<< " Null work session, use internal temporary session";
theWS = new XSControl_WorkSession();
}
Handle(IGESControl_Controller) aCntrl = Handle(IGESControl_Controller)::DownCast(theWS->NormAdaptor());
if (aCntrl.IsNull())
{
IGESControl_Controller::Init();
theWS->SelectNorm("IGES");
}
}
//======================================================================= //=======================================================================
// function : initStatic // function : initStatic
// purpose : // purpose :
@ -159,14 +181,11 @@ bool IGESCAFControl_Provider::Read(const TCollection_AsciiString& thePath,
return false; return false;
} }
Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode()); Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode());
personizeWS(theWS);
initStatic(aNode); initStatic(aNode);
XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter); XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter);
IGESCAFControl_Reader aReader; IGESCAFControl_Reader aReader;
if (!theWS.IsNull()) aReader.SetWS(theWS);
{
aReader.SetWS(theWS);
}
aReader.SetReadVisible(aNode->InternalParameters.ReadOnlyVisible); aReader.SetReadVisible(aNode->InternalParameters.ReadOnlyVisible);
@ -211,14 +230,10 @@ bool IGESCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
return false; return false;
} }
Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode()); Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode());
personizeWS(theWS);
initStatic(aNode); initStatic(aNode);
XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->InternalParameters.WriteUnit, UnitsMethods_LengthUnit_Millimeter); XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->InternalParameters.WriteUnit, UnitsMethods_LengthUnit_Millimeter);
IGESCAFControl_Writer aWriter; IGESCAFControl_Writer aWriter(theWS);
if (!theWS.IsNull())
{
aWriter = IGESCAFControl_Writer(theWS);
}
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);
@ -249,7 +264,7 @@ bool IGESCAFControl_Provider::Read(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument, const Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
Handle(XSControl_WorkSession) aWS; Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession();
return Read(thePath, theDocument, aWS, theProgress); return Read(thePath, theDocument, aWS, theProgress);
} }
@ -261,7 +276,7 @@ bool IGESCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument, const Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
Handle(XSControl_WorkSession) aWS; Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession();
return Write(thePath, theDocument, aWS, theProgress); return Write(thePath, theDocument, aWS, theProgress);
} }
@ -283,11 +298,9 @@ bool IGESCAFControl_Provider::Read(const TCollection_AsciiString& thePath,
} }
Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode()); Handle(IGESCAFControl_ConfigurationNode) aNode = Handle(IGESCAFControl_ConfigurationNode)::DownCast(GetNode());
initStatic(aNode); initStatic(aNode);
personizeWS(theWS);
IGESControl_Reader aReader; IGESControl_Reader aReader;
if (!theWS.IsNull()) aReader.SetWS(theWS);
{
aReader.SetWS(theWS);
}
aReader.SetReadVisible(aNode->InternalParameters.ReadOnlyVisible); aReader.SetReadVisible(aNode->InternalParameters.ReadOnlyVisible);
IFSelect_ReturnStatus aReadStat = IFSelect_RetVoid; IFSelect_ReturnStatus aReadStat = IFSelect_RetVoid;
aReadStat = aReader.ReadFile(thePath.ToCString()); aReadStat = aReader.ReadFile(thePath.ToCString());
@ -359,7 +372,7 @@ bool IGESCAFControl_Provider::Read(const TCollection_AsciiString& thePath,
TopoDS_Shape& theShape, TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
Handle(XSControl_WorkSession) aWS; Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession();
return Read(thePath, theShape, aWS, theProgress); return Read(thePath, theShape, aWS, theProgress);
} }
@ -371,7 +384,7 @@ bool IGESCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape, const TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
Handle(XSControl_WorkSession) aWS; Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession();
return Write(thePath, theShape, aWS, theProgress); return Write(thePath, theShape, aWS, theProgress);
} }

View File

@ -135,6 +135,11 @@ public:
private: 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 //! Initialize static variables
void initStatic(const Handle(DE_ConfigurationNode)& theNode); void initStatic(const Handle(DE_ConfigurationNode)& theNode);

View File

@ -65,12 +65,10 @@ bool STEPCAFControl_Provider::Read(const TCollection_AsciiString& thePath,
return false; return false;
} }
Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode()); Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
personizeWS(theWS);
XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter); XCAFDoc_DocumentTool::SetLengthUnit(theDocument, aNode->GlobalParameters.LengthUnit, UnitsMethods_LengthUnit_Millimeter);
STEPCAFControl_Reader aReader; STEPCAFControl_Reader aReader;
if (!theWS.IsNull()) aReader.Init(theWS);
{
aReader.Init(theWS);
}
aReader.SetColorMode(aNode->InternalParameters.ReadColor); aReader.SetColorMode(aNode->InternalParameters.ReadColor);
aReader.SetNameMode(aNode->InternalParameters.ReadName); aReader.SetNameMode(aNode->InternalParameters.ReadName);
aReader.SetLayerMode(aNode->InternalParameters.ReadLayer); aReader.SetLayerMode(aNode->InternalParameters.ReadLayer);
@ -114,11 +112,9 @@ bool STEPCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
XCAFDoc_DocumentTool::SetLengthUnit(theDocument, XCAFDoc_DocumentTool::SetLengthUnit(theDocument,
UnitsMethods::GetLengthUnitScale(aNode->InternalParameters.WriteUnit, UnitsMethods::GetLengthUnitScale(aNode->InternalParameters.WriteUnit,
UnitsMethods_LengthUnit_Millimeter), UnitsMethods_LengthUnit_Millimeter); UnitsMethods_LengthUnit_Millimeter), UnitsMethods_LengthUnit_Millimeter);
personizeWS(theWS);
STEPCAFControl_Writer aWriter; STEPCAFControl_Writer aWriter;
if (!theWS.IsNull()) aWriter.Init(theWS);
{
aWriter.Init(theWS);
}
Handle(StepData_StepModel) aModel = Handle(StepData_StepModel)::DownCast(aWriter.Writer().WS()->Model()); Handle(StepData_StepModel) aModel = Handle(StepData_StepModel)::DownCast(aWriter.Writer().WS()->Model());
STEPControl_StepModelType aMode = STEPControl_StepModelType aMode =
static_cast<STEPControl_StepModelType>(aNode->InternalParameters.WriteModelType); static_cast<STEPControl_StepModelType>(aNode->InternalParameters.WriteModelType);
@ -166,7 +162,7 @@ bool STEPCAFControl_Provider::Read(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument, const Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
Handle(XSControl_WorkSession) aWS; Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession();
return Read(thePath, theDocument, aWS, theProgress); return Read(thePath, theDocument, aWS, theProgress);
} }
@ -178,7 +174,7 @@ bool STEPCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
const Handle(TDocStd_Document)& theDocument, const Handle(TDocStd_Document)& theDocument,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
Handle(XSControl_WorkSession) aWS; Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession();
return Write(thePath, theDocument, aWS, theProgress); return Write(thePath, theDocument, aWS, theProgress);
} }
@ -199,11 +195,9 @@ bool STEPCAFControl_Provider::Read(const TCollection_AsciiString& thePath,
return false; return false;
} }
Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode()); Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
personizeWS(theWS);
STEPControl_Reader aReader; STEPControl_Reader aReader;
if(!theWS.IsNull()) aReader.SetWS(theWS);
{
aReader.SetWS(theWS);
}
IFSelect_ReturnStatus aReadstat = IFSelect_RetVoid; IFSelect_ReturnStatus aReadstat = IFSelect_RetVoid;
StepData_ConfParameters aParams; StepData_ConfParameters aParams;
aReadstat = aReader.ReadFile(thePath.ToCString(), aParams); aReadstat = aReader.ReadFile(thePath.ToCString(), aParams);
@ -242,11 +236,9 @@ bool STEPCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
} }
Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode()); Handle(STEPCAFControl_ConfigurationNode) aNode = Handle(STEPCAFControl_ConfigurationNode)::DownCast(GetNode());
personizeWS(theWS);
STEPControl_Writer aWriter; STEPControl_Writer aWriter;
if(!theWS.IsNull()) aWriter.SetWS(theWS);
{
aWriter.SetWS(theWS);
}
IFSelect_ReturnStatus aWritestat = IFSelect_RetVoid; IFSelect_ReturnStatus aWritestat = IFSelect_RetVoid;
Handle(StepData_StepModel) aModel = aWriter.Model(); Handle(StepData_StepModel) aModel = aWriter.Model();
aModel->SetWriteLengthUnit(UnitsMethods::GetLengthUnitScale(aNode->InternalParameters.WriteUnit, UnitsMethods_LengthUnit_Millimeter)); aModel->SetWriteLengthUnit(UnitsMethods::GetLengthUnitScale(aNode->InternalParameters.WriteUnit, UnitsMethods_LengthUnit_Millimeter));
@ -274,7 +266,7 @@ bool STEPCAFControl_Provider::Read(const TCollection_AsciiString& thePath,
TopoDS_Shape& theShape, TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
Handle(XSControl_WorkSession) aWS; Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession();
return Read(thePath, theShape, aWS, theProgress); return Read(thePath, theShape, aWS, theProgress);
} }
@ -286,7 +278,7 @@ bool STEPCAFControl_Provider::Write(const TCollection_AsciiString& thePath,
const TopoDS_Shape& theShape, const TopoDS_Shape& theShape,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
Handle(XSControl_WorkSession) aWS; Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession();
return Write(thePath, theShape, aWS, theProgress); return Write(thePath, theShape, aWS, theProgress);
} }
@ -307,3 +299,23 @@ TCollection_AsciiString STEPCAFControl_Provider::GetVendor() const
{ {
return TCollection_AsciiString("OCC"); return TCollection_AsciiString("OCC");
} }
//=======================================================================
// function : personizeWS
// purpose :
//=======================================================================
void STEPCAFControl_Provider::personizeWS(Handle(XSControl_WorkSession)& theWS)
{
if (theWS.IsNull())
{
Message::SendWarning() << "Warning: STEPCAFControl_Provider :"
<< " Null work session, use internal temporary session";
theWS = new XSControl_WorkSession();
}
Handle(STEPCAFControl_Controller) aCntrl = Handle(STEPCAFControl_Controller)::DownCast(theWS->NormAdaptor());
if (aCntrl.IsNull())
{
STEPCAFControl_Controller::Init();
theWS->SelectNorm("STEP");
}
}

View File

@ -133,6 +133,12 @@ public:
//! @return provider's vendor name //! @return provider's vendor name
Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE; Standard_EXPORT virtual TCollection_AsciiString GetVendor() const Standard_OVERRIDE;
private:
//! Personizes work session with current format.
//! Creates new temporary session if current session is null
//! @param[in] theWS current work session
void personizeWS(Handle(XSControl_WorkSession)& theWS);
}; };

View File

@ -256,6 +256,7 @@ static Standard_Integer ReadFile(Draw_Interpretor& theDI,
} }
Handle(DE_Wrapper) aConf = DE_Wrapper::GlobalWrapper()->Copy(); Handle(DE_Wrapper) aConf = DE_Wrapper::GlobalWrapper()->Copy();
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
Standard_Boolean aStat = Standard_True; Standard_Boolean aStat = Standard_True;
if (!aConfString.IsEmpty()) if (!aConfString.IsEmpty())
{ {
@ -264,7 +265,7 @@ static Standard_Integer ReadFile(Draw_Interpretor& theDI,
if (aStat) if (aStat)
{ {
TopoDS_Shape aShape; TopoDS_Shape aShape;
aStat = isNoDoc ? aConf->Read(aFilePath, aShape) : aConf->Read(aFilePath, aDoc); aStat = isNoDoc ? aConf->Read(aFilePath, aShape, aWS) : aConf->Read(aFilePath, aDoc, aWS);
if (isNoDoc && aStat) if (isNoDoc && aStat)
{ {
DBRep::Set(aDocShapeName.ToCString(), aShape); DBRep::Set(aDocShapeName.ToCString(), aShape);
@ -274,6 +275,7 @@ static Standard_Integer ReadFile(Draw_Interpretor& theDI,
{ {
return 1; return 1;
} }
XSDRAW::CollectActiveWorkSessions(aFilePath);
return 0; return 0;
} }
@ -335,6 +337,7 @@ static Standard_Integer WriteFile(Draw_Interpretor& theDI,
return 1; return 1;
} }
Handle(DE_Wrapper) aConf = DE_Wrapper::GlobalWrapper()->Copy(); Handle(DE_Wrapper) aConf = DE_Wrapper::GlobalWrapper()->Copy();
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
Standard_Boolean aStat = Standard_True; Standard_Boolean aStat = Standard_True;
if (!aConfString.IsEmpty()) if (!aConfString.IsEmpty())
{ {
@ -350,17 +353,18 @@ static Standard_Integer WriteFile(Draw_Interpretor& theDI,
theDI << "Error: incorrect shape " << aDocShapeName << "\n"; theDI << "Error: incorrect shape " << aDocShapeName << "\n";
return 1; return 1;
} }
aStat = aConf->Write(aFilePath, aShape); aStat = aConf->Write(aFilePath, aShape, aWS);
} }
else else
{ {
aStat = aConf->Write(aFilePath, aDoc); aStat = aConf->Write(aFilePath, aDoc, aWS);
} }
} }
if (!aStat) if (!aStat)
{ {
return 1; return 1;
} }
XSDRAW::CollectActiveWorkSessions(aFilePath);
return 0; return 0;
} }