目前AE C++的开发资料比较少,即使是C#的资料,也不尽如人意。考虑到国内目前做C++ ArcGIS engine开发甚至Qt + AE的人比较少,对于C#+AE出身的人,刚开始尝试QT +AE可能会困难重重,因此总结一下两者之间的接口调用差异,希望能对大家有所帮助。
获取接口
[C#]
IGlobeControl pGlobeCtr = axGlobeControl1.Object as IGlobeControl; pGlobeCtr.Load3dFile(Application.StartupPath + "..\\..\\..\\Test3d.3dd");[C++ Qt]
IGlobeControl *m_ipGlobeControl; HRESULT hr = this->queryInterface(IID_IGlobeControl,reinterpret_cast<void**>(&m_ipGlobeControl)); m_ipGlobeControl->Load3dFile(L"Test3d.3dd");
IGlobeCamera pGlobeCamera = axGlobeControl1.GlobeCamera; ICamera pCamera = pGlobeCamera as ICamera; //具有继承关系的接口,直接转换 IGlobeDisplay pGlobeDisplay = axGlobeControl1.GlobeDisplay; IGlobe = axGlobeControl1.Globe; if (pGlobeCamera.OrientationMode == esriGlobeCameraOrientationMode.esriGlobeCameraOrientationGlobal) { //... double zt1 = zt * (UnitSacleToMeter(axGlobeControl1.Globe.GlobeUnits)); //... }
IGlobeCamera *pGlobeCamera; HRESULT hr = m_ipGlobeControl->get_GlobeCamera(&pGlobeCamera); ICamera *pCamera = reinterpret_cast<ICamera*>(pGlobeCamera); //需要强制类型转换 IGlobeDisplay *pGlobeDispaly; //通过指针,获取对GlobeDisplay的引用 hr = m_ipGlobeControl->get_GlobeDisplay(&pGlobeDispaly); IGlobe *pGlobe; hr = m_ipGlobeControl->get_Globe(&pGlobe); //IGlobePtr pGlobe; //也可以用智能指针来实现 //hr = m_ipGlobeControl->get_Globe(&pGlobe); esriGlobeCameraOrientationMode pMode; //而这个地方需要传入一个已经分配好地址 hr= pGlobeCamera->get_OrientationMode(&pMode); if(pMode == esriGlobeCameraOrientationMode::esriGlobeCameraOrientationGlobal) { //... esriUnits pUnits; pGlobe->get_GlobeUnits(&pUnits); qreal zt1 = zt * unitScaleToMeter(pUnits); //... }
ICommand command = new ControlsGlobeNavigateToolClass(); // new ControlsGlobeZoomInOutToolClass(); command.OnCreate(axGlobeControl1.Object); if (command.Enabled == true) { axGlobeControl1.CurrentTool = (ITool)command; }
ICommandPtr cmd(CLSID_ControlsGlobeNavigateTool); //CLSID_ControlsGlobeZoomInOutTool IDispatchPtr disp; m_ipGlobeControl->get_Object(&disp); cmd->OnCreate(disp); VARIANT_BOOL bEnable; hr = cmd->get_Enabled(&bEnable); if(bEnable) { m_ipGlobeControl->putref_CurrentTool(IToolPtr(cmd)); }