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

            viewModel.SetElement(baseElement);

            return(viewModel);
        }
Ejemplo n.º 2
0
        public static BaseElementViewModel GetViewModel(Type elementType, DocumentViewModel documentViewModel, bool setModelData = true)
        {
            BaseElementViewModel resultViewModel = null;
            CustomModelAttribute attribute       =
                (CustomModelAttribute)Attribute.GetCustomAttribute(elementType, typeof(CustomModelAttribute));

            if (attribute == null)
            {
                resultViewModel = CreateStandardModel(elementType, documentViewModel, setModelData);
            }
            else
            {
                resultViewModel = CreateCustomModel(elementType, documentViewModel, setModelData);
            }
            return(resultViewModel);
        }
Ejemplo n.º 3
0
        public static BaseElementViewModel CreateStandardModel(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);
        }
Ejemplo n.º 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);
            _start = startConenctor;
            _end   = endConnector;
            Hooks  = new List <Hook>();
            Model  = model;
            CalculatePath();
        }
Ejemplo n.º 5
0
 public ConnectorViewModel(BaseElementViewModel baseElementViewModel, Placemement placemement) : base(placemement)
 {
     _parentViewModel = baseElementViewModel;
 }
Ejemplo n.º 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);
        }