giswoduxing
路人甲
路人甲
  • 注册日期2009-06-15
  • 发帖数4
  • QQ
  • 铜币126枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1418回复:0

AO加载CAD

楼主#
更多 发布于:2009-09-18 15:37
<P>用AO打开CAD文件,代码如下,但打开后只有与MapControl相关联的TOCControl中有图层显示,但MapControl中为何没数据显示?</P>
<P>void CCADFileView::OnFileOpen() <BR>{<BR> // TOD Add your command handler code here<BR> CString strFilter;<BR> strFilter="Auto CAD(*.dwg)|*.dwg|Auto CAD(*.dxf)|.dxf||";<BR> CFileDialog fileDialog(TRUE,NULL,NULL,OFN_ALLOWMULTISELECT|OFN_HIDEREADONLY|<BR>  OFN_FILEMUSTEXIST,(LPCTSTR)strFilter,NULL);<BR> CString strTitle="Select CAD Files";<BR> fileDialog.m_ofn.lpstrTitle=strTitle;<BR> CString strInit("C:\\");<BR> fileDialog.m_ofn.lpstrInitialDir=strInit;<BR> if(IDCANCEL==fileDialog.DoModal()) return;<BR> CString strPath,strExt;<BR> strPath=fileDialog.GetPathName();<BR> strExt=fileDialog.GetFileExt();<BR> if(!(strExt.IsEmpty()))<BR> {<BR>  int ncount;<BR>  ncount=strPath.ReverseFind('\\');<BR>  strPath=strPath.Left(ncount);<BR> }</P>
<P> IWorkspaceFactoryPtr ipWorkspaceFactory(CLSID_CadWorkspaceFactory);<BR> IWorkspacePtr ipWorkspace;<BR> HRESULT hr=ipWorkspaceFactory->OpenFromFile((_bstr_t)strPath,NULL,;ipWorkspace);<BR> if(FAILED(hr))  return;<BR> <BR> IFeatureWorkspacePtr ipFeatureWorkspace(ipWorkspace);<BR> IFeatureLayerPtr ipFeatureLayer;<BR> IFeatureDatasetPtr ipFeatureDataset;<BR> IFeatureClassPtr ipFeatureClass;</P>
<P> POSITION ps;<BR> ps=fileDialog.GetStartPosition();<BR> if(ps!=NULL)<BR> {<BR>  CString strFullPath=fileDialog.GetNextPathName(ps);<BR>  CString strName=strFullPath.Right(strFullPath.GetLength()-strPath.GetLength()-1);<BR>  hr=ipFeatureWorkspace->OpenFeatureDataset((_bstr_t)strName,;ipFeatureDataset);<BR>  if(FAILED(hr))  return;<BR>  IFeatureClassContainerPtr ipFeatureClassContainer(ipFeatureDataset);<BR>  long iTemp;<BR>  ipFeatureClassContainer->get_ClassCount(;iTemp);<BR>  enum esriFeatureType featuretype;<BR>  BSTR aliasname;<BR>  int i;<BR>  for(i=0;i<iTemp;i++)<BR>  {<BR>   hr=ipFeatureClassContainer->get_Class(i,;ipFeatureClass);<BR>   if(FAILED(hr))  return;<BR>   hr=ipFeatureClass->get_FeatureType(;featuretype);<BR>   if(FAILED(hr))  return;<BR>   if(featuretype==esriFTCoverageAnnotation)<BR>   {<BR>    CoCreateInstance(CLSID_CadAnnotationLayer,NULL,CLSCTX_ALL,IID_IFeatureLayer,<BR>     (void**);ipFeatureLayer);<BR>    if(ipFeatureLayer==NULL)  return;<BR>   }<BR>   else<BR>   {<BR>    CoCreateInstance(CLSID_CadFeatureLayer,NULL,CLSCTX_ALL,IID_IFeatureLayer,<BR>     (void**);ipFeatureLayer);<BR>    if(ipFeatureLayer==NULL) return;<BR>   }<BR>   ipFeatureClass->get_AliasName(;aliasname);<BR>   ipFeatureLayer->put_Name(aliasname);<BR>   ipFeatureLayer->putref_FeatureClass(ipFeatureClass);<BR>   hr=m_ipMap->AddLayer(ipFeatureLayer);<BR>   if(FAILED(hr))  return;<BR>  }<BR> }<BR> IActiveViewPtr ipActive(m_ipMap);<BR> ipActive->Refresh();<BR>}<BR></P>
喜欢0 评分0
游客

返回顶部