mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0025748: Parallel version of progress indicator
Progress indication mechanism is refactored to support incrementing progress within multithreaded algorithms. The class Message_ProgressIndicator is only an interface to the user application. It accumulates the progress provided by progress scopes. The counter is protected by mutex for thread-safety. The new class Message_ProgressScope replacing Message_ProgressSentry should be used to advance the progress. The scopes are nested to each other to reflect the nested nature of operations. The new class Message_ProgressRange should be used to pass the progress to sub-scopes. All OCCT algorithms involving progress indication have been updated to new API. Improvements in Draw_ProgressIndicator: - Separate console mode has been added in order to make possible to put the progress into std::cout instead or in addition to the draw interpreter, instead of trigger option "-tclOutput". - Treatment of Ctrl-Break signal has been added. Now any operation can be aborted by Ctrl-C or Ctrl-Break keystroke. Added new test case 'perf fclasses progr_par' for testing of parallel work of the progress.
This commit is contained in:
@@ -24,15 +24,10 @@ Message_PrinterSystemLog.cxx
|
||||
Message_PrinterSystemLog.hxx
|
||||
Message_ProgressIndicator.cxx
|
||||
Message_ProgressIndicator.hxx
|
||||
Message_ProgressIndicator.lxx
|
||||
Message_ProgressScale.cxx
|
||||
Message_ProgressScale.hxx
|
||||
Message_ProgressScale.lxx
|
||||
Message_ProgressSentry.cxx
|
||||
Message_ProgressRange.hxx
|
||||
Message_ProgressScope.hxx
|
||||
Message_ProgressSentry.hxx
|
||||
Message_ProgressSentry.lxx
|
||||
Message_SequenceOfPrinters.hxx
|
||||
Message_SequenceOfProgressScale.hxx
|
||||
Message_Status.hxx
|
||||
Message_StatusType.hxx
|
||||
Message_Alert.cxx
|
||||
|
@@ -11,164 +11,52 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
|
||||
#include <Message_ProgressIndicator.hxx>
|
||||
#include <Message_ProgressScale.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <TCollection_HAsciiString.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Message_ProgressIndicator,Standard_Transient)
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_ProgressIndicator
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Message_ProgressIndicator::Message_ProgressIndicator ()
|
||||
Message_ProgressIndicator::Message_ProgressIndicator()
|
||||
: myPosition(0.),
|
||||
myRootScope (NULL)
|
||||
{
|
||||
Reset();
|
||||
myRootScope = new Message_ProgressScope (this);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Reset
|
||||
//purpose :
|
||||
//function : ~Message_ProgressIndicator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Message_ProgressIndicator::~Message_ProgressIndicator()
|
||||
{
|
||||
// Avoid calling Increment() from myRootScope.Close()
|
||||
myRootScope->myProgress = 0;
|
||||
myRootScope->myIsActive = false;
|
||||
delete myRootScope;
|
||||
}
|
||||
|
||||
void Message_ProgressIndicator::Reset ()
|
||||
//=======================================================================
|
||||
//function : Start()
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Message_ProgressRange Message_ProgressIndicator::Start()
|
||||
{
|
||||
myPosition = 0.;
|
||||
|
||||
Message_ProgressScale scale;
|
||||
scale.SetName ( "Step" );
|
||||
scale.SetSpan ( 0., 1. );
|
||||
|
||||
myScopes.Clear();
|
||||
myScopes.Append ( scale );
|
||||
myRootScope->myValue = 0.;
|
||||
Reset();
|
||||
Show (*myRootScope, Standard_False);
|
||||
return myRootScope->Next();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetScale
|
||||
//purpose :
|
||||
//function : Start()
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Message_ProgressIndicator::SetScale (const Standard_Real min,
|
||||
const Standard_Real max,
|
||||
const Standard_Real step,
|
||||
const Standard_Boolean isInf)
|
||||
Message_ProgressRange Message_ProgressIndicator::Start
|
||||
(const Handle(Message_ProgressIndicator)& theProgress)
|
||||
{
|
||||
Message_ProgressScale &scale = myScopes.ChangeValue(1);
|
||||
scale.SetRange ( min, max );
|
||||
scale.SetStep ( step );
|
||||
scale.SetInfinite ( isInf );
|
||||
return theProgress.IsNull() ? Message_ProgressRange() : theProgress->Start();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//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;
|
||||
}
|
||||
|
||||
|
@@ -16,180 +16,162 @@
|
||||
#ifndef _Message_ProgressIndicator_HeaderFile
|
||||
#define _Message_ProgressIndicator_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <Standard_TypeDef.hxx>
|
||||
#include <Standard_Mutex.hxx>
|
||||
#include <Standard_Handle.hxx>
|
||||
|
||||
#include <Standard_Real.hxx>
|
||||
#include <Message_SequenceOfProgressScale.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <Standard_CString.hxx>
|
||||
#include <Standard_Boolean.hxx>
|
||||
#include <Standard_Integer.hxx>
|
||||
class TCollection_HAsciiString;
|
||||
class Message_ProgressScale;
|
||||
|
||||
|
||||
class Message_ProgressIndicator;
|
||||
DEFINE_STANDARD_HANDLE(Message_ProgressIndicator, Standard_Transient)
|
||||
|
||||
//! Defines abstract interface from program to the "user".
|
||||
class Message_ProgressRange;
|
||||
class Message_ProgressScope;
|
||||
|
||||
//! Defines abstract interface from program to the user.
|
||||
//! This includes progress indication and user break mechanisms.
|
||||
//!
|
||||
//! The process that uses the progress indicator interacts with it as
|
||||
//! with a scale whose range and step can be configured according to
|
||||
//! the nature of the process.
|
||||
//! The scale can be made "infinite", which means it will grow
|
||||
//! non-linearly, and end of scale will be approached asymptotically at
|
||||
//! infinite number of steps. In that case the range defines
|
||||
//! 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 levels of the process nesting.
|
||||
//! For that purpose, it is possible to create restricted sub-scope of
|
||||
//! indication by specifying part of a current scale 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.
|
||||
//! The progress indicator controls the progress scale with range from 0 to 1.
|
||||
//!
|
||||
//! The recommended way to implement progress indication in the algorithm
|
||||
//! is to use class Message_ProgressSentry that provides iterator-like
|
||||
//! interface for incrementing progress and opening nested scopes.
|
||||
//! Method Start() should be called once, at the top level of the call stack,
|
||||
//! to reset progress indicator and get access to the root range:
|
||||
//!
|
||||
//! NOTE:
|
||||
//! Currently there is no support for concurrent progress
|
||||
//! indicator that could be useful in multithreaded applications.
|
||||
//! @code{.cpp}
|
||||
//! Handle(Message_ProgressIndicator) aProgress = ...;
|
||||
//! anAlgorithm.Perform (aProgress->Start());
|
||||
//! @endcode
|
||||
//!
|
||||
//! The user break is implemented as virtual function that should
|
||||
//! return True in case if break signal from the user is received.
|
||||
//! To advance the progress indicator in the algorithm,
|
||||
//! use the class Message_ProgressScope that provides iterator-like
|
||||
//! interface for incrementing progress; see documentation of that
|
||||
//! class for details.
|
||||
//! The object of class Message_ProgressRange will automatically advance
|
||||
//! the indicator if it is not passed to any Message_ProgressScope.
|
||||
//!
|
||||
//! The derived class should take care of visualisation of the
|
||||
//! progress indicator (e.g. show total position at the graphical bar,
|
||||
//! The progress indicator supports concurrent processing and
|
||||
//! can be used in multithreaded applications.
|
||||
//!
|
||||
//! The derived class should be created to connect this interface to
|
||||
//! actual implementation of progress indicator, to take care of visualization
|
||||
//! of the progress (e.g. show total position at the graphical bar,
|
||||
//! print scopes in text mode, or else), and for implementation
|
||||
//! of user break mechanism (if necessary).
|
||||
//!
|
||||
//! See details in documentation of methods Show() and UserBreak().
|
||||
|
||||
class Message_ProgressIndicator : public Standard_Transient
|
||||
{
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Message_ProgressIndicator, Standard_Transient)
|
||||
public:
|
||||
//!@name Initialization of progress indication
|
||||
|
||||
|
||||
//! Drops all scopes and sets scale from 0 to 100, step 1
|
||||
//! This scale has name "Step"
|
||||
Standard_EXPORT virtual void Reset();
|
||||
|
||||
void SetName (const Standard_CString name);
|
||||
|
||||
//! Set (optional) name for scale
|
||||
void SetName (const Handle(TCollection_HAsciiString)& name);
|
||||
|
||||
//! Set range for current scale
|
||||
void SetRange (const Standard_Real min, const Standard_Real max);
|
||||
|
||||
//! Set step for current scale
|
||||
void SetStep (const Standard_Real step);
|
||||
|
||||
//! Set or drop infinite mode for the current scale
|
||||
void SetInfinite (const Standard_Boolean isInf = Standard_True);
|
||||
|
||||
void SetScale (const Standard_CString name, const Standard_Real min, const Standard_Real max, const Standard_Real step, const Standard_Boolean isInf = Standard_False);
|
||||
|
||||
//! Set all parameters for current scale
|
||||
Standard_EXPORT void SetScale (const Standard_Real min, const Standard_Real max, const Standard_Real step, const Standard_Boolean isInf = Standard_False);
|
||||
|
||||
//! Returns all parameters for current scale
|
||||
Standard_EXPORT void GetScale (Standard_Real& min, Standard_Real& max, Standard_Real& step, Standard_Boolean& isInf) const;
|
||||
|
||||
Standard_EXPORT void SetValue (const Standard_Real val);
|
||||
|
||||
//! 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
|
||||
Standard_EXPORT Standard_Real GetValue() const;
|
||||
|
||||
void Increment();
|
||||
|
||||
//! Increment the progress value by the default of specified step
|
||||
void Increment (const Standard_Real step);
|
||||
|
||||
Standard_Boolean NewScope (const Standard_CString name = 0);
|
||||
|
||||
Standard_Boolean NewScope (const Handle(TCollection_HAsciiString)& name);
|
||||
|
||||
Standard_Boolean NewScope (const Standard_Real span, const Standard_CString name = 0);
|
||||
|
||||
//! 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
|
||||
Standard_EXPORT Standard_Boolean NewScope (const Standard_Real span, const Handle(TCollection_HAsciiString)& name);
|
||||
|
||||
//! 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
|
||||
Standard_EXPORT Standard_Boolean EndScope();
|
||||
|
||||
Standard_Boolean NextScope (const Standard_CString name = 0);
|
||||
|
||||
//! Optimized version of { return EndScope() && NewScope(); }
|
||||
Standard_EXPORT Standard_Boolean NextScope (const Standard_Real span, const Standard_CString name = 0);
|
||||
|
||||
//! Should return True if user has send a break signal.
|
||||
//! Default implementation returns False.
|
||||
Standard_EXPORT virtual Standard_Boolean UserBreak();
|
||||
|
||||
//! 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
|
||||
Standard_EXPORT virtual Standard_Boolean Show (const Standard_Boolean force = Standard_True) = 0;
|
||||
|
||||
//! Returns total progress position on the basic scale
|
||||
//! ranged from 0. to 1.
|
||||
Standard_Real GetPosition() const;
|
||||
|
||||
//! Returns current number of opened scopes
|
||||
//! This number is always >=1 as top-level scale is always present
|
||||
Standard_Integer GetNbScopes() const;
|
||||
|
||||
//! Returns data for scale of index-th scope
|
||||
//! The first scope is current one, the last is the top-level one
|
||||
const Message_ProgressScale& GetScope (const Standard_Integer index) const;
|
||||
//! Resets the indicator to zero, calls Reset(), and returns the range.
|
||||
//! This range refers to the scope that has no name and is initialized
|
||||
//! with max value 1 and step 1.
|
||||
//! Use this method to get the top level range for progress indication.
|
||||
Standard_EXPORT Message_ProgressRange Start();
|
||||
|
||||
|
||||
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Message_ProgressIndicator,Standard_Transient)
|
||||
//! If argument is non-null handle, returns theProgress->Start().
|
||||
//! Otherwise, returns dummy range that can be safely used in the algorithms
|
||||
//! but not bound to progress indicator.
|
||||
Standard_EXPORT static Message_ProgressRange Start
|
||||
(const Handle(Message_ProgressIndicator)& theProgress);
|
||||
|
||||
protected:
|
||||
//!@name Virtual methods to be defined by descendant.
|
||||
|
||||
//! Should return True if user has sent a break signal.
|
||||
//!
|
||||
//! This method can be called concurrently, thus implementation should
|
||||
//! be thread-safe. It should not call Show() or Position() to
|
||||
//! avoid possible data races. The method should return as soon
|
||||
//! as possible to avoid delaying the calling algorithm.
|
||||
//!
|
||||
//! Default implementation returns False.
|
||||
virtual Standard_Boolean UserBreak()
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
//! Virtual method to be defined by descendant.
|
||||
//! Should update presentation of the progress indicator.
|
||||
//!
|
||||
//! It is called whenever progress position is changed.
|
||||
//! Calls to this method from progress indicator are protected by mutex so that
|
||||
//! it is never called concurrently for the same progress indicator instance.
|
||||
//! Show() should return as soon as possible to reduce thread contention
|
||||
//! in multithreaded algorithms.
|
||||
//!
|
||||
//! It is recommended to update (redraw, output etc.) only if progress advanced
|
||||
//! by at least 1% from previous update.
|
||||
//!
|
||||
//! Flag isForce is intended for forcing update in case if it is
|
||||
//! optimized; all calls to it from inside the core mechanism are
|
||||
//! done with this flag equal to False.
|
||||
//!
|
||||
//! The parameter theScope is the current scope being advanced;
|
||||
//! it can be used to show the names and ranges of the on-going scope and
|
||||
//! its parents, providing more visibility of the current stage of the process.
|
||||
virtual void Show (const Message_ProgressScope& theScope,
|
||||
const Standard_Boolean isForce) = 0;
|
||||
|
||||
//! Call-back method called by Start(), can be redefined by descendants
|
||||
//! if some actions are needed when the indicator is restarted.
|
||||
virtual void Reset() {}
|
||||
|
||||
//! Constructor, just calls own Reset() (not yet redefined)
|
||||
public:
|
||||
//!@name Auxiliary methods
|
||||
|
||||
//! Returns total progress position ranged from 0 to 1.
|
||||
//! Should not be called concurrently while the progress is advancing
|
||||
//! except from implementation of method Show().
|
||||
Standard_Real GetPosition() const
|
||||
{
|
||||
return myPosition;
|
||||
}
|
||||
|
||||
//! Destructor
|
||||
Standard_EXPORT ~Message_ProgressIndicator();
|
||||
|
||||
protected:
|
||||
|
||||
//! Constructor
|
||||
Standard_EXPORT Message_ProgressIndicator();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
//! Increment the progress value by the specified step,
|
||||
//! then calls Show() to update presentation.
|
||||
//! The parameter theScope is reference to the caller object;
|
||||
//! it is passed to Show() where can be used to track context of the process.
|
||||
void Increment (const Standard_Real theStep, const Message_ProgressScope& theScope);
|
||||
|
||||
Standard_Real myPosition;
|
||||
Message_SequenceOfProgressScale myScopes;
|
||||
private:
|
||||
|
||||
Standard_Real myPosition; //!< Total progress position ranged from 0 to 1
|
||||
Standard_Mutex myMutex; //!< Protection of myPosition from concurrent increment
|
||||
Message_ProgressScope* myRootScope; //!< The root progress scope
|
||||
|
||||
private:
|
||||
friend class Message_ProgressScope; //!< Friend: can call Increment()
|
||||
friend class Message_ProgressRange; //!< Friend: can call Increment()
|
||||
};
|
||||
|
||||
#include <Message_ProgressScope.hxx>
|
||||
|
||||
#include <Message_ProgressIndicator.lxx>
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Increment
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
inline void Message_ProgressIndicator::Increment(const Standard_Real theStep,
|
||||
const Message_ProgressScope& theScope)
|
||||
{
|
||||
// protect incrementation by mutex to avoid problems in multithreaded scenarios
|
||||
Standard_Mutex::Sentry aSentry(myMutex);
|
||||
|
||||
myPosition = Min(myPosition + theStep, 1.);
|
||||
|
||||
// show progress indicator; note that this call is protected by
|
||||
// the same mutex to avoid concurrency and ensure that this call
|
||||
// to Show() will see the position exactly as it was just set above
|
||||
Show(theScope, Standard_False);
|
||||
}
|
||||
|
||||
#endif // _Message_ProgressIndicator_HeaderFile
|
||||
|
@@ -1,174 +0,0 @@
|
||||
// Copyright (c) 1999-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#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);
|
||||
}
|
139
src/Message/Message_ProgressRange.hxx
Normal file
139
src/Message/Message_ProgressRange.hxx
Normal file
@@ -0,0 +1,139 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Message_ProgressRange_HeaderFile
|
||||
#define _Message_ProgressRange_HeaderFile
|
||||
|
||||
#include <Standard_TypeDef.hxx>
|
||||
|
||||
class Message_ProgressScope;
|
||||
|
||||
//! Auxiliary class representing a part of the global progress scale allocated by
|
||||
//! a step of the progress scope, see Message_ProgressScope::Next().
|
||||
//!
|
||||
//! A range object takes responsibility of advancing the progress by the size of
|
||||
//! allocated step, which is then performed depending on how it is used:
|
||||
//!
|
||||
//! - If Message_ProgressScope object is created using this range as argument, then
|
||||
//! this respondibility is taken over by that scope.
|
||||
//!
|
||||
//! - Otherwise, a range advances progress directly upon destruction.
|
||||
//!
|
||||
//! A range object can be copied, the responsibility for progress advancement is
|
||||
//! then taken by the copy.
|
||||
//! The same range object may be used (either copied or used to create scope) only once.
|
||||
//! Any consequenct attempts to use range will give no result on the progress;
|
||||
//! in debug mode, an assert message will be generated.
|
||||
//!
|
||||
//! @sa Message_ProgressScope for more details
|
||||
class Message_ProgressRange
|
||||
{
|
||||
public:
|
||||
//! Constructor of the range
|
||||
Message_ProgressRange()
|
||||
: myParentScope (0), myDelta (0), myWasUsed (false)
|
||||
{}
|
||||
|
||||
//! Copy constructor disarms the source.
|
||||
Message_ProgressRange (const Message_ProgressRange& theOther)
|
||||
: myParentScope (theOther.myParentScope),
|
||||
myDelta (theOther.myDelta),
|
||||
myWasUsed (theOther.myWasUsed)
|
||||
{
|
||||
// discharge theOther
|
||||
theOther.myWasUsed = true;
|
||||
}
|
||||
|
||||
//! Copy assignment disarms the source.
|
||||
Message_ProgressRange& operator=(const Message_ProgressRange& theOther)
|
||||
{
|
||||
myParentScope = theOther.myParentScope;
|
||||
myDelta = theOther.myDelta;
|
||||
myWasUsed = theOther.myWasUsed;
|
||||
theOther.myWasUsed = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Returns true if ProgressIndicator signals UserBreak
|
||||
Standard_Boolean UserBreak() const;
|
||||
|
||||
//! Returns false if ProgressIndicator signals UserBreak
|
||||
Standard_Boolean More() const
|
||||
{
|
||||
return !UserBreak();
|
||||
}
|
||||
|
||||
//! Returns true if this progress range is attached to some indicator.
|
||||
Standard_Boolean IsActive() const;
|
||||
|
||||
//! Closes the current range and advances indicator
|
||||
void Close();
|
||||
|
||||
//! Destructor
|
||||
~Message_ProgressRange()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private:
|
||||
//! Constructor is private
|
||||
Message_ProgressRange (const Message_ProgressScope& theParent, Standard_Real theDelta)
|
||||
: myParentScope (&theParent),
|
||||
myDelta (theDelta),
|
||||
myWasUsed (false)
|
||||
{}
|
||||
|
||||
private:
|
||||
const Message_ProgressScope* myParentScope; //!< Pointer to parent scope
|
||||
Standard_Real myDelta; //!< Step of incrementation
|
||||
mutable Standard_Boolean myWasUsed; //!< Flag indicating that this range
|
||||
//! was used to create a new scope
|
||||
|
||||
friend class Message_ProgressScope;
|
||||
};
|
||||
|
||||
#include <Message_ProgressIndicator.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : IsActive
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
inline Standard_Boolean Message_ProgressRange::IsActive() const
|
||||
{
|
||||
return !myWasUsed && myParentScope && myParentScope->myProgress;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : UserBreak
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
inline Standard_Boolean Message_ProgressRange::UserBreak() const
|
||||
{
|
||||
return myParentScope && myParentScope->myProgress && myParentScope->myProgress->UserBreak();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Close
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
inline void Message_ProgressRange::Close()
|
||||
{
|
||||
if (!IsActive())
|
||||
return;
|
||||
|
||||
myParentScope->myProgress->Increment(myDelta, *myParentScope);
|
||||
myParentScope = 0;
|
||||
myWasUsed = true;
|
||||
}
|
||||
|
||||
#endif // _Message_ProgressRange_HeaderFile
|
@@ -1,65 +0,0 @@
|
||||
// Copyright (c) 1999-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
|
||||
#include <Message_ProgressScale.hxx>
|
||||
#include <TCollection_HAsciiString.hxx>
|
||||
|
||||
static const Standard_Real Message_ProgressScale_ZERO = 1e-10;
|
||||
static const Standard_Real Message_ProgressScale_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 <= Message_ProgressScale_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 <= Message_ProgressScale_ZERO )
|
||||
return myInfinite ? Message_ProgressScale_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 );
|
||||
}
|
@@ -1,133 +0,0 @@
|
||||
// Created on: 2002-02-20
|
||||
// Created by: Andrey BETENEV
|
||||
// Copyright (c) 2002-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Message_ProgressScale_HeaderFile
|
||||
#define _Message_ProgressScale_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_DefineAlloc.hxx>
|
||||
#include <Standard_Handle.hxx>
|
||||
|
||||
#include <Standard_Real.hxx>
|
||||
#include <Standard_Boolean.hxx>
|
||||
#include <Standard_CString.hxx>
|
||||
class TCollection_HAsciiString;
|
||||
|
||||
|
||||
//! 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
|
||||
class Message_ProgressScale
|
||||
{
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_ALLOC
|
||||
|
||||
|
||||
//! Creates scale ranged from 0 to 100 with step 1
|
||||
Standard_EXPORT Message_ProgressScale();
|
||||
|
||||
void SetName (const Standard_CString theName);
|
||||
|
||||
//! Sets scale name
|
||||
void SetName (const Handle(TCollection_HAsciiString)& theName);
|
||||
|
||||
//! Gets scale name
|
||||
//! Name may be Null handle if not set
|
||||
Handle(TCollection_HAsciiString) GetName() const;
|
||||
|
||||
//! Sets minimum value of scale
|
||||
void SetMin (const Standard_Real theMin);
|
||||
|
||||
//! Gets minimum value of scale
|
||||
Standard_Real GetMin() const;
|
||||
|
||||
//! Sets minimum value of scale
|
||||
void SetMax (const Standard_Real theMax);
|
||||
|
||||
//! Gets minimum value of scale
|
||||
Standard_Real GetMax() const;
|
||||
|
||||
//! Set both min and max
|
||||
void SetRange (const Standard_Real min, const Standard_Real max);
|
||||
|
||||
//! Sets default step
|
||||
void SetStep (const Standard_Real theStep);
|
||||
|
||||
//! Gets default step
|
||||
Standard_Real GetStep() const;
|
||||
|
||||
//! Sets flag for infinite scale
|
||||
void SetInfinite (const Standard_Boolean theInfinite = Standard_True);
|
||||
|
||||
//! Gets flag for infinite scale
|
||||
Standard_Boolean GetInfinite() const;
|
||||
|
||||
//! Set all scale parameters
|
||||
void SetScale (const Standard_Real min, const Standard_Real max, const Standard_Real step, const Standard_Boolean theInfinite = Standard_True);
|
||||
|
||||
//! Defines span occupied by the scale on the basis scale
|
||||
void SetSpan (const Standard_Real first, const Standard_Real last);
|
||||
|
||||
Standard_Real GetFirst() const;
|
||||
|
||||
//! Return information on span occupied by the scale on the base scale
|
||||
Standard_Real GetLast() const;
|
||||
|
||||
Standard_EXPORT Standard_Real LocalToBase (const Standard_Real val) const;
|
||||
|
||||
//! Convert value from this scale to base one and back
|
||||
Standard_EXPORT Standard_Real BaseToLocal (const Standard_Real val) const;
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
Handle(TCollection_HAsciiString) myName;
|
||||
Standard_Real myMin;
|
||||
Standard_Real myMax;
|
||||
Standard_Real myStep;
|
||||
Standard_Boolean myInfinite;
|
||||
Standard_Real myFirst;
|
||||
Standard_Real myLast;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#include <Message_ProgressScale.lxx>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // _Message_ProgressScale_HeaderFile
|
@@ -1,185 +0,0 @@
|
||||
// Copyright (c) 1999-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#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;
|
||||
}
|
||||
|
579
src/Message/Message_ProgressScope.hxx
Normal file
579
src/Message/Message_ProgressScope.hxx
Normal file
@@ -0,0 +1,579 @@
|
||||
// Created on: 2002-02-22
|
||||
// Created by: Andrey BETENEV
|
||||
// Copyright (c) 2002-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Message_ProgressScope_HeaderFile
|
||||
#define _Message_ProgressScope_HeaderFile
|
||||
|
||||
#include <Standard_Assert.hxx>
|
||||
#include <Standard_TypeDef.hxx>
|
||||
#include <Standard_DefineAlloc.hxx>
|
||||
#include <Standard_Handle.hxx>
|
||||
#include <Precision.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
class Message_ProgressRange;
|
||||
class Message_ProgressIndicator;
|
||||
|
||||
//! Message_ProgressScope class provides convenient way to advance progress
|
||||
//! indicator in context of complex program organized in hierarchical way,
|
||||
//! where usually it is difficult (or even not possible) to consider process
|
||||
//! as linear with fixed step.
|
||||
//!
|
||||
//! On every level (sub-operation) in hierarchy of operations
|
||||
//! the local instance of the Message_ProgressScope class is created.
|
||||
//! It takes a part of the upper-level scope (via Message_ProgressRange) and provides
|
||||
//! a way to consider this part as independent scale with locally defined range.
|
||||
//!
|
||||
//! The position on the local scale may be advanced using the method Next(),
|
||||
//! which allows iteration-like advancement. This method can take argument to
|
||||
//! advance on the needed value. And, this method returns ProgressRange object
|
||||
//! that takes responsibility of making the specified step at its destruction.
|
||||
//! The ProgressRange can be used to create a new progress sub-scope.
|
||||
//!
|
||||
//! It is important that sub-scope must have life time less than
|
||||
//! the life time of its parent scope that provided the range.
|
||||
//!
|
||||
//! The scope has a name that can be used in visualization of the progress.
|
||||
//! It can be null. Note that the string is not copied, just pointer is stored.
|
||||
//! So, the pointer must point to the string with life time
|
||||
//! greater than that of the scope object.
|
||||
//!
|
||||
//! In multithreaded programs, for each task running concurrently it is recommended
|
||||
//! to create a separate progress scope. The same instance of the progress scope
|
||||
//! must not be used concurrently from different threads.
|
||||
//!
|
||||
//! A progress scope created with empty constructor is not connected to any
|
||||
//! progress indicator, and passing the range created on it to any algorithm
|
||||
//! allows it executing safely without progress indication.
|
||||
//!
|
||||
//! Example of preparation of progress indicator:
|
||||
//!
|
||||
//! @code{.cpp}
|
||||
//! Handle(Message_ProgressIndicator) aProgress = ...; // assume it can be null
|
||||
//! func (Message_ProgressIndicator::Start (aProgress));
|
||||
//! @endcode
|
||||
//!
|
||||
//! Example of usage in sequential process:
|
||||
//!
|
||||
//! @code{.cpp}
|
||||
//! Message_ProgressScope aWholePS(aRange, "Whole process", 100);
|
||||
//!
|
||||
//! // do one step taking 20%
|
||||
//! func1 (aWholePS.Next (20)); // func1 will take 20% of the whole scope
|
||||
//! if (aWholePS.UserBreak()) // exit prematurely if the user requested break
|
||||
//! return;
|
||||
//!
|
||||
//! // ... do next step taking 50%
|
||||
//! func2 (aWholePS.Next (50));
|
||||
//! if (aWholePS.UserBreak())
|
||||
//! return;
|
||||
//! @endcode
|
||||
//!
|
||||
//! Example of usage in nested cycle:
|
||||
//!
|
||||
//! @code{.cpp}
|
||||
//! // Outer cycle
|
||||
//! Message_ProgressScope anOuter (theProgress, "Outer", nbOuter);
|
||||
//! for (Standard_Integer i = 0; i < nbOuter && anOuter.More(); i++)
|
||||
//! {
|
||||
//! // Inner cycle
|
||||
//! Message_ProgressScope anInner (anOuter.Next(), "Inner", nbInner);
|
||||
//! for (Standard_Integer j = 0; j < nbInner && anInner.More(); j++)
|
||||
//! {
|
||||
//! // Cycle body
|
||||
//! func (anInner.Next());
|
||||
//! }
|
||||
//! }
|
||||
//! @endcode
|
||||
//!
|
||||
//! Example of use in function:
|
||||
//!
|
||||
//! @code{.cpp}
|
||||
//! //! Implementation of iterative algorithm showing its progress
|
||||
//! func (const Message_ProgressRange& theProgress)
|
||||
//! {
|
||||
//! // Create local scope covering the given progress range.
|
||||
//! // Set this scope to count aNbSteps steps.
|
||||
//! Message_ProgressScope aScope (theProgress, "", aNbSteps);
|
||||
//! for (Standard_Integer i = 0; i < aNbSteps && aScope.More(); i++)
|
||||
//! {
|
||||
//! // Optional: pass range returned by method Next() to the nested algorithm
|
||||
//! // to allow it to show its progress too (by creating its own scope object).
|
||||
//! // In any case the progress will advance to the next step by the end of the func2 call.
|
||||
//! func2 (aScope.Next());
|
||||
//! }
|
||||
//! }
|
||||
//! @endcode
|
||||
//!
|
||||
//! Example of usage in parallel process:
|
||||
//!
|
||||
//! @code{.cpp}
|
||||
//! struct Task
|
||||
//! {
|
||||
//! Data& Data;
|
||||
//! Message_ProgressRange Range;
|
||||
//!
|
||||
//! Task (const Data& theData, const Message_ProgressRange& theRange)
|
||||
//! : Data (theData), Range (theRange) {}
|
||||
//! };
|
||||
//! struct Functor
|
||||
//! {
|
||||
//! void operator() (Task& theTask) const
|
||||
//! {
|
||||
//! // Note: it is essential that this method is executed only once
|
||||
//! // for the same Task object
|
||||
//! Message_ProgressScope aPS (theTask.Range, "Processing task", 1);
|
||||
//! if (aPS.More())
|
||||
//! {
|
||||
//! // ... process data
|
||||
//! }
|
||||
//! }
|
||||
//! };
|
||||
//! ...
|
||||
//! {
|
||||
//! std::vector<Data> aData = ...;
|
||||
//! std::vector<Task> aTasks;
|
||||
//!
|
||||
//! Message_ProgressScope aPS (aRootRange, "Data processing", aData.size());
|
||||
//! for (Standard_Integer i = 0; i < aData.size(); ++i)
|
||||
//! aTasks.push_back (Task (aData[i], aPS.Next()));
|
||||
//!
|
||||
//! OSD_Parallel::ForEach (aTasks.begin(), aTasks.end(), Functor());
|
||||
//! }
|
||||
//! @endcode
|
||||
class Message_ProgressScope
|
||||
{
|
||||
public:
|
||||
class NullString; //!< auxiliary type for passing NULL name to Message_ProgressScope constructor
|
||||
public: //! @name Preparation methods
|
||||
|
||||
//! Creates dummy scope.
|
||||
//! It can be safely passed to algorithms; no progress indication will be done.
|
||||
Message_ProgressScope()
|
||||
: myProgress (0),
|
||||
myParent (0),
|
||||
myName (0),
|
||||
myPortion (1.), myMax (1.), myValue (0.),
|
||||
myIsActive (false),
|
||||
myIsOwnName (false),
|
||||
myIsInfinite (false)
|
||||
{}
|
||||
|
||||
//! Creates a new scope taking responsibility of the part of the progress
|
||||
//! scale described by theRange. The new scope has own range from 0 to
|
||||
//! theMax, which is mapped to the given range.
|
||||
//!
|
||||
//! The topmost scope is created and owned by Message_ProgressIndicator
|
||||
//! and its pointer is contained in the Message_ProgressRange returned by the Start() method of progress indicator.
|
||||
//!
|
||||
//! @param theRange [in][out] range to fill (will be disarmed)
|
||||
//! @param theName [in] new scope name
|
||||
//! @param theMax [in] number of steps in scope
|
||||
//! @param isInfinite [in] infinite flag
|
||||
Message_ProgressScope (const Message_ProgressRange& theRange,
|
||||
const TCollection_AsciiString& theName,
|
||||
Standard_Real theMax,
|
||||
Standard_Boolean isInfinite = false);
|
||||
|
||||
//! Creates a new scope taking responsibility of the part of the progress
|
||||
//! scale described by theRange. The new scope has own range from 0 to
|
||||
//! theMax, which is mapped to the given range.
|
||||
//!
|
||||
//! The topmost scope is created and owned by Message_ProgressIndicator
|
||||
//! and its pointer is contained in the Message_ProgressRange returned by the Start() method of progress indicator.
|
||||
//!
|
||||
//! @param theRange [in][out] range to fill (will be disarmed)
|
||||
//! @param theName [in] new scope name constant (will be stored by pointer with no deep copy)
|
||||
//! @param theMax [in] number of steps in scope
|
||||
//! @param isInfinite [in] infinite flag
|
||||
template<size_t N>
|
||||
Message_ProgressScope (const Message_ProgressRange& theRange,
|
||||
const char (&theName)[N],
|
||||
Standard_Real theMax,
|
||||
Standard_Boolean isInfinite = false);
|
||||
|
||||
//! Creates a new scope taking responsibility of the part of the progress
|
||||
//! scale described by theRange. The new scope has own range from 0 to
|
||||
//! theMax, which is mapped to the given range.
|
||||
//!
|
||||
//! The topmost scope is created and owned by Message_ProgressIndicator
|
||||
//! and its pointer is contained in the Message_ProgressRange returned by the Start() method of progress indicator.
|
||||
//!
|
||||
//! @param theRange [in][out] range to fill (will be disarmed)
|
||||
//! @param theName [in] empty scope name (only NULL is accepted as argument)
|
||||
//! @param theMax [in] number of steps in scope
|
||||
//! @param isInfinite [in] infinite flag
|
||||
Message_ProgressScope (const Message_ProgressRange& theRange,
|
||||
const NullString* theName,
|
||||
Standard_Real theMax,
|
||||
Standard_Boolean isInfinite = false);
|
||||
|
||||
//! Sets the name of the scope.
|
||||
void SetName (const TCollection_AsciiString& theName)
|
||||
{
|
||||
if (myIsOwnName)
|
||||
{
|
||||
Standard::Free (myName);
|
||||
myIsOwnName = false;
|
||||
}
|
||||
myName = NULL;
|
||||
if (!theName.IsEmpty())
|
||||
{
|
||||
myIsOwnName = true;
|
||||
myName = (char* )Standard::Allocate (theName.Length() + 1);
|
||||
char* aName = (char* )myName;
|
||||
memcpy (aName, theName.ToCString(), theName.Length());
|
||||
aName[theName.Length()] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
//! Sets the name of the scope; can be null.
|
||||
//! Note! Just pointer to the given string is copied,
|
||||
//! so do not pass string from a temporary variable whose
|
||||
//! lifetime is less than that of this object.
|
||||
template<size_t N>
|
||||
void SetName (const char (&theName)[N])
|
||||
{
|
||||
if (myIsOwnName)
|
||||
{
|
||||
Standard::Free (myName);
|
||||
myIsOwnName = false;
|
||||
}
|
||||
myName = theName;
|
||||
}
|
||||
|
||||
public: //! @name Advance by iterations
|
||||
|
||||
//! Returns true if ProgressIndicator signals UserBreak
|
||||
Standard_Boolean UserBreak() const;
|
||||
|
||||
//! Returns false if ProgressIndicator signals UserBreak
|
||||
Standard_Boolean More() const
|
||||
{
|
||||
return !UserBreak();
|
||||
}
|
||||
|
||||
//! Advances position by specified step and returns the range
|
||||
//! covering this step
|
||||
Message_ProgressRange Next (Standard_Real theStep = 1.);
|
||||
|
||||
public: //! @name Auxiliary methods to use in ProgressIndicator
|
||||
|
||||
//! Force update of presentation of the progress indicator.
|
||||
//! Should not be called concurrently.
|
||||
void Show();
|
||||
|
||||
//! Returns true if this progress scope is attached to some indicator.
|
||||
Standard_Boolean IsActive() const
|
||||
{
|
||||
return myIsActive;
|
||||
}
|
||||
|
||||
//! Returns the name of the scope (may be null).
|
||||
//! Scopes with null name (e.g. root scope) should
|
||||
//! be bypassed when reporting progress to the user.
|
||||
Standard_CString Name() const
|
||||
{
|
||||
return myName;
|
||||
}
|
||||
|
||||
//! Returns parent scope (null for top-level scope)
|
||||
const Message_ProgressScope* Parent() const
|
||||
{
|
||||
return myParent;
|
||||
}
|
||||
|
||||
//! Returns the maximal value of progress in this scope
|
||||
Standard_Real MaxValue() const
|
||||
{
|
||||
return myMax;
|
||||
}
|
||||
|
||||
//! Returns the current value of progress in this scope.
|
||||
//! If this scope is being advanced by sub-scoping, that value is
|
||||
//! computed by mapping current global progress into this scope range.
|
||||
Standard_Real Value() const
|
||||
{
|
||||
return myIsActive ? myValue : myMax;
|
||||
}
|
||||
|
||||
//! Returns the infinite flag
|
||||
Standard_Boolean IsInfinite() const
|
||||
{
|
||||
return myIsInfinite;
|
||||
}
|
||||
|
||||
//! Get the portion of the indicator covered by this scope (from 0 to 1)
|
||||
Standard_Real GetPortion() const
|
||||
{
|
||||
return myPortion;
|
||||
}
|
||||
|
||||
public: //! @name Destruction, allocation
|
||||
|
||||
//! Destructor - closes the scope and adds its scale to the total progress
|
||||
~Message_ProgressScope()
|
||||
{
|
||||
Relieve();
|
||||
if (myIsOwnName)
|
||||
{
|
||||
Standard::Free (myName);
|
||||
myIsOwnName = false;
|
||||
myName = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//! Closes the scope and adds its scale to the total progress.
|
||||
//! Relieved scope should not be used.
|
||||
void Relieve();
|
||||
|
||||
DEFINE_STANDARD_ALLOC
|
||||
|
||||
private: //! @name Internal methods
|
||||
|
||||
//! Creates a top-level scope with default range [0,1] and step 1.
|
||||
//! Called only by Message_ProgressIndicator constructor.
|
||||
Message_ProgressScope (Message_ProgressIndicator* theProgress);
|
||||
|
||||
//! Convert value from this scale to global one
|
||||
Standard_Real localToGlobal(const Standard_Real theVal) const;
|
||||
|
||||
//! Convert value from global scale to this one
|
||||
Standard_Real globalToLocal(const Standard_Real theVal) const;
|
||||
|
||||
private:
|
||||
//! Copy constructor is prohibited
|
||||
Message_ProgressScope (const Message_ProgressScope& theOther);
|
||||
|
||||
//! Copy assignment is prohibited
|
||||
Message_ProgressScope& operator= (const Message_ProgressScope& theOther);
|
||||
|
||||
private:
|
||||
|
||||
Message_ProgressIndicator* myProgress; //!< Pointer to progress indicator instance
|
||||
const Message_ProgressScope* myParent; //!< Pointer to parent scope
|
||||
Standard_CString myName; //!< Name of the operation being done in this scope, or null
|
||||
|
||||
Standard_Real myPortion; //!< The portion of the global scale covered by this scope (from 0 to 1)
|
||||
Standard_Real myMax; //!< Maximal value of progress in this scope
|
||||
Standard_Real myValue; //!< Current position advanced within this scope [0, Max]
|
||||
|
||||
Standard_Boolean myIsActive; //!< flag indicating armed/disarmed state
|
||||
Standard_Boolean myIsOwnName; //!< flag indicating if name was allocated or not
|
||||
Standard_Boolean myIsInfinite; //!< Option to advance by hyperbolic law
|
||||
|
||||
private:
|
||||
friend class Message_ProgressIndicator;
|
||||
friend class Message_ProgressRange;
|
||||
};
|
||||
|
||||
#include <Message_ProgressRange.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_ProgressScope
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
inline Message_ProgressScope::Message_ProgressScope (Message_ProgressIndicator* theProgress)
|
||||
: myProgress(theProgress),
|
||||
myParent(0),
|
||||
myName(0),
|
||||
myPortion(1.),
|
||||
myMax(1.),
|
||||
myValue(0.),
|
||||
myIsActive(theProgress != NULL),
|
||||
myIsOwnName(false),
|
||||
myIsInfinite(false)
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_ProgressScope
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
inline Message_ProgressScope::Message_ProgressScope (const Message_ProgressRange& theRange,
|
||||
const TCollection_AsciiString& theName,
|
||||
Standard_Real theMax,
|
||||
Standard_Boolean isInfinite)
|
||||
: myProgress (theRange.myParentScope != NULL ? theRange.myParentScope->myProgress : NULL),
|
||||
myParent (theRange.myParentScope),
|
||||
myName (NULL),
|
||||
myPortion (theRange.myDelta),
|
||||
myMax (Max (1.e-6, theMax)), // protection against zero range
|
||||
myValue (0.),
|
||||
myIsActive (myProgress != NULL && !theRange.myWasUsed),
|
||||
myIsOwnName (false),
|
||||
myIsInfinite (isInfinite)
|
||||
{
|
||||
SetName (theName);
|
||||
Standard_ASSERT_VOID (! theRange.myWasUsed, "Message_ProgressRange is used to initialize more than one scope");
|
||||
theRange.myWasUsed = true; // Disarm the range
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_ProgressScope
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
template<size_t N>
|
||||
Message_ProgressScope::Message_ProgressScope (const Message_ProgressRange& theRange,
|
||||
const char (&theName)[N],
|
||||
Standard_Real theMax,
|
||||
Standard_Boolean isInfinite)
|
||||
: myProgress (theRange.myParentScope != NULL ? theRange.myParentScope->myProgress : NULL),
|
||||
myParent (theRange.myParentScope),
|
||||
myName (theName),
|
||||
myPortion (theRange.myDelta),
|
||||
myMax (Max (1.e-6, theMax)), // protection against zero range
|
||||
myValue (0.),
|
||||
myIsActive (myProgress != NULL && !theRange.myWasUsed),
|
||||
myIsOwnName (false),
|
||||
myIsInfinite (isInfinite)
|
||||
{
|
||||
Standard_ASSERT_VOID (! theRange.myWasUsed, "Message_ProgressRange is used to initialize more than one scope");
|
||||
theRange.myWasUsed = true; // Disarm the range
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Message_ProgressScope
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
inline Message_ProgressScope::Message_ProgressScope (const Message_ProgressRange& theRange,
|
||||
const NullString* ,
|
||||
Standard_Real theMax,
|
||||
Standard_Boolean isInfinite)
|
||||
: myProgress (theRange.myParentScope != NULL ? theRange.myParentScope->myProgress : NULL),
|
||||
myParent (theRange.myParentScope),
|
||||
myName (NULL),
|
||||
myPortion (theRange.myDelta),
|
||||
myMax (Max (1.e-6, theMax)), // protection against zero range
|
||||
myValue (0.),
|
||||
myIsActive (myProgress != NULL && !theRange.myWasUsed),
|
||||
myIsOwnName (false),
|
||||
myIsInfinite (isInfinite)
|
||||
{
|
||||
Standard_ASSERT_VOID (! theRange.myWasUsed, "Message_ProgressRange is used to initialize more than one scope");
|
||||
theRange.myWasUsed = true; // Disarm the range
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Relieve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
inline void Message_ProgressScope::Relieve()
|
||||
{
|
||||
if (!myIsActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Advance indicator to the end of the scope
|
||||
Standard_Real aCurr = localToGlobal (myValue);
|
||||
myValue = (myIsInfinite ? Precision::Infinite() : myMax);
|
||||
Standard_Real aDelta = myPortion - aCurr;
|
||||
if (aDelta > 0.)
|
||||
{
|
||||
myProgress->Increment (aDelta, *this);
|
||||
}
|
||||
Standard_ASSERT_VOID (myParent == 0 || myParent->myIsActive,
|
||||
"Parent progress scope has been closed before child");
|
||||
|
||||
myIsActive = false;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : UserBreak
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
inline Standard_Boolean Message_ProgressScope::UserBreak() const
|
||||
{
|
||||
return myProgress && myProgress->UserBreak();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
inline Message_ProgressRange Message_ProgressScope::Next (Standard_Real theStep)
|
||||
{
|
||||
if (myIsActive)
|
||||
{
|
||||
if (theStep > 0.)
|
||||
{
|
||||
Standard_Real aCurr = localToGlobal (myValue);
|
||||
Standard_Real aNext = localToGlobal (myValue += theStep);
|
||||
Standard_Real aDelta = aNext - aCurr;
|
||||
if (aDelta > 0.)
|
||||
{
|
||||
return Message_ProgressRange (*this, aDelta);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Message_ProgressRange();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Show
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void Message_ProgressScope::Show ()
|
||||
{
|
||||
if (myIsActive)
|
||||
{
|
||||
myProgress->Show (*this, Standard_True);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : localToGlobal
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
inline Standard_Real Message_ProgressScope::localToGlobal (const Standard_Real theVal) const
|
||||
{
|
||||
if (theVal <= 0.)
|
||||
return 0.;
|
||||
|
||||
if (!myIsInfinite)
|
||||
{
|
||||
if (myMax - theVal < RealSmall())
|
||||
return myPortion;
|
||||
return myPortion * theVal / myMax;
|
||||
}
|
||||
|
||||
double x = theVal / myMax;
|
||||
// return myPortion * ( 1. - std::exp ( -x ) ); // exponent
|
||||
return myPortion * x / (1. + x); // hyperbola
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : globalToLocal
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline Standard_Real Message_ProgressScope::globalToLocal (const Standard_Real theVal) const
|
||||
{
|
||||
// if at end of the scope (or behind), report the maximum
|
||||
Standard_Real aDist = myPortion - theVal;
|
||||
if (aDist <= Precision::Confusion())
|
||||
return myIsInfinite ? Precision::Infinite() : myMax;
|
||||
|
||||
if (!myIsInfinite)
|
||||
return myMax * theVal / myPortion;
|
||||
|
||||
// Standard_Real x = log (theVal / aDist); // exponent
|
||||
Standard_Real x = theVal / aDist; // hyperbola
|
||||
return x * myMax;
|
||||
}
|
||||
|
||||
#endif // _Message_ProgressScope_HeaderFile
|
@@ -1,56 +0,0 @@
|
||||
// Copyright (c) 1999-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
|
||||
#include <Message_ProgressIndicator.hxx>
|
||||
#include <Message_ProgressSentry.hxx>
|
||||
#include <TCollection_HAsciiString.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//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 );
|
||||
}
|
@@ -1,6 +1,4 @@
|
||||
// Created on: 2002-02-22
|
||||
// Created by: Andrey BETENEV
|
||||
// Copyright (c) 2002-2014 OPEN CASCADE SAS
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
@@ -13,111 +11,42 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Message_ProgressSentry_HeaderFile
|
||||
#define _Message_ProgressSentry_HeaderFile
|
||||
#ifndef Message_ProgressSentry_HeaderFile
|
||||
#define Message_ProgressSentry_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_DefineAlloc.hxx>
|
||||
#include <Standard_Handle.hxx>
|
||||
#include <Message_ProgressScope.hxx>
|
||||
|
||||
#include <Standard_Boolean.hxx>
|
||||
#include <Standard_CString.hxx>
|
||||
#include <Standard_Real.hxx>
|
||||
class Message_ProgressIndicator;
|
||||
class TCollection_HAsciiString;
|
||||
|
||||
|
||||
//! 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)
|
||||
//!
|
||||
//! Example of usage in nested process:
|
||||
//!
|
||||
//! @code{.cpp}
|
||||
//! Handle(Draw_ProgressIndicator) aProgress = ...;
|
||||
//!
|
||||
//! // Outer cycle
|
||||
//! Message_ProgressSentry anOuter (aProgress, "Outer", 0, nbOuter, 1);
|
||||
//! for (int i = 0; i < nbOuter && anOuter.More(); i++, anOuter.Next())
|
||||
//! {
|
||||
//! // Inner cycle
|
||||
//! Message_ProgressSentry anInner (aProgress, "Inner", 0, nbInner, 1);
|
||||
//! for (int j = 0; j < nbInner && anInner.More(); j++, anInner.Next())
|
||||
//! {
|
||||
//! // Cycle body
|
||||
//! }
|
||||
//! }
|
||||
//! @endcode
|
||||
|
||||
class Message_ProgressSentry
|
||||
//! Functionality of this class (Message_ProgressSentry) has been superseded by Message_ProgressScope.
|
||||
//! This class is kept just to simplify transition of an old code and will be removed in future.
|
||||
class Standard_DEPRECATED("Deprecated class, Message_ProgressScope should be used instead")
|
||||
Message_ProgressSentry : public Message_ProgressScope
|
||||
{
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_ALLOC
|
||||
|
||||
|
||||
Standard_EXPORT Message_ProgressSentry(const Handle(Message_ProgressIndicator)& PI, const Standard_CString name, const Standard_Real min, const Standard_Real max, const Standard_Real step, const Standard_Boolean isInf = Standard_False, const Standard_Real newScopeSpan = 0.0);
|
||||
|
||||
//! 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)
|
||||
Standard_EXPORT Message_ProgressSentry(const Handle(Message_ProgressIndicator)& PI, const Handle(TCollection_HAsciiString)& name, const Standard_Real min, const Standard_Real max, const Standard_Real step, const Standard_Boolean isInf = Standard_False, const Standard_Real newScopeSpan = 0.0);
|
||||
|
||||
//! 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.
|
||||
void Relieve();
|
||||
~Message_ProgressSentry()
|
||||
{
|
||||
Relieve();
|
||||
}
|
||||
|
||||
void Next (const Standard_CString name = 0) const;
|
||||
|
||||
void Next (const Standard_Real span, const Standard_CString name = 0) const;
|
||||
|
||||
//! Closes current scope and opens next one
|
||||
//! with either specified or default span
|
||||
void Next (const Standard_Real span, const Handle(TCollection_HAsciiString)& name) const;
|
||||
|
||||
//! Returns False if ProgressIndicator signals UserBreak
|
||||
Standard_Boolean More() const;
|
||||
|
||||
//! Forces update of progress indicator display
|
||||
void Show() const;
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
|
||||
//! Deprecated constructor, Message_ProgressScope should be created instead.
|
||||
Message_ProgressSentry (const Message_ProgressRange& theRange,
|
||||
const Standard_CString theName,
|
||||
const Standard_Real theMin,
|
||||
const Standard_Real theMax,
|
||||
const Standard_Real theStep,
|
||||
const Standard_Boolean theIsInf = Standard_False,
|
||||
const Standard_Real theNewScopeSpan = 0.0)
|
||||
: Message_ProgressScope (theRange, theName, theMax, theIsInf)
|
||||
{
|
||||
if (theMin != 0.0 || theStep != 1.0 || theNewScopeSpan != 0.0)
|
||||
{
|
||||
throw Standard_ProgramError ("Message_ProgressSentry, invalid parameters");
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
Handle(Message_ProgressIndicator) myProgress;
|
||||
Standard_Boolean myActive;
|
||||
|
||||
|
||||
//! Message_ProgressRange should be passed to constructor instead of Message_ProgressIndicator.
|
||||
Message_ProgressSentry (const Handle(Message_ProgressIndicator)& theProgress,
|
||||
const Standard_CString theName,
|
||||
const Standard_Real theMin,
|
||||
const Standard_Real theMax,
|
||||
const Standard_Real theStep,
|
||||
const Standard_Boolean theIsInf = Standard_False,
|
||||
const Standard_Real theNewScopeSpan = 0.0);
|
||||
};
|
||||
|
||||
|
||||
#include <Message_ProgressSentry.lxx>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // _Message_ProgressSentry_HeaderFile
|
||||
#endif // Message_ProgressSentry_HeaderFile
|
||||
|
@@ -1,81 +0,0 @@
|
||||
// Copyright (c) 1999-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#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.IsNull() ) myProgress->Show();
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
// Created on: 1999-07-29
|
||||
// Created by: Roman LYGIN
|
||||
// Copyright (c) 1999 Matra Datavision
|
||||
// Copyright (c) 1999-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef Message_SequenceOfProgressScale_HeaderFile
|
||||
#define Message_SequenceOfProgressScale_HeaderFile
|
||||
|
||||
#include <Message_ProgressScale.hxx>
|
||||
#include <NCollection_Sequence.hxx>
|
||||
|
||||
typedef NCollection_Sequence<Message_ProgressScale> Message_SequenceOfProgressScale;
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user