1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-16 10:08:36 +03:00

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
This commit is contained in:
mzernova 2019-05-06 23:05:13 +03:00 committed by bugmaster
parent 01b2f506d6
commit caee80f39f
13 changed files with 112 additions and 42 deletions

View File

@ -17,6 +17,7 @@
#include <BOPTest.hxx> #include <BOPTest.hxx>
#include <BRepTest.hxx> #include <BRepTest.hxx>
#include <DBRep.hxx> #include <DBRep.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx> #include <Draw_Interpretor.hxx>
#include <Draw_PluginMacro.hxx> #include <Draw_PluginMacro.hxx>
#include <GeometryTest.hxx> #include <GeometryTest.hxx>
@ -136,7 +137,8 @@ void BOPTest::ReportAlerts(const Handle(Message_Report)& theReport)
} }
// output message with list of shapes // output message with list of shapes
Message::DefaultMessenger()->Send (aText, anAlertTypes[iGravity]); Draw_Interpretor& aDrawInterpretor = Draw::GetInterpretor();
aDrawInterpretor << aText << "\n";
} }
} }
} }

View File

@ -1332,13 +1332,23 @@ TopoDS_Shape DBRep::getShape (Standard_CString& theName,
static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc, const char **argv) 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; Standard_Boolean turn = Standard_True;
if ( argv[i][0] == '-' ) turn = Standard_False; if ( argv[i][0] == '-' ) turn = Standard_False;
else if ( argv[i][0] != '+' ) continue; 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 ( 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; Standard_Address aPtr = 0;
if (sscanf (argv[++i], "%p", &aPtr) == 1) if (sscanf (argv[++i], "%p", &aPtr) == 1)
Draw_ProgressIndicator::StopIndicator() = aPtr; Draw_ProgressIndicator::StopIndicator() = aPtr;
@ -1463,7 +1473,13 @@ void DBRep::BasicCommands(Draw_Interpretor& theCommands)
__FILE__,purgemmgt,g); __FILE__,purgemmgt,g);
// Add command for DRAW-specific ProgressIndicator // 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" theCommands.Add("binsave", "binsave shape filename\n"
"\t\tsave the shape in the binary format file", "\t\tsave the shape in the binary format file",

View File

@ -17,29 +17,11 @@
#include <Draw.hxx> #include <Draw.hxx>
#include <Draw_Drawable3D.hxx> #include <Draw_Drawable3D.hxx>
#include <Draw_Printer.hxx>
#include <Draw_ProgressIndicator.hxx> #include <Draw_ProgressIndicator.hxx>
#include <Message.hxx>
#include <Message_Messenger.hxx>
#include <Message_PrinterOStream.hxx>
#include <TCollection_AsciiString.hxx> #include <TCollection_AsciiString.hxx>
void Draw::Commands (Draw_Interpretor& theCommands) 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::BasicCommands(theCommands);
Draw::VariableCommands(theCommands); Draw::VariableCommands(theCommands);
Draw::GraphicCommands(theCommands); Draw::GraphicCommands(theCommands);

View File

