From 8242929d3384a78b0fdc56ed5568f37fa087e09c Mon Sep 17 00:00:00 2001 From: kgv Date: Thu, 27 May 2021 16:13:07 +0300 Subject: [PATCH] STEPCAFControl_Writer::WriteStream() - added interface for writing into stream. Added argument -stream to commands WriteStep, testwritestep for testing purposes. --- src/STEPCAFControl/STEPCAFControl_Writer.cxx | 65 +++- src/STEPCAFControl/STEPCAFControl_Writer.hxx | 6 +- src/STEPControl/STEPControl_Writer.cxx | 44 ++- src/STEPControl/STEPControl_Writer.hxx | 8 +- src/XDEDRAW/XDEDRAW_Common.cxx | 334 +++++++++++-------- src/XSDRAWSTEP/XSDRAWSTEP.cxx | 79 ++++- tests/bugs/step/bug32350 | 32 ++ 7 files changed, 375 insertions(+), 193 deletions(-) create mode 100644 tests/bugs/step/bug32350 diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.cxx b/src/STEPCAFControl/STEPCAFControl_Writer.cxx index b9ca23fb60..e269f57cad 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.cxx @@ -329,36 +329,67 @@ void STEPCAFControl_Writer::Init (const Handle(XSControl_WorkSession)& WS, //function : Write //purpose : //======================================================================= - -IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString filename) +IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString theFileName) { - IFSelect_ReturnStatus status = myWriter.Write ( filename ); + IFSelect_ReturnStatus aStatus = myWriter.Write (theFileName); + if (aStatus != IFSelect_RetDone) + { + return aStatus; + } // get directory name of the main file - OSD_Path mainfile ( filename ); - mainfile.SetName ( "" ); - mainfile.SetExtension ( "" ); - TCollection_AsciiString dpath; - mainfile.SystemName ( dpath ); + TCollection_AsciiString aDirPath; + { + OSD_Path aMainFile (theFileName); + aMainFile.SetName (""); + aMainFile.SetExtension (""); + aMainFile.SystemName (aDirPath); + } - NCollection_DataMap::Iterator it(myFiles); - for ( ; it.More(); it.Next() ) { - Handle(STEPCAFControl_ExternFile) EF = it.Value(); - if ( EF->GetWriteStatus() != IFSelect_RetVoid ) continue; + for (NCollection_DataMap::Iterator anExtFileIter (myFiles); + anExtFileIter.More(); anExtFileIter.Next()) + { + Handle(STEPCAFControl_ExternFile) anExtFile = anExtFileIter.Value(); + if (anExtFile->GetWriteStatus() != IFSelect_RetVoid) + { + continue; + } // construct extern file name - TCollection_AsciiString fname = OSD_Path::AbsolutePath ( dpath, EF->GetName()->String() ); - if ( fname.Length() <= 0 ) fname = EF->GetName()->String(); + TCollection_AsciiString aFileName = OSD_Path::AbsolutePath (aDirPath, anExtFile->GetName()->String()); + if (aFileName.Length() <= 0) + { + aFileName = anExtFile->GetName()->String(); + } #ifdef OCCT_DEBUG - std::cout << "Writing external file: " << fname.ToCString() << std::endl; + std::cout << "Writing external file: " << aFileName << std::endl; #endif - EF->SetWriteStatus ( EF->GetWS()->SendAll ( fname.ToCString() ) ); + const IFSelect_ReturnStatus anExtStatus = anExtFile->GetWS()->SendAll (aFileName.ToCString()); + anExtFile->SetWriteStatus (anExtStatus); + if (anExtStatus != IFSelect_RetDone) + { + aStatus = anExtStatus; + } } - return status; + return aStatus; } +//======================================================================= +//function : WriteStream +//purpose : +//======================================================================= +IFSelect_ReturnStatus STEPCAFControl_Writer::WriteStream (std::ostream& theStream) +{ + if (!myFiles.IsEmpty()) + { + // writing external files is unsupported via stream interface + return IFSelect_RetError; + } + + return myWriter.WriteStream (theStream); +} //======================================================================= //function : Transfer diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.hxx b/src/STEPCAFControl/STEPCAFControl_Writer.hxx index f74f07877e..c377284845 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.hxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.hxx @@ -73,7 +73,11 @@ public: //! filename will be a name of root file, all other files //! have names of corresponding parts //! Provided for use like single-file writer - Standard_EXPORT IFSelect_ReturnStatus Write (const Standard_CString filename); + Standard_EXPORT IFSelect_ReturnStatus Write (const Standard_CString theFileName); + + //! Writes all the produced models into the stream. + //! Provided for use like single-file writer + Standard_EXPORT IFSelect_ReturnStatus WriteStream (std::ostream& theStream); //! Transfers a document (or single label) to a STEP model //! The mode of translation of shape is AsIs diff --git a/src/STEPControl/STEPControl_Writer.cxx b/src/STEPControl/STEPControl_Writer.cxx index b2dbfd6ab1..fd0558048f 100644 --- a/src/STEPControl/STEPControl_Writer.cxx +++ b/src/STEPControl/STEPControl_Writer.cxx @@ -145,44 +145,38 @@ IFSelect_ReturnStatus STEPControl_Writer::Transfer //======================================================================= //function : Write -//purpose : +//purpose : //======================================================================= - -IFSelect_ReturnStatus STEPControl_Writer::Write (const Standard_CString filename) +IFSelect_ReturnStatus STEPControl_Writer::Write (const Standard_CString theFileName) { - return thesession->SendAll(filename); + return thesession->SendAll (theFileName); } - //======================================================================= //function : WriteStream -//purpose : +//purpose : //======================================================================= - IFSelect_ReturnStatus STEPControl_Writer::WriteStream (std::ostream& theOStream) { + Handle(StepData_StepModel) aModel = Model(); + if (aModel.IsNull()) + { + return IFSelect_RetFail; + } - Handle_StepData_Protocol stepro = Handle_StepData_Protocol::DownCast( - this->Model()->Protocol()); - - if (this->Model().IsNull() || this->Model()->Protocol().IsNull()) - return IFSelect_RetFail; - - StepData_StepWriter SW(this->Model()); - SW.SendModel( stepro ); - - Standard_Boolean isGood = SW.Print( theOStream ); - - if( isGood ) - return IFSelect_RetDone; - else - return IFSelect_RetFail; + Handle(StepData_Protocol) aProtocol = Handle(StepData_Protocol)::DownCast (aModel->Protocol()); + if (aProtocol.IsNull()) + { + return IFSelect_RetFail; + } + StepData_StepWriter aWriter (aModel); + aWriter.SendModel (aProtocol); + return aWriter.Print (theOStream) + ? IFSelect_RetDone + : IFSelect_RetFail; } - - - //======================================================================= //function : PrintStatsTransfer //purpose : diff --git a/src/STEPControl/STEPControl_Writer.hxx b/src/STEPControl/STEPControl_Writer.hxx index 81d60c195d..05b6d9f52e 100644 --- a/src/STEPControl/STEPControl_Writer.hxx +++ b/src/STEPControl/STEPControl_Writer.hxx @@ -90,13 +90,13 @@ public: const STEPControl_StepModelType mode, const Standard_Boolean compgraph = Standard_True, const Message_ProgressRange& theProgress = Message_ProgressRange()); - + //! Writes a STEP model in the file identified by filename. - Standard_EXPORT IFSelect_ReturnStatus Write (const Standard_CString filename); + Standard_EXPORT IFSelect_ReturnStatus Write (const Standard_CString theFileName); //! Writes a STEP model in the std::ostream. - Standard_EXPORT IFSelect_ReturnStatus WriteStream ( std::ostream& theOStream ); - + Standard_EXPORT IFSelect_ReturnStatus WriteStream (std::ostream& theOStream); + //! Displays the statistics for the //! last translation. what defines the kind of statistics that are displayed: //! - 0 gives general statistics (number of translated roots, diff --git a/src/XDEDRAW/XDEDRAW_Common.cxx b/src/XDEDRAW/XDEDRAW_Common.cxx index 44cc378ba4..a1231e5081 100644 --- a/src/XDEDRAW/XDEDRAW_Common.cxx +++ b/src/XDEDRAW/XDEDRAW_Common.cxx @@ -340,11 +340,13 @@ static Standard_Integer WriteIges (Draw_Interpretor& di, Standard_Integer argc, //function : ReadStep //purpose : Read STEP file to DECAF document //======================================================================= - static Standard_Integer ReadStep (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { DeclareAndCast(STEPControl_Controller,ctl,XSDRAW::Controller()); - if (ctl.IsNull()) XSDRAW::SetNorm("STEP"); + if (ctl.IsNull()) + { + XSDRAW::SetNorm ("STEP"); + } Standard_CString aDocName = NULL; TCollection_AsciiString aFilePath, aModeStr; @@ -376,26 +378,26 @@ static Standard_Integer ReadStep (Draw_Interpretor& di, Standard_Integer argc, c } } - TCollection_AsciiString fnom, rnom; - Standard_Boolean modfic = XSDRAW::FileAndVar (aFilePath.ToCString(), aDocName, "STEP", fnom, rnom); - if (modfic) di << " File STEP to read : " << fnom.ToCString() << "\n"; - else di << " Model taken from the session : " << fnom.ToCString() << "\n"; + 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 : "<Start(), "STEP import", modfic ? 2 : 1); + Message_ProgressScope aRootScope (aProgress->Start(), "STEP import", isFileMode ? 2 : 1); - IFSelect_ReturnStatus readstat = IFSelect_RetVoid; - if (modfic) + 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, fnom.ToCString(), std::ios::in | std::ios::binary); - TCollection_AsciiString aFolder, aFileName; - OSD_Path::FolderAndFileFromPath (fnom, aFolder, aFileName); - readstat = reader.ReadStream (aFileName.ToCString(), 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 { - readstat = reader.ReadFile (fnom.ToCString()); + aReadStat = aReader.ReadFile (aFileName.ToCString()); } } else if (XSDRAW::Session()->NbStartingEntities() > 0) { - readstat = IFSelect_RetDone; + aReadStat = IFSelect_RetDone; } - if (readstat != IFSelect_RetDone) + if (aReadStat != IFSelect_RetDone) { - if (modfic) + if (isFileMode) { - di << "Could not read file " << fnom << " , abandon\n"; + di << "Could not read file " << aFileName << " , abandon\n"; } else { @@ -443,30 +445,29 @@ static Standard_Integer ReadStep (Draw_Interpretor& di, Standard_Integer argc, c return 1; } - Handle(TDocStd_Document) doc; - if (!DDocStd::GetDocument (aDocName, doc, Standard_False)) + Handle(TDocStd_Document) aDoc; + if (!DDocStd::GetDocument (aDocName, aDoc, Standard_False)) { - Handle(TDocStd_Application) A = DDocStd::GetApplication(); - A->NewDocument("BinXCAF",doc); - TDataStd_Name::Set(doc->GetData()->Root(), aDocName); - Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc); - Draw::Set (aDocName, DD); + 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; } - if (!reader.Transfer (doc, aRootScope.Next())) + if (!aReader.Transfer (aDoc, aRootScope.Next())) { di << "Cannot read any relevant data from the STEP file\n"; return 1; } - - Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc); - Draw::Set (aDocName, DD); - di << "Document saved with name " << aDocName; - NCollection_DataMap DicFile = reader.ExternFiles(); - FillDicWS( DicFile ); - AddWS ( fnom , XSDRAW::Session() ); + Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument (aDoc); + Draw::Set (aDocName, aDrawDoc); + di << "Document saved with name " << aDocName; + NCollection_DataMap aDicFile = aReader.ExternFiles(); + FillDicWS (aDicFile); + AddWS (aFileName, XSDRAW::Session()); return 0; } @@ -474,124 +475,183 @@ static Standard_Integer ReadStep (Draw_Interpretor& di, Standard_Integer argc, c //function : WriteStep //purpose : Write DECAF document to STEP //======================================================================= - static Standard_Integer WriteStep (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { - if ( argc <3 ) { - di << "Use: " << argv[0] << " Doc filename [mode [multifile_prefix [label]]]: write document to the STEP file\n"; - di << "mode can be: a or 0 : AsIs (default)\n"; - di << " f or 1 : FacettedBRep s or 2 : ShellBasedSurfaceModel\n"; - di << " m or 3 : ManifoldSolidBrep w or 4 : GeometricCurveSet/WireFrame\n"; - di << "multifile_prefix: triggers writing assembly components as separate files,\n"; - di << " and defines common prefix for their names\n"; - di << "label: tag of the sub-assembly label to save only that sub-assembly\n"; - return 0; - } - - Handle(TDocStd_Document) Doc; - DDocStd::GetDocument(argv[1], Doc); - if ( Doc.IsNull() ) { - di << argv[1] << " is not a document\n"; - return 1; - } - Standard_CString multifile = 0; - - Standard_Integer k = 3; DeclareAndCast(STEPControl_Controller,ctl,XSDRAW::Controller()); - if (ctl.IsNull()) XSDRAW::SetNorm("STEP"); - STEPCAFControl_Writer writer ( XSDRAW::Session(), Standard_True ); - - STEPControl_StepModelType mode = STEPControl_AsIs; - if ( argc > k ) { - switch (argv[k][0]) { - case 'a' : - case '0' : mode = STEPControl_AsIs; break; - case 'f' : - case '1' : mode = STEPControl_FacetedBrep; break; - case 's' : - case '2' : mode = STEPControl_ShellBasedSurfaceModel; break; - case 'm' : - case '3' : mode = STEPControl_ManifoldSolidBrep; break; - case 'w' : - case '4' : mode = STEPControl_GeometricCurveSet; break; - default : di<<"3rd arg = mode, incorrect [give fsmw]\n"; return 1; - } - Standard_Boolean wrmode = Standard_True; - for ( Standard_Integer i = 0; argv[k][i] ; i++ ) - switch (argv[3][i]) { - case '-' : wrmode = Standard_False; break; - case '+' : wrmode = Standard_True; break; - case 'c' : writer.SetColorMode (wrmode); break; - case 'n' : writer.SetNameMode (wrmode); break; - case 'l' : writer.SetLayerMode (wrmode); break; - case 'v' : writer.SetPropsMode (wrmode); break; - } - k++; + if (ctl.IsNull()) + { + XSDRAW::SetNorm ("STEP"); } + STEPCAFControl_Writer aWriter (XSDRAW::Session(), Standard_True); - TDF_Label label; - if( argc > k) + Handle(TDocStd_Document) aDoc; + TCollection_AsciiString aDocName, aFilePath; + STEPControl_StepModelType aMode = STEPControl_AsIs; + bool hasModeArg = false, toTestStream = false; + TCollection_AsciiString aMultiFilePrefix, aLabelName; + TDF_Label aLabel; + for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter) { - TCollection_AsciiString aStr(argv[k]); - if( aStr.Search(":") ==-1) - multifile = argv[k++]; - + TCollection_AsciiString anArgCase (argv[anArgIter]); + anArgCase.LowerCase(); + if (anArgCase == "-stream") + { + toTestStream = true; + } + else if (aDocName.IsEmpty()) + { + Standard_CString aDocNameStr = argv[anArgIter]; + DDocStd::GetDocument (aDocNameStr, aDoc); + if (aDoc.IsNull()) + { + di << "Syntax error: '" << argv[anArgIter] << "' is not a document"; + return 1; + } + aDocName = aDocNameStr; + } + else if (aFilePath.IsEmpty()) + { + aFilePath = argv[anArgIter]; + } + else if (!hasModeArg) + { + hasModeArg = true; + switch (anArgCase.Value (1)) + { + case 'a': + case '0': aMode = STEPControl_AsIs; break; + case 'f': + case '1': aMode = STEPControl_FacetedBrep; break; + case 's': + case '2': aMode = STEPControl_ShellBasedSurfaceModel; break; + case 'm': + case '3': aMode = STEPControl_ManifoldSolidBrep; break; + case 'w': + case '4': aMode = STEPControl_GeometricCurveSet; break; + default: + { + di << "Syntax error: mode '" << argv[anArgIter] << "' is incorrect [give fsmw]"; + return 1; + } + } + Standard_Boolean wrmode = Standard_True; + for (Standard_Integer i = 1; i <= anArgCase.Length(); ++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; + } + } + } + else if (aMultiFilePrefix.IsEmpty() + && anArgCase.Search (":") == -1) + { + aMultiFilePrefix = argv[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]; + } + else + { + di << "Syntax error: unknown argument '" << argv[anArgIter] << "'"; + return 1; + } } - if( argc > k) + + if (aFilePath.IsEmpty()) { - - if( !DDF::FindLabel(Doc->Main().Data(), argv[k], label) || label.IsNull()) { - di << "No label for entry" << "\n"; - return 1; - - } + di << "Syntax error: wrong number of arguments"; + return 1; } - TCollection_AsciiString fnom, rnom; - const Standard_Boolean modfic = XSDRAW::FileAndVar(argv[2], argv[1], "STEP", fnom, rnom); + 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", modfic ? 2 : 1); - if (!label.IsNull()) + Message_ProgressScope aRootScope (aProgress->Start(), "STEP export", isFileMode ? 2 : 1); + if (!aLabel.IsNull()) { - di << "Translating label "<< argv[k]<<" of document " << argv[1] << " to STEP\n"; - if (!writer.Transfer (label, mode, multifile, aRootScope.Next())) + di << "Translating label " << aLabelName << " of document " << aDocName << " to STEP\n"; + if (!aWriter.Transfer (aLabel, aMode, + !aMultiFilePrefix.IsEmpty() ? aMultiFilePrefix.ToCString() : NULL, + aRootScope.Next())) { - di << "The label of document cannot be translated or gives no result\n"; + di << "Error: the label of document cannot be translated or gives no result"; return 1; } } else { - di << "Translating document " << argv[1] << " to STEP\n"; - if (!writer.Transfer (Doc, mode, multifile, aRootScope.Next())) + di << "Translating document " << aDocName << " to STEP\n"; + if (!aWriter.Transfer (aDoc, aMode, + !aMultiFilePrefix.IsEmpty() ? aMultiFilePrefix.ToCString() : NULL, + aRootScope.Next())) { - di << "The document cannot be translated or gives no result\n"; + di << "Error: The document cannot be translated or gives no result\n"; } } - if (modfic) + if (!isFileMode) { - Message_ProgressScope aWriteScope (aRootScope.Next(), "File writing", 1); - aWriteScope.Show(); - di << "Writing STEP file " << argv[2] << "\n"; - IFSelect_ReturnStatus stat = writer.Write(argv[2]); - switch (stat) { - case IFSelect_RetVoid : di<<"No file written\n"; break; - case IFSelect_RetDone : { - di<<"File "< DicFile = writer.ExternFiles(); - FillDicWS( DicFile ); - AddWS( argv[2], XSDRAW::Session() ); - break; - } - default : di<<"Error on writing file\n"; break; + 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) + { + 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; } } else { - di << "Document has been translated into the session"; + aStat = aWriter.Write (aFilePath.ToCString()); + } + + switch (aStat) + { + case IFSelect_RetVoid: + { + di << "Error: no file written"; + break; + } + case IFSelect_RetDone: + { + di << "File " << aFilePath << " written\n"; + + NCollection_DataMap aDicFile = aWriter.ExternFiles(); + FillDicWS (aDicFile); + AddWS (aFilePath, XSDRAW::Session()); + break; + } + default: + { + di << "Error on writing file"; + break; + } } return 0; } @@ -701,7 +761,17 @@ void XDEDRAW_Common::InitCommands(Draw_Interpretor& di) "\n\t\t: Read STEP file to a document." "\n\t\t: -stream read using istream reading interface (testing)", __FILE__, ReadStep, g); - di.Add("WriteStep" , "Doc filename [mode=a [multifile_prefix] [label]]: Write DECAF document to STEP file" ,__FILE__, WriteStep, g); + di.Add("WriteStep" , + "Doc filename [mode=a [multifile_prefix] [label]] [-stream]" + "\n\t\t: Write DECAF document to STEP file" + "\n\t\t: mode can be: a or 0 : AsIs (default)" + "\n\t\t: f or 1 : FacettedBRep s or 2 : ShellBasedSurfaceModel" + "\n\t\t: m or 3 : ManifoldSolidBrep w or 4 : GeometricCurveSet/WireFrame" + "\n\t\t: multifile_prefix: triggers writing assembly components as separate files," + "\n\t\t: and defines common prefix for their names" + "\n\t\t: label tag of the sub-assembly label to save only that sub-assembly" + "\n\t\t: -stream read using ostream writing interface (testing)", + __FILE__, WriteStep, g); di.Add("XFileList","Print list of files that was transferred by the last transfer" ,__FILE__, GetDicWSList , g); di.Add("XFileCur", ": returns name of file which is set as current",__FILE__, GetCurWS, g); diff --git a/src/XSDRAWSTEP/XSDRAWSTEP.cxx b/src/XSDRAWSTEP/XSDRAWSTEP.cxx index 5b20f2dfe4..779c4a75e7 100644 --- a/src/XSDRAWSTEP/XSDRAWSTEP.cxx +++ b/src/XSDRAWSTEP/XSDRAWSTEP.cxx @@ -441,22 +441,72 @@ static Standard_Integer stepwrite (Draw_Interpretor& di, Standard_Integer argc, //======================================================================= static Standard_Integer testwrite (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { - if (argc != 3) - { - di << "ERROR in " << argv[0] << "Wrong Number of Arguments.\n"; - di << " Usage : " << argv[0] <<" file_name shape_name \n"; - return 1; + TCollection_AsciiString aFilePath; + TopoDS_Shape aShape; + bool toTestStream = false; + for (Standard_Integer anArgIter = 1; anArgIter <= argc; ++anArgIter) + { + TCollection_AsciiString anArgCase (argv[anArgIter]); + anArgCase.LowerCase(); + if (anArgCase == "-stream") + { + toTestStream = true; } - STEPControl_Writer Writer; - Standard_CString filename = argv[1]; - TopoDS_Shape shape = DBRep::Get(argv[2]); - IFSelect_ReturnStatus stat = Writer.Transfer(shape,STEPControl_AsIs); - stat = Writer.Write(filename); - if(stat != IFSelect_RetDone){ - di<<"Error on writing file\n"; + else if (aFilePath.IsEmpty()) + { + aFilePath = argv[anArgIter]; + } + else if (aShape.IsNull()) + { + aShape = DBRep::Get (argv[anArgIter]); + if (aShape.IsNull()) + { + di << "Syntax error: '" << argv[anArgIter] << "' is not a shape"; + return 1; + } + } + else + { + di << "Syntax error: unknown argument '" << argv[anArgIter] << "'"; + return 1; + } + } + if (aShape.IsNull()) + { + di << "Syntax error: wrong number of arguments"; + return 1; + } + + STEPControl_Writer aWriter; + IFSelect_ReturnStatus aStat = aWriter.Transfer (aShape, STEPControl_AsIs); + if (aStat != IFSelect_RetDone) + { + di << "Error on transferring shape"; + return 1; + } + + if (toTestStream) + { + 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; + } + } + else + { + aStat = aWriter.Write (aFilePath.ToCString()); + } + if (aStat != IFSelect_RetDone) + { + di << "Error on writing file"; return 1; } - di<<"File Is Written\n"; + di << "File Is Written"; return 0; } @@ -556,7 +606,8 @@ void XSDRAWSTEP::InitCommands (Draw_Interpretor& theCommands) XSDRAWSTEP::Init(); XSDRAW::LoadDraw(theCommands); theCommands.Add("stepwrite" , "stepwrite mode[0-4 afsmw] shape", __FILE__, stepwrite, g); - theCommands.Add("testwritestep", "testwritestep filename.stp shape", __FILE__, testwrite, g); + theCommands.Add("testwritestep", "testwritestep filename.stp shape [-stream]", + __FILE__, testwrite, g); theCommands.Add("stepread", "stepread [file] [f or r (type of model full or reduced)]",__FILE__, stepread, g); theCommands.Add("testreadstep", "testreadstep file shape [-stream]",__FILE__, testreadstep, g); theCommands.Add("steptrans", "steptrans shape stepax1 stepax2", __FILE__, steptrans, g); diff --git a/tests/bugs/step/bug32350 b/tests/bugs/step/bug32350 new file mode 100644 index 0000000000..df067282b8 --- /dev/null +++ b/tests/bugs/step/bug32350 @@ -0,0 +1,32 @@ +puts "===================================================" +puts "0032350: Data Exchange - STEPControl_Writer.writeStream(std::ostream)" +puts "===================================================" +puts "" + +pload XDE OCAF MODELING VISUALIZATION +ReadStep D [locate_data_file "as1-oc-214-mat.stp"] -stream +set aTmpFile1 "$imagedir/${casename}_1.stp" +set aTmpFile2 "$imagedir/${casename}_2.stp" + +WriteStep D "$aTmpFile1" +WriteStep D "$aTmpFile2" -stream + +ReadStep D1 "$aTmpFile1" +ReadStep D2 "$aTmpFile2" + +file delete "$aTmpFile1" +file delete "$aTmpFile2" + +vclear +vinit View1 +XDisplay -dispMode 1 D +vfit +vdump "$imagedir/${casename}_src.png" + +vclear +XDisplay -dispMode 1 D1 +vdump "$imagedir/${casename}_out1.png" + +vclear +XDisplay -dispMode 1 D2 +vdump "$imagedir/${casename}_out2.png" -- 2.39.5