BM.AE中的命令工具体系

ArcEngine本身已经有了一套很完善的命令好工具体系,但我们直接使用时还是有些困难的。

1.ICommand接口中的图片的格式是我们不常见的,我们在设置时很不好设置。

2.Engine中的Command无法替换UI,Engine中的Command已经是和UI绑定到一起的了,如果我们要放到别的UI上需要做一些转换工作。

3.IComamnd里面的一些属性都是自读的,我们继承起来很不方面,而且有些属性例如标题、图标等,是可以允许在外部设置的。

新的命令工具框架如下:

这种结构我们在设置一些属性的时候会更加灵活,最主要的是我们把Engine中的Command和UI解耦了,当我们定义好Commad和Tool之后,我们定义的Command和Tool可以在不同的UI上体现。这样就可以很好的满足我们的项目需求。而且这样我们写代码时也就比较方便,例如我的主界面的后台代码如下:

View Code
  1 namespace BM.AE
  2 {
  3     public partial class MainWindow : DXWindow
  4     {
  5         private BM.AE.Engine.MapApplication _mapApplication = null;
  6         private Engine.GlobeApplication _globeApplication = null;
  7 
  8         public MainWindow()
  9         {
 10             ThemeManager.ApplicationThemeName = "Office2007Blue";
 11             InitializeComponent();
 12 
 13             Engine.CheckLicenses myCheckLicenses = new Engine.CheckLicenses();
 14             myCheckLicenses.Check();
 15 
 16             AxMapControl myAxMapControl = new AxMapControl();
 17             myAxMapControl.BeginInit();
 18             this.MapHost.Child = myAxMapControl;
 19             myAxMapControl.EndInit();
 20 
 21             AxPageLayoutControl myAxPageLayoutControl = new AxPageLayoutControl();
 22             myAxPageLayoutControl.BeginInit();
 23             this.PageLayoutHost.Child = myAxPageLayoutControl;
 24             myAxPageLayoutControl.EndInit();
 25 
 26             AxGlobeControl myAxGlobeControl = new AxGlobeControl();
 27             myAxGlobeControl.BeginInit();
 28             this.GlobeHost.Child = myAxGlobeControl;
 29             myAxGlobeControl.EndInit();
 30             myAxGlobeControl.Navigate = true;
 31 
 32             UI.AETocControl myAETocControl = new UI.AETocControl();
 33             this.Grid.Children.Add(myAETocControl);
 34 
 35             this._mapApplication = new BM.AE.Engine.MapApplication(myAxMapControl, myAxPageLayoutControl, myAETocControl);
 36             this._mapApplication.MainWindow = this;
 37             this._mapApplication.DefaultTool = new Commands.Maps.Standards.SelectTool(this._mapApplication);
 38 
 39             this._globeApplication = new Engine.GlobeApplication(myAxGlobeControl, null);
 40             this._globeApplication.MainWindow = this;
 41 
 42 
 43             RibbonPage myRibbonPage = new RibbonPage();
 44             myRibbonPage.Caption = "视图操作";
 45 
 46             RibbonPageGroup myRibbonPageGroup = new RibbonPageGroup();
 47             myRibbonPageGroup.Caption = "文件";
 48             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Standards.CreateNewDocCommand(this._mapApplication), false));
 49             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Standards.OpenMxdCommand(this._mapApplication), false));
 50             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Standards.SaveMxdCommand(this._mapApplication), false));
 51             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Standards.SaveAsMxdCommand(this._mapApplication), false));
 52             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Standards.ExportMapCommand(this._mapApplication), false));
 53             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Standards.OverViewCommand(this._mapApplication), false));
 54             myRibbonPage.Groups.Add(myRibbonPageGroup);
 55 
 56             myRibbonPageGroup = new RibbonPageGroup();
 57             myRibbonPageGroup.Caption = "地图工具";
 58             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.DataViews.MapZoomInTool(this._mapApplication)));
 59             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.DataViews.MapZoomOutTool(this._mapApplication)));
 60             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.DataViews.MapZoomInFixedCommand(this._mapApplication)));
 61             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.DataViews.MapZoomOutFixedCommand(this._mapApplication)));
 62             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.DataViews.MapPanTool(this._mapApplication)));
 63             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.DataViews.MapFullExtentCommand(this._mapApplication)));
 64             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.DataViews.MapZoomToLastExtentBackCommand(this._mapApplication)));
 65             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.DataViews.MapZoomToLastExtentForwardCommand(this._mapApplication)));
 66             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(this._mapApplication.DefaultTool));
 67             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Standards.IdentifyTool(this._mapApplication)));
 68             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.DataViews.MapRefreshViewCommand(this._mapApplication)));
 69             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Standards.SelectFeaturesTool(this._mapApplication)));
 70             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Standards.ClearSelectionCommand(this._mapApplication)));
 71             myRibbonPage.Groups.Add(myRibbonPageGroup);
 72 
 73             myRibbonPageGroup = new RibbonPageGroup();
 74             myRibbonPageGroup.Caption = "版式工具";
 75             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.PageLayoutViews.PageZoomInTool(this._mapApplication)));
 76             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.PageLayoutViews.PageZoomOutTool(this._mapApplication)));
 77             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.PageLayoutViews.PagePanTool(this._mapApplication)));
 78             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.PageLayoutViews.PageZoomInFixedCommand(this._mapApplication)));
 79             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.PageLayoutViews.PageZoomOutFixedCommand(this._mapApplication)));
 80             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.PageLayoutViews.PageZoomWholePageCommand(this._mapApplication)));
 81             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.PageLayoutViews.PageZoom100PercentCommand(this._mapApplication)));
 82             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.PageLayoutViews.PageZoomPageToLastExtentBackCommand(this._mapApplication)));
 83             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.PageLayoutViews.PageZoomPageToLastExtentForwardCommand(this._mapApplication)));
 84             
 85             myRibbonPage.Groups.Add(myRibbonPageGroup);
 86 
 87             myRibbonPageGroup = new RibbonPageGroup();
 88             myRibbonPageGroup.Caption = "三维操作";
 89             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Globes.Views.GlobeNavigateTool(this._globeApplication)));
 90             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Globes.Views.GlobeZoomInOutTool(this._globeApplication)));
 91             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Globes.Views.GlobePanTool(this._globeApplication)));
 92             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Globes.Views.GlobePanDragTool(this._globeApplication)));
 93             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Globes.Views.GlobeNorthCommand(this._globeApplication)));
 94             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Globes.Views.GlobeFlyTool(this._globeApplication)));
 95             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.GlobeOpenDocCommand(this._globeApplication)));
 96             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Globes.Views.GlobeFullExtentCommand(this._globeApplication)));
 97             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Globes.Views.GlobeFixedZoomInCommand(this._globeApplication)));
 98             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Globes.Views.GlobeFixedZoomOutCommand(this._globeApplication)));
 99             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Globes.Views.GlobeFullExtentCommand(this._globeApplication)));
