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();
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);
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());
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;
}
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();
for (Element anElement : aPMIData.Elements()) {
TabulatedOutput.Println("PMI Element: " + anElement.Name());
TabulatedOutput.IncreaseIndent();
SemanticRepresentation aSemanticRepresentation = anElement.SemanticRepresentation();
if (aSemanticRepresentation != null) {
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...
Definition AngleUnit.cs:12
Contains classes, types, enums, and functions related to PMI entities.
Definition AngleUnitAttribute.cs:12
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition BaseObject.cs:12