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

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.
This commit is contained in:
kgv 2020-10-17 14:04:49 +03:00 committed by bugmaster
parent 3e98579a83
commit 1877dc98c9
3 changed files with 101 additions and 33 deletions

View File

@ -11,10 +11,10 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Draw_ProgressIndicator.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_ProgressIndicator.hxx>
#include <Message.hxx>
#include <Message_Messenger.hxx>
#include <Message_ProgressScope.hxx>
@ -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;
}

View File

@ -24,6 +24,7 @@
#include <DDocStd_DrawDocument.hxx>
#include <Draw.hxx>
#include <Draw_PluginMacro.hxx>
#include <Draw_ProgressIndicator.hxx>
#include <Geom_Axis2Placement.hxx>
#include <Prs3d_Drawer.hxx>
#include <Prs3d_LineAspect.hxx>
@ -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;

View File

@ -18,6 +18,7 @@
#include <DDocStd_DrawDocument.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_ProgressIndicator.hxx>
#include <Message.hxx>
#include <IFSelect_SessionPilot.hxx>
#include <IGESCAFControl_Reader.hxx>
@ -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 "<<fnom.ToCString()<<" , abandon\n";
else di<<"No model loaded\n";
if (modfic)
{
Message_ProgressScope aReadScope (aRootScope.Next(), "File reading", 1);
aReadScope.Show();
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 "<<fnom.ToCString()<<" , abandon\n";
}
else
{
di<<"No model loaded\n";
}
return 1;
}
@ -236,7 +256,8 @@ static Standard_Integer ReadIges (Draw_Interpretor& di, Standard_Integer argc, c
Draw::Set(argv[1],DD);
// di << "Document saved with name " << argv[1];
}
if ( ! reader.Transfer ( doc ) ) {
if (!reader.Transfer (doc, aRootScope.Next()))
{
di << "Cannot read any relevant data from the IGES file\n";
return 1;
}
@ -268,10 +289,16 @@ static Standard_Integer WriteIges (Draw_Interpretor& di, Standard_Integer argc,
}
XSDRAW::SetNorm ("IGES");
TCollection_AsciiString fnom, rnom;
const Standard_Boolean modfic = XSDRAW::FileAndVar(argv[2], argv[1], "IGES", fnom, rnom);
// IGESControl_Writer ICW (Interface_Static::CVal("write.iges.unit"),
// Interface_Static::IVal("write.iges.brep.mode"));
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di);
Message_ProgressScope aRootScope (aProgress->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 "<<fnom.ToCString()<<" , abandon\n";
else di<<"No model loaded\n";
if (modfic)
{
Message_ProgressScope aReadScope (aRootScope.Next(), "File reading", 1);
aReadScope.Show();
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 " << 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) {