@ -31,7 +31,8 @@ IMPLEMENT_STANDARD_RTTIEXT(Draw_ProgressIndicator,Message_ProgressIndicator)
Draw_ProgressIndicator::Draw_ProgressIndicator (const Draw_Interpretor &di, Standard_Real theUpdateThreshold) Draw_ProgressIndicator::Draw_ProgressIndicator (const Draw_Interpretor &di, Standard_Real theUpdateThreshold)
: myTextMode ( DefaultTextMode() ), : myTextMode ( DefaultTextMode() ),
myGraphMode ( DefaultGraphMode() ), myGraphMode ( DefaultGraphMode() ),
myDraw ( (Standard_Address)&di ), myTclOutput ( DefaultTclOutput() ),
myDraw ( (Draw_Interpretor*)&di ),
myShown ( Standard_False ), myShown ( Standard_False ),
myBreak ( Standard_False ), myBreak ( Standard_False ),
myUpdateThreshold ( 0.01 * theUpdateThreshold ), myUpdateThreshold ( 0.01 * theUpdateThreshold ),
@ -59,7 +60,7 @@ void Draw_ProgressIndicator::Reset()
{ {
Message_ProgressIndicator::Reset(); Message_ProgressIndicator::Reset();
if ( myShown ) { if ( myShown ) {
((Draw_Interpretor*)myDraw)->Eval ( "destroy .xprogress" ); myDraw->Eval ( "destroy .xprogress" );
myShown = Standard_False; myShown = Standard_False;
} }
myBreak = 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%%\";" "message .xprogress.text -width 400 -text \"Progress 0%%\";"
"button .xprogress.stop -text \"Break\" -relief groove -width 9 -command {XProgress -stop %p};" "button .xprogress.stop -text \"Break\" -relief groove -width 9 -command {XProgress -stop %p};"
"pack .xprogress.bar .xprogress.text .xprogress.stop -side top;", this ); "pack .xprogress.bar .xprogress.text .xprogress.stop -side top;", this );
((Draw_Interpretor*)myDraw)->Eval ( command ); myDraw->Eval ( command );
myShown = Standard_True; myShown = Standard_True;
} }
std::stringstream aCommand; std::stringstream aCommand;
@ -155,13 +156,21 @@ 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.bar coords progress_next 2 2 " << (1 + 400 * GetScope(1).GetLast()) << " 21;";
aCommand << ".xprogress.text configure -text \"" << aText.str() << "\";"; aCommand << ".xprogress.text configure -text \"" << aText.str() << "\";";
aCommand << "update"; aCommand << "update";
((Draw_Interpretor*)myDraw)->Eval (aCommand.str().c_str()); myDraw->Eval (aCommand.str().c_str());
} }
// Print textual progress info // Print textual progress info
if ( myTextMode ) if (myTextMode)
Message::DefaultMessenger()->Send (aText.str().c_str(), Message_Info); {
if (myTclOutput && myDraw)
{
*myDraw << aText.str().c_str() << "\n";
}
else
{
std::cout << aText.str().c_str() << "\n";
}
}
return Standard_True; return Standard_True;
} }
@ -175,7 +184,7 @@ Standard_Boolean Draw_ProgressIndicator::UserBreak()
if ( StopIndicator() == this ) { if ( StopIndicator() == this ) {
// std::cout << "Progress Indicator - User Break: " << StopIndicator() << ", " << (void*)this << std::endl; // std::cout << "Progress Indicator - User Break: " << StopIndicator() << ", " << (void*)this << std::endl;
myBreak = Standard_True; myBreak = Standard_True;
((Draw_Interpretor*)myDraw)->Eval ( "XProgress -stop 0" ); myDraw->Eval ( "XProgress -stop 0" );
} }
return myBreak; return myBreak;
} }
@ -225,7 +234,7 @@ Standard_Boolean Draw_ProgressIndicator::GetGraphMode() const
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Boolean &Draw_ProgressIndicator::DefaultTextMode () Standard_Boolean &Draw_ProgressIndicator::DefaultTextMode()
{ {
static Standard_Boolean defTextMode = Standard_False; static Standard_Boolean defTextMode = Standard_False;
return defTextMode; return defTextMode;
@ -236,18 +245,29 @@ Standard_Boolean &Draw_ProgressIndicator::DefaultTextMode ()
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Boolean &Draw_ProgressIndicator::DefaultGraphMode () Standard_Boolean &Draw_ProgressIndicator::DefaultGraphMode()
{ {
static Standard_Boolean defGraphMode = Standard_False; static Standard_Boolean defGraphMode = Standard_False;
return defGraphMode; return defGraphMode;
} }
//=======================================================================
//function : DefaultTclOutput
//purpose :
//=======================================================================
Standard_Boolean &Draw_ProgressIndicator::DefaultTclOutput()
{
static Standard_Boolean defTclOutput = Standard_False;
return defTclOutput;
}
//======================================================================= //=======================================================================
//function : StopIndicator //function : StopIndicator
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Address &Draw_ProgressIndicator::StopIndicator () Standard_Address &Draw_ProgressIndicator::StopIndicator()
{ {
static Standard_Address stopIndicator = 0; static Standard_Address stopIndicator = 0;
return stopIndicator; return stopIndicator;

View File

@ -55,6 +55,12 @@ public:
//! Gets graphical output mode (on/off) //! Gets graphical output mode (on/off)
Standard_EXPORT Standard_Boolean GetGraphMode() const; 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 //! Clears/erases opened TCL windows if any
//! and sets myBreak to False //! and sets myBreak to False
Standard_EXPORT virtual void Reset() Standard_OVERRIDE; Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
@ -70,6 +76,9 @@ public:
//! Get/Set default values for output modes //! Get/Set default values for output modes
Standard_EXPORT static Standard_Boolean& DefaultGraphMode(); 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; //! Internal method for implementation of UserBreak mechanism;
//! note that it uses static variable and thus not thread-safe! //! note that it uses static variable and thus not thread-safe!
Standard_EXPORT static Standard_Address& StopIndicator(); Standard_EXPORT static Standard_Address& StopIndicator();
@ -79,7 +88,8 @@ public:
private: private:
Standard_Boolean myTextMode; Standard_Boolean myTextMode;
Standard_Boolean myGraphMode; Standard_Boolean myGraphMode;
Standard_Address myDraw; Standard_Boolean myTclOutput;
Draw_Interpretor* myDraw;
Standard_Boolean myShown; Standard_Boolean myShown;
Standard_Boolean myBreak; Standard_Boolean myBreak;
Standard_Real myUpdateThreshold; Standard_Real myUpdateThreshold;

View File

@ -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 // test behavior of progress indicator when using nested scopes with names set by Sentry objects
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1); Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1);
aProgress->SetTextMode (Standard_True); aProgress->SetTextMode (Standard_True);
aProgress->SetTclOutput (Standard_True);
// Outer cycle // Outer cycle
Message_ProgressSentry anOuter (aProgress, "Outer", 0, nbOuter, 1); Message_ProgressSentry anOuter (aProgress, "Outer", 0, nbOuter, 1);

View File

@ -23,6 +23,7 @@
#include <BRepPrimAPI_MakeSphere.hxx> #include <BRepPrimAPI_MakeSphere.hxx>
#include <DBRep.hxx> #include <DBRep.hxx>
#include <Draw_Interpretor.hxx> #include <Draw_Interpretor.hxx>
#include <Draw_Printer.hxx>
#include <DrawTrSurf.hxx> #include <DrawTrSurf.hxx>
#include <GCE2d_MakeSegment.hxx> #include <GCE2d_MakeSegment.hxx>
#include <Geom2d_TrimmedCurve.hxx> #include <Geom2d_TrimmedCurve.hxx>
@ -33,6 +34,9 @@
#include <gp_Quaternion.hxx> #include <gp_Quaternion.hxx>
#include <Image_Color.hxx> #include <Image_Color.hxx>
#include <Image_PixMap.hxx> #include <Image_PixMap.hxx>
#include <Message.hxx>
#include <Message_Messenger.hxx>
#include <Message_PrinterOStream.hxx>
#include <NCollection_Handle.hxx> #include <NCollection_Handle.hxx>
#include <NCollection_IncAllocator.hxx> #include <NCollection_IncAllocator.hxx>
#include <NCollection_Map.hxx> #include <NCollection_Map.hxx>
@ -1702,7 +1706,16 @@ static Standard_Integer OCC23951 (Draw_Interpretor& di, Standard_Integer argc, c
return 1; 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; return 0;
} }
@ -1745,7 +1758,16 @@ static Standard_Integer OCC23950 (Draw_Interpretor& di, Standard_Integer argc, c
return 1; 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]); writer.Write (argv[1]);
aMsgMgr->RemovePrinters (STANDARD_TYPE(Draw_Printer));
aMsgMgr->ChangePrinters().Append (aPrinters);
return 0; return 0;
} }

