mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +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:
@@ -42,7 +42,7 @@
|
||||
#include <TDF_Label.hxx>
|
||||
#include <TDocStd_Document.hxx>
|
||||
#include <TDocStd_Owner.hxx>
|
||||
#include <Message_ProgressSentry.hxx>
|
||||
#include <Message_ProgressScope.hxx>
|
||||
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(BinLDrivers_DocumentRetrievalDriver,PCDM_RetrievalDriver)
|
||||
@@ -80,7 +80,7 @@ void BinLDrivers_DocumentRetrievalDriver::Read
|
||||
(const TCollection_ExtendedString& theFileName,
|
||||
const Handle(CDM_Document)& theNewDocument,
|
||||
const Handle(CDM_Application)& theApplication,
|
||||
const Handle(Message_ProgressIndicator)& theProgress)
|
||||
const Message_ProgressRange& theRange)
|
||||
{
|
||||
std::ifstream aFileStream;
|
||||
OSD_OpenStream (aFileStream, theFileName, std::ios::in | std::ios::binary);
|
||||
@@ -90,8 +90,8 @@ void BinLDrivers_DocumentRetrievalDriver::Read
|
||||
Handle(Storage_Data) dData;
|
||||
TCollection_ExtendedString aFormat = PCDM_ReadWriter::FileFormat (aFileStream, dData);
|
||||
|
||||
Read(aFileStream, dData, theNewDocument, theApplication, theProgress);
|
||||
if (!theProgress.IsNull() && theProgress->UserBreak())
|
||||
Read(aFileStream, dData, theNewDocument, theApplication, theRange);
|
||||
if (!theRange.More())
|
||||
{
|
||||
myReaderStatus = PCDM_RS_UserBreak;
|
||||
return;
|
||||
@@ -117,7 +117,7 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream&
|
||||
const Handle(Storage_Data)& theStorageData,
|
||||
const Handle(CDM_Document)& theDoc,
|
||||
const Handle(CDM_Application)& theApplication,
|
||||
const Handle(Message_ProgressIndicator)& theProgress)
|
||||
const Message_ProgressRange& theRange)
|
||||
{
|
||||
myReaderStatus = PCDM_RS_DriverFailure;
|
||||
myMsgDriver = theApplication -> MessageDriver();
|
||||
@@ -233,7 +233,7 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream&
|
||||
Handle(TDF_Data) aData = new TDF_Data();
|
||||
std::streampos aDocumentPos = -1;
|
||||
|
||||
Message_ProgressSentry aPS(theProgress, "Reading data", 0, 3, 1);
|
||||
Message_ProgressScope aPS(theRange, "Reading data", 3);
|
||||
|
||||
// 2b. Read the TOC of Sections
|
||||
if (aFileVer >= 3) {
|
||||
@@ -259,13 +259,12 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream&
|
||||
theIStream.seekg ((std::streampos) aCurSection.Offset());
|
||||
if (aCurSection.Name().IsEqual ((Standard_CString)SHAPESECTION_POS))
|
||||
{
|
||||
ReadShapeSection (aCurSection, theIStream, false, theProgress);
|
||||
ReadShapeSection (aCurSection, theIStream, false, aPS.Next());
|
||||
if (!aPS.More())
|
||||
{
|
||||
myReaderStatus = PCDM_RS_UserBreak;
|
||||
return;
|
||||
}
|
||||
aPS.Next();
|
||||
}
|
||||
else
|
||||
ReadSection (aCurSection, theDoc, theIStream);
|
||||
@@ -306,13 +305,12 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream&
|
||||
CheckShapeSection(aShapeSectionPos, theIStream);
|
||||
// Read Shapes
|
||||
BinLDrivers_DocumentSection aCurSection;
|
||||
ReadShapeSection (aCurSection, theIStream, Standard_False, theProgress);
|
||||
ReadShapeSection (aCurSection, theIStream, Standard_False, aPS.Next());
|
||||
if (!aPS.More())
|
||||
{
|
||||
myReaderStatus = PCDM_RS_UserBreak;
|
||||
return;
|
||||
}
|
||||
aPS.Next();
|
||||
}
|
||||
}
|
||||
} // end of reading Sections or shape section
|
||||
@@ -325,13 +323,13 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream&
|
||||
theIStream.read ((char*)&aTag, sizeof(Standard_Integer));
|
||||
|
||||
// read sub-tree of the root label
|
||||
Standard_Integer nbRead = ReadSubTree (theIStream, aData->Root(), theProgress);
|
||||
Standard_Integer nbRead = ReadSubTree (theIStream, aData->Root(), aPS.Next());
|
||||
if (!aPS.More())
|
||||
{
|
||||
myReaderStatus = PCDM_RS_UserBreak;
|
||||
return;
|
||||
}
|
||||
aPS.Next();
|
||||
|
||||
Clear();
|
||||
if (!aPS.More())
|
||||
{
|
||||
@@ -369,13 +367,13 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream&
|
||||
Standard_Integer BinLDrivers_DocumentRetrievalDriver::ReadSubTree
|
||||
(Standard_IStream& theIS,
|
||||
const TDF_Label& theLabel,
|
||||
const Handle(Message_ProgressIndicator)& theProgress)
|
||||
const Message_ProgressRange& theRange)
|
||||
{
|
||||
Standard_Integer nbRead = 0;
|
||||
TCollection_ExtendedString aMethStr
|
||||
("BinLDrivers_DocumentRetrievalDriver: ");
|
||||
|
||||
Message_ProgressSentry aPS(theProgress, "Reading sub tree", 0, 2, 1, true);
|
||||
Message_ProgressScope aPS(theRange, "Reading sub tree", 2, true);
|
||||
|
||||
// Read attributes:
|
||||
theIS >> myPAtt;
|
||||
@@ -464,9 +462,9 @@ Standard_Integer BinLDrivers_DocumentRetrievalDriver::ReadSubTree
|
||||
return -1;
|
||||
}
|
||||
|
||||
aPS.Next();
|
||||
|
||||
// read sub-tree
|
||||
Standard_Integer nbSubRead = ReadSubTree (theIS, aLab, theProgress);
|
||||
Standard_Integer nbSubRead = ReadSubTree (theIS, aLab, aPS.Next());
|
||||
// check for error
|
||||
if (nbSubRead == -1)
|
||||
return -1;
|
||||
@@ -522,7 +520,7 @@ void BinLDrivers_DocumentRetrievalDriver::ReadShapeSection
|
||||
(BinLDrivers_DocumentSection& theSection,
|
||||
Standard_IStream& /*theIS*/,
|
||||
const Standard_Boolean isMess,
|
||||
const Handle(Message_ProgressIndicator) &/*theProgress*/)
|
||||
const Message_ProgressRange &/*theRange*/)
|
||||
|
||||
{
|
||||
if(isMess && theSection.Length()) {
|
||||
|
@@ -62,13 +62,13 @@ public:
|
||||
Standard_EXPORT virtual void Read (const TCollection_ExtendedString& theFileName,
|
||||
const Handle(CDM_Document)& theNewDocument,
|
||||
const Handle(CDM_Application)& theApplication,
|
||||
const Handle(Message_ProgressIndicator)& theProgress = NULL) Standard_OVERRIDE;
|
||||
const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE;
|
||||
|
||||
Standard_EXPORT virtual void Read (Standard_IStream& theIStream,
|
||||
const Handle(Storage_Data)& theStorageData,
|
||||
const Handle(CDM_Document)& theDoc,
|
||||
const Handle(CDM_Application)& theApplication,
|
||||
const Handle(Message_ProgressIndicator)& theProgress = NULL) Standard_OVERRIDE;
|
||||
const Message_ProgressRange& theProgress = Message_ProgressRange()) Standard_OVERRIDE;
|
||||
|
||||
Standard_EXPORT virtual Handle(BinMDF_ADriverTable) AttributeDrivers (const Handle(Message_Messenger)& theMsgDriver);
|
||||
|
||||
@@ -84,7 +84,7 @@ protected:
|
||||
Standard_EXPORT virtual Standard_Integer ReadSubTree
|
||||
(Standard_IStream& theIS,
|
||||
const TDF_Label& theData,
|
||||
const Handle(Message_ProgressIndicator)& theProgress = NULL);
|
||||
const Message_ProgressRange& theRanges = Message_ProgressRange());
|
||||
|
||||
|
||||
//! define the procedure of reading a section to file.
|
||||
@@ -98,7 +98,7 @@ protected:
|
||||
(BinLDrivers_DocumentSection& theSection,
|
||||
Standard_IStream& theIS,
|
||||
const Standard_Boolean isMess = Standard_False,
|
||||
const Handle(Message_ProgressIndicator)& theProgress = NULL);
|
||||
const Message_ProgressRange& theRange = Message_ProgressRange());
|
||||
|
||||
//! checks the shapes section can be correctly retreived.
|
||||
Standard_EXPORT virtual void CheckShapeSection (const Storage_Position& thePos, Standard_IStream& theIS);
|
||||
|
@@ -42,7 +42,7 @@
|
||||
#include <TDF_Label.hxx>
|
||||
#include <TDF_Tool.hxx>
|
||||
#include <TDocStd_Document.hxx>
|
||||
#include <Message_ProgressSentry.hxx>
|
||||
#include <Message_ProgressScope.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(BinLDrivers_DocumentStorageDriver,PCDM_StorageDriver)
|
||||
|
||||
@@ -65,7 +65,7 @@ BinLDrivers_DocumentStorageDriver::BinLDrivers_DocumentStorageDriver ()
|
||||
void BinLDrivers_DocumentStorageDriver::Write
|
||||
(const Handle(CDM_Document)& theDocument,
|
||||
const TCollection_ExtendedString& theFileName,
|
||||
const Handle(Message_ProgressIndicator)& theProgress)
|
||||
const Message_ProgressRange& theRange)
|
||||
{
|
||||
SetIsError(Standard_False);
|
||||
SetStoreStatus(PCDM_SS_OK);
|
||||
@@ -77,7 +77,7 @@ void BinLDrivers_DocumentStorageDriver::Write
|
||||
|
||||
if (aFileStream.is_open() && aFileStream.good())
|
||||
{
|
||||
Write(theDocument, aFileStream, theProgress);
|
||||
Write(theDocument, aFileStream, theRange);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -91,9 +91,9 @@ void BinLDrivers_DocumentStorageDriver::Write
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void BinLDrivers_DocumentStorageDriver::Write (const Handle(CDM_Document)& theDoc,
|
||||
Standard_OStream& theOStream,
|
||||
const Handle(Message_ProgressIndicator)& theProgress)
|
||||
void BinLDrivers_DocumentStorageDriver::Write (const Handle(CDM_Document)& theDoc,
|
||||
Standard_OStream& theOStream,
|
||||
const Message_ProgressRange& theRange)
|
||||
{
|
||||
myMsgDriver = theDoc->Application()->MessageDriver();
|
||||
myMapUnsupported.Clear();
|
||||
@@ -140,26 +140,26 @@ void BinLDrivers_DocumentStorageDriver::Write (const Handle(CDM_Document)& theDo
|
||||
myRelocTable.Clear();
|
||||
myPAtt.Init();
|
||||
|
||||
Message_ProgressSentry aPS(theProgress, "Writing document", 0, 3, 1);
|
||||
Message_ProgressScope aPS(theRange, "Writing document", 3);
|
||||
|
||||
// Write Doc structure
|
||||
WriteSubTree (aData->Root(), theOStream, theProgress); // Doc is written
|
||||
WriteSubTree (aData->Root(), theOStream, aPS.Next()); // Doc is written
|
||||
if (!aPS.More())
|
||||
{
|
||||
SetIsError(Standard_True);
|
||||
SetStoreStatus(PCDM_SS_UserBreak);
|
||||
return;
|
||||
}
|
||||
aPS.Next();
|
||||
|
||||
// 4. Write Shapes section
|
||||
WriteShapeSection (aShapesSection, theOStream, theProgress);
|
||||
WriteShapeSection (aShapesSection, theOStream, aPS.Next());
|
||||
if (!aPS.More())
|
||||
{
|
||||
SetIsError(Standard_True);
|
||||
SetStoreStatus(PCDM_SS_UserBreak);
|
||||
return;
|
||||
}
|
||||
aPS.Next();
|
||||
|
||||
// Write application-defined sections
|
||||
for (anIterS.Init (mySections); anIterS.More(); anIterS.Next()) {
|
||||
BinLDrivers_DocumentSection& aSection = anIterS.ChangeValue();
|
||||
@@ -228,16 +228,16 @@ void BinLDrivers_DocumentStorageDriver::UnsupportedAttrMsg
|
||||
//=======================================================================
|
||||
|
||||
void BinLDrivers_DocumentStorageDriver::WriteSubTree
|
||||
(const TDF_Label& theLabel,
|
||||
Standard_OStream& theOS,
|
||||
const Handle(Message_ProgressIndicator)& theProgress)
|
||||
(const TDF_Label& theLabel,
|
||||
Standard_OStream& theOS,
|
||||
const Message_ProgressRange& theRange)
|
||||
{
|
||||
// Skip empty labels
|
||||
if (!myEmptyLabels.IsEmpty() && myEmptyLabels.First() == theLabel) {
|
||||
myEmptyLabels.RemoveFirst();
|
||||
return;
|
||||
}
|
||||
Message_ProgressSentry aPS(theProgress, "Writing sub tree", 0, 2, 1, 1);
|
||||
Message_ProgressScope aPS(theRange, "Writing sub tree", 2, true);
|
||||
// Write label header: tag
|
||||
Standard_Integer aTag = theLabel.Tag();
|
||||
#if DO_INVERSE
|
||||
@@ -298,8 +298,7 @@ void BinLDrivers_DocumentStorageDriver::WriteSubTree
|
||||
SetStoreStatus(PCDM_SS_UserBreak);
|
||||
return;
|
||||
}
|
||||
aPS.Next();
|
||||
WriteSubTree (aChildLab, theOS, theProgress);
|
||||
WriteSubTree (aChildLab, theOS, aPS.Next());
|
||||
}
|
||||
|
||||
// Write the end label marker
|
||||
@@ -547,7 +546,7 @@ void BinLDrivers_DocumentStorageDriver::WriteSection
|
||||
void BinLDrivers_DocumentStorageDriver::WriteShapeSection
|
||||
(BinLDrivers_DocumentSection& theSection,
|
||||
Standard_OStream& theOS,
|
||||
const Handle(Message_ProgressIndicator)& /*theProgress*/)
|
||||
const Message_ProgressRange& /*theRange*/)
|
||||
{
|
||||
const Standard_Size aShapesSectionOffset = (Standard_Size) theOS.tellp();
|
||||
theSection.Write (theOS, aShapesSectionOffset);
|
||||
|
@@ -54,12 +54,12 @@ public:
|
||||
//! Write <theDocument> to the binary file <theFileName>
|
||||
Standard_EXPORT virtual void Write (const Handle(CDM_Document)& theDocument,
|
||||
const TCollection_ExtendedString& theFileName,
|
||||
const Handle(Message_ProgressIndicator)& theProgress = NULL) Standard_OVERRIDE;
|
||||
const Message_ProgressRange& theRange = Message_ProgressRange()) Standard_OVERRIDE;
|
||||
|
||||
//! Write <theDocument> to theOStream
|
||||
Standard_EXPORT virtual void Write (const Handle(CDM_Document)& theDocument,
|
||||
Standard_OStream& theOStream,
|
||||
const Handle(Message_ProgressIndicator)& theProgress = NULL) Standard_OVERRIDE;
|
||||
const Message_ProgressRange& theRange = Message_ProgressRange()) Standard_OVERRIDE;
|
||||
|
||||
Standard_EXPORT virtual Handle(BinMDF_ADriverTable) AttributeDrivers (const Handle(Message_Messenger)& theMsgDriver);
|
||||
|
||||
@@ -77,7 +77,7 @@ protected:
|
||||
//! Write the tree under <theLabel> to the stream <theOS>
|
||||
Standard_EXPORT void WriteSubTree (const TDF_Label& theData,
|
||||
Standard_OStream& theOS,
|
||||
const Handle(Message_ProgressIndicator)& theProgress = NULL);
|
||||
const Message_ProgressRange& theRange = Message_ProgressRange());
|
||||
|
||||
//! define the procedure of writing a section to file.
|
||||
Standard_EXPORT virtual void WriteSection (const TCollection_AsciiString& theName,
|
||||
@@ -87,7 +87,7 @@ protected:
|
||||
//! defines the procedure of writing a shape section to file
|
||||
Standard_EXPORT virtual void WriteShapeSection (BinLDrivers_DocumentSection& theDocSection,
|
||||
Standard_OStream& theOS,
|
||||
const Handle(Message_ProgressIndicator)& theProgress = NULL);
|
||||
const Message_ProgressRange& theRange = Message_ProgressRange());
|
||||
|
||||
Handle(BinMDF_ADriverTable) myDrivers;
|
||||
BinObjMgt_SRelocationTable myRelocTable;
|
||||
|
Reference in New Issue
Block a user