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