View File

@ -14,12 +14,15 @@
#include <DBRep.hxx> #include <DBRep.hxx>
#include <Draw_Appli.hxx> #include <Draw_Appli.hxx>
#include <Draw_Printer.hxx>
#include <IFSelect_Functions.hxx> #include <IFSelect_Functions.hxx>
#include <IFSelect_SessionPilot.hxx> #include <IFSelect_SessionPilot.hxx>
#include <Interface_InterfaceModel.hxx> #include <Interface_InterfaceModel.hxx>
#include <Interface_Macros.hxx> #include <Interface_Macros.hxx>
#include <Interface_Protocol.hxx> #include <Interface_Protocol.hxx>
#include <Message.hxx> #include <Message.hxx>
#include <Message_Messenger.hxx>
#include <Message_PrinterOStream.hxx>
#include <Standard_Transient.hxx> #include <Standard_Transient.hxx>
#include <TCollection_AsciiString.hxx> #include <TCollection_AsciiString.hxx>
#include <TColStd_HSequenceOfAsciiString.hxx> #include <TColStd_HSequenceOfAsciiString.hxx>
@ -48,14 +51,23 @@ static Handle(TColStd_HSequenceOfAsciiString) thenews;
static Handle(IFSelect_SessionPilot) thepilot; // detient Session, Model 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; TCollection_AsciiString mess;
for (Standard_Integer i = 0; i < argc; i ++) { for (Standard_Integer i = 0; i < argc; i ++) {
mess.AssignCat(argv[i]); mess.AssignCat(" "); 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()); 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; if (stat == IFSelect_RetError || stat == IFSelect_RetFail) return 1;
else return 0; else return 0;
} }