100             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.GlobeSelectFeaturesTool(this._globeApplication)));
101             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Globes.Views.GlobeWalkTool(this._globeApplication)));
102 
103             myRibbonPage.Groups.Add(myRibbonPageGroup);
104 
105 
106             myRibbonPageGroup = new RibbonPageGroup();
107             myRibbonPageGroup.Caption = "测试";
108             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new BM.AE.Commands.TestCommand(this._mapApplication)));
109             myRibbonPage.Groups.Add(myRibbonPageGroup);
110 
111 
112            
113 
114             this.Ribbon.Pages.Add(myRibbonPage);
115 
116 
117             myRibbonPage = new RibbonPage();
118             myRibbonPage.Caption = "编辑";
119 
120             myRibbonPageGroup = new RibbonPageGroup();
121             myRibbonPageGroup.Caption = "编辑";
122             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Editors.EditorStartCommand(this._mapApplication)));
123             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Editors.EditorStopCommand(this._mapApplication)));
124             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Editors.EditorSaveCommand(this._mapApplication)));
125             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Editors.EditorEditTool(this._mapApplication)));
126             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Editors.EditorCopyCommand(this._mapApplication)));
127             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Editors.EditorPasteCommand(this._mapApplication)));
128             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Editors.EditorSketchTool(this._mapApplication)));
129             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfCombox(new Commands.Maps.Editors.EditorTargetLayerCommand(this._mapApplication)));
130             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Editors.EditorUndoCommand(this._mapApplication)));
131             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Editors.EditorRedoCommand(this._mapApplication)));
132             myRibbonPage.Groups.Add(myRibbonPageGroup);
133             this.Ribbon.Pages.Add(myRibbonPage);
134 
135 
136             myRibbonPage = new RibbonPage();
137             myRibbonPage.Caption = "地图输出";
138 
139             myRibbonPageGroup = new RibbonPageGroup();
140             myRibbonPageGroup.Caption = "元素";
141             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Elements.NewMarkerTool(this._mapApplication)));
142             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Elements.NewLineTool(this._mapApplication)));
143             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Elements.NewCurveTool(this._mapApplication)));
144             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Elements.NewFreeHandTool(this._mapApplication)));
145             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Elements.NewRectangleTool(this._mapApplication)));
146             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Elements.NewCircleTool(this._mapApplication)));
147             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Elements.NewEllipseTool(this._mapApplication)));
148             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Elements.NewPolygonTool(this._mapApplication)));
149             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Elements.NewTextTool(this._mapApplication)));
150             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Elements.NewSplinedTextTool(this._mapApplication)));
151             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Elements.NewPictureCommand(this._mapApplication)));
152             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Elements.RotateElementTool(this._mapApplication)));
153             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfBarCheckItem(new Commands.Maps.Elements.DefaultElementSymbolSetCommand(this._mapApplication)));
154             
155             myRibbonPage.Groups.Add(myRibbonPageGroup);
156 
157             myRibbonPageGroup = new RibbonPageGroup();
158             myRibbonPageGroup.Caption = "地图图饰";
159             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.MapSurrounds.AddNorthArrowCommand(this._mapApplication)));
160             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.MapSurrounds.AddScaleBarCommand(this._mapApplication)));
161             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.MapSurrounds.AddScaleTextCommand(this._mapApplication)));
162             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.MapSurrounds.AddLegendCommand(this._mapApplication)));
163             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.PageLayoutViews.PagePropertyCommand(this._mapApplication)));
164             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.MapSurrounds.MapGridsCommand(this._mapApplication)));
165             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.MapSurrounds.ReplaceLayoutCommand(this._mapApplication)));
166             myRibbonPage.Groups.Add(myRibbonPageGroup);
167 
168             myRibbonPageGroup = new RibbonPageGroup();
169             myRibbonPageGroup.Caption = "打印";
170             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Prints.PagePrintPreviewCommand(this._mapApplication),false));
171             myRibbonPageGroup.ItemLinks.Add(new CommandUI.CommandUIOfRibbonButton(new Commands.Maps.Prints.PagePrintSetupCommand(this._mapApplication)));
172             myRibbonPage.Groups.Add(myRibbonPageGroup);
173             this.Ribbon.Pages.Add(myRibbonPage);
174 
175 
176             //图层相关的右键菜单
177             BM.AE.CommandUI.TocContextMenu myTocContextMenu = new CommandUI.TocContextMenu();
178             myTocContextMenu.AddCommandUI(new CommandUI.CommandUIOfToolStripMenuItem(new Commands.Maps.Layers.NewGroupLayerCommand(this._mapApplication)));
179             myTocContextMenu.AddCommandUI(new CommandUI.CommandUIOfToolStripMenuItem(new Commands.Maps.Layers.RemoveSelectLayerCommand(this._mapApplication)));
180             myTocContextMenu.AddCommandUI(new CommandUI.CommandUIOfToolStripMenuItem(new Commands.Maps.Layers.ZoomToSelectLayerCommand(this._mapApplication)));
181             myTocContextMenu.AddCommandUI(new CommandUI.CommandUIOfToolStripMenuItem(new Commands.Maps.Layers.FeatureLayerLabelCommand(this._mapApplication)));
182             myTocContextMenu.AddCommandUI(new CommandUI.CommandUIOfToolStripMenuItem(new Commands.Maps.Layers.LayerRendererCommand(this._mapApplication)));
183             myTocContextMenu.AddCommandUI(new CommandUI.CommandUIOfToolStripMenuItem(new Commands.Maps.Layers.SaveAsLayerFileCommand(this._mapApplication)));
184             myTocContextMenu.AddCommandUI(new CommandUI.CommandUIOfToolStripMenuItem(new Commands.Maps.Layers.TableFieldManagerCommand(this._mapApplication)));
185             myTocContextMenu.AddCommandUI(new CommandUI.CommandUIOfToolStripMenuItem(new Commands.Maps.Layers.LayerPropertyCommand(this._mapApplication)));
186             myAETocControl.LayerContextMenu = myTocContextMenu;
187 
188 
189             //地图相关的右键菜单
190             myTocContextMenu = new CommandUI.TocContextMenu();
191             myTocContextMenu.AddCommandUI(new CommandUI.CommandUIOfToolStripMenuItem(new Commands.Maps.Layers.RemoveSelectLayerCommand(this._mapApplication)));
192             myAETocControl.MapContextMenu = myTocContextMenu;
193 
194             this._mapApplication.ActivePattern = Engine.MapActivePattern.Map;
195         }
196 
197 
198 
199         private void DXTabControl_SelectionChanged(object sender, TabControlSelectionChangedEventArgs e)
200         {
201             if (this._mapApplication == null)
202             {
203                 return;
204             }
205             DXTabControl myTabControl = sender as DXTabControl;
206             if (myTabControl.SelectedIndex == 0)
207             {
208                 this._mapApplication.ActivePattern = Engine.MapActivePattern.Map;
209                 this._mapApplication.CrruteTool = this._mapApplication.DefaultTool;
210             }
211             else if (myTabControl.SelectedIndex == 1)
212             {
213                 this._mapApplication.ActivePattern = Engine.MapActivePattern.PageLayout;
214                 this._mapApplication.CrruteTool = this._mapApplication.DefaultTool;
215             }
216             else
217             {
218                 this._mapApplication.ActivePattern = Engine.MapActivePattern.None;
219             }
220 
221             this._globeApplication.IsActive = (myTabControl.SelectedIndex == 2);
222 
223         }
224 
225     }
226 
227 }

