Hide menu
exploring/pmi/main.cxx

Refer to the PMI Example.

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2022, 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.
//
// ****************************************************************************
#define __CADEX_PREVIEW_PMI 1
#include <cadex/Base_String.hxx>
#include <cadex/LicenseManager_Activate.h>
#include <cadex/ModelData_Assembly.hxx>
#include <cadex/ModelData_Instance.hxx>
#include <cadex/ModelData_IndexedTriangleSet.hxx>
#include <cadex/ModelData_ModelReader.hxx>
#include <cadex/ModelData_Part.hxx>
#include <cadex/ModelData_SceneGraphElement.hxx>
#include <cadex/ModelData_PMIData.hxx>
#include <cadex/ModelData_PMISemanticAttribute.hxx>
#include <cadex/ModelData_PMISemanticAttributeVisitor.hxx>
#include <cadex/ModelData_PMISemanticElement.hxx>
#include <cadex/ModelData_PMISemanticElementComponent.hxx>
#include <cadex/ModelData_PMISemanticElementComponentVisitor.hxx>
#include <cadex/ModelData_PMIGraphicalElement.hxx>
#include <cadex/ModelData_PMIGraphicalElementComponent.hxx>
#include <cadex/ModelData_PMIGraphicalElementComponentVisitor.hxx>
#include <cadex/ModelData_PMIOutline.hxx>
#include <cadex/ModelData_PMIOutlineVisitor.hxx>
#include <cadex/ModelData_PMITable.hxx>
#include <cadex/ModelData_PolyLineSet.hxx>
#include <cadex/ModelData_PolyLine2dSet.hxx>
#include <cadex/STEP_ReaderParameters.hxx>
#include <iostream>
#include "../../cadex_license.cxx"
using namespace std;
using namespace cadex;
class TabulatedOutput
{
public:
template<typename T>
std::ostream& operator << (const T& theObject)
{
PrintTabulation();
cout << theObject;
return cout;
}
void IncreaseIndent() { ++myNestingLevel; }
void DecreaseIndent() { --myNestingLevel; }
protected:
void PrintTabulation()
{
if (myNestingLevel <= 0) {
return;
}
// Emulate tabulation like tree.
for (int i = 0; i < myNestingLevel - 1; i++) {
if (i < 2 || i == 3) {
cout << "| ";
} else {
cout << " ";
}
}
cout << "|__";
if (myNestingLevel > 3) {
cout << " ";
}
}
int myNestingLevel = 0;
};
static TabulatedOutput theOutput;
class PMISemanticAttributeVisitor: public ModelData_PMISemanticAttributeVisitor
{
public:
void operator() (const ModelData_PMIModifierAttribute& theAttribute) override
{
theOutput << "Modifier: " << theAttribute.Modifier() << endl;
}
void operator() (const ModelData_PMIModifierWithValueAttribute& theAttribute) override
{
theOutput << "ModifierWithValue: modifier=" << theAttribute.Modifier() << ", value=" << theAttribute.Value() << endl;
}
void operator() (const ModelData_PMIQualifierAttribute& theAttribute) override
{
theOutput << "Qualifier: " << theAttribute.Qualifier() << endl;
}
void operator() (const ModelData_PMIPlusMinusBoundsAttribute& theAttribute) override
{
theOutput << "PlusMinusBounds: (" << theAttribute.LowerBound() << ", " << theAttribute.UpperBound() << ")" << endl;
}
void operator() (const ModelData_PMIRangeAttribute& theAttribute) override
{
theOutput << "Range: (" << theAttribute.LowerLimit() << ", " << theAttribute.UpperLimit() << ")" << endl;
}
void operator() (const ModelData_PMILimitsAndFitsAttribute& theAttribute) override
{
theOutput << "LimitsAndFits: value=" << theAttribute.Value() << ", type=" << theAttribute.Type() << endl;
}
void operator() (const ModelData_PMIDatumTargetAttribute& theAttribute) override
{
theOutput << "DatumTarget: index=" << theAttribute.Index() << ", description=" << theAttribute.Description() << endl;
}
void operator() (const ModelData_PMIDatumRefAttribute& theAttribute) override
{
theOutput << "DatumRef: precedence=" << theAttribute.Precedence() << ", targetLabel=" << theAttribute.TargetLabel() << endl;
}
void operator() (const ModelData_PMIDatumRefCompartmentAttribute& theAttribute) override
{
theOutput << "DatumRefCompartment:" << endl;
theOutput.IncreaseIndent();
const size_t aNumberOfReferences = theAttribute.NumberOfReferences();
if (aNumberOfReferences > 0) {
theOutput << "References:" << endl;
theOutput.IncreaseIndent();
for (size_t i = 0; i < aNumberOfReferences; i++) {
theAttribute.Reference (i).Accept (*this);
}
theOutput.DecreaseIndent();
}
const size_t aNumberOfModifierAttributes = theAttribute.NumberOfModifierAttributes();
if (aNumberOfModifierAttributes > 0) {
theOutput << "Modifiers:" << endl;
theOutput.IncreaseIndent();
for (size_t i = 0; i < aNumberOfModifierAttributes; i++) {
theAttribute.ModifierAttribute (i).Accept (*this);
}
theOutput.DecreaseIndent();
}
theOutput.DecreaseIndent();
}
void operator() (const ModelData_PMIMaximumValueAttribute& theAttribute) override
{
theOutput << "MaximumValue: " << theAttribute.MaxValue() << endl;
}
void operator() (const ModelData_PMIDisplacementAttribute& theAttribute) override
{
theOutput << "Displacement: " << theAttribute.Displacement() << endl;
}
void operator() (const ModelData_PMILengthUnitAttribute& theAttribute) override
{
theOutput << "LengthUnit: " << static_cast<int>(theAttribute.Unit()) << endl;
}
void operator() (const ModelData_PMIAngleUnitAttribute& theAttribute) override
{
theOutput << "AngleUnit: " << static_cast<int>(theAttribute.Unit()) << endl;
}
};
class PMISemanticVisitor : public ModelData_PMISemanticElementComponentVisitor
{
public:
void operator() (const ModelData_PMIDatumComponent &theComponent) override
{
theOutput << "Datum" << endl;
theOutput.IncreaseIndent();
theOutput << "Label: " << theComponent.Label() << endl;
printAttributes (theComponent);
theOutput.DecreaseIndent();
}
void operator() (const ModelData_PMIDimensionComponent &theComponent) override
{
theOutput << "Dimension" << endl;
theOutput.IncreaseIndent();
theOutput << "Nominal Value: " << theComponent.NominalValue() << endl;
theOutput << "Type of dimension: " << static_cast <int> (theComponent.TypeOfDimension()) << endl;
printAttributes (theComponent);
theOutput.DecreaseIndent();
}
void operator() (const ModelData_PMIGeometricToleranceComponent &theComponent) override
{
theOutput << "Geometric tolerance" << endl;
theOutput.IncreaseIndent();
theOutput << "Magnitude: " << theComponent.Magnitude() << endl;
theOutput << "Tolerance zone form: " << static_cast <int> (theComponent.ToleranceZoneForm()) << endl;
printAttributes(theComponent);
theOutput.DecreaseIndent();
}
void printAttributes (const ModelData_PMISemanticElementComponent& theComponent)
{
if (theComponent.HasAttributes()) {
PMISemanticAttributeVisitor aVisitor;
theComponent.Accept (aVisitor);
}
}
};
class PMIOutlineVisitor : public ModelData_PMIOutlineVisitor
{
public:
void operator() (const ModelData_PMIPolyOutline& theOutline) override
{
theOutput << "PolyLine set [" << theOutline.LineSet().NumberOfPolyLines() << " polylines]" << endl;
}
void operator() (const ModelData_PMIPoly2dOutline& theOutline) override
{
theOutput << "PolyLine2d set [" << theOutline.LineSet().NumberOfPolyLines() << " polylines]" << endl;
}
void operator() (const ModelData_PMICurveOutline& theOutline) override
{
theOutput << "Curve set [" << theOutline.NumberOfCurves() << " curves]" << endl;
}
void operator() (const ModelData_PMICurve2dOutline& theOutline) override
{
theOutput << "Curve2d set [" << theOutline.NumberOfCurves() << " curves]" << endl;
}
bool VisitEnter (const ModelData_PMICompositeOutline& /*theOutline*/) override
{
theOutput << "Outline set:" << endl;
theOutput.IncreaseIndent();
return true;
}
void VisitLeave (const ModelData_PMICompositeOutline& /*theOutline*/) override
{
theOutput.DecreaseIndent();
}
};
class PMIGraphicalVisitor : public ModelData_PMIGraphicalElementComponentVisitor
{
public:
void operator() (const ModelData_PMIOutlinedComponent& theComponent) override
{
theOutput << "Outline" << endl;
theOutput.IncreaseIndent();
PMIOutlineVisitor aVisitor;
theComponent.Outline().Accept (aVisitor);
theOutput.DecreaseIndent();
}
void operator() (const ModelData_PMITextComponent& theComponent) override
{
theOutput << "Text [" << theComponent.Text() << "]" << endl;
}
void operator() (const ModelData_PMITriangulatedComponent& theComponent) override
{
theOutput << "Triangulation [" << theComponent.TriangleSet().NumberOfFaces() << " triangles]" << endl;
}
};
class SceneGraphVisitor : public ModelData_Model::ElementVisitor
{
public:
void operator() (const ModelData_Part& thePart) override
{
PrintName ("Part", thePart.Name());
ExplorePMI (thePart);
}
bool VisitEnter (const ModelData_Instance& theInstance) override
{
theOutput.IncreaseIndent();
PrintName ("Instance", theInstance.Name());
ExplorePMI (theInstance);
return true;
}
bool VisitEnter (const ModelData_Assembly& theAssembly) override
{
theOutput.IncreaseIndent();
PrintName ("Assembly", theAssembly.Name());
ExplorePMI (theAssembly);
return true;
}
void VisitLeave (const ModelData_Instance& /*theInstance*/) override
{
theOutput.DecreaseIndent();
}
void VisitLeave (const ModelData_Assembly& /*theAssembly*/) override
{
theOutput.DecreaseIndent();
}
private:
void ExplorePMI (ModelData_SceneGraphElement theSGE)
{
ModelData_PMITable aPMITable = theSGE.PMI();
if (aPMITable) {
theOutput << "PMI Table:" << endl;
theOutput.IncreaseIndent();
while (aDataIt.HasNext()) {
ModelData_PMIData aData = aDataIt.Next();
theOutput << "PMI Data: " << aData.Name() << endl;
theOutput.IncreaseIndent();
ModelData_PMISemanticElement aSemanticElement = aData.SemanticElement();
if (aSemanticElement) {
theOutput << "Semantic element:" << endl;
theOutput.IncreaseIndent();
PMISemanticVisitor aVisitor;
aSemanticElement.Accept (aVisitor);
theOutput.DecreaseIndent();
}
ModelData_PMIGraphicalElement aGraphicalElement = aData.GraphicalElement();
if (aGraphicalElement) {
theOutput << "Graphical element:" << endl;
theOutput.IncreaseIndent();
PMIGraphicalVisitor aVisitor;
aGraphicalElement.Accept (aVisitor);
theOutput.DecreaseIndent();
}
theOutput.DecreaseIndent();
}
theOutput.DecreaseIndent();
}
}
void PrintName (string theSGElement, Base_UTF16String theName)
{
if (!theName.IsEmpty()) {
theOutput << theSGElement << ": " << theName << endl;
} else {
theOutput << theSGElement << ": <noname>" << endl;
}
}
};
int main (int argc, char *argv[])
{
auto aKey = LicenseKey::Value();
// Activate the license (aKey must be defined in cadex_license.cs)
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 STEP file to Read() model from" << endl;
return 1;
}
const char* aSource = argv[1];
aParams.ReadPMI() = true;
aReader.SetReaderParameters (aParams);
// Opening and converting the file
if (!aReader.Read (aSource, aModel)) {
cerr << "Failed to open and convert the file " << aSource << endl;
return 1;
}
// Create a PMI visitor
SceneGraphVisitor aVisitor;
aModel.Accept (aVisitor);
return 0;
}
Base_UTF16String Name() const
Definition: ModelData_BaseObject.cxx:210
Base class for part, instance and assembly.
Definition: ModelData_SceneGraphElement.hxx:36
Defines a component represented by text.
Definition: ModelData_PMIGraphicalElementComponent.hxx:80
Defines a compartment of datum references or compartments.
Definition: ModelData_PMISemanticAttribute.hxx:215
Defines a displacement value for an unequally disposed geometric tolerance.
Definition: ModelData_PMISemanticAttribute.hxx:251
Iterator over added PMIData items, which contains graphical and semantical elements.
Definition: ModelData_PMITable.hxx:80
ModelData_PMITable PMI() const
Returns a PMI table.
Definition: ModelData_SceneGraphElement.cxx:233
double LowerBound() const
Returns lower bound.
Definition: ModelData_PMISemanticAttribute.cxx:217
ModelData_PMIGraphicalElement GraphicalElement() const
Returns a graphical element.
Definition: ModelData_PMIData.cxx:97
Defines a component represented by triangulation.
Definition: ModelData_PMIGraphicalElementComponent.hxx:104
Defines a visitor of the outlines.
Definition: ModelData_PMIOutlineVisitor.hxx:33
size_t NumberOfCurves() const
Returns number of added curves.
Definition: ModelData_PMIOutline.cxx:248
Defines an angle unit.
Definition: ModelData_PMISemanticAttribute.hxx:283
Defines a visitor of the attributes.
Definition: ModelData_PMISemanticAttributeVisitor.hxx:41
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:33
IndexType NumberOfPolyLines() const
Returns a number of polylines.
Definition: ModelData_PolyLine2dSet.cxx:98
ModelData_PMISemanticElement SemanticElement() const
Returns a semantic element.
Definition: ModelData_PMIData.cxx:117
Defines a visitor of the components.
Definition: ModelData_PMISemanticElementComponentVisitor.hxx:31
Defines a type of modification with additional value.
Definition: ModelData_PMISemanticAttribute.hxx:87
Defines a collection of outlines.
Definition: ModelData_PMIOutline.hxx:129
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:40
Defines an outline consist of 2d polylines.
Definition: ModelData_PMIOutline.hxx:81
IndexType NumberOfPolyLines() const
Returns a number of polylines.
Definition: ModelData_PolyLineSet.cxx:89
double UpperBound() const
Returns upper bound.
Definition: ModelData_PMISemanticAttribute.cxx:205
Defines an outline consist of curves.
Definition: ModelData_PMIOutline.hxx:97
Defines a component represented by a datum, datum feature symbol or datum target.
Definition: ModelData_PMISemanticElementComponent.hxx:144
double Displacement() const
Returns displacement value.
Definition: ModelData_PMISemanticAttribute.cxx:501
void Accept(ModelData_PMIGraphicalElementComponentVisitor &theVisitor) const
Accepts the visitor.
Definition: ModelData_PMIGraphicalElement.cxx:160
DimensionType TypeOfDimension() const
Returns type of dimension.
Definition: ModelData_PMISemanticElementComponent.cxx:203
Defines a PMI semantic element.
Definition: ModelData_PMISemanticElement.hxx:37
double Magnitude() const
Returns a magnitude value of a tolerance.
Definition: ModelData_PMISemanticElementComponent.cxx:244
Defines a kind of a tolerance class dimension.
Definition: ModelData_PMISemanticAttribute.hxx:157
bool HasAttributes() const
Returns true if semantic attributes were added and false otherwise.
Definition: ModelData_PMISemanticElementComponent.cxx:87
double LowerLimit() const
Returns lower limit.
Definition: ModelData_PMISemanticAttribute.cxx:258
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:31
Defines a component represented by a geometric tolerance.
Definition: ModelData_PMISemanticElementComponent.hxx:111
Defines a container storing PMI data.
Definition: ModelData_PMITable.hxx:39
Defines an occurrence of assembly or part in a scene graph.
Definition: ModelData_Instance.hxx:32
void Accept(ModelData_PMISemanticElementComponentVisitor &theVisitor) const
Accepts the visitor.
Definition: ModelData_PMISemanticElement.cxx:123
Defines a component represented by a dimensional tolerance.
Definition: ModelData_PMISemanticElementComponent.hxx:73
bool Read(const Base_UTF16String &theFilePath, ModelData_Model &theModel)
Reads the file at the specified path into the specified model.
Definition: ModelData_ModelReader.cxx:120
size_t Precedence() const
Returns precedence value.
Definition: ModelData_PMISemanticAttribute.cxx:376
Defines range of value.
Definition: ModelData_PMISemanticAttribute.hxx:138
double NominalValue() const
Returns nominal value of a dimension.
Definition: ModelData_PMISemanticElementComponent.cxx:190
Defines a complete PMI element.
Definition: ModelData_PMIData.hxx:39
Defines a group of scene graph element.
Definition: ModelData_Assembly.hxx:32
Base class for various component types.
Definition: ModelData_PMISemanticElementComponent.hxx:41
bool ReadPMI() const
Specifies whether Product and Manufacturing Information (PMI) should be read from the file....
Definition: Base_ReaderParameters.cxx:140
const Base_UTF16String & Label() const
Returns a label of a datum.
Definition: ModelData_PMISemanticElementComponent.cxx:296
Defines an outline consist of 2d curves.
Definition: ModelData_PMIOutline.hxx:113
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22
void Accept(ElementVisitor &theVisitor) const
Accepts a visitor.
Definition: ModelData_Model.cxx:539
double UpperLimit() const
Returns upper limit.
Definition: ModelData_PMISemanticAttribute.cxx:246
double MaxValue() const
Returns maximum value.
Definition: ModelData_PMISemanticAttribute.cxx:472
Defines classes, types, and global functions related to standard C++ library.
void Accept(ModelData_PMISemanticAttributeVisitor &theVisitor) const
Accepts an attribute visitor.
Definition: ModelData_PMISemanticElementComponent.cxx:110
Defines a maximum value.
Definition: ModelData_PMISemanticAttribute.hxx:235
ToleranceZoneFormType ToleranceZoneForm() const
Returns tolerance zone form.
Definition: ModelData_PMISemanticElementComponent.cxx:258
Defines a component represented by outline.
Definition: ModelData_PMIGraphicalElementComponent.hxx:64
Defines a PMI graphical element.
Definition: ModelData_PMIGraphicalElement.hxx:39
Defines parameters of the STEP_Reader.
Definition: STEP_ReaderParameters.hxx:26
size_t NumberOfCurves() const
Returns number of added curves.
Definition: ModelData_PMIOutline.cxx:315
size_t Index() const
Returns index.
Definition: ModelData_PMISemanticAttribute.cxx:333
bool IsEmpty() const
Returns true if the string is empty.
Definition: Base_UTF16String.cxx:233
Defines a leaf node in the scene graph hiearchy.
Definition: ModelData_Part.hxx:34
void SetReaderParameters(const Base_ReaderParameters &theParameters)
Sets reader parameters.
Definition: ModelData_ModelReader.cxx:132
Defines a visitor of the scene graph elements.
Definition: ModelData_Model.hxx:95
Defines a datum target data.
Definition: ModelData_PMISemanticAttribute.hxx:177
Defines a length unit.
Definition: ModelData_PMISemanticAttribute.hxx:267
IndexType NumberOfFaces() const
Returns a number of faces (triangles).
Definition: ModelData_IndexedTriangleSet.cxx:179
Defines a type of qualifier.
Definition: ModelData_PMISemanticAttribute.hxx:103
Defines a visitor of the components.
Definition: ModelData_PMIGraphicalElementComponentVisitor.hxx:31
Defines a datum reference.
Definition: ModelData_PMISemanticAttribute.hxx:196
Defines an outline consist of polylines.
Definition: ModelData_PMIOutline.hxx:65
Defines a type of modification.
Definition: ModelData_PMISemanticAttribute.hxx:71
Defines a plus and minus bounds (deviations) of a tolerance.
Definition: ModelData_PMISemanticAttribute.hxx:119