#include <cadex/LicenseManager_Activate.h>
#include <cadex/ModelData_Appearance.hxx>
#include <cadex/ModelData_BRepRepresentation.hxx>
#include <cadex/ModelData_Model.hxx>
#include <cadex/ModelData_Part.hxx>
#include <cadex/ModelData_PolyRepresentation.hxx>
#include <cadex/ModelData_PolyShape.hxx>
#include <cadex/ModelData_PolyShapeList.hxx>
#include <cadex/ModelData_PolyVertexSet.hxx>
#include <cadex/ModelData_SceneGraphElement.hxx>
#include <iostream>
#include <unordered_set>
#include "../../cadex_license.cxx"
typedef unordered_set<ModelData_Appearance, ModelData_AppearanceHash> AppSetType;
class SubshapeAppearancesCollector : public ModelData_BRepRepresentation::SubshapeVisitor
{
public:
myBRep (theBRep), myAppSet (theAppSet) {}
protected:
{
ExploreShapeAppearances (theShape);
}
private:
{
if (anApp) {
myAppSet.insert (anApp);
}
}
AppSetType& myAppSet;
};
class RepVisitor : public ModelData_Part::RepresentationVisitor
{
public:
RepVisitor (AppSetType& theAppSet) : myAppSet (theAppSet) {}
protected:
{
SubshapeAppearancesCollector aCollector (theBRep, myAppSet);
}
{
ExplorePVSAppearances (thePolyRep);
}
private:
{
const ModelData_PolyShapeList& aList = thePolyRep.
Get();
for (ModelData_PolyShapeList::SizeType i = 0; i < aList.Size(); ++i) {
if (anApp) {
myAppSet.insert (anApp);
}
}
}
AppSetType& myAppSet;
};
{
public:
SGEAppearancesCollector (AppSetType& theAppset) : myAppSet (theAppset) {}
protected:
{
ExploreSGEAppearance (thePart);
RepVisitor aVisitor (myAppSet);
}
{
ExploreSGEAppearance (theElement);
return true;
}
private:
{
if (anApp) {
myAppSet.insert (anApp);
}
}
AppSetType& myAppSet;
};
class AppearancesCollector
{
public:
{
SGEAppearancesCollector aCollector (myAppSet);
}
void PrintAppearancesCount()
{
cout << "Total Model Unique Appearances Count: " << myAppSet.size() << endl;
}
private:
AppSetType myAppSet;
};
int main (int argc, char *argv[])
{
auto aKey = LicenseKey::Value();
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate CAD Exchanger license." << endl;
return 1;
}
if (argc != 2) {
cerr << "Usage: " << argv[0] << " <input_file>, where:" << endl;
cerr << " <input_file> is a name of the XML file to be read" << endl;
return 1;
}
const char* aSource = argv[1];
if (!aModel.
Open (aSource)) {
cerr << "Failed to read the file " << aSource << endl;
return 1;
}
AppearancesCollector aCollector (aModel);
aCollector.PrintAppearancesCount();
return 0;
}