Hi.Sample/Machining/DemoBuildMachiningProject.cs

227 lines
8.4 KiB
C#

using System;
using System.Collections.Generic;
using Hi.Milling.Apts;
using Hi.Common.XmlUtils;
using Hi.Geom;
using Hi.Machining;
using Hi.Mech.Topo;
using Hi.Milling.Cutters;
using Hi.Milling.FluteContours;
using Hi.MillingForces.Fittings;
using Hi.MillingMech.MillingTools;
using Hi.NcMech.Fixtures;
using Hi.NcMech.Holders;
using Hi.NcMech.Workpieces;
using Hi.NcMech.Xyzabc;
using Hi.NcOpt;
using Hi.Physics;
using Hi.MongoUtils;
using Hi.Licenses;
using Hi.MachiningProcs;
using System.IO;
namespace Sample.Machining
{
/// <summary>
/// Demonstrates how to create and configure a <see cref="MachiningProject"/> programmatically.
/// This sample shows how to set up <see cref="MillingCutter"/>, <see cref="CylindroidHolder"/>,
/// <see cref="StickMachiningTool"/>, <see cref="Fixture"/>, <see cref="Workpiece"/>,
/// and save the project configuration to a file.
/// </summary>
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Machining/DemoBuildMachiningProject.cs)]
/// </remarks>
public static class DemoBuildMachiningProject
{
#region CreateMillingCutter1
private static MillingCutter CreateMillingCutter1()
{
MillingCutter millingCutter = new MillingCutter()
{
UpperBeamGeom = new TransformationGeom(),
MillingCutterOptLimit = new MillingCutterOptLimit()
};
// since the following properties of MillingCutter has self-invoke,
// they have to be seperated from the initializer syntex.
//build ShaperProfile property
double diameter_mm = 12;
double roundRadius_mm = 0.5;
millingCutter.ShaperProfile = new AptProfile(millingCutter,
new ColumnApt()
{
Diameter_mm = diameter_mm,
Rc_mm = roundRadius_mm,
FluteHeight_mm = 40
});
//build FluteContourTray property
double helixAngle_deg = 50;
double radialRakeAngle_deg = 15;
double bottomOuterRadius_mm = diameter_mm / 2 - roundRadius_mm;
millingCutter.FluteContourTray = new UniformContourTray()
{
TrackNum = 3,
BaselineOneContour = new FluteContour()
{
BaseSideContour = new ConstHelixSideContour(millingCutter)
{
Helix_deg = helixAngle_deg,
RadialRakeAngle_deg = radialRakeAngle_deg
},
BaseBottomContour = new SlideBottomContour()
{
//In most case, helix angle from side equal to rake angle from bottom.
AxialRakeAngle_deg = MathUtil.ToDeg(helixAngle_deg),
DiskAngle_deg = 1.5,
//In most case, rake angle from side equal to eccentric angle from bottom.
EccentricAngle_deg = radialRakeAngle_deg,
CutterLengthOnBottomProjection_mm = bottomOuterRadius_mm * 0.9,
OuterRadius_mm = bottomOuterRadius_mm
}
}
};
millingCutter.InnerBeamProfile
= new FluteDependentRatioProfile(millingCutter);
return millingCutter;
}
#endregion
#region CreateMillingCutter2
private static MillingCutter CreateMillingCutter2()
{
MillingCutter millingCutter = new MillingCutter()
{
UpperBeamGeom = new TransformationGeom(),
MillingCutterOptLimit = new MillingCutterOptLimit()
};
//build ShaperProfile property
double diameter_mm = 12;
millingCutter.ShaperProfile = new AptProfile(millingCutter,
new ColumnApt()
{
Diameter_mm = diameter_mm,
FluteHeight_mm = 40
});
//build FluteContourTray property
double helixAngle_deg = 50;
double radialRakeAngle_deg = 15;
millingCutter.FluteContourTray = new UniformContourTray()
{
TrackNum = 3,
BaselineOneContour = new FluteContour()
{
BaseSideContour = new ConstHelixSideContour(millingCutter)
{
Helix_deg = helixAngle_deg,
RadialRakeAngle_deg = radialRakeAngle_deg
},
//since no bottom cut, set bottom contour to null.
BaseBottomContour = null
}
};
millingCutter.InnerBeamProfile
= new FluteDependentRatioProfile(millingCutter);
return millingCutter;
}
#endregion
#region TestMethod
[STAThread]
static void Main()
{
Console.WriteLine($"License Login.");
License.LogInAll();
Console.WriteLine($"Start Database.");
MongoServer.Default = MongoServer.Run(new MongoRunnerOptions()
{
MongoPort = 28100
});
var projectPath = "C:/HiNC-Projects/NewProject/Main.hincproj";
var projectDirectory = Path.GetDirectoryName(projectPath);
Console.WriteLine($"Directory of the New Project: {projectDirectory}");
MachiningProject machiningProject = new MachiningProject(projectDirectory);
#region ConfigureHolder
CylindroidHolder cylindroidHolder = new CylindroidHolder()
{
Note = "BT40",
Cylindroid = new Cylindroid()
{
PairZrs = new List<PairZr>([ new PairZr(0,12),new PairZr(20,12),
new PairZr(20,16),new PairZr(30,16)]),
LongitudeNum = 30
}
};
#endregion
#region ConfigureMachiningToolHouse
machiningProject.MachiningToolHouse = new MachiningToolHouse()
{
[1] = new StickMachiningTool()
{
Note = "T1",
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
Holder = cylindroidHolder,
Cutter = CreateMillingCutter1()
},
[2] = new StickMachiningTool()
{
Note = "T2",
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
Holder = cylindroidHolder,
Cutter = CreateMillingCutter2()
},
[3] = new StickMachiningTool()
{
Note = "T3",
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
Holder = cylindroidHolder,
Cutter = CreateMillingCutter1()
},
};
#endregion
#region ConfigureFixture
machiningProject.MachiningEquipment.Fixture = new Fixture()
{
Geom = new Box3d(new Vec3d(-40, -40, 0), new Vec3d(40, 40, 10)),
TableToWorkpieceTransformer = new StaticTranslation(new Vec3d(0, 0, 10)),
};
#endregion
#region ConfigureWorkpiece
machiningProject.MachiningEquipment.Workpiece = new Workpiece()
{
InitResolution = 0.25,
InitGeom = new Box3d(0, 0, -50, 70, 50, 0),
IdealGeom = null,
WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)),
MillingPara = XFactory.Default.GenByFile<ICuttingPara>(
"Resource/CuttingParameter", "Al6061T6.mp", GenMode.Default),
WorkpieceMaterial = XFactory.Default.GenByFile<WorkpieceMaterial>(
"Resource/WorkpieceMaterial", "Al6061T6.WorkpieceMaterial", GenMode.Default),
};
#endregion
#region ConfigureMachineChain
machiningProject.MachiningEquipment.SolidMachiningChain
= XFactory.Default.GenByFile<CodeXyzabcMachineTool>(
"Resource/MachineTool", "PMC-B1/PMC-B1.mt", GenMode.Default);
#endregion
machiningProject.MakeXmlSourceFile(projectPath);
}
#endregion
}
}