private StateJointCollectionViewModel SetJoints(CompoundObject co, bool enabledChildren = true)
        {
            StateJointCollectionViewModel joints = new StateJointCollectionViewModel(this, this, MainVm, enabledChildren);

            foreach (WeldJoint wj in co.WeldJoints)
            {
                WeldJointViewModel wjvm = new WeldJointViewModel(joints, this, MainVm, wj, enabledChildren);
                joints.Joints.Add(wjvm);
            }

            foreach (RevoluteJoint rj in co.RevoluteJoints)
            {
                RevoluteJointViewModel rjvm = new RevoluteJointViewModel(joints, this, MainVm, rj, enabledChildren);
                joints.Joints.Add(rjvm);
            }

            foreach (PrismaticJoint pj in co.PrismaticJoints)
            {
                PrismaticJointViewModel pjvm = new PrismaticJointViewModel(joints, this, MainVm, pj, enabledChildren);
                joints.Joints.Add(pjvm);
            }

            foreach (Rope r in co.Ropes)
            {
                RopeViewModel rvm = new RopeViewModel(joints, this, MainVm, r, enabledChildren);
                joints.Joints.Add(rvm);
            }

            return(joints);
        }
        public void InvalidateJoints()
        {
            foreach (object o in StateJoints.Joints)
            {
                // Below will take care of all joints since they
                // all inherit from WeldJoint
                if (o is WeldJointViewModel)
                {
                    WeldJointViewModel joint = (WeldJointViewModel)o;

                    joint.OnPropertyChanged("");
                }
            }
        }
        public void DeselectAllChildren()
        {
            if ((Behaviour != null) && (Behaviour.BehaviourProperties != null))
            {
                Behaviour.BehaviourProperties.IsSelected = false;
            }

            if ((StateShapes != null) && (StateShapes.Shapes != null))
            {
                foreach (object o in StateShapes.Shapes)
                {
                    if (o is LfPolygonViewModel)
                    {
                        LfPolygonViewModel pvm = o as LfPolygonViewModel;

                        pvm.DeselectAllPoints();
                        pvm.IsSelected = false;
                    }
                    else if (o is LfShapeViewModel)
                    {
                        LfShapeViewModel shape = o as LfShapeViewModel;

                        shape.IsSelected = false;
                    }
                }
            }

            if (StateJoints != null)
            {
                foreach (object o in StateJoints.Joints)
                {
                    if (o is WeldJointViewModel)
                    {
                        WeldJointViewModel joint = (WeldJointViewModel)o;

                        joint.IsSelected = false;
                    }
                }
            }

            if (ChildObjectsWithStates != null)
            {
                foreach (ChildObjectViewModel child in ChildObjectsWithStates.Children)
                {
                    child.DeselectAllChildren();
                    child.IsSelected = false;
                }
            }
        }
예제 #4
0
        public void AddChildShapesToGlobalCollection(ref CompositeCollection coll, bool showJoints, bool showSystems, bool showBackgrounds)
        {
            if (CompObj != null)
            {
                foreach (Object o in CompObj.ShapeCollection.Shapes)
                {
                    if (o is LfShapeViewModel)
                    {
                        LfShapeViewModel svm = o as LfShapeViewModel;
                        coll.Add(svm);
                    }
                }

                if (showJoints)
                {
                    foreach (Object o in CompObj.JointCollection.Joints)
                    {
                        if (o is WeldJointViewModel)
                        {
                            WeldJointViewModel wjvm = o as WeldJointViewModel;
                            coll.Add(wjvm);
                        }
                    }
                }

                if (showSystems)
                {
                    foreach (Object o in CompObj.SystemCollection.Systems)
                    {
                        if (o is CoSystemViewModel)
                        {
                            CoSystemViewModel svm = o as CoSystemViewModel;
                            coll.Add(svm);
                        }
                    }
                }


                if (CompObj != MainVm.EditedCpVm)
                {
                    foreach (ChildObjectViewModel covm in CompObj.ChildObjectCollection.Children)
                    {
                        covm.AddChildShapesToGlobalCollection(ref coll, showJoints, showSystems, showBackgrounds);
                    }
                }
            }
        }
        public void BuildViewModel(bool enabledChildren = true)
        // This method connects references in the COVM. At the creation of the COVM
        // the ModelObject, ModelObjectProperties, ParentVm and ChildObjectOfParent is defined.
        // Here we build the shape, joint and system collections and connect those objects
        // with the necessary references. The ChildObjects are also added to the corresponding
        // state index in the StateChildObjects collection
        {
//         _statesWithChildObjects.Clear();
            _treeCollection.Clear();

            _shapes  = SetShapes(ModelObject, enabledChildren);
            _joints  = SetJoints(ModelObject, enabledChildren);
            _systems = SetSystems(ModelObject, enabledChildren);

            // Only now is the Joints property valid for this state
            foreach (object o in _joints.Joints)
            {
                if (o is WeldJointViewModel)
                {
                    if (o is RopeViewModel)
                    {
                        RopeViewModel joint = (RopeViewModel)o;

                        joint.ConnectToShapes(_shapes);
                    }
                    else
                    {
                        WeldJointViewModel joint = (WeldJointViewModel)o;

                        joint.ConnectToShapes(_shapes);
                    }
                }
            }

            ChildObjectsWithStates = SetChildren(ModelObject, enabledChildren);

            BuildTreeViewCollection();
        }
        public void RemoveShape(LfShapeViewModel svm)
        {
            // Check if there are any joints connected to this svm, if so, removed them
            // We may remove joints so we need a for loop here:
            for (int i = StateJoints.Joints.Count - 1; i >= 0; i--)
            {
                // Below will take care of all joints since they
                // all inherit from WeldJoint
                if (StateJoints.Joints[i] is WeldJointViewModel)
                {
                    WeldJointViewModel joint = (WeldJointViewModel)StateJoints.Joints[i];

                    if ((joint.AName == svm.Name) || (joint.BName == svm.Name))
                    {
                        // Remove the joint
                        ModelObject.RemoveJoint(joint.ModelObject);
                        StateJoints.Joints.RemoveAt(i);
                    }
                }
            }

            // Remove the shape model
            ModelObject.RemoveShape(svm.ModelObject);

            // Remove the shape viewmodel from this
            StateShapes.Shapes.Remove(svm);

            // If there are no more shapes in the CO, remove the CO
            if (StateShapes.Shapes.Count == 0)
            {
                //ParentVm.StateChildObjects.Remove(this);
                //ParentVm.ModelObject.ChildObjectRefs(this.ChildObjectOfParent)
            }

            OnPropertyChanged("");
        }