ArcObjects SDK開發 022 開發框架搭建-FrameWorkUI包設計

mytudousi發表於2022-12-25

1、CommandUIs部分

這部分主要是定義承載Command和Tool的具體UI。如下圖所示。

image1.png

以CommandUI結尾的這幾個類都是繼承了Framework.Engine裡面的ICommandUI介面,這樣我們定義的Command和Tool就可以和這些UI繫結到一起了。

其中BarButtonItemCommandUI是DEV庫中普通的按鈕,BarCheckItemCommandUI是DEV庫中由選中狀態的按鈕,MenuItemCommandUI是選單按鈕,一般右鍵選單項會用這個UI,ToolStripMenuItemCommandUI是Winform下右鍵選單項,在TocControl圖層樹中的右鍵選單會採用這個按鈕項。

ArcObjects SDK開發 022 開發框架搭建-FrameWorkUI包設計

2、Controls部分

主要定義了常用的UI。如下圖所示。

image4.png

ArcObjects SDK開發 022 開發框架搭建-FrameWorkUI包設計

3、常用命令和工具

image6.png

我們看下最常用的地圖放大工具的定義。

public class MapZoomInTool : MapTool
{
    private readonly ESRI.ArcGIS.SystemUI.ITool _EsriTool = null;
    public MapZoomInTool(MapApplication pMapApplication)
        : base(pMapApplication)
    {
        this._EsriTool = new ControlsMapZoomInToolClass();
        this.SetIcon(CommandIconSize.IconSize16, "MapTools/Res/MapZoomIn16.png");
    }

    /// <summary>
    /// 啟用執行的函式
    /// </summary>
    public override void OnActive()
    {
        base.OnActive();
        (this._EsriTool as ESRI.ArcGIS.SystemUI.ICommand).OnCreate(this.MapApplication.ActiveControl);
        this.MapApplication.ActiveControl.CurrentTool = this._EsriTool;
    }

    /// <summary>
    /// 工具失活執行的函式
    /// </summary>
    public override void OnDeActivate()
    {
        base.OnDeActivate();
        this.MapApplication.ActiveControl.CurrentTool = null;
    }

    /// <summary>
    /// 滑鼠按下執行的函式
    /// </summary>
    /// <param name="button"></param>
    /// <param name="shift"></param>
    /// <param name="x"></param>
    /// <param name="y"></param>
    public override void OnMouseDown(int button, int shift, int x, int y)
    {
        if (button == 4)
        {
            this.MapApplication.AxControlPan();
        }
        base.OnMouseDown(button, shift, x, y);
    }
}

這就意味著,只要繼承實現了MapApplication這個類,就可以直接使用該工具。例如我們的系統首頁,定義了一個MapApplication例項,那麼可以在此基礎上初始化地圖放大工具。

我們系統裡面其他功能也要用這個工具的時候,也可以初始化一個MapApplication,或者實現一個繼承MapApplication的類。例如系統中的出圖模板設計功能。

ArcObjects SDK開發 022 開發框架搭建-FrameWorkUI包設計

這個功能裡面,我們繼承MapApplication,定義了LayoutDesignApplication。如下圖所示。

public class LayoutDesignApplication : MapApplication
{
    /// <summary>
    /// 版式設計主程式類
    /// </summary>
    /// <param name="pAxMapControl"></param>
    /// <param name="pAxPageLayoutControl"></param>
    public LayoutDesignApplication(AxMapControl pAxMapControl, AxPageLayoutControl pAxPageLayoutControl)
        : base(pAxMapControl, pAxPageLayoutControl)
    {
        this.LayoutDesign = new LayoutDesign();
    }

    /// <summary>
    /// 當前開啟的 模板檔案路徑
    /// </summary>
    public string ShmFilePath { get; set; } = "";

    /// <summary>
    /// 版式設計物件
    /// </summary>
    public LayoutDesign LayoutDesign { get; private set; } = null;

    /// <summary>
    /// 當前開啟地圖的後設資料
    /// </summary>
    public GeoChemMetaData GeoChemMetaData { get; private set; }

    /// <summary>
    /// 得到頁面佈局物件
    /// </summary>
    public IPageLayout PageLayout
    {
        get
        {
            return this.PageLayoutControl.PageLayout;
        }
    }
    /// <summary>
    /// 載入屬性皮膚的UI
    /// </summary>
    public Border PropertyBorder { get; set; } = null;
}

新增工具的程式碼如下。

this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new OpenMxdCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new OpenShmCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new AddDataCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new SaveShmCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new SaveAsShmCommand(this._LayoutDesignAplication)));

this.UI_Tool_Bar.Items.Add(new BarItemLinkSeparator());
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new MapFrameCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new MapGridCommand(this._LayoutDesignAplication)));

this.UI_Tool_Bar.Items.Add(new BarItemLinkSeparator());
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new ResTableCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new ClassTableCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new ClassHistogramCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new HistogramMapCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new NorthArrowCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new ScaleBarCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new LegendCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new TitleCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new PointTextTool(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new PictureCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new NeatlineItemCommand(this._LayoutDesignAplication)));

this.UI_Tool_Bar.Items.Add(new BarItemLinkSeparator());
SelectTool myPLDSelectTool = new SelectTool(this._LayoutDesignAplication);
this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(myPLDSelectTool));
this._LayoutDesignAplication.SelectTool = myPLDSelectTool;

