POST
|
Hello evreyone: I'm programming a tool similar to ArcMap's Midpoint (Feature Constructor in Arcmap). I draw de line with a INewLineFeedback object and works well, but de mid point is well calculated, but doesn't refresh properly. i'm wondering if someone knows how i can resolve this.... I attacht my code and a screenshot with the trouble. Thanks for your attention [ATTACH=CONFIG]28702[/ATTACH]
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using System.Windows.Forms;
namespace Editor_Tools
{
/// <summary>
/// Summary description for Midpoint.
/// </summary>
[Guid("5a956a79-8872-4f48-aec9-5b048a307c31")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("EngineClassLibrary1.Midpoint")]
public sealed class Midpoint : BaseTool
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);
//
// TODO: Add any COM registration code here
//
}
[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);
//
// TODO: Add any COM unregistration code here
//
}
#region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
ControlsCommands.Register(regKey);
}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
ControlsCommands.Unregister(regKey);
}
#endregion
#endregion
#region private members
private IHookHelper m_hookHelper;
private IEngineEditor engineEditor ;
private IEngineEditSketch engineEditSketch;
private IPoint midPoint;
private IPoint f;
private IPoint s;
private INewLineFeedback pFeedbackEnv;
#endregion
public Midpoint()
{
//
// TODO: Define values for the public properties
//
base.m_category = ""; //localizable text
base.m_caption = ""; //localizable text
base.m_message = ""; //localizable text
base.m_toolTip = "Mid point"; //localizable text
base.m_name = ""; //unique id, non-localizable (e.g. "MyCategory_MyTool")
try
{
//
// TODO: change resource name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur");
engineEditor = new EngineEditorClass();
engineEditSketch = engineEditor as IEngineEditSketch;
midPoint = new PointClass();
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}
#region Overridden Class Methods
/// <summary>
/// Occurs when this tool is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
{
if (m_hookHelper == null)
m_hookHelper = new HookHelperClass();
m_hookHelper.Hook = hook;
// TODO: Add Midpoint.OnCreate implementation
}
/// <summary>
/// Occurs when this tool is clicked
/// </summary>
public override void OnClick()
{
// TODO: Add Midpoint.OnClick implementation
}
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
// TODO: Add Midpoint.OnMouseDown implementation
IActiveView pActiveView;
IScreenDisplay pScreenDisplay;
//
pActiveView = m_hookHelper.ActiveView;//My.ArcMap.Document.FocusMap;
pScreenDisplay = pActiveView.ScreenDisplay;
IPoint pPoint = new PointClass();
pPoint.PutCoords(X, Y);
pPoint = Transforms.GetMapCoordinatesFromScreenCoordinates(pPoint, pActiveView);
if (pFeedbackEnv == null)
{
pFeedbackEnv = new NewLineFeedbackClass();
pFeedbackEnv.Display = pActiveView.ScreenDisplay;
pFeedbackEnv.Start(pPoint);
f = pPoint;
}
else
{
//pFeedbackEnv.AddPoint(pPoint);
s = pPoint;
double dx = (f.X + s.X) / 2;
double dy = (f.Y + s.Y) / 2;
midPoint.PutCoords(dx, dy);
engineEditSketch.AddPoint(midPoint, true);
pFeedbackEnv = null;
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, pActiveView.Extent);
}
//engineEditSketch.AddPoint(pPoint, true);
}
public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
// TODO: Add Midpoint.OnMouseMove implementation
IActiveView pActiveView;
IScreenDisplay pScreenDisplay;
//
pActiveView = m_hookHelper.ActiveView;//My.ArcMap.Document.FocusMap;
pScreenDisplay = pActiveView.ScreenDisplay;
IPoint pPoint = new PointClass();
pPoint.PutCoords(X, Y);
if (pFeedbackEnv != null)
{
pPoint = Transforms.GetMapCoordinatesFromScreenCoordinates(pPoint, pActiveView);
pFeedbackEnv.MoveTo(pPoint);
s = pPoint;
double dx = (f.X + s.X)/2;
double dy = (f.Y + s.Y) / 2;
midPoint.PutCoords(dx,dy);
DrawPoint(pActiveView, midPoint);
}
}
public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
// TODO: Add Midpoint.OnMouseUp implementation
}
public override void OnDblClick()
{
base.OnDblClick();
engineEditSketch.FinishSketch();
}
public override bool Enabled
{
get
{
if ((engineEditor.EditState == esriEngineEditState.esriEngineStateEditing))
{
return base.Enabled == true;
}
return base.Enabled == false;
}
}
#endregion
public void DrawPoint(ESRI.ArcGIS.Carto.IActiveView activeView, IPoint point)
{
if (activeView == null)
{
return;
}
ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;
// Constant
screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbolClass();
ESRI.ArcGIS.Display.ISymbol symbol = simpleMarkerSymbol as ESRI.ArcGIS.Display.ISymbol; // Dynamic Cast
screenDisplay.SetSymbol(symbol);
ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;
// x and y are in device coordinates
//ESRI.ArcGIS.Geometry.IPoint point = displayTransformation.ToMapPoint(x, y);
screenDisplay.DrawPoint(point);
screenDisplay.FinishDrawing();
//activeView.PartialRefresh(esriViewDrawPhase.esriViewNone , null, activeView.Extent);
}
}
}
... View more
10-29-2013
01:01 PM
|
0
|
0
|
365
|
POST
|
Any ideas for how to implement this tool. I can now programmatically calculate the closest point to the point where I click. How to force the drawing on the feature containing that point?
... View more
08-30-2011
12:28 PM
|
0
|
0
|
271
|
POST
|
I have a tool written in C# for draw pictures using mid points; but i don't know how to finish the sketch using the OnDblClick() method overriden by my tool, because when I make a double click that method is never invoked. Here's the code below:
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
namespace Editor_Tools
{
/// <summary>
/// Summary description for Midpoint.
/// </summary>
[Guid("567745d3-b672-4ec3-9f51-635a06b6dea1")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Editor_Tools.Midpoint")]
public sealed class Midpoint : BaseTool
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);
//
// TODO: Add any COM registration code here
//
}
[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);
//
// TODO: Add any COM unregistration code here
//
}
#region ArcGIS Component Category Registrar generated code
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
ControlsCommands.Register(regKey);
}
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
ControlsCommands.Unregister(regKey);
}
#endregion
#endregion
#region private members
private IHookHelper m_hookHelper;
private IEngineEditor engineEditor = new EngineEditorClass();
private IEngineEditSketch engineEditSketch;
private IMapControlDefault mapControl;
#endregion
public Midpoint()
{
base.m_category = "Editor_Tools"; //localizable text
base.m_caption = "Mid Point"; //localizable text
base.m_message = "Mid Point"; //localizable text
base.m_toolTip = "Mid Point"; //localizable text
base.m_name = "Editor_Tools_Midpoint"; //unique id, non-localizable (e.g. "MyCategory_MyTool")
try
{
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur");
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}
#region Overridden Class Methods
public override void OnCreate(object hook)
{
if (m_hookHelper == null)
m_hookHelper = new HookHelperClass();
m_hookHelper.Hook = hook;
if (hook is IToolbarControl)
{
IToolbarControlDefault tbar = hook as IToolbarControlDefault;
mapControl = tbar.Buddy as IMapControlDefault;
}
else if (hook is MapControl)
{
mapControl = hook as IMapControlDefault;
}
}
public override void OnClick()
{
// TODO: Add Midpoint.OnClick implementation
engineEditSketch = engineEditor as IEngineEditSketch;
}
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
//constructLine();
IGeometry glinea = constructLine();
IPolyline linea = glinea as IPolyline;
IPoint to = linea.ToPoint;
IPoint from = linea.FromPoint;
IPoint mid = getMidPoint(from, to);
engineEditSketch.AddPoint(mid, true);
mapControl.ActiveView.Clear();
}
public override void OnDblClick()
{
base.OnDblClick();
MessageBox.Show("buu");
}
public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
// TODO: Add Midpoint.OnMouseMove implementation
}
public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
// TODO: Add Midpoint.OnMouseUp implementation
}
public override bool Enabled
{
get
{
if (!(engineEditor.EditState != esriEngineEditState.esriEngineStateNotEditing))
{
return base.Enabled == false;
}
return base.Enabled == true;
}
}
#endregion
private IGeometry constructLine()
{
if (mapControl.ActiveView == null)
{
//return;
return null;
}
ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = mapControl.ActiveView.ScreenDisplay;
// Constant
screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
ColorSelection.SetColor(0, 0, 0);
ESRI.ArcGIS.Display.IColor color = ColorSelection.GetColor(); // Implicit Cast
ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
simpleLineSymbol.Color = color;
ESRI.ArcGIS.Display.ISymbol symbol = (ESRI.ArcGIS.Display.ISymbol)simpleLineSymbol; // Explicit Cast
ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberLineClass();
ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay, symbol);
screenDisplay.SetSymbol(symbol);
screenDisplay.DrawPolyline(geometry);
screenDisplay.FinishDrawing();
return geometry;
}
private IPoint getMidPoint(IPoint from, IPoint to)
{
double x1, x2, y1, y2;
x1 = from.X;
y1 = from.Y;
x2 = to.X;
y2 = to.Y;
IPoint mid = new PointClass();
mid.X = (x1 + x2) / 2;
mid.Y = (y1 + y2) / 2;
return mid;
}
}
}
... View more
08-16-2011
08:12 AM
|
0
|
4
|
904
|
POST
|
don't work !!!! Especifically i have to draw circles ( or arc circles)... here my code:
IScreenDisplay screenDisplay = activeView.ScreenDisplay;
screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache);
ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
rgbColor.Red = 255;
ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit Cast
ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
simpleLineSymbol.Color = color;
ESRI.ArcGIS.Display.ISymbol symbol = (ESRI.ArcGIS.Display.ISymbol)simpleLineSymbol;
ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberCircleClass();
IGeometry circulo1;
circulo1 = rubberBand.TrackNew(screenDisplay, symbol);
screenDisplay.SetSymbol(symbol);
screenDisplay.DrawPolygon(circulo1);
screenDisplay.FinishDrawing();
... View more
08-03-2011
11:43 AM
|
0
|
0
|
276
|
POST
|
What's wrog with this code?..... IPoint from = arcPoints["from"] as IPoint; IPoint to = arcPoints["to"] as IPoint; IPoint thru = arcPoints["thru"] as IPoint; ICircularArc circularArcThreePoint = new CircularArcClass(); IConstructCircularArc construtionCircularArc = circularArcThreePoint as IConstructCircularArc; construtionCircularArc.ConstructThreePoints(from, thru, to, true); IScreenDisplay screenDisplay = m_mapControl.ActiveView.ScreenDisplay; ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass(); ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as ESRI.ArcGIS.Display.ISymbol; ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberPolygonClass(); screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); ISegment pSeg; ISegmentCollection polyline; pSeg = circularArcThreePoint as ISegment; polyline = new PolylineClass(); polyline.AddSegment(pSeg); screenDisplay.DrawPolyline(polyline as IGeometry); screenDisplay.FinishDrawing(); A try draw an arc circle, and then store in a new feature, but throw the following exception: COMException was unhandled by user code
... View more
08-03-2011
06:28 AM
|
0
|
4
|
2146
|
POST
|
IConstructMerge provide "Methods for doing a 3-way merge using two modified versions of a geometry along with the original" i want with C# implement this (see attachment) ArcMap tool (merge)
... View more
06-07-2011
08:12 AM
|
0
|
0
|
636
|
POST
|
Union create a new feature but not replacing it the original features
... View more
06-07-2011
05:48 AM
|
0
|
0
|
636
|
POST
|
Hello: I'm writing a application in C#; i can select features from the map (one layer loaded). but i don't know merging it into a same layer as i perform on ArcMap. I've read about IEngineEdit, but i don't know how to use this interface properly. Also, i saw the "CutPolygonsWithoutSelection" sample, but i don't find how to associate the merge function. I hope some guidance with this issue. Thank you for your attention. (PS: i'm from colombia and i'm still learning english,I apologize for any error in writing )
... View more
06-03-2011
03:00 PM
|
0
|
6
|
3948
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|