1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +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_StatusType.hxx
Message_ExecStatus.hxx
Message_HArrayOfMsg.hxx

View File

@ -46,6 +46,7 @@ is
imported Status;
imported StatusType;
imported ExecStatus;
imported HArrayOfMsg;
class Msg;
---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
-- 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;

View File

@ -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

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