Esempio n. 1
0
        public ShellViewModel()
        {
            _messageBoxService         = ApplicationServicesProvider.Instance.Provider.MessageBoxService;
            Diagram                    = new Diagram();
            DeleteSelectedItemsCommand = new RelayCommand(ExecuteDeleteSelectedItemsCommand);
            CreateNewDiagramCommand    = new RelayCommand(ExecuteCreateNewDiagramCommand);
            SettingsDesignerItemViewModel item1 = new SettingsDesignerItemViewModel();

            item1.Parent = Diagram;
            item1.Left   = 100;
            item1.Top    = 100;
            Diagram.Items.Add(item1);
            PersistDesignerItemViewModel item2 = new PersistDesignerItemViewModel();

            item2.Parent = Diagram;
            item2.Left   = 300;
            item2.Top    = 300;
            Diagram.Items.Add(item2);
            item1.Connect(item2, ConnectorOrientation.Right, ConnectorOrientation.Left);
            this.Tools.Add(new SettingsDesignerItemViewModel());
            this.Tools.Add(new PersistDesignerItemViewModel());
            this.Tools.Add(new FanViewModel());
            this.Tools.Add(new LightViewModel());
            this.Tools.Add(new TankViewModel {
                Percent = 20
            });
            this.Tools.Add(new ThermometerViewModel {
                Value = 50
            });
        }
Esempio n. 2
0
        private void LoadPerstistDesignerItems(IDiagramItem wholeDiagramToLoad, IDiagramViewModel diagramViewModel)
        {
            //load diagram items
            foreach (DiagramItemData diagramItemData in wholeDiagramToLoad.DesignerItems)
            {
                if (diagramItemData.ItemType == typeof(PersistDesignerItem))
                {
                    PersistDesignerItem          persistedDesignerItem        = databaseAccessService.FetchPersistDesignerItem(diagramItemData.ItemId);
                    PersistDesignerItemViewModel persistDesignerItemViewModel =
                        new PersistDesignerItemViewModel(persistedDesignerItem.Id, diagramViewModel, persistedDesignerItem.Left, persistedDesignerItem.Top, persistedDesignerItem.ItemWidth, persistedDesignerItem.ItemHeight, persistedDesignerItem.HostUrl);
                    diagramViewModel.Items.Add(persistDesignerItemViewModel);
                }
                if (diagramItemData.ItemType == typeof(SettingsDesignerItem))
                {
                    SettingsDesignerItem          settingsDesignerItem          = databaseAccessService.FetchSettingsDesignerItem(diagramItemData.ItemId);
                    SettingsDesignerItemViewModel settingsDesignerItemViewModel =
                        new SettingsDesignerItemViewModel(settingsDesignerItem.Id, diagramViewModel, settingsDesignerItem.Left, settingsDesignerItem.Top, settingsDesignerItem.ItemWidth, settingsDesignerItem.ItemHeight, settingsDesignerItem.Setting1);
                    diagramViewModel.Items.Add(settingsDesignerItemViewModel);
                }
                if (diagramItemData.ItemType == typeof(GroupDesignerItem))
                {
                    GroupDesignerItem             groupDesignerItem             = databaseAccessService.FetchGroupingDesignerItem(diagramItemData.ItemId);
                    GroupingDesignerItemViewModel groupingDesignerItemViewModel =
                        new GroupingDesignerItemViewModel(groupDesignerItem.Id, diagramViewModel, groupDesignerItem.Left, groupDesignerItem.Top, groupDesignerItem.ItemWidth, groupDesignerItem.ItemHeight);
                    if (groupDesignerItem.DesignerItems != null && groupDesignerItem.DesignerItems.Count > 0)
                    {
                        LoadPerstistDesignerItems(groupDesignerItem, groupingDesignerItemViewModel);
                    }
                    diagramViewModel.Items.Add(groupingDesignerItemViewModel);
                }
            }
            //load connection items
            foreach (int connectionId in wholeDiagramToLoad.ConnectionIds)
            {
                Connection connection = databaseAccessService.FetchConnection(connectionId);

                DesignerItemViewModelBase sourceItem = GetConnectorDataItem(diagramViewModel, connection.SourceId, connection.SourceType);
                ConnectorOrientation      sourceConnectorOrientation = GetOrientationForConnector(connection.SourceOrientation);
                FullyCreatedConnectorInfo sourceConnectorInfo        = GetFullConnectorInfo(connection.Id, sourceItem, sourceConnectorOrientation);

                DesignerItemViewModelBase sinkItem = GetConnectorDataItem(diagramViewModel, connection.SinkId, connection.SinkType);
                ConnectorOrientation      sinkConnectorOrientation = GetOrientationForConnector(connection.SinkOrientation);
                FullyCreatedConnectorInfo sinkConnectorInfo        = GetFullConnectorInfo(connection.Id, sinkItem, sinkConnectorOrientation);

                ConnectorViewModel connectionVM = new ConnectorViewModel(connection.Id, diagramViewModel, sourceConnectorInfo, sinkConnectorInfo);
                diagramViewModel.Items.Add(connectionVM);
            }
        }
        /// <summary>
        /// This shows you how you can create diagram items in code, which means you can 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Window1_Loaded(object sender, RoutedEventArgs e)
        {
            SettingsDesignerItemViewModel item1 = new SettingsDesignerItemViewModel();
            item1.Parent = window1ViewModel.DiagramViewModel;
            item1.Left = 100;
            item1.Top = 100;
            window1ViewModel.DiagramViewModel.Items.Add(item1);

            PersistDesignerItemViewModel item2 = new PersistDesignerItemViewModel();
            item2.Parent = window1ViewModel.DiagramViewModel;
            item2.Left = 300;
            item2.Top = 300;
            window1ViewModel.DiagramViewModel.Items.Add(item2);

            ConnectorViewModel con1 = new ConnectorViewModel(item1.RightConnector, item2.TopConnector);
            con1.Parent = window1ViewModel.DiagramViewModel;
            window1ViewModel.DiagramViewModel.Items.Add(con1);
        }
