Hide menu
Loading...
Searching...
No Matches
MTKConverter/MTKConverter.java

Refer to the MTK Converter Example.

MTKConverter_PartProcessor.java

// ****************************************************************************
// $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.
//
// ****************************************************************************
import cadex.*;
import cadex.ModelData.*;
import java.util.ArrayList;
class MTKConverter_ProcessData {
protected MTKConverter_ProcessData(Part thePart) {
myPart = thePart;
}
public Part myPart;
}
abstract class MTKConverter_PartProcessor extends ModelElementVoidVisitor {
protected MTKConverter_PartProcessor() {
myData = new ArrayList<MTKConverter_ProcessData>();
}
public void Apply(Part thePart) {
boolean aPartWasProcessed = false;
MTKConverter_ProcessData aProcessData = CreateProcessData(thePart);
cadex.Collections.BodyList aBodyList = thePart.Bodies();
for (int i = 0; i < aBodyList.size(); ++i) {
Body aBody = aBodyList.get(i);
ShapeIterator aShapeIt = new ShapeIterator(aBody);
while (aShapeIt.HasNext()) {
Shape aShape = aShapeIt.Next();
if (aShape.Type() == ShapeType.Solid) {
ProcessSolid(aProcessData, Solid.Cast(aShape));
aPartWasProcessed = true;
} else if (aShape.Type() == ShapeType.Shell) {
ProcessShell(aProcessData, Shell.Cast(aShape));
aPartWasProcessed = true;
}
}
}
if (aPartWasProcessed) {
PostProcessPart(thePart);
myData.add(aProcessData);
}
}
public abstract MTKConverter_ProcessData CreateProcessData(Part thePart);
public abstract void ProcessShell(MTKConverter_ProcessData theProcessData, Shell theShell);
public abstract void ProcessSolid(MTKConverter_ProcessData theProcessData, Solid theSolid);
public abstract void PostProcessPart(Part thePart);
public ArrayList<MTKConverter_ProcessData> myData;
}
abstract class MTKConverter_VoidPartProcessor extends MTKConverter_PartProcessor {
public MTKConverter_VoidPartProcessor() {
super();
}
public void ProcessSolid(Part thePart, Solid theSolid) {
}
public void ProcessShell(MTKConverter_ProcessData theProcessData, Shell theShell) {
}
public void PostProcessPart(Part thePart) {
}
}
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
Definition AngleUnit.cs:12
ShapeType
Defines shape type.
Definition ShapeType.cs:17
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition BaseObject.cs:12

MTKConverter_MachiningProcessor.java

