fix bug of wpf mission initialization.
This commit is contained in:
parent
a5e8b11156
commit
a570fced8a
@ -14,128 +14,134 @@ using System.Windows;
|
||||
|
||||
namespace Sample.Machining
|
||||
{
|
||||
/// <remarks>
|
||||
/// ### Source Code
|
||||
/// [!code-csharp[SampleCode](~/../Hi.Sample/Machining/DemoMillingByCutterLocation.cs)]
|
||||
/// </remarks>
|
||||
public static class DemoMillingByCutterLocation
|
||||
{
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
int h = 2;
|
||||
string stlFile_CylinderR20 = $"Cache/CylinderH{h}R20.stl";
|
||||
string stlFile_CylinderR19 = $"Cache/CylinderH{h}R19.stl";
|
||||
string stlFile_CylinderR18 = $"Cache/CylinderH{h}R18.stl";
|
||||
new Cylindroid(new PairZr(-h, 20), new PairZr(0, 20))
|
||||
.GenStl(new PolarResolution2d(1, MathUtil.ToRad(15))).WriteBin(stlFile_CylinderR20);
|
||||
new Cylindroid(new PairZr(-h, 19), new PairZr(0, 19))
|
||||
.GenStl(new PolarResolution2d(1, MathUtil.ToRad(15))).WriteBin(stlFile_CylinderR19);
|
||||
new Cylindroid(new PairZr(-h, 18), new PairZr(0, 18))
|
||||
.GenStl(new PolarResolution2d(1, MathUtil.ToRad(15))).WriteBin(stlFile_CylinderR18);
|
||||
/// <remarks>
|
||||
/// ### Source Code
|
||||
/// [!code-csharp[SampleCode](~/../Hi.Sample/Machining/DemoMillingByCutterLocation.cs)]
|
||||
/// </remarks>
|
||||
public static class DemoMillingByCutterLocation
|
||||
{
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
int h = 2;
|
||||
string stlFile_CylinderR20 = $"Cache/CylinderH{h}R20.stl";
|
||||
string stlFile_CylinderR19 = $"Cache/CylinderH{h}R19.stl";
|
||||
string stlFile_CylinderR18 = $"Cache/CylinderH{h}R18.stl";
|
||||
new Cylindroid(new PairZr(-h, 20), new PairZr(0, 20))
|
||||
.GenStl(new PolarResolution2d(1, MathUtil.ToRad(15))).WriteBin(stlFile_CylinderR20);
|
||||
new Cylindroid(new PairZr(-h, 19), new PairZr(0, 19))
|
||||
.GenStl(new PolarResolution2d(1, MathUtil.ToRad(15))).WriteBin(stlFile_CylinderR19);
|
||||
new Cylindroid(new PairZr(-h, 18), new PairZr(0, 18))
|
||||
.GenStl(new PolarResolution2d(1, MathUtil.ToRad(15))).WriteBin(stlFile_CylinderR18);
|
||||
|
||||
LocalApp.AppBegin();
|
||||
LocalApp.AppBegin();
|
||||
|
||||
#region ProjectLoading
|
||||
//var projectPath = "C:/HiNC-Projects/DemoStandardPath/Main.hincproj";
|
||||
var projectPath = "C:/HiNC-Projects/demo-test-1/Main.hincproj";
|
||||
var projectDir = Path.GetDirectoryName(projectPath);
|
||||
Console.WriteLine($"Load Project: {projectPath}");
|
||||
MachiningProject project = MachiningProject.LoadFile(projectPath);
|
||||
#endregion
|
||||
LocalProjectService localProjectService = new LocalProjectService();
|
||||
|
||||
var projectDisplayee = new MachiningProjectDisplayee(project);
|
||||
var device = new ClMillingDevice();
|
||||
project.MachiningEquipment.MachiningChain = device;
|
||||
project.ClStrip.IsShowDot = true;
|
||||
double resolution_mm = 0.5;
|
||||
project.Workpiece.InitGeom = new StlFile(stlFile_CylinderR20, projectDir);
|
||||
project.Workpiece.IdealGeom = new StlFile(stlFile_CylinderR19, projectDir);
|
||||
project.Workpiece.InitResolution = resolution_mm;
|
||||
#region ProjectLoading
|
||||
//var projectPath = "C:/HiNC-Projects/DemoStandardPath/Main.hincproj";
|
||||
var projectPath = "C:/HiNC-Projects/demo-test-1/Main.hincproj";
|
||||
Console.WriteLine($"Load Project: {projectPath}");
|
||||
localProjectService.LoadProject(projectPath).ShowIfCatched(null);
|
||||
var project = localProjectService.MachiningProject;
|
||||
#endregion
|
||||
|
||||
project.RuntimeController.SetNcResolutionFixed(9999, 15);
|
||||
project.RuntimeController.EnableCollisionDetection = false;
|
||||
project.RuntimeController.EnablePhysics = false;
|
||||
project.RuntimeController.MachiningResolution_mm = resolution_mm;
|
||||
var projectDisplayee = new MachiningProjectDisplayee(()=> localProjectService.MachiningProject);
|
||||
var device = new ClMillingDevice();
|
||||
project.MachiningEquipment.MachiningChain = device;
|
||||
project.ClStrip.IsShowDot = true;
|
||||
double resolution_mm = 0.5;
|
||||
var projectDir = Path.GetDirectoryName(projectPath);
|
||||
project.Workpiece.InitGeom = new StlFile(stlFile_CylinderR20, projectDir);
|
||||
project.Workpiece.IdealGeom = new StlFile(stlFile_CylinderR19, projectDir);
|
||||
project.Workpiece.InitResolution = resolution_mm;
|
||||
|
||||
//RunConsole(project, projectDisplayee, resolution_mm);
|
||||
RunWindow(project, projectDisplayee, resolution_mm);
|
||||
}
|
||||
static void RunConsole(MachiningProject project,
|
||||
MachiningProjectDisplayee projectDisplayee, double resolution_mm)
|
||||
{
|
||||
RunSession(project, resolution_mm);
|
||||
DispEngine dispEngine = new DispEngine(projectDisplayee);
|
||||
dispEngine.SetViewToIsometricView();
|
||||
dispEngine.SketchView = project.ClStrip.GetFittingView(dispEngine.SketchView);
|
||||
dispEngine.SketchView = dispEngine.SketchView.Scale(0.5);
|
||||
dispEngine.Snapshot($"Cache/result.bmp", 1000, 1000);
|
||||
RuntimeApi runtimeApi = new RuntimeApi(localProjectService);
|
||||
runtimeApi.SetNcResolutionFixed(9999, 15);
|
||||
runtimeApi.EnableCollisionDetection = false;
|
||||
runtimeApi.EnablePhysics = false;
|
||||
runtimeApi.MachiningResolution_mm = resolution_mm;
|
||||
|
||||
project.Dispose();
|
||||
LocalApp.AppEnd();
|
||||
Console.WriteLine($"App exit.");
|
||||
}
|
||||
static void RunWindow(MachiningProject project,
|
||||
MachiningProjectDisplayee projectDisplayee, double resolution_mm)
|
||||
{
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
RunSession(project, resolution_mm);
|
||||
Console.WriteLine($"task done.");
|
||||
}).ShowIfCatched(null);
|
||||
//RunConsole(project, projectDisplayee, resolution_mm);
|
||||
RunWindow(project, projectDisplayee, resolution_mm);
|
||||
}
|
||||
static void RunConsole(MachiningProject project,
|
||||
MachiningProjectDisplayee projectDisplayee, double resolution_mm)
|
||||
{
|
||||
RunSession(project, resolution_mm);
|
||||
DispEngine dispEngine = new DispEngine(projectDisplayee);
|
||||
dispEngine.SetViewToIsometricView();
|
||||
dispEngine.SketchView = project.ClStrip.GetFittingView(dispEngine.SketchView);
|
||||
dispEngine.SketchView = dispEngine.SketchView.Scale(0.5);
|
||||
dispEngine.Snapshot($"Cache/result.bmp", 1000, 1000);
|
||||
|
||||
#region Create and Run WPF Application
|
||||
Application app = new Application
|
||||
{
|
||||
ShutdownMode = ShutdownMode.OnMainWindowClose
|
||||
};
|
||||
app.Exit += (o, e) =>
|
||||
{
|
||||
project.Dispose();
|
||||
LocalApp.AppEnd();
|
||||
Console.WriteLine($"App exit.");
|
||||
};
|
||||
app.Run(new RenderingWindow()
|
||||
{
|
||||
Title = "Demo",
|
||||
Displayee = projectDisplayee
|
||||
});
|
||||
#endregion
|
||||
}
|
||||
static void RunSession(MachiningProject project, double resolution_mm)
|
||||
{
|
||||
project.BeginSession();
|
||||
double radius = 20;
|
||||
double z = -1;
|
||||
project.Act(new ActToolingTeleport(1));//equip tool
|
||||
project.Act(new ActClTeleport(new DVec3d(radius, 0, z, 0, 0, 1)));//goto initial position
|
||||
//run an arbitrary contour.
|
||||
int divNum = 36;
|
||||
for (int i = 0; i <= divNum; i++)
|
||||
{
|
||||
var cl = new DVec3d(
|
||||
radius * Math.Cos(i * Math.PI * 2 / divNum),
|
||||
radius * Math.Sin(i * Math.PI * 2 / divNum), z,
|
||||
0, 0, 1);
|
||||
Console.WriteLine($"{cl.Point.CsvText},{cl.Normal.CsvText},");
|
||||
project.Act(new ActClStep(cl));
|
||||
}
|
||||
double diffLimit_mm = resolution_mm * 2;
|
||||
project.RuntimeController.Diff(resolution_mm * 2);
|
||||
Console.WriteLine($"IsDifferenceAceptable: {IsDifferenceAceptable(project, diffLimit_mm)}");
|
||||
project.EndSession();
|
||||
}
|
||||
static bool IsDifferenceAceptable(MachiningProject project, double diffLimit)
|
||||
{
|
||||
foreach (var attachment in project.Workpiece.DiffAttachmentBag)
|
||||
{
|
||||
if (double.IsNaN(attachment.Diff) || Math.Abs(attachment.Diff) > diffLimit)
|
||||
{
|
||||
Console.WriteLine($"Diff: {attachment.Diff}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
project.Dispose();
|
||||
LocalApp.AppEnd();
|
||||
Console.WriteLine($"App exit.");
|
||||
}
|
||||
static void RunWindow(MachiningProject project,
|
||||
MachiningProjectDisplayee projectDisplayee, double resolution_mm)
|
||||
{
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
RunSession(project, resolution_mm);
|
||||
Console.WriteLine($"task done.");
|
||||
}).ShowIfCatched(null);
|
||||
|
||||
#region Create and Run WPF Application
|
||||
Application app = new Application
|
||||
{
|
||||
ShutdownMode = ShutdownMode.OnMainWindowClose
|
||||
};
|
||||
app.Exit += (o, e) =>
|
||||
{
|
||||
project.Dispose();
|
||||
LocalApp.AppEnd();
|
||||
Console.WriteLine($"App exit.");
|
||||
};
|
||||
app.Run(new RenderingWindow()
|
||||
{
|
||||
Title = "Demo",
|
||||
Displayee = projectDisplayee
|
||||
});
|
||||
#endregion
|
||||
}
|
||||
static void RunSession(MachiningProject project, double resolution_mm)
|
||||
{
|
||||
RuntimeApi runtimeApi = new RuntimeApi(project);
|
||||
|
||||
project.BeginSession();
|
||||
double radius = 20;
|
||||
double z = -1;
|
||||
project.Act(new ActToolingTeleport(1));//equip tool
|
||||
project.Act(new ActClTeleport(new DVec3d(radius, 0, z, 0, 0, 1)));//goto initial position
|
||||
//run an arbitrary contour.
|
||||
int divNum = 36;
|
||||
for (int i = 0; i <= divNum; i++)
|
||||
{
|
||||
var cl = new DVec3d(
|
||||
radius * Math.Cos(i * Math.PI * 2 / divNum),
|
||||
radius * Math.Sin(i * Math.PI * 2 / divNum), z,
|
||||
0, 0, 1);
|
||||
Console.WriteLine($"{cl.Point.CsvText},{cl.Normal.CsvText},");
|
||||
project.Act(new ActClStep(cl));
|
||||
}
|
||||
double diffLimit_mm = resolution_mm * 2;
|
||||
runtimeApi.Diff(resolution_mm * 2);
|
||||
Console.WriteLine($"IsDifferenceAceptable: {IsDifferenceAceptable(project, diffLimit_mm)}");
|
||||
project.EndSession();
|
||||
}
|
||||
static bool IsDifferenceAceptable(MachiningProject project, double diffLimit)
|
||||
{
|
||||
foreach (var attachment in project.Workpiece.DiffAttachmentBag)
|
||||
{
|
||||
if (double.IsNaN(attachment.Diff) || Math.Abs(attachment.Diff) > diffLimit)
|
||||
{
|
||||
Console.WriteLine($"Diff: {attachment.Diff}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ namespace Sample.Machining
|
||||
Console.WriteLine($"Load Project: {projectPath}");
|
||||
MachiningProject machiningProject = MachiningProject.LoadFile(projectPath);
|
||||
|
||||
machiningProject.RuntimeController.MachiningStepSelected += (MachiningStep step) =>
|
||||
machiningProject.RuntimeApi.MachiningStepSelected += (MachiningStep step) =>
|
||||
{
|
||||
var sourceCommand = step.SourceCommand;
|
||||
Console.WriteLine($"Step Selected: MRR = {step.Mrr_mm3ds} At \"{sourceCommand?.FilePath}\" (Line {sourceCommand?.GetLineNo()}) \"{sourceCommand?.Line}\"");
|
||||
@ -42,7 +42,7 @@ namespace Sample.Machining
|
||||
#endregion
|
||||
|
||||
#region Configure Rendering Options
|
||||
var projectDisplayee = new MachiningProjectDisplayee(machiningProject);
|
||||
var projectDisplayee = new MachiningProjectDisplayee(()=>machiningProject);
|
||||
projectDisplayee.RenderingFlagBitArray[(int)RenderingFlag.Mech] = true;
|
||||
projectDisplayee.RenderingFlagBitArray[(int)RenderingFlag.Fixture] = true;
|
||||
projectDisplayee.RenderingFlagBitArray[(int)RenderingFlag.WorkpieceGeom] = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user