SafeDispatch/Safedispatch_4_0/SelectGT.cs
2024-02-22 18:43:59 +02:00

339 lines
12 KiB
C#

// Copyright 2010 ESRI
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
//
// See the use restrictions at <your ArcGIS install location>/DeveloperKit10.0/userestrictions.txt.
//
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using System.Collections.Generic;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.EngineCore;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto;
using System.IO;
using System.Collections;
using SafeMobileLib;
namespace Safedispatch_4_0
{
[Guid("2713c8ef-8c59-42c7-bbcd-a0a667b8f51b")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("GraphicTrackerMap.SelectGT")]
public sealed class SelectGT : 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
private IGraphicTracker LocalTracker = null;
private String tabName = "";
//private GTMapForm m_form = null;
public SelectGT(IGraphicTracker _LocalTracker,String _tabName)
{
LocalTracker = _LocalTracker;
tabName = _tabName;
base.m_category = "Graphic Tracker"; //localizable text
base.m_caption = "Select GT"; //localizable text
base.m_message = "Select GT"; //localizable text
base.m_toolTip = "Select graphic"; //localizable text
base.m_name = "GraphicTrackerMap_SelectGT"; //unique id, non-localizable (e.g. "MyCategory_MyTool")
try
{
base.m_bitmap = Dispatcher.Properties.Resources.SelectGT;
byte[] bin = Dispatcher.Properties.Resources.SelectGT1;
using (BinaryWriter binWriter = new BinaryWriter(File.Open(System.Windows.Forms.Application.StartupPath + @"\SelectGT.cur", FileMode.Create)))
{
binWriter.Write(bin);
}
base.m_cursor = new System.Windows.Forms.Cursor(System.Windows.Forms.Application.StartupPath + @"\SelectGT.cur");
}
catch (Exception ex)
{
SM.Debug("Error on create Select:"+ex.ToString());
}
}
#region Overriden Class Methods
public override void OnCreate(object hook)
{
/*if (m_hookHelper == null)
m_hookHelper = new HookHelperClass();
m_hookHelper.Hook = hook;*/
}
public override void OnClick()
{
/* IToolbarControl2 toolBarControl = m_hookHelper.Hook as IToolbarControl2;
IMapControl4 mapControl = m_hookHelper.Hook as IMapControl4;
if (toolBarControl != null)
mapControl = toolBarControl.Buddy as IMapControl4;
if (mapControl == null)
return;*/
}
public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
// Iterate through the GraphicTracker and unselect them all
/* m_form.m_graphicTracker.SuspendUpdate = true;
foreach (int i in m_form.m_GTGeometries.Keys) m_form.m_graphicTracker.Highlight(i, false);
m_form.m_graphicTracker.SuspendUpdate = false;*/
//Highlight the graphic identified by the HitTest result
try
{
int id = LocalTracker.HitTest(X, Y);
if (id != -1)
{
LocalTracker.Highlight(id, true);
foreach (String obj in MainForm2.vehicleHT.Keys)
{
if (((MapElement)(((Vehicle)MainForm2.vehicleHT[obj]).MapsHT[tabName])).GISID == id)
{
((MapElement)(((Vehicle)MainForm2.vehicleHT[obj]).MapsHT[tabName])).GISSelect = true;
//((MapElement)(((Vehicle)MainForm2.vehicleHT[obj]).MapsHT[tabName])).Updatelabel(((MapElement)(((Vehicle)MainForm2.vehicleHT[obj]).MapsHT[tabName])).labelGIS, 4);
((MapElement)(((Vehicle)MainForm2.vehicleHT[obj]).MapsHT[tabName])).UpdateLabelCMD(true);
}
else if (((MapElement)(((Vehicle)MainForm2.vehicleHT[obj]).MapsHT[tabName])).GISID!=-1)
{
try
{
LocalTracker.Highlight(((MapElement)(((Vehicle)MainForm2.vehicleHT[obj]).MapsHT[tabName])).GISID, false);
((MapElement)(((Vehicle)MainForm2.vehicleHT[obj]).MapsHT[tabName])).GISSelect = false;
if (MainForm2.Displaywithname) ((MapElement)(((Vehicle)MainForm2.vehicleHT[obj]).MapsHT[tabName])).Updatelabel(((Vehicle)MainForm2.vehicleHT[obj]).busName, 1);
else ((MapElement)(((Vehicle)MainForm2.vehicleHT[obj]).MapsHT[tabName])).Updatelabel("", 0);
}
catch (Exception ex)
{
SM.Debug("Unable to UNSELECT ID:" + ((MapElement)(((Vehicle)MainForm2.vehicleHT[obj]).MapsHT[tabName])).GISID + " name:" + ((Vehicle)MainForm2.vehicleHT[obj]).busName+" Error:"+ex.ToString());
}
}
}
}
}
catch (Exception ex)
{
SM.Debug("Error on mouse UP:"+ex.ToString());
}
}
#endregion
}
[Guid("2713c8ef-8c59-42c7-bbcd-a0a667b8f51b")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("GraphicTrackerMap.SelectGTHIS")]
public sealed class SelectGTHIS : 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
private IGraphicTracker LocalTracker = null;
private String tabName = "";
//private GTMapForm m_form = null;
public SelectGTHIS(IGraphicTracker _LocalTracker)
{
LocalTracker = _LocalTracker;
base.m_category = "Graphic Tracker"; //localizable text
base.m_caption = "Select GT"; //localizable text
base.m_message = "Select GT"; //localizable text
base.m_toolTip = "Select graphic"; //localizable text
base.m_name = "GraphicTrackerMap_SelectGT"; //unique id, non-localizable (e.g. "MyCategory_MyTool")
try
{
base.m_bitmap = Dispatcher.Properties.Resources.SelectGT;
byte[] bin = Dispatcher.Properties.Resources.SelectGT1;
using (BinaryWriter binWriter = new BinaryWriter(File.Open(System.Windows.Forms.Application.StartupPath + @"\SelectGT.cur", FileMode.Create)))
{
binWriter.Write(bin);
}
base.m_cursor = new System.Windows.Forms.Cursor(System.Windows.Forms.Application.StartupPath + @"\SelectGT.cur");
}
catch (Exception ex)
{
SM.Debug("Error on create Select:" + ex.ToString());
}
}
#region Overriden Class Methods
public override void OnCreate(object hook)
{
}
public override void OnClick()
{
}
ArrayList PositionList = new ArrayList();
public void UpdateLIST(ArrayList _posList)
{
PositionList = _posList;
}
public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
try
{
int id = LocalTracker.HitTest(X, Y);
if (id != -1)
{
try
{
if (PositionList.Count > 0)
{
Int32 both = 0;
foreach (POSIDGIS obj in PositionList)
{
if (obj.GISID==id)
{
LocalTracker.Highlight(obj.GISID, true);
MainForm2.simpleTextSymbol.YOffset = 30;
LocalTracker.SetTextSymbol(obj.GISID, MainForm2.simpleTextSymbol);
String SpeedDatax = " ;" + MainForm2.langSpeed + " " + Convert.ToString(obj.SMpos.m_speed) + MainForm2.kmh;
if (MainForm2.isInMile) SpeedDatax = " ;" + MainForm2.langSpeed + " " + Convert.ToString((int)Math.Round(obj.SMpos.m_speed * 0.621371192)) + MainForm2.milesh;
LocalTracker.SetLabel(obj.GISID, obj.SMpos.m_vehName + "_" + (obj.SMpos.m_posID-1) + "\n" + SpeedDatax + " " + MainForm2.langTime + " " + (obj.SMpos.m_time.ConvertGMTToLocal()).GetDTFromSeconds().ToShortTimeString() + "\n" + obj.SMpos.m_address);
obj.Select = true;
both++;
}
else if (obj.Select)
{
LocalTracker.Highlight(obj.GISID, false);
LocalTracker.SetLabel(obj.GISID, "");
obj.Select = false;
both++;
}
if (both == 2) break;
}
}
}
catch (Exception ex)
{
SM.Debug("Exception on click select a unit:" + ex.ToString());
}
}
}
catch (Exception ex)
{
SM.Debug("Error on mouse UP:" + ex.ToString());
}
}
#endregion
}
}