Ejemplo n.º 1
0
        public override XElement SerializeSurfaceComponent(SurfaceComponent surfaceComponent)
        {
            var elem = SerializeBaseElement(surfaceComponent, SurfaceComponent.NODE_NAME);

            elem.Add(new XAttribute("Type", surfaceComponent.ComponentType.ToString()));

            var geomElem = elem.AddElement(nameof(SurfaceComponent.Meshes));

            foreach (var geom in surfaceComponent.Meshes)
            {
                geomElem.Add(geom.SerializeToXml());
            }
            return(elem);
        }
Ejemplo n.º 2
0
        private void AddComponentMenuItem_Click(object sender, EventArgs e)
        {
            string connectionTypeStr = (sender as ToolStripMenuItem).Tag as string;

            if (!string.IsNullOrEmpty(connectionTypeStr) &&
                Enum.TryParse(connectionTypeStr,
                              out ModelComponentType componentType))
            {
                var focusedSurfaceNode = GetFocusedParentElement <PartSurface>();

                if (focusedSurfaceNode != null)
                {
                    var selectedSurface = focusedSurfaceNode.Element as PartSurface;
                    var newComponent    = SurfaceComponent.CreateEmpty(componentType);
                    selectedSurface.Components.Add(newComponent);

                    ProjectManager.SelectElement(newComponent);
                    SelectElementNodeDelayed(newComponent);
                }
            }
        }
Ejemplo n.º 3
0
        public override SurfaceComponent DeserializeSurfaceComponent(XElement element)
        {
            SurfaceComponent component = null;
            var componentType          = element.ReadAttribute <ModelComponentType>("Type");

            switch (componentType)
            {
            case ModelComponentType.Part:
                component = new PartModel();
                DeserializePartModel(component as PartModel, element);
                break;

            case ModelComponentType.MaleStud:
                component = new MaleStudModel();
                DeserializeMaleStudModel(component as MaleStudModel, element);
                break;

            case ModelComponentType.FemaleStud:
                component = new FemaleStudModel();
                DeserializeFemaleStudModel(component as FemaleStudModel, element);
                break;

            case ModelComponentType.BrickTube:
                component = new BrickTubeModel();
                DeserializeBrickTubeModel(component as BrickTubeModel, element);
                break;
            }

            if (element.HasElement(nameof(SurfaceComponent.Meshes), out XElement geomElem))
            {
                foreach (var elem in geomElem.Elements(ModelMeshReference.NODE_NAME))
                {
                    var mesh = new ModelMeshReference();
                    mesh.LoadFromXml(elem);
                    component.Meshes.Add(mesh);
                }
            }

            return(component);
        }
Ejemplo n.º 4
0
 public abstract XElement SerializeSurfaceComponent(SurfaceComponent surfaceComponent);
        /// <summary>
        /// Initializes the surface input system. This should be called after any window
        /// initialization is done, and should only be called once.
        /// </summary>
        public override void Initialize()
        {
            surfaceComp = Game.Components.OfType<SurfaceComponent>().First();

            System.Diagnostics.Debug.Assert(Game.Window.Handle != System.IntPtr.Zero,
                "Window initialization must be complete before InitializeSurfaceInput is called");
            if (Game.Window.Handle == System.IntPtr.Zero)
                return;
            System.Diagnostics.Debug.Assert(contactTarget == null,
                "Surface input already initialized");
            if (contactTarget != null)
                return;

            // Create a target for surface input.
            contactTarget = new ContactTarget(Game.Window.Handle, EventThreadChoice.OnBackgroundThread);
            contactTarget.EnableInput();

            contactTarget.EnableImage(ImageType.Normalized);
            contactTarget.FrameReceived += new EventHandler<FrameReceivedEventArgs>(contactTarget_FrameReceived);

            CurrentContacts = contactTarget.GetState();

            manipulationProcessor = new Affine2DManipulationProcessor(Affine2DManipulations.TranslateX | Affine2DManipulations.TranslateY
                | Affine2DManipulations.Rotate | Affine2DManipulations.Scale);
            manipulationProcessor.Affine2DManipulationDelta += new EventHandler<Affine2DOperationDeltaEventArgs>(manipulationDelta);
            manipulationProcessor.Affine2DManipulationStarted += (s, e) => IsManipulating = true;
            manipulationProcessor.Affine2DManipulationCompleted += (s, e) => IsManipulating = false;

            base.Initialize();
        }