/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add cmdProject.OnClick implementation m_sxDoc = (ISxDocument)m_application.Document; //FormProject pfrm = new FormProject(); //pfrm.ShowDialog(); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { try { if (m_application == null) { return; } IDocument document = m_application.Document; ISxDocument sxDocument = (ISxDocument)(document); if (sxDocument != null) { m_scene = sxDocument.Scene; } if (m_scene == null) { return; } activeView = m_scene as IActiveView; //有图层选图层 if (m_scene.LayerCount == 0) { return; } //选择基准面 if (Common.SelectLayer(m_scene.Layers, out SelectedLyrIndex, true, "选择自定义表面") == false) { return; } //QI IRasterLayer baseRasterLayer = m_scene.Layer[SelectedLyrIndex[0]] as IRasterLayer; //不管选多少个只选第一个 if (baseRasterLayer == null) { throw new ArgumentNullException("自定义表面RasterLayer转换失败,为空。"); } IRaster raster = baseRasterLayer.Raster; if (raster == null) { throw new ArgumentNullException("自定义表面Raster转换失败,为空。"); } IRasterSurface rasterSurface = new RasterSurfaceClass(); rasterSurface.PutRaster(raster, 0); ISurface surface = rasterSurface as ISurface; //选择图层 if (Common.SelectLayer(m_scene.Layers, out SelectedLyrIndex, false, "选择要进行偏移的图层") == false) { return; } //选择倍数 NumSelect MultiNS = new NumSelect("输入夸大倍数", true); if (MultiNS.ShowDialog() != DialogResult.OK) { return; } double Multiplier = MultiNS.Result; //选择偏移量 NumSelect NS = new NumSelect(); if (NS.ShowDialog() != DialogResult.OK) { return; } double Offset = NS.Result; bool DisableCache = NS.DisableCache; //Create a CancelTracker. ITrackCancel pTrackCancel = new CancelTrackerClass(); //Create the ProgressDialog. This automatically displays the dialog IProgressDialogFactory pProgDlgFactory = new ProgressDialogFactoryClass(); IProgressDialog2 pProDlg = pProgDlgFactory.Create(pTrackCancel, m_application.hWnd) as IProgressDialog2; pProDlg.CancelEnabled = true; pProDlg.Title = "正在进行自定义表面设置及偏移调整"; pProDlg.Description = "设置中,请稍候..."; pProDlg.Animation = esriProgressAnimationTypes.esriProgressSpiral; IStepProgressor pStepPro = pProDlg as IStepProgressor; pStepPro.MinRange = 0; pStepPro.MaxRange = SelectedLyrIndex.Count; pStepPro.StepValue = 1; pStepPro.Message = "初始化中..."; bool bCont = true; //对每一个选中的图层进行操作 for (int i = 0; i < SelectedLyrIndex.Count; i++) { //m_application.StatusBar.set_Message(0, i.ToString()); pStepPro.Message = "已完成(" + i.ToString() + "/" + SelectedLyrIndex.Count.ToString() + ")"; bCont = pTrackCancel.Continue(); if (!bCont) { break; } //选中一个栅格图层 IRasterLayer rasterLayer = m_scene.Layer[SelectedLyrIndex[i]] as IRasterLayer; if (rasterLayer == null) { pStepPro.Message = "选中的图层非栅格图层..."; continue; } I3DProperties p3DProperties = null; ILayerExtensions layerExtensions = rasterLayer as ILayerExtensions; //遍历LayerExtensions找到I3DProperties for (int j = 0; j < layerExtensions.ExtensionCount; j++) { if (layerExtensions.get_Extension(j) is I3DProperties) { p3DProperties = layerExtensions.get_Extension(j) as I3DProperties; } } //设置I3DProperties p3DProperties.ZFactor = Multiplier; //系数 p3DProperties.BaseOption = esriBaseOption.esriBaseSurface; //基准面浮动 p3DProperties.BaseSurface = surface; //基准面 p3DProperties.OffsetExpressionString = Offset.ToString(); //偏移常量 if (DisableCache) { p3DProperties.RenderMode = esriRenderMode.esriRenderImmediate; //直接从文件渲染 p3DProperties.RenderVisibility = esriRenderVisibility.esriRenderWhenStopped; //停止导航时渲染 } p3DProperties.Apply3DProperties(rasterLayer); } pProDlg.HideDialog(); //========================================== //刷新,不起作用 if (activeView == null) { throw new Exception("活动视图为空! "); } if (m_sceneHookHelper.ActiveViewer == null) { throw new Exception("无活动视图!"); } activeView.Refresh(); m_sceneHookHelper.ActiveViewer.Redraw(true); //========================================== } catch (Exception err) { MessageBox.Show(err.ToString()); } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { try { if (m_application == null) { return; } IDocument document = m_application.Document; //根据应用类型初始化 switch (applicationType) { case ApplicationType.ArcMap: { IMxDocument mxDocument = (IMxDocument)(document); if (mxDocument != null) { m_map = mxDocument.FocusMap; } if (m_map == null) { return; } activeView = m_map as IActiveView; //有图层则选颜色 if (m_map.LayerCount == 0) { return; } if (Common.SelectColor(out FromIC, out ToIC) == false) { return; } //选图层 if (Common.SelectLayer(m_map.Layers, out SelectedLyrIndex) == false) { return; } break; } case ApplicationType.ArcScene: { ISxDocument sxDocument = (ISxDocument)(document); if (sxDocument != null) { m_scene = sxDocument.Scene; } if (m_scene == null) { return; } activeView = m_scene as IActiveView; //有图层则选颜色 if (m_scene.LayerCount == 0) { return; } if (Common.SelectColor(out FromIC, out ToIC) == false) { return; } //选图层 if (Common.SelectLayer(m_scene.Layers, out SelectedLyrIndex) == false) { return; } break; } default: { throw new ArgumentException("未指定应用类型。"); } } //Create a CancelTracker. ITrackCancel pTrackCancel = new CancelTrackerClass(); //Create the ProgressDialog. This automatically displays the dialog IProgressDialogFactory pProgDlgFactory = new ProgressDialogFactoryClass(); IProgressDialog2 pProDlg = pProgDlgFactory.Create(pTrackCancel, m_application.hWnd) as IProgressDialog2; pProDlg.CancelEnabled = true; pProDlg.Title = "正在进行唯一值计算"; pProDlg.Description = "唯一值计算中,请稍候..."; pProDlg.Animation = esriProgressAnimationTypes.esriProgressSpiral; IStepProgressor pStepPro = pProDlg as IStepProgressor; pStepPro.MinRange = 0; pStepPro.MaxRange = SelectedLyrIndex.Count; pStepPro.StepValue = 1; pStepPro.Message = "初始化中..."; bool bCont = true; //对每一个选中的图层进行唯一值化 for (int i = 0; i < SelectedLyrIndex.Count; i++) { //m_application.StatusBar.set_Message(0, i.ToString()); pStepPro.Message = "已完成(" + i.ToString() + "/" + SelectedLyrIndex.Count.ToString() + ")"; bCont = pTrackCancel.Continue(); if (!bCont) { break; } IRasterLayer rasterLayer = null; switch (applicationType) { case ApplicationType.ArcMap: { rasterLayer = m_map.Layer[SelectedLyrIndex[i]] as IRasterLayer; break; } case ApplicationType.ArcScene: { rasterLayer = m_scene.Layer[SelectedLyrIndex[i]] as IRasterLayer; break; } default: { throw new ArgumentException("未指定应用类型。"); } } if (rasterLayer == null) { pStepPro.Message = "选中的图层非栅格图层..."; continue; } //设置图层渲染器并更新 IRasterRenderer pRasterRenderer = UniqueValueRender(rasterLayer); //渲染唯一值 rasterLayer.Renderer = pRasterRenderer; rasterLayer.Renderer.Update(); //========================================== //刷新看起来不起作用 if (applicationType == ApplicationType.ArcScene) { m_scene.SceneGraph.Invalidate(rasterLayer, true, false); m_sceneHookHelper.ActiveViewer.Redraw(true); m_scene.SceneGraph.RefreshViewers(); //pRasterRenderer.Draw(rasterLayer.Raster,esriDrawPhase.esriDPGeography,display,null); } //========================================== } pProDlg.HideDialog(); //刷新 if (activeView == null) { throw new Exception("活动视图为空! "); } switch (applicationType) { case ApplicationType.ArcMap: { activeView.Refresh(); break; } case ApplicationType.ArcScene: { //========================================== //刷新看起来不起作用 //if (m_sceneHookHelper.ActiveViewer == null) // throw new Exception("无活动视图。"); activeView.Refresh(); //m_sceneHookHelper.ActiveViewer.Redraw(true); //IDisplay display = m_scene.SceneGraph as IDisplay; //if (display == null) // throw new ArgumentNullException("显示对象为空。"); //for (int i = 0; i < SelectedLyrIndex.Count; i++) //{ // IRasterLayer rasterLayer = m_scene.Layer[SelectedLyrIndex[i]] as IRasterLayer; // rasterLayer.Draw(esriDrawPhase.esriDPGeography, display, null); //} //IViewers3D viewers3D = m_scene.SceneGraph as IViewers3D; //if (viewers3D == null) // throw new ArgumentNullException("3D显示对象为空。"); //viewers3D.RefreshViewers(); break; //========================================== } default: { throw new ArgumentException("未指定应用类型。"); } } } catch (Exception err) { MessageBox.Show(err.ToString()); } }