public Type TypeOfViewModel(ICAEXWrapper model)
        {
            if (model is InternalElementType internalElement)
            {
                switch (internalElement.RefBaseSystemUnitPath)
                {
                case "/Kinematic":
                    return(typeof(Kinematic));

                case "/Kinematic/Joint":
                    return(typeof(KinematicJoint));

                case "/Kinematic/Link":
                    return(typeof(KinematicLink));
                }
            }

            if (model is ExternalInterfaceType externalInterface)
            {
                switch (externalInterface.RefBaseClassPath)
                {
                case "/Kinematic/Link/Flange":
                    return(typeof(Flange));
                }
            }
            return(null);
        }
Exemple #2
0
		public T Create<T>(ICAEXWrapper model, IAmlProvider provider) where T : CaexObjectViewModel
		{
			if (model.GetType() == typeof(InstanceHierarchyType)) return new InstanceHierarchyViewModel((InstanceHierarchyType)model, provider) as T;
			if (model.GetType() == typeof(InternalElementType)) return new InternalElementViewModel((InternalElementType)model, provider) as T;
			if (model.GetType() == typeof(ExternalInterfaceType)) return new InterfaceViewModel((ExternalInterfaceType)model, provider) as T;
			return null;
		}
        public bool CanCreate <T>(ICAEXWrapper model) where T : CaexObjectViewModel
        {
            if (model is InternalElementType internalElement)
            {
                switch (internalElement.RefBaseSystemUnitPath)
                {
                case "/Kinematic":
                    return(typeof(T).IsAssignableFrom(typeof(Kinematic)));

                case "/Kinematic/Joint":
                    return(typeof(T).IsAssignableFrom(typeof(KinematicJoint)));

                case "/Kinematic/Link":
                    return(typeof(T).IsAssignableFrom(typeof(KinematicLink)));
                }
            }

            if (model is ExternalInterfaceType externalInterface)
            {
                switch (externalInterface.RefBaseClassPath)
                {
                case "/Kinematic/Link/Flange":
                    return(typeof(T).IsAssignableFrom(typeof(Flange)));
                }
            }
            return(false);
        }
        public T Create <T>(ICAEXWrapper model, IAmlProvider provider) where T : CaexObjectViewModel
        {
            var t = TypeOfViewModel(model);

            if (t == null)
            {
                return(null);
            }

            if (t == typeof(Kinematic))
            {
                return(new Kinematic(model as InternalElementType, provider) as T);
            }
            if (t == typeof(KinematicJoint))
            {
                return(new KinematicJoint(model as InternalElementType, provider) as T);
            }
            if (t == typeof(KinematicLink))
            {
                return(new KinematicLink(model as InternalElementType, provider) as T);
            }
            if (t == typeof(Flange))
            {
                return(new Flange(model as ExternalInterfaceType, provider) as T);
            }
            return(null);
        }
        public bool CanCreate <T>(ICAEXWrapper model) where T : CaexObjectViewModel
        {
            if (!(model is ExternalInterfaceType iface))
            {
                return(false);
            }
            if (iface.RefBaseClassPath == null)
            {
                return(false);
            }

            var name = GeometryDataConnectorViewModel.ColladaClassPath.Split('/').Last();

            if (iface.RefBaseClassPath.Contains(name))
            {
                return(true);
            }

            name = GeometryDataConnectorViewModel.GenericGeometryClassPath.Split('/').Last();
            if (iface.RefBaseClassPath.Contains(name))
            {
                return(true);
            }

            return(false);
        }
        /// <inheritdoc />
        public virtual Type TypeOfViewModel(ICAEXWrapper model)
        {
            if (!(model is ExternalInterfaceType iface))
            {
                return(null);
            }
            if (iface.RefBaseClassPath == null)
            {
                return(null);
            }

            var name = ExternalGeometryConnectorViewModel.ColladaClassPath.Split('/').Last();

            if (iface.RefBaseClassPath.Contains(name))
            {
                return(typeof(ExternalGeometryConnectorViewModel));
            }

            name = ExternalGeometryConnectorViewModel.GenericGeometryClassPath.Split('/').Last();
            if (iface.RefBaseClassPath.Contains(name))
            {
                return(typeof(ExternalGeometryConnectorViewModel));
            }

            return(null);
        }
        public bool CanCreate <T>(ICAEXWrapper model) where T : CaexObjectViewModel
        {
            if (!(model is AttributeType attribute))
            {
                return(false);
            }

            if (attribute.Name == FrameProperty.AttributeName)
            {
                return(true);
            }

            if (attribute.Name == CouplingPropertyViewModel.AttributeName)
            {
                return(true);
            }

            if (attribute.RefAttributeType == KinematicJointValue.AttributeRefTypeName)
            {
                return(true);
            }

            switch (attribute.AttributeDataType)
            {
            case XMLDataTypeMapper.StringTypeName:
            case XMLDataTypeMapper.BooleanTypeName:
            case XMLDataTypeMapper.IntTypeName:
            case XMLDataTypeMapper.DoubleTypeName:
                return(true);

            default:
                return(false);
            }
        }
