Hide menu
Loading...
Searching...
No Matches
utilities/progress_bar/main.cxx

Refer to the Progress Bar Example.

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2025, CADEX. All rights reserved.
//
// This file is part of the Manufacturing Toolkit software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
#include <cadex/Base/ProgressScope.hxx>
#include <cadex/Base/ProgressStatus.hxx>
#include <cadex/LicenseManager_Activate.h>
#include <cadex/ModelAlgo/MeshGenerator.hxx>
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/ModelReader.hxx>
#include <iostream>
#include "../../mtk_license.cxx"
using namespace std;
using namespace cadex;
class ProgressBarObserver : public ProgressStatus::Observer
{
public:
void ChangedValue (const ProgressStatus& theInfo) override
{
cout << theInfo.Value() << "%" << endl;
}
void Completed (const ProgressStatus& theInfo) override
{
cout << theInfo.Value() << "%: complete!" << endl;
}
};
int main (int argc, char* argv[])
{
auto aKey = MTKLicenseKey::Value();
// Activate the license (aKey must be defined in mtk_license.cxx)
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate Manufacturing Toolkit license." << endl;
return 1;
}
// Get the input
if (argc != 2) {
cerr << "Usage: " << argv[0] << " <input_file>, where:" << endl;
cerr << " <input_file> is a name of the file to be read" << endl;
return 1;
}
const char* aSource = argv[1];
// Create observer
// An observer must have a greater life span than aStatus
// so create it in explicit external scope for aStatus
ProgressBarObserver anObserver;
anObserver.SetAllNotifyingThreads();
ProgressStatus aStatus;
aStatus.Register (anObserver); // Register an Observer to progress status
ProgressScope aTopScope (aStatus); // The top scope occupies the whole progress status range
{
ProgressScope aReaderScope (aTopScope, 50); // The remaining 50% of TopScope for reading
aReader.SetProgressStatus (aStatus);
aReader.Read (aSource, aModel);
}
if (!aModel.IsEmpty()) {
ProgressScope aMesherScope (aTopScope, 50); // The remaining 50% of TopScope for meshing
aMesher.SetProgressStatus (aStatus); // Connect progress status object
aMesher.Generate (aModel);
}
return 0;
}
Generates a polygonal mesh for a B-Rep body.
Definition MeshGenerator.hxx:39
Provides MTK data model.
Definition Model.hxx:40
bool IsEmpty() const
Returns true if the model is empty.
Definition Model.cxx:173
Reads STEP and native format.
Definition ModelReader.hxx:33
bool Read(const UTF16String &theFilePath, ModelData::Model &theModel)
Reads the file at the specified path into the specified model.
Definition ModelReader.cxx:276
Represents a node in a hierarchy of progress scopes.
Definition ProgressScope.hxx:35
Base abstract class for observers registered in ProgressStatus.
Definition ProgressStatus.hxx:35
Provides progress status and notification mechanism.
Definition ProgressStatus.hxx:32
double Value() const
Returns a current value.
Definition ProgressStatus.cxx:237
void Register(Observer &theObserver, double theValueThreshold=0.1f, unsigned int theTimeThreshold=20U)
Adds an observer that will be notified when the progress status has changed.
Definition ProgressStatus.cxx:257
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition LicenseManager_LicenseError.hxx:30