Review, apply and undo scoped vision asset and step renames
This commit is contained in:
parent
2e03f3b617
commit
860602b480
@ -28,7 +28,7 @@ internal sealed class ProjectGateway(string root, bool allowWrite)
|
||||
return ProjectPipe.Call(root, new() { ["operation"] = operation, ["arguments"] = arguments }, () =>
|
||||
{
|
||||
using var project = ProjectDirectory.Open(root);
|
||||
if (operation is "preview" or "previewScript" or "previewRename" or "previewWorkflowRename" or "previewPointRename" or "previewVisionRename" or "previewAxisRename" or "previewIoRename" or "previewDeviceRename" or "previewUndo" or "apply" or "status")
|
||||
if (operation is "preview" or "previewScript" or "previewRename" or "previewWorkflowRename" or "previewPointRename" or "previewVisionRename" or "previewAxisRename" or "previewIoRename" or "previewVisionAssetRename" or "previewDeviceRename" or "previewUndo" or "apply" or "status")
|
||||
return changes.Execute(project, operation, arguments, allowWrite, change => (change.Review == null && change.Rename == null) || approved);
|
||||
return ProjectInspection.Query(project, operation, arguments);
|
||||
}).ToJsonString();
|
||||
|
||||
@ -11,6 +11,10 @@ internal sealed class ProjectTools(ProjectGateway gateway)
|
||||
public string PreviewVisionFunctionRename(string id, string newName) =>
|
||||
gateway.Call("previewVisionRename", new() { ["id"] = id, ["newName"] = newName });
|
||||
|
||||
[McpServerTool(Name = "preview_vision_asset_rename"), Description("Preview a Cameras, ImageDatas or LocalImageDatas rename with scoped vision steps, compiled workflow edits and manual references.")]
|
||||
public string PreviewVisionAssetRename(string kind, string id, string newName) =>
|
||||
gateway.Call("previewVisionAssetRename", new() { ["kind"] = kind, ["id"] = id, ["newName"] = newName });
|
||||
|
||||
[McpServerTool(Name = "preview_device_rename"), Description("Preview renaming a Cylinders, Robots or Connects ID. Updates the hardware definition and bound lookups across recipes, compiles affected scripts and lists manual references.")]
|
||||
public string PreviewDeviceRename(string kind, string id, string newName) =>
|
||||
gateway.Call("previewDeviceRename", new() { ["kind"] = kind, ["id"] = id, ["newName"] = newName });
|
||||
|
||||
@ -32,7 +32,7 @@ public partial class GlobalModel
|
||||
if (!AllowAiAccess) throw new InvalidOperationException("请在机种配方页面启用 AI 访问。");
|
||||
string operation = (string)request["operation"];
|
||||
var args = request["arguments"].AsObject();
|
||||
if (operation is "preview" or "previewScript" or "previewRename" or "previewWorkflowRename" or "previewPointRename" or "previewVisionRename" or "previewAxisRename" or "previewIoRename" or "previewDeviceRename" or "previewUndo" or "apply" or "status")
|
||||
if (operation is "preview" or "previewScript" or "previewRename" or "previewWorkflowRename" or "previewPointRename" or "previewVisionRename" or "previewAxisRename" or "previewIoRename" or "previewVisionAssetRename" or "previewDeviceRename" or "previewUndo" or "apply" or "status")
|
||||
{
|
||||
if (operation == "apply" && (ModeState.State.Execute || WorkflowsModel.IsBusy))
|
||||
throw new InvalidOperationException("运行或切换配方期间无法保存 AI 修改。");
|
||||
@ -74,6 +74,8 @@ public partial class GlobalModel
|
||||
updateEditorView = Project.PrepareAxisView(axis, ControllersModel, CurrentRecipe.ID);
|
||||
if (accepted && change.Rename is { IsIo: true } io)
|
||||
updateEditorView = Project.PrepareIoView(io, ControllersModel, CylindersModel);
|
||||
if (accepted && change.Rename is { IsVisionAsset: true } asset)
|
||||
updateEditorView = Project.PrepareAssetView(asset, VisionsModel, CurrentRecipe.ID);
|
||||
if (accepted && change.Rename is { IsDevice: true } device)
|
||||
updateEditorView = PrepareDeviceView(device);
|
||||
return accepted;
|
||||
|
||||
@ -26,10 +26,12 @@ public sealed class ProjectChanges
|
||||
public JsonNode Execute(ProjectDirectory project, string operation, JsonObject args, bool allowWrite,
|
||||
Func<ProjectChange, bool> confirm = null)
|
||||
{
|
||||
if (operation is "previewRename" or "previewWorkflowRename" or "previewPointRename" or "previewVisionRename" or "previewAxisRename" or "previewIoRename" or "previewDeviceRename" or "previewUndo")
|
||||
if (operation is "previewRename" or "previewWorkflowRename" or "previewPointRename" or "previewVisionRename" or "previewAxisRename" or "previewIoRename" or "previewVisionAssetRename" or "previewDeviceRename" or "previewUndo")
|
||||
{
|
||||
ProjectRename plan;
|
||||
if (operation == "previewDeviceRename")
|
||||
if (operation == "previewVisionAssetRename")
|
||||
plan = project.PlanVisionAssetRename((string)args["kind"], Guid.Parse((string)args["id"]), (string)args["newName"]);
|
||||
else if (operation == "previewDeviceRename")
|
||||
plan = project.PlanDeviceRename((string)args["kind"], Guid.Parse((string)args["id"]), (string)args["newName"]);
|
||||
else if (operation == "previewIoRename")
|
||||
plan = project.PlanIoRename((string)args["kind"], Guid.Parse((string)args["id"]), (string)args["newName"]);
|
||||
|
||||
@ -21,12 +21,16 @@ public sealed record ProjectRename(Guid ObjectId, Guid RecipeId, string OldName,
|
||||
internal static string PathFor(string kind, Guid recipe) => kind switch
|
||||
{
|
||||
"AxisPoints" or "RobotPoints" => "configuration/points.json",
|
||||
"VisionFunctions" => "configuration/vision.json",
|
||||
"DI" or "DQ" or "Axes" or "Cylinders" or "Robots" or "Connects" => "configuration/hardware.json",
|
||||
"VisionFunctions" or "ImageDatas" or "LocalImageDatas" => "configuration/vision.json",
|
||||
"Cameras" or "DI" or "DQ" or "Axes" or "Cylinders" or "Robots" or "Connects" => "configuration/hardware.json",
|
||||
"Workflows" => $"recipes/{recipe:D}/recipe.json",
|
||||
_ => ProjectDirectory.VariablesPath
|
||||
};
|
||||
public List<PointField> MatrixReferences { get; init; } = [];
|
||||
public bool IsVisionAsset => Kind is "Cameras" or "ImageDatas" or "LocalImageDatas";
|
||||
public List<VisionStepEdit> VisionReferences { get; init; } = [];
|
||||
[JsonIgnore] internal string OriginalVision { get; init; }
|
||||
[JsonIgnore] internal string SavedVision { get; set; }
|
||||
public bool IsDevice => Kind is "Cylinders" or "Robots" or "Connects";
|
||||
public bool IsIo => Kind is "DI" or "DQ";
|
||||
public List<PointField> CylinderReferences { get; init; } = [];
|
||||
@ -129,13 +133,14 @@ public sealed partial class ProjectDirectory
|
||||
internal ProjectRename PlanUndo(Guid operationId, ProjectRename saved)
|
||||
{
|
||||
if (saved.SavedScope != RenameScope(saved.RecipeId) || saved.SavedMetadata != baseline[saved.MetadataPath] ||
|
||||
(saved.IsVisionAsset && saved.SavedVision != baseline[ConfigPath("vision")]) ||
|
||||
(saved.Kind == "Axes" && saved.SavedPoints != baseline[ConfigPath("points")]))
|
||||
throw new ProjectConflictException("保存后配方脚本或名称文件已改变,无法安全撤销。");
|
||||
CheckName(saved, saved.NewName, saved.OldName);
|
||||
var inverse = saved.Scripts.Select(s => s with { Before = s.After, After = s.Before,
|
||||
Review = WorkflowScriptReview.Create(s.Id, s.After, s.Before) }).ToList();
|
||||
return new(saved.ObjectId, saved.RecipeId, saved.NewName, saved.OldName, inverse,
|
||||
saved.ManualReferences, new JsonArray()) { Kind = saved.Kind, CylinderReferences = saved.CylinderReferences, PointReferences = saved.PointReferences, OriginalPoints = saved.SavedPoints, SavedPoints = saved.OriginalPoints, MatrixReferences = saved.MatrixReferences, RobotScope = saved.RobotScope, UndoOf = operationId, Scope = saved.SavedScope,
|
||||
saved.ManualReferences, new JsonArray()) { Kind = saved.Kind, VisionReferences = saved.VisionReferences.Select(e => e.Inverse()).ToList(), OriginalVision = saved.SavedVision, SavedVision = saved.OriginalVision, CylinderReferences = saved.CylinderReferences, PointReferences = saved.PointReferences, OriginalPoints = saved.SavedPoints, SavedPoints = saved.OriginalPoints, MatrixReferences = saved.MatrixReferences, RobotScope = saved.RobotScope, UndoOf = operationId, Scope = saved.SavedScope,
|
||||
OriginalMetadata = saved.SavedMetadata, SavedMetadata = saved.OriginalMetadata };
|
||||
}
|
||||
|
||||
@ -143,6 +148,7 @@ public sealed partial class ProjectDirectory
|
||||
{
|
||||
if (plan.Kind == "Workflows") CheckWorkflowName(plan.RecipeId, plan.ObjectId, before, after);
|
||||
else if (plan.Kind == "VisionFunctions") CheckVisionName(plan.RecipeId, plan.ObjectId, before, after);
|
||||
else if (plan.IsVisionAsset) CheckAssetName(plan.Kind, plan.ObjectId, before, after);
|
||||
else if (plan.IsIo || plan.IsDevice) CheckHardwareName(plan.Kind, plan.ObjectId, before, after, plan.UndoOf.HasValue || plan.SavedMetadata != null);
|
||||
else if (plan.Kind == "Axes") CheckAxisName(plan.ObjectId, before, after);
|
||||
else if (plan.IsPoint) ValidatePoint(plan, before, after);
|
||||
@ -188,6 +194,21 @@ public sealed partial class ProjectDirectory
|
||||
row[field] = plan.NewName;
|
||||
foreach (var reference in plan.MatrixReferences.Concat(plan.CylinderReferences))
|
||||
reference.Row(metadata)[reference.Field] = plan.NewName;
|
||||
if (plan.IsVisionAsset)
|
||||
{
|
||||
if (baseline[ConfigPath("vision")] != plan.OriginalVision)
|
||||
throw new ProjectConflictException("视觉配置已经改变,请重新预览。");
|
||||
var vision = plan.Kind == "Cameras" ? JsonNode.Parse(plan.OriginalVision) : metadata;
|
||||
foreach (var edit in plan.VisionReferences) edit.Apply(vision);
|
||||
if (plan.Kind == "Cameras")
|
||||
{
|
||||
var parameters = row["Params"].AsObject();
|
||||
if (parameters["DiscoveryName"] == null) parameters["DiscoveryName"] = plan.OldName;
|
||||
scope.Add(ConfigPath("vision"));
|
||||
files[ConfigPath("vision")] = plan.UndoOf.HasValue ? plan.SavedVision :
|
||||
plan.VisionReferences.Count == 0 ? plan.OriginalVision : Serialize(vision);
|
||||
}
|
||||
}
|
||||
files[plan.MetadataPath] = plan.UndoOf.HasValue ? plan.SavedMetadata : Serialize(metadata);
|
||||
if (plan.Kind == "RobotPoints") scope.Add(ConfigPath("hardware"));
|
||||
if (plan.Kind == "Axes")
|
||||
@ -217,6 +238,7 @@ public sealed partial class ProjectDirectory
|
||||
if (plan.Kind == "Variables" && Data.Variables.Where(v => v.ID == plan.ObjectId && v.Name == plan.OldName)
|
||||
.ExecuteUpdate(s => s.SetProperty(v => v.Name, plan.NewName)) != 1)
|
||||
throw new ProjectConflictException("变量已发生变化。");
|
||||
var acceptAsset = plan.IsVisionAsset ? WriteVisionAsset(plan, files) : null;
|
||||
try { WriteFiles(Root, files, scope.ToArray(), transaction == null ? null : transaction.Commit); }
|
||||
catch (IOException) when (scope.Any(path => !File.Exists(ProjectFile(Root, path)) ||
|
||||
File.ReadAllText(ProjectFile(Root, path)) != baseline[path]))
|
||||
@ -231,6 +253,12 @@ public sealed partial class ProjectDirectory
|
||||
configuration[plan.MetadataPath] = files[plan.MetadataPath];
|
||||
if (plan.Kind == "Axes")
|
||||
configuration[ConfigPath("points")] = files[ConfigPath("points")];
|
||||
if (plan.IsVisionAsset)
|
||||
{
|
||||
configuration[ConfigPath("vision")] = files[ConfigPath("vision")];
|
||||
acceptAsset();
|
||||
return;
|
||||
}
|
||||
if (plan.IsDevice)
|
||||
{
|
||||
var device = (INamedDevice)Data.Find(new PointField(plan.Kind, plan.ObjectId, "Name").EntityType, plan.ObjectId);
|
||||
@ -255,6 +283,7 @@ public sealed partial class ProjectDirectory
|
||||
Data.Entry(variable).Property(v => v.Name).OriginalValue = plan.NewName;
|
||||
});
|
||||
if (plan.Kind == "Axes") plan.SavedPoints = files[ConfigPath("points")];
|
||||
if (plan.IsVisionAsset) plan.SavedVision = files[ConfigPath("vision")];
|
||||
plan.SavedScope = RenameScope(plan.RecipeId);
|
||||
plan.SavedMetadata = files[plan.MetadataPath];
|
||||
}
|
||||
|
||||
183
PLCSharpWpf/Models/VisionAssetRename.cs
Normal file
183
PLCSharpWpf/Models/VisionAssetRename.cs
Normal file
@ -0,0 +1,183 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PLCSharp.VVMs.Vision;
|
||||
using PLCSharp.VVMs.Vision.Camera;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace PLCSharp.Models;
|
||||
|
||||
public sealed record VisionStepEdit(Guid FunctionId, int Index, VisionFlowType Type, string Key,
|
||||
bool HadValue, string Before, bool HasValue, string After)
|
||||
{
|
||||
internal VisionStepEdit Inverse() => new(FunctionId, Index, Type, Key, HasValue, After, HadValue, Before);
|
||||
|
||||
internal void Apply(JsonNode vision)
|
||||
{
|
||||
var function = vision["VisionFunctions"].AsArray().Single(f => Guid.Parse((string)f["ID"]) == FunctionId);
|
||||
ApplyToSteps(function["VisionFlows"]);
|
||||
}
|
||||
|
||||
internal void ApplyToSteps(JsonNode steps)
|
||||
{
|
||||
var step = steps[Index];
|
||||
if ((int)step["Type"] != (int)Type || step["StringParams"] is not JsonObject args ||
|
||||
args.ContainsKey(Key) != HadValue || (string)args[Key] != Before)
|
||||
throw new ProjectConflictException("视觉步骤参数已改变,请重新预览。");
|
||||
if (HasValue) args[Key] = After;
|
||||
else args.Remove(Key);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed partial class ProjectDirectory
|
||||
{
|
||||
private static Guid Owner(JsonNode row, string kind) => kind switch
|
||||
{
|
||||
"Cameras" => Guid.Empty,
|
||||
"ImageDatas" => Guid.Parse((string)row["RecipeID"]),
|
||||
"LocalImageDatas" => Guid.Parse((string)row["FuncID"]),
|
||||
_ => throw new ArgumentException("请选择 Cameras、ImageDatas 或 LocalImageDatas。")
|
||||
};
|
||||
|
||||
private JsonNode CheckAssetName(string kind, Guid id, string before, string after)
|
||||
{
|
||||
if (kind is not ("Cameras" or "ImageDatas" or "LocalImageDatas") || string.IsNullOrWhiteSpace(after) ||
|
||||
after.Trim() != after || after == before) throw new ArgumentException("视觉对象类型或新名称无效。");
|
||||
var rows = ProjectConfiguration.Capture(Data, [kind], false)[kind].AsArray();
|
||||
var target = rows.Single(r => Guid.Parse((string)r["ID"]) == id);
|
||||
if ((string)target["Name"] != before || rows.Any(r => r != target && Owner(r, kind) == Owner(target, kind) &&
|
||||
((string)r["Name"] == after || (string)r["Name"] == before)))
|
||||
throw new ProjectConflictException("对象已改变或在所属范围内存在重名。");
|
||||
return target;
|
||||
}
|
||||
|
||||
private static (string Key, string Fallback) Parameter(string kind, VisionFlowType type) => (kind, type) switch
|
||||
{
|
||||
("Cameras", VisionFlowType.拍照) => ("Camera", null),
|
||||
("ImageDatas", VisionFlowType.从全局图像获取图片 or VisionFlowType.存到全局图像) => ("Image", null),
|
||||
("LocalImageDatas", VisionFlowType.从局部图像获取图片 or VisionFlowType.存到局部图像 or VisionFlowType.图像相减) => ("Image", null),
|
||||
("LocalImageDatas", VisionFlowType.ORB匹配) => ("TemplateName", "ORB_Template"),
|
||||
("LocalImageDatas", VisionFlowType.灰度模板匹配) => ("TemplateName", "GrayMatch_Template"),
|
||||
("LocalImageDatas", VisionFlowType.SIFT匹配) => ("TemplateName", "SIFT_Template"),
|
||||
_ => default
|
||||
};
|
||||
|
||||
internal ProjectRename PlanVisionAssetRename(string kind, Guid id, string after)
|
||||
{
|
||||
CheckSavedRecipes();
|
||||
var target = ProjectInspection.Query(this, "get", new() { ["kind"] = kind, ["id"] = id.ToString() });
|
||||
var before = (string)target["Name"];
|
||||
CheckAssetName(kind, id, before, after);
|
||||
var recipe = kind == "Cameras" ? Guid.Empty : Guid.Parse((string)target["RecipeID"]);
|
||||
var vision = baseline[ConfigPath("vision")];
|
||||
List<VisionStepEdit> edits = [];
|
||||
foreach (var func in JsonNode.Parse(vision)["VisionFunctions"].AsArray())
|
||||
{
|
||||
var fid = Guid.Parse((string)func["ID"]);
|
||||
if (kind == "LocalImageDatas" && fid != Owner(target, kind) ||
|
||||
recipe != Guid.Empty && recipe != Guid.Parse((string)func["RecipeID"])) continue;
|
||||
var steps = func["VisionFlows"].AsArray();
|
||||
for (int i = 0; i < steps.Count; i++)
|
||||
{
|
||||
var type = (VisionFlowType)(int)steps[i]["Type"];
|
||||
var (key, fallback) = Parameter(kind, type);
|
||||
if (key == null) continue;
|
||||
var args = steps[i]["StringParams"].AsObject();
|
||||
var value = (string)args[key];
|
||||
if ((string.IsNullOrEmpty(value) ? fallback : value) == before)
|
||||
edits.Add(new(fid, i, type, key, args.ContainsKey(key), value, true, after));
|
||||
}
|
||||
}
|
||||
return PlanReferences(kind, id, recipe, before, after) with { OriginalVision = vision, VisionReferences = edits };
|
||||
}
|
||||
|
||||
private static Action PrepareSteps(ProjectRename plan, IEnumerable<VisionFunction> functions)
|
||||
{
|
||||
List<Action> actions = [];
|
||||
foreach (var function in functions)
|
||||
foreach (var edit in plan.VisionReferences.Where(e => e.FunctionId == function.ID))
|
||||
{
|
||||
var step = function.VisionFlows.ElementAtOrDefault(edit.Index);
|
||||
if (step?.Type != edit.Type || step.StringParams.TryGetValue(edit.Key, out var previous) != edit.HadValue ||
|
||||
previous != edit.Before) throw new ProjectConflictException("视觉步骤存在未保存的修改。");
|
||||
actions.Add(() =>
|
||||
{
|
||||
if (edit.HasValue) step.StringParams[edit.Key] = edit.After;
|
||||
else step.StringParams.Remove(edit.Key);
|
||||
});
|
||||
}
|
||||
return () => actions.ForEach(a => a());
|
||||
}
|
||||
|
||||
internal Action PrepareAssetView(ProjectRename plan, VisionsModel model, Guid recipe)
|
||||
{
|
||||
if (plan.Kind != "Cameras" && recipe != plan.RecipeId) return null;
|
||||
IEnumerable<INamedDevice> objects = plan.Kind switch
|
||||
{
|
||||
"Cameras" => model.Cameras,
|
||||
"ImageDatas" => model.ImageDatas,
|
||||
_ => model.VisionFunctions.Single(f => f.ID == Data.LocalImageDatas.Find(plan.ObjectId).FuncID).LocalImageDatas
|
||||
};
|
||||
var target = objects.Single(o => o.ID == plan.ObjectId);
|
||||
if (target.Name != plan.OldName || objects.Any(o => o.ID != target.ID && (o.Name == plan.NewName || o.Name == plan.OldName)))
|
||||
throw new ProjectConflictException("编辑器中的名称已改变。");
|
||||
var steps = PrepareSteps(plan, model.VisionFunctions);
|
||||
return () =>
|
||||
{
|
||||
target.SetReviewedName(plan.NewName);
|
||||
if (target is CameraBase cam) cam.Params.DiscoveryName = Data.Cameras.Find(target.ID).Params.DiscoveryName;
|
||||
steps();
|
||||
};
|
||||
}
|
||||
|
||||
private Action WriteVisionAsset(ProjectRename plan, Dictionary<string, string> files)
|
||||
{
|
||||
INamedDevice target = plan.Kind switch
|
||||
{
|
||||
"Cameras" => Data.Cameras.Find(plan.ObjectId),
|
||||
"ImageDatas" => Data.ImageDatas.Find(plan.ObjectId),
|
||||
_ => Data.LocalImageDatas.Find(plan.ObjectId)
|
||||
};
|
||||
if (target.Name != plan.OldName) throw new ProjectConflictException("对象存在未保存的名称修改。");
|
||||
var id = plan.ObjectId;
|
||||
string discovery = null;
|
||||
int count;
|
||||
if (target is CameraBase)
|
||||
{
|
||||
var row = JsonNode.Parse(files[plan.MetadataPath])["Cameras"].AsArray().Single(r => Guid.Parse((string)r["ID"]) == id);
|
||||
discovery = (string)row["Params"]?["DiscoveryName"];
|
||||
var json = row["Params"].ToJsonString();
|
||||
count = Data.Cameras.Where(c => c.ID == id && c.Name == plan.OldName)
|
||||
.ExecuteUpdate(s => s.SetProperty(c => c.Name, plan.NewName).SetProperty(c => c.SerializedParams, json));
|
||||
}
|
||||
else if (target is ImageData)
|
||||
count = Data.ImageDatas.Where(i => i.ID == id && i.Name == plan.OldName).ExecuteUpdate(s => s.SetProperty(i => i.Name, plan.NewName));
|
||||
else
|
||||
count = Data.LocalImageDatas.Where(i => i.ID == id && i.Name == plan.OldName).ExecuteUpdate(s => s.SetProperty(i => i.Name, plan.NewName));
|
||||
if (count != 1) throw new ProjectConflictException("视觉对象已改变。");
|
||||
List<VisionFunction> tracked = [];
|
||||
foreach (var group in plan.VisionReferences.GroupBy(e => e.FunctionId))
|
||||
{
|
||||
var fid = group.Key;
|
||||
var raw = Data.VisionFunctions.Where(f => f.ID == fid).Select(f => f.SerializedVisionFlows).Single();
|
||||
var steps = JsonNode.Parse(raw);
|
||||
foreach (var edit in group) edit.ApplyToSteps(steps);
|
||||
var json = steps.ToJsonString();
|
||||
if (Data.VisionFunctions.Where(f => f.ID == fid && f.SerializedVisionFlows == raw)
|
||||
.ExecuteUpdate(s => s.SetProperty(f => f.SerializedVisionFlows, json)) != 1)
|
||||
throw new ProjectConflictException("视觉步骤已经改变。");
|
||||
tracked.Add(Data.VisionFunctions.Find(fid));
|
||||
}
|
||||
var update = PrepareSteps(plan, tracked);
|
||||
return () =>
|
||||
{
|
||||
target.SetReviewedName(plan.NewName);
|
||||
Data.Entry((object)target).Property("Name").OriginalValue = plan.NewName;
|
||||
if (target is CameraBase camera)
|
||||
{
|
||||
camera.Params.DiscoveryName = discovery;
|
||||
Data.Entry(camera).Property(c => c.SerializedParams).OriginalValue = camera.SerializedParams;
|
||||
}
|
||||
update();
|
||||
foreach (var f in tracked) Data.Entry(f).Property(v => v.SerializedVisionFlows).OriginalValue = f.SerializedVisionFlows;
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp;
|
||||
using PLCSharp.Core.Tools;
|
||||
using Prism.Commands;
|
||||
using Prism.Mvvm;
|
||||
@ -14,7 +14,7 @@ namespace PLCSharp.VVMs.Vision.Camera
|
||||
/// <summary>
|
||||
/// 相机Base
|
||||
/// </summary>
|
||||
public partial class CameraBase : BindableBase
|
||||
public partial class CameraBase : BindableBase, PLCSharp.Models.INamedDevice
|
||||
{
|
||||
/// <summary>
|
||||
/// 唯一标识
|
||||
@ -22,6 +22,7 @@ namespace PLCSharp.VVMs.Vision.Camera
|
||||
[Key]
|
||||
public Guid ID { get; set; } = Guid.NewGuid();
|
||||
|
||||
void PLCSharp.Models.INamedDevice.SetReviewedName(string value) => SetProperty(ref _Name, value, nameof(Name));
|
||||
private string _Name;
|
||||
|
||||
/// <summary>
|
||||
@ -297,6 +298,8 @@ namespace PLCSharp.VVMs.Vision.Camera
|
||||
/// </summary>
|
||||
public class CameraParams : BindableBase
|
||||
{
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string DiscoveryName { get; set; }
|
||||
private double _MinExposureTime;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp;
|
||||
using Prism.Mvvm;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
@ -9,7 +9,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
/// <summary>
|
||||
/// 图像数据
|
||||
/// </summary>
|
||||
public class ImageData : BindableBase
|
||||
public class ImageData : BindableBase, PLCSharp.Models.INamedDevice
|
||||
{
|
||||
/// <summary>
|
||||
/// 唯一标识
|
||||
@ -22,6 +22,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
/// </summary>
|
||||
public Guid RecipeID { get; set; }
|
||||
|
||||
void PLCSharp.Models.INamedDevice.SetReviewedName(string value) => Name = value;
|
||||
private string _Name;
|
||||
|
||||
/// <summary>
|
||||
@ -99,7 +100,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
}
|
||||
}
|
||||
|
||||
public class LocalImageData : BindableBase
|
||||
public class LocalImageData : BindableBase, PLCSharp.Models.INamedDevice
|
||||
{
|
||||
/// <summary>
|
||||
/// 唯一标识
|
||||
@ -112,6 +113,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
/// </summary>
|
||||
public Guid FuncID { get; set; }
|
||||
|
||||
void PLCSharp.Models.INamedDevice.SetReviewedName(string value) => Name = value;
|
||||
private string _Name;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using PLCSharp.Core.Prism;
|
||||
using PLCSharp.Core.Prism;
|
||||
using PLCSharp.Core.Tools;
|
||||
using PLCSharp.Models;
|
||||
using PLCSharp.VVMs.Vision.Camera;
|
||||
@ -29,9 +29,10 @@ namespace PLCSharp.VVMs.Vision
|
||||
switch (item.Brand)
|
||||
{
|
||||
case CameraBrand.HikRobot:
|
||||
var camera = _HikCameras.Cameras.Where(c => c.Name == item.Name).FirstOrDefault();
|
||||
var camera = _HikCameras.Cameras.Where(c => c.Name == (item.Params.DiscoveryName ?? item.Name)).FirstOrDefault();
|
||||
if (camera != null)
|
||||
{
|
||||
camera.Name = item.Name;
|
||||
camera.Params = item.Params;
|
||||
camera.ID = item.ID;
|
||||
camera.Comment = item.Comment;
|
||||
@ -353,7 +354,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
}
|
||||
else
|
||||
{
|
||||
var camera = _DatasContext.Cameras.Where(c => c.Name == item.Name).FirstOrDefault();
|
||||
var camera = _DatasContext.Cameras.Single(c => c.ID == item.ID);
|
||||
|
||||
camera.Params = item.Params;
|
||||
camera.Comment = item.Comment;
|
||||
|
||||
@ -11,7 +11,7 @@ public partial class ScriptReviewWindow : Window
|
||||
InitializeComponent();
|
||||
if (change.Rename is { } rename)
|
||||
{
|
||||
var subject = rename.Kind switch { "Cylinders" => "气缸", "Robots" => "机器人", "Connects" => "通信连接",
|
||||
var subject = rename.Kind switch { "Cameras" => "相机", "ImageDatas" => "视觉图像数据", "LocalImageDatas" => "本地图像数据", "Cylinders" => "气缸", "Robots" => "机器人", "Connects" => "通信连接",
|
||||
"DI" => "数字输入", "DQ" => "数字输出", "Axes" => "运动轴", "VisionFunctions" => "视觉功能", "Workflows" => "工作流",
|
||||
"AxisPoints" or "RobotPoints" => "点位", _ => "变量" };
|
||||
Title = $"确认{(rename.UndoOf.HasValue ? "撤销" : "")}{subject}重命名";
|
||||
@ -20,6 +20,7 @@ public partial class ScriptReviewWindow : Window
|
||||
CheckResult.Text = $"已通过编译的工作流:{rename.Scripts.Count},需人工核对的引用:{rename.ManualReferences.Count}";
|
||||
CodeDiff.Text = string.Join("\n", rename.PointReferences.Select(p => $"configuration/points.json · {p.Table}/{p.Id} · {p.Field}:{rename.OldName} → {rename.NewName}")
|
||||
.Concat(rename.CylinderReferences.Select(p => $"configuration/hardware.json · {p.Table}/{p.Id} · {p.Field}:{rename.OldName} → {rename.NewName}"))
|
||||
.Concat(rename.VisionReferences.Select(e => $"configuration/vision.json · {e.FunctionId} · 步骤 {e.Index + 1} · {e.Key}:{rename.OldName} → {rename.NewName}"))
|
||||
.Concat(rename.MatrixReferences.Select(m => $"{m.Table}/{m.Id} · {m.Field}:{rename.OldName} → {rename.NewName}"))
|
||||
.Concat(rename.ManualReferences.Select(h =>
|
||||
$"待核对 [{h["confidence"]}] {h["path"]}:{h["line"]} {h["expression"]}"))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user