]> OCCT Git - occt-copy.git/commitdiff
STEPCAFControl_Writer::WriteStream() - added interface for writing into stream. CR32350
authorkgv <kgv@opencascade.com>
Thu, 27 May 2021 13:13:07 +0000 (16:13 +0300)
committerkgv <kgv@opencascade.com>
Thu, 27 May 2021 13:34:31 +0000 (16:34 +0300)
Added argument -stream to commands WriteStep, testwritestep for testing purposes.

src/STEPCAFControl/STEPCAFControl_Writer.cxx
src/STEPCAFControl/STEPCAFControl_Writer.hxx
src/STEPControl/STEPControl_Writer.cxx
src/STEPControl/STEPControl_Writer.hxx
src/XDEDRAW/XDEDRAW_Common.cxx
src/XSDRAWSTEP/XSDRAWSTEP.cxx
tests/bugs/step/bug32350 [new file with mode: 0644]

index b9ca23fb606741c386b2e60beb426c7f3365e2cd..e269f57cadeaabd892c26295a93465c027376098 100644 (file)
@@ -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<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>::Iterator it(myFiles);
-  for ( ; it.More(); it.Next() ) {
-    Handle(STEPCAFControl_ExternFile) EF = it.Value();
-    if ( EF->GetWriteStatus() != IFSelect_RetVoid ) continue;
+  for (NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>::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
index f74f07877e1e76d03819a80e48075b6893ce7410..c377284845376f83540d1d3786ddc62b570722bd 100644 (file)
@@ -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
index b2dbfd6ab10fff5036208080e4ce93a5668bc10d..fd0558048f2e97f025d0434ff0d3e1896a649dbd 100644 (file)
@@ -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  : 
index 81d60c195da79c03ab3504e990c66616d3b4e548..05b6d9f52e1d557f3485727f3d38c112034512ac 100644 (file)
@@ -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,
index 44cc378ba4eb6b40f39341c0305050c3a9d8637c..a1231e5081fe6e1e6e0e7e60b1fcb7cc37ed0051 100644 (file)
@@ -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 : "<<rnom<<"\n";
 
-  STEPCAFControl_Reader reader ( XSDRAW::Session(),modfic);
+  STEPCAFControl_Reader aReader (XSDRAW::Session(), isFileMode);
   if (!aModeStr.IsEmpty())
   {
-    Standard_Boolean mode = Standard_True;
+    Standard_Boolean aMode = Standard_True;
     for (Standard_Integer i = 1; aModeStr.Value (i); ++i)
     {
       switch (aModeStr.Value (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 'v' : reader.SetPropsMode (mode); break;
+        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;
         default:
         {
           Message::SendFail() << "Syntax error at '" << aModeStr << "'\n";
@@ -406,35 +408,35 @@ static Standard_Integer ReadStep (Draw_Interpretor& di, Standard_Integer argc, c
   }
   
   Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di);
-  Message_ProgressScope aRootScope (aProgress->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<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> 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<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> 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 "<<argv[2]<<" written\n";
-
-        NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> 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<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> 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);
index 5b20f2dfe44e0a9266836e639f6387e04fff222f..779c4a75e71b6e7395d4a548010a86a844430394 100644 (file)
@@ -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 (file)
index 0000000..df06728
--- /dev/null
@@ -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"