public void Initialize()
        {
            RegisterCommands();

            foreach (IManipulator manipulator in m_manipulators)
            {
                ManipulatorInfo info = manipulator.ManipulatorInfo;
                m_commandService.RegisterCommand(
                    manipulator,
                    StandardMenu.Modify,
                    CommandGroup.Manipulators,
                    info.Name,
                    info.Description,
                    info.ShortCut,
                    info.Image,
                    CommandVisibility.All,
                    this);
            }

            if (m_settingsService != null)
            {
                m_settingsService.Reloaded += (sender, e) =>
                {
                    ISnapSettings snapSettings = (ISnapSettings)m_designView;
                    m_snapFromModeComboBox.SelectedItem = snapSettings.SnapFrom;
                };
            }
        }
        protected override Matrix4F GetManipulatorMatrix()
        {
            ITransformable node = GetManipulatorNode(TransformationTypes.Translation);

            if (node == null)
            {
                return(null);
            }

            ISnapSettings  snapSettings = (ISnapSettings)DesignView;
            Path <DomNode> path         = new Path <DomNode>(node.Cast <DomNode>().GetPath());
            Matrix4F       localToWorld = TransformUtils.CalcPathTransform(path, path.Count - 1);

            Matrix4F toworld = new Matrix4F();

            if (snapSettings.ManipulateLocalAxis)
            {
                toworld.Set(localToWorld);
                toworld.Normalize(toworld);
            }
            else
            {
                toworld.Translation = localToWorld.Translation;
            }

            Vec3F offset = TransformUtils.CalcSnapFromOffset(node, snapSettings.SnapFrom);

            // Offset by pivot
            Matrix4F P = new Matrix4F();

            P.Translation = offset;
            toworld.Mul(toworld, P);

            return(toworld);
        }
        /// <summary>
        /// Does the command</summary>
        /// <param name="commandTag">Command to be done</param>
        public void DoCommand(object commandTag)
        {
            ISnapSettings snapSettings = (ISnapSettings)m_designView;
            IManipulator  manip        = commandTag as IManipulator;

            if (manip != null)
            {
                m_designView.Manipulator = manip;
            }
            else if (commandTag is Command)
            {
                switch ((Command)commandTag)
                {
                case Command.Select:
                    m_designView.Manipulator = null;
                    break;

                case Command.SnapToVertex:
                    snapSettings.SnapVertex = !snapSettings.SnapVertex;
                    break;

                case Command.RotateOnSnap:
                    snapSettings.RotateOnSnap = !snapSettings.RotateOnSnap;
                    break;
                }
            }
        }
        void m_snapFromModeComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ISnapSettings snapSettings = (ISnapSettings)m_designView;

            snapSettings.SnapFrom = (SnapFromMode)m_snapFromModeComboBox.SelectedItem;
            m_designView.InvalidateViews();
        }
        // Change the currently active DesignView to reflect the new combo box item.
        private void referenceCoordinateSystemComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ISnapSettings snapSettings = (ISnapSettings)m_designView;

            snapSettings.ManipulateLocalAxis = (m_referenceCoordinateSystemComboBox.SelectedIndex == 1);
            m_designView.InvalidateViews();
        }
        /// <summary>
        /// Updates the view's commands</summary>
        /// <param name="commandTag">The command tag</param>
        /// <param name="state">State of the command</param>
        public void UpdateCommand(object commandTag, CommandState state)
        {
            ISnapSettings snapSettings = (ISnapSettings)m_designView;
            IManipulator  manip        = commandTag as IManipulator;

            if (manip != null)
            {
                state.Check = manip == m_designView.Manipulator;
            }
            else if (commandTag is Command)
            {
                switch ((Command)commandTag)
                {
                case Command.Select:
                    state.Check = m_designView.Manipulator == null;
                    break;

                case Command.SnapToVertex:
                    state.Check = snapSettings.SnapVertex;
                    break;

                case Command.RotateOnSnap:
                    state.Check = snapSettings.RotateOnSnap;
                    break;
                }
            }
        }
Esempio n. 7
0
 public NewPointLayer(DotSpatial.Controls.IMap map, DotSpatial.Projections.ProjectionInfo projection, string filePath, ISnapSettings snapSettings)
     : base(map)
 {
     this.map          = map;
     this.projection   = projection;
     this.filePath     = filePath;
     this.snapSettings = snapSettings;
     DoSnapping        = this.snapSettings.Snap;
 }
