public StateMachinePropertyGridSource(StateMachineViewModel stateMachine) { if (stateMachine == null) { throw new ArgumentNullException(nameof(stateMachine)); } _stateMachine = stateMachine; _stateMachine.PropertyChanged += StateMachinePropertyChanged; }
public StateDialogViewModel(StateMachineViewModel parent, State model, Action <State> updateParent, IMessageBoxService messageBoxService) { _parent = parent ?? throw new ArgumentNullException(nameof(parent)); _model = model ?? throw new ArgumentNullException(nameof(model)); Outputs = _parent.Outputs ?? throw new ArgumentNullException(nameof(_parent.Outputs)); _messageBoxService = messageBoxService ?? throw new ArgumentNullException(nameof(messageBoxService)); _updateParent = updateParent; InitializeActions(); OkCommand = new RelayCommand(Ok); DirtyService.MarkClean(); }
public TransitionEditorViewModel( StateMachineTransition model, StateMachineViewModel parent, Action <StateMachineTransition> updateParentModel, IMessageBoxService messageBoxService) { _model = model ?? throw new ArgumentNullException(nameof(model)); _updateParentModel = updateParentModel; _parent = parent ?? throw new ArgumentNullException(nameof(parent)); _messageBoxService = messageBoxService ?? throw new ArgumentNullException(nameof(messageBoxService)); Inputs = new ObservableCollection <StateMachineInputViewModel>(parent.Inputs); Outputs = new ObservableCollection <StateMachineOutputActionViewModel>(parent.Outputs); _transition = ApplicationContainer.Container.Resolve <TransitionViewModel>( new TypedParameter(typeof(StateMachineViewModel), parent), new TypedParameter(typeof(StateMachineTransition), model) ); Actions = new OrderedListDesigner <StateMachineOutputActionViewModel>(NewFactory, parent.Outputs.Where(o => _transition.Actions.Contains(o.Id))); _actions.ListChanged += ActionsOnListChanged; Name = Transition.Name; Criteria = new CriteriaTransitionViewModel(this, _messageBoxService); OkCommand = new RelayCommand(Ok); _dirtyService.MarkClean(); RecalculateConditionText(); Criteria.PropertyChanged += CriteriaPropertyChanged; if (Criteria.RootCondition != null) { Criteria.RootCondition.ConditionChanged += RootConditionChanged; } }
public StateMachineVisualiserForm(int memoryLocation, string memory) : this() { _stateMachineViewModel = new StateMachineViewModel(memoryLocation, memory); this.Paint += FormPaint; }
private void SaveImage(StateMachine stateMachine, string pngPath) { var stateMachineViewModel = new StateMachineViewModel( stateMachine, ApplicationContainer.Container.Resolve <IViewService>(), null, null, ApplicationContainer.Container.Resolve <IMessageBoxService>(), true); //Render using this approach // https://stackoverflow.com/a/5189179/232566 StateMachineView control = new StateMachineView { DataContext = stateMachineViewModel }; const int temporarySize = 800; control.Measure(new System.Windows.Size(temporarySize, temporarySize)); control.Arrange(new Rect(new System.Windows.Size(temporarySize, temporarySize))); control.UpdateLayout(); //Calculate the bounds of the state machine var bounds = VisualTreeHelper.GetDescendantBounds(control.RenderRoot); int width = (int)bounds.Width; int height = (int)bounds.Height; //There are errors if these are 0. if (width > 0 && height > 0) { //Got the render transform idea here: // https://stackoverflow.com/a/224492/232566 DrawingVisual visual = new DrawingVisual(); using (DrawingContext context = visual.RenderOpen()) { //Create a brush that references the visual representation of the state machine VisualBrush brush = new VisualBrush(control.RenderRoot); //Fill the visual with our background context.DrawRectangle(System.Windows.Media.Brushes.White, null, bounds); //Draw the system onto the visual context.DrawRectangle(brush, null, bounds); } //Apply a transform that positions the system near (0, 0) visual.Transform = new TranslateTransform(bounds.X * -1, bounds.Y * -1); //Create the render target RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32); //Render it bmp.Render(visual); using (MemoryStream stream = new MemoryStream()) { BitmapEncoder encoder2 = new BmpBitmapEncoder(); encoder2.Frames.Add(BitmapFrame.Create(bmp)); encoder2.Save(stream); using (Bitmap bitmap = new Bitmap(stream)) { //Save it bitmap.Save(pngPath); } }; } }