Exemple #8
0
		public Type TypeOfViewModel(ICAEXWrapper model)
		{
			if (model.GetType() == typeof(InstanceHierarchyType)) return typeof(InstanceHierarchyViewModel);
			if (model.GetType() == typeof(InternalElementType)) return typeof(InternalElementViewModel);
			if (model.GetType() == typeof(ExternalInterfaceType)) return typeof(InterfaceViewModel);
			return null;
		}
Exemple #9
0
        /// <summary>
        /// Create a view model for the specified model and add the view model to this collection.
        /// </summary>
        /// <param name="model"></param>
        private void AddModel(ICAEXWrapper model)
        {
            // skip if a view model for the model already exists
            foreach (var vm in this)
            {
                if (Equals(vm.CaexObject, model))
                {
                    return;
                }
            }

            var factory = CaexViewModelFactoryManager.Instance.GetFactory <T>(model);

            if (factory == null)
            {
                return;
            }

            var viewModel = factory.Create <T>(model, _parent.Provider);

            // if the needed viewmodel could not be created, just dont add it the collection
            if (viewModel == null)
            {
                return;
            }
            Add(viewModel);
        }
        public T Create <T>(ICAEXWrapper model, IAmlProvider provider) where T : CaexObjectViewModel
        {
            if (TypeOfViewModel(model) == null)
            {
                return(null);
            }
            var assembly = new AssemblyViewModel((InternalElementType)model, provider) as T;

            return(assembly);
        }
        public virtual T Create <T>(ICAEXWrapper model, IAmlProvider provider) where T : CaexObjectViewModel
        {
            if (TypeOfViewModel(model) == null)
            {
                return(default(T));
            }
            var connector = new GeometryDataConnectorViewModel((ExternalInterfaceType)model, provider) as T;

            return(connector);
        }
