private StateSystemCollectionViewModel SetSystems(CompoundObject co, bool enabledChildren = true)
        {
            StateSystemCollectionViewModel systems = new StateSystemCollectionViewModel(this, this, MainVm, enabledChildren);

            foreach (CoSystem s in co.Systems)
            {
                CoSystemViewModel svm = new CoSystemViewModel(systems, this, MainVm, s, enabledChildren);
                systems.Systems.Add(svm);
            }

            return(systems);
        }
        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();
        }