1
0
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:
msv
2020-07-10 14:19:31 +03:00
committed by abv
parent 99289bed0a
commit 7e785937b3
271 changed files with 3701 additions and 3149 deletions

View File

@@ -29,6 +29,7 @@
#include <Interface_EntityIterator.hxx>
#include <Interface_Static.hxx>
#include <Message_Messenger.hxx>
#include <Message_ProgressScope.hxx>
#include <MoniTool_DataMapIteratorOfDataMapOfShapeTransient.hxx>
#include <OSD_Path.hxx>
#include <Quantity_TypeOfColor.hxx>
@@ -365,16 +366,17 @@ IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString filen
//purpose :
//=======================================================================
Standard_Boolean STEPCAFControl_Writer::Transfer( const Handle(TDocStd_Document) &doc,
const STEPControl_StepModelType mode,
const Standard_CString multi )
Standard_Boolean STEPCAFControl_Writer::Transfer(const Handle(TDocStd_Document) &doc,
const STEPControl_StepModelType mode,
const Standard_CString multi,
const Message_ProgressRange& theProgress)
{
Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
if ( STool.IsNull() ) return Standard_False;
TDF_LabelSequence labels;
STool->GetFreeShapes ( labels );
return Transfer ( myWriter, labels, mode, multi );
return Transfer(myWriter, labels, mode, multi, Standard_False, theProgress);
}
@@ -383,13 +385,14 @@ Standard_Boolean STEPCAFControl_Writer::Transfer( const Handle(TDocStd_Document)
//purpose :
//=======================================================================
Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_Label& L,
const STEPControl_StepModelType mode,
const Standard_CString multi )
Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_Label& L,
const STEPControl_StepModelType mode,
const Standard_CString multi,
const Message_ProgressRange& theProgress)
{
TDF_LabelSequence labels;
labels.Append ( L );
return Transfer ( myWriter, labels, mode, multi );
return Transfer(myWriter, labels, mode, multi, Standard_False, theProgress);
}
//=======================================================================
@@ -397,11 +400,12 @@ Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_Label& L,
//purpose :
//=======================================================================
Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_LabelSequence& labels,
const STEPControl_StepModelType mode,
const Standard_CString multi )
Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_LabelSequence& labels,
const STEPControl_StepModelType mode,
const Standard_CString multi,
const Message_ProgressRange& theProgress)
{
return Transfer( myWriter, labels, mode, multi );
return Transfer(myWriter, labels, mode, multi, Standard_False, theProgress);
}
//=======================================================================
@@ -410,9 +414,10 @@ Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_LabelSequence& label
//=======================================================================
Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
const Standard_CString filename)
const Standard_CString filename,
const Message_ProgressRange& theProgress)
{
if ( ! Transfer ( doc ) ) return Standard_False;
if (!Transfer(doc, STEPControl_AsIs, 0L, theProgress)) return Standard_False;
return Write ( filename ) == IFSelect_RetDone;
}
@@ -423,9 +428,10 @@ Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document)
//=======================================================================
Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
const TCollection_AsciiString &filename)
const TCollection_AsciiString &filename,
const Message_ProgressRange& theProgress)
{
if ( ! Transfer ( doc ) ) return Standard_False;
if ( ! Transfer ( doc, STEPControl_AsIs, 0L, theProgress ) ) return Standard_False;
return Write ( filename.ToCString() ) == IFSelect_RetDone;
}
@@ -500,10 +506,11 @@ const STEPControl_Writer &STEPCAFControl_Writer::Writer () const
//=======================================================================
Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
const TDF_LabelSequence &labels,
const STEPControl_StepModelType mode,
const Standard_CString multi,
const Standard_Boolean isExternFile)
const TDF_LabelSequence &labels,
const STEPControl_StepModelType mode,
const Standard_CString multi,
const Standard_Boolean isExternFile,
const Message_ProgressRange& theProgress)
{
if ( labels.Length() <=0 ) return Standard_False;
@@ -513,7 +520,10 @@ Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
// translate free top-level shapes of the DECAF document
Standard_Integer ap = Interface_Static::IVal ("write.step.schema");
TDF_LabelSequence sublabels;
for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
Message_ProgressScope aPS(theProgress, "Labels", labels.Length());
for ( Standard_Integer i=1; i <= labels.Length() && aPS.More(); i++)
{
Message_ProgressRange aRange = aPS.Next();
TDF_Label L = labels.Value(i);
if ( myLabels.IsBound ( L ) ) continue; // already processed
@@ -576,12 +586,15 @@ Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
if ( XCAFDoc_ShapeTool::IsAssembly ( L ) || XCAFDoc_ShapeTool::IsReference ( L ) )
Actor->RegisterAssembly ( shape );
writer.Transfer(shape,mode,Standard_False);
writer.Transfer(shape, mode, Standard_False, aRange);
Actor->SetStdMode ( Standard_True ); // restore default behaviour
}
else {
// translate final solids
TopoDS_Shape Sass = TransferExternFiles ( L, mode, sublabels, multi );
Message_ProgressScope aPS1 (aRange, NULL, 2);
TopoDS_Shape Sass = TransferExternFiles(L, mode, sublabels, multi, aPS1.Next());
if (aPS1.UserBreak())
return Standard_False;
// translate main assembly structure
/*
@@ -603,11 +616,13 @@ Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
*/
Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
Interface_Static::SetCVal ("write.step.assembly", "On");
writer.Transfer ( Sass, STEPControl_AsIs );
writer.Transfer ( Sass, STEPControl_AsIs, Standard_True, aPS1.Next());
Interface_Static::SetIVal ("write.step.assembly", assemblymode);
Interface_Static::SetIVal ("write.step.schema", ap);
}
}
if (aPS.UserBreak())
return Standard_False;
writer.WS()->ComputeGraph(Standard_True );// added by skl 03.11.2003 since we use
// writer.Transfer() wihtout compute graph
@@ -716,9 +731,10 @@ Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
//=======================================================================
TopoDS_Shape STEPCAFControl_Writer::TransferExternFiles (const TDF_Label &L,
const STEPControl_StepModelType mode,
TDF_LabelSequence &labels,
const Standard_CString prefix)
const STEPControl_StepModelType mode,
TDF_LabelSequence &labels,
const Standard_CString prefix,
const Message_ProgressRange& theProgress)
{
// if label already translated, just return the shape
if ( myLabels.IsBound ( L ) ) {
@@ -763,7 +779,7 @@ TopoDS_Shape STEPCAFControl_Writer::TransferExternFiles (const TDF_Label &L,
Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
Interface_Static::SetCVal ("write.step.assembly", "Off");
const Standard_CString multi = 0;
EF->SetTransferStatus ( Transfer ( sw, Lseq, mode, multi, Standard_True ) );
EF->SetTransferStatus ( Transfer ( sw, Lseq, mode, multi, Standard_True, theProgress) );
Interface_Static::SetIVal ("write.step.assembly", assemblymode);
myLabEF.Bind ( L, EF );
myFiles.Bind ( name->ToCString(), EF );
@@ -787,11 +803,12 @@ TopoDS_Shape STEPCAFControl_Writer::TransferExternFiles (const TDF_Label &L,
XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_False );
labels.Append ( aCurL );
for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
Message_ProgressScope aPS(theProgress, NULL, comp.Length());
for ( Standard_Integer k=1; k <= comp.Length() && aPS.More(); k++ ) {
TDF_Label lab = comp(k);
TDF_Label ref;
if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, ref ) ) continue;
TopoDS_Shape Scomp = TransferExternFiles ( ref, mode, labels, prefix );
TopoDS_Shape Scomp = TransferExternFiles(ref, mode, labels, prefix, aPS.Next());
Scomp.Location ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
B.Add ( C, Scomp );
}