Hide menu
Loading...
Searching...
No Matches
machining/dfm_analyzer/main.cxx

Refer to the CNC Machining DFM Analyzer Example

feature_group.hxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2025, CADEX. All rights reserved.
//
// This file is part of the Manufacturing Toolkit software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
#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 cadex;
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,
const MTKBase_Feature& theFeature)
{
//find or create
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));
}
//update
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;
}
return MTKBase_FeatureComparator() (anAFeatureSubgroups.begin()->first,
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

shape_processor.hxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2025, CADEX. All rights reserved.
//
// This file is part of the Manufacturing Toolkit software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
#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 cadex;
using namespace std;
class ShapeProcessor : public ModelData::ModelElementVoidVisitor
{
public:
void operator() (const ModelData::Part& thePart) override
{
auto aPartName = thePart.Name().IsEmpty() ? "noname" : thePart.Name();
size_t aBodyNumber = 0;
const auto& aBodies = thePart.Bodies();
for (const auto& aBody : aBodies) {
ModelData::ShapeIterator aShapeIt (aBody);
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;
}
virtual void ProcessSolid (const ModelData::Solid& theSolid) = 0;
virtual void ProcessShell (const ModelData::Shell& theShell) = 0;
private:
size_t myPartIndex = 0;
};
class SolidProcessor : public ModelData::ModelElementVoidVisitor
{
public:
void operator() (const ModelData::Part& thePart) override
{
auto aPartName = thePart.Name().IsEmpty() ? "noname" : thePart.Name();
size_t aBodyNumber = 0;
const auto& aBodies = thePart.Bodies();
for (const auto& aBody : aBodies) {
ModelData::ShapeIterator aShapeIt (aBody);
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;
}
virtual void ProcessSolid (const ModelData::Solid& theSolid) = 0;
private:
size_t myPartIndex = 0;
};
class SolidAndMeshProcessor : public ModelData::ModelElementVoidVisitor
{
public:
void operator() (const ModelData::Part& thePart) override
{
auto aPartName = thePart.Name().IsEmpty() ? "noname" : thePart.Name();
size_t aBodyNumber = 0;
const auto& aBodies = thePart.Bodies();
for (const auto& aBody : aBodies) {
ModelData::ShapeIterator aShapeIt (aBody);
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;
}
virtual void ProcessSolid (const ModelData::Solid& theSolid,
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

main.cxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2025, CADEX. All rights reserved.
//
// This file is part of the Manufacturing Toolkit software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
#include <cadex/DFMMachining_Analyzer.hxx>
#include <cadex/DFMMachining_DeepBoredHoleIssue.hxx>
#include <cadex/DFMMachining_DeepHoleIssue.hxx>
#include <cadex/DFMMachining_DeepPocketIssue.hxx>
#include <cadex/DFMMachining_DrillingAnalyzerParameters.hxx>
#include <cadex/DFMMachining_FlatBottomHoleIssue.hxx>
#include <cadex/DFMMachining_HighBossIssue.hxx>
#include <cadex/DFMMachining_InconsistentRadiusMilledPartFloorFilletIssue.hxx>
#include <cadex/DFMMachining_IntersectingCavityHoleIssue.hxx>
#include <cadex/DFMMachining_IrregularTurnedPartOuterDiameterProfileReliefIssue.hxx>
#include <cadex/DFMMachining_LargeMilledPartIssue.hxx>
#include <cadex/DFMMachining_LargeTurnedPartIssue.hxx>
#include <cadex/DFMMachining_LongSlenderTurnedPartIssue.hxx>
#include <cadex/DFMMachining_NonSymmetricalAxialSlotIssue.hxx>
#include <cadex/DFMMachining_MilledPartExternalEdgeFilletIssue.hxx>
#include <cadex/DFMMachining_MilledPartSize.hxx>
#include <cadex/DFMMachining_MillingAnalyzerParameters.hxx>
#include <cadex/DFMMachining_NonPerpendicularHoleIssue.hxx>
#include <cadex/DFMMachining_NonPerpendicularMilledPartShapeIssue.hxx>
#include <cadex/DFMMachining_NonStandardDiameterHoleIssue.hxx>
#include <cadex/DFMMachining_NonStandardDrillPointAngleBlindHoleIssue.hxx>
#include <cadex/DFMMachining_NonStandardRadiusMilledPartFloorFilletIssue.hxx>
#include <cadex/DFMMachining_PartialHoleIssue.hxx>
#include <cadex/DFMMachining_SmallDepthBlindBoredHoleReliefIssue.hxx>
#include <cadex/DFMMachining_SmallDiameterHoleIssue.hxx>
#include <cadex/DFMMachining_SmallRadiusMilledPartInternalCornerIssue.hxx>
#include <cadex/DFMMachining_SmallRadiusTurnedPartInternalCornerIssue.hxx>
#include <cadex/DFMMachining_SmallWallThicknessIssue.hxx>
#include <cadex/DFMMachining_SquareEndKeywayIssue.hxx>
#include <cadex/DFMMachining_TurnedPartSize.hxx>
#include <cadex/DFMMachining_TurningAnalyzerParameters.hxx>
#include <cadex/DFMMachining_NarrowRegionInPocketIssue.hxx>
#include <cadex/DFMMachining_LargeDifferenceRegionsSizeInPocketIssue.hxx>
#include <cadex/LicenseManager_Activate.h>
#include <cadex/Machining_Data.hxx>
#include <cadex/Machining_FeatureRecognizer.hxx>
#include <cadex/Machining_FeatureRecognizerParameters.hxx>
#include <cadex/Machining_OperationType.hxx>
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/ModelReader.hxx>
#include <cadex/MTKBase_FeatureList.hxx>
#define _USE_MATH_DEFINES
#include <math.h>
#include <unordered_map>
#include "../../helpers/feature_group.hxx"
#include "../../helpers/shape_processor.hxx"
#include "../../mtk_license.cxx"
using namespace cadex;
using namespace std;
double ToDegrees (double theAngleRad)
{
return theAngleRad * 180. / M_PI;
}
void PrintIssues (const MTKBase_FeatureList& theIssueList)
{
FeatureGroupManager aManager;
//group by parameters to provide more compact information about issues
for (size_t i = 0; i < theIssueList.Size(); ++i) {
const auto& anIssue = theIssueList[i];
//drilling
if (anIssue.IsOfType<DFMMachining_SmallDiameterHoleIssue>()) {
aManager.AddFeature ("Small Diameter Hole Issue(s)", "Hole(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_DeepHoleIssue>()) {
aManager.AddFeature ("Deep Hole Issue(s)", "Hole(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_NonStandardDiameterHoleIssue>()) {
aManager.AddFeature ("Non Standard Diameter Hole Issue(s)", "Hole(s)", true, anIssue);
aManager.AddFeature ("Non Standard Drill Point Angle Blind Hole Issue(s)", "Hole(s)", true, anIssue);
}
else if (anIssue.IsOfType<DFMMachining_FlatBottomHoleIssue>()) {
aManager.AddFeature ("Flat Bottom Hole Issue(s)", "", false, anIssue);
} else if (anIssue.IsOfType<DFMMachining_NonPerpendicularHoleIssue>()) {
aManager.AddFeature ("Non Perpendicular Hole Issue(s)", "", false, anIssue);
} else if (anIssue.IsOfType<DFMMachining_IntersectingCavityHoleIssue>()) {
aManager.AddFeature ("Intersecting Cavity Hole Issue(s)", "", false, anIssue);
} else if (anIssue.IsOfType<DFMMachining_PartialHoleIssue>()) {
aManager.AddFeature ("Partial Hole Issue(s)", "Hole(s)", true, anIssue);
}
//milling
aManager.AddFeature ("Non Standard Radius Milled Part Floor Fillet Issue(s)", "Floor Fillet(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_DeepPocketIssue>()) {
aManager.AddFeature ("Deep Pocket Issue(s)", "Pocket(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_HighBossIssue>()) {
aManager.AddFeature ("High Boss Issue(s)", "Boss(es)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_LargeMilledPartIssue>()) {
aManager.AddFeature ("Large Milled Part Issue(s)", "Part(s)", true, anIssue);
aManager.AddFeature ("Small Radius Milled Part Internal Corner Issue(s)", "Internal Corner(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_NonPerpendicularMilledPartShapeIssue>()) {
aManager.AddFeature ("Non Perpendicular Milled Part Shape Issue(s)", "Shape(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_MilledPartExternalEdgeFilletIssue>()) {
aManager.AddFeature ("Milled Part External Edge Fillet Issue(s)", "", false, anIssue);
aManager.AddFeature ("Inconsistent Radius Milled Part Floor Fillet Issue(s)", "Floor Fillet(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_NarrowRegionInPocketIssue>()) {
aManager.AddFeature ("Narrow Region In Pocket Issue(s)", "Region(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_LargeDifferenceRegionsSizeInPocketIssue>()) {
aManager.AddFeature ("Large Difference Regions Size In Pocket Issue(s)", "Region Size(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_SmallWallThicknessIssue>()) {
aManager.AddFeature ("Small Wall Thickness Issue(s)", "Wall(s)", true, anIssue);
}
//turning
aManager.AddFeature ("Irregular Turned Part Outer Diameter Profile Relief Issue(s)", "Outer Diameter Profile Relief(s)", true, anIssue);
aManager.AddFeature ("Small Radius Turned Part Internal Corner Issue(s)", "Internal Corner(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_LargeTurnedPartIssue>()) {
aManager.AddFeature ("Large Turned Part Issue(s)", "Part(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_LongSlenderTurnedPartIssue>()) {
aManager.AddFeature ("Long Slender Turned Part Issue(s)", "Part(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_SmallDepthBlindBoredHoleReliefIssue>()) {
aManager.AddFeature ("Small Depth Blind Bored Hole Relief Issue(s)", "Blind Bored Hole(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_DeepBoredHoleIssue>()) {
aManager.AddFeature ("Deep Bored Hole Issue(s)", "Bored Hole(s)", true, anIssue);
} else if (anIssue.IsOfType<DFMMachining_SquareEndKeywayIssue>()) {
aManager.AddFeature ("Square End Keyway Issue(s)", "", false, anIssue);
} else if (anIssue.IsOfType<DFMMachining_NonSymmetricalAxialSlotIssue>()) {
aManager.AddFeature ("Non Symmetrical Axial Slot Issue(s)", "", false, anIssue);
}
}
//print
auto PrintFeatureParameters = [] (const MTKBase_Feature& theIssue)
{
//drilling
if (theIssue.IsOfType<DFMMachining_SmallDiameterHoleIssue>()) {
const auto& aSDHIssue = static_cast<const DFMMachining_SmallDiameterHoleIssue&> (theIssue);
FeatureGroupManager::PrintFeatureParameter ("expected min diameter", aSDHIssue.ExpectedMinDiameter(), "mm");
FeatureGroupManager::PrintFeatureParameter ("actual diameter", aSDHIssue.ActualDiameter(), "mm");
} else if (theIssue.IsOfType<DFMMachining_DeepHoleIssue>()) {
const auto& aDHIssue = static_cast<const DFMMachining_DeepHoleIssue&> (theIssue);
FeatureGroupManager::PrintFeatureParameter ("expected max depth", aDHIssue.ExpectedMaxDepth(), "mm");
FeatureGroupManager::PrintFeatureParameter ("actual depth", aDHIssue.ActualDepth(), "mm");
} else if (theIssue.IsOfType<DFMMachining_NonStandardDiameterHoleIssue>()) {
const auto& aNSDHIssue = static_cast<const DFMMachining_NonStandardDiameterHoleIssue&> (theIssue);
FeatureGroupManager::PrintFeatureParameter (
"nearest standard diameter", aNSDHIssue.NearestStandardDiameter(), "mm");
FeatureGroupManager::PrintFeatureParameter (
"actual diameter", aNSDHIssue.ActualDiameter(), "mm");
} else if (theIssue.IsOfType<DFMMachining_NonStandardDrillPointAngleBlindHoleIssue>()) {
const auto& aNSDPABHIssue = static_cast<const DFMMachining_NonStandardDrillPointAngleBlindHoleIssue&> (theIssue);
FeatureGroupManager::PrintFeatureParameter (
"nearest standard angle", ToDegrees (aNSDPABHIssue.NearestStandardAngle()), "deg");
FeatureGroupManager::PrintFeatureParameter (
"actual angle", ToDegrees (aNSDPABHIssue.ActualAngle()), "deg");
}
else if (theIssue.IsOfType<DFMMachining_FlatBottomHoleIssue>()) {
//no parameters
} else if (theIssue.IsOfType<DFMMachining_NonPerpendicularHoleIssue>()) {
//no parameters
} else if (theIssue.IsOfType<DFMMachining_IntersectingCavityHoleIssue>()) {
//no parameters
} else if (theIssue.IsOfType<DFMMachining_PartialHoleIssue>()) {
const auto& aPHIssue = static_cast<const DFMMachining_PartialHoleIssue&> (theIssue);
FeatureGroupManager::PrintFeatureParameter (
"expected min material percent", aPHIssue.ExpectedMinMaterialPercent(), "");
FeatureGroupManager::PrintFeatureParameter (
"actual material percent", aPHIssue.ActualMaterialPercent(), "");
}
//milling
const auto& aNSRMPFFIssue =
FeatureGroupManager::PrintFeatureParameter (
"nearest standard radius", aNSRMPFFIssue.NearestStandardRadius(), "mm");
FeatureGroupManager::PrintFeatureParameter (
"actual radius", aNSRMPFFIssue.ActualRadius(), "mm");
} else if (theIssue.IsOfType<DFMMachining_DeepPocketIssue>()) {
const auto& aDPIssue = static_cast<const DFMMachining_DeepPocketIssue&> (theIssue);
FeatureGroupManager::PrintFeatureParameter ("expected max depth", aDPIssue.ExpectedMaxDepth(), "mm");
FeatureGroupManager::PrintFeatureParameter ("actual depth", aDPIssue.ActualDepth(), "mm");
} else if (theIssue.IsOfType<DFMMachining_HighBossIssue>()) {
const auto& aHBIssue = static_cast<const DFMMachining_HighBossIssue&> (theIssue);
FeatureGroupManager::PrintFeatureParameter ("expected max height", aHBIssue.ExpectedMaxHeight(), "mm");
FeatureGroupManager::PrintFeatureParameter ("actual height", aHBIssue.ActualHeight(), "mm");
} else if (theIssue.IsOfType<DFMMachining_LargeMilledPartIssue>()) {
const auto& aLMPIssue = static_cast<const DFMMachining_LargeMilledPartIssue&> (theIssue);
const auto& anExpectedSize = aLMPIssue.ExpectedMaxMilledPartSize();
const auto& anActualSize = aLMPIssue.ActualMilledPartSize();
FeatureGroupManager::PrintFeatureParameter (
"expected max size (LxWxH)",
ArrayType ({ anExpectedSize.Length(), anExpectedSize.Width(), anExpectedSize.Height() }),
"mm");
FeatureGroupManager::PrintFeatureParameter (
"actual size (LxWxH)",
ArrayType ({ anActualSize.Length(), anActualSize.Width(), anActualSize.Height() }),
"mm");
} else if (theIssue.IsOfType<DFMMachining_SmallRadiusMilledPartInternalCornerIssue>()) {
const auto& aSRMPICIssue =
FeatureGroupManager::PrintFeatureParameter ("expected min radius", aSRMPICIssue.ExpectedMinRadius(), "mm");
FeatureGroupManager::PrintFeatureParameter ("actual radius", aSRMPICIssue.ActualRadius(), "mm");
} else if (theIssue.IsOfType<DFMMachining_NonPerpendicularMilledPartShapeIssue>()) {
const auto& aNPMPSIssue =
static_cast<const DFMMachining_NonPerpendicularMilledPartShapeIssue&> (theIssue);
FeatureGroupManager::PrintFeatureParameter ("actual angle", ToDegrees (aNPMPSIssue.ActualAngle()), "deg");
} else if (theIssue.IsOfType<DFMMachining_MilledPartExternalEdgeFilletIssue>()) {
//no parameters
const auto& aIRMPFFIssue =
FeatureGroupManager::PrintFeatureParameter ("expected radius", aIRMPFFIssue.ExpectedRadius(), "mm");
FeatureGroupManager::PrintFeatureParameter ("actual radius", aIRMPFFIssue.ActualRadius(), "mm");
} else if (theIssue.IsOfType<DFMMachining_NarrowRegionInPocketIssue>()) {
const auto& aSMNRDIssue =
static_cast<const DFMMachining_NarrowRegionInPocketIssue&> (theIssue);
FeatureGroupManager::PrintFeatureParameter ("expected minimum region size", aSMNRDIssue.ExpectedMinRegionSize(), "mm");
FeatureGroupManager::PrintFeatureParameter ("actual region size", aSMNRDIssue.ActualRegionSize(), "mm");
} else if (theIssue.IsOfType<DFMMachining_LargeDifferenceRegionsSizeInPocketIssue>()) {
const auto& aLMNRRIssue =
FeatureGroupManager::PrintFeatureParameter ("expected regions maximum to minimum size ratio", aLMNRRIssue.ExpectedMaxRegionsMaxToMinSizeRatio(), "");
FeatureGroupManager::PrintFeatureParameter ("actual regions maximum to minimum size ratio", aLMNRRIssue.ActualMaxRegionsMaxToMinSizeRatio(), "");
} else if (theIssue.IsOfType<DFMMachining_SmallWallThicknessIssue>()) {
const auto& aSWTIssue = static_cast<const DFMMachining_SmallWallThicknessIssue&> (theIssue);
FeatureGroupManager::PrintFeatureParameter ("expected min wall thickness", aSWTIssue.ExpectedMinThickness(), "mm");
FeatureGroupManager::PrintFeatureParameter ("actual wall thickness", aSWTIssue.ActualThickness(), "mm");
}
//turning
const auto& anITPODPRIssue =
FeatureGroupManager::PrintFeatureParameter (
"expected max incline angle", ToDegrees (anITPODPRIssue.ExpectedMaxFaceInclineAngle()), "deg");
FeatureGroupManager::PrintFeatureParameter (
"actual incline angle", ToDegrees (anITPODPRIssue.ActualFaceInclineAngle()), "deg");
} else if (theIssue.IsOfType<DFMMachining_SmallRadiusTurnedPartInternalCornerIssue>()) {
const auto& aSRTPICIssue =
FeatureGroupManager::PrintFeatureParameter ("expected min radius", aSRTPICIssue.ExpectedMinRadius(), "mm");
FeatureGroupManager::PrintFeatureParameter ("actual radius", aSRTPICIssue.ActualRadius(), "mm");
} else if (theIssue.IsOfType<DFMMachining_LargeTurnedPartIssue>()) {
const auto& aLTPIssue = static_cast<const DFMMachining_LargeTurnedPartIssue&> (theIssue);
const auto& anExpectedSize = aLTPIssue.ExpectedMaxTurnedPartSize();
const auto& anActualSize = aLTPIssue.ActualTurnedPartSize();
FeatureGroupManager::PrintFeatureParameter (
"expected max size (LxR)",
std::make_pair (anExpectedSize.Length(), anExpectedSize.Radius()),
"mm");
FeatureGroupManager::PrintFeatureParameter (
"actual size (LxR)",
std::make_pair (anActualSize.Length(), anActualSize.Radius()),
"mm");
} else if (theIssue.IsOfType<DFMMachining_LongSlenderTurnedPartIssue>()) {
const auto& aLSTPIssue =
static_cast<const DFMMachining_LongSlenderTurnedPartIssue&> (theIssue);
FeatureGroupManager::PrintFeatureParameter ("expected min length", aLSTPIssue.ExpectedMaxLength(), "mm");
FeatureGroupManager::PrintFeatureParameter ("actual length", aLSTPIssue.ActualLength(), "mm");
FeatureGroupManager::PrintFeatureParameter ("actual min diameter", aLSTPIssue.ActualMinDiameter(), "mm");
} else if (theIssue.IsOfType<DFMMachining_SmallDepthBlindBoredHoleReliefIssue>()) {
const auto& aSDBBHRIssue =
static_cast<const DFMMachining_SmallDepthBlindBoredHoleReliefIssue&> (theIssue);
FeatureGroupManager::PrintFeatureParameter (
"expected min relief depth", aSDBBHRIssue.ExpectedMinReliefDepth(), "mm");
FeatureGroupManager::PrintFeatureParameter (
"actual relief depth", aSDBBHRIssue.ActualReliefDepth(), "mm");
FeatureGroupManager::PrintFeatureParameter (
"actual diameter", aSDBBHRIssue.ActualDiameter(), "mm");
} else if (theIssue.IsOfType<DFMMachining_DeepBoredHoleIssue>()) {
const auto& aDBHIssue =
static_cast<const DFMMachining_DeepBoredHoleIssue&> (theIssue);
FeatureGroupManager::PrintFeatureParameter ("expected max depth", aDBHIssue.ExpectedMaxDepth(), "mm");
FeatureGroupManager::PrintFeatureParameter ("actual depth", aDBHIssue.ActualDepth(), "mm");
FeatureGroupManager::PrintFeatureParameter ("actual diameter", aDBHIssue.ActualDiameter(), "mm");
} else if (theIssue.IsOfType<DFMMachining_SquareEndKeywayIssue>()) {
//no parameters
} else if (theIssue.IsOfType<DFMMachining_NonSymmetricalAxialSlotIssue>()) {
//no parameters
}
};
aManager.Print ("issues", PrintFeatureParameters);
}
class PartProcessor : public SolidProcessor
{
public:
PartProcessor (Machining_OperationType theOperation) : myOperation (theOperation)
{}
void ProcessSolid (const ModelData::Solid& theSolid) override
{
// Find features
aRecognizer.Parameters().SetOperation (myOperation);
aRecognizer.Perform (theSolid, aData);
// Run drilling analyzer for found features
DFMMachining_Analyzer aDrillingAnalyzer (aDrillingParameters);
auto anIssueList = aDrillingAnalyzer.Perform (theSolid, aData);
// Run milling analyzer for found features
DFMMachining_Analyzer aMillingAnalyzer (aMillingParameters);
MTKBase_FeatureList aMillingIssueList = aMillingAnalyzer.Perform (theSolid, aData);
// Combine issue lists
CombineFeatureLists (anIssueList, aMillingIssueList);
MTKBase_FeatureList aTurningIssueList;
if (myOperation == Machining_OT_LatheMilling) {
// Run turning analyzer for found features
DFMMachining_Analyzer aTurningAnalyzer (aTurninigParameters);
aTurningIssueList = aTurningAnalyzer.Perform (theSolid, aData);
// Combine issue lists
CombineFeatureLists (anIssueList, aTurningIssueList);
}
PrintIssues (anIssueList);
}
private:
void CombineFeatureLists (MTKBase_FeatureList& theFirst, const MTKBase_FeatureList& theSecond)
{
for (size_t i = 0; i < theSecond.Size(); i++) {
const auto& aFeature = theSecond[i];
if (myOperation == Machining_OT_LatheMilling
&& aFeature.IsOfType<DFMMachining_MillingIssue>()
&& !aFeature.IsOfType<DFMMachining_DeepPocketIssue>()) {
continue;
}
theFirst.Append (aFeature);
}
}
};
void PrintSupportedOperations()
{
cerr << "Supported operations:" << endl;
cerr << " milling:\t CNC Machining Milling feature recognition" << endl;
cerr << " turning:\t CNC Machining Lathe+Milling feature recognition" << endl;
}
Machining_OperationType OperationType (std::string theOperationStr)
{
static std::unordered_map<std::string, Machining_OperationType> aProcessMap
{
{"milling", Machining_OT_Milling},
};
auto aRes = aProcessMap.find (theOperationStr);
if (aRes != aProcessMap.end()) {
return aRes->second;
}
}
int main (int argc, char* argv[])
{
auto aKey = MTKLicenseKey::Value();
// Activate the license (aKey must be defined in mtk_license.cxx)
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate Manufacturing Toolkit license." << endl;
return 1;
}
if (argc != 3) {
cerr << "Usage: " << argv[0] << " <input_file> <operation>, where:" << endl;
cerr << " <input_file> is a name of the file to be read" << endl;
cerr << " <operation> is a name of desired machining operation" << endl << endl;
PrintSupportedOperations();
return 1;
}
const char* aSource = argv[1];
// Reading the file
if (!aReader.Read (aSource, aModel)) {
cerr << "Failed to read the file " << aSource << endl;
return 1;
}
cout << "Model: " << aModel.Name() << "\n" << endl;
const char* anOperationStr = argv[2];
auto anOperation = OperationType (anOperationStr);
if (anOperation == Machining_OT_Undefined) {
cerr << "Unsupported operation - " << anOperationStr << endl;
cerr << "Please use one of the following." << endl;
PrintSupportedOperations();
return 1;
}
//processing
PartProcessor aPartProcessor (anOperation);
ModelData::ModelElementUniqueVisitor aVisitor (aPartProcessor);
aModel.Accept (aVisitor);
return 0;
}
Provides an interface to run DFM Machining analysis.
Definition DFMMachining_Analyzer.hxx:43
Describes deep bored hole issue found during cnc machining turning design analysis.
Definition DFMMachining_DeepBoredHoleIssue.hxx:33
Describes deep hole issues found during cnc machining drilling design analysis.
Definition DFMMachining_DeepHoleIssue.hxx:29
Describes deep pocket issue found during cnc machining milling design analysis.
Definition DFMMachining_DeepPocketIssue.hxx:30
Defines parameters used in cnc machining drilling design analysis.
Definition DFMMachining_DrillingAnalyzerParameters.hxx:31
Describes flat bottom hole issues found during cnc machining drilling design analysis.
Definition DFMMachining_FlatBottomHoleIssue.hxx:29
Describes high boss issues found during cnc machining milling design analysis.
Definition DFMMachining_HighBossIssue.hxx:30
Describes inconsistent radius milled part floor fillet issue found during cnc machining milling desig...
Definition DFMMachining_InconsistentRadiusMilledPartFloorFilletIssue.hxx:33
Describes intersecting cavity hole issues found during cnc machining drilling design analysis.
Definition DFMMachining_IntersectingCavityHoleIssue.hxx:29
Describes irregular outer diameter profile relief found during cnc machining turning design analysis.
Definition DFMMachining_IrregularTurnedPartOuterDiameterProfileReliefIssue.hxx:33
Described the Narrow Pocket maximum to minimum sizes ratio issue found during cnc machining milling d...
Definition DFMMachining_LargeDifferenceRegionsSizeInPocketIssue.hxx:35
Describes large milled part issue found during cnc machining milling design analysis.
Definition DFMMachining_LargeMilledPartIssue.hxx:31
const DFMMachining_MilledPartSize & ExpectedMaxMilledPartSize() const
Definition DFMMachining_LargeMilledPartIssue.cxx:72
Describes large turned part issue found during cnc machining turning design analysis.
Definition DFMMachining_LargeTurnedPartIssue.hxx:31
const DFMMachining_TurnedPartSize & ExpectedMaxTurnedPartSize() const
Definition DFMMachining_LargeTurnedPartIssue.cxx:71
Describes long-slender turned part issue found during cnc machining turning design analysis.
Definition DFMMachining_LongSlenderTurnedPartIssue.hxx:29
Describes external edge fillet issue found during cnc machining milling design analysis.
Definition DFMMachining_MilledPartExternalEdgeFilletIssue.hxx:33
Defines parameters used in cnc machining milling design analysis.
Definition DFMMachining_MillingAnalyzerParameters.hxx:36
Describes a base class for milling issues found during cnc machining milling design analysis.
Definition DFMMachining_MillingIssue.hxx:33
Described the Narrow Pocket minimum size issue found during DFM analysis for Machining Milling operat...
Definition DFMMachining_NarrowRegionInPocketIssue.hxx:33
Describes non perpendicular hole issues found during cnc machining drilling design analysis.
Definition DFMMachining_NonPerpendicularHoleIssue.hxx:29
Describes non perpendicular milled part shape issue found during cnc machining milling design analysi...
Definition DFMMachining_NonPerpendicularMilledPartShapeIssue.hxx:33
Describes non standard diameter hole issues found during cnc machining drilling design analysis.
Definition DFMMachining_NonStandardDiameterHoleIssue.hxx:29
Describes non standard drill point angle blind hole issues found during cnc machining drilling design...
Definition DFMMachining_NonStandardDrillPointAngleBlindHoleIssue.hxx:29
Describes non standard radius milled part floor fillet issue found during cnc machining milling desig...
Definition DFMMachining_NonStandardRadiusMilledPartFloorFilletIssue.hxx:33
Describes asymmetric axial slot issue found during cnc machining turning design analysis.
Definition DFMMachining_NonSymmetricalAxialSlotIssue.hxx:29
Describes partial hole issues found during cnc machining drilling design analysis.
Definition DFMMachining_PartialHoleIssue.hxx:28
Describes small depth blind bored hole relief found during cnc machining turning design analysis.
Definition DFMMachining_SmallDepthBlindBoredHoleReliefIssue.hxx:32
Describes small diameter hole issues found during cnc machining drilling design analysis.
Definition DFMMachining_SmallDiameterHoleIssue.hxx:29
Describes internal corner radius issues found during cnc machining milling design analysis.
Definition DFMMachining_SmallRadiusMilledPartInternalCornerIssue.hxx:33
Describes internal corner radius issues found during cnc machining turning design analysis.
Definition DFMMachining_SmallRadiusTurnedPartInternalCornerIssue.hxx:33
Describes wall with small thickness issues found during cnc machining milling design analysis.
Definition DFMMachining_SmallWallThicknessIssue.hxx:33
Describes square form keyway issue found during cnc machining turning design analysis.
Definition DFMMachining_SquareEndKeywayIssue.hxx:30
Defines parameters used in cnc machining turning design analysis.
Definition DFMMachining_TurningAnalyzerParameters.hxx:35
Defines a list of features.
Definition MTKBase_FeatureList.hxx:36
size_t Size() const
Returns the number of elements in the list.
Definition MTKBase_FeatureList.cxx:88
void Append(const MTKBase_Feature &theFeature)
Adds a feature to the list.
Definition MTKBase_FeatureList.cxx:56
Defines data used in Machining analysis.
Definition Machining_Data.hxx:36
Provides an interface to recognizing machining features tool.
Definition Machining_FeatureRecognizer.hxx:45
MTKBase_FeatureList Perform(const ModelData::Solid &theSolid, const cadex::ProgressStatus &theProgressStatus=cadex::ProgressStatus())
Runs features recognition process.
Definition Machining_FeatureRecognizer.cxx:285
const Machining_FeatureRecognizerParameters & Parameters() const
Returns parameters.
Definition Machining_FeatureRecognizer.cxx:304
void SetOperation(Machining_OperationType theOperation)
Definition Machining_FeatureRecognizerParameters.cxx:205
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
Machining_OperationType
Defines an operation type in machining.
Definition Machining_OperationType.hxx:28
@ Machining_OT_Undefined
Unknown operation type.
Definition Machining_OperationType.hxx:31
@ Machining_OT_Milling
Milling operation type.
Definition Machining_OperationType.hxx:29
@ Machining_OT_LatheMilling
Lathe + Milling operation type.
Definition Machining_OperationType.hxx:30