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