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