// ****************************************************************************
// $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.
//
// ****************************************************************************
import cadex.*;
import cadex.ModelData.*;
class MTKConverter_MachiningData extends MTKConverter_ProcessData {
public MTKConverter_MachiningData(Part thePart) {
super(thePart);
myFeatureList = new MTKBase_FeatureList();
myIssueList = new MTKBase_FeatureList();
}
public MTKBase_FeatureList myFeatureList;
public MTKBase_FeatureList myIssueList;
public Machining_OperationType myOperation;
}
class MTKConverter_MachiningProcessor extends MTKConverter_VoidPartProcessor {
public MTKConverter_MachiningProcessor(Machining_OperationType theOperation) {
super();
myOperation = theOperation;
}
public MTKConverter_ProcessData CreateProcessData(Part thePart) {
return new MTKConverter_MachiningData(thePart);
}
public void ProcessSolid(MTKConverter_ProcessData theProcessData, Solid theSolid) {
MTKConverter_MachiningData aMachiningData = (MTKConverter_MachiningData) theProcessData;
aMachiningData.myOperation = myOperation;
Machining_FeatureRecognizer aFeatureRecognizer = new Machining_FeatureRecognizer();
aFeatureRecognizer.Parameters().SetOperation(myOperation);
Machining_Analyzer anAnalyzer = new Machining_Analyzer();
anAnalyzer.AddTool(aFeatureRecognizer);
Machining_Data aData = anAnalyzer.Perform(theSolid);
if (aData.IsEmpty()) {
return;
}
//features
aMachiningData.myFeatureList.Append(aData.FeatureList());
//issues
DFMMachining_DrillingAnalyzerParameters aDrillingParameters = new DFMMachining_DrillingAnalyzerParameters();
DFMMachining_Analyzer aDrillingAnalyzer = new DFMMachining_Analyzer(aDrillingParameters);
aMachiningData.myIssueList.Append(aDrillingAnalyzer.Perform(theSolid, aData));
DFMMachining_MillingAnalyzerParameters aMillingParameters = new DFMMachining_MillingAnalyzerParameters();
DFMMachining_Analyzer aMillingAnalyzer = new DFMMachining_Analyzer(aMillingParameters);
MTKBase_FeatureList aMillingIssueList = aMillingAnalyzer.Perform(theSolid, aData);
for (long i = 0; i < aMillingIssueList.Size(); ++i) {
MTKBase_Feature anIssue = aMillingIssueList.Feature(i);
if (myOperation == Machining_OperationType.Machining_OT_LatheMilling
&& !DFMMachining_DeepPocketIssue.CompareType(anIssue)) {
continue;
}
aMachiningData.myIssueList.Append(anIssue);
}
if (myOperation == Machining_OperationType.Machining_OT_LatheMilling) {
DFMMachining_TurningAnalyzerParameters aTurninigParameters = new DFMMachining_TurningAnalyzerParameters();
DFMMachining_Analyzer aTurningAnalyzer = new DFMMachining_Analyzer(aTurninigParameters);
MTKBase_FeatureList aTurningIssueList = aTurningAnalyzer.Perform(theSolid, aData);
for (long i = 0; i < aTurningIssueList.Size(); ++i) {
MTKBase_Feature anIssue = aTurningIssueList.Feature(i);
aMachiningData.myIssueList.Append(anIssue);
}
}
}
private Machining_OperationType myOperation;
}
Machining_OperationType
Defines an operation type in machining.
Definition Machining_OperationType.cs:19

MTKConverter_SheetMetalProcessor.java

