using System;
using System.Collections.Generic;
namespace bom
{
class Program
{
static int Main(string[] args)
{
string aKey = MTKLicenseKey.Value();
if (!LicenseManager.Activate(aKey))
{
Console.WriteLine("Failed to activate Manufacturing Toolkit license.");
return 1;
}
if (args.Length != 1)
{
Console.WriteLine("Usage: " +
$"{System.Reflection.Assembly.GetExecutingAssembly().Location} <input_file>, where:");
Console.WriteLine($" <input_file> is a name of the file to be read");
Console.WriteLine($"");
return 1;
}
string aSource = args[0];
{
Console.WriteLine("Failed to read the file " + aSource);
return 1;
}
SceneGraphVisitor aCounter = new SceneGraphVisitor();
aCounter.PrintCounts();
return 0;
}
}
{
public SceneGraphVisitor()
{
myNestingLevel = 0;
margin = 0;
}
public void PrintCounts()
{
Console.WriteLine("Total:");
Console.WriteLine("\t{0,8:c}", "name".PadRight(margin, ' ') + " | " + "type".PadRight(margin, ' ') + " | count");
foreach (KeyValuePair<ModelElement, int> i in mySGEMap)
{
Console.WriteLine("\t{0,8:c}", i.Key.Name().ToString().PadRight(margin, ' ') + " | " + PrintSGEType(i.Key).PadRight(margin, ' ') + " | " + i.Value);
}
}
public override void Apply(
Part thePart)
{
PrintName(
"Part", thePart.
Name());
UpdateTable(thePart);
}
public override bool VisitEnter(
Assembly theAssembly)
{
PrintName(
"Assembly", theAssembly.
Name());
UpdateTable(theAssembly);
++myNestingLevel;
return true;
}
public override bool VisitEnter(
Instance theInstance)
{
PrintName(
"Instance", theInstance.
Name());
++myNestingLevel;
return true;
}
public override void VisitLeave(
Assembly theAssembly)
{
--myNestingLevel;
}
public override void VisitLeave(
Instance theInstance)
{
--myNestingLevel;
}
private void PrintName(
string theModelElement,
UTF16String theName)
{
for (int i = 0; i < myNestingLevel; ++i)
{
Console.Write("--- ");
}
{
Console.WriteLine(theModelElement + ": " + theName);
}
else
{
Console.WriteLine(theModelElement + ": <noname>");
}
margin = Math.Max(margin, (
int)theName.
Length());
}
{
if (!mySGEMap.ContainsKey(theModelElement))
{
mySGEMap.Add(theModelElement, 1);
}
else
{
++mySGEMap[theModelElement];
}
}
{
if (
Part.
CompareType(theElement))
{
return "Part";
}
{
return "Assembly";
}
{
return "Instance";
}
return "Undefined";
}
private int margin;
private Dictionary<ModelElement, int> mySGEMap = new Dictionary<ModelElement, int>();
private int myNestingLevel;
}
}
Defines a group of model element.
Definition Assembly.hxx:33
static bool CompareType(const BaseObject &theObject)
Returns true if theObject is an assembly.
Definition Assembly.cxx:170
Defines an occurrence of assembly or part in a scene graph.
Definition Instance.hxx:31
static bool CompareType(const BaseObject &theObject)
Returns true if theObject is an instance.
Definition Instance.cxx:165
Base class for part, instance and assembly.
Definition ModelElement.hxx:38
UTF16String Name() const
Returns a name.
Definition ModelElement.cxx:55
Defines a visitor of the scene graph elements.
Definition ModelElementVisitor.hxx:53
Provides MTK data model.
Definition Model.hxx:40
void Accept(ModelElementVisitor &theVisitor) const
Accepts a visitor.
Definition Model.cxx:274
Reads supported formats, see Import section.
Definition ModelReader.hxx:33
Defines a leaf node in the scene graph hiearchy.
Definition Part.hxx:34
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition UTF16String.hxx:30
bool IsEmpty() const
Returns true if the string is empty.
Definition UTF16String.cxx:336
size_t Length() const
Returns a string length in UTF16 characters.
Definition UTF16String.cxx:331
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition LicenseManager_LicenseError.hxx:30