《GS软件设计》实习报告
#region constructor
public ControlsSynchronizer() {
//初始化ArrayList
m_frameworkControls = new ArrayList(); }
public ControlsSynchronizer(IMapControl3 mapControl, IPageLayoutControl2 pageLayoutControl) : this() {
//为类成员赋值
m_pageLayoutControl = pageLayoutControl; }
#endregion
#region properties
public IMapControl3 MapControl {
get { return m_mapControl; } set { m_mapControl = value; } }
public IPageLayoutControl2 PageLayoutControl {
get { return m_pageLayoutControl; } set { m_pageLayoutControl = value; } }
public string ActiveViewType {
get {
if (m_IsMapCtrlactive)
return \ else
return \ } }
public object ActiveControl {
get {
if (m_mapControl == null | m_pageLayoutControl == null) throw new
Exception(\PageLayoutControl are not initialized!\
if (m_IsMapCtrlactive)
return m_mapControl.Object; else
return m_pageLayoutControl.Object; } }
#endregion #regio
public void ActivateMap()
5
《GS软件设计》实习报告
{
try {
if (m_pageLayoutControl == null | m_mapControl == null) throw new Exception(\ MapControl or PageLayoutControl
are not initialized!\m_pageLayoutActiveTool = m_pageLayoutControl.CurrentTool;
m_pageLayoutControl.ActiveView.Deactivate(); MapControl m_mapControl.ActiveView.Activate(m_mapControl.hWnd); if (m_mapActiveTool != null) m_mapControl.CurrentTool = m_mapActiveTool;
的 CurrentTool
m_IsMapCtrlactive = true; MapControl
this.SetBuddies(m_mapControl.Object); } catch (Exception ex) Exception(string.Format(\ throw new
{ ex.Message));
} }
public void ActivatePageLayout() {
try Exception(\ {
if (m_pageLayoutControl == null |
m_mapControl == null) PageLayoutControl are not initialized!\
m_mapControl.CurrentTool;
if (m_mapControl.CurrentTool != null) m_mapActiveTool = m_pageLayoutControl.ActiveView.Activate(m_pageLayoutControl.hWnd); m_mapControl.ActiveView.Deactivate(); m_pageLayoutControl.CurrentTool = m_pageLayoutActiveTool;
if (m_pageLayoutActiveTool != null) this.SetBuddies(m_pageLayoutControl.Object); m_IsMapCtrlactive = false; }
catch (Exception ex) Exception(string.Format(\ throw new
{ ex.Message));
} }
public void ReplaceMap(IMap newMap) {
Exception(\ if (newMap == null) throw new
not initialized!\
if (m_pageLayoutControl == null | m_mapControl == null)
Exception(\ throw new
PageLayoutControl are not
6
or
《GS软件设计》实习报告
initialized!\
IMaps maps = new Maps();
maps.Add(newMap);
bool bIsMapActive = m_IsMapCtrlactive; this.ActivatePageLayout();
m_pageLayoutControl.PageLayout.ReplaceMaps(maps);
m_mapControl.Map = newMap;
m_pageLayoutActiveTool = null; m_mapActiveTool = null;
if (bIsMapActive) {
this.ActivateMap();
m_mapControl.ActiveView.Refresh(); } else {
this.ActivatePageLayout();
m_pageLayoutControl.ActiveView.Refresh(); } }
public void BindControls(IMapControl3 mapControl, IPageLayoutControl2 pageLayoutControl, bool activateMapFirst) {
if (mapControl == null | pageLayoutControl == null)
throw new
Exception(\PageLayoutControl are not initialized!\
m_mapControl = MapControl; m_pageLayoutControl = pageLayoutControl;
this.BindControls(activateMapFirst); }
public void BindControls(bool activateMapFirst) {
if (m_pageLayoutControl == null | m_mapControl == null)
throw new
Exception(\PageLayoutControl are not initialized!\
IMap newMap = new MapClass(); newMap.Name = \
IMaps maps = new Maps();
maps.Add(newMap);
m_pageLayoutControl.PageLayout.ReplaceMaps(maps);
m_mapControl.Map = newMap;
7
《GS软件设计》实习报告
m_pageLayoutActiveTool = null; m_mapActiveTool = null;
if (activateMapFirst)
this.ActivateMap(); else
this.ActivatePageLayout(); }
public void AddFrameworkControl(object control) {
if (control == null) throw new
Exception(\not initialized!\
m_frameworkControls.Add(control); }
public void RemoveFrameworkControl(object control) {
if (control == null) throw new
Exception(\ to be removed is not initialized!\
m_frameworkControls.Remove(control); }
public void RemoveFrameworkControlAt(int index) {
if (m_frameworkControls.Count < index) throw new
Exception(\of range!\
m_frameworkControls.RemoveAt(index); }
private void SetBuddies(object buddy) {
try {
if (buddy == null)
throw new
Exception(\initialized!\
foreach (object obj in m_frameworkControls) {
if (obj is IToolbarControl) {
((IToolbarControl)obj).SetBuddyControl(buddy); }
else if (obj is ITOCControl) {
((ITOCControl)obj).SetBuddyControl(buddy); } } }
catch (Exception ex) { throw new
Exception(string.Format(\ex.Message));
}
8
《GS软件设计》实习报告
}
#endregion } }
新建 Maps 类
在同步类中,要用到 Maps 类,用于管理地图对象。与新建同步类 ControlsSynchronizer 类似,我们新建一 Maps 类,其所有 代码如下所示:
using System;
using System.Collections;
using System.Collections.Generic; using System.Text;
using System.Runtime.InteropServices; using ESRI.ArcGIS.Carto;
namespace _sdnMap {
[Guid(\ [ClassInterface(ClassInterfaceType.None)] [ProgId(\
public class Maps : IMaps, IDisposable {
//class member - using internally an ArrayList to manage the Maps collection
private ArrayList m_array = null; #region class constructor public Maps() {
m_array = new ArrayList(); }
#endregion
#region IDisposable Members
public void Dispose() {
if (m_array != null) { m_array.Clear(); m_array = null; } }
#endregion
#region IMaps Members
public void RemoveAt(int Index) {
if (Index > m_array.Count | Index < 0)
throw new Exception(\range!\
m_array.RemoveAt(Index); }
public void Reset() {
9