基礎的Mapgis三維二次開發-外掛式

lightmare625發表於2018-07-12

最近在做一個杭州石油的專案開發一個小系統。


1.命令必須是 ICommand 的派生類

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using MapGIS.PluginEngine;
using System.Windows.Forms;
using MapGIS.Scene3D;


namespace ThreeDimenModeling
{
    class IsoheightModeling : ICommand
    {
        //應用框架物件
        IApplication hock = null;
        //場景檢視控制元件
        SceneControl sceneCtrl = null; 

        #region ICommand成員 

        public Bitmap Bitmap
        {
            get { return null; }
        }

        public string Caption
        {
            get { return "等高線建模"; }
        }

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

        public bool Checked
        {
            get { return false; }
        }

        public bool Enabled
        {
            get { return true; }
        }

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

        public string Name
        {
            get { return "等高線建模"; }
        }

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

        public void OnClick()
        {
            sceneCtrl = (this.hock.ActiveContentsView as ISceneContentsView).SceneControl;
            IsoheightModelingForm IsoHeiMoForm = new IsoheightModelingForm(sceneCtrl ); 
            if (IsoHeiMoForm.ShowDialog() != DialogResult.OK) return;         
        }
        public void OnCreate(IApplication hook)
        {
            if (hook != null)
            {
                this.hock = hook;
                this.hock.StateManager.StateChangedEvent += new StateChangedHandler(StateManager_StateChangedEvent);
            }
        }
        void StateManager_StateChangedEvent(object sender, StateEventArgs e)
        {
            this.hock.PluginContainer.PluginEnable(this, false);
            bool bEnable = false;
            if (this.hock.ActiveContentsView != null && this.hock.ActiveContentsView is ISceneContentsView)
            {
                //當存在當前編輯狀態的圖層時,才可以進行查詢
                SceneControl ctr = (this.hock.ActiveContentsView as ISceneContentsView).SceneControl;
                if (ctr != null && ctr.GetSceneNum() > 0)
                {
                    bEnable = true;
                }
            }
            this.hock.PluginContainer.PluginEnable(this, bEnable); 
            return;
        }
        private void PluginContainer_ContentsViewClosingEvent(IContentsView contentsView, ContentsViewClosingEventArgs args)
        {
            if (contentsView is ISceneContentsView)
            {
                SceneControl ctr = (this.hock.ActiveContentsView as ISceneContentsView).SceneControl;
            }
        }
        #endregion
    }
}

2.彈出Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MapGIS.Scene3D; 

namespace ThreeDimenModeling
{
    public partial class IsoheightModelingForm : Form
    {
        //場景控制元件
        SceneControl sceneCtrl = null; 

        public IsoheightModelingForm(SceneControl sCtrl )
        {
            InitializeComponent();
            this.sceneCtrl = sCtrl; 
        }
    }
}

相關文章