// ****************************************************************************
// $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.
//
// ****************************************************************************
import cadex.*;
import cadex.ModelData.*;
import java.util.ArrayList;
class MTKConverter_UnfoldedPartData {
public MTKConverter_UnfoldedPartData() {
myFlatPatterns = new ArrayList<SheetMetal_FlatPattern>();
myIssueList = new MTKBase_FeatureList();
}
public boolean IsInit() {
return !myFlatPatterns.isEmpty();
}
public ArrayList<SheetMetal_FlatPattern> myFlatPatterns;
public MTKBase_FeatureList myIssueList;
}
class MTKConverter_SheetMetalData extends MTKConverter_ProcessData {
public MTKConverter_SheetMetalData(Part thePart) {
super(thePart);
myFeatureList = new MTKBase_FeatureList();
myIssueList = new MTKBase_FeatureList();
myUnfoldedPartData = new MTKConverter_UnfoldedPartData();
}
public boolean myIsSheetMetalPart = false;
public MTKBase_FeatureList myFeatureList;
public MTKBase_FeatureList myIssueList;
public MTKConverter_UnfoldedPartData myUnfoldedPartData;
}
class MTKConverter_SheetMetalProcessor extends MTKConverter_VoidPartProcessor {
public MTKConverter_SheetMetalProcessor(Model theUnfoldedModel) {
super();
myAnalyzer = new SheetMetal_Analyzer();
myAnalyzer.AddTool(new SheetMetal_FeatureRecognizer());
myAnalyzer.AddTool(new SheetMetal_Unfolder());
myUnfoldedModel = theUnfoldedModel;
myCurrentUnfoldedBody = new SheetBody();
}
public MTKConverter_ProcessData CreateProcessData(Part thePart) {
return new MTKConverter_SheetMetalData(thePart);
}
public void ProcessSolid(MTKConverter_ProcessData theProcessData, Solid theSolid) {
SheetMetal_Data anSMData = myAnalyzer.Perform(theSolid);
Process(theProcessData, anSMData);
}
public void ProcessShell(MTKConverter_ProcessData theProcessData, Shell theShell) {
SheetMetal_Data anSMData = myAnalyzer.Perform(theShell);
Process(theProcessData, anSMData);
}
public void PostProcessPart(Part thePart) {
if (myCurrentUnfoldedBody.Shapes().isEmpty()) {
return;
}
Part anUnfoldedPart = new Part(thePart.Name());
anUnfoldedPart.SetUuid(thePart.Uuid());
anUnfoldedPart.AddBody(myCurrentUnfoldedBody);
myUnfoldedModel.AddRoot(anUnfoldedPart);
myCurrentUnfoldedBody = new SheetBody();
}
public void Process(MTKConverter_ProcessData theProcessData, SheetMetal_Data theData) {
if (theData.IsEmpty()) {
return;
}
MTKConverter_SheetMetalData anSMData = (MTKConverter_SheetMetalData) theProcessData;
anSMData.myIsSheetMetalPart = true;
anSMData.myFeatureList.Append(theData.FeatureList());
SheetMetal_FlatPattern aFlatPattern = theData.FlatPattern();
Shell anUnfoldedShell = !aFlatPattern.IsNull() ? aFlatPattern.UnfoldedShell() : null;
MTKConverter_UnfoldedPartData anUnfoldedData = anSMData.myUnfoldedPartData;
if (anUnfoldedShell != null) {
myCurrentUnfoldedBody.Append(anUnfoldedShell);
anUnfoldedData.myFlatPatterns.add(aFlatPattern);
}
DFMSheetMetal_Analyzer aDFMAnalyzer = new DFMSheetMetal_Analyzer();
MTKBase_FeatureList anIssueList = aDFMAnalyzer.Perform(theData);
for (long i = 0; i < anIssueList.Size(); ++i) {
MTKBase_Feature anIssue = anIssueList.Feature(i);
if (anUnfoldedData.IsInit()
&& (DFMSheetMetal_FlatPatternInterferenceIssue.CompareType(anIssue)
|| DFMSheetMetal_NonStandardSheetSizeIssue.CompareType(anIssue)
|| DFMSheetMetal_NonStandardSheetThicknessIssue.CompareType(anIssue))) {
anUnfoldedData.myIssueList.Append(anIssue);
} else {
anSMData.myIssueList.Append(anIssue);
}
}
}
private SheetMetal_Analyzer myAnalyzer;
private Model myUnfoldedModel;
private SheetBody myCurrentUnfoldedBody;
}

MTKConverter_Report.java

