Hide menu
Loading...
Searching...
No Matches
exploring/propertytable/main.cxx

Refer to the Property Table Example.

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger 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_String.hxx>
#include <cadex/LicenseManager_Activate.h>
#include <cadex/ModelData_Assembly.hxx>
#include <cadex/ModelData_Body.hxx>
#include <cadex/ModelData_BodyList.hxx>
#include <cadex/ModelData_BRepRepresentation.hxx>
#include <cadex/ModelData_Instance.hxx>
#include <cadex/ModelData_ModelReader.hxx>
#include <cadex/ModelData_Part.hxx>
#include <cadex/ModelData_PropertyTable.hxx>
#include <cadex/ModelData_Shape.hxx>
#include <iostream>
#include <vector>
#include "../../cadex_license.cxx"
using namespace std;
using namespace cadex;
// Print only I32 and double properties. Should be extended to print other supported properties (I64, float, etc)
class PropertyVisitor : public ModelData_PropertyTable::VoidVisitor
{
public:
PropertyVisitor()
{
cout << "\nProperty table: " << endl;
}
void operator() (PropertyNameConstReference theName, I32 theValue) override
{
OutputData (theName, theValue);
}
void operator() (PropertyNameConstReference theName, double theValue) override
{
OutputData (theName, theValue);
}
void operator() (PropertyNameConstReference theName, const Base_UTF16String& theValue) override
{
OutputData (theName, theValue);
}
protected:
template <typename T>
void OutputData (PropertyNameConstReference& theName, T theValue)
{
cout << theName << ": " << theValue << endl;
}
};
static void ExplorePropertyTable (const ModelData_PropertyTable& thePT)
{
// Traverse property table
PropertyVisitor aPropVisitor;
thePT.Accept (aPropVisitor);
}
class SubshapePropertiesVisitor : public ModelData_BRepRepresentation::SubshapeVisitor
{
public:
SubshapePropertiesVisitor (const ModelData_BRepRepresentation& theBRep) : myBRep (theBRep) {}
vector<ModelData_PropertyTable> PropertyTables()
{
return myPTVector;
}
protected:
void operator() (const ModelData_Shape& theShape) override
{
ModelData_PropertyTable aPT = myBRep.PropertyTable (theShape);
myPTVector.push_back (aPT);
}
private:
vector<ModelData_PropertyTable> myPTVector;
};
class PropertiesVisitor : public ModelData_Model::CombinedElementVisitor
{
protected:
void operator() (const ModelData_Part& thePart) override
{
ExplorePropertyTable (aPT);
if (aBRep) {
SubshapePropertiesVisitor aVisitor (aBRep);
aBRep.Accept (aVisitor);
// Extract all PropertyTables from SubShapes in B-Rep and explore it
vector<ModelData_PropertyTable> aPTVector = aVisitor.PropertyTables();
for (size_t i = 0; i < aPTVector.size(); ++i) {
ExplorePropertyTable (aPTVector[i]);
}
}
}
bool VisitEnter (const ModelData_SceneGraphElement& theElement) override
{
ModelData_PropertyTable aPT = theElement.Properties();
ExplorePropertyTable (aPT);
return true;
}
};
int main (int argc, char *argv[])
{
auto aKey = LicenseKey::Value();
// Activate the license (aKey must be defined in cadex_license.cxx)
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate CAD Exchanger 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 XML file to be read" << endl;
return 1;
}
const char* aSource = argv[1];
if (!ModelData_ModelReader().Read (aSource, aModel)) {
cerr << "Failed to read the file " << aSource << endl;
return 1;
}
PropertiesVisitor aVisitor;
aModel.Accept (aVisitor);
return 0;
}
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
Defines precise Boundary Representation of part.
Definition: ModelData_BRepRepresentation.hxx:39
void Accept(SubshapeVisitor &theVisitor) const
Applies the visitor to visit the subshapes.
Definition: ModelData_BRepRepresentation.cxx:993
Provides combined methods VisitEnter() and VisitLeave() to visit all elements.
Definition: ModelData_Model.hxx:123
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
void Accept(ElementVisitor &theVisitor) const
Accepts a visitor.
Definition: ModelData_Model.cxx:882
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:33
Defines a leaf node in the scene graph hiearchy.
Definition: ModelData_Part.hxx:35
ModelData_BRepRepresentation BRepRepresentation() const
Definition: ModelData_Part.cxx:360
Defines a collection of properties.
Definition: ModelData_PropertyTable.hxx:40
void Accept(Visitor &theVisitor) const
Accepts the visitor.
Definition: ModelData_PropertyTable.cxx:496
Base class for part, instance and assembly.
Definition: ModelData_SceneGraphElement.hxx:39
ModelData_PropertyTable Properties() const
Returns a property table.
Definition: ModelData_SceneGraphElement.cxx:338
Base class of topological shapes.
Definition: ModelData_Shape.hxx:37
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22
int I32
Defines a signed 32-bit integer.
Definition: Base_TypeDef.hxx:50