mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +03:00
Integration of OCCT 6.5.0 from SVN
This commit is contained in:
3
src/Message/FILES
Executable file
3
src/Message/FILES
Executable file
@@ -0,0 +1,3 @@
|
||||
Message_Status.hxx
|
||||
Message_StatusType.hxx
|
||||
Message_ExecStatus.hxx
|
88
src/Message/Message.cdl
Executable file
88
src/Message/Message.cdl
Executable file
@@ -0,0 +1,88 @@
|
||||
-- File: Message.cdl
|
||||
-- Created: Thu Jul 29 11:48:06 1999
|
||||
-- Author: Roman LYGIN
|
||||
-- <rln@zamox.nnov.matra-dtv.fr>
|
||||
---Copyright: Matra Datavision 1999
|
||||
|
||||
|
||||
package Message
|
||||
|
||||
---Purpose: Defines
|
||||
-- - tools to work with messages
|
||||
-- - basic tools intended for progress indication
|
||||
|
||||
uses
|
||||
|
||||
MMgt,
|
||||
TColStd,
|
||||
TCollection,
|
||||
Standard
|
||||
|
||||
is
|
||||
|
||||
enumeration Gravity is
|
||||
---Purpose: Defines gravity level of messages
|
||||
-- - Trace: low-level details on algorithm execution (usually for debug purposes)
|
||||
-- - Info: informative message
|
||||
-- - Warning: warning message
|
||||
-- - Alarm: non-critical error
|
||||
-- - Fail: fatal error
|
||||
Trace,
|
||||
Info,
|
||||
Warning,
|
||||
Alarm,
|
||||
Fail
|
||||
end Gravity;
|
||||
|
||||
imported Status;
|
||||
imported StatusType;
|
||||
imported ExecStatus;
|
||||
|
||||
class Msg;
|
||||
---Purpose: Defines message.
|
||||
class MsgFile;
|
||||
---Purpose: Defines file storing messages.
|
||||
|
||||
class Messenger;
|
||||
---Purpose: Messenger is API class providing general-purpose interface for
|
||||
-- libraries that may issue text messages without knowledge
|
||||
-- of how these messages will be further processed.
|
||||
|
||||
class Algorithm;
|
||||
---Purpose: Class Message_Algorithm is the root class for all algorithms.
|
||||
-- It provides generic mechanism for management execution status,
|
||||
-- collection and output of corresponding error/warning messages
|
||||
|
||||
deferred class Printer;
|
||||
---Purpose: Defines basic message printer.
|
||||
|
||||
class PrinterOStream;
|
||||
---Purpose: Defines printer associated with an ostream
|
||||
|
||||
class ListOfMsg instantiates List from TCollection (Msg from Message);
|
||||
|
||||
class SequenceOfPrinters instantiates
|
||||
Sequence from TCollection (Printer from Message);
|
||||
|
||||
-- Progress indication
|
||||
deferred class ProgressIndicator;
|
||||
class ProgressScale;
|
||||
class ProgressSentry;
|
||||
class SequenceOfProgressScale instantiates
|
||||
Sequence from TCollection (ProgressScale from Message);
|
||||
|
||||
DefaultMessenger returns Messenger from Message;
|
||||
---Purpose: Defines default messenger for OCCT applications.
|
||||
-- This is global static instance of the messenger.
|
||||
-- By default, it contains single printer directed to cout.
|
||||
-- It can be customized according to the application needs.
|
||||
---C++: return const &
|
||||
|
||||
FillTime (Hour, Minute: Integer; Second: Real) returns AsciiString from TCollection;
|
||||
---Purpose: Returns the string filled with values of hours, minutes and seconds.
|
||||
-- Example:
|
||||
-- 1. (5, 12, 26.3345) returns "05h:12m:26.33s",
|
||||
-- 2. (0, 6, 34.496 ) returns "06m:34.50s",
|
||||
-- 3. (0, 0, 4.5 ) returns "4.50s"
|
||||
|
||||
end Message;
|
41
src/Message/Message.cxx
Executable file
41
src/Message/Message.cxx
Executable file
@@ -0,0 +1,41 @@
|
||||
// File: Message.cxx
|
||||
// Created: Tue Nov 23 17:45:42 1999
|
||||
// Author: data exchange team
|
||||
// <det@kinox>
|
||||
|
||||
|
||||
#include <Message.ixx>
|
||||
#include <Message_Messenger.hxx>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
//=======================================================================
|
||||
//function : DefaultMessenger
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Handle(Message_Messenger)& Message::DefaultMessenger ()
|
||||
{
|
||||
static Handle(Message_Messenger) aMessenger = new Message_Messenger;
|
||||
return aMessenger;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : FillTime
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TCollection_AsciiString Message::FillTime (const Standard_Integer hour,
|
||||
const Standard_Integer minute,
|
||||
const Standard_Real second)
|
||||
{
|
||||
char t [30];
|
||||
if (hour > 0)
|
||||
sprintf (t, "%02dh:%02dm:%.2fs", hour, minute, second);
|
||||
else if (minute > 0)
|
||||
sprintf (t, "%02dm:%.2fs", minute, second);
|
||||
else
|
||||
sprintf (t, "%.2fs", second);
|
||||
return TCollection_AsciiString (t);
|
||||
}
|
210
src/Message/Message_Algorithm.cdl
Executable file
210
src/Message/Message_Algorithm.cdl
Executable file
@@ -0,0 +1,210 @@
|
||||
-- File: Message_Algorithm.cdl
|
||||
-- Created: Fri Jul 6 09:22:36 2007
|
||||
-- Author: Pavel TELKOV
|
||||
-- <ptv@valenox>
|
||||
-- Copyright: Open CASCADE S.A. 2007
|
||||
-- The original implementation copyright (c) RINA S.p.A
|
||||
|
||||
class Algorithm from Message inherits TShared from MMgt
|
||||
|
||||
---Purpose: Class Message_Algorithm is intended to be the base class for
|
||||
-- classes implementing algorithms or any operations that need
|
||||
-- to provide extended information on its execution to the
|
||||
-- caller / user.
|
||||
--
|
||||
-- It provides generic mechanism for management of the execution
|
||||
-- status, collection and output of messages.
|
||||
--
|
||||
-- The algorithm uses methods SetStatus() to set an execution status.
|
||||
-- It is possible to associate a status with a number or a string
|
||||
-- (second argument of SetStatus() methods) to indicate precisely
|
||||
-- the item (object, element etc.) in the input data which caused
|
||||
-- the problem.
|
||||
--
|
||||
-- Each execution status generated by the algorithm has associated
|
||||
-- text message that should be defined in the resouce file loaded
|
||||
-- with call to Message_MsgFile::LoadFile().
|
||||
--
|
||||
-- The messages corresponding to the statuses generated during the
|
||||
-- algorithm execution are output to Message_Messenger using
|
||||
-- methods SendMessages(). If status have associated numbers
|
||||
-- or strings, they are included in the message body in place of
|
||||
-- "%s" placeholder which should be present in the message text.
|
||||
--
|
||||
-- The name of the message text in the resource file is constructed
|
||||
-- from name of the class and name of the status, separated by dot,
|
||||
-- for instance:
|
||||
--
|
||||
-- .TObj_CheckModel.Alarm2
|
||||
-- Error: Some objects (%s) have references to dead object(s)
|
||||
--
|
||||
-- If message for the status is not found with prefix of
|
||||
-- the current class type, the same message is searched for the base
|
||||
-- class(es) recursively.
|
||||
--
|
||||
-- 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.
|
||||
|
||||
uses
|
||||
|
||||
TShared from MMgt,
|
||||
Messenger from Message,
|
||||
Gravity from Message,
|
||||
Status from Message,
|
||||
ExecStatus from Message,
|
||||
AsciiString from TCollection,
|
||||
HAsciiString from TCollection,
|
||||
ExtendedString from TCollection,
|
||||
HExtendedString from TCollection,
|
||||
SequenceOfInteger from TColStd,
|
||||
HSequenceOfInteger from TColStd,
|
||||
HArray1OfTransient from TColStd,
|
||||
HPackedMapOfInteger from TColStd,
|
||||
SequenceOfHExtendedString from TColStd,
|
||||
HSequenceOfHExtendedString from TColStd
|
||||
|
||||
is
|
||||
|
||||
Create returns Algorithm from Message;
|
||||
---Purpose: Empty constructor
|
||||
|
||||
SetStatus(me: mutable; theStat : Status from Message);
|
||||
---Purpose: Sets status with no parameter
|
||||
|
||||
SetStatus(me: mutable; theStat : Status from Message;
|
||||
theInt : Integer);
|
||||
---Purpose: Sets status with integer parameter
|
||||
|
||||
SetStatus(me: mutable; theStat : Status from Message;
|
||||
theStr : CString;
|
||||
noRepetitions : Boolean = Standard_True);
|
||||
---Purpose: Sets status with string parameter.
|
||||
-- If noRepetitions is True, the parameter will be added only
|
||||
-- if it has not been yet recorded for the same status flag
|
||||
---C++: inline
|
||||
|
||||
SetStatus(me: mutable; theStat : Status from Message;
|
||||
theStr : AsciiString from TCollection;
|
||||
noRepetitions : Boolean = Standard_True);
|
||||
---Purpose: Sets status with string parameter
|
||||
-- If noRepetitions is True, the parameter will be added only
|
||||
-- if it has not been yet recorded for the same status flag
|
||||
---C++: inline
|
||||
|
||||
SetStatus(me: mutable; theStat : Status from Message;
|
||||
theStr : HAsciiString from TCollection;
|
||||
noRepetitions : Boolean = Standard_True);
|
||||
---Purpose: Sets status with string parameter
|
||||
-- If noRepetitions is True, the parameter will be added only
|
||||
-- if it has not been yet recorded for the same status flag
|
||||
---C++: inline
|
||||
|
||||
SetStatus(me: mutable; theStat : Status from Message;
|
||||
theStr : ExtendedString from TCollection;
|
||||
noRepetitions : Boolean = Standard_True);
|
||||
---Purpose: Sets status with string parameter
|
||||
-- If noRepetitions is True, the parameter will be added only
|
||||
-- if it has not been yet recorded for the same status flag
|
||||
---C++: inline
|
||||
|
||||
SetStatus(me: mutable; theStat : Status from Message;
|
||||
theStr : HExtendedString from TCollection;
|
||||
noRepetitions : Boolean = Standard_True);
|
||||
---Purpose: Sets status with string parameter
|
||||
-- If noRepetitions is True, the parameter will be added only
|
||||
-- if it has not been yet recorded for the same status flag
|
||||
|
||||
GetStatus(me) returns ExecStatus from Message;
|
||||
---Purpose: Returns copy of exec status of algorithm
|
||||
---C++: inline
|
||||
---C++: return const &
|
||||
|
||||
ChangeStatus(me: mutable) returns ExecStatus from Message;
|
||||
---Purpose: Returns exec status of algorithm
|
||||
---C++: inline
|
||||
---C++: return &
|
||||
|
||||
ClearStatus(me: mutable);
|
||||
---Purpose: Clear exec status of algorithm
|
||||
|
||||
-- Message management
|
||||
|
||||
SetMessenger(me: mutable; theMsgr : Messenger from Message);
|
||||
---Purpose: Sets messenger to algorithm
|
||||
|
||||
GetMessenger(me)
|
||||
returns Messenger from Message;
|
||||
---Purpose: Returns messenger of algorithm.
|
||||
-- The returned handle is always non-null and can
|
||||
-- be used for sending messages.
|
||||
---C++: inline
|
||||
|
||||
SendStatusMessages(me; theFilter : ExecStatus from Message;
|
||||
theTraceLevel: Gravity from Message = Message_Warning;
|
||||
theMaxCount: Integer = 20)
|
||||
is virtual;
|
||||
---Purpose: Print messages for all status flags that have been set during
|
||||
-- algorithm execution, excluding statuses that are NOT set
|
||||
-- in theFilter.
|
||||
--
|
||||
-- The messages are taken from resource file, names being
|
||||
-- constructed as {dynamic class type}.{status name},
|
||||
-- for instance, "Message_Algorithm.Fail5".
|
||||
-- If message is not found in resources for this class and all
|
||||
-- its base types, surrogate text is printed.
|
||||
--
|
||||
-- For the statuses having number or string parameters,
|
||||
-- theMaxCount defines maximal number of numbers or strings to be
|
||||
-- included in the message
|
||||
--
|
||||
-- Note that this method is virtual; this allows descendant
|
||||
-- classes to customize message output (e.g. by adding
|
||||
-- messages from other sub-algorithms)
|
||||
|
||||
SendMessages(me; theTraceLevel: Gravity from Message = Message_Warning;
|
||||
theMaxCount: Integer = 20);
|
||||
---Purpose: Convenient variant of SendStatusMessages() with theFilter
|
||||
-- having defined all WARN, ALARM, and FAIL (but not DONE)
|
||||
-- status flags
|
||||
|
||||
AddStatus(me: mutable; theOther : Algorithm from Message);
|
||||
---Purpose: Add statuses to this algorithm from other algorithm
|
||||
-- (including messages)
|
||||
|
||||
AddStatus(me: mutable; theStatus : ExecStatus from Message;
|
||||
theOther : Algorithm from Message);
|
||||
---Purpose: Add statuses to this algorithm from other algorithm, but
|
||||
-- only those items are moved that correspond to statuses
|
||||
-- set in theStatus
|
||||
|
||||
GetMessageNumbers(me; theStatus : Status from Message)
|
||||
returns HPackedMapOfInteger from TColStd;
|
||||
---Purpose: Return the numbers associated with the indicated status;
|
||||
-- Null handle if no such status or no numbers associated with it
|
||||
|
||||
GetMessageStrings(me; theStatus : Status from Message)
|
||||
returns HSequenceOfHExtendedString from TColStd;
|
||||
---Purpose: Return the strings associated with the indicated status;
|
||||
-- Null handle if no such status or no strings associated with it
|
||||
|
||||
PrepareReport(myclass; theError : HPackedMapOfInteger from TColStd;
|
||||
theMaxCount: Integer)
|
||||
returns ExtendedString from TCollection;
|
||||
---Purpose: Prepares a string containing a list of integers contained
|
||||
-- in theError map, but not more than theMaxCount
|
||||
|
||||
PrepareReport(myclass; theReportSeq : SequenceOfHExtendedString from TColStd;
|
||||
theMaxCount: Integer)
|
||||
returns ExtendedString from TCollection;
|
||||
---Purpose: Prepares a string containing a list of names contained
|
||||
-- in theReportSeq sequence, but not more than theMaxCount
|
||||
|
||||
fields
|
||||
|
||||
myStatus : ExecStatus from Message is protected;
|
||||
myMessenger : Messenger from Message is protected;
|
||||
myReportIntegers : HArray1OfTransient from TColStd;
|
||||
myReportStrings : HArray1OfTransient from TColStd;
|
||||
|
||||
end Algorithm;
|
382
src/Message/Message_Algorithm.cxx
Executable file
382
src/Message/Message_Algorithm.cxx
Executable file
@@ -0,0 +1,382 @@
|
||||
// File: Message_Algorithm.cxx
|
||||
// Created: 04.03.03 12:23:33
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE S.A. 2007
|
||||
// The original implementation copyright (c) RINA S.p.A.
|
||||
|
||||
#include <Message_Algorithm.ixx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Msg.hxx>
|
||||
#include <Message_MsgFile.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Standard_AncestorIterator.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <TColStd_SequenceOfInteger.hxx>
|
||||
#include <TColStd_HSequenceOfInteger.hxx>
|
||||
#include <TColStd_HSequenceOfHExtendedString.hxx>
|
||||
#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : SetMessenger
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Message_Algorithm::Message_Algorithm ()
|
||||
{
|
||||
myMessenger = Message::DefaultMessenger();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetMessenger
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Algorithm::SetMessenger (const Handle(Message_Messenger)& theMsgr)
|
||||
{
|
||||
if ( theMsgr.IsNull() )
|
||||
myMessenger = Message::DefaultMessenger();
|
||||
else
|
||||
myMessenger = theMsgr;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetStatus
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Algorithm::SetStatus(const Message_Status& theStat)
|
||||
{
|
||||
myStatus.Set( theStat );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetStatus
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Algorithm::SetStatus (const Message_Status& theStat,
|
||||
const Standard_Integer theInt)
|
||||
{
|
||||
// Set status flag
|
||||
SetStatus ( theStat );
|
||||
|
||||
// Find index of bit corresponding to that flag
|
||||
Standard_Integer aFlagIndex = Message_ExecStatus::StatusIndex(theStat);
|
||||
if ( !aFlagIndex ) return;
|
||||
|
||||
// Create map of integer parameters for a given flag, if not yet done
|
||||
if ( myReportIntegers.IsNull() )
|
||||
myReportIntegers = new TColStd_HArray1OfTransient (Message_ExecStatus::FirstStatus,
|
||||
Message_ExecStatus::LastStatus);
|
||||
Handle(Standard_Transient)& aData =
|
||||
myReportIntegers->ChangeValue(aFlagIndex);
|
||||
if ( aData.IsNull() )
|
||||
aData = new TColStd_HPackedMapOfInteger;
|
||||
|
||||
// add integer parameter for the status
|
||||
Handle(TColStd_HPackedMapOfInteger)::DownCast(aData)->ChangeMap().Add(theInt);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetStatus
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Algorithm::SetStatus (const Message_Status& theStat,
|
||||
const Handle(TCollection_HExtendedString) &theStr,
|
||||
const Standard_Boolean noRepetitions)
|
||||
{
|
||||
// Set status flag
|
||||
SetStatus ( theStat );
|
||||
if ( theStr.IsNull() )
|
||||
return;
|
||||
|
||||
// Find index of bit corresponding to that flag
|
||||
Standard_Integer aFlagIndex = Message_ExecStatus::StatusIndex(theStat);
|
||||
if ( !aFlagIndex ) return;
|
||||
|
||||
// Create sequence of string parameters for a given flag, if not yet done
|
||||
if ( myReportStrings.IsNull() )
|
||||
myReportStrings = new TColStd_HArray1OfTransient (Message_ExecStatus::FirstStatus,
|
||||
Message_ExecStatus::LastStatus);
|
||||
Handle(Standard_Transient)& aData =
|
||||
myReportStrings->ChangeValue(aFlagIndex);
|
||||
if ( aData.IsNull() )
|
||||
aData = new TColStd_HSequenceOfHExtendedString;
|
||||
|
||||
// Add string parameter
|
||||
Handle(TColStd_HSequenceOfHExtendedString) aReportSeq =
|
||||
Handle(TColStd_HSequenceOfHExtendedString)::DownCast(aData);
|
||||
if ( aReportSeq.IsNull() )
|
||||
return;
|
||||
if ( noRepetitions )
|
||||
{
|
||||
// if the provided string has been already registered, just do nothing
|
||||
for ( Standard_Integer i=1; i <= aReportSeq->Length(); i++ )
|
||||
if ( aReportSeq->Value(i)->String().IsEqual( theStr->String() ) )
|
||||
return;
|
||||
}
|
||||
|
||||
aReportSeq->Append ( theStr );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ClearStatus
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Algorithm::ClearStatus()
|
||||
{
|
||||
myStatus.Clear();
|
||||
myReportIntegers.Nullify();
|
||||
myReportStrings.Nullify();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SendStatusMessages
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Algorithm::SendStatusMessages (const Message_ExecStatus& theStatus,
|
||||
const Message_Gravity theTraceLevel,
|
||||
const Standard_Integer theMaxCount) const
|
||||
{
|
||||
Handle(Message_Messenger) aMsgr = GetMessenger();
|
||||
if (aMsgr.IsNull()) return;
|
||||
|
||||
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 ) )
|
||||
continue;
|
||||
|
||||
// construct message suffix
|
||||
TCollection_AsciiString aSuffix;
|
||||
switch( Message_ExecStatus::TypeOfStatus( stat ) )
|
||||
{
|
||||
case Message_DONE: aSuffix.AssignCat( ".Done" ); break;
|
||||
case Message_WARN: aSuffix.AssignCat( ".Warn" ); break;
|
||||
case Message_ALARM: aSuffix.AssignCat( ".Alarm"); break;
|
||||
case Message_FAIL: aSuffix.AssignCat( ".Fail" ); break;
|
||||
default: continue;
|
||||
}
|
||||
aSuffix.AssignCat( Message_ExecStatus::LocalStatusIndex( stat ) );
|
||||
|
||||
// find message, iterating by base classes if necessary
|
||||
TCollection_AsciiString aMsgName = aClassName + aSuffix;
|
||||
Handle(Standard_Type) aType = DynamicType();
|
||||
while (Message_MsgFile::Msg(aMsgName).Length() == 0 && !aType.IsNull())
|
||||
{
|
||||
Standard_AncestorIterator it(aType);
|
||||
aType.Nullify();
|
||||
for (; it.More(); it.Next())
|
||||
{
|
||||
aType = it.Value();
|
||||
TCollection_AsciiString aClassName1 (aType->Name());
|
||||
TCollection_AsciiString aMsgName1 = aClassName1 + aSuffix;
|
||||
if (Message_MsgFile::Msg(aMsgName1).Length() != 0)
|
||||
{
|
||||
aMsgName = aMsgName1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create a message
|
||||
Message_Msg aMsg ( aMsgName );
|
||||
|
||||
// if additional parameters are defined for a given status flag,
|
||||
// try to feed them into the message
|
||||
if ( ! myReportIntegers.IsNull() )
|
||||
{
|
||||
Handle(TColStd_HPackedMapOfInteger) aMapErrors =
|
||||
Handle(TColStd_HPackedMapOfInteger)::DownCast(myReportIntegers->Value(i));
|
||||
if (!aMapErrors.IsNull() )
|
||||
aMsg << PrepareReport ( aMapErrors, theMaxCount );
|
||||
}
|
||||
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 );
|
||||
}
|
||||
|
||||
// output the message
|
||||
aMsgr->Send(aMsg, theTraceLevel);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SendMessages
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Algorithm::SendMessages (const Message_Gravity theTraceLevel,
|
||||
const Standard_Integer theMaxCount) const
|
||||
{
|
||||
Message_ExecStatus aStat;
|
||||
aStat.SetAllWarn();
|
||||
aStat.SetAllAlarm();
|
||||
aStat.SetAllFail();
|
||||
SendStatusMessages( aStat, theTraceLevel, theMaxCount );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddStatus
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Algorithm::AddStatus
|
||||
(const Handle(Message_Algorithm)& theOtherAlgo)
|
||||
{
|
||||
AddStatus( theOtherAlgo->GetStatus(), theOtherAlgo );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddStatus
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Algorithm::AddStatus
|
||||
(const Message_ExecStatus& theAllowedStatus,
|
||||
const Handle(Message_Algorithm)& theOtherAlgo)
|
||||
{
|
||||
// Iterate on all set flags in the specified range
|
||||
const Message_ExecStatus& aStatusOfAlgo = theOtherAlgo->GetStatus();
|
||||
for ( Standard_Integer i = Message_ExecStatus::FirstStatus;
|
||||
i <= Message_ExecStatus::LastStatus; i++ )
|
||||
{
|
||||
Message_Status stat = Message_ExecStatus::StatusByIndex( i );
|
||||
if ( ! theAllowedStatus.IsSet( stat ) || ! aStatusOfAlgo.IsSet( stat ) )
|
||||
continue;
|
||||
|
||||
SetStatus ( stat );
|
||||
|
||||
// if additional parameters are defined for a given status flag,
|
||||
// move them to <this> algorithm
|
||||
// a) numbers
|
||||
Handle(TColStd_HPackedMapOfInteger) aNumsOther =
|
||||
theOtherAlgo->GetMessageNumbers (stat);
|
||||
if ( ! aNumsOther.IsNull() )
|
||||
{
|
||||
// Create sequence of integer parameters for a given flag, if not yet done
|
||||
if ( myReportIntegers.IsNull() )
|
||||
myReportIntegers =
|
||||
new TColStd_HArray1OfTransient(Message_ExecStatus::FirstStatus,
|
||||
Message_ExecStatus::LastStatus);
|
||||
Handle(Standard_Transient)& aData =
|
||||
myReportIntegers->ChangeValue(i);
|
||||
if ( aData.IsNull() )
|
||||
aData = new TColStd_HPackedMapOfInteger;
|
||||
|
||||
// add integer parameter for the status
|
||||
Handle(TColStd_HPackedMapOfInteger)::DownCast(aData)
|
||||
->ChangeMap().Unite(aNumsOther->Map());
|
||||
}
|
||||
// b) strings
|
||||
Handle(TColStd_HSequenceOfHExtendedString) aStrsOther =
|
||||
theOtherAlgo->GetMessageStrings (stat);
|
||||
if ( ! aStrsOther.IsNull() )
|
||||
{
|
||||
for (Standard_Integer n=1; n < aStrsOther->Length(); n++ )
|
||||
SetStatus (stat, aStrsOther->Value(n));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetMessageNumbers
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TColStd_HPackedMapOfInteger) Message_Algorithm::GetMessageNumbers
|
||||
(const Message_Status& theStatus) const
|
||||
{
|
||||
if ( myReportIntegers.IsNull() )
|
||||
return 0;
|
||||
|
||||
// Find index of bit corresponding to that flag
|
||||
Standard_Integer aFlagIndex = Message_ExecStatus::StatusIndex(theStatus);
|
||||
if ( ! aFlagIndex ) return 0;
|
||||
|
||||
return Handle(TColStd_HPackedMapOfInteger)::DownCast(myReportIntegers->Value(aFlagIndex));
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetMessageStrings
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TColStd_HSequenceOfHExtendedString) Message_Algorithm::GetMessageStrings
|
||||
(const Message_Status& theStatus) const
|
||||
{
|
||||
if ( myReportStrings.IsNull() )
|
||||
return 0;
|
||||
|
||||
// Find index of bit corresponding to that flag
|
||||
Standard_Integer aFlagIndex = Message_ExecStatus::StatusIndex(theStatus);
|
||||
if ( ! aFlagIndex ) return 0;
|
||||
|
||||
return Handle(TColStd_HSequenceOfHExtendedString)::DownCast(myReportStrings->Value(aFlagIndex));
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : PrepareReport
|
||||
//purpose : static method
|
||||
//=======================================================================
|
||||
|
||||
TCollection_ExtendedString Message_Algorithm::PrepareReport
|
||||
(const Handle(TColStd_HPackedMapOfInteger)& theMapError,
|
||||
const Standard_Integer theMaxCount)
|
||||
{
|
||||
TCollection_ExtendedString aNewReport;
|
||||
TColStd_MapIteratorOfPackedMapOfInteger anIt(theMapError->Map());
|
||||
Standard_Integer nb = 1;
|
||||
for (; anIt.More() && nb <= theMaxCount; anIt.Next(), nb++ )
|
||||
{
|
||||
if ( nb > 1 )
|
||||
aNewReport += " ";
|
||||
aNewReport += anIt.Key();
|
||||
}
|
||||
|
||||
if ( anIt.More() )
|
||||
{
|
||||
aNewReport += " ... (total ";
|
||||
aNewReport += theMapError->Map().Extent();
|
||||
aNewReport += ")";
|
||||
}
|
||||
return aNewReport;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : PrepareReport
|
||||
//purpose : static method
|
||||
//=======================================================================
|
||||
|
||||
TCollection_ExtendedString Message_Algorithm::PrepareReport
|
||||
(const TColStd_SequenceOfHExtendedString& theReportSeq,
|
||||
const Standard_Integer theMaxCount)
|
||||
{
|
||||
TCollection_ExtendedString aNewReport;
|
||||
Standard_Integer nb = 1;
|
||||
for ( ; nb <= theReportSeq.Length() && nb <= theMaxCount; nb++)
|
||||
{
|
||||
aNewReport += (Standard_CString)( nb > 1 ? ", \'" : "\'" );
|
||||
aNewReport += theReportSeq.Value(nb)->String();
|
||||
aNewReport += "\'";
|
||||
}
|
||||
|
||||
if (theReportSeq.Length() > theMaxCount )
|
||||
{
|
||||
aNewReport += " ... (total ";
|
||||
aNewReport += theReportSeq.Length();
|
||||
aNewReport += ") ";
|
||||
}
|
||||
return aNewReport;
|
||||
}
|
86
src/Message/Message_Algorithm.lxx
Executable file
86
src/Message/Message_Algorithm.lxx
Executable file
@@ -0,0 +1,86 @@
|
||||
// File: Message_Algorithm.lxx
|
||||
// Created: 06.07.07 10:27:14
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE S.A. 2007
|
||||
|
||||
#include <Message_Algorithm.hxx>
|
||||
#include <TCollection_HExtendedString.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : SetStatus
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_Algorithm::SetStatus (const Message_Status& theStat,
|
||||
const Standard_CString theStr,
|
||||
const Standard_Boolean noRepetitions)
|
||||
{
|
||||
SetStatus ( theStat, new TCollection_HExtendedString ( theStr ), noRepetitions );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetStatus
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_Algorithm::SetStatus (const Message_Status& theStat,
|
||||
const TCollection_AsciiString &theStr,
|
||||
const Standard_Boolean noRepetitions)
|
||||
{
|
||||
SetStatus ( theStat, new TCollection_HExtendedString ( theStr ), noRepetitions );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetStatus
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_Algorithm::SetStatus (const Message_Status& theStat,
|
||||
const Handle(TCollection_HAsciiString) &theStr,
|
||||
const Standard_Boolean noRepetitions)
|
||||
{
|
||||
SetStatus ( theStat, new TCollection_HExtendedString ( theStr ), noRepetitions );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetStatus
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_Algorithm::SetStatus (const Message_Status& theStat,
|
||||
const TCollection_ExtendedString &theStr,
|
||||
const Standard_Boolean noRepetitions)
|
||||
{
|
||||
SetStatus ( theStat, new TCollection_HExtendedString ( theStr ), noRepetitions );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetStatus
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline const Message_ExecStatus& Message_Algorithm::GetStatus() const
|
||||
{
|
||||
return myStatus;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ChangeStatus
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Message_ExecStatus& Message_Algorithm::ChangeStatus()
|
||||
{
|
||||
return myStatus;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetMessenger
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Handle(Message_Messenger) Message_Algorithm::GetMessenger() const
|
||||
{
|
||||
return myMessenger;
|
||||
}
|
||||
|
221
src/Message/Message_ExecStatus.hxx
Executable file
221
src/Message/Message_ExecStatus.hxx
Executable file
@@ -0,0 +1,221 @@
|
||||
// File: Message_ExecStatus.hxx
|
||||
// Created: 04.03.03 10:54:28
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE S.A. 2007
|
||||
// The original implementation copyright (c) RINA S.p.A.
|
||||
|
||||
#ifndef Message_ExecStatus_HeaderFile
|
||||
#define Message_ExecStatus_HeaderFile
|
||||
|
||||
#include <Message_StatusType.hxx>
|
||||
#include <Message_Status.hxx>
|
||||
|
||||
/**
|
||||
* Tiny class for extended handling of error / execution
|
||||
* status of algorithm in universal way.
|
||||
*
|
||||
* It is in fact a set of integers represented as a collection of bit flags
|
||||
* for each of four types of status; each status flag has its own symbolic
|
||||
* name and can be set/tested individually.
|
||||
*
|
||||
* The flags are grouped in semantic groups:
|
||||
* - No flags means nothing done
|
||||
* - Done flags correspond to some operation succesffuly completed
|
||||
* - Warning flags correspond to warning messages on some
|
||||
* potentially wrong situation, not harming algorithm execution
|
||||
* - Alarm flags correspond to more severe warnings about incorrect
|
||||
* user data, while not breaking algorithm execution
|
||||
* - Fail flags correspond to cases when algorithm failed to complete
|
||||
*/
|
||||
|
||||
class Standard_EXPORT Message_ExecStatus
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
//! Mask to separate bits indicating status type and index within the type
|
||||
enum StatusMask {
|
||||
MType = 0x0000ff00,
|
||||
MIndex = 0x000000ff
|
||||
};
|
||||
static inline int getBitFlag (int status)
|
||||
{
|
||||
return 0x1 << (status & MIndex);
|
||||
}
|
||||
|
||||
public:
|
||||
//!@name Creation and simple operations with statuses
|
||||
//!@{
|
||||
|
||||
//! Create empty execution status
|
||||
Message_ExecStatus ()
|
||||
: myDone( Message_None), myWarn( Message_None),
|
||||
myAlarm( Message_None), myFail( Message_None)
|
||||
{}
|
||||
|
||||
//! Initialise the execution status
|
||||
Message_ExecStatus ( Message_Status status )
|
||||
: myDone( Message_None), myWarn( Message_None),
|
||||
myAlarm( Message_None), myFail( Message_None)
|
||||
{
|
||||
Set( status );
|
||||
}
|
||||
|
||||
//! Sets a status flag
|
||||
void Set (Message_Status status)
|
||||
{
|
||||
switch( status & MType )
|
||||
{
|
||||
case Message_DONE: myDone |= (getBitFlag( status )); break;
|
||||
case Message_WARN: myWarn |= (getBitFlag( status )); break;
|
||||
case Message_ALARM:myAlarm |= (getBitFlag( status )); break;
|
||||
case Message_FAIL: myFail |= (getBitFlag( status )); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
//! Check status for being set
|
||||
Standard_Boolean IsSet (Message_Status status) const
|
||||
{
|
||||
switch( status & MType )
|
||||
{
|
||||
case Message_DONE: return ( myDone & getBitFlag( status ) ? Standard_True : Standard_False );
|
||||
case Message_WARN: return ( myWarn & getBitFlag( status ) ? Standard_True : Standard_False );
|
||||
case Message_ALARM:return ( myAlarm & getBitFlag( status ) ? Standard_True : Standard_False );
|
||||
case Message_FAIL: return ( myFail & getBitFlag( status ) ? Standard_True : Standard_False );
|
||||
default: return Standard_False;
|
||||
}
|
||||
}
|
||||
|
||||
//! Clear one status
|
||||
void Clear (Message_Status status)
|
||||
{
|
||||
switch( status & MType )
|
||||
{
|
||||
case Message_DONE: myDone &= ~(getBitFlag( status )); return;
|
||||
case Message_WARN: myWarn &= ~(getBitFlag( status )); return;
|
||||
case Message_ALARM:myAlarm &= ~(getBitFlag( status )); return;
|
||||
case Message_FAIL: myFail &= ~(getBitFlag( status )); return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
//!@}
|
||||
|
||||
//!@name Advanced: Group operations (useful for analysis)
|
||||
//!@{
|
||||
|
||||
//! Check if at least one status of each type is set
|
||||
Standard_Boolean IsDone () const { return myDone != Message_None; }
|
||||
Standard_Boolean IsFail () const { return myFail != Message_None; }
|
||||
Standard_Boolean IsWarn () const { return myWarn != Message_None; }
|
||||
Standard_Boolean IsAlarm () const { return myAlarm != Message_None; }
|
||||
|
||||
//! Set all statuses of each type
|
||||
void SetAllDone () { myDone = ~0; };
|
||||
void SetAllWarn () { myWarn = ~0; };
|
||||
void SetAllAlarm () { myAlarm = ~0; };
|
||||
void SetAllFail () { myFail = ~0; };
|
||||
|
||||
//! Clear all statuses of each type
|
||||
void ClearAllDone () { myDone = Message_None; };
|
||||
void ClearAllWarn () { myWarn = Message_None; };
|
||||
void ClearAllAlarm() { myAlarm = Message_None; };
|
||||
void ClearAllFail () { myFail = Message_None; };
|
||||
|
||||
//! Clear all statuses
|
||||
void Clear ()
|
||||
{
|
||||
myDone = myWarn = myAlarm = myFail = Message_None;
|
||||
}
|
||||
|
||||
//! Add statuses to me from theOther execution status
|
||||
void Add ( const Message_ExecStatus& theOther )
|
||||
{
|
||||
myDone |= theOther.myDone;
|
||||
myWarn |= theOther.myWarn;
|
||||
myAlarm |= theOther.myAlarm;
|
||||
myFail |= theOther.myFail;
|
||||
}
|
||||
const Message_ExecStatus& operator |= ( const Message_ExecStatus& theOther )
|
||||
{ Add ( theOther ); return *this; }
|
||||
|
||||
//! Leave only the statuses common with theOther
|
||||
void And ( const Message_ExecStatus& theOther )
|
||||
{
|
||||
myDone &= theOther.myDone;
|
||||
myWarn &= theOther.myWarn;
|
||||
myAlarm &= theOther.myAlarm;
|
||||
myFail &= theOther.myFail;
|
||||
}
|
||||
const Message_ExecStatus& operator &= ( const Message_ExecStatus& theOther )
|
||||
{ And ( theOther ); return *this; }
|
||||
|
||||
//@}
|
||||
|
||||
public:
|
||||
|
||||
//!@name Advanced: Iteration and analysis of status flags
|
||||
//!@{
|
||||
|
||||
//! Definitions of range of available statuses
|
||||
enum StatusRange
|
||||
{
|
||||
FirstStatus = 1,
|
||||
StatusesPerType = 32,
|
||||
NbStatuses = 128,
|
||||
LastStatus = 129
|
||||
};
|
||||
|
||||
//! Returns index of status in whole range [FirstStatus, LastStatus]
|
||||
static Standard_Integer StatusIndex( Message_Status status )
|
||||
{
|
||||
switch( status & MType )
|
||||
{
|
||||
case Message_DONE: return 0 * StatusesPerType + LocalStatusIndex(status);
|
||||
case Message_WARN: return 1 * StatusesPerType + LocalStatusIndex(status);
|
||||
case Message_ALARM: return 2 * StatusesPerType + LocalStatusIndex(status);
|
||||
case Message_FAIL: return 3 * StatusesPerType + LocalStatusIndex(status);
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//! Returns index of status inside type of status (Done or Warn or, etc)
|
||||
//! in range [1, StatusesPerType]
|
||||
static Standard_Integer LocalStatusIndex( Message_Status status )
|
||||
{
|
||||
return (status & MIndex) + 1;
|
||||
}
|
||||
|
||||
//! Returns status type (DONE, WARN, ALARM, or FAIL)
|
||||
static Message_StatusType TypeOfStatus( Message_Status status )
|
||||
{
|
||||
return (Message_StatusType)(status & MType);
|
||||
}
|
||||
|
||||
//! Returns status with index theIndex in whole range [FirstStatus, LastStatus]
|
||||
static Message_Status StatusByIndex( const Standard_Integer theIndex )
|
||||
{
|
||||
Standard_Integer indx = theIndex - 1;
|
||||
if ( indx < 32 )
|
||||
return (Message_Status)(Message_DONE + indx);
|
||||
else if ( indx < 64 )
|
||||
return (Message_Status)(Message_WARN + ( indx - 32 ));
|
||||
else if ( indx < 96 )
|
||||
return (Message_Status)(Message_ALARM + ( indx - 64 ));
|
||||
else if ( indx < 128 )
|
||||
return (Message_Status)(Message_FAIL + ( indx - 96 ));
|
||||
return Message_None;
|
||||
}
|
||||
|
||||
//!@}
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE FIELDS ----------
|
||||
Standard_Integer myDone;
|
||||
Standard_Integer myWarn;
|
||||
Standard_Integer myAlarm;
|
||||
Standard_Integer myFail;
|
||||
};
|
||||
|
||||
#endif
|
97
src/Message/Message_Messenger.cdl
Executable file
97
src/Message/Message_Messenger.cdl
Executable file
@@ -0,0 +1,97 @@
|
||||
-- File: Message_Messenger.cdl
|
||||
-- Created: Thu Jun 28 15:49:01 2007
|
||||
-- Author: OCC Team
|
||||
---Copyright: Open CASCADE S.A. 2007
|
||||
|
||||
class Messenger from Message inherits TShared from MMgt
|
||||
|
||||
---Purpose: Messenger is API class providing general-purpose interface for
|
||||
-- libraries that may issue text messages without knowledge
|
||||
-- of how these messages will be further processed.
|
||||
--
|
||||
-- The messenger contains a sequence of "printers" which can be
|
||||
-- customized by the application, and dispatches every received
|
||||
-- message to all the printers.
|
||||
--
|
||||
-- For convenience, a number of operators << are defined with left
|
||||
-- argument being Handle(Message_Messenger); thus it can be used
|
||||
-- with syntax similar to C++ streams.
|
||||
-- Note that all these operators use trace level Warning.
|
||||
|
||||
uses
|
||||
|
||||
Printer from Message,
|
||||
PrinterOStream from Message,
|
||||
SequenceOfPrinters from Message,
|
||||
Gravity from Message,
|
||||
AsciiString from TCollection,
|
||||
ExtendedString from TCollection
|
||||
|
||||
is
|
||||
|
||||
Create returns Messenger from Message;
|
||||
---Purpose: Empty constructor; initializes by single printer directed to cout.
|
||||
-- Note: the default messenger is not empty but directed to cout
|
||||
-- in order to protect against possibility to forget defining printers.
|
||||
-- If printing to cout is not needed, clear messenger by GetPrinters().Clear()
|
||||
|
||||
Create (thePrinter: Printer from Message)
|
||||
returns Messenger from Message;
|
||||
---Purpose: Create messenger with single printer
|
||||
|
||||
AddPrinter (me: mutable; thePrinter: Printer from Message)
|
||||
returns Boolean from Standard;
|
||||
---Purpose: Add a printer to the messenger.
|
||||
-- The printer will be added only if it is not yet in the list.
|
||||
-- Returns True if printer has been added.
|
||||
|
||||
RemovePrinter (me: mutable; thePrinter: Printer from Message)
|
||||
returns Boolean from Standard;
|
||||
---Purpose: Removes specified printer from the messenger.
|
||||
-- Returns True if this printer has been found in the list
|
||||
-- and removed.
|
||||
|
||||
RemovePrinters (me: mutable; theType: Type from Standard)
|
||||
returns Integer from Standard;
|
||||
---Purpose: Removes printers of specified type (including derived classes)
|
||||
-- from the messenger.
|
||||
-- Returns number of removed printers.
|
||||
|
||||
Printers(me)
|
||||
returns SequenceOfPrinters from Message;
|
||||
---C++: inline
|
||||
---C++: return const &
|
||||
---Purpose: Returns current sequence of printers
|
||||
|
||||
ChangePrinters(me: mutable)
|
||||
returns SequenceOfPrinters from Message;
|
||||
---C++: inline
|
||||
---C++: return &
|
||||
---Purpose: Returns sequence of printers
|
||||
-- The sequence can be modified.
|
||||
|
||||
Send (me; theString : CString from Standard;
|
||||
theGravity: Gravity from Message = Message_Warning;
|
||||
putEndl: Boolean from Standard = Standard_True);
|
||||
---Purpose: Dispatch a message to all the printers in the list.
|
||||
-- Three versions of string representations are accepted for
|
||||
-- convenience, by default all are converted to ExtendedString.
|
||||
-- The parameter putEndl specifies whether the new line should
|
||||
-- be started after this message (default) or not (may have
|
||||
-- sense in some conditions).
|
||||
|
||||
Send (me; theString : AsciiString from TCollection;
|
||||
theGravity: Gravity from Message = Message_Warning;
|
||||
putEndl: Boolean from Standard = Standard_True);
|
||||
---Purpose: See above
|
||||
|
||||
Send (me; theString : ExtendedString from TCollection;
|
||||
theGravity: Gravity from Message = Message_Warning;
|
||||
putEndl: Boolean from Standard = Standard_True);
|
||||
---Purpose: See above
|
||||
|
||||
fields
|
||||
|
||||
myPrinters: SequenceOfPrinters from Message;
|
||||
|
||||
end Messenger;
|
132
src/Message/Message_Messenger.cxx
Executable file
132
src/Message/Message_Messenger.cxx
Executable file
@@ -0,0 +1,132 @@
|
||||
// File: Message_Messenger.cxx
|
||||
// Created: Sat Jan 6 19:47:14 2001
|
||||
// Author: OCC Team
|
||||
// Copyright: Open CASCADE S.A. 2005
|
||||
|
||||
#include <Message_Messenger.ixx>
|
||||
#include <Message_PrinterOStream.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_Messenger
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Message_Messenger::Message_Messenger ()
|
||||
{
|
||||
AddPrinter ( new Message_PrinterOStream );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_Messenger
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Message_Messenger::Message_Messenger (const Handle(Message_Printer)& thePrinter)
|
||||
{
|
||||
AddPrinter (thePrinter);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddPrinter
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Message_Messenger::AddPrinter (const Handle(Message_Printer)& thePrinter)
|
||||
{
|
||||
// check whether printer is already in the list
|
||||
for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
|
||||
if ( myPrinters(i) == thePrinter )
|
||||
return Standard_False;
|
||||
// add to the list
|
||||
myPrinters.Append (thePrinter);
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RemovePrinter
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Message_Messenger::RemovePrinter (const Handle(Message_Printer)& thePrinter)
|
||||
{
|
||||
// find printer in the list
|
||||
for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
|
||||
if ( myPrinters(i) == thePrinter )
|
||||
{
|
||||
myPrinters.Remove (i);
|
||||
return Standard_True;
|
||||
}
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RemovePrinters
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Message_Messenger::RemovePrinters (const Handle(Standard_Type)& theType)
|
||||
{
|
||||
// remove printers from the list
|
||||
Standard_Integer nb = 0;
|
||||
for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
|
||||
if ( myPrinters(i)->IsKind(theType) )
|
||||
{
|
||||
myPrinters.Remove (i--);
|
||||
nb++;
|
||||
}
|
||||
return nb;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Send
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Messenger::Send (const Standard_CString theString,
|
||||
const Message_Gravity theGravity,
|
||||
const Standard_Boolean putEndl) const
|
||||
{
|
||||
Standard_Integer nb = myPrinters.Length();
|
||||
for (Standard_Integer i = 1; i <= nb; i++)
|
||||
{
|
||||
Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
|
||||
if ( ! aPrinter.IsNull() )
|
||||
aPrinter->Send ( theString, theGravity, putEndl );
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Send
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Messenger::Send (const TCollection_AsciiString& theString,
|
||||
const Message_Gravity theGravity,
|
||||
const Standard_Boolean putEndl) const
|
||||
{
|
||||
Standard_Integer nb = myPrinters.Length();
|
||||
for (Standard_Integer i = 1; i <= nb; i++)
|
||||
{
|
||||
Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
|
||||
if ( ! aPrinter.IsNull() )
|
||||
aPrinter->Send ( theString, theGravity, putEndl );
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Send
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Messenger::Send (const TCollection_ExtendedString& theString,
|
||||
const Message_Gravity theGravity,
|
||||
const Standard_Boolean putEndl) const
|
||||
{
|
||||
Standard_Integer nb = myPrinters.Length();
|
||||
for (Standard_Integer i = 1; i <= nb; i++)
|
||||
{
|
||||
Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
|
||||
if ( ! aPrinter.IsNull() )
|
||||
aPrinter->Send ( theString, theGravity, putEndl );
|
||||
}
|
||||
}
|
144
src/Message/Message_Messenger.lxx
Executable file
144
src/Message/Message_Messenger.lxx
Executable file
@@ -0,0 +1,144 @@
|
||||
// File: Message_Messenger.lxx
|
||||
// Created: 29.06.07 09:19:08
|
||||
// Author: OCC Team
|
||||
// Copyright: Open CASCADE S.A. 2007
|
||||
|
||||
#include <Message_Messenger.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : GetPrinters
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline const Message_SequenceOfPrinters& Message_Messenger::Printers() const
|
||||
{
|
||||
return myPrinters;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetPrinters
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Message_SequenceOfPrinters& Message_Messenger::ChangePrinters()
|
||||
{
|
||||
return myPrinters;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator <<
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
#ifndef _TCollection_HAsciiString_HeaderFile
|
||||
#include <TCollection_HAsciiString.hxx>
|
||||
#endif
|
||||
#ifndef _TCollection_HExtendedString_HeaderFile
|
||||
#include <TCollection_HExtendedString.hxx>
|
||||
#endif
|
||||
|
||||
// CString
|
||||
inline const Handle(Message_Messenger)&
|
||||
operator << (const Handle(Message_Messenger)& theMessenger,
|
||||
const Standard_CString theStr)
|
||||
{
|
||||
theMessenger->Send (theStr, Message_Info, Standard_False);
|
||||
return theMessenger;
|
||||
}
|
||||
|
||||
// const char* (not the same as const CString which is char const*)
|
||||
/*
|
||||
inline const Handle(Message_Messenger)&
|
||||
operator << (const Handle(Message_Messenger)& theMessenger,
|
||||
const char* theStr)
|
||||
{
|
||||
theMessenger->Send ((Standard_CString)theStr, Message_Info, Standard_False);
|
||||
return theMessenger;
|
||||
}
|
||||
*/
|
||||
// AsciiString
|
||||
inline const Handle(Message_Messenger)&
|
||||
operator << (const Handle(Message_Messenger)& theMessenger,
|
||||
const TCollection_AsciiString& theStr)
|
||||
{
|
||||
theMessenger->Send (theStr, Message_Info, Standard_False);
|
||||
return theMessenger;
|
||||
}
|
||||
|
||||
// HAsciiString
|
||||
inline const Handle(Message_Messenger)&
|
||||
operator << (const Handle(Message_Messenger)& theMessenger,
|
||||
const Handle(TCollection_HAsciiString)& theStr)
|
||||
{
|
||||
theMessenger->Send (theStr->String(), Message_Info, Standard_False);
|
||||
return theMessenger;
|
||||
}
|
||||
|
||||
// ExtendedString
|
||||
inline const Handle(Message_Messenger)&
|
||||
operator << (const Handle(Message_Messenger)& theMessenger,
|
||||
const TCollection_ExtendedString& theStr)
|
||||
{
|
||||
theMessenger->Send (theStr, Message_Info, Standard_False);
|
||||
return theMessenger;
|
||||
}
|
||||
|
||||
// HExtendedString
|
||||
inline const Handle(Message_Messenger)&
|
||||
operator << (const Handle(Message_Messenger)& theMessenger,
|
||||
const Handle(TCollection_HExtendedString)& theStr)
|
||||
{
|
||||
theMessenger->Send (theStr->String(), Message_Info, Standard_False);
|
||||
return theMessenger;
|
||||
}
|
||||
|
||||
// Integer
|
||||
inline const Handle(Message_Messenger)&
|
||||
operator << (const Handle(Message_Messenger)& theMessenger,
|
||||
const Standard_Integer theVal)
|
||||
{
|
||||
TCollection_AsciiString aStr (theVal);
|
||||
theMessenger->Send (aStr, Message_Info, Standard_False);
|
||||
return theMessenger;
|
||||
}
|
||||
|
||||
// Real
|
||||
inline const Handle(Message_Messenger)&
|
||||
operator << (const Handle(Message_Messenger)& theMessenger,
|
||||
const Standard_Real theVal)
|
||||
{
|
||||
TCollection_AsciiString aStr (theVal);
|
||||
theMessenger->Send (aStr, Message_Info, Standard_False);
|
||||
return theMessenger;
|
||||
}
|
||||
|
||||
// Stream
|
||||
inline const Handle(Message_Messenger)&
|
||||
operator << (const Handle(Message_Messenger)& theMessenger,
|
||||
const Standard_SStream& theStream)
|
||||
{
|
||||
#ifdef USE_STL_STREAM
|
||||
theMessenger->Send (theStream.str().c_str(), Message_Info, Standard_False);
|
||||
#else
|
||||
// Note: use dirty tricks -- unavoidable with old streams
|
||||
TCollection_AsciiString aStr (((Standard_SStream&)theStream).str(), theStream.pcount());
|
||||
theMessenger->Send (aStr, Message_Info, Standard_False);
|
||||
((Standard_SStream&)theStream).freeze (false);
|
||||
#endif
|
||||
return theMessenger;
|
||||
}
|
||||
|
||||
// manipulators
|
||||
inline const Handle(Message_Messenger)&
|
||||
operator << (const Handle(Message_Messenger)& theMessenger,
|
||||
const Handle(Message_Messenger)& (*pman) (const Handle(Message_Messenger)&))
|
||||
{
|
||||
return pman (theMessenger);
|
||||
}
|
||||
|
||||
// endl
|
||||
inline const Handle(Message_Messenger)& endl (const Handle(Message_Messenger)& theMessenger)
|
||||
{
|
||||
theMessenger->Send ("", Message_Info, Standard_True);
|
||||
return theMessenger;
|
||||
}
|
147
src/Message/Message_Msg.cdl
Executable file
147
src/Message/Message_Msg.cdl
Executable file
@@ -0,0 +1,147 @@
|
||||
-- File: Message_Msg.cdl
|
||||
-- Created: 18.01.01 16:55:51
|
||||
-- Author: OCC Team
|
||||
---Copyright: Open CASCADE S.A. 2005
|
||||
|
||||
|
||||
class Msg from Message
|
||||
|
||||
---Purpose: This class provides a tool for constructing the parametrized message
|
||||
-- basing on resources loaded by Message_MsgFile tool.
|
||||
--
|
||||
-- A Message is created from a keyword: this keyword identifies the
|
||||
-- message in a message file that should be previously loaded by call
|
||||
-- to Message_MsgFile::LoadFile().
|
||||
--
|
||||
-- The text of the message can contain placeholders for the parameters
|
||||
-- which are to be filled by the proper values when the message
|
||||
-- is prepared. Most of the format specifiers used in C can be used,
|
||||
-- for instance, %s for string, %d for integer etc. In addition,
|
||||
-- specifier %f is supported for double numbers (for compatibility
|
||||
-- with previous versions).
|
||||
--
|
||||
-- User fills the parameter fields in the text of the message by
|
||||
-- calling corresponding methods Arg() or operators "<<".
|
||||
--
|
||||
-- The resulting message, filled with all parameters, can be obtained
|
||||
-- by method Get(). If some parameters were not filled, the text
|
||||
-- UNKNOWN is placed instead.
|
||||
|
||||
uses
|
||||
|
||||
AsciiString from TCollection,
|
||||
HAsciiString from TCollection,
|
||||
ExtendedString from TCollection,
|
||||
HExtendedString from TCollection,
|
||||
SequenceOfInteger from TColStd
|
||||
|
||||
is
|
||||
|
||||
Create returns Msg from Message;
|
||||
---Purpose : Empty constructor
|
||||
|
||||
Create (theMsg: Msg from Message) returns Msg from Message;
|
||||
---Purpose : Copy constructor
|
||||
|
||||
Create (theKey: CString) returns Msg from Message;
|
||||
---Purpose : Create a message using a corresponding entry in Message_MsgFile
|
||||
|
||||
Create (theKey: ExtendedString from TCollection) returns Msg from Message;
|
||||
---Purpose : Create a message using a corresponding entry in Message_MsgFile
|
||||
|
||||
Set (me: in out; theMsg: CString);
|
||||
---Purpose : Set a message body text -- can be used as alternative to
|
||||
-- using messages from resource file
|
||||
|
||||
Set (me: in out; theMsg: ExtendedString from TCollection);
|
||||
---Purpose : Set a message body text -- can be used as alternative to
|
||||
-- using messages from resource file
|
||||
|
||||
-- Adding arguments
|
||||
|
||||
Arg (me: in out; theString : CString)
|
||||
returns Msg from Message;
|
||||
---C++: return &
|
||||
---C++: alias operator <<
|
||||
---Purpose : Set a value for %..s conversion
|
||||
|
||||
Arg (me: in out; theString : AsciiString from TCollection)
|
||||
returns Msg from Message;
|
||||
---C++: return &
|
||||
---C++: inline
|
||||
---C++: alias operator <<
|
||||
---Purpose : Set a value for %..s conversion
|
||||
|
||||
Arg (me: in out; theString : HAsciiString from TCollection)
|
||||
returns Msg from Message;
|
||||
---C++: return &
|
||||
---C++: inline
|
||||
---C++: alias operator <<
|
||||
---Purpose : Set a value for %..s conversion
|
||||
|
||||
Arg (me: in out; theString : ExtendedString from TCollection)
|
||||
returns Msg from Message;
|
||||
---C++: return &
|
||||
---C++: alias operator <<
|
||||
---Purpose : Set a value for %..s conversion
|
||||
|
||||
Arg (me: in out; theString : HExtendedString from TCollection)
|
||||
returns Msg from Message;
|
||||
---C++: return &
|
||||
---C++: inline
|
||||
---C++: alias operator <<
|
||||
---Purpose : Set a value for %..s conversion
|
||||
|
||||
Arg (me: in out; theInt : Integer)
|
||||
returns Msg from Message;
|
||||
---C++: return &
|
||||
---C++: alias operator <<
|
||||
---Purpose : Set a value for %..d, %..i, %..o, %..u, %..x or %..X conversion
|
||||
|
||||
Arg (me: in out; theReal : Real)
|
||||
returns Msg from Message;
|
||||
---C++: return &
|
||||
---C++: alias operator <<
|
||||
---Purpose : Set a value for %..f, %..e, %..E, %..g or %..G conversion
|
||||
|
||||
Original (me) returns ExtendedString from TCollection;
|
||||
---C++: inline
|
||||
---C++: return const &
|
||||
---Purpose : Returns the original message text
|
||||
|
||||
Value (me) returns ExtendedString from TCollection;
|
||||
---C++: inline
|
||||
---C++: return const &
|
||||
---Purpose : Returns current state of the message text with
|
||||
-- parameters to the moment
|
||||
|
||||
IsEdited (me) returns Boolean;
|
||||
---C++: inline
|
||||
---Purpose : Tells if Value differs from Original
|
||||
|
||||
Get (me: in out)
|
||||
returns ExtendedString from TCollection;
|
||||
---C++: return const &
|
||||
---C++: alias "operator const TCollection_ExtendedString& () { return Get(); }"
|
||||
---Purpose : Return the resulting message string with all parameters
|
||||
-- filled. If some parameters were not yet filled by calls
|
||||
-- to methods Arg (or <<), these parameters are filled by
|
||||
-- the word UNKNOWN
|
||||
|
||||
-- Private methods
|
||||
|
||||
getFormat (me: in out; theType : Integer;
|
||||
theFormat : in out AsciiString from TCollection)
|
||||
returns Integer is private;
|
||||
|
||||
replaceText (me: in out; theFirst : Integer;
|
||||
theNb : Integer;
|
||||
theStr : ExtendedString from TCollection) is private;
|
||||
|
||||
fields
|
||||
|
||||
myOriginal : ExtendedString from TCollection;
|
||||
myMessageBody : ExtendedString from TCollection;
|
||||
mySeqOfFormats : SequenceOfInteger from TColStd;
|
||||
|
||||
end Msg;
|
309
src/Message/Message_Msg.cxx
Executable file
309
src/Message/Message_Msg.cxx
Executable file
@@ -0,0 +1,309 @@
|
||||
// File: Message_Msg.cxx
|
||||
// Created: 27.04.01 19:44:52
|
||||
// Author: OCC Team
|
||||
// Copyright: Open CASCADE S.A. 2005
|
||||
|
||||
#include <Message_Msg.hxx>
|
||||
#include <Message_MsgFile.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
Msg_IntegerType,
|
||||
Msg_RealType,
|
||||
Msg_StringType,
|
||||
Msg_IndefiniteType
|
||||
} FormatType;
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_Msg()
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
|
||||
Message_Msg::Message_Msg ()
|
||||
{}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_Msg()
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
|
||||
Message_Msg::Message_Msg (const Message_Msg& theMsg)
|
||||
{
|
||||
myMessageBody = theMsg.myMessageBody;
|
||||
myOriginal = theMsg.myOriginal;
|
||||
for ( Standard_Integer i = 1, n = theMsg.mySeqOfFormats.Length(); i <=n; i++ )
|
||||
mySeqOfFormats.Append ( theMsg.mySeqOfFormats.Value(i) );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_Msg()
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
|
||||
Message_Msg::Message_Msg (const Standard_CString theMsgCode)
|
||||
{
|
||||
TCollection_AsciiString aKey((char*)theMsgCode);
|
||||
Set ( Message_MsgFile::Msg(aKey) );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_Msg()
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
|
||||
Message_Msg::Message_Msg (const TCollection_ExtendedString& theMsgCode)
|
||||
{
|
||||
Set ( Message_MsgFile::Msg(theMsgCode) );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Msg::Set (const Standard_CString theMsg)
|
||||
{
|
||||
TCollection_AsciiString aMsg((char*)theMsg);
|
||||
Set ( aMsg );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Msg::Set (const TCollection_ExtendedString& theMsg)
|
||||
{
|
||||
myMessageBody = theMsg;
|
||||
|
||||
const Standard_ExtString anExtString = myMessageBody.ToExtString();
|
||||
Standard_Integer anMsgLength = myMessageBody.Length();
|
||||
for (Standard_Integer i = 0; i < anMsgLength; i++)
|
||||
{
|
||||
// Search for '%' character starting a format specification
|
||||
if (ToCharacter (anExtString[i]) == '%')
|
||||
{
|
||||
Standard_Integer aStart = i++;
|
||||
Standard_Character aChar = ToCharacter (anExtString[i]);
|
||||
// Check for format '%%'
|
||||
if (aChar == '%')
|
||||
{
|
||||
myMessageBody.Remove (i+1);
|
||||
if (i >= --anMsgLength) break;
|
||||
aChar = ToCharacter (anExtString[i]);
|
||||
}
|
||||
// Skip flags, field width and precision
|
||||
while (i < anMsgLength)
|
||||
{
|
||||
if (aChar == '-' || aChar == '+' || aChar == ' ' ||
|
||||
aChar == '#' || (aChar >= '0' && aChar <= '9') || aChar == '.')
|
||||
i++;
|
||||
else break;
|
||||
aChar = ToCharacter (anExtString[i]);
|
||||
}
|
||||
if (i >= anMsgLength) break;
|
||||
|
||||
FormatType aFormatType;
|
||||
if (aChar == 'h' || aChar == 'l') aChar = ToCharacter (anExtString[++i]);
|
||||
switch (aChar) // detect the type of format spec
|
||||
{
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'o':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
aFormatType = Msg_IntegerType;
|
||||
break;
|
||||
case 'f':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
aFormatType = Msg_RealType;
|
||||
break;
|
||||
case 's':
|
||||
aFormatType = Msg_StringType;
|
||||
break;
|
||||
default:
|
||||
aFormatType = Msg_IndefiniteType;
|
||||
continue;
|
||||
}
|
||||
mySeqOfFormats.Append (Standard_Integer(aFormatType)); // type
|
||||
mySeqOfFormats.Append (aStart); // beginning pos
|
||||
mySeqOfFormats.Append (i + 1 - aStart); // length
|
||||
}
|
||||
}
|
||||
myOriginal = myMessageBody;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Arg (Standard_CString)
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Message_Msg& Message_Msg::Arg (const Standard_CString theString)
|
||||
{
|
||||
// get location and format
|
||||
TCollection_AsciiString aFormat;
|
||||
Standard_Integer aFirst = getFormat ( Msg_StringType, aFormat );
|
||||
if ( !aFirst )
|
||||
return *this;
|
||||
|
||||
// print string according to format
|
||||
char * sStringBuffer = new char [Max (strlen(theString)+1, 1024)];
|
||||
sprintf (sStringBuffer, aFormat.ToCString(), theString);
|
||||
TCollection_ExtendedString aStr ( sStringBuffer );
|
||||
delete sStringBuffer;
|
||||
sStringBuffer = 0;
|
||||
|
||||
// replace the format placeholder by the actual string
|
||||
replaceText ( aFirst, aFormat.Length(), aStr );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Arg (TCollection_ExtendedString)
|
||||
//purpose :
|
||||
//remark : This type of string is inserted without conversion (i.e. like %s)
|
||||
//=======================================================================
|
||||
|
||||
Message_Msg& Message_Msg::Arg (const TCollection_ExtendedString& theString)
|
||||
{
|
||||
// get location and format
|
||||
TCollection_AsciiString aFormat;
|
||||
Standard_Integer aFirst = getFormat ( Msg_StringType, aFormat );
|
||||
if ( !aFirst )
|
||||
return *this;
|
||||
|
||||
// replace the format placeholder by the actual string
|
||||
replaceText ( aFirst, aFormat.Length(), theString );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Arg (Standard_Integer)
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Message_Msg& Message_Msg::Arg (const Standard_Integer theValue)
|
||||
{
|
||||
// get location and format
|
||||
TCollection_AsciiString aFormat;
|
||||
Standard_Integer aFirst = getFormat ( Msg_IntegerType, aFormat );
|
||||
if ( !aFirst )
|
||||
return *this;
|
||||
|
||||
// print string according to format
|
||||
char sStringBuffer [64];
|
||||
sprintf (sStringBuffer, aFormat.ToCString(), theValue);
|
||||
TCollection_ExtendedString aStr ( sStringBuffer );
|
||||
|
||||
// replace the format placeholder by the actual string
|
||||
replaceText ( aFirst, aFormat.Length(), aStr );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Arg (Standard_Real)
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Message_Msg& Message_Msg::Arg (const Standard_Real theValue)
|
||||
{
|
||||
// get location and format
|
||||
TCollection_AsciiString aFormat;
|
||||
Standard_Integer aFirst = getFormat ( Msg_RealType, aFormat );
|
||||
if ( !aFirst )
|
||||
return *this;
|
||||
|
||||
// print string according to format
|
||||
char sStringBuffer [64];
|
||||
sprintf (sStringBuffer, aFormat.ToCString(), theValue);
|
||||
TCollection_ExtendedString aStr ( sStringBuffer );
|
||||
|
||||
// replace the format placeholder by the actual string
|
||||
replaceText ( aFirst, aFormat.Length(), aStr );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Get
|
||||
//purpose : used when the message is dispatched in Message_Messenger
|
||||
//=======================================================================
|
||||
|
||||
const TCollection_ExtendedString& Message_Msg::Get ()
|
||||
{
|
||||
// remove all non-initialised format specifications
|
||||
Standard_Integer i, anIncrement = 0;
|
||||
static const TCollection_ExtendedString anUnknown ("UNKNOWN");
|
||||
for (i = 1; i < mySeqOfFormats.Length(); i += 3)
|
||||
{
|
||||
TCollection_ExtendedString aRightPart =
|
||||
myMessageBody.Split(mySeqOfFormats(i+1) + anIncrement);
|
||||
aRightPart.Remove(1, mySeqOfFormats(i+2));
|
||||
myMessageBody += anUnknown;
|
||||
myMessageBody += aRightPart;
|
||||
anIncrement += (anUnknown.Length() - mySeqOfFormats(i+2));
|
||||
}
|
||||
return myMessageBody;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getFormat
|
||||
//purpose : Find placeholder in the string where to put next value of
|
||||
// specified type, return its starting position in the string
|
||||
// and relevant format string (located at that position).
|
||||
// The information on returned placeholder is deleted immediately,
|
||||
// so it will not be found further
|
||||
// If failed (no placeholder with relevant type found), returns 0
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Message_Msg::getFormat (const Standard_Integer theType,
|
||||
TCollection_AsciiString &theFormat)
|
||||
{
|
||||
for (Standard_Integer i = 1; i <= mySeqOfFormats.Length(); i += 3)
|
||||
if (mySeqOfFormats(i) == theType)
|
||||
{
|
||||
// Extract format
|
||||
Standard_Integer aFirst = mySeqOfFormats(i+1);
|
||||
Standard_Integer aLen = mySeqOfFormats(i+2);
|
||||
theFormat = TCollection_AsciiString ( aLen, ' ' );
|
||||
for ( Standard_Integer j=1; j <= aLen; j++ )
|
||||
if ( IsAnAscii ( myMessageBody.Value ( aFirst + j ) ) )
|
||||
theFormat.SetValue ( j, (Standard_Character)myMessageBody.Value ( aFirst + j ) );
|
||||
// delete information on this placeholder
|
||||
mySeqOfFormats.Remove (i, i+2);
|
||||
// return start position
|
||||
return aFirst + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : replaceText
|
||||
//purpose : Replace format text in myMessageBody (theNb chars from theFirst)
|
||||
// by string theStr
|
||||
//=======================================================================
|
||||
|
||||
void Message_Msg::replaceText (const Standard_Integer theFirst,
|
||||
const Standard_Integer theNb,
|
||||
const TCollection_ExtendedString &theStr)
|
||||
{
|
||||
myMessageBody.Remove ( theFirst, theNb );
|
||||
myMessageBody.Insert ( theFirst, theStr );
|
||||
|
||||
// update information on remaining format placeholders
|
||||
Standard_Integer anIncrement = theStr.Length() - theNb;
|
||||
if ( ! anIncrement ) return;
|
||||
for ( Standard_Integer i = 1; i <= mySeqOfFormats.Length(); i += 3 )
|
||||
if ( mySeqOfFormats(i+1) > theFirst )
|
||||
mySeqOfFormats(i+1) += anIncrement;
|
||||
}
|
73
src/Message/Message_Msg.lxx
Executable file
73
src/Message/Message_Msg.lxx
Executable file
@@ -0,0 +1,73 @@
|
||||
// File: Message_Msg.lxx
|
||||
// Created: 04.07.07 10:11:15
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
|
||||
#include <Message_Msg.hxx>
|
||||
|
||||
#ifndef _TCollection_HAsciiString_HeaderFile
|
||||
#include <TCollection_HAsciiString.hxx>
|
||||
#endif
|
||||
#ifndef _TCollection_HExtendedString_HeaderFile
|
||||
#include <TCollection_HExtendedString.hxx>
|
||||
#endif
|
||||
|
||||
//=======================================================================
|
||||
//function : Arg (TCollection_AsciiString)
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Message_Msg& Message_Msg::Arg (const TCollection_AsciiString& theString)
|
||||
{
|
||||
return Arg (theString.ToCString());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Arg (TCollection_HAsciiString)
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Message_Msg& Message_Msg::Arg (const Handle(TCollection_HAsciiString)& theString)
|
||||
{
|
||||
return Arg (theString->String().ToCString());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Arg (TCollection_HExtendedString)
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Message_Msg& Message_Msg::Arg (const Handle(TCollection_HExtendedString)& theString)
|
||||
{
|
||||
return Arg (theString->String());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Original
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline const TCollection_ExtendedString& Message_Msg::Original() const
|
||||
{
|
||||
return myOriginal;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline const TCollection_ExtendedString& Message_Msg::Value() const
|
||||
{
|
||||
return myMessageBody;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsEdited
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Boolean Message_Msg::IsEdited() const
|
||||
{
|
||||
return !myOriginal.IsEqual( myMessageBody );
|
||||
}
|
80
src/Message/Message_MsgFile.cdl
Executable file
80
src/Message/Message_MsgFile.cdl
Executable file
@@ -0,0 +1,80 @@
|
||||
-- File: Message_MsgFile.cdl
|
||||
-- Created: 26.04.01 18:24:38
|
||||
-- Author: OCC Team
|
||||
---Copyright: Open CASCADE S.A. 2007
|
||||
|
||||
|
||||
class MsgFile from Message
|
||||
|
||||
---Purpose: A tool providing facility to load definitions of message strings from
|
||||
-- resource file(s).
|
||||
--
|
||||
-- The message file is an ASCII file which defines a set of messages.
|
||||
-- Each message is identified by its keyword (string).
|
||||
--
|
||||
-- All lines in the file starting with the exclamation sign
|
||||
-- (perhaps preceeding by spaces and/or tabs) are ignored as comments.
|
||||
--
|
||||
-- Each line in the file starting with the dot character "."
|
||||
-- (perhaps preceeding by spaces and/or tabs) defines the keyword.
|
||||
-- The keyword is a string starting from the next symbol after dot
|
||||
-- and ending at the symbol preceeding ending newline character "\n".
|
||||
--
|
||||
-- All the lines in the file after the keyword and before next
|
||||
-- keyword (and which are not comments) define the message for that
|
||||
-- keyword. If the message consists of several lines, the message
|
||||
-- string will contain newline symbols "\n" between parts (but not
|
||||
-- at the end).
|
||||
--
|
||||
-- The experimental support of Unicode message files is provided.
|
||||
-- These are distinguished by two bytes FF.FE or FE.FF at the beginning.
|
||||
--
|
||||
-- The loaded messages are stored in static data map; all methods of that
|
||||
-- class are also static.
|
||||
|
||||
uses
|
||||
|
||||
CString,
|
||||
AsciiString from TCollection,
|
||||
ExtendedString from TCollection
|
||||
|
||||
is
|
||||
|
||||
Load (myclass; theDirName, theFileName: CString) returns Boolean;
|
||||
---Purpose: Load message file <theFileName> from directory <theDirName>
|
||||
-- or its sub-directory
|
||||
|
||||
|
||||
LoadFile (myclass; theFName: CString) returns Boolean;
|
||||
---Purpose: Load the messages from the given file, additive to any previously
|
||||
-- loaded messages. Messages with same keywords, if already present,
|
||||
-- are replaced with the new ones.
|
||||
|
||||
LoadFromEnv (myclass; envname: CString; filename: CString; ext: CString = "");
|
||||
---Purpose: Loads the messages from the file with name (without extension)
|
||||
-- given by environment variable.
|
||||
-- Extension of the file name is given separately. If its not
|
||||
-- defined, it is taken:
|
||||
-- - by default from environment CSF_LANGUAGE,
|
||||
-- - if not defined either, as "us".
|
||||
|
||||
AddMsg (myclass; key: AsciiString from TCollection;
|
||||
text: ExtendedString from TCollection) returns Boolean;
|
||||
---Purpose: Adds new message to the map. Parameter <key> gives
|
||||
-- the key of the message, <text> defines the message itself.
|
||||
-- If there already was defined the message identified by the
|
||||
-- same keyword, it is replaced with the new one.
|
||||
|
||||
Msg (myclass; key: CString) returns ExtendedString from TCollection;
|
||||
---C++: return const &
|
||||
Msg (myclass; key: AsciiString from TCollection) returns ExtendedString from TCollection;
|
||||
---C++: return const &
|
||||
---Purpose: Gives the text for the message identified by the keyword <key>
|
||||
-- If there are no messages with such keyword defined,
|
||||
-- the error message is returned.
|
||||
-- In that case reference to static string is returned, it can
|
||||
-- be chenged with next call(s) to Msg().
|
||||
-- Note: The error message is constructed like 'Unknown message: <key>', and can
|
||||
-- itself be customized by defining message with key Message_Msg_BadKeyword.
|
||||
|
||||
end MsgFile;
|
344
src/Message/Message_MsgFile.cxx
Executable file
344
src/Message/Message_MsgFile.cxx
Executable file
@@ -0,0 +1,344 @@
|
||||
// File: Message_MsgFile.cxx
|
||||
// Created: 26.04.01 19:48:39
|
||||
// Author: OCC Team
|
||||
// Copyright: Open CASCADE S.A. 2005
|
||||
|
||||
#include <Message_MsgFile.hxx>
|
||||
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
#include <NCollection_DefineBaseCollection.hxx>
|
||||
#include <NCollection_DefineDataMap.hxx>
|
||||
#include <OSD_Environment.hxx>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
DEFINE_BASECOLLECTION(Message_CollectionOfExtendedString, TCollection_ExtendedString)
|
||||
DEFINE_DATAMAP(Message_DataMapOfExtendedString,
|
||||
Message_CollectionOfExtendedString,
|
||||
TCollection_AsciiString,
|
||||
TCollection_ExtendedString)
|
||||
|
||||
static Message_DataMapOfExtendedString& msgsDataMap ()
|
||||
{
|
||||
static Message_DataMapOfExtendedString aDataMap;
|
||||
return aDataMap;
|
||||
}
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MsgFile_WaitingKeyword,
|
||||
MsgFile_WaitingMessage,
|
||||
MsgFile_WaitingMoreMessage,
|
||||
MsgFile_Indefinite
|
||||
} LoadingState;
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_MsgFile
|
||||
//purpose : Load file from given directories
|
||||
// theDirName may be represented as list: "/dirA/dirB /dirA/dirC"
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Message_MsgFile::Load (const Standard_CString theDirName,
|
||||
const Standard_CString theFileName)
|
||||
{
|
||||
if ( ! theDirName || ! theFileName ) return Standard_False;
|
||||
|
||||
Standard_Boolean ret = Standard_True;
|
||||
TCollection_AsciiString aDirList (theDirName);
|
||||
// Try to load from all consecutive directories in list
|
||||
for (int i = 1;; i++)
|
||||
{
|
||||
TCollection_AsciiString aFileName = aDirList.Token (" \t\n", i);
|
||||
if (aFileName.IsEmpty()) break;
|
||||
#ifdef WNT
|
||||
aFileName += '\\';
|
||||
#else
|
||||
aFileName += '/';
|
||||
#endif
|
||||
aFileName += theFileName;
|
||||
if ( ! LoadFile (aFileName.ToCString()) )
|
||||
ret = Standard_False;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getString
|
||||
//purpose : Takes a TCollection_ExtendedString from Ascii or Unicode
|
||||
// Strings are left-trimmed; those beginning with '!' are omitted
|
||||
//Called : from loadFile()
|
||||
//=======================================================================
|
||||
|
||||
template <class _Char> static inline Standard_Boolean
|
||||
getString (_Char *& thePtr,
|
||||
TCollection_ExtendedString& theString,
|
||||
Standard_Integer& theLeftSpaces)
|
||||
{
|
||||
_Char * anEndPtr = thePtr;
|
||||
_Char * aPtr;
|
||||
Standard_Integer aLeftSpaces;
|
||||
|
||||
do
|
||||
{
|
||||
// Skip whitespaces in the beginning of the string
|
||||
aPtr = anEndPtr;
|
||||
aLeftSpaces = 0;
|
||||
while (1)
|
||||
{
|
||||
_Char aChar = * aPtr;
|
||||
if (aChar == ' ') aLeftSpaces++;
|
||||
else if (aChar == '\t') aLeftSpaces += 8;
|
||||
else if (aChar == '\r' || * aPtr == '\n') aLeftSpaces = 0;
|
||||
else break;
|
||||
aPtr++;
|
||||
}
|
||||
|
||||
// Find the end of the string
|
||||
for (anEndPtr = aPtr; * anEndPtr; anEndPtr++)
|
||||
if (anEndPtr[0] == '\n')
|
||||
{
|
||||
if (anEndPtr[-1] == '\r') anEndPtr--;
|
||||
break;
|
||||
}
|
||||
|
||||
} while (aPtr[0] == '!');
|
||||
|
||||
// form the result
|
||||
if (aPtr == anEndPtr) return Standard_False;
|
||||
thePtr = anEndPtr;
|
||||
if (*thePtr)
|
||||
*thePtr++ = '\0';
|
||||
theString = TCollection_ExtendedString (aPtr);
|
||||
theLeftSpaces = aLeftSpaces;
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : loadFile
|
||||
//purpose : Static function, fills the DataMap of Messages from Ascii or Unicode
|
||||
//Called : from LoadFile()
|
||||
//=======================================================================
|
||||
|
||||
template <class _Char> static inline Standard_Boolean loadFile (_Char * theBuffer)
|
||||
{
|
||||
TCollection_AsciiString aKeyword;
|
||||
TCollection_ExtendedString aMessage, aString;
|
||||
LoadingState aState = MsgFile_WaitingKeyword;
|
||||
_Char * sCurrentString = theBuffer;
|
||||
Standard_Integer aLeftSpaces=0, aFirstLeftSpaces = 0;
|
||||
|
||||
// Take strings one-by-one; comments already screened
|
||||
while (::getString (sCurrentString, aString, aLeftSpaces))
|
||||
{
|
||||
Standard_Boolean isKeyword = (aString.Value(1) == '.');
|
||||
switch (aState)
|
||||
{
|
||||
case MsgFile_WaitingMoreMessage:
|
||||
if (isKeyword)
|
||||
Message_MsgFile::AddMsg (aKeyword, aMessage); // terminate the previous one
|
||||
// Pass from here to 'case MsgFile_WaitingKeyword'
|
||||
else
|
||||
{
|
||||
// Add another line to the message already in the buffer 'aMessage'
|
||||
aMessage += '\n';
|
||||
aLeftSpaces -= aFirstLeftSpaces;
|
||||
if (aLeftSpaces > 0) aMessage += TCollection_ExtendedString (aLeftSpaces, ' ');
|
||||
aMessage += aString;
|
||||
break;
|
||||
}
|
||||
case MsgFile_WaitingMessage:
|
||||
if (isKeyword == Standard_False)
|
||||
{
|
||||
aMessage = aString;
|
||||
aFirstLeftSpaces = aLeftSpaces; // remember the starting position
|
||||
aState = MsgFile_WaitingMoreMessage;
|
||||
break;
|
||||
}
|
||||
// Pass from here to 'case MsgFile_WaitingKeyword'
|
||||
case MsgFile_WaitingKeyword:
|
||||
if (isKeyword)
|
||||
{
|
||||
// remove the first dot character and all subsequent spaces + right-trim
|
||||
aKeyword = TCollection_AsciiString (aString.Split(1));
|
||||
aKeyword.LeftAdjust();
|
||||
aKeyword.RightAdjust();
|
||||
aState = MsgFile_WaitingMessage;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Process the last string still remaining in the buffer
|
||||
if (aState == MsgFile_WaitingMoreMessage)
|
||||
Message_MsgFile::AddMsg (aKeyword, aMessage);
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetFileSize
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
static Standard_Integer GetFileSize (FILE *theFile)
|
||||
{
|
||||
if ( !theFile ) return -1;
|
||||
|
||||
// get real file size
|
||||
long nRealFileSize = 0;
|
||||
if ( fseek(theFile, 0, SEEK_END) != 0 ) return -1;
|
||||
nRealFileSize = ftell(theFile);
|
||||
if ( fseek(theFile, 0, SEEK_SET) != 0 ) return -1;
|
||||
|
||||
return (Standard_Integer) nRealFileSize;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LoadFile
|
||||
//purpose : Load the list of messages from a file
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Message_MsgFile::LoadFile (const Standard_CString theFileName)
|
||||
{
|
||||
if (theFileName == NULL || * theFileName == '\0') return Standard_False;
|
||||
|
||||
// Open the file
|
||||
FILE *anMsgFile = fopen (theFileName, "rb");
|
||||
if (!anMsgFile) return Standard_False;
|
||||
|
||||
// Read the file into memory
|
||||
class Buffer
|
||||
{
|
||||
// self-destructing buffer
|
||||
char *myBuf;
|
||||
public:
|
||||
Buffer (Standard_Integer theSize) : myBuf(new char [theSize]) {}
|
||||
~Buffer () { delete [] myBuf; }
|
||||
operator char* () const { return myBuf; }
|
||||
char& operator [] (Standard_Integer theInd) { return myBuf[theInd]; }
|
||||
};
|
||||
Standard_Integer aFileSize = GetFileSize (anMsgFile);
|
||||
if (aFileSize <= 0)
|
||||
{
|
||||
fclose (anMsgFile);
|
||||
return Standard_False;
|
||||
}
|
||||
Buffer anMsgBuffer (aFileSize + 2);
|
||||
Standard_Integer nbRead =
|
||||
(Standard_Integer) fread (anMsgBuffer, 1, aFileSize, anMsgFile);
|
||||
fclose (anMsgFile);
|
||||
if (nbRead != aFileSize)
|
||||
return Standard_False;
|
||||
anMsgBuffer[aFileSize] = 0;
|
||||
anMsgBuffer[aFileSize+1] = 0;
|
||||
|
||||
// Read the messages in the file and append them to the global DataMap
|
||||
Standard_Boolean isLittleEndian = (anMsgBuffer[0] == '\xff' && anMsgBuffer[1] == '\xfe');
|
||||
Standard_Boolean isBigEndian = (anMsgBuffer[0] == '\xfe' && anMsgBuffer[1] == '\xff');
|
||||
if ( isLittleEndian || isBigEndian )
|
||||
{
|
||||
Standard_ExtCharacter * aUnicodeBuffer =
|
||||
(Standard_ExtCharacter *) &anMsgBuffer[2];
|
||||
// Convert Unicode representation to order adopted on current platform
|
||||
#if defined(__sparc) && defined(__sun)
|
||||
if ( isLittleEndian )
|
||||
#else
|
||||
if ( isBigEndian )
|
||||
#endif
|
||||
{
|
||||
// Reverse the bytes throughout the buffer
|
||||
for (Standard_ExtCharacter * aPtr = aUnicodeBuffer;
|
||||
aPtr < (Standard_ExtCharacter *) &anMsgBuffer[aFileSize]; aPtr++)
|
||||
{
|
||||
unsigned short aWord = *aPtr;
|
||||
*aPtr = (aWord & 0x00ff) << 8 | (aWord & 0xff00) >> 8;
|
||||
}
|
||||
}
|
||||
return ::loadFile (aUnicodeBuffer);
|
||||
}
|
||||
else
|
||||
return ::loadFile ((char*) anMsgBuffer);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LoadFromEnv
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void Message_MsgFile::LoadFromEnv
|
||||
(const Standard_CString envname,
|
||||
const Standard_CString filename,
|
||||
const Standard_CString ext)
|
||||
{
|
||||
Standard_CString extname = ext;
|
||||
TCollection_AsciiString extstr;
|
||||
if (!extname || extname[0] == '\0') {
|
||||
OSD_Environment extenv("CSF_LANGUAGE");
|
||||
extstr = extenv.Value();
|
||||
extname = extstr.ToCString();
|
||||
}
|
||||
if (!extname || extname[0] == '\0') extname = "us";
|
||||
|
||||
TCollection_AsciiString filestr(filename);
|
||||
if (envname && envname[0] != '\0') {
|
||||
OSD_Environment envenv(envname);
|
||||
TCollection_AsciiString envstr = envenv.Value();
|
||||
if (envstr.Length() > 0) {
|
||||
if (envstr.Value(envstr.Length()) != '/') filestr.Insert (1,'/');
|
||||
filestr.Insert (1,envstr.ToCString());
|
||||
}
|
||||
}
|
||||
if (extname[0] != '.') filestr.AssignCat ('.');
|
||||
filestr.AssignCat (extname);
|
||||
|
||||
Message_MsgFile::LoadFile (filestr.ToCString());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddMsg
|
||||
//purpose : Add one message to the global table. Fails if the same keyword
|
||||
// already exists in the table
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Message_MsgFile::AddMsg (const TCollection_AsciiString& theKeyword,
|
||||
const TCollection_ExtendedString& theMessage)
|
||||
{
|
||||
Message_DataMapOfExtendedString& aDataMap = ::msgsDataMap();
|
||||
// if (aDataMap.IsBound (theKeyword))
|
||||
// return Standard_False;
|
||||
aDataMap.Bind (theKeyword, theMessage);
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getMsg
|
||||
//purpose : retrieve the message previously defined for the given keyword
|
||||
//=======================================================================
|
||||
|
||||
const TCollection_ExtendedString &Message_MsgFile::Msg (const Standard_CString theKeyword)
|
||||
{
|
||||
TCollection_AsciiString aKey((char*)theKeyword);
|
||||
return Msg (aKey);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getMsg
|
||||
//purpose : retrieve the message previously defined for the given keyword
|
||||
//=======================================================================
|
||||
|
||||
const TCollection_ExtendedString &Message_MsgFile::Msg (const TCollection_AsciiString& theKeyword)
|
||||
{
|
||||
// find message in the map
|
||||
Message_DataMapOfExtendedString& aDataMap = ::msgsDataMap();
|
||||
if (aDataMap.IsBound (theKeyword))
|
||||
return aDataMap.Find (theKeyword);
|
||||
|
||||
// if not found, generate error message
|
||||
static const TCollection_ExtendedString aDefPrefix ("Unknown message invoked with the keyword: ");
|
||||
static const TCollection_AsciiString aPrefixCode ("Message_Msg_BadKeyword");
|
||||
static TCollection_ExtendedString aFailureMessage;
|
||||
if (aDataMap.IsBound (aPrefixCode))
|
||||
aFailureMessage = aDataMap.Find (aPrefixCode) + " " + theKeyword;
|
||||
else aFailureMessage = aDefPrefix + theKeyword;
|
||||
return aFailureMessage;
|
||||
}
|
47
src/Message/Message_Printer.cdl
Executable file
47
src/Message/Message_Printer.cdl
Executable file
@@ -0,0 +1,47 @@
|
||||
-- File: Message_Printer.cdl
|
||||
-- Created: Sat Jan 6 19:12:06 2001
|
||||
-- Author: OCC Team
|
||||
---Copyright: Open CASCADE S.A. 2005
|
||||
|
||||
|
||||
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.
|
||||
|
||||
uses
|
||||
|
||||
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().
|
||||
|
||||
end Printer;
|
33
src/Message/Message_Printer.cxx
Executable file
33
src/Message/Message_Printer.cxx
Executable file
@@ -0,0 +1,33 @@
|
||||
// File: Message_Printer.cxx
|
||||
// Created: Sat Jan 6 19:26:55 2001
|
||||
// Author: OCC Team
|
||||
// Copyright: Open CASCADE S.A. 2005
|
||||
|
||||
#include <Message_Printer.ixx>
|
||||
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Send
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Printer::Send (const Standard_CString theString,
|
||||
const Message_Gravity theGravity,
|
||||
const Standard_Boolean putEndl) const
|
||||
{
|
||||
Send ( TCollection_ExtendedString(theString), theGravity, putEndl );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Send
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_Printer::Send (const TCollection_AsciiString& theString,
|
||||
const Message_Gravity theGravity,
|
||||
const Standard_Boolean putEndl) const
|
||||
{
|
||||
Send ( TCollection_ExtendedString(theString), theGravity, putEndl );
|
||||
}
|
94
src/Message/Message_PrinterOStream.cdl
Executable file
94
src/Message/Message_PrinterOStream.cdl
Executable file
@@ -0,0 +1,94 @@
|
||||
-- File: Message_PrinterOStream.cdl
|
||||
-- Created: Sat Jan 6 19:52:34 2001
|
||||
-- Author: OCC Team
|
||||
---Copyright: Open CASCADE S.A. 2005
|
||||
|
||||
|
||||
class PrinterOStream from Message inherits Printer from Message
|
||||
|
||||
---Purpose: Implementation of a message printer associated with an ostream
|
||||
-- The ostream may be either externally defined one (e.g. cout),
|
||||
-- or file stream maintained internally (depending on constructor).
|
||||
|
||||
uses
|
||||
|
||||
Address from Standard,
|
||||
OStream from Standard,
|
||||
Gravity from Message,
|
||||
AsciiString from TCollection,
|
||||
ExtendedString from TCollection
|
||||
|
||||
is
|
||||
|
||||
Create (theTraceLevel: Gravity from Message = Message_Info)
|
||||
returns PrinterOStream from Message;
|
||||
---Purpose: Empty constructor, defaulting to cout
|
||||
|
||||
Create (theFileName: CString; theDoAppend: Boolean;
|
||||
theTraceLevel: Gravity from Message = Message_Info)
|
||||
returns PrinterOStream from Message;
|
||||
---Purpose: Create printer for output to a specified file.
|
||||
-- The option theDoAppend specifies whether file should be
|
||||
-- appended or rewritten.
|
||||
-- For specific file names (cout, cerr) standard streams are used
|
||||
|
||||
Close (me: mutable);
|
||||
---C++: alias ~
|
||||
---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
|
||||
---C++: inline
|
||||
|
||||
SetUseUtf8 (me: mutable; useUtf8: Boolean);
|
||||
---Purpose: Sets option to convert non-Ascii symbols to UTF8 encoding
|
||||
---C++: inline
|
||||
|
||||
GetStream (me) returns OStream;
|
||||
---Purpose: Returns reference to the output stream
|
||||
---C++: return &
|
||||
---C++: inline
|
||||
|
||||
Send (me; theString : CString; theGravity: Gravity from Message;
|
||||
putEndl: Boolean = Standard_True) is redefined;
|
||||
---Purpose: Puts a message to the current stream
|
||||
-- if its gravity is equal or greater
|
||||
-- to the trace level set by SetTraceLevel()
|
||||
|
||||
Send (me; theString : AsciiString from TCollection;
|
||||
theGravity: Gravity from Message;
|
||||
putEndl: Boolean = Standard_True) is redefined;
|
||||
---Purpose: Puts a message to the current stream
|
||||
-- if its gravity is equal or greater
|
||||
-- to the trace level set by SetTraceLevel()
|
||||
|
||||
Send (me; theString : ExtendedString from TCollection;
|
||||
theGravity: Gravity from Message;
|
||||
putEndl: Boolean = Standard_True) is redefined;
|
||||
---Purpose: Puts a message to the current stream
|
||||
-- if its gravity is equal or greater
|
||||
-- to the trace level set by SetTraceLevel()
|
||||
-- Non-Ascii symbols are converted to UTF-8 if UseUtf8
|
||||
-- option is set, else replaced by symbols '?'
|
||||
|
||||
fields
|
||||
|
||||
myTraceLevel: Gravity from Message;
|
||||
myStream: Address from Standard; -- pointer to OStream
|
||||
myIsFile: Boolean from Standard;
|
||||
myUseUtf8: Boolean from Standard;
|
||||
|
||||
end PrinterOStream;
|
131
src/Message/Message_PrinterOStream.cxx
Executable file
131
src/Message/Message_PrinterOStream.cxx
Executable file
@@ -0,0 +1,131 @@
|
||||
// File: Message_PrinterOStream.cxx
|
||||
// Created: Sat Jan 6 20:01:38 2001
|
||||
// Author: OCC Team
|
||||
// Copyright: Open CASCADE S.A. 2005
|
||||
|
||||
#include <Message_PrinterOStream.ixx>
|
||||
|
||||
#include <Message_Gravity.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
#include <Standard_Mutex.hxx>
|
||||
#include <Standard_Stream.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Constructor
|
||||
//purpose : Empty constructor, defaulting to cerr
|
||||
//=======================================================================
|
||||
|
||||
Message_PrinterOStream::Message_PrinterOStream (const Message_Gravity theTraceLevel)
|
||||
: myTraceLevel(theTraceLevel), myStream(&cout),
|
||||
myIsFile(Standard_False), myUseUtf8(Standard_False)
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Constructor
|
||||
//purpose : Opening a file as an ostream
|
||||
// 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)
|
||||
{
|
||||
if ( strcasecmp(theFileName, "cout") == 0 )
|
||||
myStream = &cerr;
|
||||
else if ( strcasecmp(theFileName, "cerr") == 0 )
|
||||
myStream = &cout;
|
||||
else
|
||||
{
|
||||
TCollection_AsciiString aFileName (theFileName);
|
||||
#ifdef WNT
|
||||
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 ) );
|
||||
#else
|
||||
(doAppend ? ios::app : ios::out ) );
|
||||
#endif
|
||||
if ( ofile ) {
|
||||
myStream = (Standard_OStream*)ofile;
|
||||
myIsFile = Standard_True;
|
||||
}
|
||||
else {
|
||||
myStream = &cout;
|
||||
cerr << "Error opening " << theFileName << endl << flush;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Close
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_PrinterOStream::Close ()
|
||||
{
|
||||
if ( ! myStream ) return;
|
||||
Standard_OStream* ostr = (Standard_OStream*)myStream;
|
||||
myStream = 0;
|
||||
|
||||
ostr->flush();
|
||||
if ( myIsFile )
|
||||
{
|
||||
ofstream* ofile = (ofstream*)ostr;
|
||||
ofile->close();
|
||||
delete ofile;
|
||||
myIsFile = Standard_False;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Send
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_PrinterOStream::Send (const Standard_CString theString,
|
||||
const Message_Gravity theGravity,
|
||||
const Standard_Boolean putEndl) const
|
||||
{
|
||||
if ( theGravity < myTraceLevel || ! myStream ) return;
|
||||
Standard_OStream* ostr = (Standard_OStream*)myStream;
|
||||
(*ostr) << theString;
|
||||
if ( putEndl ) (*ostr) << endl;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Send
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_PrinterOStream::Send (const TCollection_AsciiString &theString,
|
||||
const Message_Gravity theGravity,
|
||||
const Standard_Boolean putEndl) const
|
||||
{
|
||||
Send ( theString.ToCString(), theGravity, putEndl );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Send
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_PrinterOStream::Send (const TCollection_ExtendedString &theString,
|
||||
const Message_Gravity theGravity,
|
||||
const Standard_Boolean putEndl) const
|
||||
{
|
||||
// Note: the string might need to be converted to Ascii
|
||||
if ( myUseUtf8 ) {
|
||||
char* astr = new char[theString.LengthOfCString()+1];
|
||||
theString.ToUTF8CString (astr);
|
||||
Send ( astr, theGravity, putEndl );
|
||||
delete astr;
|
||||
}
|
||||
else {
|
||||
TCollection_AsciiString aStr ( theString, '?' );
|
||||
Send ( aStr.ToCString(), theGravity, putEndl );
|
||||
}
|
||||
}
|
57
src/Message/Message_PrinterOStream.lxx
Executable file
57
src/Message/Message_PrinterOStream.lxx
Executable file
@@ -0,0 +1,57 @@
|
||||
// File: Message_PrinterOStream.lxx
|
||||
// Created: 28.06.07 14:31:55
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE S.A. 2007
|
||||
|
||||
#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 :
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Boolean Message_PrinterOStream::GetUseUtf8() const
|
||||
{
|
||||
return myUseUtf8;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetUseUtf8
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_PrinterOStream::SetUseUtf8 (const Standard_Boolean useUtf8)
|
||||
{
|
||||
myUseUtf8 = useUtf8;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetStream
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_OStream& Message_PrinterOStream::GetStream () const
|
||||
{
|
||||
return *(Standard_OStream*)myStream;
|
||||
}
|
||||
|
182
src/Message/Message_ProgressIndicator.cdl
Executable file
182
src/Message/Message_ProgressIndicator.cdl
Executable file
@@ -0,0 +1,182 @@
|
||||
-- File: Message_ProgressIndicator.cdl
|
||||
-- Created: Wed Feb 20 13:43:47 2002
|
||||
-- Author: Andrey BETENEV
|
||||
-- <abv@doomox>
|
||||
---Copyright: Open CASCADE SA 2002
|
||||
|
||||
|
||||
deferred class ProgressIndicator from Message inherits TShared from MMgt
|
||||
|
||||
---Purpose: Defines abstract interface from program to the "user".
|
||||
-- That includes progress indication and user break mechanisms
|
||||
--
|
||||
-- The interface to progress indicator represents it as a scale
|
||||
-- for each range and step can be defined by the program that uses it.
|
||||
-- The scale can be made "infinite", which means it will grow
|
||||
-- non-linearly, end of scale will be approached asymptotically at
|
||||
-- infinite number of steps. In that case value of scale range
|
||||
-- gives a number of steps corresponding to position at 1/2 of scale.
|
||||
-- The current position can be either set directly (in a range from
|
||||
-- current position to maximum scale value), or incremented step
|
||||
-- by step.
|
||||
--
|
||||
-- Progress indication mechanism is adapted for convenient
|
||||
-- usage in hiererchical processes that require indication of
|
||||
-- progress at several (sub)levels of the process.
|
||||
-- For that purpose, it is possible to create restricted sub-scope of
|
||||
-- indication by specifying part of a current scale that is to be
|
||||
-- used by the subprocess.
|
||||
-- When subprocess works with progress indicator in the restricted
|
||||
-- scope, it has the same interface to a scale, while actually it
|
||||
-- deals only with part of the whole scale.
|
||||
--
|
||||
-- NOTE:
|
||||
-- Currently there is no support for concurrent progress
|
||||
-- indicator that could be useful in multithreaded applications.
|
||||
-- The main reason for this is that such implementation would be
|
||||
-- too complex regarding forecasted lack of real need for such
|
||||
-- support.
|
||||
-- To support this it would require that ProgressScale keep its
|
||||
-- own position and take care of incrementing main ProgressIndicator
|
||||
-- in destructor. This would also require having cross-references
|
||||
-- between nested instances of ProgressScale, ie. potential
|
||||
-- problems with memory management.
|
||||
-- In case of need of concurrent progress indicator two things can
|
||||
-- be suggested: either creation of single spane with summary number
|
||||
-- of steps, or usage of infinite scale.
|
||||
--
|
||||
-- The user break is implemented as virtual function that might
|
||||
-- return True in case if break signal from the user is obtained.
|
||||
--
|
||||
-- The derived classes should take care of visualisation of the
|
||||
-- progress indicator (e.g. show total position at the graphical bar,
|
||||
-- and/or print all scopes in text mode), and for implementation
|
||||
-- of user break mechanism (if defined).
|
||||
|
||||
uses
|
||||
HAsciiString from TCollection,
|
||||
ProgressScale from Message,
|
||||
SequenceOfProgressScale from Message
|
||||
is
|
||||
|
||||
---Scope: Initialisations
|
||||
|
||||
Initialize returns mutable ProgressIndicator from Message;
|
||||
---Purpose: Constructor, just calls own Reset() (not yet redefined)
|
||||
|
||||
Reset (me: mutable) is virtual;
|
||||
---Purpose: Drops all scopes and sets scale from 0 to 100, step 1
|
||||
-- This scale has name "Step"
|
||||
|
||||
---Scope: Program API
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Management of current scale
|
||||
|
||||
SetName (me: mutable; name: CString);
|
||||
---C++: inline
|
||||
SetName (me: mutable; name: HAsciiString from TCollection);
|
||||
---C++: inline
|
||||
---Purpose: Set (optional) name for scale
|
||||
|
||||
SetRange (me: mutable; min, max: Real);
|
||||
---C++: inline
|
||||
---Purpose: Set range for current scale
|
||||
|
||||
SetStep (me: mutable; step: Real);
|
||||
---C++: inline
|
||||
---Purpose: Set step for current scale
|
||||
|
||||
SetInfinite (me: mutable; isInf: Boolean = Standard_True);
|
||||
---C++: inline
|
||||
---Purpose: Set or drop infinite mode for the current scale
|
||||
|
||||
SetScale (me: mutable; name: CString; min, max, step: Real; isInf: Boolean = Standard_False);
|
||||
---C++: inline
|
||||
SetScale (me: mutable; min, max, step: Real; isInf: Boolean = Standard_False);
|
||||
---Purpose: Set all parameters for current scale
|
||||
|
||||
GetScale (me; min, max, step: out Real; isInf: out Boolean);
|
||||
---Purpose: Returns all parameters for current scale
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Management of current progress value
|
||||
|
||||
SetValue (me: mutable; val: Real);
|
||||
GetValue (me) returns Real;
|
||||
---Purpose: Set and get progress value at current scale
|
||||
-- If the value to be set is more than currently set one, or out
|
||||
-- of range for the current scale, it is limited by that range
|
||||
|
||||
Increment (me: mutable);
|
||||
---C++: inline
|
||||
Increment (me: mutable; step: Real);
|
||||
---C++: inline
|
||||
---Purpose: Increment the progress value by the default of specified step
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Management of scopes
|
||||
|
||||
NewScope (me: mutable; name: CString = 0) returns Boolean;
|
||||
---C++: inline
|
||||
NewScope (me: mutable; name: HAsciiString from TCollection) returns Boolean;
|
||||
---C++: inline
|
||||
NewScope (me: mutable; span: Real; name: CString = 0) returns Boolean;
|
||||
---C++: inline
|
||||
NewScope (me: mutable; span: Real; name: HAsciiString from TCollection) returns Boolean;
|
||||
---Purpose: Creates new scope on a part of a current scale from current
|
||||
-- position with span either equal to default step, or specified
|
||||
-- The scale for the new scope will have specified name and
|
||||
-- ranged from 0 to 100 with step 1
|
||||
-- Returns False if something is wrong in arguments or in current
|
||||
-- position of progress indicator; scope is opened anyway
|
||||
|
||||
EndScope (me: mutable) returns Boolean;
|
||||
---Purpose: Close the current scope and thus return to previous scale
|
||||
-- Updates position to be at the end of the closing scope
|
||||
-- Returns False if no scope is opened
|
||||
|
||||
NextScope (me: mutable; name: CString = 0) returns Boolean;
|
||||
---C++: inline
|
||||
NextScope (me: mutable; span: Real; name: CString = 0) returns Boolean;
|
||||
---Purpose: Optimized version of { return EndScope() && NewScope(); }
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- User break mechanism
|
||||
|
||||
UserBreak (me: mutable) returns Boolean is virtual;
|
||||
---Purpose: Should return True if user has send a break signal.
|
||||
-- Default implementation returns False.
|
||||
|
||||
|
||||
---Scope: Deferred methods to be defined by descendants
|
||||
|
||||
Show (me: mutable; force: Boolean = Standard_True) returns Boolean is deferred;
|
||||
---Purpose: Update presentation of the progress indicator
|
||||
-- Called when progress position is changed
|
||||
-- Flag force is intended for forcing update in case if it is
|
||||
-- optimized; all internal calls from ProgressIndicator are
|
||||
-- done with this flag equal to False
|
||||
|
||||
---Scope: Methods to request state of progress indicator (mainly for descendants)
|
||||
|
||||
GetPosition (me) returns Real;
|
||||
---C++: inline
|
||||
---Purpose: Returns total progress position on the basic scale
|
||||
-- ranged from 0. to 1.
|
||||
|
||||
GetNbScopes (me) returns Integer;
|
||||
---Purpose: Returns current number of opened scopes
|
||||
-- This number is always >=1 as top-level scale is always present
|
||||
|
||||
GetScope (me; index: Integer) returns ProgressScale from Message;
|
||||
---C++: return const &
|
||||
---Purpose: Returns data for scale of index-th scope
|
||||
-- The first scope is current one, the last is the top-level one
|
||||
|
||||
fields
|
||||
|
||||
myPosition: Real;
|
||||
myScopes: SequenceOfProgressScale from Message;
|
||||
|
||||
end ProgressIndicator;
|
156
src/Message/Message_ProgressIndicator.cxx
Executable file
156
src/Message/Message_ProgressIndicator.cxx
Executable file
@@ -0,0 +1,156 @@
|
||||
#include <Message_ProgressIndicator.ixx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_ProgressIndicator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Message_ProgressIndicator::Message_ProgressIndicator ()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Reset
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_ProgressIndicator::Reset ()
|
||||
{
|
||||
myPosition = 0.;
|
||||
|
||||
Message_ProgressScale scale;
|
||||
scale.SetName ( "Step" );
|
||||
scale.SetSpan ( 0., 1. );
|
||||
|
||||
myScopes.Clear();
|
||||
myScopes.Append ( scale );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetScale
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_ProgressIndicator::SetScale (const Standard_Real min,
|
||||
const Standard_Real max,
|
||||
const Standard_Real step,
|
||||
const Standard_Boolean isInf)
|
||||
{
|
||||
Message_ProgressScale &scale = myScopes.ChangeValue(1);
|
||||
scale.SetRange ( min, max );
|
||||
scale.SetStep ( step );
|
||||
scale.SetInfinite ( isInf );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetScale
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_ProgressIndicator::GetScale (Standard_Real &min,
|
||||
Standard_Real &max,
|
||||
Standard_Real &step,
|
||||
Standard_Boolean &isInf) const
|
||||
{
|
||||
const Message_ProgressScale &scale = myScopes(1);
|
||||
min = scale.GetMin();
|
||||
max = scale.GetMax();
|
||||
step = scale.GetStep();
|
||||
isInf = scale.GetInfinite();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetValue
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_ProgressIndicator::SetValue (const Standard_Real val)
|
||||
{
|
||||
const Message_ProgressScale &scale = myScopes(1);
|
||||
Standard_Real p = scale.LocalToBase ( val );
|
||||
if ( myPosition < p ) {
|
||||
myPosition = Min ( p, 1. );
|
||||
Show(Standard_False);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetValue
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Real Message_ProgressIndicator::GetValue () const
|
||||
{
|
||||
return myScopes(1).BaseToLocal ( myPosition );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NewScope
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Message_ProgressIndicator::NewScope (const Standard_Real span,
|
||||
const Handle(TCollection_HAsciiString) &name)
|
||||
{
|
||||
Message_ProgressScale scale;
|
||||
scale.SetName ( name );
|
||||
scale.SetSpan ( myPosition, myScopes(1).LocalToBase ( GetValue() + span ) );
|
||||
myScopes.Prepend ( scale );
|
||||
// Show(Standard_False); // to update textual representation, if any
|
||||
return myPosition < 1.;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : EndScope
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Message_ProgressIndicator::EndScope ()
|
||||
{
|
||||
Standard_Real end = myScopes(1).GetLast();
|
||||
Standard_Boolean ret = ( myScopes.Length() >1 );
|
||||
if ( ret ) myScopes.Remove(1);
|
||||
if ( myPosition != end ) {
|
||||
myPosition = end;
|
||||
Show(Standard_False);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NextScope
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Message_ProgressIndicator::NextScope (const Standard_Real span,
|
||||
const Standard_CString name)
|
||||
{
|
||||
Message_ProgressScale &scale = myScopes.ChangeValue(1);
|
||||
if ( myPosition != scale.GetLast() ) {
|
||||
myPosition = scale.GetLast();
|
||||
Show(Standard_False);
|
||||
}
|
||||
if ( myScopes.Length() <2 ) return Standard_False;
|
||||
|
||||
if ( name ) scale.SetName ( name );
|
||||
const Message_ProgressScale &scale2 = myScopes(2);
|
||||
scale.SetSpan ( myPosition, scale2.LocalToBase ( scale2.BaseToLocal(myPosition) + span ) );
|
||||
// if ( myMax - myMin <= gp::Resolution() ) return myLast;
|
||||
// Standard_Real next = ( myMax - myMin <= gp::Resolution() ? 1. - myPosition :
|
||||
// span * ( scale2.GetLast() - scale2.GetFirst() ) /
|
||||
// ( scale2.GetMax() - scale2.GetMin() ) );
|
||||
// scale.SetSpan ( myPosition, myPosition + next );
|
||||
return myPosition < 1.;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : UserBreak
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Message_ProgressIndicator::UserBreak ()
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
|
161
src/Message/Message_ProgressIndicator.lxx
Executable file
161
src/Message/Message_ProgressIndicator.lxx
Executable file
@@ -0,0 +1,161 @@
|
||||
#include <Message_ProgressScale.hxx>
|
||||
#include <TCollection_HAsciiString.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : SetName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressIndicator::SetName (const Standard_CString name)
|
||||
{
|
||||
if (name != 0)
|
||||
myScopes.ChangeValue(1).SetName ( name );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressIndicator::SetName (const Handle(TCollection_HAsciiString) &name)
|
||||
{
|
||||
if (!name.IsNull())
|
||||
myScopes.ChangeValue(1).SetName ( name );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetRange
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressIndicator::SetRange (const Standard_Real min,
|
||||
const Standard_Real max)
|
||||
{
|
||||
myScopes.ChangeValue(1).SetRange ( min, max );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetStep
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressIndicator::SetStep (const Standard_Real step)
|
||||
{
|
||||
myScopes.ChangeValue(1).SetStep ( step );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetInfinite
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressIndicator::SetInfinite (const Standard_Boolean isInf)
|
||||
{
|
||||
myScopes.ChangeValue(1).SetInfinite ( isInf );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetScale
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressIndicator::SetScale (const Standard_CString name,
|
||||
const Standard_Real min,
|
||||
const Standard_Real max,
|
||||
const Standard_Real step,
|
||||
const Standard_Boolean isInf)
|
||||
{
|
||||
SetName ( name );
|
||||
SetScale ( min, max, step, isInf );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Increment
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressIndicator::Increment ()
|
||||
{
|
||||
Increment ( myScopes(1).GetStep() );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Increment
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressIndicator::Increment (const Standard_Real step)
|
||||
{
|
||||
SetValue ( GetValue() + step );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NewScope
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Boolean Message_ProgressIndicator::NewScope (const Standard_CString name)
|
||||
{
|
||||
return NewScope ( name ? new TCollection_HAsciiString ( name ) : 0 );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NewScope
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Boolean Message_ProgressIndicator::NewScope (const Handle(TCollection_HAsciiString) &name)
|
||||
{
|
||||
return NewScope ( myScopes(1).GetStep(), name );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NewScope
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Boolean Message_ProgressIndicator::NewScope (const Standard_Real span,
|
||||
const Standard_CString name)
|
||||
{
|
||||
return NewScope ( span, name ? new TCollection_HAsciiString ( name ) : 0 );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NextScope
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Boolean Message_ProgressIndicator::NextScope (const Standard_CString name)
|
||||
{
|
||||
return NextScope ( myScopes.Length() >1 ? myScopes(1).GetStep() : 1., name );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetPosition
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Real Message_ProgressIndicator::GetPosition () const
|
||||
{
|
||||
return myPosition;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetNbScopes
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Integer Message_ProgressIndicator::GetNbScopes () const
|
||||
{
|
||||
return myScopes.Length();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetScope
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline const Message_ProgressScale &Message_ProgressIndicator::GetScope (const Standard_Integer index) const
|
||||
{
|
||||
return myScopes(index);
|
||||
}
|
108
src/Message/Message_ProgressScale.cdl
Executable file
108
src/Message/Message_ProgressScale.cdl
Executable file
@@ -0,0 +1,108 @@
|
||||
-- File: Message_ProgressScale.cdl
|
||||
-- Created: Wed Feb 20 15:52:41 2002
|
||||
-- Author: Andrey BETENEV
|
||||
-- <abv@doomox>
|
||||
---Copyright: Open CASCADE SA 2002
|
||||
|
||||
|
||||
class ProgressScale from Message
|
||||
|
||||
---Purpose: Internal data structure for scale in ProgressIndicator
|
||||
--
|
||||
-- Basically it defines three things:
|
||||
-- - name that can be used for generating user messages
|
||||
-- - limits and characteristics of the current scale,
|
||||
-- along with derived coefficients to map it into basic scale [0-1]
|
||||
-- - methods for conversion of values from current scale
|
||||
-- to basic one and back
|
||||
--
|
||||
-- NOTE: There is no special protection against bad input data
|
||||
-- like min > max etc. except cases when it can cause exception
|
||||
|
||||
uses
|
||||
HAsciiString from TCollection
|
||||
is
|
||||
|
||||
Create returns ProgressScale from Message;
|
||||
---Purpose: Creates scale ranged from 0 to 100 with step 1
|
||||
|
||||
---Scope: Access to fields
|
||||
|
||||
SetName(me : out; theName : CString);
|
||||
---C++:inline
|
||||
SetName(me : out; theName : HAsciiString from TCollection);
|
||||
---C++:inline
|
||||
---Purpose: Sets scale name
|
||||
|
||||
GetName(me) returns HAsciiString from TCollection;
|
||||
---C++:inline
|
||||
---Purpose: Gets scale name
|
||||
-- Name may be Null handle if not set
|
||||
|
||||
SetMin(me : out; theMin : Real);
|
||||
---C++:inline
|
||||
---Purpose: Sets minimum value of scale
|
||||
|
||||
GetMin(me) returns Real;
|
||||
---C++:inline
|
||||
---Purpose: Gets minimum value of scale
|
||||
|
||||
SetMax(me : out; theMax : Real);
|
||||
---C++:inline
|
||||
---Purpose: Sets minimum value of scale
|
||||
|
||||
GetMax(me) returns Real;
|
||||
---C++:inline
|
||||
---Purpose: Gets minimum value of scale
|
||||
|
||||
SetRange (me: out; min, max: Real);
|
||||
---C++: inline
|
||||
---Purpose: Set both min and max
|
||||
|
||||
SetStep(me : out; theStep : Real);
|
||||
---C++:inline
|
||||
---Purpose: Sets default step
|
||||
|
||||
GetStep(me) returns Real;
|
||||
---C++:inline
|
||||
---Purpose: Gets default step
|
||||
|
||||
SetInfinite(me : out; theInfinite : Boolean = Standard_True);
|
||||
---C++:inline
|
||||
---Purpose: Sets flag for infinite scale
|
||||
|
||||
GetInfinite(me) returns Boolean;
|
||||
---C++:inline
|
||||
---Purpose: Gets flag for infinite scale
|
||||
|
||||
SetScale (me: out; min, max, step: Real; theInfinite : Boolean = Standard_True);
|
||||
---C++: inline
|
||||
---Purpose: Set all scale parameters
|
||||
|
||||
---Scope: Mapping to base scale
|
||||
|
||||
SetSpan (me: out; first, last: Real);
|
||||
---C++: inline
|
||||
---Purpose: Defines span occupied by the scale on the basis scale
|
||||
|
||||
GetFirst (me) returns Real;
|
||||
---C++: inline
|
||||
GetLast (me) returns Real;
|
||||
---C++: inline
|
||||
---Purpose: Return information on span occupied by the scale on the base scale
|
||||
|
||||
LocalToBase (me; val: Real) returns Real;
|
||||
BaseToLocal (me; val: Real) returns Real;
|
||||
---Purpose: Convert value from this scale to base one and back
|
||||
|
||||
fields
|
||||
|
||||
myName: HAsciiString from TCollection; -- name
|
||||
|
||||
myMin, myMax: Real; -- range of a scale
|
||||
myStep : Real; -- default step
|
||||
myInfinite: Boolean; -- flag for infinite scale
|
||||
|
||||
myFirst, myLast : Real; -- span on base scale
|
||||
|
||||
end ProgressScale;
|
50
src/Message/Message_ProgressScale.cxx
Executable file
50
src/Message/Message_ProgressScale.cxx
Executable file
@@ -0,0 +1,50 @@
|
||||
#include <Message_ProgressScale.ixx>
|
||||
|
||||
static const Standard_Real ZERO = 1e-10;
|
||||
static const Standard_Real INFINITE = 1e100;
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_ProgressScale
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Message_ProgressScale::Message_ProgressScale () :
|
||||
myMin(0.), myMax(100.), myStep(1.), myInfinite(Standard_False),
|
||||
myFirst(0.), myLast(1.)
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LocalToBase
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Real Message_ProgressScale::LocalToBase (const Standard_Real val) const
|
||||
{
|
||||
if ( val <= myMin ) return myFirst;
|
||||
if ( myMax - myMin <= ZERO ) return myLast;
|
||||
|
||||
if ( ! myInfinite ) {
|
||||
if ( val >= myMax ) return myLast;
|
||||
return myFirst + ( myLast - myFirst ) * ( val - myMin ) / ( myMax - myMin );
|
||||
}
|
||||
Standard_Real x = ( val - myMin ) / ( myMax - myMin );
|
||||
// return myFirst + ( myLast - myFirst ) * ( 1. - exp ( -x ) ); // exponent
|
||||
return myFirst + ( myLast - myFirst ) * x / ( 1. + x ); // hyperbola
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : BaseToLocal
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Real Message_ProgressScale::BaseToLocal (const Standard_Real val) const
|
||||
{
|
||||
if ( myLast - val <= ZERO )
|
||||
return myInfinite ? INFINITE : myMax;
|
||||
if ( ! myInfinite )
|
||||
return myMin + ( myMax - myMin ) * ( val - myFirst ) / ( myLast - myFirst );
|
||||
// Standard_Real x = log ( ( val - myFirst ) / ( myLast - val ) ); // exponent
|
||||
Standard_Real x = ( val - myFirst ) / ( myLast - val ); // hyperbola
|
||||
return myMin + x * ( myMax - myMin );
|
||||
}
|
172
src/Message/Message_ProgressScale.lxx
Executable file
172
src/Message/Message_ProgressScale.lxx
Executable file
@@ -0,0 +1,172 @@
|
||||
#include <TCollection_HAsciiString.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : SetName
|
||||
//purpose : Sets scale name
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressScale::SetName(const Standard_CString theName)
|
||||
{
|
||||
myName = new TCollection_HAsciiString ( theName );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetName
|
||||
//purpose : Sets scale name
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressScale::SetName(const Handle(TCollection_HAsciiString)& theName)
|
||||
{
|
||||
myName = theName;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetName
|
||||
//purpose : Returns scale name
|
||||
//=======================================================================
|
||||
|
||||
inline Handle(TCollection_HAsciiString) Message_ProgressScale::GetName() const
|
||||
{
|
||||
return myName;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetMin
|
||||
//purpose : Sets minimum value of scale
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressScale::SetMin(const Standard_Real theMin)
|
||||
{
|
||||
myMin = theMin;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetMin
|
||||
//purpose : Returns minimum value of scale
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Real Message_ProgressScale::GetMin() const
|
||||
{
|
||||
return myMin;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetMax
|
||||
//purpose : Sets minimum value of scale
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressScale::SetMax(const Standard_Real theMax)
|
||||
{
|
||||
myMax = theMax;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetMax
|
||||
//purpose : Returns minimum value of scale
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Real Message_ProgressScale::GetMax() const
|
||||
{
|
||||
return myMax;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetRange
|
||||
//purpose : Sets both min and max
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressScale::SetRange(const Standard_Real theMin,
|
||||
const Standard_Real theMax)
|
||||
{
|
||||
myMin = theMin;
|
||||
myMax = theMax;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetStep
|
||||
//purpose : Sets default step
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressScale::SetStep(const Standard_Real theStep)
|
||||
{
|
||||
myStep = theStep;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetStep
|
||||
//purpose : Returns default step
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Real Message_ProgressScale::GetStep() const
|
||||
{
|
||||
return myStep;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetInfinite
|
||||
//purpose : Sets flag for infinite scale
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressScale::SetInfinite(const Standard_Boolean theInfinite)
|
||||
{
|
||||
myInfinite = theInfinite;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetInfinite
|
||||
//purpose : Returns flag for infinite scale
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Boolean Message_ProgressScale::GetInfinite() const
|
||||
{
|
||||
return myInfinite;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetScale
|
||||
//purpose : Set all scale parameters
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressScale::SetScale(const Standard_Real theMin,
|
||||
const Standard_Real theMax,
|
||||
const Standard_Real theStep,
|
||||
const Standard_Boolean theInfinite)
|
||||
{
|
||||
myMin = theMin;
|
||||
myMax = theMax;
|
||||
myStep = theStep;
|
||||
myInfinite = theInfinite;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetSpan
|
||||
//purpose : Sets span on a basis scale
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressScale::SetSpan(const Standard_Real theFirst,
|
||||
const Standard_Real theLast)
|
||||
{
|
||||
myFirst = theFirst;
|
||||
myLast = theLast;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetFirst
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Real Message_ProgressScale::GetFirst () const
|
||||
{
|
||||
return myFirst;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetLast
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Real Message_ProgressScale::GetLast () const
|
||||
{
|
||||
return myLast;
|
||||
}
|
||||
|
68
src/Message/Message_ProgressSentry.cdl
Executable file
68
src/Message/Message_ProgressSentry.cdl
Executable file
@@ -0,0 +1,68 @@
|
||||
-- File: Message_ProgressSentry.cdl
|
||||
-- Created: Fri Feb 22 11:44:07 2002
|
||||
-- Author: Andrey BETENEV
|
||||
-- <abv@doomox>
|
||||
---Copyright: Open CASCADE SA 2002
|
||||
|
||||
|
||||
class ProgressSentry from Message
|
||||
|
||||
---Purpose: This class is a tool allowing to manage opening/closing
|
||||
-- scopes in the ProgressIndicator in convenient and safe way.
|
||||
--
|
||||
-- Its main features are:
|
||||
-- - Set all parameters for the current scale on the given
|
||||
-- ProgressIndicator and open a new scope at one line
|
||||
-- - Iterator-like interface to opening next scopes and
|
||||
-- check for user break
|
||||
-- - Automatic scope closing in destructor
|
||||
-- - Safe for NULL ProgressIndicator (just does nothing)
|
||||
|
||||
uses
|
||||
HAsciiString from TCollection,
|
||||
ProgressIndicator from Message
|
||||
|
||||
is
|
||||
|
||||
Create (PI: ProgressIndicator from Message; name: CString;
|
||||
min, max, step: Real; isInf: Boolean = Standard_False;
|
||||
newScopeSpan: Real = 0.0);
|
||||
Create (PI: ProgressIndicator from Message; name: HAsciiString from TCollection;
|
||||
min, max, step: Real; isInf: Boolean = Standard_False;
|
||||
newScopeSpan: Real = 0.0);
|
||||
---Purpose: Creates an instance of ProgressSentry attaching it to
|
||||
-- the specified ProgressIndicator, selects parameters of
|
||||
-- the current scale, and opens a new scope with specified
|
||||
-- span (equal to step by default)
|
||||
|
||||
Relieve (me: in out);
|
||||
---C++: inline
|
||||
---C++: alias ~
|
||||
---Purpose: Moves progress indicator to the end of the current scale
|
||||
-- and relieves sentry from its duty. Methods other than Show()
|
||||
-- will do nothing after this one is called.
|
||||
|
||||
Next (me; name: CString = 0);
|
||||
---C++: inline
|
||||
Next (me; span: Real; name: CString = 0);
|
||||
---C++: inline
|
||||
Next (me; span: Real; name: HAsciiString from TCollection);
|
||||
---C++: inline
|
||||
---Purpose: Closes current scope and opens next one
|
||||
-- with either specified or default span
|
||||
|
||||
More (me) returns Boolean;
|
||||
---C++: inline
|
||||
---Purpose: Returns False if ProgressIndicator signals UserBreak
|
||||
|
||||
Show (me);
|
||||
---C++: inline
|
||||
---Purpose: Forces update of progress indicator display
|
||||
|
||||
fields
|
||||
|
||||
myProgress: ProgressIndicator from Message;
|
||||
myActive: Boolean; -- True if ProgressIndicator is non-Null and scope is opened
|
||||
|
||||
end ProgressSentry;
|
||||
|
41
src/Message/Message_ProgressSentry.cxx
Executable file
41
src/Message/Message_ProgressSentry.cxx
Executable file
@@ -0,0 +1,41 @@
|
||||
#include <Message_ProgressSentry.ixx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_ProgressSentry
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Message_ProgressSentry::Message_ProgressSentry (const Handle(Message_ProgressIndicator) &progress,
|
||||
const Standard_CString name,
|
||||
const Standard_Real min,
|
||||
const Standard_Real max,
|
||||
const Standard_Real step,
|
||||
const Standard_Boolean isInf,
|
||||
const Standard_Real newScopeSpan) :
|
||||
myProgress(progress), myActive(!progress.IsNull())
|
||||
{
|
||||
if ( ! myActive ) return;
|
||||
progress->SetName ( name );
|
||||
progress->SetScale ( min, max, step, isInf );
|
||||
progress->NewScope ( newScopeSpan >0 ? newScopeSpan : step );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_ProgressSentry
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Message_ProgressSentry::Message_ProgressSentry (const Handle(Message_ProgressIndicator) &progress,
|
||||
const Handle(TCollection_HAsciiString) &name,
|
||||
const Standard_Real min,
|
||||
const Standard_Real max,
|
||||
const Standard_Real step,
|
||||
const Standard_Boolean isInf,
|
||||
const Standard_Real newScopeSpan) :
|
||||
myProgress(progress), myActive(!progress.IsNull())
|
||||
{
|
||||
if ( ! myActive ) return;
|
||||
progress->SetName ( name );
|
||||
progress->SetScale ( min, max, step, isInf );
|
||||
progress->NewScope ( newScopeSpan >0 ? newScopeSpan : step );
|
||||
}
|
68
src/Message/Message_ProgressSentry.lxx
Executable file
68
src/Message/Message_ProgressSentry.lxx
Executable file
@@ -0,0 +1,68 @@
|
||||
#include <Message_ProgressIndicator.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Relieve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressSentry::Relieve ()
|
||||
{
|
||||
if ( ! myActive ) return;
|
||||
myProgress->EndScope();
|
||||
myActive = 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressSentry::Next (const Standard_CString name) const
|
||||
{
|
||||
if ( myActive ) myProgress->NextScope(name);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressSentry::Next (const Standard_Real span,
|
||||
const Standard_CString name) const
|
||||
{
|
||||
if ( myActive ) myProgress->NextScope(span, name);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressSentry::Next (const Standard_Real span,
|
||||
const Handle(TCollection_HAsciiString)& name) const
|
||||
{
|
||||
if ( myActive ) {
|
||||
myProgress->EndScope();
|
||||
myProgress->NewScope(span, name);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Boolean Message_ProgressSentry::More () const
|
||||
{
|
||||
return myActive ? ! myProgress->UserBreak() : Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Show
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressSentry::Show () const
|
||||
{
|
||||
if ( myProgress ) myProgress->Show();
|
||||
}
|
65
src/Message/Message_Status.hxx
Executable file
65
src/Message/Message_Status.hxx
Executable file
@@ -0,0 +1,65 @@
|
||||
// File: Message_Status.hxx
|
||||
// Created: 06.07.07 11:21:37
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE S.A. 2007
|
||||
// Original implementation copyright (c) RINA S.p.A.
|
||||
|
||||
#ifndef Message_Status_HeaderFile
|
||||
#define Message_Status_HeaderFile
|
||||
|
||||
#include <Message_StatusType.hxx>
|
||||
|
||||
//! Enumeration covering all execution statuses supported by the class
|
||||
//! Message_ExecStatus: 32 statuses per each of 4 types (DONE, WARN, ALARM, FAIL)
|
||||
|
||||
enum Message_Status
|
||||
{
|
||||
//! Empty status
|
||||
Message_None = 0,
|
||||
|
||||
//! Something done, 32 variants
|
||||
Message_Done1 = Message_DONE,
|
||||
Message_Done2, Message_Done3, Message_Done4, Message_Done5,
|
||||
Message_Done6, Message_Done7, Message_Done8, Message_Done9,
|
||||
Message_Done10, Message_Done11, Message_Done12, Message_Done13,
|
||||
Message_Done14, Message_Done15, Message_Done16, Message_Done17,
|
||||
Message_Done18, Message_Done19, Message_Done20, Message_Done21,
|
||||
Message_Done22, Message_Done23, Message_Done24, Message_Done25,
|
||||
Message_Done26, Message_Done27, Message_Done28, Message_Done29,
|
||||
Message_Done30, Message_Done31, Message_Done32,
|
||||
|
||||
//! Warning for possible problem encountered, 32 variants
|
||||
Message_Warn1 = Message_WARN,
|
||||
Message_Warn2, Message_Warn3, Message_Warn4, Message_Warn5,
|
||||
Message_Warn6, Message_Warn7, Message_Warn8, Message_Warn9,
|
||||
Message_Warn10, Message_Warn11, Message_Warn12, Message_Warn13,
|
||||
Message_Warn14, Message_Warn15, Message_Warn16, Message_Warn17,
|
||||
Message_Warn18, Message_Warn19, Message_Warn20, Message_Warn21,
|
||||
Message_Warn22, Message_Warn23, Message_Warn24, Message_Warn25,
|
||||
Message_Warn26, Message_Warn27, Message_Warn28, Message_Warn29,
|
||||
Message_Warn30, Message_Warn31, Message_Warn32,
|
||||
|
||||
//! Alarm (severe warning) for problem encountered, 32 variants
|
||||
Message_Alarm1 = Message_ALARM,
|
||||
Message_Alarm2, Message_Alarm3, Message_Alarm4, Message_Alarm5,
|
||||
Message_Alarm6, Message_Alarm7, Message_Alarm8, Message_Alarm9,
|
||||
Message_Alarm10, Message_Alarm11, Message_Alarm12, Message_Alarm13,
|
||||
Message_Alarm14, Message_Alarm15, Message_Alarm16, Message_Alarm17,
|
||||
Message_Alarm18, Message_Alarm19, Message_Alarm20, Message_Alarm21,
|
||||
Message_Alarm22, Message_Alarm23, Message_Alarm24, Message_Alarm25,
|
||||
Message_Alarm26, Message_Alarm27, Message_Alarm28, Message_Alarm29,
|
||||
Message_Alarm30, Message_Alarm31, Message_Alarm32,
|
||||
|
||||
//! Execution failed, 32 variants
|
||||
Message_Fail1 = Message_FAIL,
|
||||
Message_Fail2, Message_Fail3, Message_Fail4, Message_Fail5,
|
||||
Message_Fail6, Message_Fail7, Message_Fail8, Message_Fail9,
|
||||
Message_Fail10, Message_Fail11, Message_Fail12, Message_Fail13,
|
||||
Message_Fail14, Message_Fail15, Message_Fail16, Message_Fail17,
|
||||
Message_Fail18, Message_Fail19, Message_Fail20, Message_Fail21,
|
||||
Message_Fail22, Message_Fail23, Message_Fail24, Message_Fail25,
|
||||
Message_Fail26, Message_Fail27, Message_Fail28, Message_Fail29,
|
||||
Message_Fail30, Message_Fail31, Message_Fail32
|
||||
};
|
||||
|
||||
#endif
|
21
src/Message/Message_StatusType.hxx
Executable file
21
src/Message/Message_StatusType.hxx
Executable file
@@ -0,0 +1,21 @@
|
||||
// File: Message_StatusType.hxx
|
||||
// Created: 06.07.07 11:43:48
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE S.A. 2007
|
||||
// Original implementation copyright (c) RINA S.p.A.
|
||||
|
||||
#ifndef Message_StatusType_HeaderFile
|
||||
#define Message_StatusType_HeaderFile
|
||||
|
||||
//! Definition of types of execution status supported by
|
||||
//! the class Message_ExecStatus
|
||||
|
||||
enum Message_StatusType
|
||||
{
|
||||
Message_DONE = 0x00000100,
|
||||
Message_WARN = 0x00000200,
|
||||
Message_ALARM = 0x00000400,
|
||||
Message_FAIL = 0x00000800
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user