From: kgv Date: Thu, 16 Jan 2014 07:55:43 +0000 (+0400) Subject: 0024438: Message_Algorithm - allow customized status descriptions X-Git-Tag: HYDRO-2014-01-31~45 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=15cea4ef7a79732a616f6cfd75d7903b915339ed;p=occt-copy.git 0024438: Message_Algorithm - allow customized status descriptions --- diff --git a/src/Message/FILES b/src/Message/FILES index 1e59798a42..3086407eae 100755 --- a/src/Message/FILES +++ b/src/Message/FILES @@ -1,3 +1,4 @@ Message_Status.hxx Message_StatusType.hxx Message_ExecStatus.hxx +Message_HArrayOfMsg.hxx diff --git a/src/Message/Message.cdl b/src/Message/Message.cdl index 85e8565ac6..507b331233 100644 --- a/src/Message/Message.cdl +++ b/src/Message/Message.cdl @@ -46,6 +46,7 @@ is imported Status; imported StatusType; imported ExecStatus; + imported HArrayOfMsg; class Msg; ---Purpose: Defines message. diff --git a/src/Message/Message_Algorithm.cdl b/src/Message/Message_Algorithm.cdl index 0bbb389dec..29da636721 100644 --- a/src/Message/Message_Algorithm.cdl +++ b/src/Message/Message_Algorithm.cdl @@ -52,6 +52,9 @@ class Algorithm from Message inherits TShared from MMgt -- the current class type, the same message is searched for the base -- class(es) recursively. -- + -- Message can be set explicitly for the status; in this case the + -- above procedure is not used and supplied message is used as is. + -- -- The messages are output to the messenger, stored in the field; -- though messenger can be changed, it is guaranteed to be non-null. -- By default, Message::DefaultMessenger() is used. @@ -59,6 +62,8 @@ class Algorithm from Message inherits TShared from MMgt uses TShared from MMgt, + HArrayOfMsg from Message, + Msg from Message, Messenger from Message, Gravity from Message, Status from Message, @@ -125,6 +130,12 @@ is -- If noRepetitions is True, the parameter will be added only -- if it has not been yet recorded for the same status flag + SetStatus(me: mutable; theStat : Status from Message; + theMsg : Msg from Message); + ---Purpose: Sets status with preformatted message. This message will be + -- used directly to report the status; automatic generation of + -- status messages will be disabled for it. + GetStatus(me) returns ExecStatus from Message; ---Purpose: Returns copy of exec status of algorithm ---C++: inline @@ -216,5 +227,6 @@ fields myMessenger : Messenger from Message is protected; myReportIntegers : HArray1OfTransient from TColStd; myReportStrings : HArray1OfTransient from TColStd; + myReportMessages : HArrayOfMsg from Message; end Algorithm; diff --git a/src/Message/Message_Algorithm.cxx b/src/Message/Message_Algorithm.cxx index 73f4cd0022..8ec510bc57 100644 --- a/src/Message/Message_Algorithm.cxx +++ b/src/Message/Message_Algorithm.cxx @@ -132,39 +132,82 @@ void Message_Algorithm::SetStatus (const Message_Status& theStat, aReportSeq->Append ( theStr ); } +//======================================================================= +//function : SetStatus +//purpose : +//======================================================================= + +void Message_Algorithm::SetStatus (const Message_Status& theStat, + const Message_Msg& theMsg) +{ + // Set status flag + SetStatus (theStat); + + // Find index of bit corresponding to that flag + Standard_Integer aFlagIndex = Message_ExecStatus::StatusIndex (theStat); + if (aFlagIndex == 0) + { + return; + } + + // Create sequence of messages for a given flag, if not yet done + if (myReportMessages.IsNull()) + { + myReportMessages = new Message_ArrayOfMsg (Message_ExecStatus::FirstStatus, Message_ExecStatus::LastStatus); + } + + myReportMessages->ChangeValue (aFlagIndex) = new Message_Msg (theMsg); +} + //======================================================================= //function : ClearStatus //purpose : //======================================================================= -void Message_Algorithm::ClearStatus() -{ +void Message_Algorithm::ClearStatus() +{ myStatus.Clear(); myReportIntegers.Nullify(); myReportStrings.Nullify(); + myReportMessages.Nullify(); } //======================================================================= //function : SendStatusMessages -//purpose : +//purpose : //======================================================================= void Message_Algorithm::SendStatusMessages (const Message_ExecStatus& theStatus, - const Message_Gravity theTraceLevel, - const Standard_Integer theMaxCount) const + const Message_Gravity theTraceLevel, + const Standard_Integer theMaxCount) const { Handle(Message_Messenger) aMsgr = GetMessenger(); - if (aMsgr.IsNull()) return; + if (aMsgr.IsNull()) + { + return; + } - TCollection_AsciiString aClassName ( DynamicType()->Name() ); + const TCollection_AsciiString aClassName (DynamicType()->Name()); // Iterate on all set flags in the specified range for ( Standard_Integer i = Message_ExecStatus::FirstStatus; i <= Message_ExecStatus::LastStatus; i++ ) { Message_Status stat = Message_ExecStatus::StatusByIndex( i ); - if ( !theStatus.IsSet( stat ) || !myStatus.IsSet( stat ) ) + if (!theStatus.IsSet (stat) || !myStatus.IsSet (stat)) + { continue; + } + + Handle(Message_Msg) aMsgCustom = !myReportMessages.IsNull() + ? myReportMessages->Value (i) + : Handle(Message_Msg)(); + if (!aMsgCustom.IsNull()) + { + // print custom message + aMsgr->Send (*aMsgCustom, theTraceLevel); + continue; + } // construct message suffix TCollection_AsciiString aSuffix; @@ -203,19 +246,24 @@ void Message_Algorithm::SendStatusMessages (const Message_ExecStatus& theStatus, // if additional parameters are defined for a given status flag, // try to feed them into the message - if ( ! myReportIntegers.IsNull() ) + if (!myReportIntegers.IsNull()) { Handle(TColStd_HPackedMapOfInteger) aMapErrors = - Handle(TColStd_HPackedMapOfInteger)::DownCast(myReportIntegers->Value(i)); - if (!aMapErrors.IsNull() ) - aMsg << PrepareReport ( aMapErrors, theMaxCount ); + Handle(TColStd_HPackedMapOfInteger)::DownCast(myReportIntegers->Value(i)); + if (!aMapErrors.IsNull()) + { + aMsg << PrepareReport (aMapErrors, theMaxCount); + } } - if ( ! myReportStrings.IsNull() && ! myReportStrings->Value(i).IsNull() ) + if (!myReportStrings.IsNull() + && !myReportStrings->Value (i).IsNull()) { - Handle(TColStd_HSequenceOfHExtendedString) aReportSeq = - Handle(TColStd_HSequenceOfHExtendedString)::DownCast ( myReportStrings->Value(i) ); - if ( ! aReportSeq.IsNull() ) - aMsg << PrepareReport ( aReportSeq->Sequence(), theMaxCount ); + Handle(TColStd_HSequenceOfHExtendedString) aReportSeq = + Handle(TColStd_HSequenceOfHExtendedString)::DownCast (myReportStrings->Value(i)); + if (!aReportSeq.IsNull()) + { + aMsg << PrepareReport (aReportSeq->Sequence(), theMaxCount); + } } // output the message diff --git a/src/Message/Message_HArrayOfMsg.hxx b/src/Message/Message_HArrayOfMsg.hxx new file mode 100644 index 0000000000..fb10e01247 --- /dev/null +++ b/src/Message/Message_HArrayOfMsg.hxx @@ -0,0 +1,26 @@ +// Copyright (c) 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. + +#ifndef _Message_HArrayOfMsg_HeaderFile +#define _Message_HArrayOfMsg_HeaderFile + +#include +#include +#include + +typedef NCollection_Handle Handle(Message_Msg); +typedef NCollection_Array1 Message_ArrayOfMsg; +typedef NCollection_Handle Handle(Message_ArrayOfMsg); +typedef Handle(Message_ArrayOfMsg) Message_HArrayOfMsg; + +#endif // _Message_HArrayOfMsg_HeaderFile