From caee80f39fc059c59f040dcc5a603d3cee158d02 Mon Sep 17 00:00:00 2001 From: mzernova Date: Mon, 6 May 2019 23:05:13 +0300 Subject: [PATCH] 0030697: Draw Harness - Draw_Printer should not be set to Message::DefaultMessenger() by default Fixed bugs that occurred when using the default std::cout from Message::DefaultMessenger() instead of Draw_Printer A dedicated option was added to Draw_ProgressIndicator, for outputting data to the tcl when performing tests Added -tclOutput parameter to XProgress command --- src/BOPTest/BOPTest.cxx | 4 ++- src/DBRep/DBRep.cxx | 24 ++++++++++++--- src/Draw/Draw_Commands.cxx | 18 ----------- src/Draw/Draw_ProgressIndicator.cxx | 48 ++++++++++++++++++++--------- src/Draw/Draw_ProgressIndicator.hxx | 16 ++++++++-- src/QABugs/QABugs_11.cxx | 1 + src/QABugs/QABugs_19.cxx | 24 ++++++++++++++- src/XSDRAW/XSDRAW.cxx | 14 ++++++++- tests/bugs/modalg_5/bug22747 | 1 + tests/bugs/moddata_2/bug22572 | 1 + tests/bugs/moddata_2/bug22746_1 | 1 + tests/bugs/moddata_2/bug22746_2 | 1 + tests/bugs/moddata_2/bug22746_3 | 1 + 13 files changed, 112 insertions(+), 42 deletions(-) diff --git a/src/BOPTest/BOPTest.cxx b/src/BOPTest/BOPTest.cxx index 1f797ecae6..23c67bddeb 100644 --- a/src/BOPTest/BOPTest.cxx +++ b/src/BOPTest/BOPTest.cxx @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -136,7 +137,8 @@ void BOPTest::ReportAlerts(const Handle(Message_Report)& theReport) } // output message with list of shapes - Message::DefaultMessenger()->Send (aText, anAlertTypes[iGravity]); + Draw_Interpretor& aDrawInterpretor = Draw::GetInterpretor(); + aDrawInterpretor << aText << "\n"; } } } diff --git a/src/DBRep/DBRep.cxx b/src/DBRep/DBRep.cxx index 0641003640..f5d8ad9b15 100644 --- a/src/DBRep/DBRep.cxx +++ b/src/DBRep/DBRep.cxx @@ -1332,13 +1332,23 @@ TopoDS_Shape DBRep::getShape (Standard_CString& theName, static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc, const char **argv) { - for ( Standard_Integer i=1; i < argc; i++ ) { + for ( Standard_Integer i=1; i < argc; i++ ) + { Standard_Boolean turn = Standard_True; if ( argv[i][0] == '-' ) turn = Standard_False; else if ( argv[i][0] != '+' ) continue; - if ( argv[i][1] == 't' ) Draw_ProgressIndicator::DefaultTextMode() = turn; + + TCollection_AsciiString anArgCase (argv[i]); + anArgCase.LowerCase(); + if (anArgCase == "-tcloutput") + { + Draw_ProgressIndicator::DefaultTclOutput() = Standard_True; + return 0; + } + else if ( argv[i][1] == 't' ) Draw_ProgressIndicator::DefaultTextMode() = turn; else if ( argv[i][1] == 'g' ) Draw_ProgressIndicator::DefaultGraphMode() = turn; - else if ( ! strcmp ( argv[i], "-stop" ) && i+1 < argc ) { + else if ( ! strcmp ( argv[i], "-stop" ) && i+1 < argc ) + { Standard_Address aPtr = 0; if (sscanf (argv[++i], "%p", &aPtr) == 1) Draw_ProgressIndicator::StopIndicator() = aPtr; @@ -1463,7 +1473,13 @@ void DBRep::BasicCommands(Draw_Interpretor& theCommands) __FILE__,purgemmgt,g); // Add command for DRAW-specific ProgressIndicator - theCommands.Add ( "XProgress","XProgress [+|-t] [+|-g]: switch on/off textual and graphical mode of Progress Indicator",XProgress,"DE: General"); + theCommands.Add ( "XProgress", + "XProgress [+|-t] [+|-g] [-tclOutput]" + "\n\t\t: The options are:" + "\n\t\t: +|-t, +|-g : switch on/off textual and graphical mode of Progress Indicator" + "\n\t\t: -tclOutput : switch on data output mode in tcl" + "\n\t\t: Allows to control the output form of Progress Indicator", + XProgress,"DE: General"); theCommands.Add("binsave", "binsave shape filename\n" "\t\tsave the shape in the binary format file", diff --git a/src/Draw/Draw_Commands.cxx b/src/Draw/Draw_Commands.cxx index 6444f5d722..c375f9eeda 100644 --- a/src/Draw/Draw_Commands.cxx +++ b/src/Draw/Draw_Commands.cxx @@ -17,29 +17,11 @@ #include #include -#include #include -#include -#include -#include #include void Draw::Commands (Draw_Interpretor& theCommands) { - static Standard_Boolean isFirstTime = Standard_True; - if (isFirstTime) - { - // override default std::cout printer by draw interpretor printer - const Handle(Message_Messenger)& aMsgMgr = Message::DefaultMessenger(); - if (!aMsgMgr.IsNull()) - { - aMsgMgr->RemovePrinters (STANDARD_TYPE (Message_PrinterOStream)); - aMsgMgr->RemovePrinters (STANDARD_TYPE (Draw_Printer)); - aMsgMgr->AddPrinter (new Draw_Printer (theCommands)); - } - isFirstTime = Standard_False; - } - Draw::BasicCommands(theCommands); Draw::VariableCommands(theCommands); Draw::GraphicCommands(theCommands); diff --git a/src/Draw/Draw_ProgressIndicator.cxx b/src/Draw/Draw_ProgressIndicator.cxx index 8c68e7e954..6c92b2dda6 100644 --- a/src/Draw/Draw_ProgressIndicator.cxx +++ b/src/Draw/Draw_ProgressIndicator.cxx @@ -31,7 +31,8 @@ IMPLEMENT_STANDARD_RTTIEXT(Draw_ProgressIndicator,Message_ProgressIndicator) Draw_ProgressIndicator::Draw_ProgressIndicator (const Draw_Interpretor &di, Standard_Real theUpdateThreshold) : myTextMode ( DefaultTextMode() ), myGraphMode ( DefaultGraphMode() ), - myDraw ( (Standard_Address)&di ), + myTclOutput ( DefaultTclOutput() ), + myDraw ( (Draw_Interpretor*)&di ), myShown ( Standard_False ), myBreak ( Standard_False ), myUpdateThreshold ( 0.01 * theUpdateThreshold ), @@ -59,7 +60,7 @@ void Draw_ProgressIndicator::Reset() { Message_ProgressIndicator::Reset(); if ( myShown ) { - ((Draw_Interpretor*)myDraw)->Eval ( "destroy .xprogress" ); + myDraw->Eval ( "destroy .xprogress" ); myShown = Standard_False; } myBreak = Standard_False; @@ -145,7 +146,7 @@ Standard_Boolean Draw_ProgressIndicator::Show(const Standard_Boolean force) "message .xprogress.text -width 400 -text \"Progress 0%%\";" "button .xprogress.stop -text \"Break\" -relief groove -width 9 -command {XProgress -stop %p};" "pack .xprogress.bar .xprogress.text .xprogress.stop -side top;", this ); - ((Draw_Interpretor*)myDraw)->Eval ( command ); + myDraw->Eval ( command ); myShown = Standard_True; } std::stringstream aCommand; @@ -155,16 +156,24 @@ Standard_Boolean Draw_ProgressIndicator::Show(const Standard_Boolean force) aCommand << ".xprogress.bar coords progress_next 2 2 " << (1 + 400 * GetScope(1).GetLast()) << " 21;"; aCommand << ".xprogress.text configure -text \"" << aText.str() << "\";"; aCommand << "update"; - ((Draw_Interpretor*)myDraw)->Eval (aCommand.str().c_str()); + myDraw->Eval (aCommand.str().c_str()); } // Print textual progress info - if ( myTextMode ) - Message::DefaultMessenger()->Send (aText.str().c_str(), Message_Info); - + if (myTextMode) + { + if (myTclOutput && myDraw) + { + *myDraw << aText.str().c_str() << "\n"; + } + else + { + std::cout << aText.str().c_str() << "\n"; + } + } return Standard_True; } - + //======================================================================= //function : UserBreak //purpose : @@ -175,7 +184,7 @@ Standard_Boolean Draw_ProgressIndicator::UserBreak() if ( StopIndicator() == this ) { // std::cout << "Progress Indicator - User Break: " << StopIndicator() << ", " << (void*)this << std::endl; myBreak = Standard_True; - ((Draw_Interpretor*)myDraw)->Eval ( "XProgress -stop 0" ); + myDraw->Eval ( "XProgress -stop 0" ); } return myBreak; } @@ -225,29 +234,40 @@ Standard_Boolean Draw_ProgressIndicator::GetGraphMode() const //purpose : //======================================================================= -Standard_Boolean &Draw_ProgressIndicator::DefaultTextMode () +Standard_Boolean &Draw_ProgressIndicator::DefaultTextMode() { static Standard_Boolean defTextMode = Standard_False; return defTextMode; } - + //======================================================================= //function : DefaultGraphMode //purpose : //======================================================================= -Standard_Boolean &Draw_ProgressIndicator::DefaultGraphMode () +Standard_Boolean &Draw_ProgressIndicator::DefaultGraphMode() { static Standard_Boolean defGraphMode = Standard_False; return defGraphMode; } - + +//======================================================================= +//function : DefaultTclOutput +//purpose : +//======================================================================= + +Standard_Boolean &Draw_ProgressIndicator::DefaultTclOutput() +{ + static Standard_Boolean defTclOutput = Standard_False; + return defTclOutput; +} + //======================================================================= //function : StopIndicator //purpose : //======================================================================= -Standard_Address &Draw_ProgressIndicator::StopIndicator () +Standard_Address &Draw_ProgressIndicator::StopIndicator() { static Standard_Address stopIndicator = 0; return stopIndicator; diff --git a/src/Draw/Draw_ProgressIndicator.hxx b/src/Draw/Draw_ProgressIndicator.hxx index bfb6710e4d..0bfcfdbc33 100644 --- a/src/Draw/Draw_ProgressIndicator.hxx +++ b/src/Draw/Draw_ProgressIndicator.hxx @@ -54,7 +54,13 @@ public: //! Gets graphical output mode (on/off) Standard_EXPORT Standard_Boolean GetGraphMode() const; - + + //! Sets tcl output mode (on/off) + void SetTclOutput (const Standard_Boolean theTclOutput) { myTclOutput = theTclOutput; } + + //! Gets tcl output mode (on/off) + Standard_Boolean GetTclOutput() const { return myTclOutput; } + //! Clears/erases opened TCL windows if any //! and sets myBreak to False Standard_EXPORT virtual void Reset() Standard_OVERRIDE; @@ -69,7 +75,10 @@ public: //! Get/Set default values for output modes Standard_EXPORT static Standard_Boolean& DefaultGraphMode(); - + + //! Get/Set default values for tcl output mode + Standard_EXPORT static Standard_Boolean& DefaultTclOutput(); + //! Internal method for implementation of UserBreak mechanism; //! note that it uses static variable and thus not thread-safe! Standard_EXPORT static Standard_Address& StopIndicator(); @@ -79,7 +88,8 @@ public: private: Standard_Boolean myTextMode; Standard_Boolean myGraphMode; - Standard_Address myDraw; + Standard_Boolean myTclOutput; + Draw_Interpretor* myDraw; Standard_Boolean myShown; Standard_Boolean myBreak; Standard_Real myUpdateThreshold; diff --git a/src/QABugs/QABugs_11.cxx b/src/QABugs/QABugs_11.cxx index c7012e849e..dff3a55c62 100644 --- a/src/QABugs/QABugs_11.cxx +++ b/src/QABugs/QABugs_11.cxx @@ -4753,6 +4753,7 @@ Standard_Integer OCC28478 (Draw_Interpretor& di, Standard_Integer argc, const ch // test behavior of progress indicator when using nested scopes with names set by Sentry objects Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1); aProgress->SetTextMode (Standard_True); + aProgress->SetTclOutput (Standard_True); // Outer cycle Message_ProgressSentry anOuter (aProgress, "Outer", 0, nbOuter, 1); diff --git a/src/QABugs/QABugs_19.cxx b/src/QABugs/QABugs_19.cxx index d61fcc5c3e..b87dfa16e7 100644 --- a/src/QABugs/QABugs_19.cxx +++ b/src/QABugs/QABugs_19.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -1702,7 +1706,16 @@ static Standard_Integer OCC23951 (Draw_Interpretor& di, Standard_Integer argc, c return 1; } - writer.Write(argv[1]); + const Handle(Message_Messenger)& aMsgMgr = Message::DefaultMessenger(); + Message_SequenceOfPrinters aPrinters; + aPrinters.Append (aMsgMgr->ChangePrinters()); + aMsgMgr->AddPrinter (new Draw_Printer (di)); + + writer.Write (argv[1]); + + aMsgMgr->RemovePrinters (STANDARD_TYPE(Draw_Printer)); + aMsgMgr->ChangePrinters().Append (aPrinters); + return 0; } @@ -1745,7 +1758,16 @@ static Standard_Integer OCC23950 (Draw_Interpretor& di, Standard_Integer argc, c return 1; } + const Handle(Message_Messenger)& aMsgMgr = Message::DefaultMessenger(); + Message_SequenceOfPrinters aPrinters; + aPrinters.Append (aMsgMgr->ChangePrinters()); + aMsgMgr->AddPrinter (new Draw_Printer (di)); + writer.Write (argv[1]); + + aMsgMgr->RemovePrinters (STANDARD_TYPE(Draw_Printer)); + aMsgMgr->ChangePrinters().Append (aPrinters); + return 0; } diff --git a/src/XSDRAW/XSDRAW.cxx b/src/XSDRAW/XSDRAW.cxx index 9bf22b69e6..0114302f5f 100644 --- a/src/XSDRAW/XSDRAW.cxx +++ b/src/XSDRAW/XSDRAW.cxx @@ -14,12 +14,15 @@ #include #include +#include #include #include #include #include #include #include +#include +#include #include #include #include @@ -48,14 +51,23 @@ static Handle(TColStd_HSequenceOfAsciiString) thenews; static Handle(IFSelect_SessionPilot) thepilot; // detient Session, Model -static Standard_Integer XSTEPDRAWRUN (Draw_Interpretor& , Standard_Integer argc, const char** argv) +static Standard_Integer XSTEPDRAWRUN (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { TCollection_AsciiString mess; for (Standard_Integer i = 0; i < argc; i ++) { mess.AssignCat(argv[i]); mess.AssignCat(" "); } + const Handle(Message_Messenger)& aMsgMgr = Message::DefaultMessenger(); + Message_SequenceOfPrinters aPrinters; + aPrinters.Append (aMsgMgr->ChangePrinters()); + aMsgMgr->AddPrinter (new Draw_Printer (di)); + IFSelect_ReturnStatus stat = thepilot->Execute (mess.ToCString()); + + aMsgMgr->RemovePrinters (STANDARD_TYPE(Draw_Printer)); + aMsgMgr->ChangePrinters().Append (aPrinters); + if (stat == IFSelect_RetError || stat == IFSelect_RetFail) return 1; else return 0; } diff --git a/tests/bugs/modalg_5/bug22747 b/tests/bugs/modalg_5/bug22747 index 5f58c89d34..19365a8c62 100644 --- a/tests/bugs/modalg_5/bug22747 +++ b/tests/bugs/modalg_5/bug22747 @@ -12,6 +12,7 @@ pload XSDRAW restore [locate_data_file OCC22765.brep] a vinit +XProgress -tclOutput XProgress -t set List1 [sewing result 0.1 a] if { [string compare $List1 ""] != 0 } { diff --git a/tests/bugs/moddata_2/bug22572 b/tests/bugs/moddata_2/bug22572 index da7d65a52c..e0adc028ff 100755 --- a/tests/bugs/moddata_2/bug22572 +++ b/tests/bugs/moddata_2/bug22572 @@ -10,6 +10,7 @@ set BugNumber OCC22572 catch { pload XSDRAW } vinit +XProgress -tclOutput XProgress -t set List1 [meshfromstl result [locate_data_file bearing.stl]] puts "----------------------" diff --git a/tests/bugs/moddata_2/bug22746_1 b/tests/bugs/moddata_2/bug22746_1 index 8baeee9cf8..7ca33e8973 100755 --- a/tests/bugs/moddata_2/bug22746_1 +++ b/tests/bugs/moddata_2/bug22746_1 @@ -11,6 +11,7 @@ set BugNumber OCC22746 catch { pload XSDRAW } restore [locate_data_file OCC22746-om.brep] a vinit +XProgress -tclOutput XProgress -t set List1 [fixshape result a] puts "----------------------" diff --git a/tests/bugs/moddata_2/bug22746_2 b/tests/bugs/moddata_2/bug22746_2 index 141fd897b3..4318a9edbb 100755 --- a/tests/bugs/moddata_2/bug22746_2 +++ b/tests/bugs/moddata_2/bug22746_2 @@ -11,6 +11,7 @@ set BugNumber OCC22746 catch { pload XSDRAW } restore [locate_data_file OCC22746-trampafus-notfixed.brep] a vinit +XProgress -tclOutput XProgress -t set List1 [fixshape result a] puts "----------------------" diff --git a/tests/bugs/moddata_2/bug22746_3 b/tests/bugs/moddata_2/bug22746_3 index aa24416784..987fc6c70a 100755 --- a/tests/bugs/moddata_2/bug22746_3 +++ b/tests/bugs/moddata_2/bug22746_3 @@ -14,6 +14,7 @@ catch { pload XSDRAW } restore [locate_data_file OCC22761-TransmissionTestModel5-notfixed.brep] a vinit +XProgress -tclOutput XProgress -t set List1 [fixshape result a] puts "----------------------" -- 2.20.1