public static MachineElementViewModel ToViewModel(this MachineModels.Models.MachineElement me, MachineElementViewModel parentViewModel = null)
        {
            var vm = new MachineElementViewModel()
            {
                Name             = me.Name,
                ModelFile        = me.ModelFile,
                Color            = me.Color.Convert(),
                LinkToParentType = me.LinkToParentType,
                LinkToParentData = me.LinkToParentData.Convert(),
                Parent           = parentViewModel,
                ToolHolderType   = me.ToolHolderType,
                ToolHolderData   = me.ToolHolderData?.ToViewModel(),
                ColliderGeometry = me.ColiderType,
                Collider         = me.Collider.ToViewMode(),
                HasPanelHolder   = me.HasPanelHolder,
                PanelHolder      = me.PanelHolder.ToViewModel(),
                InserterType     = me.InserterType,
                InserterData     = me.Inserter.ToViewModel()
            };

            vm.Children = me.Children.Convert(vm);

            if (vm.Model != null)
            {
                vm.Model.Transform = new System.Windows.Media.Media3D.MatrixTransform3D(me.TrasformationMatrix3D.Convert());
            }

            return(vm);
        }
        private static MachineElementViewModel CreateViewModel(Models.MachineElement me)
        {
            MachineElementViewModel vm;

            switch (me.ToolHolderType)
            {
            case MachineModels.Enums.ToolHolderType.None:
                vm = new MachineElementViewModel();
                break;

            case MachineModels.Enums.ToolHolderType.Static:
                vm = new StaticToolHolderViewModel().UpdateFromModel(me.ToolHolderData);
                break;

            case MachineModels.Enums.ToolHolderType.AutoSource:
                vm = new AutoSourceToolHolderViewModel().UpdateFromModel(me.ToolHolderData);
                break;

            case MachineModels.Enums.ToolHolderType.AutoSink:
                vm = new AutoSinkToolHolderViewModel().UpdateFromModel(me.ToolHolderData);
                break;

            default:
                throw new NotImplementedException();
            }

            vm.Visible = true;

            return(vm);
        }
        private static MachineElementViewModel ConvertModelToViewModel(Models.MachineElement me, IMachineElementViewModel parent = null)
        {
            var vm = CreateViewModel(me);

            UpdateFromModel(me, vm);
            vm.Parent = parent;

            foreach (var item in me.Children)
            {
                var childVm = ConvertModelToViewModel(item, vm);

                vm.Children.Add(childVm);
            }

            if (me.HasPanelHolder)
            {
                vm.Children.Add(me.PanelHolder.ToViewModel(vm));
            }
            if (me.InserterType != InserterType.None)
            {
                vm.Children.Add(me.Inserter.ToViewModel(vm));
            }
            if (me.ColiderType != ColliderGeometry.None)
            {
                vm.Children.Add(me.Collider.ToViewModel(vm));
            }

            return(vm);
        }
        private static void UpdateFromModel(Models.MachineElement me, MachineElementViewModel vm)
        {
            vm.Name         = me.Name;
            vm.Geometry     = LoadGeometry(me.ModelFile);
            vm.Transform    = ConvertTransform(me.TrasformationMatrix3D);
            vm.Material     = me.Color.ToMaterial();
            vm.LinkToParent = me.LinkToParentData.Convert();

            if (vm.LinkToParent != null)
            {
                vm.LinkToParent.Description = vm.Name;
            }
            vm.ApplyLinkAction();
        }
        private MachineElementViewModel ToViewModel(MM.MachineElement model)
        {
            var vm = new MachineElementViewModel()
            {
                Name = model.Name
            };

            foreach (var item in model.Children)
            {
                vm.Children.Add(ToViewModel(item));
            }

            return(vm);
        }