Hide menu
Loading...
Searching...
No Matches
exploring/pmi/pmi.java

Refer to the PMI 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.
//
// ****************************************************************************
import cadex.*;
import cadex.ModelData.*;
import cadex.PMI.*;
import java.util.*;
public class pmi {
static {
try {
System.loadLibrary("CadExMTK");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String[] args) {
String aKey = MTKLicenseKey.Value();
// Activate the license (the key must be defined in MTKLicenseKey.java)
if (!LicenseManager.Activate(aKey)) {
System.out.println("Failed to activate Manufacturing Toolkit license.");
System.exit(1);
}
if (args.length != 1) {
System.out.println("Usage: " + " <input_file>, where:");
System.out.println(" <input_file> is a name of the file to be read");
System.exit(1);
}
String aSource = args[0];
Model aModel = new Model();
ModelReader aReader = new ModelReader();
ModelReaderParameters aParams = new ModelReaderParameters();
aParams.SetReadPMI(true);
aReader.SetParameters(aParams);
// Reading the file
if (!aReader.Read(new UTF16String(aSource), aModel)) {
System.out.println("Failed to read the file " + aSource);
System.exit(1);
}
System.out.format("Model: %s\n\n", aModel.Name());
// Create a PMI visitor
SceneGraphVisitor aVisitor = new SceneGraphVisitor();
aModel.Accept(aVisitor);
}
}
class TabulatedOutput {
public static void Println(Object theObject) {
PrintTabulation();
System.out.println(theObject);
}
public static void IncreaseIndent() {
++myNestingLevel;
}
public static void DecreaseIndent() {
--myNestingLevel;
}
private static void PrintTabulation() {
if (myNestingLevel <= 0) {
return;
}
// Emulate tabulation like tree.
for (int i = 0; i < myNestingLevel - 1; i++) {
if (i < 2 || i == 3) {
System.out.print("| ");
} else {
System.out.print(" ");
}
}
System.out.print("|__");
if (myNestingLevel > 3) {
System.out.print(" ");
}
}
private static int myNestingLevel = 0;
}
class SceneGraphVisitor extends ModelElementVisitor {
@Override
public void Apply(Part thePart) {
PrintName("Part", thePart.Name());
ExplorePMI(thePart);
}
@Override
public boolean VisitEnter(Instance theInstance) {
TabulatedOutput.IncreaseIndent();
PrintName("Instance", theInstance.Name());
ExplorePMI(theInstance);
return true;
}
@Override
public boolean VisitEnter(Assembly theAssembly) {
TabulatedOutput.IncreaseIndent();
PrintName("Assembly", theAssembly.Name());
ExplorePMI(theAssembly);
return true;
}
@Override
public void VisitLeave(Instance theInstance) {
TabulatedOutput.DecreaseIndent();
}
@Override
public void VisitLeave(Assembly theAssembly) {
TabulatedOutput.DecreaseIndent();
}
private void ExplorePMI(ModelElement theSGE) {
Data aPMIData = theSGE.PMI();
if (aPMIData != null) {
TabulatedOutput.Println("PMI Data:");
TabulatedOutput.IncreaseIndent();
if (aPMIData.NumberOfElements() == 0) {
return;
}
for (Element anElement : aPMIData.Elements()) {
TabulatedOutput.Println("PMI Element: " + anElement.Name());
TabulatedOutput.IncreaseIndent();
SemanticRepresentation aSemanticRepresentation = anElement.SemanticRepresentation();
if (aSemanticRepresentation != null && !aSemanticRepresentation.IsEmpty()) {
TabulatedOutput.Println("Semantic Representation:");
TabulatedOutput.IncreaseIndent();
PMISemanticVisitor aVisitor = new PMISemanticVisitor();
aSemanticRepresentation.Accept(aVisitor);
TabulatedOutput.DecreaseIndent();
}
GraphicalRepresentation aGraphicalRepresentation = anElement.GraphicalRepresentation();
if (aGraphicalRepresentation != null) {
TabulatedOutput.Println("Graphical Representation:");
TabulatedOutput.IncreaseIndent();
PMIGraphicalVisitor aVisitor = new PMIGraphicalVisitor();
aGraphicalRepresentation.Accept(aVisitor);
TabulatedOutput.DecreaseIndent();
}
TabulatedOutput.DecreaseIndent();
}
TabulatedOutput.DecreaseIndent();
}
}
private void PrintName(String theSGElement, UTF16String theName) {
if (!theName.IsEmpty()) {
TabulatedOutput.Println(theSGElement + ": " + theName);
} else {
TabulatedOutput.Println(theSGElement + ": <noname>");
}
}
}
class PMISemanticVisitor extends SemanticComponentVisitor {
@Override
public void Apply(DatumComponent theComponent) {
TabulatedOutput.Println("Datum");
TabulatedOutput.IncreaseIndent();
TabulatedOutput.Println("Label: " + theComponent.Label());
printAttributes(theComponent);
TabulatedOutput.DecreaseIndent();
}
@Override
public void Apply(DimensionComponent theComponent) {
TabulatedOutput.Println("Dimension");
TabulatedOutput.IncreaseIndent();
TabulatedOutput.Println("Nominal Value: " + theComponent.NominalValue());
TabulatedOutput.Println("Type of dimension: " + theComponent.TypeOfDimension());
printAttributes(theComponent);
TabulatedOutput.DecreaseIndent();
}
@Override
public void Apply(GeometricToleranceComponent theComponent) {
TabulatedOutput.Println("Geometric tolerance");
TabulatedOutput.IncreaseIndent();
TabulatedOutput.Println("Magnitude: " + theComponent.Magnitude());
TabulatedOutput.Println("Type of tolerance: " + theComponent.TypeOfTolerance());
TabulatedOutput.Println("Tolerance zone form: " + theComponent.ToleranceZoneForm());
printAttributes(theComponent);
TabulatedOutput.DecreaseIndent();
}
@Override
public void Apply(SurfaceFinishComponent theComponent) {
TabulatedOutput.Println("Surface Finish");
TabulatedOutput.IncreaseIndent();
TabulatedOutput.Println("Material removal: " + theComponent.MaterialRemoval());
TabulatedOutput.Println("Lay direction: " + theComponent.LayDirection());
TabulatedOutput.Println("All around flag: " + theComponent.IsAllAround());
TabulatedOutput.Println("Manufacturing method: " + theComponent.ManufacturingMethod());
printAttributes(theComponent);
TabulatedOutput.DecreaseIndent();
}
void printAttributes(SemanticComponent theComponent) {
if (theComponent.HasAttributes()) {
PMISemanticAttributeVisitor aVisitor = new PMISemanticAttributeVisitor();
theComponent.Accept(aVisitor);
}
}
}
class PMISemanticAttributeVisitor extends SemanticAttributeVisitor {
@Override
public void Apply(ModifierAttribute theAttribute) {
TabulatedOutput.Println("Modifier: " + theAttribute.Modifier());
}
@Override
public void Apply(ModifierWithValueAttribute theAttribute) {
TabulatedOutput.Println("ModifierWithValue: modifier=" + theAttribute.Modifier() + ", value=" + theAttribute.Value());
}
@Override
public void Apply(QualifierAttribute theAttribute) {
TabulatedOutput.Println("Qualifier: " + theAttribute.Qualifier());
}
@Override
public void Apply(PlusMinusBoundsAttribute theAttribute) {
TabulatedOutput.Println("PlusMinusBounds: (" + theAttribute.LowerBound() + ", " + theAttribute.UpperBound() + ")");
}
@Override
public void Apply(RangeAttribute theAttribute) {
TabulatedOutput.Println("Range: [" + theAttribute.LowerLimit() + ", " + theAttribute.UpperLimit() + "]");
}
@Override
public void Apply(LimitsAndFitsAttribute theAttribute) {
TabulatedOutput.Println("LimitsAndFits: value=" + theAttribute.Value() + ", type=" + theAttribute.Type());
}
@Override
public void Apply(DatumTargetAttribute theAttribute) {
TabulatedOutput.Println("DatumTarget: index=" + theAttribute.Index() + ", description=" + theAttribute.Description());
}
@Override
public void Apply(DatumRefAttribute theAttribute) {
TabulatedOutput.Println("DatumRef: precedence=" + theAttribute.Precedence() + ", targetLabel=" + theAttribute.TargetLabel());
}
@Override
public void Apply(DatumRefCompartmentAttribute theAttribute) {
TabulatedOutput.Println("DatumRefCompartment:");
TabulatedOutput.IncreaseIndent();
long aNumberOfReferences = theAttribute.NumberOfReferences();
if (aNumberOfReferences > 0) {
TabulatedOutput.Println("References:");
TabulatedOutput.IncreaseIndent();
for (long i = 0; i < aNumberOfReferences; i++) {
theAttribute.Reference(i).Accept(this);
}
TabulatedOutput.DecreaseIndent();
}
long aNumberOfModifierAttributes = theAttribute.NumberOfModifierAttributes();
if (aNumberOfModifierAttributes > 0) {
TabulatedOutput.Println("Modifiers:");
TabulatedOutput.IncreaseIndent();
for (long i = 0; i < aNumberOfModifierAttributes; i++) {
theAttribute.ModifierAttribute(i).Accept(this);
}
TabulatedOutput.DecreaseIndent();
}
TabulatedOutput.DecreaseIndent();
}
@Override
public void Apply(MaximumValueAttribute theAttribute) {
TabulatedOutput.Println("MaximumValue: " + theAttribute.MaxValue());
}
@Override
public void Apply(DisplacementAttribute theAttribute) {
TabulatedOutput.Println("Displacement: " + theAttribute.Displacement());
}
@Override
public void Apply(LengthUnitAttribute theAttribute) {
TabulatedOutput.Println("LengthUnit: " + theAttribute.Unit());
}
@Override
public void Apply(AngleUnitAttribute theAttribute) {
TabulatedOutput.Println("AngleUnit: " + theAttribute.Unit());
}
@Override
public void Apply(MachiningAllowanceAttribute theAttribute) {
TabulatedOutput.Println("Machining allowance");
TabulatedOutput.IncreaseIndent();
TabulatedOutput.Println("Value: " + theAttribute.Value());
TabulatedOutput.Println("Upper bound: " + theAttribute.UpperBound());
TabulatedOutput.Println("Lower bound: " + theAttribute.LowerBound());
TabulatedOutput.DecreaseIndent();
}
@Override
public void Apply(SurfaceTextureRequirementAttribute theAttribute) {
TabulatedOutput.Println("Surface texture requirement #" + theAttribute.Precedence());
TabulatedOutput.IncreaseIndent();
TabulatedOutput.Println("Specification limit: " + theAttribute.SpecificationLimit());
TabulatedOutput.Println("Filter name: " + theAttribute.FilterName());
TabulatedOutput.Println("Short wave filter: " + theAttribute.ShortWaveFilter());
TabulatedOutput.Println("Long wave filter: " + theAttribute.LongWaveFilter());
TabulatedOutput.Println("Surface parameter: " + theAttribute.SurfaceParameter());
TabulatedOutput.Println("Evaluation length: " + theAttribute.EvaluationLength());
TabulatedOutput.Println("Comparison rule: " + theAttribute.ComparisonRule());
TabulatedOutput.Println("Limit value: " + theAttribute.LimitValue());
TabulatedOutput.DecreaseIndent();
}
}
class PMIGraphicalVisitor extends GraphicalComponentVisitor {
@Override
public void Apply(OutlinedComponent theComponent) {
TabulatedOutput.Println("Outline");
TabulatedOutput.IncreaseIndent();
PMIOutlineVisitor aVisitor = new PMIOutlineVisitor();
theComponent.Outline().Accept(aVisitor);
TabulatedOutput.DecreaseIndent();
}
@Override
public void Apply(TextComponent theComponent) {
TabulatedOutput.Println("Text [" + theComponent.Text() + "]");
}
@Override
public void Apply(TriangulatedComponent theComponent) {
TabulatedOutput.Println("Triangulation [" + theComponent.TriangleSet().NumberOfTriangles() + " triangles]");
}
}
class PMIOutlineVisitor extends OutlineVisitor {
@Override
public void Apply(PolyOutline theOutline) {
TabulatedOutput.Println("PolyLine set [" + theOutline.LineSet().NumberOfPolylines() + " polylines]");
}
@Override
public void Apply(Poly2dOutline theOutline) {
TabulatedOutput.Println("PolyLine2d set [" + theOutline.LineSet().NumberOfPolylines() + " polylines]");
}
@Override
public void Apply(CurveOutline theOutline) {
TabulatedOutput.Println("Curve set [" + theOutline.NumberOfCurves() + " curves]");
}
@Override
public void Apply(Curve2dOutline theOutline) {
TabulatedOutput.Println("Curve2d set [" + theOutline.NumberOfCurves() + " curves]");
}
@Override
public boolean VisitEnter(CompositeOutline theOutline) {
TabulatedOutput.Println("Outline set:");
TabulatedOutput.IncreaseIndent();
return true;
}
@Override
public void VisitLeave(CompositeOutline theOutline) {
TabulatedOutput.DecreaseIndent();
}
}
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
Defines classes, types, enums, and functions related to PMI entities.
Defines classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition LicenseManager_LicenseError.hxx:30