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);
        }
Esempio n. 2
0
        //private ObservableCollection<CollectionViewModelBase> _treeCollection = new ObservableCollection<CollectionViewModelBase>();

        #endregion

        #region Constructors

        public ChildCOViewModel(
            TreeViewViewModel treeParent,
            CompoundObjectViewModel parentVm,
            MainViewModel mainVm,
            CompoundObject compoundObject,
            bool enabled = true) :
            base(treeParent, parentVm, mainVm, compoundObject)
        {
        }
Esempio n. 3
0
 public FileCOViewModel(
     TreeViewViewModel treeParent,
     CompoundObjectViewModel parentVm,
     MainViewModel mainVm,
     string fileName,
     CompoundObject modelObject) :
     base(treeParent, parentVm, mainVm, modelObject)
 {
     _fileName = fileName;
 }
        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);
        }
        // All children CompoundObjectViewModels are created here. The constructor of the ChildObjectViewModel
        // creates a ChildObjectStatePropertiesViewModel which's constructor creates the CompoundObjectViewModel.
        private StateChildCollectionViewModel SetChildren(CompoundObject ModelObject, bool enabledChildren = true)
        {
            StateChildCollectionViewModel schcvm = new StateChildCollectionViewModel(this, this, MainVm, enabledChildren);

            foreach (ChildObject cho in ModelObject.ChildObjects)
            {
                ChildObjectViewModel chovm = new ChildObjectViewModel(schcvm, this, MainVm, cho, enabledChildren);

                schcvm.Children.Add(chovm);
            }

            return(schcvm);
        }
        public CompoundObjectViewModel(
            TreeViewViewModel treeParent,
            CompoundObjectViewModel parentVm,
            MainViewModel mainVm,
            CompoundObject modelObject,
            bool enabled = true) :
            base(treeParent, parentVm, mainVm, enabled)
        {
            ModelObject = modelObject;

            Behaviour = new CoBehaviourViewModel(TreeParent, this, MainVm, ModelObject.Behaviour);

            SelectedBehaviourIndex = Behaviours.IndexOf(ModelObject.Behaviour.Type);

            ChildObjectsWithStates = new StateChildCollectionViewModel(treeParent, parentVm, MainVm);
        }
