ConvDwg2Kmg.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:5k
源码类别:

CAD

开发平台:

Visual C++

  1. // ConvDwg2Kmg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "FileSwitch.h"
  5. #include "ConvDwg2Kmg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CConvDwg2Kmg
  13. IMPLEMENT_DYNCREATE(CConvDwg2Kmg, CCmdTarget)
  14. CConvDwg2Kmg::CConvDwg2Kmg()
  15. {
  16. EnableAutomation();
  17. // To keep the application running as long as an OLE automation 
  18. // object is active, the constructor calls AfxOleLockApp.
  19. AfxOleLockApp();
  20. }
  21. CConvDwg2Kmg::~CConvDwg2Kmg()
  22. {
  23. // To terminate the application when all objects created with
  24. //  with OLE automation, the destructor calls AfxOleUnlockApp.
  25. AfxOleUnlockApp();
  26. }
  27. void CConvDwg2Kmg::OnFinalRelease()
  28. {
  29. // When the last reference for an automation object is released
  30. // OnFinalRelease is called.  The base class will automatically
  31. // deletes the object.  Add additional cleanup required for your
  32. // object before calling the base class.
  33. CCmdTarget::OnFinalRelease();
  34. }
  35. BEGIN_MESSAGE_MAP(CConvDwg2Kmg, CCmdTarget)
  36. //{{AFX_MSG_MAP(CConvDwg2Kmg)
  37. // NOTE - the ClassWizard will add and remove mapping macros here.
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. BEGIN_DISPATCH_MAP(CConvDwg2Kmg, CCmdTarget)
  41. //{{AFX_DISPATCH_MAP(CConvDwg2Kmg)
  42. DISP_FUNCTION(CConvDwg2Kmg, "BeginConverter", BeginConverter, VT_BOOL, VTS_BSTR)
  43. DISP_FUNCTION(CConvDwg2Kmg, "EndConverter", EndConverter, VT_BOOL, VTS_NONE)
  44. DISP_FUNCTION(CConvDwg2Kmg, "ConverterDwg2Kmg", ConverterDwg2Kmg, VT_BOOL, VTS_BSTR VTS_BSTR VTS_I4)
  45. DISP_FUNCTION(CConvDwg2Kmg, "GetProgressInfo", GetProgressInfo, VT_BOOL, VTS_PR8 VTS_PBSTR)
  46. DISP_FUNCTION(CConvDwg2Kmg, "GetRegInt", GetRegInt, VT_I4, VTS_BSTR VTS_BSTR VTS_I4)
  47. DISP_FUNCTION(CConvDwg2Kmg, "GetRegStr", GetRegStr, VT_BSTR, VTS_BSTR VTS_BSTR VTS_BSTR)
  48. DISP_FUNCTION(CConvDwg2Kmg, "SetRegInt", SetRegInt, VT_EMPTY, VTS_BSTR VTS_BSTR VTS_I4)
  49. DISP_FUNCTION(CConvDwg2Kmg, "SetRegStr", SetRegStr, VT_EMPTY, VTS_BSTR VTS_BSTR VTS_BSTR)
  50. //}}AFX_DISPATCH_MAP
  51. END_DISPATCH_MAP()
  52. // Note: we add support for IID_IConvDwg2Kmg to support typesafe binding
  53. //  from VBA.  This IID must match the GUID that is attached to the 
  54. //  dispinterface in the .ODL file.
  55. // {859B1323-1130-4E4D-A3DA-BF73E9265A65}
  56. static const IID IID_IConvDwg2Kmg =
  57. { 0x859b1323, 0x1130, 0x4e4d, { 0xa3, 0xda, 0xbf, 0x73, 0xe9, 0x26, 0x5a, 0x65 } };
  58. BEGIN_INTERFACE_MAP(CConvDwg2Kmg, CCmdTarget)
  59. INTERFACE_PART(CConvDwg2Kmg, IID_IConvDwg2Kmg, Dispatch)
  60. END_INTERFACE_MAP()
  61. // {B4CAB403-44A6-4287-B9A3-3FE032C64134}
  62. IMPLEMENT_OLECREATE(CConvDwg2Kmg, "FileSwitch.ConvDwg2Kmg", 0xb4cab403, 0x44a6, 0x4287, 0xb9, 0xa3, 0x3f, 0xe0, 0x32, 0xc6, 0x41, 0x34)
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CConvDwg2Kmg message handlers
  65. extern CFileSwitchApp theApp;
  66. extern CStdioFile g_CensorialFile; //监察转换进度的文件
  67. extern int g_mode;
  68. BOOL CConvDwg2Kmg::BeginConverter(LPCTSTR strRegistryKey) 
  69. {
  70. m_pProgress=new CProgressInfo; 
  71. m_pCommand=new CCommandInfo;  
  72. m_pConverter=new CKmgConverter(m_pCommand); 
  73. m_pReader=new CDwgReader(m_pProgress,m_pCommand,m_pConverter);       
  74. theApp.SetUserRegistryKey(strRegistryKey);
  75. return m_pReader->BeginConvert();
  76. }
  77. BOOL CConvDwg2Kmg::EndConverter() 
  78. {
  79. BOOL bSuccess=m_pReader->EndConvert();
  80. delete m_pProgress; 
  81. delete m_pCommand;  
  82. delete m_pReader;       
  83. delete m_pConverter;    
  84. return bSuccess;
  85. }
  86. BOOL CConvDwg2Kmg::ConverterDwg2Kmg(LPCTSTR strDwgFilename, LPCTSTR strKmgFilename, long hwnd) 
  87. {
  88. m_pCommand->m_strSourceName=strDwgFilename;
  89. m_pCommand->m_strAimName=strKmgFilename;
  90. m_pCommand->m_hmainfrm=(HWND)hwnd;
  91. g_mode=0;
  92. //仅供测试 g_mode=1;
  93. //theApp.GetProfileInt("PARAMETER","CONVMODE",0);
  94. //if(g_mode!=1)
  95. //{
  96. // g_mode=0;
  97. //}
  98. //theApp.WriteProfileInt("PARAMETER","CONVMODE",0);
  99. _CONV_OPEN;
  100. BOOL bSucc;
  101. // try
  102. // {
  103. bSucc=m_pReader->Parse();
  104. // }
  105. // catch(...)
  106. // {
  107. // return FALSE;
  108. // }
  109. //_CONV_CLOSE;
  110. if(g_mode==2) 
  111. if(g_CensorialFile.m_pStream)  
  112. g_CensorialFile.Close(); 
  113. g_mode=0; 
  114. return bSucc;
  115. }
  116. BOOL CConvDwg2Kmg::GetProgressInfo(double FAR* pdProgress, BSTR FAR* pstrProgressTip) 
  117. {
  118. // TODO: Add your dispatch handler code here
  119. double dProgress;
  120. CString strProgressTip;
  121. if(m_pProgress==NULL)
  122. {
  123. return FALSE;
  124. }
  125. m_pProgress->GetProgressInfo(dProgress,strProgressTip);
  126. *pstrProgressTip=(BSTR FAR)(LPCTSTR)strProgressTip;
  127. *pdProgress=dProgress;
  128. return TRUE;
  129. }
  130. long CConvDwg2Kmg::GetRegInt(LPCTSTR strName1, LPCTSTR strName2, long iDefault) 
  131. {
  132. // TODO: Add your dispatch handler code here
  133. return theApp.GetProfileInt(strName1,strName2,iDefault);
  134. }
  135. BSTR CConvDwg2Kmg::GetRegStr(LPCTSTR strName1, LPCTSTR strName2, LPCTSTR strDefault) 
  136. {
  137. CString strResult;
  138. strResult=theApp.GetProfileString(strName1,strName2,strDefault);
  139. return strResult.AllocSysString();
  140. }
  141. void CConvDwg2Kmg::SetRegInt(LPCTSTR strName1, LPCTSTR strName2, long iValue) 
  142. {
  143. theApp.WriteProfileInt(strName1,strName2,iValue);
  144. }
  145. void CConvDwg2Kmg::SetRegStr(LPCTSTR strName1, LPCTSTR strName2, LPCTSTR strValue) 
  146. {
  147. theApp.WriteProfileString(strName1,strName2,strValue);
  148. }