Example #1
0
        internal static BaseElementViewModel GetViewModel(VisualElement baseElement, DocumentViewModel documentViewModel)
        {
            BaseElementViewModel viewModel = GetViewModel(baseElement.GetType(), documentViewModel, false);

            viewModel.SetElement(baseElement);
            return(viewModel);
        }
Example #2
0
 /// <summary>
 /// Creates ElementsConnectionViewModel and add model connection
 /// </summary>
 /// <param name="documentViewModel"></param>
 /// <param name="start"></param>
 /// <param name="end"></param>
 public ElementsConnectionViewModel(DocumentViewModel documentViewModel, ConnectorViewModel start, ConnectorViewModel end) : base(documentViewModel)
 {
     BaseElement                  = new VisualElement();
     _start                       = start;
     _end                         = end;
     StartPoint                   = start.Position;
     EndPoint                     = end.Position;
     From                         = start.Parent;
     To                           = end.Parent;
     start.PropertyChanged       += Start_PropertyChanged;
     end.PropertyChanged         += End_PropertyChanged;
     start.Parent.ElementDeleted += ElementDeleted;
     end.Parent.ElementDeleted   += ElementDeleted;
     start.Parent.SetConnection(this);
     end.Parent.SetConnection(this);
     Hooks = new List <Hook>();
     Model = new ConnectionElement(start.Parent.BaseElement, end.Parent.BaseElement);
     ModelHelper.AddModelConnection(this);
     CalculatePath();
 }
Example #3
0
        public static BaseElementViewModel GetViewModel(Type elementType, DocumentViewModel documentViewModel, bool setModelData = true)
        {
            ElementViewModelAttribute attribute =
                (ElementViewModelAttribute)Attribute.GetCustomAttribute(elementType, typeof(ElementViewModelAttribute));

            if (attribute == null)
            {
                throw new NotSupportedException(string.Format("Not supported type {0}. Does not have ElementViewModelAttribute", elementType));
            }
            Type viewModelType             = attribute.ViewModelType;
            BaseElementViewModel viewModel =
                (BaseElementViewModel)Activator.CreateInstance(viewModelType, documentViewModel);

            if (setModelData)
            {
                viewModel.BaseElement = viewModel.CreateElement();
                viewModel.Height      = attribute.InitialSize.Height;
                viewModel.Width       = attribute.InitialSize.Width;
            }
            return(viewModel);
        }
Example #4
0
        public ElementsConnectionViewModel(DocumentViewModel documentViewModel, ConnectionElement model, BaseElementViewModel start, BaseElementViewModel end, Point startPoint, Point endPoint) : base(documentViewModel)
        {
            BaseElement = new VisualElement();
            var startConenctor = start.GetNearestConnector(startPoint);
            var endConnector   = end.GetNearestConnector(endPoint);

            _start     = startConenctor;
            _end       = endConnector;
            StartPoint = startConenctor.Position;
            EndPoint   = endConnector.Position;
            From       = startConenctor.Parent;
            To         = endConnector.Parent;
            startConenctor.PropertyChanged       += Start_PropertyChanged;
            endConnector.PropertyChanged         += End_PropertyChanged;
            startConenctor.Parent.ElementDeleted += ElementDeleted;
            endConnector.Parent.ElementDeleted   += ElementDeleted;
            startConenctor.Parent.SetConnection(this);
            endConnector.Parent.SetConnection(this);
            Hooks = new List <Hook>();
            Model = model;
            CalculatePath();
        }
Example #5
0
 public ConnectorViewModel(BaseElementViewModel baseElementViewModel, Placemement placemement) : base(placemement)
 {
     _parentViewModel = baseElementViewModel;
 }
Example #6
0
        public void Fill()
        {
            //TODO: Refactor
            PoolElement mainPoolElement = DocumentViewModel.Document.MainPoolElement;

            foreach (IBaseElement baseElement in mainPoolElement.Elements)
            {
                VisualElement        visualElement = baseElement as VisualElement;
                BaseElementViewModel baseViewModel = BaseElementViewModel.GetViewModel(visualElement, DocumentViewModel);
                _viewModelDictionary.Add(visualElement.Guid, baseViewModel);
                _viewModels.Add(baseViewModel);
            }
            foreach (ConnectionElement connection in mainPoolElement.Connections)
            {
                BaseElementViewModel start = null;
                BaseElementViewModel end   = null;
                if (_viewModelDictionary.TryGetValue(connection.SourceElement.Guid, out start) &&
                    _viewModelDictionary.TryGetValue(connection.TargetElement.Guid, out end))
                {
                    Point startPoint = new Point();
                    Point endPoint   = new Point();
                    if (connection.Points.Count >= 2)
                    {
                        startPoint = connection.Points[0];
                        endPoint   = connection.Points.Last();
                    }

                    ElementsConnectionViewModel connectionViewModel = new ElementsConnectionViewModel(
                        DocumentViewModel, connection, start, end, startPoint, endPoint);
                    _viewModels.Add(connectionViewModel);
                }
            }
            foreach (PoolElement poolElement in DocumentViewModel.Document.Pools)
            {
                PoolViewModel poolViewModel = new PoolViewModel(DocumentViewModel, poolElement);
                _poolViewModelsDictionary.Add(poolElement.Guid, poolViewModel);
                _viewModels.Add(poolViewModel);
                foreach (IBaseElement baseElement in poolElement.Elements)
                {
                    VisualElement        visualElement        = baseElement as VisualElement;
                    BaseElementViewModel baseViewModel        = BaseElementViewModel.GetViewModel(visualElement, DocumentViewModel);
                    PoolElementViewModel poolElementViewModel = baseViewModel as PoolElementViewModel;
                    poolElementViewModel.Pool = poolViewModel;
                    poolViewModel.Elements.Add(poolElementViewModel);
                    _viewModelDictionary.Add(visualElement.Guid, baseViewModel);
                    _viewModels.Add(baseViewModel);
                }
                foreach (ConnectionElement connection in poolElement.Connections)
                {
                    BaseElementViewModel start = null;
                    BaseElementViewModel end   = null;
                    if (_viewModelDictionary.TryGetValue(connection.SourceElement.Guid, out start) &&
                        _viewModelDictionary.TryGetValue(connection.TargetElement.Guid, out end))
                    {
                        Point startPoint = new Point();
                        Point endPoint   = new Point();
                        if (connection.Points.Count >= 2)
                        {
                            startPoint = connection.Points[0];
                            endPoint   = connection.Points.Last();
                        }

                        ElementsConnectionViewModel connectionViewModel = new ElementsConnectionViewModel(
                            DocumentViewModel, connection, start, end, startPoint, endPoint);
                        _viewModels.Add(connectionViewModel);
                    }
                }
            }
            DocumentViewModel.BaseElements = new ObservableCollection <BaseElementViewModel>(_viewModels);
        }