using System;
using System.Collections.Generic;
using FeatureMapType = System.Collections.Generic.SortedDictionary<
cadex.MTKBase_Feature, uint>;
namespace feature_group
{
class FeatureComparer : IComparer<MTKBase_Feature>
{
public int Compare(MTKBase_Feature theA, MTKBase_Feature theB)
{
MTKBase_FeatureComparator aComparator = new MTKBase_FeatureComparator();
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);
}
MTKBase_Feature anAFeature = new MTKBase_Feature();
MTKBase_Feature aBFeature = new MTKBase_Feature();
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}");
}
}
}
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
using feature_group;
using shape_processor;
using System;
namespace dfm_analyzer
{
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();
var aReader = new ModelReader();
if (!aReader.Read(new UTF16String(aSource), aModel))
{
Console.WriteLine($"Failed to read the file {aSource}");
return 1;
}
Console.WriteLine($"Model: {aModel.Name()}\n");
var aPartProcessor = new PartProcessor();
var aVisitor = new ModelElementUniqueVisitor(aPartProcessor);
aModel.Accept(aVisitor);
return 0;
}
class PartProcessor : ShapeProcessor
{
public PartProcessor()
{
myAnalyzer = new DFMSheetMetal_Analyzer();
}
public override void ProcessSolid(Solid theSolid)
{
var anIssueList = myAnalyzer.Perform(theSolid);
PrintIssues(anIssueList);
}
public override void ProcessShell(Shell theShell)
{
var anIssueList = myAnalyzer.Perform(theShell);
PrintIssues(anIssueList);
}
private DFMSheetMetal_Analyzer myAnalyzer;
}
static void PrintIssues(MTKBase_FeatureList theIssueList)
{
FeatureGroupManager aManager = new FeatureGroupManager();
for (uint i = 0; i < theIssueList.Size(); ++i)
{
MTKBase_Feature anIssue = theIssueList.Feature(i);
if (DFMSheetMetal_SmallRadiusBendIssue.CompareType(anIssue))
{
aManager.AddFeature("Small Radius Bend Issue(s)", "Bend(s)", true, anIssue);
}
else if (DFMSheetMetal_SmallDiameterHoleIssue.CompareType(anIssue))
{
aManager.AddFeature("Small Diameter Hole Issue(s)", "Hole(s)", true, anIssue);
}
else if (DFMSheetMetal_FlatPatternInterferenceIssue.CompareType(anIssue))
{
aManager.AddFeature("Flat Pattern Interference Issue(s)", "", false, anIssue);
}
else if (DFMSheetMetal_IrregularCornerFilletRadiusNotchIssue.CompareType(anIssue))
{
aManager.AddFeature("Irregular Corner Fillet Radius Notch Issue(s)", "Notch(es)", true, anIssue);
}
else if (DFMSheetMetal_IrregularDepthExtrudedHoleIssue.CompareType(anIssue))
{
aManager.AddFeature("Irregular Depth Extruded Hole Issue(s)", "Hole(s)", true, anIssue);
}
else if (DFMSheetMetal_IrregularRadiusOpenHemBendIssue.CompareType(anIssue))
{
aManager.AddFeature("Irregular Radius Open Hem Bend Issue(s)", "Bend(s)", true, anIssue);
}
else if (DFMSheetMetal_IrregularSizeBendReliefIssue.CompareType(anIssue))
{
aManager.AddFeature("Irregular Size Bend Relief Issue(s)", "Bend(s)", true, anIssue);
}
else if (DFMSheetMetal_LargeDepthBeadIssue.CompareType(anIssue))
{
aManager.AddFeature("Large Depth Bead Issue(s)", "Bead(s)", true, anIssue);
}
else if (DFMSheetMetal_SmallDepthLouverIssue.CompareType(anIssue))
{
aManager.AddFeature("Small Depth Louver Issue(s)", "Louver(s)", true, anIssue);
}
else if (DFMSheetMetal_InconsistentRadiusBendIssue.CompareType(anIssue))
{
aManager.AddFeature("Inconsistent Radius Bend Issue(s)", "Bend(s)", true, anIssue);
}
else if (DFMSheetMetal_SmallLengthFlangeIssue.CompareType(anIssue))
{
aManager.AddFeature("Small Length Flange Issue(s)", "Flange(s)", true, anIssue);
}
else if (DFMSheetMetal_SmallLengthHemBendFlangeIssue.CompareType(anIssue))
{
aManager.AddFeature("Small Length Hem Bend Flange Issue(s)", "Flange(s)", true, anIssue);
}
else if (DFMSheetMetal_IrregularSizeNotchIssue.CompareType(anIssue))
{
aManager.AddFeature("Irregular Size Notch Issue(s)", "Notch(s)", true, anIssue);
}
else if (DFMSheetMetal_IrregularSizeTabIssue.CompareType(anIssue))
{
aManager.AddFeature("Irregular Size Tab Issue(s)", "Tab(s)", true, anIssue);
}
else if (DFMSheetMetal_SmallDistanceBetweenFeaturesIssue.CompareType(anIssue))
{
DFMSheetMetal_SmallDistanceBetweenFeaturesIssue aSDBFIssue = DFMSheetMetal_SmallDistanceBetweenFeaturesIssue.Cast(anIssue);
aManager.AddFeature(SmallDistanceIssueName(aSDBFIssue), "Distance(s)", true, anIssue);
}
else if (DFMSheetMetal_NonStandardSheetThicknessIssue.CompareType(anIssue))
{
aManager.AddFeature("Non Standard Sheet Thickness Issue(s)", "Sheet Thickness(s)", true, anIssue);
}
else if (DFMSheetMetal_NonStandardSheetSizeIssue.CompareType(anIssue))
{
aManager.AddFeature("Non Standard Sheet Size Issue(s)", "Sheet Size(s)", true, anIssue);
}
}
Action<MTKBase_Feature> PrintFeatureParameters = theIssue =>
{
if (DFMSheetMetal_SmallRadiusBendIssue.CompareType(theIssue))
{
DFMSheetMetal_SmallRadiusBendIssue aSRBIssue = DFMSheetMetal_SmallRadiusBendIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter("expected min radius", aSRBIssue.ExpectedMinRadius(), "mm");
FeatureGroupManager.PrintFeatureParameter("actual radius", aSRBIssue.ActualRadius(), "mm");
}
else if (DFMSheetMetal_SmallDiameterHoleIssue.CompareType(theIssue))
{
DFMSheetMetal_SmallDiameterHoleIssue aSDHIssue = DFMSheetMetal_SmallDiameterHoleIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter("expected min diameter", aSDHIssue.ExpectedMinDiameter(), "mm");
FeatureGroupManager.PrintFeatureParameter("actual diameter", aSDHIssue.ActualDiameter(), "mm");
}
else if (DFMSheetMetal_SmallDistanceBetweenFeaturesIssue.CompareType(theIssue))
{
DFMSheetMetal_SmallDistanceBetweenFeaturesIssue aSDBFIssue = DFMSheetMetal_SmallDistanceBetweenFeaturesIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter("expected min distance", aSDBFIssue.ExpectedMinDistanceBetweenFeatures(), "mm");
FeatureGroupManager.PrintFeatureParameter("actual distance", aSDBFIssue.ActualDistanceBetweenFeatures(), "mm");
}
else if (DFMSheetMetal_FlatPatternInterferenceIssue.CompareType(theIssue))
{
}
else if (DFMSheetMetal_IrregularCornerFilletRadiusNotchIssue.CompareType(theIssue))
{
DFMSheetMetal_IrregularCornerFilletRadiusNotchIssue aICFRNIssue = DFMSheetMetal_IrregularCornerFilletRadiusNotchIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter("expected corner fillet radius", aICFRNIssue.ExpectedCornerFilletRadius(), "mm");
FeatureGroupManager.PrintFeatureParameter("actual corner fillet radius", aICFRNIssue.ActualCornerFilletRadius(), "mm");
}
else if (DFMSheetMetal_IrregularDepthExtrudedHoleIssue.CompareType(theIssue))
{
DFMSheetMetal_IrregularDepthExtrudedHoleIssue aIDEHIssue = DFMSheetMetal_IrregularDepthExtrudedHoleIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter("expected min extruded height", aIDEHIssue.ExpectedMinExtrudedHeight(), "mm");
FeatureGroupManager.PrintFeatureParameter("expected max extruded height", aIDEHIssue.ExpectedMaxExtrudedHeight(), "mm");
FeatureGroupManager.PrintFeatureParameter("actual extruded height", aIDEHIssue.ActualExtrudedHeight(), "mm");
}
else if (DFMSheetMetal_IrregularRadiusOpenHemBendIssue.CompareType(theIssue))
{
DFMSheetMetal_IrregularRadiusOpenHemBendIssue aIROHBIssue = DFMSheetMetal_IrregularRadiusOpenHemBendIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter("expected radius", aIROHBIssue.ExpectedRadius(), "mm");
FeatureGroupManager.PrintFeatureParameter("actual radius", aIROHBIssue.ActualRadius(), "mm");
}
else if (DFMSheetMetal_IrregularSizeBendReliefIssue.CompareType(theIssue))
{
DFMSheetMetal_IrregularSizeBendReliefIssue aISBRIssue = DFMSheetMetal_IrregularSizeBendReliefIssue.Cast(theIssue);
SheetMetal_BendRelief anExpectedRelief = aISBRIssue.ExpectedMinBendRelief();
SheetMetal_BendRelief aFirstActualRelief = aISBRIssue.FirstActualRelief();
SheetMetal_BendRelief aSecondActualRelief = aISBRIssue.SecondActualRelief();
FeatureGroupManager.PrintFeatureParameter(
"expected min relief size (LxW)",
new Pair(anExpectedRelief.Length(), anExpectedRelief.Width()),
"mm");
if (!aFirstActualRelief.IsNull() && !aSecondActualRelief.IsNull())
{
FeatureGroupManager.PrintFeatureParameter(
"first actual relief size (LxW)",
new Pair(aFirstActualRelief.Length(), aFirstActualRelief.Width()),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"second actual relief size (LxW)",
new Pair(aSecondActualRelief.Length(), aSecondActualRelief.Width()),
"mm");
}
else if (aFirstActualRelief.IsNull())
{
FeatureGroupManager.PrintFeatureParameter(
"actual relief size (LxW)",
new Pair(aSecondActualRelief.Length(), aSecondActualRelief.Width()),
"mm");
}
else
{
FeatureGroupManager.PrintFeatureParameter(
"actual relief size (LxW)",
new Pair(aFirstActualRelief.Length(), aFirstActualRelief.Width()),
"mm");
}
}
else if (DFMSheetMetal_LargeDepthBeadIssue.CompareType(theIssue))
{
DFMSheetMetal_LargeDepthBeadIssue aLDBIssue = DFMSheetMetal_LargeDepthBeadIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter("expected max depth", aLDBIssue.ExpectedMaxDepth(), "mm");
FeatureGroupManager.PrintFeatureParameter("actual depth", aLDBIssue.ActualDepth(), "mm");
}
else if (DFMSheetMetal_SmallDepthLouverIssue.CompareType(theIssue))
{
DFMSheetMetal_SmallDepthLouverIssue aSDLIssue = DFMSheetMetal_SmallDepthLouverIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter("expected min depth", aSDLIssue.ExpectedMinDepth(), "mm");
FeatureGroupManager.PrintFeatureParameter("actual depth", aSDLIssue.ActualDepth(), "mm");
}
else if (DFMSheetMetal_InconsistentRadiusBendIssue.CompareType(theIssue))
{
DFMSheetMetal_InconsistentRadiusBendIssue aIRBIssue = DFMSheetMetal_InconsistentRadiusBendIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter("expected max radius", aIRBIssue.ExpectedRadius(), "mm");
FeatureGroupManager.PrintFeatureParameter("actual radius", aIRBIssue.ActualRadius(), "mm");
}
else if (DFMSheetMetal_SmallLengthFlangeIssue.CompareType(theIssue))
{
DFMSheetMetal_SmallLengthFlangeIssue aSLFIssue = DFMSheetMetal_SmallLengthFlangeIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter("expected min length", aSLFIssue.ExpectedMinLength(), "mm");
FeatureGroupManager.PrintFeatureParameter("actual length", aSLFIssue.ActualLength(), "mm");
}
else if (DFMSheetMetal_SmallLengthHemBendFlangeIssue.CompareType(theIssue))
{
DFMSheetMetal_SmallLengthHemBendFlangeIssue aSLHBFIssue = DFMSheetMetal_SmallLengthHemBendFlangeIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter("expected min length", aSLHBFIssue.ExpectedMinLength(), "mm");
FeatureGroupManager.PrintFeatureParameter("actual length", aSLHBFIssue.ActualLength(), "mm");
}
else if (DFMSheetMetal_IrregularSizeNotchIssue.CompareType(theIssue))
{
DFMSheetMetal_IrregularSizeNotchIssue aISNIssue = DFMSheetMetal_IrregularSizeNotchIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter(
"expected size (LxW)",
new Pair(aISNIssue.ExpectedLength(), aISNIssue.ExpectedWidth()),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"actual size (LxW)",
new Pair(aISNIssue.ActualLength(), aISNIssue.ActualWidth()),
"mm");
}
else if (DFMSheetMetal_IrregularSizeTabIssue.CompareType(theIssue))
{
DFMSheetMetal_IrregularSizeTabIssue aISTIssue = DFMSheetMetal_IrregularSizeTabIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter(
"expected size (LxW)",
new Pair(aISTIssue.ExpectedLength(), aISTIssue.ExpectedWidth()),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"actual size (LxW)",
new Pair(aISTIssue.ActualLength(), aISTIssue.ActualWidth()),
"mm");
}
else if (DFMSheetMetal_NonStandardSheetThicknessIssue.CompareType(theIssue))
{
DFMSheetMetal_NonStandardSheetThicknessIssue aNSSTIssue = DFMSheetMetal_NonStandardSheetThicknessIssue.Cast(theIssue);
FeatureGroupManager.PrintFeatureParameter(
"nearest standard sheet thickness", aNSSTIssue.NearestStandardSheetThickness(), "mm");
FeatureGroupManager.PrintFeatureParameter(
"actual sheet thickness", aNSSTIssue.ActualSheetThickness(), "mm");
}
else if (DFMSheetMetal_NonStandardSheetSizeIssue.CompareType(theIssue))
{
DFMSheetMetal_NonStandardSheetSizeIssue aNSSSIssue = DFMSheetMetal_NonStandardSheetSizeIssue.Cast(theIssue);
DFMSheetMetal_SheetSize aNearestStandardSize = aNSSSIssue.NearestStandardSheetSize();
DFMSheetMetal_SheetSize anActualSize = aNSSSIssue.ActualSheetSize();
FeatureGroupManager.PrintFeatureParameter(
"nearest standard sheet size (LxW)",
new Pair(aNearestStandardSize.Length(), aNearestStandardSize.Width()),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"actual sheet size (LxW)",
new Pair(anActualSize.Length(), anActualSize.Width()),
"mm");
}
};
aManager.Print("issues", PrintFeatureParameters);
}
static string SmallDistanceIssueName(DFMSheetMetal_SmallDistanceBetweenFeaturesIssue theIssue)
{
if (DFMSheetMetal_SmallDistanceBetweenBendAndLouverIssue.CompareType(theIssue))
{
return "Small Distance Between Bend And Louver Issue(s)";
}
else if (DFMSheetMetal_SmallDistanceBetweenExtrudedHoleAndBendIssue.CompareType(theIssue))
{
return "Small Distance Between Extruded Hole And Bend Issue(s)";
}
else if (DFMSheetMetal_SmallDistanceBetweenExtrudedHoleAndEdgeIssue.CompareType(theIssue))
{
return "Small Distance Between Extruded Hole And Edge Issue(s)";
}
else if (DFMSheetMetal_SmallDistanceBetweenExtrudedHolesIssue.CompareType(theIssue))
{
return "Small Distance Between Extruded Holes Issue(s)";
}
else if (DFMSheetMetal_SmallDistanceBetweenHoleAndBendIssue.CompareType(theIssue))
{
return "Small Distance Between Hole And Bend Issue(s)";
}
else if (DFMSheetMetal_SmallDistanceBetweenHoleAndCutoutIssue.CompareType(theIssue))
{
return "Small Distance Between Hole And Cutout Issue(s)";
}
else if (DFMSheetMetal_SmallDistanceBetweenHoleAndEdgeIssue.CompareType(theIssue))
{
return "Small Distance Between Hole And Edge Issue(s)";
}
else if (DFMSheetMetal_SmallDistanceBetweenHoleAndLouverIssue.CompareType(theIssue))
{
return "Small Distance Between Hole And Louver Issue(s)";
}
else if (DFMSheetMetal_SmallDistanceBetweenHoleAndNotchIssue.CompareType(theIssue))
{
return "Small Distance Between Hole And Notch Issue(s)";
}
else if (DFMSheetMetal_SmallDistanceBetweenHolesIssue.CompareType(theIssue))
{
return "Small Distance Between Holes Issue(s)";
}
else if (DFMSheetMetal_SmallDistanceBetweenNotchAndBendIssue.CompareType(theIssue))
{
return "Small Distance Between Notch And Bend Issue(s)";
}
else if (DFMSheetMetal_SmallDistanceBetweenNotchesIssue.CompareType(theIssue))
{
return "Small Distance Between Notches Issue(s)";
}
else if (DFMSheetMetal_SmallDistanceBetweenTabsIssue.CompareType(theIssue))
{
return "Small Distance Between Tabs Issue(s)";
}
return "Small Distance Between Feature(s)";
}
static double ToDegrees(double theAngleRad)
{
return theAngleRad * 180 / Math.PI;
}
}
}