this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new PageZoomInTool(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new PageZoomOutTool(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new PagePanTool(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new PageZoomInFixedCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new PageZoomOutFixedCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new PageZoomWholePageCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new PageZoom100PercentCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new PageZoomBackCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new PageZoomForwardCommand(this._LayoutDesignAplication)));
this.UI_Tool_Bar.Items.Add(new BarItemLinkSeparator());
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new ViewExportPicCommand(this._LayoutDesignAplication)));

 

再例如,布點的這個模組。

ArcObjects SDK開發 022 開發框架搭建-FrameWorkUI包設計

我們繼承MapApplication定義了DeployApplication,如下圖所示。

public class DeployApplication : MapApplication
{
    private Project _Project = null;
    private object _SelectObjectOnProjectTree = null;
    private IFeature _SelectPointFeature = null;

    /// <summary>
    /// 取樣點佈置主App
    /// </summary>
    /// <param name="pAxMapControl"></param>
    /// <param name="pAxPageLayoutControl"></param>
    public DeployApplication(AxMapControl pAxMapControl, AxPageLayoutControl pAxPageLayoutControl)
        : base(pAxMapControl, pAxPageLayoutControl)
    {
        this.EngineEditor = new EngineEditorClass();
    }

    /// <summary>
    /// ArcEngine編輯類
    /// </summary>
    public EngineEditorClass EngineEditor { get; private set; }

    /// <summary>
    /// 當前工程物件
    /// </summary>
    public Project Project
    {
        get
        {
            return this._Project;
        }
        set
        {
            this._Project = value;
            this.OnProjectChanged?.Invoke(this, new EventArgs());
        }
    }

    /// <summary>
    /// 得到或設定樹上選擇的物件
    /// </summary>
    public object SelectObjectOnWorkZoneTree
    {
        get { return this._SelectObjectOnProjectTree; }
        set
        {
            this._SelectObjectOnProjectTree = value;
            this.OnSelectObjectOnProjectTreeChanged?.Invoke(this, new EventArgs());
        }
    }

    /// <summary>
    /// 得到或設定當前選中的取樣點要素
    /// </summary>
    public IFeature SelectPointFeature
    {
        get
        {
            return this._SelectPointFeature;
        }
        set
        {
            this._SelectPointFeature = value;
            this.OnSelectPointFeatureChanged?.Invoke(this, new EventArgs());
        }
    }

    /// <summary>
    /// 觸發Map25Sheet資訊變化事件
    /// </summary>
    public void FireMap25SheetInfoChangedEvent()
    {
        this.OnMap25SheetInfoChanged?.Invoke(this, new EventArgs());
    }

    /// <summary>
    /// 當工程發生變化觸發的事件
    /// </summary>
    public event EventHandler<EventArgs> OnProjectChanged;

    /// <summary>
    /// 當在樹上選中的物件發生變化觸發的事件
    /// </summary>
    public event EventHandler<EventArgs> OnSelectObjectOnProjectTreeChanged;

    /// <summary>
    /// 當選擇的取樣點元素髮生變化觸發的事件
    /// </summary>
    public event EventHandler<EventArgs> OnSelectPointFeatureChanged;

    /// <summary>
    /// 當Map25Sheet的資訊發生變化後觸發的函式
    /// </summary>
    public event EventHandler<EventArgs> OnMap25SheetInfoChanged;
}

新增工具如下。

//初始化Application
this._DeployApplication = new DeployApplication(myAxMapControl, myAxPageLayoutControl);
this._DeployApplication.MainWindow = this;
this._DeployApplication.OnProjectChanged += Application_OnWorkZoneChanged;
this._DeployApplication.OnSelectObjectOnProjectTreeChanged += _Application_OnSelectObjectOnWorkZoneTreeChanged;
this._DeployApplication.OnSelectPointFeatureChanged += Application_OnSelectPointFeatureChanged;
this._DeployApplication.OnMap25SheetInfoChanged += Application_OnMap25SheetInfoChanged;

this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new ProjectNewCommand(this._DeployApplication)));
ProjectOpenCommand myWorkZoneOpenCommand = new ProjectOpenCommand(this._DeployApplication);
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(myWorkZoneOpenCommand));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.Files.AddDataCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarItemLinkSeparator());
this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new FrameworkUI.MapTools.MapZoomInTool(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new FrameworkUI.MapTools.MapZoomOutTool(this._DeployApplication)));
FrameworkUI.MapTools.MapPanTool myMapPanTool = new FrameworkUI.MapTools.MapPanTool(this._DeployApplication);
this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(myMapPanTool));
this._DeployApplication.CrruteTool = myMapPanTool;
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.MapTools.MapZoomInFixedCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.MapTools.MapZoomOutFixedCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.MapTools.MapFullExtentCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.MapTools.MapZoomBackCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.MapTools.MapZoomForwardCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarItemLinkSeparator());
this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new FrameworkUI.MapTools.MeasureTool(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarItemLinkSeparator());
this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new Map5SheetSelectTool(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new FrameworkUI.MapTools.FeaturesClearSelectCommand(this._DeployApplication) { Caption = "Clear Select" }));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new MapSheetLabelCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new SamplePointLabelCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new Map5TerrainViewCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarItemLinkSeparator());
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new Map25AutoPointCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new Map25ClearPointCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarItemLinkSeparator());
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new EditorStartCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new EditorEditTool(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new EditorNewPointTool(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new EditorSaveCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new EditorStopCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarItemLinkSeparator());
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new Map25LoadUnitCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new Map25EncodeCommand(this._DeployApplication)));
this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new Map25ExportCommand(this._DeployApplication)));

相關文章