Esempio n. 8
0
        /// <summary>
        /// Does the command</summary>
        /// <param name="commandTag">Command to be done</param>
        public void DoCommand(object commandTag)
        {
            ISnapSettings snapSettings = (ISnapSettings)m_designView;
            IManipulator  manip        = commandTag as IManipulator;

            if (manip != null)
            {
                m_designView.Manipulator = manip;
            }
            else if (commandTag is Command)
            {
                switch ((Command)commandTag)
                {
                case Command.Select:
                    m_designView.Manipulator = null;
                    break;

                case Command.SnapToVertex:
                    snapSettings.SnapVertex = !snapSettings.SnapVertex;
                    break;

                case Command.RotateOnSnap:
                    snapSettings.RotateOnSnap = !snapSettings.RotateOnSnap;
                    break;

                case Command.AlignToTerrainUp:
                    if (snapSettings.TerrainAlignment == TerrainAlignmentMode.TerrainUp)
                    {
                        snapSettings.TerrainAlignment = TerrainAlignmentMode.None;
                    }
                    else
                    {
                        snapSettings.TerrainAlignment = TerrainAlignmentMode.TerrainUp;
                    }
                    break;

                case Command.AlignToWorldUp:
                    if (snapSettings.TerrainAlignment == TerrainAlignmentMode.WorldUp)
                    {
                        snapSettings.TerrainAlignment = TerrainAlignmentMode.None;
                    }
                    else
                    {
                        snapSettings.TerrainAlignment = TerrainAlignmentMode.WorldUp;
                    }
                    break;
                }
            }
        }
