Rotate tool

2290
2
04-19-2010 01:41 PM
KrishnaPragada
New Contributor II
Hi All,

I am writing rotate tool similar to ArcMap rotate tool using EngineRotateTrackerClass.  I am unable to rotate to features first time, however , able to rotate second time onwards. Can any one help me please.

Here is the scenorio 

1. Start editing
2. Select features
3. Select Rotate tool
4. Mousedown on map & rotate features...which is not working.
5. If again mousedown & rotate features working fine.

Here is the code I am using...


private IHookHelper m_hookHelper = null;
private IRotateTracker rotateTracker = null;
bool m_bMouseDownOccurred = true;


       public override void OnClick()
        {
            this.rotateTracker = new EngineRotateTrackerClass();
            IScreenDisplay screenDisplay = this.m_hookHelper.ActiveView.ScreenDisplay;
            this.rotateTracker.Display = screenDisplay;
        }

        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            InitializeTracker();

            if (this.rotateTracker != null)
                this.rotateTracker.OnMouseDown();

            m_bMouseDownOccurred = true;
        }

        private void InitializeTracker()
        {

            IEnumFeature enumFeat = this.m_hookHelper.FocusMap.FeatureSelection as IEnumFeature;
            if (enumFeat != null)
            {
                this.rotateTracker.ClearGeometry();

                IFeature feat = enumFeat.Next();
                ESRI.ArcGIS.Geometry.IGeometry objGeometry = feat.ShapeCopy;
                ESRI.ArcGIS.Geometry.IPoint objPoint = new ESRI.ArcGIS.Geometry.PointClass();
                objPoint.X = ((objGeometry.Envelope.UpperRight.X - objGeometry.Envelope.LowerLeft.X) / 2.0) +   
                                   objGeometry.Envelope.LowerLeft.X;
                objPoint.Y = ((objGeometry.Envelope.UpperRight.Y - objGeometry.Envelope.LowerLeft.Y) / 2.0) +
                                  objGeometry.Envelope.LowerLeft.Y;
                this.rotateTracker.Origin = objPoint;
                this.rotateTracker.ClearGeometry();
                //this.rotateTracker.AddGeometry(feat.ShapeCopy);
                enumFeat.Reset();
                feat = enumFeat.Next();
                while (feat != null)
                {
                    this.rotateTracker.AddGeometry(feat.ShapeCopy);
                    feat = enumFeat.Next();
                }
            }
        }


        public override void OnMouseMove(int Button, int Shift, int X, int Y)
        {
            if (!(Button == 1)) return;

            if (m_bMouseDownOccurred)
            {
                //Debug.WriteLine("RotationTrackerTool beginning OnMouseMove");
                if ((this.rotateTracker != null))
                {
                    ESRI.ArcGIS.Geometry.IPoint pPoint = new PointClass();

                    ESRI.ArcGIS.Display.IScreenDisplay pScreenDisplay = this.m_hookHelper.ActiveView.ScreenDisplay;

                    pPoint = pScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                    rotateTracker.OnMouseMove(pPoint);
                    // this.m_hookHelper.ActiveView.Refresh();
                }
            }
        }


       public override void OnMouseUp(int Button, int Shift, int X, int Y)
        {

            try
            {
                if (!(Button == 1)) return;

                //Debug.WriteLine("RotationTrackerTool beginning OnMouseUp");
                if ((rotateTracker != null))
                {
                    if (!rotateTracker.OnMouseUp())
                    {
                        return;
                    }
                    IInvalidArea2 pRefresh = null; ;
                    pRefresh = new InvalidAreaClass();
                    pRefresh.Display = this.m_hookHelper.ActiveView.ScreenDisplay;
                    engineEditor.StartOperation();
                    IEnumFeature enumFeat = this.engineEditor.EditSelection;
                    IFeature feat = enumFeat.Next();
                    while (feat != null)
                    {

                        pRefresh.Add(feat);
                        ESRI.ArcGIS.Geometry.IGeometry pGeom = feat.ShapeCopy;
                        if (pGeom is ESRI.ArcGIS.Geometry.ITransform2D)
                        {
                            ESRI.ArcGIS.Geometry.ITransform2D pTransform2D = pGeom as
                                          ESRI.ArcGIS.Geometry.ITransform2D;
                            pTransform2D.Rotate(rotateTracker.Origin, rotateTracker.Angle);
                            feat.Shape = pGeom;
                            feat.Store();
                            pRefresh.Add(feat);

                        }
                        feat = enumFeat.Next();
                    }

                    engineEditor.StopOperation("Rotate Operation");

                    pRefresh.Invalidate((short)ESRI.ArcGIS.Display.esriScreenCache.esriAllScreenCaches);
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {

            }

        }
0 Kudos
2 Replies
johnkaralis
New Contributor

same problem.. workaround:

[set OnMouseMove(point)<>Origin(point)] and before the OnMouseDown event to wake up rotateTracker mechanism..

try this:

        public override void OnMouseDown(int Button, int Shift, int X, int Y)

        {

            InitializeTracker();

            if (this.rotateTracker != null)

            {

               var hitPoint = this.m_hookHelper.ActiveView..ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

               this.rotateTracker.OnMouseMove(hitPoint);

               this.rotateTracker.OnMouseDown();

           }

            m_bMouseDownOccurred = true;

        }

0 Kudos
ChrisKushnir
New Contributor III

I believe the Origin and first OnMouseMove() point are specifying the '0-degree' vector wrt to feedback (not sure about the actual angle).

e.g.

public override void OnMouseDown( int BUTTON, int SHIFT, int X, int Y )

{

     if( App.EngineEditor.SelectionCount < 1 ) return;

     var pt = Hook.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

     RotateTracker = new RotateTrackerClass();

     RotateTracker.Display = Hook.ActiveView.ScreenDisplay;

     RotateTracker.Origin = pt;

     RotateTracker.ClearGeometry();

     // ... for each feature ... RotateTracker.AddGeometry(f.ShapeCopy);

     // specify point away from Origin to define 0-degree vector

     pt.Y += 10;

     RotateTracker.OnMouseMove(pt);

     RotateTracker.OnMouseDown();

}

You may also want to add all features in OnMouseDown to a SetClass and then iterate through the set and call IFeatureEdit.RotateSet() to mass rotate in OnMouseUp.  Using ITransform2D.Rotate() doesn't seem to handle anno properly (rotates feature polygon, not element) whereas RotateSet does.

If you use IFeatureEdit.RotateSet() make sure to read the doc's first:

http://edndoc.esri.com/arcobjects/9.1/ComponentHelp/esriGeoDatabase/IFeatureEdit.htm

0 Kudos