When using the OpenCascade C++ libaries, certain functions will print out some status or response to the console/terminal. For example STEPCAFControl_Writer::perform() will print out something like:
*******************************************************************
****** Statistics on Transfer (Write) ******
*******************************************************************
****** Transfer Mode = 0 I.E. As Is ******
****** Transferring Shape, ShapeType = 0 ******
** WorkSession : Sending all data
Step File Name : <file-name> Write Done
to the console. Is there a way to prevent this?
Normally OCCT does not print messages directly into console, instead it relies on Message_Messenger
interface. Default implementation registers Message_PrinterOStream
printer which puts all messages into console with colors assigned depending on a message gravity.
So, there are several options in your case:
Message::DefaultMessenger()->RemovePrinters (STANDARD_TYPE(Message_PrinterOStream))
Message_Info
, which means that all messages will be printed except Message_Trace
designated for verbose or debug outputs. Message_Gravity aGravity = Message_Alarm;
for (Message_SequenceOfPrinters::Iterator aPrinterIter (Message::DefaultMessenger()->Printers());
aPrinterIter.More(); aPrinterIter.Next())
{
aPrinterIter.Value()->SetTraceLevel (aGravity);
}
Message_PrinterOStream
and register your own printer implementing Message_Printer
interface with desired behavior. Normally, GUI applications do not print messages to console and instead print them to dedicated GUI control basing on user preferences. class MyPrinter : public Message_Printer
{
protected:
virtual void send (const TCollection_AsciiString& theString, const Message_Gravity theGravity) const override
{
std::cerr << "[GRAV: " << theGravity << "] " << theString << "\n";
}
};
STEPCAFControl_Writer
, it should be noted that this class prints messages into Transfer_TransferProcess::Messenger()
, which is set to a global Message::DefaultMessenger()
messenger by default, but could be overridden by application in case if specific algorithm output should be suppressed / redirected. This would require diving into STEPCAFControl
internal logic, as it doesn't look like an API easily accessible to application code... And it seems some messages will be print to Message::DefaultMessenger()
anyway. STEPCAFControl_Writer aWriter;
Handle(Message_Messenger) aMessenger = new Message_Messenger();
aMessenger->ChangePrinters().Clear();
aMessenger->AddPrinter (new MyPrinter());
aWriter.ChangeWriter().WS()->TransferWriter()->FinderProcess()->SetMessenger (aMessenger);
...
Below is a screenshot of Draw Harness showing messages with different gravity having different color (default behavior of Message_PrinterOStream
since OCCT 7.5.0) - intense red for errors (Message_Alarm
/Message_Fail
), intense yellow for warnings (Message_ConsoleColor_Yellow
), intense green for information (Message_ConsoleColor_Green
), and thin yellow for verbose/debug messages (Message_ConsoleColor_Yellow
).