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

GIS编程

开发平台:

Visual C++

  1. // 3D0214View.cpp : implementation of the CMy3D0214View class
  2. //
  3. #include "stdafx.h"
  4. #include "3D0214.h"
  5. #include "3D0214Doc.h"
  6. #include "3D0214View.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMy3D0214View
  14. IMPLEMENT_DYNCREATE(CMy3D0214View, CFormView)
  15. BEGIN_MESSAGE_MAP(CMy3D0214View, CFormView)
  16. //{{AFX_MSG_MAP(CMy3D0214View)
  17. ON_WM_SIZE()
  18. ON_COMMAND(ID_FILE_EXPORT_MAP, OnFileExportMap)
  19. ON_COMMAND(ID_ADD_DEM_TO_SCENE, OnAddDemToScene)
  20. ON_COMMAND(ID_CREATE_RASTER_IDW, OnCreateRasterIdw)
  21. ON_COMMAND(ID_CREATEDEM_TIN, OnCreatedemTin)
  22. ON_COMMAND(ID_SET_SCENE, OnSetScene)
  23. ON_COMMAND(ID_SET_BASEHEIGHT, OnSetBaseheight)
  24. ON_COMMAND(ID_ADDLAYER, OnAddlayer)
  25. ON_COMMAND(ID_CLASSBREAKRENDERER, OnClassbreakrenderer)
  26. ON_COMMAND(ID_INFORMATION_QUERY, OnInformationQuery)
  27. ON_UPDATE_COMMAND_UI(ID_INFORMATION_QUERY, OnUpdateInformationQuery)
  28. ON_COMMAND(ID_CREATE_SLOP, OnCreateSlop)
  29. ON_COMMAND(ID_VIEWSHED, OnViewshed)
  30. ON_COMMAND(ID_LINEOFSIGHTPROFILE, OnLineofsightprofile)
  31. ON_UPDATE_COMMAND_UI(ID_LINEOFSIGHTPROFILE, OnUpdateLineofsightprofile)
  32. ON_COMMAND(ID_CREATE_CONTOUR, OnCreateContour)
  33. ON_COMMAND(ID_SELECTFEATRUES, OnSelectfeatrues)
  34. ON_UPDATE_COMMAND_UI(ID_SELECTFEATRUES, OnUpdateSelectfeatrues)
  35. //}}AFX_MSG_MAP
  36. // Standard printing commands
  37. ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
  38. ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
  39. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
  40. ON_UPDATE_COMMAND_UI(ID_INDICATOR_DEMO,CMy3D0214View::OnUpdateIndicatorDEMO)
  41. ON_UPDATE_COMMAND_UI(ID_INDICATOR_AUTHOR,CMy3D0214View::OnUpdateIndicatorAUTHOR)
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CMy3D0214View construction/destruction
  45. CMy3D0214View::CMy3D0214View()
  46. : CFormView(CMy3D0214View::IDD)
  47. {
  48. //{{AFX_DATA_INIT(CMy3D0214View)
  49. // NOTE: the ClassWizard will add member initialization here
  50. //}}AFX_DATA_INIT
  51. // TODO: add construction code here
  52. tbrIsstarted=0;
  53. m_Qcheckstate=0;
  54. m_Pcheckstate=0;
  55. m_Scheckstate=0;
  56. m_pInfoQueryDlg=NULL;
  57. }
  58. CMy3D0214View::~CMy3D0214View()
  59. {
  60. }
  61. void CMy3D0214View::DoDataExchange(CDataExchange* pDX)
  62. {
  63. CFormView::DoDataExchange(pDX);
  64. //{{AFX_DATA_MAP(CMy3D0214View)
  65. DDX_Control(pDX, IDC_SCENECONTROL1, m_Scontrol);
  66. //}}AFX_DATA_MAP
  67. }
  68. BOOL CMy3D0214View::PreCreateWindow(CREATESTRUCT& cs)
  69. {
  70. // TODO: Modify the Window class or styles here by modifying
  71. //  the CREATESTRUCT cs
  72. return CFormView::PreCreateWindow(cs);
  73. }
  74. void CMy3D0214View::OnInitialUpdate()
  75. {
  76. CFormView::OnInitialUpdate();
  77. GetParentFrame()->RecalcLayout();
  78. ResizeParentToFit();
  79. ///关联代码开始
  80. CWnd *pWndCal=GetDlgItem(IDC_SCENECONTROL1);
  81. LPUNKNOWN pUnk=pWndCal->GetControlUnknown();
  82. //获取IScenePtr控件接口
  83. pUnk->QueryInterface(IID_ISceneControl,(LPVOID *)&m_ipSceneControl);
  84. m_ipSceneControl->get_Scene(&m_ipScene);    //由SceneCpntrol得到Scene
  85. m_ipScene->get_Layer (2,&m_ipLayer);
  86. // m_ipSceneGrap->get_Scene(&m_ipScene);//Scene得到SceneGrap
  87. // m_ipSceneGrap->SetBackgroundColor(1.0,0.0,1.0);
  88. //关联代码结束
  89. LoadData();
  90. }
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CMy3D0214View printing
  93. BOOL CMy3D0214View::OnPreparePrinting(CPrintInfo* pInfo)
  94. {
  95. // default preparation
  96. return DoPreparePrinting(pInfo);
  97. }
  98. void CMy3D0214View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  99. {
  100. // TODO: add extra initialization before printing
  101. }
  102. void CMy3D0214View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  103. {
  104. // TODO: add cleanup after printing
  105. }
  106. void CMy3D0214View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
  107. {
  108. // TODO: add customized printing code here
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CMy3D0214View diagnostics
  112. #ifdef _DEBUG
  113. void CMy3D0214View::AssertValid() const
  114. {
  115. CFormView::AssertValid();
  116. }
  117. void CMy3D0214View::Dump(CDumpContext& dc) const
  118. {
  119. CFormView::Dump(dc);
  120. }
  121. CMy3D0214Doc* CMy3D0214View::GetDocument() // non-debug version is inline
  122. {
  123. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy3D0214Doc)));
  124. return (CMy3D0214Doc*)m_pDocument;
  125. }
  126. #endif //_DEBUG
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CMy3D0214View message handlers
  129. void CMy3D0214View::OnSize(UINT nType, int cx, int cy) 
  130. {
  131. CFormView::OnSize(nType, cx, cy);
  132. // TODO: Add your message handler code here
  133.     CWnd *  Control=GetDlgItem(IDC_SCENECONTROL1);
  134.     CRect  Controlrect;
  135. if(Control)
  136. {
  137.  Control->GetWindowRect(&Controlrect);
  138.  Control->MoveWindow(0,0,cx,cy);
  139. }
  140. }
  141. void CMy3D0214View::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
  142. {
  143. // TODO: Add your specialized code here and/or call the base class
  144. ::OleInitialize(NULL);//组件操作初始化  
  145.  
  146. if(!tbrIsstarted)
  147. {
  148. tbrIsstarted=1;
  149.     UpdateData(TRUE);
  150. CMainFrame *pFrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;//获取框架类指针
  151. LPUNKNOWN pUnk = m_Scontrol.GetControlUnknown();
  152.     LPDISPATCH pDisp = 0;
  153.     pUnk->QueryInterface(IID_IDispatch, (void **) &pDisp);
  154.     
  155. pFrm->m_tocdlg.m_TocControl.SetBuddyControl(pDisp);
  156. pFrm->m_tbr.SetBuddyControl(pDisp);
  157.     
  158. //pFrm->m_tocdlg.m_ipToolbarMenu->SetHook(pDisp);
  159.     pDisp->Release();
  160. CComBSTR bstrProgID;  
  161. CComVariant varProgID;  
  162. varProgID.vt = VT_BSTR;  
  163. // Add generic commands
  164. bstrProgID = _T("esri3DAnalyst.ControlsSceneOpenDocCommand");  
  165. varProgID.bstrVal = bstrProgID;
  166.     pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  167. bstrProgID = _T("esri3DAnalyst.ControlsSceneSceneToolbar");  
  168. varProgID.bstrVal = bstrProgID;
  169.     pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  170. // bstrProgID = _T("esriControlCommands.ControlsSelectTool");  
  171. // varProgID.bstrVal = bstrProgID;
  172.  //   pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  173. // bstrProgID = _T("ESRI_Scene.Fly");  
  174. // varProgID.bstrVal = bstrProgID;
  175. //    pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  176. // bstrProgID = _T("ESRI_Scene.ExpandFOV");  
  177. // varProgID.bstrVal = bstrProgID;
  178. //    pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  179. //     bstrProgID = _T("ESRI_Scene.FullExtent");  
  180. // varProgID.bstrVal = bstrProgID;
  181. //    pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  182. // bstrProgID = _T("ESRI_Scene.NarrowFOV");  
  183. // varProgID.bstrVal = bstrProgID;
  184. //    pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  185. // bstrProgID = _T("ESRI_Scene.Navigate");  
  186. // varProgID.bstrVal = bstrProgID;
  187. //    pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  188. // bstrProgID = _T("ESRI_Scene.Pan");  
  189. // varProgID.bstrVal = bstrProgID;
  190. //    pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  191. // bstrProgID = _T("ESRI_Scene.ZoomInOut");  
  192. // varProgID.bstrVal = bstrProgID;
  193. //    pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  194. // bstrProgID = _T("ESRI_Scene.ZoomOut");  
  195. // varProgID.bstrVal = bstrProgID;
  196. //    pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  197. //    bstrProgID = _T("ESRI_Scene.ZoomIn");  
  198. // varProgID.bstrVal = bstrProgID;
  199. //    pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  200. // bstrProgID = _T("ESRI_Scene.SelectFeatures");  
  201. // varProgID.bstrVal = bstrProgID;
  202.  //   pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  203. // bstrProgID = _T("ESRI_Scene.SetObserver");  
  204. // varProgID.bstrVal = bstrProgID;
  205. //    pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  206. // bstrProgID = _T("ESRI_Scene.TargetCenter");  
  207. // varProgID.bstrVal = bstrProgID;
  208. //    pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  209. // bstrProgID = _T("ESRI_Scene.TargetZoom");  
  210. // varProgID.bstrVal = bstrProgID;
  211. //    pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly); 
  212.    
  213. // bstrProgID = _T("TinBldgBurner.TinBuildingBurner");  
  214. // varProgID.bstrVal = bstrProgID;
  215. //   pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconAndText); 
  216. //bstrProgID = _T("prjSceneBackdrop.SceneBackdrop");  
  217. // varProgID.bstrVal = bstrProgID;
  218.  //   pFrm->m_tbr.AddItem(varProgID, -1, -1, VARIANT_FALSE, 0, esriCommandStyleIconAndText); 
  219. }
  220. CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  221. }
  222. void CMy3D0214View::LoadData()
  223. {
  224. CComBSTR SX_DATAFILE("DATE/Tin.sxd");
  225. //SX_DATAFILE ="DATE/Tin.sxd";
  226. VARIANT_BOOL bIsSceneDoc;
  227. m_ipSceneControl->CheckSxFile(SX_DATAFILE, &bIsSceneDoc);
  228. if (bIsSceneDoc)
  229. {
  230. m_ipSceneControl->LoadSxFile(SX_DATAFILE);
  231. m_ipSceneControl->get_Scene(&m_ipScene);
  232. m_ipScene->get_Layer(0,&m_ipLayer);
  233. }
  234. }
  235. void CMy3D0214View::OnFileExportMap() 
  236. {
  237. // TODO: Add your command handler code here
  238. CString strFilter="JPEG File(*.jpg)|*.jpg||";//设置打开文件的过滤条件
  239. CString strTitle="Export Map";
  240.         DWORD MAXFILE = 2412; // allocate enough memory space
  241.      CString strPath,strInit,strTemp;
  242.         CFileDialog pDlg(FALSE,".jpg",0,OFN_ALLOWMULTISELECT| OFN_EXPLORER | OFN_LONGNAMES|
  243.                         OFN_FILEMUSTEXIST |OFN_HIDEREADONLY,(LPCTSTR)strFilter, NULL);
  244.         //设置对话框               
  245.         pDlg.m_ofn.nMaxFile = MAXFILE; // set the buffer size        
  246.         pDlg.m_ofn.lpstrTitle=strTitle;
  247.         pDlg.m_ofn.lpstrInitialDir=strInit;
  248. char* buf = new char[MAXFILE];
  249. pDlg.m_ofn.lpstrFile = buf;
  250. pDlg.m_ofn.lpstrFile[0] = NULL;
  251. if(pDlg.DoModal()== IDOK)
  252. {
  253. POSITION pos = pDlg.GetStartPosition();
  254. strPath=pDlg.GetNextPathName(pos);
  255. AfxMessageBox(strPath);
  256. }
  257. ISceneGraphPtr ipSceneGrap(m_Scontrol.GetSceneGraph());
  258. ISceneViewerPtr  ipViewer;
  259. ipSceneGrap->get_ActiveViewer(&ipViewer);
  260. ipViewer->GetScreenShot(JPEG,(CComBSTR)strPath);
  261. }
  262. void CMy3D0214View::OnAddDemToScene() 
  263. {
  264. // TODO: Add your command handler code here
  265. ::OleInitialize(NULL);//组件操作初始化      
  266.  IGxDialogPtr ipGxDialog(CLSID_GxDialog);
  267.     //设置过滤器为SurfaceDatasets
  268.     IGxObjectFilterPtr ipGxObjectFilter(CLSID_GxFilterSurfaceDatasets);
  269.     HRESULT hr = ipGxDialog->putref_ObjectFilter(ipGxObjectFilter);
  270.     if(FAILED(hr)) return;
  271.     hr=ipGxDialog->put_Title( CComBSTR("选择一个DEM表面数据"));
  272.     if(FAILED(hr)) return;
  273. IEnumGxObjectPtr  ipEnumGxObject;
  274. VARIANT_BOOL bResult;
  275. hr=ipGxDialog->DoModalOpen(0,&ipEnumGxObject,&bResult);
  276. if(FAILED(hr)) return;
  277. if(bResult== VARIANT_FALSE) return;
  278. hr=ipEnumGxObject->Reset();
  279. if(FAILED(hr)) return;
  280. IGxObjectPtr ipGxObject;
  281. ipGxDialog->get_FinalLocation(&ipGxObject);
  282. while(!ipEnumGxObject->Next(&ipGxObject))
  283. {   
  284. IGxDatasetPtr ipGxDataset(ipGxObject);
  285. if(ipGxDataset!=0) 
  286. {
  287. IDatasetPtr ipDataset;
  288.     hr=ipGxDataset->get_Dataset(&ipDataset);
  289.     if(FAILED(hr))return;
  290.     IRasterDatasetPtr ipRasterDataset(ipDataset);
  291.     if(ipRasterDataset!=NULL)
  292. {
  293. CComBSTR bstrName;
  294. hr=ipRasterDataset->get_CompleteName(&bstrName);
  295. if(FAILED(hr)) return;
  296. //构造RASTER图层
  297. IRasterLayerPtr pRLayer(CLSID_RasterLayer);
  298. hr=pRLayer->CreateFromDataset(ipRasterDataset);
  299. hr=pRLayer->put_Name(CComBSTR("myRaster"));
  300. m_ipLayer=pRLayer;
  301. //增加RASTER图层
  302. //获取ISceneGrap接口指针
  303.         //m_ipSceneGrap=m_Scontrol.GetSceneGraph(); 
  304. //获取IScene接口指针   
  305. m_ipScene=m_Scontrol.GetScene();  
  306. hr=m_ipScene->AddLayer(m_ipLayer,VARIANT_TRUE);
  307. }
  308. ITinPtr ipTin(ipDataset);
  309. if ( ipTin!=NULL)
  310. {
  311. CComBSTR bstrName;
  312. hr=ipDataset->get_Name(&bstrName);
  313. if(FAILED(hr)) return;
  314. //构造TIN图层
  315. ITinLayerPtr pTLayer( CLSID_TinLayer);
  316. hr=pTLayer->putref_Dataset(ipTin);
  317. hr=pTLayer->put_Name(CComBSTR("myTin"));
  318. m_ipLayer=pTLayer;
  319. //增加TIN图层
  320.       
  321. m_ipScene=m_Scontrol.GetScene(); 
  322. // hr=m_ipSceneGrap->get_Scene(&m_ipScene);
  323. hr=m_ipScene->AddLayer(m_ipLayer,VARIANT_TRUE);
  324. }
  325. }
  326. }
  327. }
  328. void CMy3D0214View::OnCreateRasterIdw() 
  329. {
  330. // TODO: Add your command handler code here
  331. CDlgCreateRasterIDW theDlg;
  332. if(theDlg.DoModal()==IDOK) 
  333. {
  334. return;
  335. }
  336. }
  337. void CMy3D0214View::OnCreatedemTin() 
  338. {
  339. // TODO: Add your command handler code here
  340. CDlgCreateTINfromFeature theDLG;
  341. if(theDLG.DoModal()==IDOK)
  342. {
  343. }
  344. }
  345. bool CMy3D0214View::GetSceneFromView(IScene **ipScene)
  346. {
  347.  m_ipScene=m_Scontrol.GetScene(); 
  348.       *ipScene = m_ipScene;
  349.       if ( m_ipScene==NULL) return FALSE;
  350.      // (*ipScene)->AddRef();
  351.       return TRUE;
  352. }
  353. void CMy3D0214View::OnSetScene() 
  354. {
  355. // TODO: Add your command handler code here
  356. CDlgSetScene theDLG;
  357. if(theDLG.DoModal()==IDOK)
  358. {
  359. }
  360. }
  361. void CMy3D0214View::OnSetBaseheight() 
  362. {
  363. // TODO: Add your command handler code here
  364. CDlgBaseHeight theDlg;
  365. if(theDlg.DoModal()==IDOK) 
  366. {
  367. }
  368. }
  369. void CMy3D0214View::OnAddlayer() 
  370. {
  371. // TODO: Add your command handler code here
  372.    //打开对话框
  373.     ::OleInitialize(NULL);//组件操作初始化 
  374.     IGxDialogPtr ipGxDialog(CLSID_GxDialog);
  375. //Set the Filter to FeatureDatasets and FeatureClasses
  376. IGxObjectFilterPtr ipGxObjectFilter(CLSID_GxFilterFeatureClasses);
  377. HRESULT hr=ipGxDialog->putref_ObjectFilter(ipGxObjectFilter);
  378. if(FAILED(hr ))return;
  379.     hr=ipGxDialog->put_AllowMultiSelect(VARIANT_TRUE);
  380. if(FAILED(hr))return;
  381. hr = ipGxDialog->put_Title(CComBSTR("选择数据"));
  382. if(FAILED(hr)) return;
  383. IEnumGxObjectPtr ipEnumGxObject;
  384. VARIANT_BOOL bResult;
  385. hr=ipGxDialog->DoModalOpen(0,&ipEnumGxObject,&bResult);
  386. if(FAILED(hr)) return;
  387. if(bResult== VARIANT_FALSE)return;
  388. hr= ipEnumGxObject->Reset();
  389. if(FAILED(hr)) return;
  390. IGxObjectPtr ipGxObject;
  391. while(!ipEnumGxObject->Next(&ipGxObject))
  392. {
  393. IGxDatasetPtr ipGxDataset(ipGxObject);
  394. if(ipGxDataset!=0)
  395. {
  396. IDatasetPtr ipDataset;
  397. hr=ipGxDataset->get_Dataset(&ipDataset);
  398. if(FAILED(hr)) return;
  399. IFeatureClassPtr ipFeatureClass(ipDataset);
  400. IFeatureLayerPtr ipFeatureLayer(CLSID_FeatureLayer);
  401. hr=ipFeatureLayer->putref_FeatureClass(ipFeatureClass);
  402. if(FAILED(hr)) return;
  403. hr=ipFeatureLayer->put_Visible(VARIANT_FALSE);
  404. if(FAILED(hr)) return;
  405. CComBSTR bstrName;
  406. hr=ipFeatureClass->get_AliasName(&bstrName);
  407. if(FAILED(hr)) return;
  408. hr = ipFeatureLayer->put_Name(bstrName);
  409. if(FAILED(hr )) return;
  410. hr=ipFeatureLayer->put_Visible(VARIANT_TRUE);
  411. if(FAILED(hr)) return;
  412. ILayerPtr m_ipLayer=ipFeatureLayer;
  413. //hr=m_ipMap->AddLayer( m_ipLayer);
  414.                     m_ipScene=m_Scontrol.GetScene(); 
  415. //加到三维场景
  416.                      hr=m_ipScene->get_SceneGraph(&m_ipSceneGrap);
  417. if( FAILED(hr ))return;
  418. hr=m_ipScene->AddLayer(m_ipLayer,VARIANT_TRUE);
  419.      if( FAILED(hr ))return;
  420.      m_ipSceneGrap->RefreshViewers();
  421. }
  422. }
  423. }
  424. void CMy3D0214View::OnClassbreakrenderer() 
  425. {
  426. // TODO: Add your command handler code here
  427. CDlgClassBreakRenderer theDlg;
  428.      if(theDlg.DoModal()==IDOK)
  429. {
  430. }
  431. }
  432. BEGIN_EVENTSINK_MAP(CMy3D0214View, CFormView)
  433.     //{{AFX_EVENTSINK_MAP(CMy3D0214View)
  434. ON_EVENT(CMy3D0214View, IDC_SCENECONTROL1, 1 /* OnMouseDown */, OnOnMouseDownScenecontrol1, VTS_I4 VTS_I4 VTS_I4 VTS_I4)
  435. ON_EVENT(CMy3D0214View, IDC_SCENECONTROL1, 3 /* OnMouseMove */, OnOnMouseMoveScenecontrol1, VTS_I4 VTS_I4 VTS_I4 VTS_I4)
  436. ON_EVENT(CMy3D0214View, IDC_SCENECONTROL1, 2 /* OnMouseUp */, OnOnMouseUpScenecontrol1, VTS_I4 VTS_I4 VTS_I4 VTS_I4)
  437. //}}AFX_EVENTSINK_MAP
  438. END_EVENTSINK_MAP()
  439. void CMy3D0214View::OnInformationQuery() 
  440. {
  441. // TODO: Add your command handler code here
  442.  if(!m_Qcheckstate)
  443.     {
  444. m_Qcheckstate=1;
  445. m_pInfoQueryDlg=new CDlgInfoQuery(this);
  446. m_pInfoQueryDlg->Create(IDD_DLG_INFO_QUERY);
  447. m_pInfoQueryDlg->ShowWindow(SW_SHOW);
  448.   }
  449.  else
  450. {
  451. m_Qcheckstate=0;
  452. if(m_pInfoQueryDlg!=NULL)
  453. {
  454. delete m_pInfoQueryDlg;    
  455. }
  456. }
  457. }
  458. void CMy3D0214View::OnUpdateInformationQuery(CCmdUI* pCmdUI) 
  459. {
  460. // TODO: Add your command update UI handler code here
  461. pCmdUI->SetCheck(m_Qcheckstate);
  462. }
  463. void CMy3D0214View::OnOnMouseDownScenecontrol1(long button, long shift, long x, long y) 
  464. {
  465. // TODO: Add your control notification handler code here
  466. HRESULT hr=m_ipScene->get_SceneGraph(&m_ipSceneGrap);//获取SceneGraph
  467.     if(m_ipSceneGrap==NULL)
  468.     {
  469.         AfxMessageBox("no scene!");
  470.             return;
  471.     }
  472.     if(m_Qcheckstate==1)
  473.     {
  474.     m_Scontrol.SetMousePointer(esriPointerCrosshair);
  475. //ISceneGraphPtr pSG(m_ipSceneGrap);
  476. ISceneViewerPtr pViewer;
  477. m_ipSceneGrap->get_ActiveViewer(&pViewer);
  478. //声明输出变量
  479. IPointPtr pPoint;
  480. IUnknownPtr pOwner;
  481. IUnknownPtr pObject;
  482. //当点击鼠标时执行Locate函数,该函数返回一个点击处的3D点、
  483. //特征对象和包含该对象的图层
  484. m_ipSceneGrap->Locate(pViewer,
  485.                   x,
  486.   y,
  487.   esriScenePickGeography,
  488.   VARIANT_TRUE,
  489.   &pPoint,
  490.   &pOwner,
  491.   &pObject);
  492. //报告结果
  493. if(pPoint==NULL) return;
  494. //设置点击效果
  495.     m_ipScene=m_Scontrol.GetScene(); //由SceneCpntrol得到Scene
  496. m_ipSceneGrap->get_Scene(&m_ipScene);//Scene得到SceneGrap
  497. IClonePtr ppFlashPoint;
  498. IClonePtr pClone(pPoint);
  499. pClone->Clone(&ppFlashPoint);
  500. IPointPtr pFlashPoint(ppFlashPoint);
  501. IDisplay3DPtr pDisplay(m_ipSceneGrap);
  502. pDisplay->FlashLocation(pFlashPoint);
  503. // double x1,y1,z1;
  504. // pPoint->get_X(&x1);
  505. // pPoint->get_Y(&y1);
  506. //  pPoint->get_Z(&z1);
  507. // CString str;
  508. // str.Format("(%f,%f)n Height=%f",x1,y1,z1);
  509. // AfxMessageBox(str); 
  510. pPoint->get_X(&(m_pInfoQueryDlg->m_edit_X));
  511. pPoint->get_Y(&(m_pInfoQueryDlg->m_edit_Y));
  512.   pPoint->get_Z(&(m_pInfoQueryDlg->m_edit_Z));
  513. CString strX,strY,strZ;
  514. strX.Format("%f",m_pInfoQueryDlg->m_edit_X);
  515. strY.Format("%f",m_pInfoQueryDlg->m_edit_Y);
  516. strZ.Format("%f",m_pInfoQueryDlg->m_edit_Z);
  517. m_pInfoQueryDlg->m_control_X.SetWindowText(strX);
  518. m_pInfoQueryDlg->m_control_Y.SetWindowText(strY);
  519. m_pInfoQueryDlg->m_control_Z.SetWindowText(strZ);
  520. }
  521. else
  522. {
  523. m_Scontrol.SetMousePointer(0);
  524. }
  525. if(m_Pcheckstate==1)
  526. DoRealGraphWork(x, y);
  527. }
  528. }
  529. void CMy3D0214View::OnOnMouseMoveScenecontrol1(long button, long shift, long x, long y) 
  530. {
  531. // TODO: Add your control notification handler code here
  532. if(m_Qcheckstate==1)
  533. {
  534. //改变鼠标样式
  535. m_Scontrol.SetMousePointer(esriPointerCrosshair);
  536. }
  537. else
  538. {
  539. m_Scontrol.SetMousePointer(0); 
  540. }
  541. }
  542. void CMy3D0214View::OnCreateSlop() 
  543. {
  544. // TODO: Add your command handler code here
  545. CDlgSlope theDlg;
  546.     if(theDlg.DoModal()==IDOK)
  547. {
  548. }
  549. }
  550. void CMy3D0214View::OnViewshed() 
  551. {
  552. // TODO: Add your command handler code here
  553. CDlgViewshed theDlg;
  554. if(theDlg.DoModal()==IDOK)
  555. {
  556. }
  557. }
  558. void CMy3D0214View::OnLineofsightprofile() 
  559. {
  560. // TODO: Add your command handler code here
  561.  if(!m_Pcheckstate)
  562.     {
  563. m_Pcheckstate=1;
  564. m_pDlg=new CDlgProfileGraph(this);
  565. m_pDlg->Create(IDD_DLG_PROFILE_GRAPH);
  566. m_pDlg->ShowWindow(SW_SHOW);
  567.   }
  568. else
  569. {
  570. m_Pcheckstate=0;
  571. if(m_pDlg!=NULL)
  572. {
  573. delete m_pDlg;    
  574. }
  575. }
  576. }
  577. void CMy3D0214View::OnUpdateLineofsightprofile(CCmdUI* pCmdUI) 
  578. {
  579. // TODO: Add your command update UI handler code here
  580. pCmdUI->SetCheck(m_Pcheckstate);
  581. }
  582. CString CMy3D0214View::FindBasename(CString filename)
  583. {
  584.     CString basename;
  585.    int pos=filename.ReverseFind('.');
  586.    if ( pos==-1)return filename; //没有'.' 
  587.    basename=filename.Left(pos);
  588.    return basename;
  589. }
  590. BOOL CMy3D0214View::DeleteSHP(CString pathname,CString filename)
  591. { CFileFind finder;
  592. CString strWildcard(pathname);
  593.     CString basename= FindBasename(filename);
  594.     strWildcard +=_T("\"+basename+".*");
  595. BOOL bWorking=finder.FindFile(strWildcard);
  596. while(bWorking)
  597. {      
  598. bWorking=finder.FindNextFile(); 
  599. if(!finder.IsDots())
  600. if(!finder.IsDirectory())
  601. {
  602. CString str=finder.GetFilePath();
  603. CString fileExtension;
  604. fileExtension= str.Right(3);
  605. if(fileExtension=="shp"||             
  606. fileExtension=="shx"||  
  607. fileExtension=="dbf"||   
  608. fileExtension=="sbx"||    
  609. fileExtension=="sbn") 
  610. {
  611. DeleteFile(str);
  612. }
  613.  
  614. }
  615. finder.Close();
  616. return TRUE;
  617. }
  618. int CMy3D0214View::IsDirectory (CString pathname )//**判断文件或文件夹是否存在
  619. {
  620. DWORD  dwFlag=GetFileAttributes(pathname);
  621. if( 0xFFFFFFFF==dwFlag)
  622. return 0 ;//不存在
  623. else
  624. {
  625. if(FILE_ATTRIBUTE_DIRECTORY&dwFlag)
  626. return 1;//是文件夹
  627.         else
  628.             return -1; //是文件
  629. }
  630.      
  631. CString CMy3D0214View::GetCurrentDir()
  632. {
  633.     TCHAR cCurDir[100];
  634.     CString strCurDir;
  635. ::GetCurrentDirectory(256,cCurDir);
  636. strCurDir=cCurDir;
  637.     return strCurDir;
  638. BOOL CMy3D0214View::MakeProfileChart(CString sDir,CString sFileName,CString sGraphTitle,CString sGraphSubTitle)
  639. {
  640.     HRESULT hr;
  641.     //打开指定的featurec}}ss
  642.     IWorkspaceFactoryPtr pFact(CLSID_ShapefileWorkspaceFactory);
  643.     IWorkspacePtr pWorkspace;
  644.     hr=pFact->OpenFromFile((CComBSTR)sDir,NULL,&pWorkspace);
  645.     if(FAILED(hr ))return FALSE; 
  646. IFeatureWorkspacePtr pFeatws(pWorkspace);
  647. IFeatureClassPtr pFClass;
  648. hr= pFeatws->OpenFeatureClass((CComBSTR)sFileName,&pFClass);
  649. if(FAILED(hr ))return FALSE;
  650. IFeatureLayerPtr pFLayer(CLSID_FeatureLayer );
  651. hr= pFLayer->putref_FeatureClass(pFClass);
  652. //QI table
  653. ITablePtr pTable(pFLayer);
  654. if(pTable==NULL){AfxMessageBox("Table QI failed!");return FALSE;}
  655. //创建一个新的图表对象
  656. IDataGraphPtr pDataGraph(CLSID_DataGraph);
  657. if(m_pDlg==NULL)return FALSE;
  658. if(FAILED(hr=pDataGraph->Attach((OLE_HANDLE)m_pDlg->m_static_ProfileGraph.m_hWnd))) return FALSE;
  659. //设置默认的表格
  660. hr=pDataGraph->putref_Table(pTable);
  661. //为datagraph设置字段
  662. hr=pDataGraph->put_FieldSet1(CComBSTR("Z"));
  663. hr=pDataGraph->put_FieldSet2(CComBSTR("M"));
  664. hr=pDataGraph->put_Name((CComBSTR)sGraphTitle);
  665. //设置datagraph属性
  666. IDataGraphPropertiesPtr pDataGraphProp(pDataGraph);
  667. //将图表类型设置为二维简单线
  668. hr=pDataGraphProp->put_GraphType(esriDataGraphTypeLine);
  669. hr=pDataGraphProp->put_GraphSubtype(esriDataGraphSubtypeLine2DSimple);
  670. hr=pDataGraphProp->put_ShowXAxisLabels(VARIANT_TRUE);
  671. hr=pDataGraphProp->put_ShowLegend(VARIANT_FALSE);
  672. hr=pDataGraphProp->put_Title(CComBSTR(sGraphTitle));
  673. hr=pDataGraphProp->put_SubTitle((CComBSTR)sGraphSubTitle);
  674.     hr=pDataGraph->Reload();
  675.     hr=pDataGraph->Draw();
  676.     hr=pDataGraph->Detach();//释放
  677.     return TRUE;
  678. void CMy3D0214View::DoRealGraphWork(long xPos,long yPos)
  679. {
  680. HRESULT hr;
  681. m_ipScene=m_Scontrol.GetScene(); //由SceneCpntrol得到Scene
  682. hr=m_ipSceneGrap->get_Scene(&m_ipScene);//Scene得到SceneGrap
  683.     ISceneGraphPtr pSG(m_ipSceneGrap);
  684. ISceneViewerPtr pViewer;
  685. m_ipSceneGrap->get_ActiveViewer(&pViewer);//SceneGrape得到SceneViewer
  686. IPointPtr pPnt;
  687. IUnknownPtr pOwner;
  688. IUnknownPtr pObject;
  689. hr=pSG->Locate(pViewer,xPos,yPos,
  690.                     esriScenePickAll,
  691.                     VARIANT_TRUE,
  692.                     &pPnt,
  693.                     &pOwner,
  694.                     &pObject);
  695. if(FAILED(hr )){AfxMessageBox("Famed");return;}
  696. if(pPnt==NULL){return;}
  697.     if(pOwner!= m_ipLayer){AfxMessageBox("WRONG LAYER!");return;}
  698. IClonePtr ppFlashPoint;
  699. IClonePtr pClone(pPnt);
  700. pClone->Clone(&ppFlashPoint);
  701. IPointPtr pFlashPoint( ppFlashPoint);
  702. //考虑拉伸系数影响
  703. //pFlashPoint. Z=pFlashPoint. Z/pSG. VerticalExaggetion
  704. ISpatialReferencePtr ipSR;
  705. m_ipScene->get_SpatialReference(&ipSR);
  706. pFlashPoint->putref_SpatialReference(ipSR);
  707. //设置点击效果
  708. IDisplay3DPtr pDisplay(pSG);
  709. pDisplay->FlashLocation(pFlashPoint);
  710. if(m_pScenePoints==NULL)
  711. {
  712.  m_pScenePoints. CreateInstance(CLSID_Polyline);
  713.  IGeometryPtr pGeom(m_pScenePoints);    
  714.  pGeom->putref_SpatialReference(ipSR);
  715. }
  716.  m_pScenePoints->AddPoint(pPnt);
  717.  long pcount;
  718.  m_pScenePoints->get_PointCount(&pcount);
  719.  IPolylinePtr pPolyline;
  720.  IClonePtr pCPolyline;
  721.  if(pcount==2)
  722.  {    
  723. pClone=m_pScenePoints;    
  724. pClone->Clone(&pCPolyline);    
  725. pPolyline=pCPolyline;
  726.  }
  727.  if(pPolyline!=NULL)
  728.  {
  729. //准备剖面图  
  730. ISurfacePtr m_ipSurface;  
  731. IRasterLayerPtr ipRLayer(m_ipLayer);  
  732. ITinLayerPtr ipTLayer( m_ipLayer);
  733. if(ipRLayer==NULL&&ipTLayer==NULL){AfxMessageBox( "投有表面数据!");return;}
  734. if(ipRLayer!=NULL)
  735. {
  736. IRasterPtr ipRaster;    
  737. IRasterBandPtr pRasterBand;
  738. hr=ipRLayer->get_Raster( &ipRaster);   
  739. if(FAILED(hr))   return;
  740. IRasterBandCollectionPtr pRasterBands(ipRaster);
  741. hr = pRasterBands->Item(0,&pRasterBand);    
  742. if(FAILED(hr ))return;    
  743. IRasterSurfacePtr pRasterSurface(CLSID_RasterSurface);    
  744. hr=pRasterSurface->put_RasterBand(pRasterBand);
  745. if(FAILED(hr )) return;    
  746. m_ipSurface=pRasterSurface;
  747. }
  748. if(ipTLayer!=NULL)
  749. {   
  750. ITinPtr ipT;   
  751. hr=ipTLayer->get_Dataset(&ipT);    
  752. m_ipSurface = ipT;
  753. }
  754.  
  755. IGeometryPtr pInshape(pPolyline);
  756. IGeometryPtr pOutshape;
  757. hr=m_ipSurface->InterpolateShape(pInshape,&pOutshape);
  758. //将2维图形插入到3维表面
  759. if(FAILED(hr)) return;   
  760. //显示
  761. IElementPtr pElem(CLSID_LineElement);
  762. //使用IElement接口设置LineElement的几何图形。
  763. hr=pElem->put_Geometry(pOutshape);
  764. //使用ILineElement接口设置Symbol属性
  765. ILineElementPtr pElemLine(pElem);
  766. //创建一个RGB颜色
  767. IRgbColorPtr pRGB(CLSID_RgbColor);
  768. pRGB->put_Red(100);pRGB->put_Green(0);pRGB->put_Blue(100);
  769. //创建一个SimpleLineSymbol,设置它的颜色、样式
  770. ISimpleLineSymbolPtr pSLnSym(CLSID_SimpleLineSymbol);
  771. pSLnSym->put_Color(pRGB);
  772. pSLnSym->put_Style(esriSLSSolid);
  773. pElemLine->put_Symbol(pSLnSym);
  774. IGraphicsLayerPtr pGLayer;
  775. hr=m_ipScene->get_BasicGraphicsLayer( &pGLayer);
  776. IGraphicsContainer3DPtr pGCon3D(pGLayer);
  777. hr=pGCon3D->AddElement((IElementPtr) pElemLine);
  778. IGraphicsSelectionPtr pGS(pGCon3D);
  779. hr=pGS->UnselectAllElements();
  780.   hr=pGS->SelectElement((IElementPtr) pElemLine);
  781. m_ipSceneGrap->RefreshViewers();
  782. //制作剖面图
  783. IPointCollectionPtr pPointZGeom(pOutshape);
  784. if(pPointZGeom==NULL ){AfxMessageBox("No geometry found.");return;}
  785. IMAwarePtr pMA(pPointZGeom);//M 属性操作接口
  786. hr=pMA->put_MAware(VARIANT_TRUE);
  787. if(FAILED(hr))return;
  788. IZAwarePtr pZA(pPointZGeom);//Z 属性操作接口
  789. hr=pZA->put_ZAware(VARIANT_TRUE);
  790. if(FAILED(hr ))return;
  791. IMSegmentationPtr pMSeg(pPointZGeom);
  792. //IMSegmentation: access to members for defining an M-based linear
  793. //coordinate system on a polyline or polygon
  794. //距离储存在M属性中
  795.     if(FAILED(pMSeg->SetMsAsDistance(VARIANT_FALSE)))return;
  796. //Sets the M values to the cumulative length from the origin of the geometry
  797. IEnvelopePtr pEnv;
  798. if(FAILED(pOutshape->get_Envelope(&pEnv)))return;
  799. double xmin;
  800. hr=pEnv->get_XMin(&xmin);
  801. ISpatialReferencePtr pSR(CLSID_UnknownCoordinateSystem);
  802. //准备创建shapefile
  803. CString sDir=GetCurrentDir();
  804. IWorkspaceFactoryPtr shapeWorkspaceFactory(CLSID_ShapefileWorkspaceFactory);
  805.           IPropertySetPtr connectionProperties(CLSID_PropertySet);
  806. CString Name="DATABASE";
  807. CComBSTR bstr( sDir);
  808. CComVariant pValue(bstr);
  809. if(FAILED(connectionProperties->SetProperty(( CComBSTR)Name,pValue)))return;
  810. CString sFileName="Profile";
  811. IWorkspacePtr pshapeWorkspace;
  812. hr=shapeWorkspaceFactory->Open(connectionProperties,
  813.                                                         NULL,
  814.                                                         &pshapeWorkspace);
  815. IFeatureWorkspacePtr shapeWorkspace(pshapeWorkspace);
  816. if(shapeWorkspace!=NULL)
  817. {
  818. IFeatureClassPtr pFeatCls;
  819. IFeatureBufferPtr pBuffer;
  820. IFeatureCursorPtr pCursor;
  821. //创建基本字段
  822. IFieldsPtr pFlds(CLSID_Fields);
  823. IFieldsEditPtr pFldsEdt(pFlds);
  824. IFieldPtr pFld(CLSID_Field);
  825. IFieldEditPtr pFldEdt(pFld);
  826. IGeometryDefEditPtr pGeoDef(CLSID_GeometryDef);
  827. hr=pGeoDef->put_GeometryType(esriGeometryPoint);
  828. hr=pGeoDef->put_HasM(VARIANT_TRUE);
  829. hr=pGeoDef->put_HasZ(VARIANT_TRUE);
  830. hr=pGeoDef->putref_SpatialReference(pSR);
  831. //添加oid字段
  832. hr=pFldEdt.CreateInstance(CLSID_Field);
  833. hr=pFldEdt->put_Name(( CComBSTR)("OID"));
  834. hr=pFldEdt->put_Type(esriFieldTypeOID);
  835. hr=pFldsEdt->AddField(pFldEdt);
  836. //添加Geometry字段
  837. hr=pFldEdt.CreateInstance(CLSID_Field);
  838. hr=pFldEdt->put_Name(CComBSTR("Shape"));
  839. hr=pFldEdt->put_IsNullable(VARIANT_TRUE);
  840. hr=pFldEdt->put_Type(esriFieldTypeGeometry);
  841. hr=pFldEdt->putref_GeometryDef(pGeoDef);
  842. hr=pFldsEdt->AddField(pFldEdt);
  843.   //开始创建shapefile
  844.                  if(IsDirectory(sDir+"\"+sFileName+".shp")==-1)
  845. {
  846. if(!DeleteSHP(sDir,sFileName)) return;
  847. }
  848. hr=shapeWorkspace->CreateFeatureClass(
  849.                                         (CComBSTR)(sFileName),
  850.                                          pFldsEdt,
  851.                                          NULL,
  852.                                          NULL,
  853.                                          esriFTSimple,
  854.                                          CComBSTR("Shape"),
  855.                                          CComBSTR(""),
  856.                                           &pFeatCls);
  857. if(FAILED(hr)){AfxMessageBox("创建临时shp失败!");   return;}
  858.  
  859. //添加两个字段:M和Z
  860. IFieldEditPtr pFieldEdit(CLSID_Field);
  861. hr=pFieldEdit->put_Name((CComBSTR)("M"));
  862. hr=pFieldEdit->put_IsNullable(VARIANT_TRUE);
  863. hr=pFieldEdit->put_Type(esriFieldTypeDouble);
  864. hr=pFieldEdit->put_Length(8);
  865. IFieldPtr pField(pFieldEdit);
  866. hr=pFeatCls->AddField(pField);
  867. hr=pFieldEdit.CreateInstance(CLSID_Field);
  868. hr=pFieldEdit->put_Name((CComBSTR)("Z"));
  869. hr=pFieldEdit->put_IsNullable(VARIANT_TRUE);
  870. hr=pFieldEdit->put_Type(esriFieldTypeDouble);
  871. hr=pFieldEdit->put_Length(8);
  872. pField=pFieldEdit;
  873. hr=pFeatCls->AddField(pField);
  874.   //添加点要素
  875. hr=pFeatCls->Insert(VARIANT_TRUE,&pCursor);  
  876. hr=pFeatCls->CreateFeatureBuffer(&pBuffer);   
  877. long j;long count;
  878. pPointZGeom->get_PointCount(&count);
  879. for(j=0;j<count;j++)
  880. {   
  881. IPointPtr pPoint;    
  882. hr =pPointZGeom->get_Point(j,&pPoint);    
  883. IGeometryPtr pGeo(pPoint);    
  884. hr=pBuffer->putref_Shape(pGeo);    
  885. double pM,pZ;    
  886. hr=pPoint->get_M(&pM);    
  887. hr=pPoint->get_Z(&pZ);                        
  888. VARIANT tempM;    
  889. tempM.vt=VT_R8;    
  890. tempM.dblVal=pM;    
  891. VARIANT tempZ;    
  892. tempZ.vt=VT_R8;    
  893. tempZ.dblVal=pZ;    
  894. hr=pBuffer->put_Value(3,tempM);    
  895. hr=pBuffer->put_Value(4,tempZ); 
  896. CComVariant ret ;
  897. hr=pCursor->InsertFeature(pBuffer,&ret);//书中参数为NULL,不能保存
  898. //将要素加入到要素集的缓存中,当所有的要素都完成缓存写入,
  899. //最后用 FLUSH一次写入数据库或文件,可以提高写入速度
  900. if (FAILED(hr))     
  901. {  AfxMessageBox("Couldn't insert featuren");  return ; }
  902. }
  903.                    hr= pCursor->Flush();//将缓存中的数据写入
  904.  pFeatCls=NULL;
  905. }
  906. shapeWorkspaceFactory=NULL;
  907. pshapeWorkspace=NULL;
  908. shapeWorkspace=NULL;
  909. CString graphTitle="Elevation-Profile";
  910. CString graphSubTitle="ZvsM";
  911. //**生成剖面图
  912. MakeProfileChart(sDir,sFileName,graphTitle,graphSubTitle);
  913. if(IsDirectory(sDir+CString("\")+sFileName+CString(".shp"))==-1) 
  914. {
  915.     
  916. if(!DeleteSHP(sDir,sFileName)) return;
  917.                          
  918. m_pScenePoints=NULL;
  919.             
  920. }
  921. }
  922. }
  923. void CMy3D0214View::OnCreateContour() 
  924. {
  925. // TODO: Add your command handler code here
  926. CDlgCreateContour theDlg;
  927. if(theDlg.DoModal()== IDOK)
  928. {
  929. }
  930. }
  931. void CMy3D0214View::OnUpdateIndicatorDEMO(CCmdUI *pCCmdUI)
  932. {
  933. //pCCmdUI->Enable(TRUE);
  934. pCCmdUI->SetRadio(TRUE);
  935. pCCmdUI->SetText("   Hunan University Of Science and Technology   ");
  936. }
  937. void CMy3D0214View::OnUpdateIndicatorAUTHOR(CCmdUI *pCCmdUI)
  938. {
  939. //pCCmdUI->Enable(TRUE);
  940. pCCmdUI->SetRadio(TRUE);
  941. pCCmdUI->SetText(" Author:于智慧");
  942. }
  943. void CMy3D0214View::OnSelectfeatrues() 
  944. {
  945. // TODO: Add your command handler code here
  946. if(!m_Scheckstate)
  947. m_Scheckstate=1;
  948. else
  949. m_Scheckstate=0;
  950. }
  951. void CMy3D0214View::OnUpdateSelectfeatrues(CCmdUI* pCmdUI) 
  952. {
  953. // TODO: Add your command update UI handler code here
  954. pCmdUI->SetRadio(m_Scheckstate);
  955. }
  956. void CMy3D0214View::OnOnMouseUpScenecontrol1(long button, long shift, long x, long y) 
  957. {
  958. // TODO: Add your control notification handler code here
  959. if(m_Scheckstate)
  960. {
  961. //获取IScene接口指针   
  962. m_ipScene=m_Scontrol.GetScene();
  963. IElementPtr ipElement;
  964. IElementPtr selElmt;
  965. IPointPtr ipPoint;
  966. IUnknownPtr ipOwner;
  967. IUnknownPtr ipObject;
  968. // selElmt = SelectElement(m_ipScene, x, y);
  969. // selElmt->get_Geometry()
  970. //
  971. // IMarker3DSymbol m_ipMS;
  972. //
  973. // IMarkerElementPtr pME;
  974. //    Set Posation = selElmt.Geometry  '  pMks.Shape
  975. //    Set pME = selElmt
  976. //    Set pMS = pME.Symbol
  977. //    Dim pMP As IMarker3DPlacement
  978. //    Set pMP = pMS
  979. //    Dim outGem As IGeometry
  980. //    pMP.ApplyToPoint Posation, outGem
  981. //    Set selMP = outGem
  982. //    
  983. //     Dim pElemProps As IElementProperties: Set pElemProps = selElmt
  984. //     
  985. //    MsgBox pElemProps.Name
  986. //    Debug.Print outGem.Envelope.zmax - outGem.Envelope.zmin
  987. }
  988. }