// ****************************************************************************
// $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.
//
// ****************************************************************************
import cadex.*;
import cadex.ModelData.*;
import cadex.Geom.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
class MTKConverter_Point {
public MTKConverter_Point(double theX, double theY, double theZ) {
this.X = theX;
this.Y = theY;
this.Z = theZ;
}
public String toString() {
return "(" + FormattedString(X) + ", " + FormattedString(Y) + ", " + FormattedString(Z) + ")";
}
private String FormattedString(double theValue) {
DecimalFormatSymbols aDFS = new DecimalFormatSymbols();
aDFS.setDecimalSeparator('.');
DecimalFormat aDF = new DecimalFormat("0.00", aDFS);
return aDF.format(theValue);
}
public double X;
public double Y;
public double Z;
}
class MTKConverter_Report {
public MTKConverter_Report() {
myData = new ArrayList<MTKConverter_ProcessData>();
}
public void AddData(MTKConverter_ProcessData theData) {
myData.add(theData);
}
public boolean WriteToJSON(UTF16String thePath) {
String aPath = thePath.toString();
File aFile = new File(aPath);
if (aFile.exists()) {
aFile.delete();
}
try {
PrintWriter aStream = new PrintWriter(new BufferedWriter(new FileWriter(aPath)));
JSONWriter aWriter = new JSONWriter(aStream, 0);
aWriter.OpenSection();
aWriter.WriteData("version", "1");
if (myData.isEmpty()) {
aWriter.WriteData("error", "The model doesn't contain any parts.");
} else {
aWriter.OpenArraySection("parts");
for (MTKConverter_ProcessData aProcessData : myData) {
aWriter.OpenSection();
WritePartProcessData(aWriter, aProcessData);
aWriter.CloseSection();
}
aWriter.CloseArraySection();
}
aWriter.CloseSection();
aStream.close();
} catch (Exception anE) {
return false;
}
return true;
}
private boolean WriteFeatures(JSONWriter theWriter, String theGroupName, String theSubgroupName, MTKBase_FeatureList theFeatures,
String theMessageForEmptyList) {
theWriter.OpenSection(theSubgroupName);
theWriter.WriteData("name", theGroupName);
if (theFeatures.IsEmpty()) {
theWriter.WriteData("message", theMessageForEmptyList);
} else {
JSONSerializerParameters aParams = new JSONSerializerParameters();
aParams.SetStartIndentLevel(theWriter.NestingLevel());
JSONSerializer aJSONSerializer = new JSONSerializer(aParams);
String aFeaturesJSON = aJSONSerializer.Serialize(theFeatures);
theWriter.WriteRawData(aFeaturesJSON);
}
theWriter.CloseSection();
return true;
}
private String MachiningProcessName(Machining_OperationType theOperation) {
switch (theOperation) {
return "CNC Machining Milling";
return "CNC Machining Lathe+Milling";
default:
break;
}
return "CNC Machining";
}
private boolean HasShapes(cadex.Collections.BodyList theBodies, ShapeType theType) {
for (Body aBody : theBodies) {
ShapeIterator aShapeIt = new ShapeIterator(aBody, theType);
if (aShapeIt.HasNext()) {
return true;
}
}
return false;
}
private void WriteThicknessNode(JSONWriter theWriter, String theParamName, double theParamValue,
PointPair thePoints, String theNodeName) {
Point aFirstPoint = thePoints.First;
Point aSecondPoint = thePoints.Second;
theWriter.OpenSection(theNodeName);
theWriter.WriteData("name", theParamName);
theWriter.WriteData("units", "mm");
theWriter.WriteData("value", theParamValue);
theWriter.WriteData("firstPoint", new MTKConverter_Point(aFirstPoint.X(), aFirstPoint.Y(), aFirstPoint.Z()));
theWriter.WriteData("secondPoint", new MTKConverter_Point(aSecondPoint.X(), aSecondPoint.Y(), aSecondPoint.Z()));
theWriter.CloseSection();
}
private void WriteUnfoldedPartFeatures(JSONWriter theWriter, MTKConverter_UnfoldedPartData theData) {
theWriter.OpenSection("featureRecognitionUnfolded");
theWriter.WriteData("name", "Feature Recognition");
if (theData.IsInit()) {
JSONSerializerParameters aParams = new JSONSerializerParameters();
aParams.SetStartIndentLevel(4);
JSONSerializer aJSONSerializer = new JSONSerializer(aParams);
String aFeaturesJSON = aJSONSerializer.Serialize(theData.myFlatPatterns.get(0));
theWriter.WriteRawData(aFeaturesJSON);
} else {
theWriter.WriteData("message", "Unfolded part wasn't generated.");
}
theWriter.CloseSection();
}
private void WritePartProcessData(JSONWriter theWriter, MTKConverter_ProcessData theProcessData) {
boolean aRes = false;
theWriter.WriteData("partId", theProcessData.myPart.Uuid());
String anErrorMsg = "An error occurred while processing the part.";
if (theProcessData instanceof MTKConverter_MachiningData) {
MTKConverter_MachiningData aMD = (MTKConverter_MachiningData) theProcessData;
theWriter.WriteData("process", MachiningProcessName(aMD.myOperation));
if (!aMD.myFeatureList.IsEmpty()) {
WriteFeatures(theWriter, "Feature Recognition", "featureRecognition", aMD.myFeatureList, "");
WriteFeatures(theWriter, "Design for Manufacturing", "dfm", aMD.myIssueList,
"Part contains no DFM improvement suggestions.");
aRes = true;
} else if (!HasShapes(aMD.myPart.Bodies(), ShapeType.Solid)) {
anErrorMsg = "The part can't be analyzed due to lack of: BRep representation or solids in BRep representation.";
}
} else if (theProcessData instanceof MTKConverter_MoldingData) {
MTKConverter_MoldingData aMoldingData = (MTKConverter_MoldingData) theProcessData;
theWriter.WriteData("process", "Molding Analysis");
if (!aMoldingData.myFeatureList.IsEmpty()) {
WriteFeatures(theWriter, "Feature Recognition", "featureRecognition", aMoldingData.myFeatureList, "");
WriteFeatures(theWriter, "Design for Manufacturing", "dfm", aMoldingData.myIssueList,
"Part contains no DFM improvement suggestions.");
aRes = true;
} else if (!HasShapes(aMoldingData.myPart.Bodies(), ShapeType.Solid)) {
anErrorMsg = "The part can't be analyzed due to lack of: " +
"BRep representation, solids in BRep representation or Poly representations.";
}
} else if (theProcessData instanceof MTKConverter_SheetMetalData) {
MTKConverter_SheetMetalData aSMD = (MTKConverter_SheetMetalData) theProcessData;
theWriter.WriteData("process", "Sheet Metal");
if (aSMD.myIsSheetMetalPart) {
WriteFeatures(theWriter, "Feature Recognition", "featureRecognition", aSMD.myFeatureList,
"Part contains no features.");
WriteFeatures(theWriter, "Design for Manufacturing", "dfm", aSMD.myIssueList,
"Part contains no DFM improvement suggestions.");
MTKConverter_UnfoldedPartData anUnfoldedPartData = aSMD.myUnfoldedPartData;
WriteUnfoldedPartFeatures(theWriter, anUnfoldedPartData);
if (anUnfoldedPartData.IsInit()) {
WriteFeatures(theWriter, "Design for Manufacturing", "dfmUnfolded", anUnfoldedPartData.myIssueList,
"Unfolded part contains no DFM improvement suggestions.");
}
aRes = true;
} else if (!HasShapes(aSMD.myPart.Bodies(), ShapeType.Solid)
&& !HasShapes(aSMD.myPart.Bodies(), ShapeType.Shell)) {
anErrorMsg = "The part can't be analyzed due to lack of: BRep representation, solids and shells in BRep representation.";
} else {
anErrorMsg = "The part wasn't recognized as a sheet metal part.";
}
} else if (theProcessData instanceof MTKConverter_WallThicknessData) {
MTKConverter_WallThicknessData aWTD = (MTKConverter_WallThicknessData) theProcessData;
theWriter.WriteData("process", "Wall Thickness Analysis");
if (aWTD.myIsInit) {
WriteThicknessNode(theWriter, "Minimum Thickness", aWTD.myMinThickness, aWTD.myMinThicknessPoints, "minThickness");
WriteThicknessNode(theWriter, "Maximum Thickness", aWTD.myMaxThickness, aWTD.myMaxThicknessPoints, "maxThickness");
aRes = true;
} else if (!HasShapes(aWTD.myPart.Bodies(), ShapeType.Solid)) {
anErrorMsg = "The part can't be analyzed due to lack of: " +
"BRep representation, solids in BRep representation.";
}
} else {
anErrorMsg = "Unrecognized process";
}
if (!aRes) {
theWriter.WriteData("error", anErrorMsg);
}
}
private ArrayList<MTKConverter_ProcessData> myData;
}
Definition BodyList.cs:15
Serializes MTK entities into a JSON report.
Definition JSONSerializer.cs:17
Configuration for JSON serialization.
Definition JSONSerializerParameters.cs:20
Definition ArrayDouble2.cs:12
Contains classes, types, enums, and functions related to geometric entities.
Definition Axis1d.cs:12
Contains utility classes that can be useful for debugging or configuring global settings.
Definition JSONSerializer.cs:12
@ Machining_OT_LatheMilling
Lathe + Milling operation type.
@ Machining_OT_Milling
Milling operation type.