Esempio n. 4
0
        /// <summary>
        /// This shows you how you can create diagram items in code, which means you can
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Window1_Loaded(object sender, RoutedEventArgs e)
        {
            SettingsDesignerItemViewModel item1 = new SettingsDesignerItemViewModel();

            item1.Parent = window1ViewModel.DiagramViewModel;
            item1.Left   = 100;
            item1.Top    = 100;
            window1ViewModel.DiagramViewModel.Items.Add(item1);

            PersistDesignerItemViewModel item2 = new PersistDesignerItemViewModel();

            item2.Parent = window1ViewModel.DiagramViewModel;
            item2.Left   = 300;
            item2.Top    = 300;
            window1ViewModel.DiagramViewModel.Items.Add(item2);

            ConnectorViewModel con1 = new ConnectorViewModel(item1.RightConnector, item2.TopConnector);

            con1.Parent = window1ViewModel.DiagramViewModel;
            window1ViewModel.DiagramViewModel.Items.Add(con1);
        }
Esempio n. 5
0
        private void ExecuteLoadDiagramCommand(object parameter)
        {
            IsBusy = true;
            DiagramItem wholeDiagramToLoad = null;

            if (SavedDiagramId == null)
            {
                messageBoxService.ShowError("You need to select a diagram to load");
                return;
            }

            Task <DiagramViewModel> task = Task.Factory.StartNew <DiagramViewModel>(() =>
            {
                //ensure that itemsToRemove is cleared ready for any new changes within a session
                itemsToRemove = new List <SelectableDesignerItemViewModelBase>();
                DiagramViewModel diagramViewModel = new DiagramViewModel();

                wholeDiagramToLoad = databaseAccessService.FetchDiagram((int)SavedDiagramId.Value);

                //load diagram items
                foreach (DiagramItemData diagramItemData in wholeDiagramToLoad.DesignerItems)
                {
                    if (diagramItemData.ItemType == typeof(PersistDesignerItem))
                    {
                        PersistDesignerItem persistedDesignerItem = databaseAccessService.FetchPersistDesignerItem(diagramItemData.ItemId);
                        PersistDesignerItemViewModel persistDesignerItemViewModel =
                            new PersistDesignerItemViewModel(persistedDesignerItem.Id, diagramViewModel, persistedDesignerItem.Left, persistedDesignerItem.Top, persistedDesignerItem.HostUrl);
                        diagramViewModel.Items.Add(persistDesignerItemViewModel);
                    }
                    if (diagramItemData.ItemType == typeof(SettingsDesignerItem))
                    {
                        SettingsDesignerItem settingsDesignerItem = databaseAccessService.FetchSettingsDesignerItem(diagramItemData.ItemId);
                        SettingsDesignerItemViewModel settingsDesignerItemViewModel =
                            new SettingsDesignerItemViewModel(settingsDesignerItem.Id, diagramViewModel, settingsDesignerItem.Left, settingsDesignerItem.Top, settingsDesignerItem.Setting1);
                        diagramViewModel.Items.Add(settingsDesignerItemViewModel);
                    }
                }
                //load connection items
                foreach (int connectionId in wholeDiagramToLoad.ConnectionIds)
                {
                    Connection connection = databaseAccessService.FetchConnection(connectionId);

                    DesignerItemViewModelBase sourceItem            = GetConnectorDataItem(diagramViewModel, connection.SourceId, connection.SourceType);
                    ConnectorOrientation sourceConnectorOrientation = GetOrientationForConnector(connection.SourceOrientation);
                    FullyCreatedConnectorInfo sourceConnectorInfo   = GetFullConnectorInfo(connection.Id, sourceItem, sourceConnectorOrientation);

                    DesignerItemViewModelBase sinkItem            = GetConnectorDataItem(diagramViewModel, connection.SinkId, connection.SinkType);
                    ConnectorOrientation sinkConnectorOrientation = GetOrientationForConnector(connection.SinkOrientation);
                    FullyCreatedConnectorInfo sinkConnectorInfo   = GetFullConnectorInfo(connection.Id, sinkItem, sinkConnectorOrientation);

                    ConnectorViewModel connectionVM = new ConnectorViewModel(connection.Id, diagramViewModel, sourceConnectorInfo, sinkConnectorInfo);
                    diagramViewModel.Items.Add(connectionVM);
                }

                return(diagramViewModel);
            });

            task.ContinueWith((ant) =>
            {
                this.DiagramViewModel = ant.Result;
                IsBusy = false;
                messageBoxService.ShowInformation(string.Format("Finished loading Diagram Id : {0}", wholeDiagramToLoad.Id));
            }, TaskContinuationOptions.OnlyOnRanToCompletion);
        }