Esempio n. 7
0
        public static CompoundObject ReadFromFile(string fileName)
        // This method reads an xml file containing a CompoundObject
        // and returns with the generated CompoundObject.
        // All child objects with other XML-files are also read
        // (however it will not be possible to edit them without
        // explicitly open thems as separate files.
        // TODO: Error handling is non-existent.
        {
            string path = Path.GetDirectoryName(fileName);

            XmlSerializer  ser    = new XmlSerializer(typeof(CompoundObject));
            FileStream     fs     = new FileStream(fileName, FileMode.Open);
            XmlReader      reader = XmlReader.Create(fs);
            CompoundObject co     = (CompoundObject)ser.Deserialize(reader);

            co.AnalyseForChildFiles(path);

            fs.Close();

            return(co);
        }
        private StateShapeCollectionViewModel SetShapes(CompoundObject co, bool enabledChildren = true)
        {
            StateShapeCollectionViewModel shapes = new StateShapeCollectionViewModel(this, this, MainVm, enabledChildren);

            foreach (LfSpriteBox sb in co.SpriteBoxes)
            {
                LfSpriteBoxViewModel shapevm = new LfSpriteBoxViewModel(shapes, this, MainVm, sb, enabledChildren);
                shapes.Shapes.Add(shapevm);
            }

            foreach (LfSpritePolygon sp in co.SpritePolygons)
            {
                LfSpritePolygonViewModel shapevm = new LfSpritePolygonViewModel(shapes, this, MainVm, sp, enabledChildren);

                foreach (LfDragablePoint dragPoint in sp.Points)
                {
                    LfDragablePointViewModel dragPointVm = new LfDragablePointViewModel(shapevm, this, MainVm, shapevm, dragPoint, enabledChildren);
                    shapevm.PointVms.Add(dragPointVm);
                }

                shapes.Shapes.Add(shapevm);
            }

            foreach (LfStaticBox sb in co.StaticBoxes)
            {
                LfStaticBoxViewModel shapevm = new LfStaticBoxViewModel(shapes, this, MainVm, sb, enabledChildren);
                shapes.Shapes.Add(shapevm);
            }

            foreach (LfStaticCircle sb in co.StaticCircles)
            {
                LfStaticCircleViewModel shapevm = new LfStaticCircleViewModel(shapes, this, MainVm, sb, enabledChildren);
                shapes.Shapes.Add(shapevm);
            }

            foreach (LfStaticPolygon sp in co.StaticPolygons)
            {
                LfStaticPolygonViewModel shapevm = new LfStaticPolygonViewModel(shapes, this, MainVm, sp, enabledChildren);

                foreach (LfDragablePoint dragPoint in sp.Points)
                {
                    LfDragablePointViewModel dragPointVm = new LfDragablePointViewModel(shapevm, this, MainVm, shapevm, dragPoint, enabledChildren);
                    shapevm.PointVms.Add(dragPointVm);
                }

                shapes.Shapes.Add(shapevm);
            }

            foreach (LfDynamicBox db in co.DynamicBoxes)
            {
                LfDynamicBoxViewModel shapevm = new LfDynamicBoxViewModel(shapes, this, MainVm, db, enabledChildren);
                shapes.Shapes.Add(shapevm);
            }

            foreach (LfDynamicCircle db in co.DynamicCircles)
            {
                LfDynamicCircleViewModel shapevm = new LfDynamicCircleViewModel(shapes, this, MainVm, db, enabledChildren);
                shapes.Shapes.Add(shapevm);
            }

            foreach (LfDynamicPolygon dp in co.DynamicPolygons)
            {
                LfDynamicPolygonViewModel shapevm = new LfDynamicPolygonViewModel(shapes, this, MainVm, dp, enabledChildren);

                foreach (LfDragablePoint dragPoint in dp.Points)
                {
                    LfDragablePointViewModel dragPointVm = new LfDragablePointViewModel(shapevm, this, MainVm, shapevm, dragPoint, enabledChildren);
                    shapevm.PointVms.Add(dragPointVm);
                }

                shapes.Shapes.Add(shapevm);
            }

            foreach (LfStaticBoxedSpritePolygon bsp in co.StaticBoxedSpritePolygons)
            {
                LfStaticBoxedSpritePolygonViewModel shapevm = new LfStaticBoxedSpritePolygonViewModel(shapes, this, MainVm, bsp, enabledChildren);

                foreach (LfDragablePoint dragPoint in bsp.Points)
                {
                    LfDragablePointViewModel dragPointVm = new LfDragablePointViewModel(shapevm, this, MainVm, shapevm, dragPoint, enabledChildren);
                    shapevm.PointVms.Add(dragPointVm);
                }

                shapes.Shapes.Add(shapevm);
            }

            foreach (LfDynamicBoxedSpritePolygon bsp in co.DynamicBoxedSpritePolygons)
            {
                LfDynamicBoxedSpritePolygonViewModel shapevm = new LfDynamicBoxedSpritePolygonViewModel(shapes, this, MainVm, bsp, enabledChildren);

                foreach (LfDragablePoint dragPoint in bsp.Points)
                {
                    LfDragablePointViewModel dragPointVm = new LfDragablePointViewModel(shapevm, this, MainVm, shapevm, dragPoint, enabledChildren);
                    shapevm.PointVms.Add(dragPointVm);
                }

                shapes.Shapes.Add(shapevm);
            }

            return(shapes);
        }
Esempio n. 9
0
        public static CompoundObject ReadFromFile(string fileName)
        // This method reads an xml file containing a CompoundObject
        // and returns with the generated CompoundObject.
        // All child objects with other XML-files are also read
        // (however it will not be possible to edit them without
        // explicitly open thems as separate files.
        // TODO: Error handling is non-existent.
        {
            string path = Path.GetDirectoryName(fileName);

            XmlSerializer  ser    = new XmlSerializer(typeof(CompoundObject));
            FileStream     fs     = new FileStream(fileName, FileMode.Open);
            XmlReader      reader = XmlReader.Create(fs);
            CompoundObject co     = (CompoundObject)ser.Deserialize(reader);

            // Iterate ChildObjects to load all child objects
            foreach (ChildObject cor in co.ChildObjects)
            {
                // Iterate all state properties
                foreach (TStateProperties <ChildObjectStateProperties> sp in cor.StateProperties)
                {
                    // Only read files if the child object is referenced from a
                    // separate file, otherwise the serialization will already have
                    // populated the child object.
                    if ((sp.Properties.File != "") && (sp.Properties.CompObj == null))
                    {
                        string newFile = System.IO.Path.Combine(path, sp.Properties.File);

                        CompoundObject childCo = CompoundObject.ReadFromFile(newFile);

                        sp.Properties.CompObj = childCo;
                    }
                }
            }

            // Iterate SpawnObjects of BreakableObject Behaviour properties to load all spawn objects
            if (co.Behaviour.Type == "breakableObject")
            {
                foreach (SpawnObject so in co.Behaviour.BreakableObjProps.SpawnObjects)
                {
                    ChildObject cor = so.MyChildObject;

                    // Iterate all state properties
                    foreach (TStateProperties <ChildObjectStateProperties> sp in cor.StateProperties)
                    {
                        // Only read files if the child object is referenced from a
                        // separate file, otherwise the serialization will already have
                        // populated the child object.
                        if ((sp.Properties.File != "") && (sp.Properties.CompObj == null))
                        {
                            string newFile = System.IO.Path.Combine(path, sp.Properties.File);

                            CompoundObject childCo = CompoundObject.ReadFromFile(newFile);

                            sp.Properties.CompObj = childCo;
                        }
                    }
                }
            }

            // Iterate ClippedWindows to load all each child objects
            foreach (ClippedWindowRef cwr in co.ClippedWindows)
            {
                // Iterate all state properties
                foreach (TStateProperties <ClippedWindowProperties> sp in cwr.StateProperties)
                {
                    string newFile = System.IO.Path.Combine(path, sp.Properties.SpaceSceneFile);

                    CompoundObject childCo = CompoundObject.ReadFromFile(newFile);

                    sp.Properties.CompObj = childCo;
                }
            }

            fs.Close();

            return(co);
        }