Esempio n. 9
0
        protected override void OnDragOver(DragEventArgs drgevent)
        {
            base.OnDragOver(drgevent);
            if (DesignView.Context == null || m_ghosts.Count == 0)
            {
                return;
            }

            //  Just do an intersection against the terrain to
            //  calculate basic insertion position
            Vec3F terrainHit;

            if (GetInsertionPosition(out terrainHit, PointToClient(new Point(drgevent.X, drgevent.Y))))
            {
                ISnapSettings snapSettings = (ISnapSettings)DesignView;
                foreach (var ghost in m_ghosts)
                {
                    var gameObject = ghost.As <ITransformable>();
                    if (gameObject != null)
                    {
                        gameObject.Translation = terrainHit;

                        // When if terrain alignment mode, we need to query the terrain collision model
                        // for a terrain normal associated with this point. The
                        if (snapSettings.TerrainAlignment == TerrainAlignmentMode.TerrainUp)
                        {
                            using (var intersectionScene = GameEngine.GetEditorSceneManager().GetIntersectionScene())
                            {
                                float            terrainHeight;
                                GUILayer.Vector3 terrainNormal;
                                if (GUILayer.EditorInterfaceUtils.GetTerrainHeightAndNormal(
                                        out terrainHeight, out terrainNormal,
                                        intersectionScene, terrainHit.X, terrainHit.Y))
                                {
                                    gameObject.Rotation = TransformUtils.RotateToVector(
                                        gameObject.Rotation, new Vec3F(terrainNormal.X, terrainNormal.Y, terrainNormal.Z),
                                        Sce.Atf.Rendering.Dom.AxisSystemType.ZIsUp);
                                }
                            }
                        }
                    }
                }

                DesignView.InvalidateViews();
            }
        }
        protected override Matrix4F GetManipulatorMatrix()
        {
            ITransformable node = GetManipulatorNode(TransformationTypes.Translation);

            if (node == null)
            {
                return(null);
            }

            ISnapSettings  snapSettings = (ISnapSettings)DesignView;
            Path <DomNode> path         = new Path <DomNode>(node.Cast <DomNode>().GetPath());
            Matrix4F       localToWorld = TransformUtils.CalcPathTransform(path, path.Count - 1);

            Matrix4F toworld = new Matrix4F();

            if (snapSettings.ManipulateLocalAxis)
            {
                toworld.Set(localToWorld);
                toworld.Normalize(toworld);
            }
            else
            {
                toworld.Translation = localToWorld.Translation;
            }

            //  DavidJ --   note -- this "pivot" behaviour was inherited from another manipulator
            //                  but appears to be broken! Check coordinate space of value returned from CalcSnapFromOffset
            // Vec3F offset = TransformUtils.CalcSnapFromOffset(node, snapSettings.SnapFrom);
            //
            // // Offset by pivot
            // Matrix4F P = new Matrix4F();
            // P.Translation = offset;
            // toworld.Mul(toworld,P);

            return(toworld);
        }
        public override void OnDragging(ViewControl vc, Point scrPt)
        {
            if (m_cancelDrag || m_hitRegion == HitRegion.None || NodeList.Count == 0)
            {
                return;
            }

            bool hitAxis = m_hitRegion == HitRegion.XAxis ||
                           m_hitRegion == HitRegion.YAxis ||
                           m_hitRegion == HitRegion.ZAxis;


            Matrix4F view = vc.Camera.ViewMatrix;
            Matrix4F proj = vc.Camera.ProjectionMatrix;
            Matrix4F vp   = view * proj;

            // create ray in world space.
            Ray3F rayW = vc.GetRay(scrPt, vp);

            // create ray in view space.
            Ray3F rayV      = vc.GetRay(scrPt, proj);
            Vec3F translate = m_translatorControl.OnDragging(rayV);

            ISnapSettings snapSettings = (ISnapSettings)DesignView;
            bool          snapToGeom   = Control.ModifierKeys == m_snapGeometryKey;

            if (snapToGeom)
            {
                Vec3F manipPos = HitMatrix.Translation;
                Vec3F manipMove;
                if (hitAxis)
                {
                    //Make rayw to point toward moving axis and starting
                    // from manipulator’s world position.
                    rayW.Direction = Vec3F.Normalize(translate);
                    rayW.Origin    = manipPos;
                    manipMove      = Vec3F.ZeroVector;
                    m_cancelDrag   = true; //stop further snap-to's
                }
                else
                {
                    manipMove = rayW.ProjectPoint(manipPos) - manipPos;
                }

                for (int i = 0; i < NodeList.Count; i++)
                {
                    ITransformable node               = NodeList[i];
                    Vec3F          snapOffset         = TransformUtils.CalcSnapFromOffset(node, snapSettings.SnapFrom);
                    Path <DomNode> path               = new Path <DomNode>(Adapters.Cast <DomNode>(node).GetPath());
                    Matrix4F       parentLocalToWorld = TransformUtils.CalcPathTransform(path, path.Count - 2);
                    Vec3F          orgPosW;
                    parentLocalToWorld.Transform(m_originalValues[i], out orgPosW);

                    Matrix4F parentWorldToLocal = new Matrix4F();
                    parentWorldToLocal.Invert(parentLocalToWorld);

                    rayW.MoveToIncludePoint(orgPosW + snapOffset + manipMove);

                    HitRecord[] hits    = GameEngine.RayPick(view, proj, rayW, true);
                    bool        cansnap = false;
                    HitRecord   target  = new HitRecord();
                    if (hits.Length > 0)
                    {
                        // find hit record.
                        foreach (var hit in hits)
                        {
                            if (m_snapFilter.CanSnapTo(node, GameEngine.GetAdapterFromId(hit.instanceId)))
                            {
                                target  = hit;
                                cansnap = true;
                                break;
                            }
                        }
                    }

                    if (cansnap)
                    {
                        Vec3F pos;
                        if (target.hasNearestVert && snapSettings.SnapVertex)
                        {
                            pos = target.nearestVertex;
                        }
                        else
                        {
                            pos = target.hitPt;
                        }

                        pos -= snapOffset;
                        parentWorldToLocal.Transform(ref pos);
                        Vec3F diff = pos - node.Transform.Translation;
                        node.Translation += diff;
                        bool rotateOnSnap = snapSettings.RotateOnSnap &&
                                            target.hasNormal &&
                                            (node.TransformationType & TransformationTypes.Rotation) != 0;
                        if (rotateOnSnap)
                        {
                            Vec3F localSurfaceNormal;
                            parentWorldToLocal.TransformNormal(target.normal, out localSurfaceNormal);
                            node.Rotation = TransformUtils.RotateToVector(
                                m_originalRotations[i],
                                localSurfaceNormal,
                                AxisSystemType.YIsUp);
                        }
                    }
                }
            }
            else
            {
                IGrid grid       = DesignView.Context.Cast <IGame>().Grid;
                bool  snapToGrid = Control.ModifierKeys == m_snapGridKey &&
                                   grid.Visible &&
                                   vc.Camera.ViewType == ViewTypes.Perspective;
                float gridHeight = grid.Height;
                // translate.
                for (int i = 0; i < NodeList.Count; i++)
                {
                    ITransformable node = NodeList[i];
                    Path <DomNode> path = new Path <DomNode>(Adapters.Cast <DomNode>(node).GetPath());
                    Matrix4F       parentLocalToWorld = TransformUtils.CalcPathTransform(path, path.Count - 2);
                    Matrix4F       parentWorldToLocal = new Matrix4F();
                    parentWorldToLocal.Invert(parentLocalToWorld);
                    Vec3F localTranslation;
                    parentWorldToLocal.TransformVector(translate, out localTranslation);
                    Vec3F trans = m_originalValues[i] + localTranslation;

                    if (snapToGrid)
                    {
                        if (grid.Snap)
                        {
                            trans = grid.SnapPoint(trans);
                        }
                        else
                        {
                            trans.Y = gridHeight;
                        }
                    }

                    node.Translation = trans;
                }
            }
        }
        public override void OnDragging(ViewControl vc, Point scrPt)
        {
            if (m_hitRegion == HitRegion.None || m_activeOp == null || m_activeOp.NodeList.Count == 0)
            {
                return;
            }

            // create ray in view space.
            Ray3F rayV = vc.GetWorldRay(scrPt);

            using (var intersectionScene = GameEngine.GetEditorSceneManager().GetIntersectionScene())
            {
                PickResult intersectionPt;
                if (!CalculateTerrainIntersection(vc, rayV, intersectionScene, out intersectionPt))
                {
                    return;
                }

                if (m_pendingStartPt)
                {
                    m_startPt        = intersectionPt._pt.Value;
                    m_pendingStartPt = false;
                }
                else
                {
                    ISnapSettings snapSettings = (ISnapSettings)DesignView;

                    bool  clampToSurface = Control.ModifierKeys == Keys.Shift;
                    var   pt             = intersectionPt._pt.Value;
                    Vec3F translate      = new Vec3F(pt.X - m_startPt.X, pt.Y - m_startPt.Y, 0.0f);
                    for (int i = 0; i < m_activeOp.NodeList.Count; i++)
                    {
                        ITransformable node = m_activeOp.NodeList[i];

                        Path <DomNode> path = new Path <DomNode>(Adapters.Cast <DomNode>(node).GetPath());
                        Matrix4F       parentLocalToWorld = TransformUtils.CalcPathTransform(path, path.Count - 2);
                        Matrix4F       parentWorldToLocal = new Matrix4F();
                        parentWorldToLocal.Invert(parentLocalToWorld);

                        Vec3F            newWorldPos   = m_originalTranslations[i] + translate;
                        float            terrainHeight = 0.0f;
                        GUILayer.Vector3 terrainNormal;
                        if (GUILayer.EditorInterfaceUtils.GetTerrainHeightAndNormal(
                                out terrainHeight, out terrainNormal,
                                intersectionScene, newWorldPos.X, newWorldPos.Y))
                        {
                            newWorldPos.Z = terrainHeight + (clampToSurface ? 0.0f : m_originalHeights[i]);
                            Vec3F localTranslation;
                            parentWorldToLocal.TransformVector(newWorldPos, out localTranslation);
                            node.Translation = localTranslation;

                            // There are two ways to orient the "up" vector of the object.
                            // One way is to decompose the 3x3 rotation matrix into a up vector + a rotation around
                            // that vector. Then we retain the rotation, and just move the up vector.
                            // Another way is to take the 3x3 matrix, and adjust it's up vector. Then just perform
                            // the Gram–Schmidt algorithm to re-orthogonalize it.
                            // We'll use the code from the SCEE level editor. This isn't the ideal math (there's a
                            // lot of room for floating point creep) but it should work.
                            var currentUp = node.Transform.ZAxis;
                            if (snapSettings.TerrainAlignment == TerrainAlignmentMode.TerrainUp)
                            {
                                node.Rotation = TransformUtils.RotateToVector(
                                    node.Rotation, new Vec3F(terrainNormal.X, terrainNormal.Y, terrainNormal.Z),
                                    AxisSystemType.ZIsUp);
                            }
                            else
                            if (snapSettings.TerrainAlignment == TerrainAlignmentMode.WorldUp)
                            {
                                // Prevent the change if the normal is already very close to straight up
                                if (Math.Abs(currentUp.X - 0.0f) > 1e-4f || Math.Abs(currentUp.Y - 0.0f) > 1e-4f || Math.Abs(currentUp.Z - 1.0f) > 1e-4f)
                                {
                                    node.Rotation = TransformUtils.RotateToVector(
                                        node.Rotation, new Vec3F(0.0f, 0.0f, 1.0f),
                                        AxisSystemType.ZIsUp);
                                }
                            }

                            node.UpdateTransform();
                        }
                    }
                }
            }
        }