#include <cadex/Base/UTF16String.hxx>
#include <cadex/LicenseManager_Activate.h>
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/ModelReader.hxx>
#include <cadex/ModelData/ModelElementVisitor.hxx>
#include <cadex/ModelData/Assembly.hxx>
#include <cadex/ModelData/Instance.hxx>
#include <cadex/ModelData/Part.hxx>
#include <iostream>
#include <string>
#include <unordered_map>
#include "../../mtk_license.cxx"
using namespace std;
typedef unordered_map<const ModelData::ModelElement, size_t, BaseObjectHash> ElementMap;
string PrintElementType (const ModelData::ModelElement& theElement)
{
if (theElement.IsOfType<ModelData::Assembly> ()) {
return "Assembly";
} else if (theElement.IsOfType<ModelData::Instance>()) {
return "Instance";
} else if (theElement.IsOfType<ModelData::Part>()) {
return "Part";
}
return "Undefined";
}
class SceneGraphVisitor : public ModelData::ModelElementVisitor
{
public:
SceneGraphVisitor() : myNestingLevel (0)
{}
void PrintCounts()
{
cout << endl << "Total:" << endl << "name | type | count" << endl;
for (const auto& anElement : myElementMap) {
string aTypeStr = PrintElementType (anElement.first);
cout << anElement.first.Name() << " | " << aTypeStr << " | " << anElement.second << endl;
}
}
virtual bool VisitEnter (const ModelData::Assembly& theAssembly) override
{
PrintName (theAssembly);
UpdateTable (theAssembly);
++myNestingLevel;
return true;
}
virtual void VisitLeave (const ModelData::Assembly&) override
{
--myNestingLevel;
}
virtual bool VisitEnter (const ModelData::Instance& theInstance) override
{
PrintName (theInstance);
++myNestingLevel;
return true;
}
virtual void VisitLeave (const ModelData::Instance&) override
{
--myNestingLevel;
}
virtual void operator() (const ModelData::Part& thePart) override
{
PrintName (thePart);
UpdateTable (thePart);
}
private:
void PrintName (const ModelData::ModelElement& theElement)
{
for (size_t i = 0; i < myNestingLevel; ++i) {
cout << "--- ";
}
cout << PrintElementType (theElement);
if (!theElement.Name().IsEmpty()) {
cout << ": " << theElement.Name() << endl;
} else {
cout << ": <noname>" << endl;
}
}
void UpdateTable (const ModelData::ModelElement& theElement)
{
++myElementMap[theElement];
}
size_t myNestingLevel;
ElementMap myElementMap;
};
int main (int argc, char* argv[])
{
auto aKey = MTKLicenseKey::Value();
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate Manufacturing Toolkit license." << endl;
return 1;
}
if (argc != 2) {
cerr << "Usage: " << argv[0] << " <input_file>" << endl;
return 1;
}
const char* aSource = argv[1];
ModelData::Model aModel;
ModelData::ModelReader aReader;
if (!aReader.Read (aSource, aModel)) {
cerr << "Failed to read file: " << aSource << endl;
return 1;
}
SceneGraphVisitor aVisitor;
aModel.Accept (aVisitor);
aVisitor.PrintCounts();
return 0;
}
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.