From 1877dc98c980ca3a76f9c77119359e303188c09b Mon Sep 17 00:00:00 2001 From: kgv Date: Sat, 17 Oct 2020 14:04:49 +0300 Subject: [PATCH] 0031856: Draw Harness - ReadStep should propagate progress indicator Added progress indication to commands ReadStep, WriteStep, ReadIges, WriteIges, XOpen, XSave. Draw_ProgressIndicator::Reset() now backups Tcl result string before evaluating command, so that Draw_ProgressIndicator destructor will not eat error/result message in main command. --- src/Draw/Draw_ProgressIndicator.cxx | 14 +++- src/XDEDRAW/XDEDRAW.cxx | 10 ++- src/XDEDRAW/XDEDRAW_Common.cxx | 110 +++++++++++++++++++++------- 3 files changed, 101 insertions(+), 33 deletions(-) diff --git a/src/Draw/Draw_ProgressIndicator.cxx b/src/Draw/Draw_ProgressIndicator.cxx index dd075df42c..6b2f4efaae 100644 --- a/src/Draw/Draw_ProgressIndicator.cxx +++ b/src/Draw/Draw_ProgressIndicator.cxx @@ -11,10 +11,10 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include #include -#include #include #include #include @@ -64,8 +64,12 @@ Draw_ProgressIndicator::~Draw_ProgressIndicator() void Draw_ProgressIndicator::Reset() { Message_ProgressIndicator::Reset(); - if ( myShown ) { + if (myShown) + { + // eval will reset current string result - backup it beforehand + const TCollection_AsciiString aTclResStr (myDraw->Result()); myDraw->Eval ( "destroy .xprogress" ); + *myDraw << aTclResStr; myShown = Standard_False; } myBreak = Standard_False; @@ -147,6 +151,8 @@ void Draw_ProgressIndicator::Show (const Message_ProgressScope& theScope, const "/" << ( aTime - myStartTime ) / GetPosition() << " sec"; } + // eval will reset current string result - backup it beforehand + const TCollection_AsciiString aTclResStr (myDraw->Result()); if ( ! myShown ) { char command[1024]; Sprintf ( command, "toplevel .xprogress -height 100 -width 410;" @@ -168,7 +174,9 @@ void Draw_ProgressIndicator::Show (const Message_ProgressScope& theScope, const aCommand << ".xprogress.bar coords progress_next 2 2 " << (1 + 400 * theScope.GetPortion()) << " 21;"; aCommand << ".xprogress.text configure -text \"" << aText.str() << "\";"; aCommand << "update"; + myDraw->Eval (aCommand.str().c_str()); + *myDraw << aTclResStr; } // Print textual progress info @@ -313,5 +321,3 @@ Standard_Address &Draw_ProgressIndicator::StopIndicator() static Standard_Address stopIndicator = 0; return stopIndicator; } - - diff --git a/src/XDEDRAW/XDEDRAW.cxx b/src/XDEDRAW/XDEDRAW.cxx index 7f577ce167..ba4365b13e 100644 --- a/src/XDEDRAW/XDEDRAW.cxx +++ b/src/XDEDRAW/XDEDRAW.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -147,11 +148,13 @@ static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, co if (!DDocStd::GetDocument(argv[1],D)) return 1; } + Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di); + PCDM_StoreStatus aStatus = PCDM_SS_Doc_IsNull; if (argc == 3) { TCollection_ExtendedString path (argv[2]); - aStatus = A->SaveAs (D, path); + aStatus = A->SaveAs (D, path, aProgress->Start()); } else if (!D->IsSaved()) { @@ -160,7 +163,7 @@ static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, co } else { - aStatus = A->Save(D); + aStatus = A->Save (D, aProgress->Start()); } switch (aStatus) @@ -218,7 +221,8 @@ static Standard_Integer openDoc (Draw_Interpretor& di, Standard_Integer argc, co return 1; } - if ( A->Open(Filename, D) != PCDM_RS_OK ) + Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di); + if ( A->Open(Filename, D, aProgress->Start()) != PCDM_RS_OK ) { di << "cannot open XDE document\n"; return 1; diff --git a/src/XDEDRAW/XDEDRAW_Common.cxx b/src/XDEDRAW/XDEDRAW_Common.cxx index a84d43962d..ac9a94b25a 100644 --- a/src/XDEDRAW/XDEDRAW_Common.cxx +++ b/src/XDEDRAW/XDEDRAW_Common.cxx @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -218,12 +219,31 @@ static Standard_Integer ReadIges (Draw_Interpretor& di, Standard_Integer argc, c case 'l' : reader.SetLayerMode (mode); break; } } + + Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di); + Message_ProgressScope aRootScope (aProgress->Start(), "IGES import", modfic ? 2 : 1); + IFSelect_ReturnStatus readstat = IFSelect_RetVoid; - if (modfic) readstat = reader.ReadFile (fnom.ToCString()); - else if (XSDRAW::Session()->NbStartingEntities() > 0) readstat = IFSelect_RetDone; - if (readstat != IFSelect_RetDone) { - if (modfic) di<<"Could not read file "<NbStartingEntities() > 0) + { + readstat = IFSelect_RetDone; + } + if (readstat != IFSelect_RetDone) + { + if (modfic) + { + di<<"Could not read file "<Start(), "IGES export", modfic ? 2 : 1); + IGESCAFControl_Writer writer ( XSDRAW::Session(), Standard_True ); if (argc == 4) { Standard_Boolean mode = Standard_True; @@ -284,15 +311,21 @@ static Standard_Integer WriteIges (Draw_Interpretor& di, Standard_Integer argc, case 'l' : writer.SetLayerMode (mode); break; } } - writer.Transfer ( Doc ); + writer.Transfer (Doc, aRootScope.Next()); - TCollection_AsciiString fnom, rnom; - Standard_Boolean modfic = XSDRAW::FileAndVar(argv[2], argv[1], "IGES", fnom, rnom); if (modfic) { - di << "Writig IGES model to file " << argv[2] << "\n"; - if ( writer.Write ( argv[2] ) ) di<<" Write OK\n"; - else di<<" Write failed\n"; + Message_ProgressScope aWriteScope (aRootScope.Next(), "File writing", 1); + aWriteScope.Show(); + di << "Writing IGES model to file " << argv[2] << "\n"; + if (writer.Write (argv[2])) + { + di << " Write OK\n"; + } + else + { + di << " Write failed\n"; + } } else { @@ -365,12 +398,30 @@ 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); + IFSelect_ReturnStatus readstat = IFSelect_RetVoid; - if (modfic) readstat = reader.ReadFile (fnom.ToCString()); - else if (XSDRAW::Session()->NbStartingEntities() > 0) readstat = IFSelect_RetDone; - if (readstat != IFSelect_RetDone) { - if (modfic) di<<"Could not read file "<NbStartingEntities() > 0) + { + readstat = IFSelect_RetDone; + } + if (readstat != IFSelect_RetDone) + { + if (modfic) + { + di << "Could not read file " << fnom << " , abandon\n"; + } + else + { + di << "No model loaded\n"; + } return 1; } @@ -384,7 +435,8 @@ static Standard_Integer ReadStep (Draw_Interpretor& di, Standard_Integer argc, c Draw::Set (aDocName, DD); // di << "Document saved with name " << aDocName; } - if ( ! reader.Transfer ( doc ) ) { + if (!reader.Transfer (doc, aRootScope.Next())) + { di << "Cannot read any relevant data from the STEP file\n"; return 1; } @@ -476,28 +528,34 @@ static Standard_Integer WriteStep (Draw_Interpretor& di, Standard_Integer argc, } } - if( !label.IsNull()) + + TCollection_AsciiString fnom, rnom; + const Standard_Boolean modfic = XSDRAW::FileAndVar(argv[2], argv[1], "STEP", fnom, rnom); + + Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di); + Message_ProgressScope aRootScope (aProgress->Start(), "STEP export", modfic ? 2 : 1); + if (!label.IsNull()) { di << "Translating label "<< argv[k]<<" of document " << argv[1] << " to STEP\n"; - if(!writer.Transfer ( label, mode, multifile )) + if (!writer.Transfer (label, mode, multifile, aRootScope.Next())) { di << "The label of document cannot be translated or gives no result\n"; return 1; } - } else { di << "Translating document " << argv[1] << " to STEP\n"; - if ( ! writer.Transfer ( Doc, mode, multifile ) ) { + if (!writer.Transfer (Doc, mode, multifile, aRootScope.Next())) + { di << "The document cannot be translated or gives no result\n"; } } - - TCollection_AsciiString fnom, rnom; - Standard_Boolean modfic = XSDRAW::FileAndVar(argv[2], argv[1], "STEP", fnom, rnom); + if (modfic) { + 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) {