Esempio n. 10
0
        // Following is special cases for landing scenes. Maybe these will be specialised
        // xml files with specialised format.

        //[XmlElement("planetActor")]
        //public ObservableCollection<PlanetActorRef> PlanetActors
        //{
        //   get { return _planetActors; }
        //   set { _planetActors = value; }
        //}

        //// At serialisation of a parent CompoundObject this collection
        //// is read. Once read, the spaceSceneFile is used to create
        //// a child CompoundObject.
        //[XmlElement("clippedWindow")]
        //public ObservableCollection<ClippedWindowRef> ClippedWindows
        //{
        //   get { return _clippedWindows; }
        //   set { _clippedWindows = value; }
        //}

        #endregion

        #region Public Methods

        public void AnalyseForChildFiles(string path)
        {
            // Iterate ChildObjects to load all child objects
            foreach (ChildObject cor in ChildObjects)
            {
                // Only read files if the child object is referenced from a
                // separate file, otherwise the serialization will already have
                // populated the child object.
                if ((cor.File != "") && (cor.File != "undef_file.xml") && (cor.CompObj == null))
                {
                    string newFile = System.IO.Path.Combine(path, cor.File);

                    CompoundObject childCo = CompoundObject.ReadFromFile(newFile);

                    cor.CompObj = childCo;
                }
                else
                {
                    //...however, the child objects may have behaviours or systems that
                    // has spawn objects or child objects that need to be loaded
                    cor.CompObj.AnalyseForChildFiles(path);
                }
            }

            // Iterate SpawnObjects of BreakableObject Behaviour properties to load all spawn objects
            if (Behaviour.Type == "breakableObject")
            {
                foreach (SpawnObject so in Behaviour.BreakableObjProps.SpawnObjects)
                {
                    ChildObject cor = so.MyChildObject;

                    // Only read files if the child object is referenced from a
                    // separate file, otherwise the serialization will already have
                    // populated the child object.
                    if ((cor.File != "") && (cor.File != "undef_file.xml") && (cor.CompObj == null))
                    {
                        string newFile = System.IO.Path.Combine(path, cor.File);

                        CompoundObject childCo = CompoundObject.ReadFromFile(newFile);

                        cor.CompObj = childCo;
                    }
                }
            }


            // Iterate SpawnObjects of ObejctFactories in Systems.Propertiesto load all spawn objects
            foreach (CoSystem sys in Systems)
            {
                if (sys.Type == "objectFactory")
                {
                    foreach (SpawnObject so in sys.ObjFactStateProperties.SpawnObjects)
                    {
                        ChildObject cor = so.MyChildObject;

                        // Only read files if the child object is referenced from a
                        // separate file, otherwise the serialization will already have
                        // populated the child object.
                        if ((cor.File != "") && (cor.File != "undef_file.xml") && (cor.CompObj == null))
                        {
                            string newFile = System.IO.Path.Combine(path, cor.File);

                            CompoundObject childCo = CompoundObject.ReadFromFile(newFile);

                            cor.CompObj = childCo;
                        }
                    }
                }
            }

            //// Iterate ClippedWindows to load all each child objects
            //foreach (ClippedWindowRef cwr in ClippedWindows)
            //{
            //   // Iterate all state properties
            //   foreach (TStateProperties<ClippedWindowProperties> sp in cwr.StateProperties)
            //   {
            //      string newFile = System.IO.Path.Combine(path, sp.Properties.SpaceSceneFile);

            //      CompoundObject childCo = CompoundObject.ReadFromFile(newFile);

            //      sp.Properties.CompObj = childCo;
            //   }
            //}
        }