pragada_rk

Rotate tool - Need help please urgent

Discussion created by pragada_rk on May 11, 2010
Latest reply on Sep 1, 2011 by charga
Rotate tool
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.esr iScreenCache.esriAllScreenCaches);
}
}
catch (Exception ex)
{

}
finally
{

}

}

Outcomes