mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0024644: Draw_Printer - provide the way to control messages gravity filter
Message_Printer - define GetTraceLevel()/SetTraceLevel() methods in base interface. Implement message gravity filter in Draw_Printer. Add new Draw Harness command dtracelevel to show/change message gravity filter. Redirect default messenger to Draw_Printer within TKDraw instead of TKXSDRAW Draw::Commands() - assign Draw_Printer only once
This commit is contained in:
@@ -702,6 +702,99 @@ static int dmeminfo (Draw_Interpretor& theDI,
|
||||
return 0;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
//function : dtracelevel
|
||||
//purpose :
|
||||
//==============================================================================
|
||||
|
||||
static int dtracelevel (Draw_Interpretor& theDI,
|
||||
Standard_Integer theArgNb,
|
||||
const char** theArgVec)
|
||||
{
|
||||
Message_Gravity aLevel = Message_Info;
|
||||
if (theArgNb < 1 || theArgNb > 2)
|
||||
{
|
||||
std::cout << "Error: wrong number of arguments! See usage:\n";
|
||||
theDI.PrintHelp (theArgVec[0]);
|
||||
return 1;
|
||||
}
|
||||
else if (theArgNb == 2)
|
||||
{
|
||||
TCollection_AsciiString aVal (theArgVec[1]);
|
||||
aVal.LowerCase();
|
||||
if (aVal == "trace")
|
||||
{
|
||||
aLevel = Message_Trace;
|
||||
}
|
||||
else if (aVal == "info")
|
||||
{
|
||||
aLevel = Message_Info;
|
||||
}
|
||||
else if (aVal == "warn"
|
||||
|| aVal == "warning")
|
||||
{
|
||||
aLevel = Message_Warning;
|
||||
}
|
||||
else if (aVal == "alarm")
|
||||
{
|
||||
aLevel = Message_Alarm;
|
||||
}
|
||||
else if (aVal == "fail")
|
||||
{
|
||||
aLevel = Message_Fail;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Error: unknown gravity '" << theArgVec[1] << "'!\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
Handle(Message_Messenger) aMessenger = Message::DefaultMessenger();
|
||||
if (aMessenger.IsNull())
|
||||
{
|
||||
std::cout << "Error: default messenger is unavailable!\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
Message_SequenceOfPrinters& aPrinters = aMessenger->ChangePrinters();
|
||||
if (aPrinters.Length() < 1)
|
||||
{
|
||||
std::cout << "Error: no printers registered in default Messenger!\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (Standard_Integer aPrinterIter = 1; aPrinterIter <= aPrinters.Length(); ++aPrinterIter)
|
||||
{
|
||||
Handle(Message_Printer)& aPrinter = aPrinters.ChangeValue (aPrinterIter);
|
||||
if (theArgNb == 1)
|
||||
{
|
||||
if (aPrinterIter == 1)
|
||||
{
|
||||
aLevel = aPrinter->GetTraceLevel();
|
||||
}
|
||||
else if (aLevel == aPrinter->GetTraceLevel())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (aPrinter->GetTraceLevel())
|
||||
{
|
||||
case Message_Trace: theDI << "trace"; break;
|
||||
case Message_Info: theDI << "info"; break;
|
||||
case Message_Warning: theDI << "warn"; break;
|
||||
case Message_Alarm: theDI << "alarm"; break;
|
||||
case Message_Fail: theDI << "fail"; break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
aPrinter->SetTraceLevel (aLevel);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Draw::BasicCommands(Draw_Interpretor& theCommands)
|
||||
{
|
||||
static Standard_Boolean Done = Standard_False;
|
||||
@@ -711,7 +804,7 @@ void Draw::BasicCommands(Draw_Interpretor& theCommands)
|
||||
ios::sync_with_stdio();
|
||||
|
||||
const char* g = "DRAW General Commands";
|
||||
|
||||
|
||||
theCommands.Add("batch", "returns 1 in batch mode",
|
||||
__FILE__,ifbatch,g);
|
||||
theCommands.Add("spy","spy [file], Save commands in file. no file close",
|
||||
@@ -732,13 +825,15 @@ void Draw::BasicCommands(Draw_Interpretor& theCommands)
|
||||
" : memory counters for this process",
|
||||
__FILE__, dmeminfo, g);
|
||||
|
||||
// Logging commands; note that their names are hard-coded in the code
|
||||
// Logging commands; note that their names are hard-coded in the code
|
||||
// of Draw_Interpretor, thus should not be changed without update of that code!
|
||||
theCommands.Add("dlog", "manage logging of commands and output; run without args to get help",
|
||||
__FILE__,dlog,g);
|
||||
theCommands.Add("decho", "switch on / off echo of commands to cout; run without args to get help",
|
||||
__FILE__,decho,g);
|
||||
|
||||
theCommands.Add("dtracelevel", "dtracelevel [trace|info|warn|alarm|fail]",
|
||||
__FILE__, dtracelevel, g);
|
||||
|
||||
theCommands.Add("dbreak", "raises Tcl exception if user has pressed Control-Break key",
|
||||
__FILE__,dbreak,g);
|
||||
theCommands.Add("dversion", "provides information on OCCT build configuration (version, compiler, OS, C library, etc.)",
|
||||
|
@@ -16,8 +16,27 @@
|
||||
|
||||
#include <Draw.ixx>
|
||||
|
||||
void Draw::Commands(Draw_Interpretor& theCommands)
|
||||
#include <Draw_Printer.hxx>
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Message_PrinterOStream.hxx>
|
||||
|
||||
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);
|
||||
|
@@ -576,6 +576,18 @@ Standard_Integer Draw_Interpretor::EvalFile(const Standard_CString fname)
|
||||
return Tcl_EvalFile(myInterp,pfname);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : PrintHelp
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Draw_Interpretor::PrintHelp (const Standard_CString theCommandName)
|
||||
{
|
||||
TCollection_AsciiString aCmd = TCollection_AsciiString ("help ") + theCommandName;
|
||||
Standard_PCharacter aLinePtr = (Standard_PCharacter )aCmd.ToCString();
|
||||
return Tcl_Eval (myInterp, aLinePtr);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function :Complete
|
||||
//purpose :
|
||||
|
@@ -209,6 +209,9 @@ public:
|
||||
//! Eval the content on the file and returns status
|
||||
Standard_EXPORT Standard_Integer EvalFile (const Standard_CString theFileName);
|
||||
|
||||
//! Eval the script "help command_name"
|
||||
Standard_EXPORT Standard_Integer PrintHelp (const Standard_CString theCommandName);
|
||||
|
||||
//! Returns True if the script is complete, no pending closing braces. (})
|
||||
Standard_EXPORT static Standard_Boolean Complete (const Standard_CString theScript);
|
||||
|
||||
|
@@ -30,51 +30,66 @@ Draw_Printer::Draw_Printer (const Draw_Interpretor& theTcl)
|
||||
|
||||
//=======================================================================
|
||||
//function : Send
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Draw_Printer::Send (const TCollection_ExtendedString& theString,
|
||||
const Message_Gravity /*theGravity*/,
|
||||
const Standard_Boolean putEndl) const
|
||||
const Message_Gravity theGravity,
|
||||
const Standard_Boolean theToPutEol) const
|
||||
{
|
||||
if ( ! myTcl )
|
||||
if (!myTcl
|
||||
|| theGravity < myTraceLevel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
(*(Draw_Interpretor*)myTcl) << theString;
|
||||
if ( putEndl ){
|
||||
if (theToPutEol)
|
||||
{
|
||||
(*(Draw_Interpretor*)myTcl) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Send
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Draw_Printer::Send (const Standard_CString theString,
|
||||
const Message_Gravity /*theGravity*/,
|
||||
const Standard_Boolean putEndl) const
|
||||
const Message_Gravity theGravity,
|
||||
const Standard_Boolean theToPutEol) const
|
||||
{
|
||||
if ( ! myTcl )
|
||||
if (!myTcl
|
||||
|| theGravity < myTraceLevel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
(*(Draw_Interpretor*)myTcl) << theString;
|
||||
if ( putEndl ){
|
||||
if (theToPutEol)
|
||||
{
|
||||
(*(Draw_Interpretor*)myTcl) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Send
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Draw_Printer::Send (const TCollection_AsciiString& theString,
|
||||
const Message_Gravity /*theGravity*/,
|
||||
const Standard_Boolean putEndl) const
|
||||
const Message_Gravity theGravity,
|
||||
const Standard_Boolean theToPutEol) const
|
||||
{
|
||||
if ( ! myTcl )
|
||||
if (!myTcl
|
||||
|| theGravity < myTraceLevel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
(*(Draw_Interpretor*)myTcl) << theString;
|
||||
if ( putEndl ){
|
||||
if (theToPutEol)
|
||||
{
|
||||
(*(Draw_Interpretor*)myTcl) << "\n";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user