两百多行代码,就生成了我们下面的主界面上的Command和Tool。

IAECommand的代码定义如下:

View Code
namespace BM.AE.Engine
{

    /// <summary>
    /// 系统命令接口
    /// </summary>
    public interface IAECommand:ESRI.ArcGIS.SystemUI.ICommand
    {
        /// <summary>
        /// 是否可见
        /// </summary>
        bool Visible { get;}

        /// <summary>
        /// 主操作对象
        /// </summary>
        IApplication Application { get; }


        /// <summary>
        /// 显示的图像
        /// </summary>
        ImageSource Image { get; }


        /// <summary>
        /// 命令和U传递数据的值对象
        /// </summary>
        ICommandValue CommandValue{ get; }

        /// <summary>
        /// 设置工具UI
        /// </summary>
        /// <param name="pCommandUI"></param>
        void SetCommandUI(ICommandUI pCommandUI);


    }
}

AECommand的代码定义如下:

View Code
namespace BM.AE.Engine
{

    /// <summary>
    /// 命令基类
    /// </summary>
    public class AECommand:IAECommand
    {
        private IApplication _application = null;
        private ICommandUI _commandUI=null;

        private string _caption = "";
        private bool _checked = false;
        private bool _enabled = true;
        private string _message="";
        private string _name = "";
        private string _tooltip = "";
        private bool _visible = true;
        private ImageSource _image = null;

