public LadderDiagramReplaceNetworksCommand( LadderDiagramViewModel ld, LadderNetworkViewModel replacedNet, IEnumerable <LadderNetworkViewModel> removedNets, int index, NetworkChangeElementArea area = null, NetworkChangeElementArea oldarea = null) { _ladderDiagram = ld; _replacedNetworks = new SortedSet <LadderNetworkViewModel>() { replacedNet }; _removedNetworks = new SortedSet <LadderNetworkViewModel>(removedNets); _index = index; _oldarea = oldarea; _area = area; if (_oldarea == null) { _oldarea = NetworkChangeElementArea.Create( _ladderDiagram, _removedNetworks); } if (_area == null) { _area = NetworkChangeElementArea.Create( _ladderDiagram, _replacedNetworks); } }
public void Unroute(LadderDiagramViewModel ldvmodel) { foreach (LadderNetworkViewModel lnvmodel in ldvmodel.GetNetworks()) { Unroute(lnvmodel); } }
private void OnBreakpointChanged(object sender, BreakpointChangedEventArgs e) { LadderNetworkViewModel lnvmodel = (LadderNetworkViewModel)sender; LadderDiagramViewModel ldvmodel = lnvmodel.LDVModel; IEnumerable <SimuBrpoElement> fit = null; SimuBrpoElement ele = null; if (e.BPRect_old != null) { fit = items.Where((_ele) => { return(_ele.BPRect == e.BPRect_old); }); if (fit.Count() > 0) { ele = fit.First(); Unactive(ele); items.Remove(ele); } } if (e.BPRect_new != null) { ele = new SimuBrpoElement(); ele.IsActive = true; ele.LDVModel = ldvmodel; ele.LNVModel = lnvmodel; ele.BVModel = e.BPRect_new.BVModel; ele.BPRect = e.BPRect_new; ele.BreakTime = "1"; items.Add(ele); Active(ele); } PropertyChanged(this, new PropertyChangedEventArgs("Items")); ifacade.MainWindow.LACBreakpoint.Show(); }
private static void Setup(LadderDiagramViewModel ldvmodel) { foreach (LadderNetworkViewModel lnvmodel in ldvmodel.GetNetworks()) { Setup(lnvmodel); } }
public void Initialize() { pmodel = new ProjectModel("效果展示"); ldvmodel = new LadderDiagramViewModel("效果展示", pmodel); lnvmodel = ldvmodel.GetNetworks().First(); ldvmodel.LadderMode = LadderMode.Demo; ldvmodel.Visibility = Visibility.Hidden; GD_Main.Children.Add(ldvmodel); LDDemoViewModel ldmodel = new LDDemoViewModel(); LDWEQDemoViewModel ldweqmodel = new LDWEQDemoViewModel(); SMOVDemoViewModel smovmodel = new SMOVDemoViewModel(); lnvmodel.LadderCanvas.Children.Add(ldmodel); lnvmodel.LadderCanvas.Children.Add(ldweqmodel); lnvmodel.LadderCanvas.Children.Add(smovmodel); lnvmodel.CommentAreaExpander.IsEnabled = false; lnvmodel.ladderExpander.IsEnabled = false; lnvmodel.LadderCanvas.IsEnabled = false; ldvmodel.CommentAreaExpander.IsEnabled = false; ldvmodel.ladderExpander.IsEnabled = false; ldvmodel.IsCommentMode = true; fbvmodel = new FuncBlockViewModel("效果展示", null); fbvmodel.Code = "void Func(WORD* w1, WORD* w2, WORD* w3)\n{\n\tw3[0] = w1[0] + w2[0];\n}\n"; fbvmodel.CodeTextBox.IsReadOnly = true; GD_Main.Children.Add(fbvmodel); fbvmodel.Visibility = Visibility.Hidden; }
private BackTraceElement GetElement(int bpaddr) { BaseViewModel bvmodel = BreakPointManager.GetBVModel(bpaddr); if (bvmodel != null) { LadderNetworkViewModel lnvmodel = ifacade.ProjectModel.GetNetwork(bvmodel); if (lnvmodel == null) { return(null); } LadderDiagramViewModel ldvmodel = lnvmodel.LDVModel; SimuBrpoElement brpo = new SimuBrpoElement(); brpo.LDVModel = ldvmodel; brpo.LNVModel = lnvmodel; brpo.BVModel = bvmodel; return(new BackTraceElement(BackTraceType.Diagram, brpo)); } FuncBlock fblock = BreakPointManager.GetFBlock(bpaddr); if (fblock != null) { FuncBlockViewModel fbvmodel = ifacade.ProjectModel.GetFuncBlock(fblock); if (fbvmodel == null) { return(null); } FuncBrpoElement brpo = new FuncBrpoElement(); brpo.FBVModel = fbvmodel; brpo.FBlock = fblock; return(new BackTraceElement(BackTraceType.FuncBlock, brpo)); } return(new BackTraceElement(BackTraceType.External)); }
public void Undo() { // ToList确保在遍历时可以修改 var movedElements = _network.GetElements().Where(e => e.Y > _rowNumber).ToList().OrderBy(x => { return(x.Y); }); var movedVLines = _network.GetVerticalLines().Where(e => e.Y > _rowNumber).ToList().OrderBy(x => { return(x.Y); }); foreach (var ele in movedElements) { _network.RemoveEle(ele.X, ele.Y); ele.Y--; _network.ReplaceEle(ele); } foreach (var vline in movedVLines) { _network.RemoveVLine(vline.X, vline.Y); vline.Y--; _network.ReplaceVLine(vline); } _network.RowCount = _oldRowCount; //_network.INVModel.Setup(_network); // 将梯形图光标移到删除的行的位置 _network.AcquireSelectRect(); LadderDiagramViewModel ldvmodel = _network.LDVModel; ldvmodel.SelectionRect.X = 0; ldvmodel.SelectionRect.Y = (_rowNumber < _network.RowCount ? _rowNumber : _rowNumber - 1); ldvmodel.ProjectModel.IFacade.NavigateToNetwork( new NavigateToNetworkEventArgs( _network.NetworkNumber, ldvmodel.ProgramName, ldvmodel.SelectionRect.X, ldvmodel.SelectionRect.Y)); }
public void Undo() { if (bvmodel.InstructionName.Equals("CALLM")) { int argcount = (pstring_old.Count() - 2) / 4; ArgumentValue[] _values = new ArgumentValue[argcount]; for (int i = 0; i < argcount; i++) { _values[i] = ArgumentValue.Create( pstring_old[i * 4 + 3], pstring_old[i * 4 + 2], pstring_old[i * 4 + 4], PLCDevice.PLCDeviceManager.GetPLCDeviceManager().SelectDevice); _values[i].Comment = pstring_old[i * 4 + 5]; } ((CALLMViewModel)(bvmodel)).AcceptNewValues( pstring_old[0], pstring_old[1], _values); } else { bvmodel.AcceptNewValues(pstring_old, PLCDevice.PLCDeviceManager.GetPLCDeviceManager().SelectDevice); } //lnvmodel.INVModel.Setup(lnvmodel); // 导航到修改参数的元件 lnvmodel.AcquireSelectRect(); LadderDiagramViewModel ldvmodel = lnvmodel.LDVModel; ldvmodel.SelectionRect.X = bvmodel.X; ldvmodel.SelectionRect.Y = bvmodel.Y; ldvmodel.ProjectModel.IFacade.NavigateToNetwork( new NavigateToNetworkEventArgs( lnvmodel.NetworkNumber, ldvmodel.ProgramName, ldvmodel.SelectionRect.X, ldvmodel.SelectionRect.Y)); }
private static bool CheckProgramControlInstructions(LadderDiagramViewModel ladderDiagram) { List <BaseViewModel> eles = GetProgramControlViewModels(ladderDiagram); List <BaseViewModel> eles_for = eles.Where(x => { return(x.GetType() == typeof(FORViewModel)); }).ToList(); List <BaseViewModel> eles_next = eles.Where(x => { return(x.GetType() == typeof(NEXTViewModel)); }).ToList(); List <BaseViewModel> eles_jmp = eles.Where(x => { return(x.GetType() == typeof(JMPViewModel)); }).ToList(); List <BaseViewModel> eles_lbl = eles.Where(x => { return(x.GetType() == typeof(LBLViewModel)); }).ToList(); if (eles_for.Count != eles_next.Count || eles_jmp.Count != eles_lbl.Count) { return(false); } else { foreach (var ele_jmp in eles_jmp) { string lblindex = (ele_jmp.Model as JMPModel).LBLIndex.ToString(); if (!eles_lbl.Exists(x => { return((x.Model as LBLModel).LBLIndex.ToString() == lblindex); })) { return(false); } } return(true); } }
private void OnMenuItemClick(object sender, RoutedEventArgs e) { LadderDiagramViewModel ldvmodel = lnvmodel.LDVModel; for (int i = 0; i < Count; i++) { if (sender == MI_Values[i]) { ShowModifyDialog(i); } } if (sender == MI_Breakpoint) { switch (MI_Breakpoint.Header.ToString()) { case "添加断点": BreakpointRect brect = new BreakpointRect(String.Empty); brect.BVModel = bvmodel; ldvmodel.ReplaceBreakpoint(lnvmodel, brect); break; case "删除断点": ldvmodel.RemoveBreakpoint(lnvmodel, bvmodel.BPRect); break; } } }
private void Initialize(LadderDiagramViewModel ldvmodel) { foreach (LadderNetworkViewModel lnvmodel in ldvmodel.GetNetworks()) { Initialize(lnvmodel); } }
public void Add(LadderDiagramViewModel ldmodel) { if (!SubRoutines.Contains(ldmodel)) { SubRoutines.Add(ldmodel); IsModify = true; } }
public virtual void Dispose() { lnvmodel.ElementChanged -= OnElementChanged; parent = null; bvmodel = null; ldvmodel = null; lnvmodel = null; }
public void Remove(LadderDiagramViewModel ldmodel) { if (SubRoutines.Contains(ldmodel)) { SubRoutines.Remove(ldmodel); IsModify = true; } }
public FindElement ( FindWindow _parent, BaseViewModel _bvmodel, LadderDiagramViewModel _ldvmodel, LadderNetworkViewModel _lnvmodel ) : base(null, _bvmodel, _ldvmodel, _lnvmodel) { parent = _parent; }
public ErrorReportElement ( PLCOriginInst _inst, LadderNetworkViewModel _lnvmodel, LadderDiagramViewModel _ldvmodel ) { this.inst = _inst; this.lnvmodel = _lnvmodel; this.ldvmodel = _ldvmodel; }
public LadderNetworkViewModel GetNetwork(BaseViewModel bvmodel, LadderDiagramViewModel ldvmodel) { foreach (LadderNetworkViewModel lnvmodel in ldvmodel.GetNetworks()) { if (lnvmodel.ContainBPAddr(bvmodel.BPAddress)) { return(lnvmodel); } } return(null); }
static public NetworkChangeElementArea Create( LadderDiagramViewModel ldvmodel, IEnumerable <LadderNetworkViewModel> lnvmodels) { NetworkChangeElementArea area = null; foreach (LadderNetworkViewModel lnvmodel in lnvmodels) { Analyze(ldvmodel, lnvmodel, ref area); } return(area); }
private void AddElementByRoutine(LadderDiagramViewModel ldmodel, MonitorVariableTable table, int startindex, int endindex) { foreach (var network in ldmodel.LadderNetworks.Where(x => { return(x.NetworkNumber >= startindex && x.NetworkNumber <= endindex); })) { if (network.IsMasked) { continue; } AddElementByNetWork(network, table); } tables.Add(table); }
public LadderDiagramReplaceNetworksCommand( LadderDiagramViewModel ld, IEnumerable <LadderNetworkViewModel> replacedNets, IEnumerable <LadderNetworkViewModel> removedNets, int index, NetworkChangeElementArea area = null, NetworkChangeElementArea oldarea = null) { _ladderDiagram = ld; _replacedNetworks = new SortedSet <LadderNetworkViewModel>(replacedNets); _removedNetworks = new SortedSet <LadderNetworkViewModel>(removedNets); _index = index; _oldarea = oldarea; _area = area; }
private void _Thread_Run() { isalive = true; Started(this, new RoutedEventArgs()); while (thalive) { do { isactive = false; Paused(this, new RoutedEventArgs()); Thread.Sleep(GlobalSetting.InstTimeSpan * 1000); } while (thalive && (!GlobalSetting.IsInstByTime || !thactive)); if (!thalive) { break; } isactive = true; Resumed(this, new RoutedEventArgs()); ProjectModel pmodel = ifacade.ProjectModel; if (pmodel == null) { continue; } LadderDiagramViewModel main = pmodel.MainRoutine; if (main == null) { continue; } _Thread_Update(main); if (!thalive) { break; } foreach (LadderDiagramViewModel ldvmodel in pmodel.SubRoutines) { _Thread_Update(ldvmodel); if (!thalive) { break; } } if (!thalive) { break; } } isalive = false; thread = null; Aborted(this, new RoutedEventArgs()); }
public void Select(LadderNetworkViewModel lnvmodel) { if (this == Empty) { return; } LadderDiagramViewModel ldvmodel = lnvmodel.LDVModel; ProjectModel pmodel = ldvmodel.ProjectModel; InteractionFacade ifacade = pmodel.IFacade; ldvmodel.AcquireArea(this); ifacade.MainTabControl.ShowItem(ldvmodel); }
private static List <BaseViewModel> GetProgramControlViewModels(LadderDiagramViewModel ladderDiagram) { List <BaseViewModel> eles = new List <BaseViewModel>(); foreach (var network in ladderDiagram.GetNetworks().Where(x => { return(!x.IsMasked); })) { foreach (var model in network.GetElements().Where(x => { return(x.GetType() == typeof(FORViewModel) || x.GetType() == typeof(NEXTViewModel) || x.GetType() == typeof(JMPViewModel) || x.GetType() == typeof(LBLViewModel)); })) { eles.Add(model); } } return(eles); }
static private void Initialize(LadderDiagramViewModel ldvmodel) { foreach (LadderNetworkViewModel lnvmodel in ldvmodel.GetNetworks()) { foreach (BaseViewModel bvmodel in lnvmodel.GetElements()) { BaseModel bmodel = bvmodel.Model; if (bmodel == null) { continue; } if (bmodel is TONModel) { TONModel tmodel = (TONModel)(bmodel); IValueModel ivmodel = tmodel.TimerValue; if (ivmodel.IsVariable) { continue; } if (ivmodel is TVWordValue) { int index = (int)(ivmodel.Index); timers[index] = new SFCTimerModel(tmodel); } } else { for (int i = 0; i < bmodel.ParaCount; i++) { IValueModel ivmodel = bmodel.GetPara(i); if (ivmodel is SBitValue) { int index = (int)(ivmodel.Index); if (status[index] == null) { status[index] = new SFCStatusModel(ldvmodel); } else if (status[index].LDVModel != ldvmodel) { status[index] = new SFCInvalidStatusModel(); } } } } } } }
/// <summary> 构造函数 </summary> public ReplaceElement ( ReplaceWindow _parent, BaseViewModel _bvmodel, LadderDiagramViewModel _ldvmodel, LadderNetworkViewModel _lnvmodel ) { parent = _parent; bvmodel = _bvmodel; ldvmodel = _ldvmodel; lnvmodel = _lnvmodel; lnvmodel.ElementChanged += OnElementChanged; PropertyChanged(this, new PropertyChangedEventArgs("Detail")); PropertyChanged(this, new PropertyChangedEventArgs("Diagram")); PropertyChanged(this, new PropertyChangedEventArgs("Network")); }
public static XElement CreateXElementByLadderDiagram(LadderDiagramViewModel ldmodel) { XElement result = new XElement("Ladder"); result.SetAttributeValue("Name", ldmodel.ProgramName); result.SetAttributeValue("IsExpand", ldmodel.ladderExpander.IsExpand); if (ldmodel.IsMainLadder) { result.SetAttributeValue("IsMain", "True"); } foreach (var net in ldmodel.GetNetworks()) { var netEle = CreateXElementByLadderNetwork(net); result.Add(netEle); } return(result); }
public ProjectModel(string projectname) { ProjectName = projectname; MainRoutine = new LadderDiagramViewModel("Main", this); MainRoutine.IsMainLadder = true; MMonitorManager = new MonitorManager(this); MTVModel = new ModbusTableViewModel(this); MMonitorManager.MMWindow.Manager = MMonitorManager; PManager = new SerialPortManager(); UManager = new USBManager(); StreamReader sr = new StreamReader( String.Format(@"{0:s}\simug\simuflib.c", FileHelper.AppRootPath)); FuncBlockViewModel libfuncblock = new FuncBlockViewModel(Properties.Resources.Library_Function, this); libfuncblock.Code = sr.ReadToEnd(); libfuncblock.IsReadOnly = true; LibFuncBlock = libfuncblock; }
private void _Thread_Update(LadderDiagramViewModel ldvmodel) { foreach (LadderNetworkViewModel lnvmodel in ldvmodel.GetNetworks()) { InstructionNetworkViewModel invmodel = lnvmodel.INVModel; if (invmodel != null && invmodel.IsModified) { invmodel.Dispatcher.Invoke(new Utility.Delegates.Execute(() => { invmodel.Update(); })); } if (!thalive) { return; } } }
/// <summary> /// 在给定程序内查找指令 /// </summary> /// <param name="ldvmodel"></param> private void Find(LadderDiagramViewModel ldvmodel) { foreach (LadderNetworkViewModel lnvmodel in ldvmodel.GetNetworks()) { foreach (BaseViewModel bvmodel in lnvmodel.GetElements()) { if (bvmodel is HorizontalLineViewModel || bvmodel is VerticalLineViewModel) { continue; } BaseModel bmodel = bvmodel.Model; if (RF_Input.Match(bvmodel.ToInstString())) { items.Add(new ReplaceElement(this, bvmodel, ldvmodel, lnvmodel)); } } } }
public void Redo() { _network.RemoveElements(_removedElements); _network.RemoveVerticalLines(_removedVerticalLines); var movedElements = _network.GetElements().Where(e => e.Y > _startRow + _count - 1).ToList().OrderBy(x => { return(x.Y); }); var movedVLines = _network.GetVerticalLines().Where(e => e.Y > _startRow + _count - 1).ToList().OrderBy(x => { return(x.Y); }); foreach (var ele in movedElements) { _network.RemoveEle(ele.X, ele.Y); ele.Y -= _count; _network.ReplaceEle(ele); } foreach (var vline in movedVLines) { _network.RemoveVLine(vline.X, vline.Y); vline.Y -= _count; _network.ReplaceVLine(vline); } InstructionCommentManager.RaiseMappedMessageChangedEvent(); _oldRowCount = _network.RowCount; if (_count == _network.RowCount) { _network.RowCount = 1; } else { _network.RowCount -= _count; } _network.AcquireSelectRect(); LadderDiagramViewModel ldvmodel = _network.LDVModel; ldvmodel.SelectionRect.X = 0; ldvmodel.SelectionRect.Y = (_startRow < _network.RowCount ? _startRow : _startRow - 1); ldvmodel.ProjectModel.IFacade.NavigateToNetwork( new NavigateToNetworkEventArgs( _network.NetworkNumber, ldvmodel.ProgramName, ldvmodel.SelectionRect.X, ldvmodel.SelectionRect.Y)); }