using System;
using System.Collections.Generic;
namespace poly_projector
{
class Program
{
static int Main(string[] args)
{
string aKey = MTKLicenseKey.Value();
if (!LicenseManager.Activate(aKey))
{
Console.WriteLine("Failed to activate Manufacturing Toolkit license.");
return 1;
}
if (args.Length != 2)
{
Console.WriteLine("Usage: poly_projector <input_file> <output_folder>, where:");
Console.WriteLine(" <input_file> is a name of the file to be read");
Console.WriteLine(" <output_folder> is a folder to save projections to (must end with '/' or '\\\\')");
return 1;
}
UTF16String aSource = new UTF16String(args[0]);
string anOutFolder = args[1];
Model aModel = new Model();
ModelReader aReader = new ModelReader();
if (!aReader.Read(aSource, aModel))
{
Console.WriteLine("Failed to read the file " + args[0]);
return 1;
}
Console.WriteLine("Model: " + aModel.Name());
Console.WriteLine("");
var aProjectionDataCollection = new List<KeyValuePair<UTF16String, Direction>>
{
new KeyValuePair<UTF16String, Direction>(new UTF16String("X"), Direction.XDir()),
new KeyValuePair<UTF16String, Direction>(new UTF16String("Y"), Direction.YDir()),
new KeyValuePair<UTF16String, Direction>(new UTF16String("Z"), Direction.ZDir())
};
foreach (var aProjectionData in aProjectionDataCollection)
{
UTF16String aProjectionName = aProjectionData.Key;
Direction aProjectionDirection = aProjectionData.Value;
UTF16String anOutFilePath = new UTF16String(anOutFolder + "projection_" + aProjectionName + ".stl");
if (ComputeProjection(aModel, aProjectionDirection, aProjectionName, anOutFilePath))
{
Console.WriteLine("The output projection is written: " + anOutFilePath);
}
else
{
Console.WriteLine("Failed to save the result: " + anOutFilePath);
}
Console.WriteLine("");
}
return 0;
}
private static void PrintProjectionInfo(Part thePart,
UTF16String theDirectionName,
Projector_Projection theProjection)
{
Console.WriteLine("Part [" + thePart.Name() + "], projection " + theDirectionName + ":");
if (theProjection != null)
{
Console.WriteLine(" area = " + theProjection.Area() + " mm");
Console.WriteLine(" outer perimeter = " + theProjection.OuterPerimeter() + " mm");
}
else
{
Console.WriteLine(" undefined");
}
Console.WriteLine("");
}
private class ProjectionComputer : ModelElementVoidVisitor
{
public ProjectionComputer(Direction theDirection,
UTF16String theDirectionName)
{
myDirection = theDirection;
myDirectionName = theDirectionName;
}
public bool SaveProjection(UTF16String theFileName)
{
if (myPartProjections.Count == 0)
{
return false;
}
Part aPart = new Part(new UTF16String("Projections"));
foreach (Projector_Projection aProjection in myPartProjections)
{
MeshBody aMeshBody = new MeshBody(aProjection.Mesh());
aPart.AddBody(aMeshBody);
}
Model anOutModel = new Model(new UTF16String("Projector"));
anOutModel.AddRoot(aPart);
ModelWriter aWriter = new ModelWriter();
return aWriter.Write(anOutModel, theFileName);
}
public override void Apply(Part thePart)
{
Projector_Projection aProjection = myProjector.Perform(thePart, myDirection);
PrintProjectionInfo(thePart, myDirectionName, aProjection);
if (aProjection != null)
{
myPartProjections.Add(aProjection);
}
}
private readonly Direction myDirection;
private readonly UTF16String myDirectionName;
private Projector_PolyProjector myProjector = new Projector_PolyProjector();
private List<Projector_Projection> myPartProjections = new List<Projector_Projection>();
}
static bool ComputeProjection(Model theModel,
Direction theDirection,
UTF16String theDirectionName,
UTF16String theOutFileName)
{
ProjectionComputer aComputer = new ProjectionComputer(theDirection, theDirectionName);
theModel.Accept(aComputer);
return aComputer.SaveProjection(theOutFileName);
}
}
}
Contains classes, types, enums, and functions related to geometric entities.
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.