View File

@ -12,6 +12,7 @@ pload XSDRAW
restore [locate_data_file OCC22765.brep] a restore [locate_data_file OCC22765.brep] a
vinit vinit
XProgress -tclOutput
XProgress -t XProgress -t
set List1 [sewing result 0.1 a] set List1 [sewing result 0.1 a]
if { [string compare $List1 ""] != 0 } { if { [string compare $List1 ""] != 0 } {

View File

@ -10,6 +10,7 @@ set BugNumber OCC22572
catch { pload XSDRAW } catch { pload XSDRAW }
vinit vinit
XProgress -tclOutput
XProgress -t XProgress -t
set List1 [meshfromstl result [locate_data_file bearing.stl]] set List1 [meshfromstl result [locate_data_file bearing.stl]]
puts "----------------------" puts "----------------------"

View File

@ -11,6 +11,7 @@ set BugNumber OCC22746
catch { pload XSDRAW } catch { pload XSDRAW }
restore [locate_data_file OCC22746-om.brep] a restore [locate_data_file OCC22746-om.brep] a
vinit vinit
XProgress -tclOutput
XProgress -t XProgress -t
set List1 [fixshape result a] set List1 [fixshape result a]
puts "----------------------" puts "----------------------"

View File

@ -11,6 +11,7 @@ set BugNumber OCC22746
catch { pload XSDRAW } catch { pload XSDRAW }
restore [locate_data_file OCC22746-trampafus-notfixed.brep] a restore [locate_data_file OCC22746-trampafus-notfixed.brep] a
vinit vinit
XProgress -tclOutput
XProgress -t XProgress -t
set List1 [fixshape result a] set List1 [fixshape result a]
puts "----------------------" puts "----------------------"

View File

@ -14,6 +14,7 @@ catch { pload XSDRAW }
restore [locate_data_file OCC22761-TransmissionTestModel5-notfixed.brep] a restore [locate_data_file OCC22761-TransmissionTestModel5-notfixed.brep] a
vinit vinit
XProgress -tclOutput
XProgress -t XProgress -t
set List1 [fixshape result a] set List1 [fixshape result a]
puts "----------------------" puts "----------------------"