Exemple #12
0
		public bool CanCreate<T>(ICAEXWrapper model) where T : CaexObjectViewModel
		{
			if (model == null) return false;

			return (model.GetType() == typeof(InstanceHierarchyViewModel) &&
						typeof(T).IsAssignableFrom(typeof(InstanceHierarchyViewModel)))
			       || (model.GetType() == typeof(InternalElementViewModel) &&
			           typeof(T).IsAssignableFrom(typeof(InternalElementViewModel)))
				   || (model.GetType() == typeof(InterfaceViewModel) &&
				       typeof(T).IsAssignableFrom(typeof(InterfaceViewModel)));
		}
 /// <inheritdoc />
 public Type TypeOfViewModel(ICAEXWrapper model)
 {
     if (!(model is InternalElementType ie))
     {
         return(null);
     }
     if (ie.RefBaseSystemUnitPath.Contains("Assembly"))
     {
         return(typeof(AssemblyViewModel));
     }
     return(null);
 }
 public bool CanCreate <T>(ICAEXWrapper model) where T : CaexObjectViewModel
 {
     if (!(model is InternalElementType ie))
     {
         return(false);
     }
     if (ie.RefBaseSystemUnitPath == null)
     {
         return(false);
     }
     return(ie.RefBaseSystemUnitPath.Contains("Assembly"));
 }
        internal void Select(ICAEXWrapper caexObject, bool activate)
        {
            var lib = caexObject.Library();

            if (lib is InstanceHierarchyType)
            {
                AMLDocumentTreeViewModel?.SelectCaexNode(caexObject.Node, true, true);
                if (activate)
                {
                    AMLDocumentTreeViewModel.RaisePropertyChanged("Activate");
                }
            }
        }
        public T Create <T>(ICAEXWrapper model, IAmlProvider provider) where T : CaexObjectViewModel
        {
            var t = TypeOfViewModel(model);

            if (t == null)
            {
                return(null);
            }

            var inst = Activator.CreateInstance(t, model, provider) as T;

            return(inst);
        }
 /// <inheritdoc />
 public Type TypeOfViewModel(ICAEXWrapper model)
 {
     if (!(model is ExternalInterfaceType iface))
     {
         return(null);
     }
     if (iface.RefBaseClassPath == null)
     {
         return(null);
     }
     if (iface.RefBaseClassPath.Contains("ExternalDataConnector"))
     {
         return(typeof(ExternalDataConnectorViewModel));
     }
     return(null);
 }
 public bool CanCreate <T>(ICAEXWrapper model) where T : CaexObjectViewModel
 {
     if (!(model is ExternalInterfaceType iface))
     {
         return(false);
     }
     if (iface.RefBaseClassPath == null)
     {
         return(false);
     }
     if (iface.RefBaseClassPath.Contains("ExternalDataConnector"))
     {
         return(true);
     }
     return(false);
 }
        public Type TypeOfViewModel(ICAEXWrapper model)
        {
            if (!(model is AttributeType attribute))
            {
                return(null);
            }

            // attributes with special name
            if (attribute.Name == FrameProperty.AttributeName)
            {
                return(typeof(FrameProperty));
            }

            if (attribute.Name == CouplingPropertyViewModel.AttributeName)
            {
                return(typeof(CouplingPropertyViewModel));
            }

            // attribute with special reference attribute type
            if (attribute.RefAttributeType == KinematicJointValue.AttributeRefTypeName)
            {
                return(typeof(KinematicJointValue));
            }

            switch (attribute.AttributeDataType)
            {
            case XMLDataTypeMapper.StringTypeName: return(typeof(StringPropertyViewModel));

            case XMLDataTypeMapper.BooleanTypeName: return(typeof(BooleanPropertyViewModel));

            case XMLDataTypeMapper.IntTypeName: return(typeof(IntegerPropertyViewModel));

            case XMLDataTypeMapper.DoubleTypeName: return(typeof(DoublePropertyViewModel));

            default:
                // TODO: how to handle missing attribute data type
                return(null);
            }
        }
Exemple #20
0
        public ICaexViewModelFactory GetFactory <T>(ICAEXWrapper model) where T : CaexObjectViewModel
        {
            var factories = new List <ICaexViewModelFactory>();

            foreach (var factory in _factories)
            {
                // only factories that can create the destination type
                var canCreateDestinationType = factory.CanCreate <T>(model);
                if (!canCreateDestinationType)
                {
                    continue;
                }

                // only factories that can handle the given CAEX object
                if (factory.TypeOfViewModel(model) == null)
                {
                    continue;
                }

                factories.Add(factory);
            }

            if (factories.Count == 0)
            {
                return(null);
            }
            if (factories.Count == 1)
            {
                return(factories[0]);
            }

            ICaexViewModelFactory match = null;

            foreach (var factory in factories)
            {
                var hasSubClass = false;
                foreach (var f in factories)
                {
                    var thisType  = factory.TypeOfViewModel(model);
                    var otherType = f.TypeOfViewModel(model);
                    if (otherType.IsSubclassOf(thisType))
                    {
                        hasSubClass = true;
                    }
                }

                if (!hasSubClass)
                {
                    if (match != null)
                    {
                        throw new Exception("Multiple factories found");
                    }
                    match = factory;
                }
            }

            if (match == null)
            {
                throw new Exception("Weird: factory missing for type " + model.GetType());
            }
            return(match);
        }