1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-21 10:13:43 +03:00

0024438: Message_Algorithm - allow customized status descriptions

This commit is contained in:
kgv 2014-01-16 11:55:43 +04:00 committed by bugmaster
parent 7e7c2f0b6f
commit 15cea4ef7a
5 changed files with 105 additions and 17 deletions

View File

@ -1,3 +1,4 @@
Message_Status.hxx Message_Status.hxx
Message_StatusType.hxx Message_StatusType.hxx
Message_ExecStatus.hxx Message_ExecStatus.hxx
Message_HArrayOfMsg.hxx

View File

@ -46,6 +46,7 @@ is
imported Status; imported Status;
imported StatusType; imported StatusType;
imported ExecStatus; imported ExecStatus;
imported HArrayOfMsg;
class Msg; class Msg;
---Purpose: Defines message. ---Purpose: Defines message.

View File

@ -52,6 +52,9 @@ class Algorithm from Message inherits TShared from MMgt
-- the current class type, the same message is searched for the base -- the current class type, the same message is searched for the base
-- class(es) recursively. -- 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; -- The messages are output to the messenger, stored in the field;
-- though messenger can be changed, it is guaranteed to be non-null. -- though messenger can be changed, it is guaranteed to be non-null.
-- By default, Message::DefaultMessenger() is used. -- By default, Message::DefaultMessenger() is used.
@ -59,6 +62,8 @@ class Algorithm from Message inherits TShared from MMgt
uses uses
TShared from MMgt, TShared from MMgt,
HArrayOfMsg from Message,
Msg from Message,
Messenger from Message, Messenger from Message,
Gravity from Message, Gravity from Message,
Status from Message, Status from Message,
@ -125,6 +130,12 @@ is
-- If noRepetitions is True, the parameter will be added only -- If noRepetitions is True, the parameter will be added only
-- if it has not been yet recorded for the same status flag -- 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; GetStatus(me) returns ExecStatus from Message;
---Purpose: Returns copy of exec status of algorithm ---Purpose: Returns copy of exec status of algorithm
---C++: inline ---C++: inline
@ -216,5 +227,6 @@ fields
myMessenger : Messenger from Message is protected; myMessenger : Messenger from Message is protected;
myReportIntegers : HArray1OfTransient from TColStd; myReportIntegers : HArray1OfTransient from TColStd;
myReportStrings : HArray1OfTransient from TColStd; myReportStrings : HArray1OfTransient from TColStd;
myReportMessages : HArrayOfMsg from Message;
end Algorithm; end Algorithm;

View File

@ -132,6 +132,33 @@ void Message_Algorithm::SetStatus (const Message_Status& theStat,
aReportSeq->Append ( theStr ); 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 //function : ClearStatus
//purpose : //purpose :
@ -142,6 +169,7 @@ void Message_Algorithm::ClearStatus()
myStatus.Clear(); myStatus.Clear();
myReportIntegers.Nullify(); myReportIntegers.Nullify();
myReportStrings.Nullify(); myReportStrings.Nullify();
myReportMessages.Nullify();
} }
//======================================================================= //=======================================================================
@ -154,9 +182,12 @@ void Message_Algorithm::SendStatusMessages (const Message_ExecStatus& theStatus,
const Standard_Integer theMaxCount) const const Standard_Integer theMaxCount) const
{ {
Handle(Message_Messenger) aMsgr = GetMessenger(); 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 // Iterate on all set flags in the specified range
for ( Standard_Integer i = Message_ExecStatus::FirstStatus; for ( Standard_Integer i = Message_ExecStatus::FirstStatus;
@ -164,7 +195,19 @@ void Message_Algorithm::SendStatusMessages (const Message_ExecStatus& theStatus,
{ {
Message_Status stat = Message_ExecStatus::StatusByIndex( i ); Message_Status stat = Message_ExecStatus::StatusByIndex( i );
if (!theStatus.IsSet (stat) || !myStatus.IsSet (stat)) if (!theStatus.IsSet (stat) || !myStatus.IsSet (stat))
{
continue; 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 // construct message suffix
TCollection_AsciiString aSuffix; TCollection_AsciiString aSuffix;
@ -208,15 +251,20 @@ void Message_Algorithm::SendStatusMessages (const Message_ExecStatus& theStatus,
Handle(TColStd_HPackedMapOfInteger) aMapErrors = Handle(TColStd_HPackedMapOfInteger) aMapErrors =
Handle(TColStd_HPackedMapOfInteger)::DownCast(myReportIntegers->Value(i)); Handle(TColStd_HPackedMapOfInteger)::DownCast(myReportIntegers->Value(i));
if (!aMapErrors.IsNull()) if (!aMapErrors.IsNull())
{
aMsg << PrepareReport (aMapErrors, theMaxCount); 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) aReportSeq =
Handle(TColStd_HSequenceOfHExtendedString)::DownCast (myReportStrings->Value(i)); Handle(TColStd_HSequenceOfHExtendedString)::DownCast (myReportStrings->Value(i));
if (!aReportSeq.IsNull()) if (!aReportSeq.IsNull())
{
aMsg << PrepareReport (aReportSeq->Sequence(), theMaxCount); aMsg << PrepareReport (aReportSeq->Sequence(), theMaxCount);
} }
}
// output the message // output the message
aMsgr->Send(aMsg, theTraceLevel); aMsgr->Send(aMsg, theTraceLevel);

View File

@ -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 <Message_Msg.hxx>
#include <NCollection_Array1.hxx>
#include <NCollection_Handle.hxx>
typedef NCollection_Handle<Message_Msg> Handle(Message_Msg);
typedef NCollection_Array1<Handle(Message_Msg)> Message_ArrayOfMsg;
typedef NCollection_Handle<Message_ArrayOfMsg> Handle(Message_ArrayOfMsg);
typedef Handle(Message_ArrayOfMsg) Message_HArrayOfMsg;
#endif // _Message_HArrayOfMsg_HeaderFile