tune
This commit is contained in:
@@ -172,9 +172,9 @@ namespace Sample.Common
|
||||
public static class DemoSessionMessage
|
||||
{
|
||||
#region Demo_UseSessionMessageHost
|
||||
internal static void DemoUseSessionMessageHost(MachiningProject project)
|
||||
internal static void DemoUseSessionMessageHost(LocalProjectService localProjectService)
|
||||
{
|
||||
SessionMessageHost sessionMessageHost = project.SessionMessageHost;
|
||||
SessionMessageHost sessionMessageHost = localProjectService.SessionMessageHost;
|
||||
|
||||
SessionMessageHost.FilterFlag filterFlags =
|
||||
SessionMessageHost.FilterFlag.NC |
|
||||
@@ -208,10 +208,10 @@ namespace Sample.Common
|
||||
}
|
||||
#endregion
|
||||
|
||||
internal static void DemoUseSessionMessageHost2(MachiningProject project)
|
||||
internal static void DemoUseSessionMessageHost2(LocalProjectService localProjectService)
|
||||
{
|
||||
SessionMessageHost sessionMessageHost = project.SessionMessageHost;
|
||||
IMachiningChain machiningChain = project.MachiningEquipment?.MachiningChain;
|
||||
SessionMessageHost sessionMessageHost = localProjectService.SessionMessageHost;
|
||||
IMachiningChain machiningChain = localProjectService.MachiningChain;
|
||||
|
||||
PresentAttribute mrrPresent = typeof(MachiningStep).GetProperty(nameof(MachiningStep.Mrr_mm3ds)).GetCustomAttribute<PresentAttribute>();
|
||||
string mrrUnit = mrrPresent?.TailUnitString;
|
||||
|
||||
@@ -155,7 +155,7 @@ Handles common initialization and cleanup tasks for visualization examples.</p>
|
||||
using Hi.HiNcKits;
|
||||
using Hi.Licenses;
|
||||
using Hi.MongoUtils;
|
||||
using Hi.Wpf.Disp;
|
||||
using Hi.WpfPlus.Disp;
|
||||
using System.Windows;
|
||||
|
||||
namespace Sample.Disp
|
||||
|
||||
+9
-7
@@ -193,11 +193,13 @@ namespace Sample.Machining
|
||||
static void Main()
|
||||
{
|
||||
LocalApp.AppBegin();
|
||||
LocalProjectService localProjectService = new LocalProjectService();
|
||||
|
||||
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);
|
||||
localProjectService.LoadProject(projectPath);
|
||||
MachiningProject machiningProject = localProjectService.MachiningProject;
|
||||
|
||||
CylindroidHolder cylindroidHolder = new CylindroidHolder()
|
||||
{
|
||||
@@ -205,7 +207,7 @@ namespace Sample.Machining
|
||||
Cylindroid = new Cylindroid([ new PairZr(0,12),new PairZr(20,12),
|
||||
new PairZr(20,16),new PairZr(30,16)])
|
||||
};
|
||||
machiningProject.MachiningToolHouse = new MachiningToolHouse()
|
||||
localProjectService.MachiningToolHouse = new MachiningToolHouse()
|
||||
{
|
||||
[1] = new MillingTool()
|
||||
{
|
||||
@@ -216,13 +218,13 @@ namespace Sample.Machining
|
||||
},
|
||||
};
|
||||
|
||||
machiningProject.MachiningEquipment.Fixture = new Fixture()
|
||||
localProjectService.Fixture = new Fixture()
|
||||
{
|
||||
Geom = new Box3d(new Vec3d(-40, -40, 0), new Vec3d(40, 40, 10)),
|
||||
GeomToWorkpieceTransformer = new StaticTranslation(new Vec3d(0, 0, 10)),
|
||||
};
|
||||
|
||||
machiningProject.MachiningEquipment.Workpiece = new Workpiece()
|
||||
localProjectService.Workpiece = new Workpiece()
|
||||
{
|
||||
InitResolution = 0.25,
|
||||
InitGeom = new Box3d(0, 0, -50, 70, 50, 0),
|
||||
@@ -230,12 +232,12 @@ namespace Sample.Machining
|
||||
WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)),
|
||||
};
|
||||
|
||||
machiningProject.MachiningEquipment.MachiningChain
|
||||
localProjectService.MachiningChain
|
||||
= XFactory.GenByFile<CodeXyzabcMachineTool>(
|
||||
"Resource", "MachineTool/PMC-B1/PMC-B1.mt", GenMode.Default);
|
||||
machiningProject.MachiningEquipment.MachiningChainFile = "PMC-B1/PMC-B1.mt";
|
||||
localProjectService.MachiningChainFile = "PMC-B1/PMC-B1.mt";
|
||||
|
||||
machiningProject.MakeXmlSourceFile(projectPath);
|
||||
localProjectService.SaveProject();
|
||||
|
||||
machiningProject.Dispose();
|
||||
LocalApp.AppEnd();
|
||||
|
||||
+7
-5
@@ -297,14 +297,16 @@ namespace Sample.Machining
|
||||
static void Main()
|
||||
{
|
||||
LocalApp.AppBegin();
|
||||
LocalProjectService localProjectService = new LocalProjectService();
|
||||
|
||||
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);
|
||||
localProjectService.LoadProject(projectPath);
|
||||
MachiningProject machiningProject = localProjectService.MachiningProject;
|
||||
|
||||
#region ConfigureMachiningToolHouse
|
||||
machiningProject.MachiningToolHouse = new MachiningToolHouse()
|
||||
localProjectService.MachiningToolHouse = new MachiningToolHouse()
|
||||
{
|
||||
[1] = new MillingTool()
|
||||
{
|
||||
@@ -331,7 +333,7 @@ namespace Sample.Machining
|
||||
#endregion
|
||||
|
||||
#region ConfigureFixture
|
||||
machiningProject.MachiningEquipment.Fixture = new Fixture()
|
||||
localProjectService.Fixture = new Fixture()
|
||||
{
|
||||
Geom = new Box3d(new Vec3d(-40, -40, 0), new Vec3d(40, 40, 10)),
|
||||
GeomToWorkpieceTransformer = new StaticTranslation(new Vec3d(0, 0, 10)),
|
||||
@@ -339,7 +341,7 @@ namespace Sample.Machining
|
||||
#endregion
|
||||
|
||||
#region ConfigureWorkpiece
|
||||
machiningProject.MachiningEquipment.Workpiece = new Workpiece()
|
||||
localProjectService.Workpiece = new Workpiece()
|
||||
{
|
||||
InitResolution = 0.25,
|
||||
InitGeom = new Box3d(0, 0, -50, 70, 50, 0),
|
||||
@@ -353,7 +355,7 @@ namespace Sample.Machining
|
||||
#endregion
|
||||
|
||||
#region ConfigureMachineChain
|
||||
machiningProject.MachiningEquipment.MachiningChain
|
||||
localProjectService.MachiningChain
|
||||
= XFactory.GenByFile<CodeXyzabcMachineTool>(
|
||||
"Resource", "MachineTool/PMC-B1/PMC-B1.mt", GenMode.Default);
|
||||
#endregion
|
||||
|
||||
+23
-23
@@ -155,7 +155,7 @@ using Hi.Geom.Resolution;
|
||||
using Hi.HiNcKits;
|
||||
using Hi.MachiningProcs;
|
||||
using Hi.Numerical.Acts;
|
||||
using Hi.Wpf.Disp;
|
||||
using Hi.WpfPlus.Disp;
|
||||
using HiMachining.Milling;
|
||||
using System;
|
||||
using System.IO;
|
||||
@@ -192,21 +192,21 @@ namespace Sample.Machining
|
||||
//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);
|
||||
localProjectService.LoadProject(projectPath);
|
||||
var project = localProjectService.MachiningProject;
|
||||
#endregion
|
||||
|
||||
var projectDisplayee = new MachiningProjectDisplayee(()=> localProjectService.MachiningProject);
|
||||
var projectDisplayee = new MachiningProjectDisplayee(localProjectService);
|
||||
var device = new ClMillingDevice();
|
||||
project.MachiningEquipment.MachiningChain = device;
|
||||
project.ClStrip.IsShowDot = true;
|
||||
localProjectService.MachiningEquipment.MachiningChain = device;
|
||||
localProjectService.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;
|
||||
localProjectService.Workpiece.InitGeom = new StlFile(stlFile_CylinderR20, projectDir);
|
||||
localProjectService.Workpiece.IdealGeom = new StlFile(stlFile_CylinderR19, projectDir);
|
||||
localProjectService.Workpiece.InitResolution = resolution_mm;
|
||||
|
||||
RuntimeApi runtimeApi = project.RuntimeApi;
|
||||
RuntimeApi runtimeApi = localProjectService.RuntimeApi;
|
||||
runtimeApi.SetNcResolutionFixed(9999, 15);
|
||||
runtimeApi.EnableCollisionDetection = false;
|
||||
runtimeApi.EnablePhysics = false;
|
||||
@@ -215,13 +215,13 @@ namespace Sample.Machining
|
||||
//RunConsole(project, projectDisplayee, resolution_mm);
|
||||
RunWindow(localProjectService, projectDisplayee, resolution_mm);
|
||||
}
|
||||
static void RunConsole(IProjectService projectService,
|
||||
static void RunConsole(LocalProjectService projectService,
|
||||
MachiningProjectDisplayee projectDisplayee, double resolution_mm)
|
||||
{
|
||||
RunSession(projectService, resolution_mm);
|
||||
DispEngine dispEngine = new DispEngine(projectDisplayee);
|
||||
dispEngine.SetViewToIsometricView();
|
||||
dispEngine.SketchView = projectService.MachiningProject.ClStrip.GetFittingView(dispEngine.SketchView);
|
||||
dispEngine.SketchView = projectService.ClStrip.GetFittingView(dispEngine.SketchView);
|
||||
dispEngine.SketchView = dispEngine.SketchView.Scale(0.5);
|
||||
dispEngine.Snapshot($"Cache/result.bmp", 1000, 1000);
|
||||
|
||||
@@ -229,7 +229,7 @@ namespace Sample.Machining
|
||||
LocalApp.AppEnd();
|
||||
Console.WriteLine($"App exit.");
|
||||
}
|
||||
static void RunWindow(IProjectService projectService,
|
||||
static void RunWindow(LocalProjectService projectService,
|
||||
MachiningProjectDisplayee projectDisplayee, double resolution_mm)
|
||||
{
|
||||
var task = Task.Run(() =>
|
||||
@@ -256,16 +256,16 @@ namespace Sample.Machining
|
||||
});
|
||||
#endregion
|
||||
}
|
||||
static void RunSession(IProjectService projectService, double resolution_mm)
|
||||
static void RunSession(LocalProjectService localProjectService, double resolution_mm)
|
||||
{
|
||||
var project=projectService.MachiningProject;
|
||||
RuntimeApi runtimeApi = project.RuntimeApi;
|
||||
var project=localProjectService.MachiningProject;
|
||||
RuntimeApi runtimeApi = localProjectService.RuntimeApi;
|
||||
|
||||
project.BeginSession();
|
||||
localProjectService.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
|
||||
localProjectService.Act(new ActToolingTeleport(1));//equip tool
|
||||
localProjectService.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++)
|
||||
@@ -275,16 +275,16 @@ namespace Sample.Machining
|
||||
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));
|
||||
localProjectService.Act(new ActClStep(cl));
|
||||
}
|
||||
double diffLimit_mm = resolution_mm * 2;
|
||||
runtimeApi.Diff(resolution_mm * 2);
|
||||
Console.WriteLine($"IsDifferenceAceptable: {IsDifferenceAceptable(project, diffLimit_mm)}");
|
||||
project.EndSession();
|
||||
Console.WriteLine($"IsDifferenceAceptable: {IsDifferenceAceptable(localProjectService, diffLimit_mm)}");
|
||||
localProjectService.EndSession();
|
||||
}
|
||||
static bool IsDifferenceAceptable(MachiningProject project, double diffLimit)
|
||||
static bool IsDifferenceAceptable(LocalProjectService localProjectService, double diffLimit)
|
||||
{
|
||||
foreach (var attachment in project.Workpiece.DiffAttachmentBag)
|
||||
foreach (var attachment in localProjectService.Workpiece.DiffAttachmentBag)
|
||||
{
|
||||
if (double.IsNaN(attachment.Diff) || Math.Abs(attachment.Diff) > diffLimit)
|
||||
{
|
||||
|
||||
+7
-5
@@ -151,7 +151,7 @@ Provides a complete example of a 3D visualization application with HiAPI and WPF
|
||||
|
||||
<h2 id="Sample_Machining_DemoRenderingMachiningProcessAndStripPosSelection_remarks">Remarks</h2>
|
||||
<div class="markdown level0 remarks"><h3 id="source-code">Source Code</h3>
|
||||
<pre><code class="lang-csharp" name="SampleCode">using Hi.Wpf.Disp;
|
||||
<pre><code class="lang-csharp" name="SampleCode">using Hi.WpfPlus.Disp;
|
||||
using System;
|
||||
using Hi.MachiningProcs;
|
||||
using Hi.Common.FileLines;
|
||||
@@ -176,22 +176,24 @@ namespace Sample.Machining
|
||||
static void Main(string[] args)
|
||||
{
|
||||
LocalApp.AppBegin();
|
||||
LocalProjectService localProjectService = new LocalProjectService();
|
||||
|
||||
#region Load Machining Project
|
||||
var projectPath = "C:/HiNC-Projects/DemoStandardPath/Main.hincproj";
|
||||
Console.WriteLine($"Load Project: {projectPath}");
|
||||
MachiningProject machiningProject = MachiningProject.LoadFile(projectPath);
|
||||
localProjectService.LoadProject(projectPath);
|
||||
MachiningProject machiningProject = localProjectService.MachiningProject;
|
||||
|
||||
machiningProject.RuntimeApi.MachiningStepSelected += (MachiningStep step) =>
|
||||
localProjectService.RuntimeApi.MachiningStepSelected += (MachiningStep step) =>
|
||||
{
|
||||
var sourceCommand = step.SourceCommand;
|
||||
Console.WriteLine($"Step Selected: MRR = {step.Mrr_mm3ds} At \"{sourceCommand?.FilePath}\" (Line {sourceCommand?.GetLineNo()}) \"{sourceCommand?.Line}\"");
|
||||
};
|
||||
machiningProject.PacePlayer.Start();
|
||||
localProjectService.PacePlayer.Start();
|
||||
#endregion
|
||||
|
||||
#region Configure Rendering Options
|
||||
var projectDisplayee = new MachiningProjectDisplayee(()=>machiningProject);
|
||||
var projectDisplayee = new MachiningProjectDisplayee(localProjectService);
|
||||
projectDisplayee.RenderingFlagBitArray[(int)RenderingFlag.Mech] = true;
|
||||
projectDisplayee.RenderingFlagBitArray[(int)RenderingFlag.Fixture] = true;
|
||||
projectDisplayee.RenderingFlagBitArray[(int)RenderingFlag.WorkpieceGeom] = true;
|
||||
|
||||
+14
-12
@@ -176,11 +176,13 @@ namespace Sample.Machining
|
||||
static void Main()
|
||||
{
|
||||
LocalApp.AppBegin();
|
||||
LocalProjectService localProjectService = new LocalProjectService();
|
||||
|
||||
#region ProjectLoading
|
||||
var projectPath = "C:/HiNC-Projects/DemoStandardPath/Main.hincproj";
|
||||
Console.WriteLine($"Load Project: {projectPath}");
|
||||
MachiningProject machiningProject = MachiningProject.LoadFile(projectPath);
|
||||
localProjectService.LoadProject(projectPath);
|
||||
MachiningProject machiningProject = localProjectService.MachiningProject;
|
||||
#endregion
|
||||
|
||||
#region EventHandling
|
||||
@@ -188,7 +190,7 @@ namespace Sample.Machining
|
||||
|
||||
using StreamWriter writer = new StreamWriter("msg.txt");
|
||||
//show message if something abnormal.
|
||||
machiningProject.SessionMessageHost.CollectionItemAdded += pack =>
|
||||
localProjectService.SessionMessageHost.CollectionItemAdded += pack =>
|
||||
{
|
||||
if (pack.Tags.Contains(MessageFlag.Warning.ToString()) ||
|
||||
pack.Tags.Contains(MessageFlag.Error.ToString()) ||
|
||||
@@ -200,7 +202,7 @@ namespace Sample.Machining
|
||||
};
|
||||
Console.WriteLine($"Set machining step event.");
|
||||
//show MRR.
|
||||
machiningProject.RuntimeApi.MachiningStepBuilt += (preStep, curStep) =>
|
||||
localProjectService.RuntimeApi.MachiningStepBuilt += (preStep, curStep) =>
|
||||
{
|
||||
var sourceCommand = curStep.SourceCommand;
|
||||
if (curStep.Mrr_mm3ds > 500) //show only the step that contains large MRR.
|
||||
@@ -210,18 +212,18 @@ namespace Sample.Machining
|
||||
|
||||
#region MachiningExecution
|
||||
Console.WriteLine($"Reset runtime status.");
|
||||
machiningProject.ResetRuntime();
|
||||
localProjectService.ResetRuntime();
|
||||
|
||||
Console.WriteLine($"Session begin.");
|
||||
machiningProject.BeginSession();
|
||||
machiningProject.RuntimeApi.MachiningResolution_mm = 1;
|
||||
machiningProject.RuntimeApi.EnableCollisionDetection = true;
|
||||
machiningProject.RuntimeApi.EnablePauseOnFailure = false;
|
||||
machiningProject.RuntimeApi.EnablePhysics = false;
|
||||
localProjectService.BeginSession();
|
||||
localProjectService.RuntimeApi.MachiningResolution_mm = 1;
|
||||
localProjectService.RuntimeApi.EnableCollisionDetection = true;
|
||||
localProjectService.RuntimeApi.EnablePauseOnFailure = false;
|
||||
localProjectService.RuntimeApi.EnablePhysics = false;
|
||||
//the path from Shell-API is relative by project directory.
|
||||
machiningProject.RuntimeApi.PlayNcFile("NC/side.ptp");
|
||||
machiningProject.RuntimeApi.PlayNcFile("NC/circle.ptp");
|
||||
machiningProject.EndSession();
|
||||
localProjectService.RuntimeApi.PlayNcFile("NC/side.ptp");
|
||||
localProjectService.RuntimeApi.PlayNcFile("NC/circle.ptp");
|
||||
localProjectService.EndSession();
|
||||
Console.WriteLine($"Session end.");
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user