MTKConverter_Application.java

// ****************************************************************************
// $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.
//
// ****************************************************************************
import cadex.*;
import cadex.View.*;
import cadex.ModelData.*;
import java.io.File;
import java.util.HashMap;
enum MTKConverter_ReturnCode {
// General codes
MTKConverter_RC_OK(0),
MTKConverter_RC_UnknownError(1),
MTKConverter_RC_GeneralException(2),
MTKConverter_RC_NoValidLicense(3),
MTKConverter_RC_InvalidArgumentsNumber(4),
MTKConverter_RC_InvalidArgument(5),
// Import errors
MTKConverter_RC_UnsupportedVersion(100),
MTKConverter_RC_UnexpectedFormat(101),
MTKConverter_RC_UnsupportedFileVariant(102),
MTKConverter_RC_ImportError(103),
// Process errors
MTKConverter_RC_ProcessError(200),
// Export errors
MTKConverter_RC_ExportError(300);
private MTKConverter_ReturnCode(int theValue) {
this.myValue = theValue;
}
public int GetValue() {
return myValue;
}
private final int myValue;
}
enum MTKConverter_ProcessType {
MTKConverter_PT_Undefined,
MTKConverter_PT_WallThickness,
MTKConverter_PT_MachiningMilling,
MTKConverter_PT_MachiningTurning,
MTKConverter_PT_Molding,
MTKConverter_PT_SheetMetal
}
//parse and execute command line
enum Mode {NeutralMode, ImportMode, ProcessMode, ExportMode}
class MTKConverter_Application {
public MTKConverter_Application() {
}
public MTKConverter_ReturnCode Run(String[] args) {
if (args.length == 1 ||
(args[0].equals("-?")) || (args[0].equals("/?")) ||
(args[0].equals("-h")) || (args[0].equals("--help"))) {
PrintUsage();
return MTKConverter_ReturnCode.MTKConverter_RC_OK;
}
if (args.length < 6) {
System.out.println("Invalid number of arguments. Please use \"-h\" or \"--help\" for usage information.");
return MTKConverter_ReturnCode.MTKConverter_RC_InvalidArgumentsNumber;
}
Model aModel = new Model();
Model aProcessModel = new Model();
Mode aMode = Mode.NeutralMode;
MTKConverter_Report aReport = new MTKConverter_Report();
MTKConverter_ReturnCode aRes = MTKConverter_ReturnCode.MTKConverter_RC_OK;
boolean aToGenerateScreenshot = true;
for (int i = 0; (i < args.length) && (aRes == MTKConverter_ReturnCode.MTKConverter_RC_OK); ++i) {
String anArgument = args[i];
if (anArgument.equals("--no-screenshot")) {
aToGenerateScreenshot = false;
} else if (anArgument.equals("-i")) {
aMode = Mode.ImportMode;
} else if (anArgument.equals("-p")) {
aMode = Mode.ProcessMode;
} else if (anArgument.equals("-e")) {
aMode = Mode.ExportMode;
} else {
try {
if (aMode == Mode.ImportMode) {
aRes = Import(anArgument, aModel);
} else if (aMode == Mode.ProcessMode) {
aRes = Process(anArgument, aModel, aReport, aProcessModel);
} else if (aMode == Mode.ExportMode) {
aRes = Export(anArgument, aModel, aToGenerateScreenshot, aReport, aProcessModel);
} else {
System.out.println("ERROR!: Invalid argument " + anArgument + ". Exiting");
System.out.println("Type \"-h\" for help.");
return MTKConverter_ReturnCode.MTKConverter_RC_InvalidArgument;
}
System.out.println("Done.");
} catch (Exception anE) {
System.out.println("Failed.\nERROR: Unhandled exception caught.");
return MTKConverter_ReturnCode.MTKConverter_RC_GeneralException;
}
}
}
return aRes;
}
public void PrintUsage() {
System.out.println("Usage:");
System.out.println("MTKConverter -i <import_file> -p <process> --no-screenshot -e <export_folder>\n");
System.out.println("Arguments:");
System.out.println(" <import_file> - import file name");
System.out.println(" <process> - manufacturing process or algorithm name");
System.out.println(" <export_folder> - export folder name");
System.out.println(" --no-screenshot - disable screenshot generation (optional)");
System.out.println("Example:");
System.out.println("MTKConverter -i C:\\models\\test.step -p machining_milling -e C:\\models\\test");
System.out.println("\nRecognized processes:");
System.out.println(" machining_milling:\t CNC Machining Milling feature recognition and DFM analysis");
System.out.println(" machining_turning:\t CNC Machining Lathe+Milling feature recognition and DFM analysis");
System.out.println(" molding :\t Molding feature recognition and DFM analysis");
System.out.println(" sheet_metal :\t Sheet Metal feature recognition, unfolding and DFM analysis");
}
private static MTKConverter_ProcessType ProcessType(String theOperationStr) {
HashMap<String, MTKConverter_ProcessType> aProcessMap = new HashMap<>();
aProcessMap.put("wall_thickness", MTKConverter_ProcessType.MTKConverter_PT_WallThickness);
aProcessMap.put("machining_milling", MTKConverter_ProcessType.MTKConverter_PT_MachiningMilling);
aProcessMap.put("machining_turning", MTKConverter_ProcessType.MTKConverter_PT_MachiningTurning);
aProcessMap.put("molding", MTKConverter_ProcessType.MTKConverter_PT_Molding);
aProcessMap.put("sheet_metal", MTKConverter_ProcessType.MTKConverter_PT_SheetMetal);
MTKConverter_ProcessType aProcess = aProcessMap.getOrDefault(theOperationStr, MTKConverter_ProcessType.MTKConverter_PT_Undefined);
return aProcess;
}
private MTKConverter_ReturnCode Import(String theFilePath, Model theModel) {
UTF16String aFilePath = new UTF16String(theFilePath);
System.out.print("Importing " + theFilePath + "...");
ModelReader aReader = new ModelReader();
if (!aReader.Read(aFilePath, theModel)) {
System.out.println("\nERROR: Failed to import " + theFilePath + ". Exiting");
return MTKConverter_ReturnCode.MTKConverter_RC_ImportError;
}
return MTKConverter_ReturnCode.MTKConverter_RC_OK;
}
private boolean CreateOriginModelThumbnail(UTF16String theFilePath, Model theModel) {
ImageWriter aWriter = new ImageWriter();
ImageWriterParameters aParameters = aWriter.Parameters();
aParameters.SetImageHeight(800);
aParameters.SetImageWidth(600);
aParameters.SetViewCameraProjection(CameraProjectionType.Perspective);
aParameters.SetViewCameraPosition(CameraPositionType.Default);
aParameters.SetViewIsFitAll(true);
aParameters.SetViewAntialiasing(AntialiasingMode.High);
aParameters.SetViewBackground(new ColorBackgroundStyle(new Color(255, 255, 255)));
aWriter.SetParameters(aParameters);
boolean aRes = aWriter.WriteFile(theModel, theFilePath);
return aRes;
}
private void ApplyProcessorToModel(Model theModel, MTKConverter_Report theReport, MTKConverter_PartProcessor theProcessor) {
ModelElementUniqueVisitor aVisitor = new ModelElementUniqueVisitor(theProcessor);
theModel.Accept(aVisitor);
for (MTKConverter_ProcessData i : theProcessor.myData) {
theReport.AddData(i);
}
}
private MTKConverter_ReturnCode Process(String theProcess, Model theModel,
MTKConverter_Report theReport, Model theProcessModel) {
System.out.print("Processing " + theProcess + "...");
theModel.AssignUuids();
MTKConverter_ProcessType aProcessType = ProcessType(theProcess);
switch (aProcessType) {
case MTKConverter_PT_WallThickness: {
MTKConverter_WallThicknessProcessor aProcessor = new MTKConverter_WallThicknessProcessor(800);
ApplyProcessorToModel(theModel, theReport, aProcessor);
break;
}
case MTKConverter_PT_MachiningMilling: {
MTKConverter_MachiningProcessor aProcessor = new MTKConverter_MachiningProcessor(Machining_OperationType.Machining_OT_Milling);
ApplyProcessorToModel(theModel, theReport, aProcessor);
break;
}
case MTKConverter_PT_MachiningTurning: {
MTKConverter_MachiningProcessor aProcessor = new MTKConverter_MachiningProcessor(Machining_OperationType.Machining_OT_LatheMilling);
ApplyProcessorToModel(theModel, theReport, aProcessor);
break;
}
case MTKConverter_PT_Molding: {
UTF16String aProcessModelName = new UTF16String(theModel.Name() + "_extra");
theProcessModel.SetName(aProcessModelName);
MTKConverter_MoldingProcessor aProcessor = new MTKConverter_MoldingProcessor(theProcessModel);
ApplyProcessorToModel(theModel, theReport, aProcessor);
break;
}
case MTKConverter_PT_SheetMetal: {
UTF16String aProcessModelName = new UTF16String(theModel.Name() + "_unfolded");
theProcessModel.SetName(aProcessModelName);
MTKConverter_SheetMetalProcessor aProcessor = new MTKConverter_SheetMetalProcessor(theProcessModel);
ApplyProcessorToModel(theModel, theReport, aProcessor);
break;
}
case MTKConverter_PT_Undefined:
default:
return MTKConverter_ReturnCode.MTKConverter_RC_InvalidArgument;
}
return MTKConverter_ReturnCode.MTKConverter_RC_OK;
}
private MTKConverter_ReturnCode Export(String theFolderPath, Model theModel, boolean theToGenerateScreenshot,
MTKConverter_Report theReport, Model theProcessModel) {
System.out.print("Exporting " + theFolderPath + "...");
File directory = new File(theFolderPath);
directory.mkdirs();
UTF16String aModelPath = new UTF16String(theFolderPath + "/" + theModel.Name() + ".mtkweb" + "/scenegraph.mtkweb");
if (!theModel.Save(aModelPath, Model.FileFormatType.MTKWEB)) {
System.out.println("\nERROR: Failed to export " + aModelPath + ". Exiting");
return MTKConverter_ReturnCode.MTKConverter_RC_ExportError;
}
UTF16String aThumbnailPath = new UTF16String(theFolderPath + "/thumbnail.png");
if (theToGenerateScreenshot && !CreateOriginModelThumbnail(aThumbnailPath, theModel)) {
System.out.println("\nERROR: Failed to create thumbnail " + aThumbnailPath + ". Exiting");
return MTKConverter_ReturnCode.MTKConverter_RC_ExportError;
}
if (!theProcessModel.IsEmpty()) {
UTF16String aProcessModelPath = new UTF16String(theFolderPath + "/" + theProcessModel.Name() + ".mtkweb" + "/scenegraph.mtkweb");
if (!theProcessModel.Save(aProcessModelPath, Model.FileFormatType.MTKWEB)) {
System.out.println("\nERROR: Failed to export " + aProcessModelPath + ". Exiting");
return MTKConverter_ReturnCode.MTKConverter_RC_ExportError;
}
}
UTF16String aJsonPath = new UTF16String(theFolderPath + "/process_data.json");
if (!theReport.WriteToJSON(aJsonPath)) {
System.out.println("\nERROR: Failed to create JSON file " + aJsonPath + ". Exiting");
return MTKConverter_ReturnCode.MTKConverter_RC_ExportError;
}
return MTKConverter_ReturnCode.MTKConverter_RC_OK;
}
}
Contains classes, types, enums, and functions related to image generation.
Definition AntialiasingMode.cs:12

MTKConverter.java

// ****************************************************************************
// $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.
//
// ****************************************************************************
import cadex.*;
public class MTKConverter {
static {
try {
System.loadLibrary("CadExMTK");
System.loadLibrary("MTKView");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String[] args) {
String aKey = MTKLicenseKey.Value();
// Activate the license (the key must be defined in MTKLicenseKey.java)
if (!LicenseManager.Activate(aKey)) {
System.out.println("Failed to activate Manufacturing Toolkit license.");
System.exit(1);
}
MTKConverter_Application anApp = new MTKConverter_Application();
System.exit(anApp.Run(args).GetValue());
}
}