How to use Message_ProgressIndicator?

frankpian

CAD practitioner
I read carefully occt's header file and kgv's articles. But I still don't know how to use it.

I'll write a simple example referring to Draw. But it doesn't work. Is there a complete example I can use as a reference?

C++:
#include <Standard.hxx>
#include <Message_ProgressIndicator.hxx>
#include <STEPControl_Reader.hxx>
#include <TopoDS_Shape.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS.hxx>
#include <TDocStd_Document.hxx>
#include <Quantity_Color.hxx>
#include <XCAFApp_Application.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <gp_Ax2.hxx>
#include <gp_Circ.hxx>
#include <STEPCAFControl_Writer.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_ColorTool.hxx>
#include <TDataStd_Name.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <NCollection_List.hxx>

class Progress : public Message_ProgressIndicator
{
private:
    Standard_Real myUpdateThreshold;
public:
    DEFINE_STANDARD_RTTIEXT(Progress, Message_ProgressIndicator)


    Standard_EXPORT Progress(Standard_Real theUpdateThreshold = 1.) :myUpdateThreshold(0.01 * theUpdateThreshold) {}
    Standard_EXPORT ~Progress() { Reset(); }
    Standard_EXPORT virtual void Reset() Standard_OVERRIDE {
        Message_ProgressIndicator::Reset();

    }
    Standard_EXPORT virtual void Show(const Message_ProgressScope& theScope,
        const Standard_Boolean force = Standard_True) Standard_OVERRIDE {
        std::stringstream aText;
        aText.setf(std::ios::fixed, std::ios::floatfield);
        aText.precision(0);
        aText << "Progress: " << 100. * GetPosition() << "%";
        NCollection_List<const Message_ProgressScope*> aScopes;
        for (const Message_ProgressScope* aPS = &theScope; aPS; aPS = aPS->Parent())
            aScopes.Prepend(aPS);
        for (NCollection_List<const Message_ProgressScope*>::Iterator it(aScopes); it.More(); it.Next())
        {
            const Message_ProgressScope* aPS = it.Value();
            if (!aPS->Name()) continue; // skip unnamed scopes
            aText << " " << aPS->Name() << ": ";

            // print progress info differently for finite and infinite scopes
            Standard_Real aVal = aPS->Value();
            if (aPS->IsInfinite())
            {
                if (Precision::IsInfinite(aVal))
                {
                    aText << "finished";
                }
                else
                {
                    aText << aVal;
                }
            }
            else
            {
                aText << aVal << " / " << aPS->MaxValue();
            }
        }
    }

    Standard_EXPORT virtual Standard_Boolean UserBreak() Standard_OVERRIDE {
        return true;
    }
};
DEFINE_STANDARD_HANDLE(Progress, Message_ProgressIndicator);
IMPLEMENT_STANDARD_RTTIEXT(Progress, Message_ProgressIndicator);
int main()
{
    Handle(Progress) theProgress = new Progress(1);


    Handle(TDocStd_Document) hDoc;
    Quantity_Color redColor(Quantity_NOC_RED);
    XCAFApp_Application::GetApplication()->NewDocument("MDTV-XCAF", hDoc);

    Handle(XCAFDoc_ColorTool) hColorTool = XCAFDoc_DocumentTool::ColorTool(hDoc->Main());
    Handle(XCAFDoc_ShapeTool) hShapeTool = XCAFDoc_DocumentTool::ShapeTool(hDoc->Main());

    gp_Circ aCirc(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), 100);
    BRepBuilderAPI_MakeWire wire;
    TopoDS_Edge aEdge = BRepBuilderAPI_MakeEdge(aCirc);
    wire.Add(aEdge);
    BRepBuilderAPI_MakeFace face(wire.Wire());

    TDF_Label aLabel = hShapeTool->NewShape();
    TDataStd_Name::Set(aLabel, "testModel");
    gp_Trsf aTrsf;
    for (int i = 0; i < 100; ++i) {
        aTrsf.SetTranslation(gp_Vec(0, 0 + i, 0));
        TopoDS_Shape theShape = BRepBuilderAPI_Transform(face.Face(), aTrsf).Shape();
        TDF_Label newLabel = hShapeTool->AddComponent(aLabel, theShape);
        //TDF_Label prototypeShape
        //hShapeTool->GetReferredShape();
        Quantity_Color theColr(i/255.0, 0.0, 0.0, Quantity_TOC_RGB);
        hColorTool->SetColor(newLabel, theColr, XCAFDoc_ColorSurf);
    }
    hShapeTool->UpdateAssemblies();

    STEPCAFControl_Writer aWriter;
    aWriter.SetColorMode(Standard_True);
    if (!aWriter.Perform(hDoc, "myColoredFace.stp", theProgress->Start()))
    {
        std::cerr << "Failed to transfer document" << std::endl;
        return 0;
    }


    return 0;
}
 

Quaoar

Administrator
Staff member
I guess you can find a workable example inside the data exchange package, like STEP Reader, for example. Also, in BOPAlgo_Builder class.
 
Top