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
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;
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",
" : 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.)",
#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);
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 :
//! 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);
//=======================================================================
//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";
}
}
deferred class Printer from Message inherits TShared from MMgt
- ---Purpose: Abstract interface class defining printer as output context for
- -- text messages
- --
- -- The message, besides being text string, has associated gravity
- -- level, which can be used by printer to decide either to process
- -- a message or ignore it.
+ ---Purpose: Abstract interface class defining printer as output context for text messages
+ --
+ -- The message, besides being text string, has associated gravity
+ -- level, which can be used by printer to decide either to process a message or ignore it.
uses
- Gravity from Message,
- AsciiString from TCollection,
- ExtendedString from TCollection
-
+ Gravity from Message,
+ AsciiString from TCollection,
+ ExtendedString from TCollection
+
is
- Send (me; theString: ExtendedString from TCollection;
- theGravity: Gravity from Message;
- putEndl: Boolean) is deferred;
- ---Purpose: Send a string message with specified trace level.
- -- The parameter putEndl specified whether end-of-line
- -- should be added to the end of the message.
- -- This method must be redefined in descentant.
-
- Send (me; theString: CString; theGravity: Gravity from Message;
- putEndl: Boolean) is virtual;
- ---Purpose: Send a string message with specified trace level.
- -- The parameter putEndl specified whether end-of-line
- -- should be added to the end of the message.
- -- Default implementation calls first method Send().
-
- Send (me; theString: AsciiString from TCollection;
- theGravity: Gravity from Message;
- putEndl: Boolean) is virtual;
- ---Purpose: Send a string message with specified trace level.
- -- The parameter putEndl specified whether end-of-line
- -- should be added to the end of the message.
- -- Default implementation calls first method Send().
+ Initialize returns Printer from Message;
+ ---Purpose: Empty constructor with Message_Info trace level
+
+ GetTraceLevel (me) returns Gravity from Message;
+ ---C++: inline
+ ---Purpose: Return trace level used for filtering messages;
+ -- messages with lover gravity will be ignored.
+
+ SetTraceLevel (me : mutable;
+ theTraceLevel : Gravity from Message);
+ ---C++: inline
+ ---Purpose: Set trace level used for filtering messages.
+ -- By default, trace level is Message_Info, so that all messages are output
+
+ Send (me;
+ theString : ExtendedString from TCollection;
+ theGravity : Gravity from Message;
+ theToPutEol : Boolean) is deferred;
+ ---Purpose: Send a string message with specified trace level.
+ -- The parameter theToPutEol specified whether end-of-line should be added to the end of the message.
+ -- This method must be redefined in descentant.
+
+ Send (me;
+ theString : CString;
+ theGravity : Gravity from Message;
+ theToPutEol : Boolean) is virtual;
+ ---Purpose: Send a string message with specified trace level.
+ -- The parameter theToPutEol specified whether end-of-line should be added to the end of the message.
+ -- Default implementation calls first method Send().
+
+ Send (me;
+ theString : AsciiString from TCollection;
+ theGravity : Gravity from Message;
+ theToPutEol : Boolean) is virtual;
+ ---Purpose: Send a string message with specified trace level.
+ -- The parameter theToPutEol specified whether end-of-line should be added to the end of the message.
+ -- Default implementation calls first method Send().
+
+fields
+
+ myTraceLevel : Gravity from Message is protected;
end Printer;
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
+//=======================================================================
+//function : Constructor
+//purpose :
+//=======================================================================
+
+Message_Printer::Message_Printer()
+: myTraceLevel (Message_Info)
+{
+}
+
//=======================================================================
//function : Send
-//purpose :
+//purpose :
//=======================================================================
void Message_Printer::Send (const Standard_CString theString,
- const Message_Gravity theGravity,
- const Standard_Boolean putEndl) const
+ const Message_Gravity theGravity,
+ const Standard_Boolean theToOutEol) const
{
- Send ( TCollection_ExtendedString(theString), theGravity, putEndl );
+ if (theGravity >= myTraceLevel)
+ {
+ Send (TCollection_ExtendedString (theString), theGravity, theToOutEol);
+ }
}
//=======================================================================
//function : Send
-//purpose :
+//purpose :
//=======================================================================
void Message_Printer::Send (const TCollection_AsciiString& theString,
- const Message_Gravity theGravity,
- const Standard_Boolean putEndl) const
+ const Message_Gravity theGravity,
+ const Standard_Boolean theToOutEol) const
{
- Send ( TCollection_ExtendedString(theString), theGravity, putEndl );
+ if (theGravity >= myTraceLevel)
+ {
+ Send (TCollection_ExtendedString (theString), theGravity, theToOutEol);
+ }
}
--- /dev/null
+// Created on: 2007-06-28
+// Created by: Pavel TELKOV
+// Copyright (c) 2007-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and / or modify it
+// under the terms of the GNU Lesser General Public version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <Message_Printer.hxx>
+
+//=======================================================================
+//function : GetTraceLevel
+//purpose :
+//=======================================================================
+
+inline Message_Gravity Message_Printer::GetTraceLevel() const
+{
+ return myTraceLevel;
+}
+
+//=======================================================================
+//function : SetTraceLevel
+//purpose :
+//=======================================================================
+
+inline void Message_Printer::SetTraceLevel (const Message_Gravity theTraceLevel)
+{
+ myTraceLevel = theTraceLevel;
+}
---Purpose: Flushes the output stream and destroys it if it has been
-- specified externally with option doFree (or if it is internal
-- file stream)
-
- GetTraceLevel (me) returns Gravity from Message;
- ---C++: inline
- ---Purpose: Return trace level used for filtering messages;
- -- messages with lover gravity will be ignored.
-
- SetTraceLevel (me: mutable; theTraceLevel: Gravity from Message);
- ---C++: inline
- ---Purpose: Set trace level used for filtering messages.
- -- By default, trace level is Message_Info, so that
- -- all messages are output
GetUseUtf8 (me) returns Boolean;
---Purpose: Returns option to convert non-Ascii symbols to UTF8 encoding
fields
- myTraceLevel: Gravity from Message;
myStream: Address from Standard; -- pointer to OStream
myIsFile: Boolean from Standard;
myUseUtf8: Boolean from Standard;
//purpose : Empty constructor, defaulting to cerr
//=======================================================================
-Message_PrinterOStream::Message_PrinterOStream (const Message_Gravity theTraceLevel)
-: myTraceLevel(theTraceLevel), myStream(&cout),
- myIsFile(Standard_False), myUseUtf8(Standard_False)
+Message_PrinterOStream::Message_PrinterOStream (const Message_Gravity theTraceLevel)
+: myStream (&cout),
+ myIsFile (Standard_False),
+ myUseUtf8 (Standard_False)
{
+ myTraceLevel = theTraceLevel;
}
//=======================================================================
// for specific file names standard streams are created
//=======================================================================
Message_PrinterOStream::Message_PrinterOStream (const Standard_CString theFileName,
- const Standard_Boolean doAppend,
- const Message_Gravity theTraceLevel)
-: myTraceLevel(theTraceLevel), myStream(&cout), myIsFile(Standard_False)
+ const Standard_Boolean theToAppend,
+ const Message_Gravity theTraceLevel)
+: myStream (&cout),
+ myIsFile (Standard_False)
{
+ myTraceLevel = theTraceLevel;
if ( strcasecmp(theFileName, "cout") == 0 )
myStream = &cerr;
else if ( strcasecmp(theFileName, "cerr") == 0 )
else
{
TCollection_AsciiString aFileName (theFileName);
-#ifdef WNT
+#ifdef _WIN32
aFileName.ChangeAll ('/', '\\');
#endif
ofstream *ofile = new ofstream (aFileName.ToCString(),
#ifdef USE_STL_STREAMS
- (doAppend ? (std::ios_base::app | std::ios_base::out) : std::ios_base::out ) );
+ (theToAppend ? (std::ios_base::app | std::ios_base::out) : std::ios_base::out ) );
#else
- (doAppend ? ios::app : ios::out ) );
+ (theToAppend ? ios::app : ios::out ) );
#endif
if ( ofile ) {
myStream = (Standard_OStream*)ofile;
#include <Message_PrinterOStream.hxx>
-//=======================================================================
-//function : GetTraceLevel
-//purpose :
-//=======================================================================
-
-inline Message_Gravity Message_PrinterOStream::GetTraceLevel() const
-{
- return myTraceLevel;
-}
-
-//=======================================================================
-//function : SetTraceLevel
-//purpose :
-//=======================================================================
-
-inline void Message_PrinterOStream::SetTraceLevel (const Message_Gravity theTraceLevel)
-{
- myTraceLevel = theTraceLevel;
-}
-
//=======================================================================
//function : GetUseUtf8
//purpose :
{
return *(Standard_OStream*)myStream;
}
-
#include <stdio.h>
#include <Message.hxx>
-#include <Message_Messenger.hxx>
-#include <Message_PrinterOStream.hxx>
-#include <Draw_Printer.hxx>
static int deja = 0, dejald = 0;
//unused variable
// performed not in IFSelect_SessionPilot but in standard Tcl interpretor
XSDRAW::RemoveCommand("x");
XSDRAW::RemoveCommand("exit");
- const Handle(Message_Messenger) &sout = Message::DefaultMessenger();
- if (!sout.IsNull()){
- sout->RemovePrinters(STANDARD_TYPE(Message_PrinterOStream));
- sout->AddPrinter(new Draw_Printer(theCommands));
- }
+
// if (!getenv("WBHOSTTOP")) XSDRAW::RemoveCommand("xsnew");
Handle(TColStd_HSequenceOfAsciiString) list =
IFSelect_Activator::Commands(0);
#include <Geom_Surface.hxx>
#include <Interface_Macros.hxx>
+#include <Message.hxx>
#include <Message_Messenger.hxx>
#include <Draw_Appli.hxx>
-#include <Draw_Printer.hxx>
#include <DrawTrSurf.hxx>
#include <DBRep.hxx>
//#include <GeometryTest.hxx> essai CKY 4-AUT-1998
case 3:
di << "Face: " << "\n"; break;
}
- Handle(Message_Messenger) aDIMessenger =
- new Message_Messenger (new Draw_Printer(di));
+
TColStd_MapIteratorOfMapOfTransient itmap;
for(itmap.Initialize(aMap); itmap.More(); itmap.Next()) {
- //XSDRAW::Model()->Print(itmap.Key(),cout);
- Standard_SStream aSStream;
- XSDRAW::Model()->Print(itmap.Key(),aDIMessenger);
- di << aSStream;
- di<<" ";
+ XSDRAW::Model()->Print (itmap.Key(), Message::DefaultMessenger());
+ di << " ";
}
di << "\n";
di << "\n" << "Number:"<< nbFaces << "\n";
#include <Draw_Appli.hxx>
#include <Draw_Interpretor.hxx>
-#include <Draw_Printer.hxx>
+#include <Message.hxx>
#include <Message_Messenger.hxx>
#include <DBRep.hxx>
// nom = "." -> fichier deja lu
Standard_Integer i, num, nbs, modepri = 1;
if (fromtcl) modepri = 4;
- Handle(Message_Messenger) aDIMessenger =
- new Message_Messenger (new Draw_Printer(di));
while (modepri) {
num = sr.NbRootsForTransfer();
if (!fromtcl) {
di<<"NbRootsForTransfer="<<num<<" :\n";
for (i = 1; i <= num; i ++) {
di<<"Root."<<i<<", Ent. ";
- sr.Model()->Print(sr.RootForTransfer(i),aDIMessenger);
+ sr.Model()->Print (sr.RootForTransfer(i), Message::DefaultMessenger());
di<<" Type:"<<sr.RootForTransfer(i)->DynamicType()->Name()<<"\n";
}