大赵传奇

GIS解决方案,webgis , 桌面、数据、服务--QQ276605216

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
namespace Business.OutputMap
{
    [Guid("068df737-4a05-4d23-b906-e96693bfabe5")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("OutputMap.SaveMapMxdCommand")]
    public sealed class SaveMapMxdCommand : BaseCommand, IBarButtonItem, IShortCut
    {
        #endregion

        private IHookHelper m_hookHelper;
        //private IMapControl3 m_MapControl = null;
        private IMapDocument m_PageLayoutDocument = null;
        private IPageLayoutControl2 m_PageLayoutControl = null;
        public SaveMapMxdCommand(IMapDocument mxdDoc)
        {
        }

        #region Overriden Class Methods

        /// <summary>
        /// 勾子,命令创建的时候触发
        /// </summary>
        /// <param name="hook">Instance of the application</param>
        public override void OnCreate(object hook)
        {
            if (hook == null)
                return;

            if (m_hookHelper == null)
                m_hookHelper = new HookHelperClass();

            m_hookHelper.Hook = hook;

            // TODO:  Add other initialization code
            object hookMap = null;
            if (m_hookHelper.Hook is IToolbarControl2)
                hookMap = (m_hookHelper.Hook as IToolbarControl2).Buddy;
            else
                hookMap = m_hookHelper.Hook;

            if (hookMap is IPageLayoutControl2)
                this.m_PageLayoutControl = hookMap as IPageLayoutControl2;
            //if (hookMap is IMapControl3)
            //    m_MapControl = hookMap as IMapControl3;
        }

        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {

            //IObjectCopy lip_ObjCopy = new ObjectCopyClass();
            //IMxdContents pMxdContents = ((IMap)lip_ObjCopy.Copy(this.m_hookHelper.ActiveView.FocusMap)) as IMxdContents;
            //m_PageLayoutDocument.ReplaceContents(pMxdContents);
            //m_PageLayoutDocument.Save(m_PageLayoutDocument.UsesRelativePaths, false);

            m_PageLayoutDocument.ReplaceContents((IMxdContents)m_PageLayoutControl.Object);
            m_PageLayoutDocument.SetActiveView(m_PageLayoutControl.ActiveView);
            m_PageLayoutDocument.Save(m_PageLayoutDocument.UsesRelativePaths, true);
        }

        public override bool Enabled
        {
        }

        #endregion
    }
}

 

posted on 2024-10-29 12:21  赵长青  阅读(4)  评论(0编辑  收藏  举报