DlgBaseHeight.cpp
上传用户:juying163
上传日期:2014-09-24
资源大小:5867k
文件大小:4k
源码类别:

GIS编程

开发平台:

Visual C++

  1. // DlgBaseHeight.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "3D0214.h"
  5. #include "DlgBaseHeight.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CDlgBaseHeight dialog
  13. CDlgBaseHeight::CDlgBaseHeight(CWnd* pParent /*=NULL*/)
  14. : CDialog(CDlgBaseHeight::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CDlgBaseHeight)
  17. //}}AFX_DATA_INIT
  18. }
  19. void CDlgBaseHeight::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. //{{AFX_DATA_MAP(CDlgBaseHeight)
  23. DDX_Control(pDX, IDC_COMBO_LAYERS, m_combo_layers);
  24. DDX_Control(pDX, IDC_COMBO_CURRENT_LAYER, m_combo_currentlayer);
  25. //}}AFX_DATA_MAP
  26. }
  27. BEGIN_MESSAGE_MAP(CDlgBaseHeight, CDialog)
  28. //{{AFX_MSG_MAP(CDlgBaseHeight)
  29. //}}AFX_MSG_MAP
  30. END_MESSAGE_MAP()
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CDlgBaseHeight message handlers
  33. BOOL CDlgBaseHeight::OnInitDialog() 
  34. {
  35. CDialog::OnInitDialog();
  36. // TODO: Add extra initialization here
  37. //在这里需要注意:两个Conbo box 控件的属性的 Sort 都不能选
  38. //否则,你选择的都要乱
  39. m_combo_layers.ResetContent();
  40. //获得Scene
  41. HRESULT hr;
  42. CMainFrame *pFrame=(CMainFrame*)AfxGetMainWnd();//获得主框架指针
  43. CMy3D0214View *pView=(CMy3D0214View*)pFrame->GetActiveView();//获视图指针
  44. if(!pView->GetSceneFromView(&m_ipScene))
  45. {
  46. AfxMessageBox("不能得到Scene");
  47. return false;
  48. }
  49.  
  50. //为combo box添加项
  51. long layercount;
  52. m_ipScene->get_LayerCount(&layercount);
  53. ILayerPtr ipLayer;
  54. CComBSTR layername;
  55. for(int i=0;i<layercount;i++)
  56. {
  57.     
  58. m_ipScene->get_Layer(i,&ipLayer);
  59. hr=ipLayer->get_Name(&layername);
  60.  
  61.   m_combo_layers.AddString((CString)layername);
  62. m_combo_layers.SetItemDataPtr(i,ipLayer);
  63. m_combo_currentlayer.AddString((CString)layername);
  64. m_combo_currentlayer.SetItemDataPtr(i,ipLayer);
  65. }
  66. //设置como box默认选择项
  67. // m_combo_currentlayer.SetCurSel(0);
  68. // m_combo_layers.SetCurSel(0);
  69. return TRUE;  // return TRUE unless you set the focus to a control
  70.               // EXCEPTION: OCX Property Pages should return FALSE
  71. }
  72. void CDlgBaseHeight::OnOK() 
  73. {
  74. // TODO: Add extra validation here
  75. UpdateData(TRUE);
  76. if(m_ipScene) SetBaseHeight();
  77. CDialog::OnOK();
  78. }
  79. void CDlgBaseHeight::SetBaseHeight()
  80. {
  81. ::OleInitialize(FALSE);//组件操作初始化
  82.  HRESULT hr;
  83.  int index=m_combo_currentlayer.GetCurSel();
  84.  
  85.  ILayerPtr pCurrentLyer=(ILayer*)m_combo_currentlayer.GetItemDataPtr(index);
  86.  
  87.  index=m_combo_layers.GetCurSel();
  88.      ILayerPtr ppbasehLyer=(ILayer*) m_combo_layers.GetItemDataPtr(index);  
  89.  
  90.  //Raster表面 
  91.  IRasterSurfacePtr pRSurface(CLSID_RasterSurface);
  92.  IRasterLayerPtr prbasehLyer( ppbasehLyer);
  93.  ISurfacePtr pSurface;     
  94.  if(prbasehLyer!=NULL)
  95.  {
  96.        
  97.  IRasterPtr ipR;    
  98.  prbasehLyer->get_Raster(&ipR);    
  99.  IRasterBandCollectionPtr pRasterBands(ipR);    
  100.  IRasterBandPtr pRasterBand;   
  101.  pRasterBands->Item(0,&pRasterBand);   
  102.  pRSurface->put_RasterBand(pRasterBand);    
  103.  pSurface=pRSurface;
  104.  }
  105.  //Tin表面
  106.  ITinLayerPtr pTbasehLyer(ppbasehLyer);
  107.  ITinPtr ipT;
  108.  if(pTbasehLyer!=NULL)
  109.  {            
  110.  pTbasehLyer->get_Dataset(&ipT);    
  111.  pSurface=ipT;
  112.  }
  113.  I3DPropertiesPtr pDDD;
  114.  //得到pDDD
  115. // AfxMessageBox("不能得到1");
  116.  ILayerExtensionsPtr pLayerExts( pCurrentLyer) ;
  117.  
  118.  //(pCurrentLyer);
  119.  //从Extension获得三维属性;
  120.  //这是三维显示的关键
  121.  long count=1;
  122.     hr=pLayerExts->get_ExtensionCount(&count);
  123.  if(FAILED(hr))  AfxMessageBox("不能得到2");;
  124.     //AfxMessageBox("不能得到2");;
  125.  IUnknownPtr p3DProps;
  126.  for(long i=0;i<count;i++)
  127.  {
  128.  pLayerExts->get_Extension(i,&p3DProps);
  129.  if(p3DProps!= NULL)
  130.  {
  131.  pDDD=p3DProps;
  132.  break;
  133.  }
  134.  }
  135.  pDDD->put_BaseOption(esriBaseSurface);
  136.  hr=pDDD->putref_BaseSurface(pSurface);
  137.  if(FAILED(hr)) return;
  138.  hr=pDDD->Apply3DProperties(pCurrentLyer);
  139.  ISceneGraphPtr ipSceneGrap;
  140.  m_ipScene->get_SceneGraph(&ipSceneGrap);
  141.  ipSceneGrap->RefreshViewers();
  142. }
  143.