        /// <summary>
        /// 命令抽象类
        /// </summary>
        /// <param name="pDCApplication"></param>
        public AECommand(IApplication pApplication)
        {
            this._application = pApplication;
            this._commandUI = new NullCommandUI();
            this.Application.OnActiveStateChanged += new EventHandler<EventArgs>(ActiveStateChanged);
        }


        /// <summary>
        /// 命令抽象类
        /// </summary>
        public AECommand()
        {
            this._commandUI = new NullCommandUI();
        }


        public int Bitmap
        {
            get { return 0; }
        }



        public string Caption
        {
            get 
            {
                return this._caption;
            }
            set 
            {
                this._caption = value; 
            }
        }


        public string Category
        {
            get 
            {
                return "";
            }
        }


        /// <summary>
        /// 是否选中
        /// </summary>
        public bool Checked
        {
            get
            {
                return this._checked;
            }
            protected set
            {
                this._checked = value;
                this._commandUI.SetCheckedState(value);
            }
        }


        /// <summary>
        /// 是否可用
        /// </summary>
        public bool Enabled
        {
            get
            {
                return this._enabled;
            }
            protected set
            {
                this._enabled = value;
                this._commandUI.SetEnabledState(value);
                if (value == false && this.Checked)
                {
                    this.Checked = false;
                }
            }
        }

        public int HelpContextID
        {
            get { return 0; }
        }

        public string HelpFile
        {
            get { return ""; }
        }

        public string Message
        {
            get { return this._message; }
            set
            {
                this._message = value;
            }
        }

        public string Name
        {
            get { return this._name; }
            protected set { this._name = value; }
        }


        public bool Visible
        {
            get { return this._visible; }
            protected set
            {
                this._visible = value;
                this._commandUI.SetVisibleState(value);
            }
        }


