#ifndef _FeatureGroup_HeaderFile
#define _FeatureGroup_HeaderFile
#include <cadex/Geom/Direction.hxx>
#include <cadex/MTKBase_Feature.hxx>
#include <cadex/MTKBase_FeatureComparator.hxx>
#include <algorithm>
#include <array>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>
using namespace std;
typedef std::pair<double, double> PairType;
typedef std::array<double, 3> ArrayType;
inline std::ostream& operator<< (std::ostream& theStream, const PairType& thePair)
{
return theStream << thePair.first << " x " << thePair.second;
}
inline std::ostream& operator<< (std::ostream& theStream, const ArrayType& theArray)
{
return theStream << theArray[0] << " x " << theArray[1] << " x " << theArray[2];
}
inline std::ostream& operator<< (std::ostream& theStream,
const Geom::Direction& theDir)
{
stringstream aStream;
aStream << setprecision(2) << fixed <<
"(" << theDir.
X() <<
", " << theDir.
Y() <<
", " << theDir.
Z() <<
")";
return theStream << aStream.str();
}
class FeatureGroupManager
{
public:
void AddFeature (const char* theGroupName,
const char* theSubgroupName,
bool theHasParameters,
{
auto aRes = std::find_if (myGroups.begin(), myGroups.end(),
[&] (const FeatureGroup& theGroup) { return theGroup.myName == theGroupName; });
if (aRes == myGroups.end()) {
aRes = myGroups.insert (aRes, FeatureGroup (theGroupName, theSubgroupName, theHasParameters));
}
auto& aGroup = *aRes;
++aGroup.myFeatureSubgroups[theFeature];
}
void Print (
const char* theFeatureType, function<
void (
MTKBase_Feature)> thePrintFeatureParameters)
{
sort (myGroups.begin(), myGroups.end(), FeatureGroupComparator());
cout << setprecision(6);
size_t aTotalCount = 0;
for (const auto& aFeatureGroup : myGroups) {
size_t aFeatureCount = aFeatureGroup.FeatureCount();
aTotalCount += aFeatureCount;
cout << " " << aFeatureGroup.myName << ": " << aFeatureCount << endl;
if (!aFeatureGroup.myHasParameters) {
continue;
}
const char* aSubgroupName = aFeatureGroup.mySubgroupName.c_str();
for (const auto& aFeatureSubgroup : aFeatureGroup.myFeatureSubgroups) {
cout << " " << aFeatureSubgroup.second << " " << aSubgroupName << " with" << endl;
thePrintFeatureParameters (aFeatureSubgroup.first);
}
}
cout << "\n Total " << theFeatureType << ": " << aTotalCount << "\n" << endl;
}
template <typename T>
static void PrintFeatureParameter (const char* theName, const T& theValue, const char* theUnits)
{
cout << " " << theName << ": " << theValue << " " << theUnits << endl;
}
private:
class FeatureGroup
{
public:
FeatureGroup (const std::string& theName, const std::string& theSubgroupName, bool theHasParameters) :
myName (theName), mySubgroupName (theSubgroupName), myHasParameters (theHasParameters)
{}
size_t FeatureCount() const
{
size_t aCount = 0;
for (const auto& aFeatureSubgroup : myFeatureSubgroups) {
aCount += aFeatureSubgroup.second;
}
return aCount;
}
string myName;
string mySubgroupName;
bool myHasParameters;
map<MTKBase_Feature, size_t, MTKBase_FeatureComparator> myFeatureSubgroups;
};
class FeatureGroupComparator
{
public:
bool operator() (const FeatureGroup& theA, const FeatureGroup& theB) const
{
const auto& anAName = theA.myName;
const auto& aBName = theB.myName;
if (anAName == aBName) {
return false;
}
const auto& anAFeatureSubgroups = theA.myFeatureSubgroups;
const auto& aBFeatureSubgroups = theB.myFeatureSubgroups;
if (anAFeatureSubgroups.empty() || aBFeatureSubgroups.empty()) {
return anAName < aBName;
}
aBFeatureSubgroups.begin()->first);
}
};
vector<FeatureGroup> myGroups;
};
#endif
Defines a 3D Direction.
Definition Direction.hxx:34
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
#ifndef _ShapeProcessor_HeaderFile
#define _ShapeProcessor_HeaderFile
#include <cadex/Base/UTF16String.hxx>
#include <cadex/ModelData/Body.hxx>
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/Part.hxx>
#include <cadex/ModelData/Shell.hxx>
#include <cadex/ModelData/Solid.hxx>
#include <cadex/WallThickness_Data.hxx>
#include <iostream>
using namespace std;
{
public:
{
size_t aBodyNumber = 0;
const auto& aBodies = thePart.
Bodies();
for (const auto& aBody : aBodies) {
while (aShapeIt.
HasNext()) {
const auto& aShape = aShapeIt.
Next();
if (aShape.Type() == ModelData::ShapeType::Solid) {
cout << "Part #" << myPartIndex << " [\"" << aPartName << "\"] - solid #" << std::to_string (aBodyNumber) << " has:" << endl;
ProcessSolid (ModelData::Solid::Cast (aShape));
} else if (aShape.Type() == ModelData::ShapeType::Shell) {
cout << "Part #" << myPartIndex << " [\"" << aPartName << "\"] - shell #" << std::to_string (aBodyNumber) << " has:" << endl;
ProcessShell (ModelData::Shell::Cast (aShape));
}
}
++aBodyNumber;
}
++myPartIndex;
}
private:
size_t myPartIndex = 0;
};
{
public:
{
size_t aBodyNumber = 0;
const auto& aBodies = thePart.Bodies();
for (const auto& aBody : aBodies) {
while (aShapeIt.HasNext()) {
const auto& aShape = aShapeIt.Next();
if (aShape.Type() == ModelData::ShapeType::Solid) {
cout << "Part #" << myPartIndex << " [\"" << aPartName << "\"] - solid #" << std::to_string (aBodyNumber++) << " has:" << endl;
ProcessSolid (ModelData::Solid::Cast (aShape));
}
}
}
++myPartIndex;
}
private:
size_t myPartIndex = 0;
};
{
public:
{
size_t aBodyNumber = 0;
const auto& aBodies = thePart.Bodies();
for (const auto& aBody : aBodies) {
while (aShapeIt.HasNext()) {
const auto& aShape = aShapeIt.Next();
if (aShape.Type() == ModelData::ShapeType::Solid) {
cout << "Part #" << myPartIndex << " [\"" << aPartName << "\"] - solid #" << std::to_string (aBodyNumber++) << " has:" << endl;
ProcessSolid (ModelData::Solid::Cast (aShape), aPartName, aBodyNumber);
}
}
}
++myPartIndex;
}
const UTF16String& thePartName,
size_t theShapeIndex) = 0;
protected:
size_t myPartIndex = 0;
};
#endif
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
#include <cadex/Geom/Axis3d.hxx>
#include <cadex/LicenseManager_Activate.h>
#include <cadex/Measurements/ValidationProperties.hxx>
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/ModelReader.hxx>
#include <cadex/MTKBase_FeatureList.hxx>
#include <cadex/SheetMetal_Bead.hxx>
#include <cadex/SheetMetal_Bridge.hxx>
#include <cadex/SheetMetal_ComplexHole.hxx>
#include <cadex/SheetMetal_CompoundBend.hxx>
#include <cadex/SheetMetal_CurvedBend.hxx>
#include <cadex/SheetMetal_Cutout.hxx>
#include <cadex/SheetMetal_FeatureRecognizer.hxx>
#include <cadex/SheetMetal_HemBend.hxx>
#include <cadex/SheetMetal_HemBendType.hxx>
#include <cadex/SheetMetal_Louver.hxx>
#include <cadex/SheetMetal_Notch.hxx>
#include <cadex/SheetMetal_StraightNotch.hxx>
#include <cadex/SheetMetal_Tab.hxx>
#include <cadex/SheetMetal_VNotch.hxx>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include "../../helpers/feature_group.hxx"
#include "../../helpers/shape_processor.hxx"
#include "../../mtk_license.cxx"
using namespace std;
double ToDegrees (double theAngleRad)
{
return theAngleRad * 180. / M_PI;
}
{
switch (theType) {
case SheetMetal_HBT_Flattened: return "Flattened Hem Bend(s)";
case SheetMetal_HBT_Open: return "Open Hem Bend(s)";
case SheetMetal_HBT_Teardrop: return "Teardrop Hem Bend(s)";
case SheetMetal_HBT_Rope: return "Rope Hem Bend(s)";
case SheetMetal_HBT_Rolled: return "Rolled Hem Bend(s)";
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)";
}
{
FeatureGroupManager aManager;
for (size_t i = 0; i < theFeatures.Size(); ++i) {
const auto& aFeature = theFeatures[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);
aManager.AddFeature (HoleName (aHole), "Hole(s)", true, aFeature);
aManager.AddFeature (BendName (aBend), "Bend(s)", true, aFeature);
aManager.AddFeature (NotchName (aNotch), "Notch(es)", true, aFeature);
aManager.AddFeature ("Tab(s)", "Tab(s)", true, aFeature);
GroupByParameters (aCompoundBend.FeatureList());
}
}
};
GroupByParameters (theFeatureList);
{
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");
FeatureGroupManager::PrintFeatureParameter ("radius", aHole.Radius(), "mm");
FeatureGroupManager::PrintFeatureParameter ("depth", aHole.Depth(), "mm");
FeatureGroupManager::PrintFeatureParameter ("axis", aHole.Axis().Axis(), "");
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);
}
class PartProcessor : public ShapeProcessor
{
public:
{
auto aFeatureList = myRecognizer.Perform (theSolid);
PrintFeatures (aFeatureList);
}
{
auto aFeatureList = myRecognizer.Perform (theShell);
PrintFeatures (aFeatureList);
}
private:
};
int main (int argc, char* argv[])
{
auto aKey = MTKLicenseKey::Value();
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate Manufacturing Toolkit license." << endl;
return 1;
}
if (argc != 2) {
cerr << "Usage: " << argv[0] << " <input_file>, where:" << endl;
cerr << " <input_file> is a name of the file to be read" << endl;
return 1;
}
const char* aSource = argv[1];
if (!aReader.
Read (aSource, aModel)) {
cerr << "Failed to read the file " << aSource << endl;
return 1;
}
cout <<
"Model: " << aModel.
Name() <<
"\n" << endl;
PartProcessor aPartProcessor;
return 0;
}
Defines a list of features.
Definition MTKBase_FeatureList.hxx:36
Defines a visitor that visits each unique element only once.
Definition ModelElementVisitor.hxx:87
Provides MTK data model.
Definition Model.hxx:40
UTF16String Name() const
Returns a model name.
Definition Model.cxx:250
void Accept(ModelElementVisitor &theVisitor) const
Accepts a visitor.
Definition Model.cxx:270
Reads STEP and native format.
Definition ModelReader.hxx:29
bool Read(const UTF16String &theFilePath, ModelData::Model &theModel)
Reads the file at the specified path into the specified model.
Definition ModelReader.cxx:227
SheetMetal_HemBendType
Defines a hem bend type in sheet metal.
Definition SheetMetal_HemBendType.hxx:28