using System;
using System.Collections.Generic;
namespace feature_group
{
class FeatureComparer : IComparer<MTKBase_Feature>
{
{
bool anALessThanB = aComparator.Apply(theA, theB);
if (anALessThanB)
{
return -1;
}
bool aBLessThanA = aComparator.Apply(theB, theA);
if (aBLessThanA)
{
return 1;
}
return 0;
}
}
public struct Pair
{
public Pair(double theFirst, double theSecond)
{
First = theFirst;
Second = theSecond;
}
public double First { get; }
public double Second { get; }
public override string ToString() => $"{First} x {Second}";
}
public struct Dimension
{
public Dimension(double theL, double theW, double theD)
{
L = theL;
W = theW;
D = theD;
}
public double L { get; }
public double W { get; }
public double D { get; }
public override string ToString() => $"{L} x {W} x {D}";
}
public struct Direction
{
public Direction(double theX, double theY, double theZ)
{
X = theX;
Y = theY;
Z = theZ;
}
public double X { get; }
public double Y { get; }
public double Z { get; }
public override string ToString() => $"({FormattedString(X)}, {FormattedString(Y)}, {FormattedString(Z)})";
private string FormattedString(double theValue)
{
System.Globalization.CultureInfo aCI = new System.Globalization.CultureInfo("en-US");
return string.Format(aCI, "{0:0.00}", theValue);
}
}
class FeatureGroupManager
{
public FeatureGroupManager()
{
myGroups = new List<FeatureGroup>();
}
private class FeatureGroup
{
public FeatureGroup(string theName, string theSubgroupName, bool theHasParameters)
{
myName = theName;
mySubgroupName = theSubgroupName;
myHasParameters = theHasParameters;
myFeatureSubgroups = new FeatureMapType(new FeatureComparer());
}
public uint FeatureCount()
{
uint aCount = 0;
foreach (var i in myFeatureSubgroups)
{
aCount += i.Value;
}
return aCount;
}
public string myName;
public string mySubgroupName;
public bool myHasParameters;
public FeatureMapType myFeatureSubgroups;
}
private class FeatureGroupComparer : IComparer<FeatureGroup>
{
public int Compare(FeatureGroup theA, FeatureGroup theB)
{
string anAName = theA.myName;
string aBName = theB.myName;
if (anAName == aBName)
{
return 0;
}
FeatureMapType anAFeatureSubgroups = theA.myFeatureSubgroups;
FeatureMapType aBFeatureSubgroups = theB.myFeatureSubgroups;
if (anAFeatureSubgroups.Count == 0 || aBFeatureSubgroups.Count == 0)
{
return anAName.CompareTo(aBName);
}
foreach (var i in anAFeatureSubgroups)
{
anAFeature = i.Key;
break;
}
foreach (var i in aBFeatureSubgroups)
{
aBFeature = i.Key;
break;
}
FeatureComparer aFeatureComparator = new FeatureComparer();
return aFeatureComparator.Compare(anAFeature, aBFeature);
}
}
private List<FeatureGroup> myGroups;
public void AddFeature(
string theGroupName,
string theSubgroupName,
bool theHasParameters,
MTKBase_Feature theFeature)
{
int aRes = myGroups.FindIndex(theGroup => theGroup.myName == theGroupName);
if (aRes == -1)
{
myGroups.Add(new FeatureGroup(theGroupName, theSubgroupName, theHasParameters));
aRes = myGroups.Count - 1;
}
FeatureGroup aGroup = myGroups[aRes];
FeatureMapType aSubgroups = aGroup.myFeatureSubgroups;
if (aSubgroups.ContainsKey(theFeature))
{
++aSubgroups[theFeature];
}
else
{
aSubgroups[theFeature] = 1;
}
}
public void Print(string theFeatureType, Action<MTKBase_Feature> thePrintFeatureParameters)
{
myGroups.Sort(new FeatureGroupComparer());
uint aTotalCount = 0;
foreach (var i in myGroups)
{
uint aFeatureCount = i.FeatureCount();
aTotalCount += aFeatureCount;
Console.WriteLine($" {i.myName}: {aFeatureCount}");
if (!i.myHasParameters)
{
continue;
}
string aSubgroupName = i.mySubgroupName;
foreach (var j in i.myFeatureSubgroups)
{
Console.WriteLine($" {j.Value} {aSubgroupName} with");
thePrintFeatureParameters(j.Key);
}
}
Console.WriteLine($"\n Total {theFeatureType}: {aTotalCount}\n");
}
public static void PrintFeatureParameter<T>(string theName, T theValue, string theUnits)
{
Console.WriteLine($" {theName}: {theValue} {theUnits}");
}
}
}
Provides possibility to compare MTK based features depending on their type and parameters.
Definition MTKBase_FeatureComparator.hxx:29
Describes a base class of MTK based features.
Definition MTKBase_Feature.hxx:33
Defines classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition LicenseManager_LicenseError.hxx:30
using System;
namespace shape_processor
{
{
public override void Apply(
Part thePart)
{
var aBodyVec = thePart.
Bodies();
if (aBodyVec.Count != 0)
{
for (int i = 0; i < aBodyVec.Count; ++i)
{
Body aBody = aBodyVec[i];
while (aShapeIt.HasNext())
{
var aShape = aShapeIt.Next();
{
Console.Write($"Part #{myPartIndex} [\"{aPartName}\"] - solid #{i} has:\n");
ProcessSolid(
Solid.
Cast(aShape));
}
{
Console.Write($"Part #{myPartIndex} [\"{aPartName}\"] - shell #{i} has:\n");
ProcessShell(
Shell.
Cast(aShape));
}
}
++myPartIndex;
}
}
}
public abstract void ProcessSolid(
Solid theSolid);
public abstract void ProcessShell(
Shell theShell);
private uint myPartIndex = 0;
}
{
public override void Apply(
Part thePart)
{
var aBodyVec = thePart.Bodies();
if (aBodyVec.Count != 0)
{
for (int i = 0; i < aBodyVec.Count; ++i)
{
Body aBody = aBodyVec[i];
while (aShapeIt.HasNext())
{
var aShape = aShapeIt.Next();
{
Console.Write ($"Part #{myPartIndex} [\"{aPartName}\"] - solid #{i} has:\n");
ProcessSolid(
Solid.Cast(aShape));
}
}
++myPartIndex;
}
}
}
public abstract void ProcessSolid(
Solid theSolid);
private uint myPartIndex = 0;
}
}
UTF16String Name() const
Returns a name.
Definition ModelElement.cxx:55
Element visitor with empty implementation.
Definition ModelElementVisitor.hxx:64
Defines a leaf node in the scene graph hiearchy.
Definition Part.hxx:34
Iterates over subshapes in a shape.
Definition ShapeIterator.hxx:32
Defines a connected set of faces.
Definition Shell.hxx:32
Defines a topological solid.
Definition Solid.hxx:32
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:337
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
ShapeType
Defines shape type.
Definition ShapeType.hxx:27
using feature_group;
using shape_processor;
using System;
namespace feature_recognizer
{
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");
return 1;
}
string aSource = args[0];
var aModel =
new Model();
{
Console.WriteLine($"Failed to read the file {aSource}");
return 1;
}
Console.WriteLine($"Model: {aModel.Name()}\n");
var aPartProcessor = new PartProcessor();
aModel.Accept(aVisitor);
return 0;
}
class PartProcessor : ShapeProcessor
{
public PartProcessor()
{
}
public override void ProcessSolid(
Solid theSolid)
{
var aFeatureList = myRecognizer.Perform(theSolid);
PrintFeatures(aFeatureList);
}
public override void ProcessShell(
Shell theShell)
{
var aFeatureList = myRecognizer.Perform(theShell);
PrintFeatures(aFeatureList);
}
}
{
FeatureGroupManager aManager = new FeatureGroupManager();
Action<MTKBase_FeatureList> GroupByParameters = null;
GroupByParameters = new Action<MTKBase_FeatureList>((theFeatures) =>
{
for (uint i = 0; i < theFeatures.Size(); ++i)
{
{
aManager.AddFeature("Bead(s)", "Bead(s)", true, aFeature);
}
{
aManager.AddFeature("Cutout(s)", "Cutout(s)", true, aFeature);
}
{
aManager.AddFeature("Louver(s)", "", true, aFeature);
}
{
aManager.AddFeature("Bridge(s)", "Bridge(s)", true, aFeature);
}
{
SheetMetal_Hole aHole = SheetMetal_Hole.Cast(aFeature);
aManager.AddFeature(HoleName(aHole), "Hole(s)", true, aFeature);
}
{
SheetMetal_Bend aBend = SheetMetal_Bend.Cast(aFeature);
aManager.AddFeature(BendName(aBend), "Bend(s)", true, aFeature);
}
{
SheetMetal_Notch aNotch = SheetMetal_Notch.Cast(aFeature);
aManager.AddFeature(NotchName (aNotch), "Notch(es)", true, aFeature);
}
{
aManager.AddFeature("Tab(s)", "Tab(s)", true, aFeature);
}
{
SheetMetal_CompoundBend aCompoundBend = SheetMetal_CompoundBend.Cast(aFeature);
GroupByParameters(aCompoundBend.FeatureList());
}
}
});
GroupByParameters(theFeatureList);
Action<MTKBase_Feature> PrintFeatureParameters = theFeature =>
{
{
FeatureGroupManager.PrintFeatureParameter(
"depth", aBead.
Depth(),
"mm");
}
{
FeatureGroupManager.PrintFeatureParameter(
"perimeter", aCutout.
Perimeter(),
"mm");
}
{
FeatureGroupManager.PrintFeatureParameter(
"depth", aLouver.
Depth(),
"mm");
}
{
FeatureGroupManager.PrintFeatureParameter(
"length", aBridge.
Length(),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"depth", aBridge.
Depth(),
"mm");
}
{
feature_group.Direction aDir =
new feature_group.
Direction(anAxis.
X(), anAxis.
Y(), anAxis.
Z());
FeatureGroupManager.PrintFeatureParameter(
"radius", aHole.
Radius(),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"depth", aHole.
Depth(),
"mm");
FeatureGroupManager.PrintFeatureParameter("axis", aDir, "");
}
{
FeatureGroupManager.PrintFeatureParameter(
"radius", aBend.
Radius(),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"angle", ToDegrees(aBend.
Angle()),
"deg");
FeatureGroupManager.PrintFeatureParameter(
"length", aBend.
Length(),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"width", aBend.
Width(),
"mm");
}
{
FeatureGroupManager.PrintFeatureParameter(
"length", aNotch.
Length(),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"width", aNotch.
Width(),
"mm");
{
FeatureGroupManager.PrintFeatureParameter (
"corner fillet radius", aStraightNotch.
CornerFilletRadius(),
"mm");
}
{
FeatureGroupManager.PrintFeatureParameter (
"angle", ToDegrees(aVNotch.
Angle()),
"deg");
}
}
{
FeatureGroupManager.PrintFeatureParameter(
"length", aTab.
Length(),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"width", aTab.
Width(),
"mm");
}
};
aManager.Print("features", PrintFeatureParameters);
}
{
switch (theType) {
default:
break;
}
return "Hem Bend(s)";
}
{
{
return HemTypeToString(aHemBend.
Type());
}
{
return "Curved Bend(s)";
}
return "Bend(s)";
}
{
{
return "Complex Hole(s)";
}
return "Hole(s)";
}
{
{
return "Straight Notch(es)";
}
{
return "V Notch(es)";
}
return "Notch(es)";
}
static double ToDegrees(double theAngleRad)
{
return theAngleRad * 180 / Math.PI;
}
}
}
const Direction & Axis() const
Returns a Z-direction of the axis.
Definition Axis3d.cxx:110
Defines a 3D Direction.
Definition Direction.hxx:34
Direction()
Constructor.
Definition Direction.cxx:38
Defines a list of features.
Definition MTKBase_FeatureList.hxx:36
const Geom::Axis3d & Axis() const
Definition MTKBase_Hole.cxx:128
double Depth() const
Definition MTKBase_Hole.cxx:99
double Radius() const
Definition MTKBase_Hole.cxx:79
Defines a visitor that visits each unique element only once.
Definition ModelElementVisitor.hxx:87
Provides MTK data model.
Definition Model.hxx:40
Reads STEP and native format.
Definition ModelReader.hxx:29
SheetMetal_HemBendType
Defines a hem bend type in sheet metal.
Definition SheetMetal_HemBendType.hxx:28