        public virtual void OnClick()
        {
            this.Checked = false;
        }


        public void OnCreate(object hook)
        {
        }

        public string Tooltip
        {
            get { return this._tooltip; }
            set
            {
                this._tooltip = value;
                this._commandUI.SetToolTip(value);
            }
        }


        public ImageSource Image
        {
            get { return this._image; }
            set
            {
                this._image = value;
                this._commandUI.SetImageSource(value);
            }
        }


        public IApplication Application
        {
            get { return this._application; }
        }


        /// <summary>
        /// 命令和UI传递数据的值对象
        /// </summary>
        public ICommandValue CommandValue { get; protected set; }


        /// <summary>
        /// 得到会设置按钮所包含的UI
        /// </summary>
        public void SetCommandUI(ICommandUI pCommandUI)
        {
            this._commandUI = pCommandUI;
            if (this._commandUI == null)
            {
                this._commandUI = new NullCommandUI();
            }
            this._commandUI.SetCaption(this.Caption);
            this._commandUI.SetCheckedState(this.Checked);
            this._commandUI.SetEnabledState(this.Enabled);
            this._commandUI.SetImageSource(this.Image);
            this._commandUI.SetToolTip(this.Tooltip);
            this._commandUI.SetVisibleState(this.Visible);
        }


        /// <summary>
        /// 当系统的激活模式发生变化时执行的函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void ActiveStateChanged(object sender, EventArgs e)
        {
        }



        /// <summary>
        /// 设置图标
        /// </summary>
        /// <param name="pUrl"></param>
        protected void SetImage(string pAssemblyName,string pImagePath="")
        {
            this.Image = new BitmapImage(new Uri("/" + pAssemblyName + ";component/"+ pImagePath, UriKind.RelativeOrAbsolute));
        }


        internal void SetChecked(bool pIsChecked)
        {
            this.Checked = pIsChecked;
        }

    }
}

AETool的代码定义如下:

View Code
namespace BM.AE.Engine
{

    /// <summary>
    /// 基础工具的抽象类
    /// </summary>
    public abstract class AETool : AECommand,ITool
    {

        /// <summary>
        /// 工具基类
        /// </summary>
        /// <param name="pApplication"></param>
        public AETool(IApplication pApplication)
            : base(pApplication)
        { }


        public virtual int Cursor { get; set; }


        public virtual bool Deactivate()
        {
            return true;
        }

        public bool OnContextMenu(int x, int y)
        {
            return false;
        }

        public override void OnClick()
        {
            this.Application.CrruteTool = this;
        }

        public virtual void OnDblClick() { }

        public virtual void OnKeyDown(int keyCode, int shift) { }

        public virtual void OnKeyUp(int keyCode, int shift) { }

        public virtual void OnMouseDown(int button, int shift, int x, int y) 
        {
        }

        public virtual void OnMouseMove(int button, int shift, int x, int y) { }

        public virtual void OnMouseUp(int button, int shift, int x, int y) { }

        public virtual void Refresh(int hdc) { }

    }
}

ICommandUI的定义如下:

View Code
namespace BM.AE.Engine
{

    /// <summary>
    /// 命令可以绑定的UI接口
    /// </summary>
    public interface ICommandUI
    {

        /// <summary>
        /// 设置标题
        /// </summary>
        /// <param name="pCaption"></param>
        void SetCaption(string pCaption);


        /// <summary>
        /// 设置工具提示信息
        /// </summary>
        /// <param name="pToolTip"></param>
        void SetToolTip(string pToolTip);


        /// <summary>
        /// 设置图标
        /// </summary>
        /// <param name="pImageSource"></param>
        void SetImageSource(ImageSource pImageSource);


        /// <summary>
        /// 设置是否被选中
        /// </summary>
        /// <param name="pIsCheced"></param>
        void SetCheckedState(bool pIsCheced);


        /// <summary>
        /// 设置是否可用
        /// </summary>
        /// <param name="pIsEnabled"></param>
        void SetEnabledState(bool pIsEnabled);


        /// <summary>
        /// 设置是否可见
        /// </summary>
        /// <param name="IsVisible"></param>
        void SetVisibleState(bool pIsVisible);


        /// <summary>
        /// 得到命令对象
        /// </summary>
        /// <returns></returns>
        IAECommand GetCommand();

    }
}

 

 

posted @ 2012-12-13 21:32  xzbluemap  阅读(525)  评论(0编辑  收藏  举报