home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************/
- /* */
- /* TurboCAD for Windows */
- /* Copyright (c) 1993 - 2001 */
- /* International Microcomputer Software, Inc. */
- /* (IMSI) */
- /* All rights reserved. */
- /* */
- /******************************************************************/
-
- // ViewWnd.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "tcintf.h"
- #include "InsTool.h"
- #include "InsSymb.h"
- #include "ViewWnd.h"
- #include "TDialog.h"
-
-
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CPreviewWnd
-
- CPreviewWnd::CPreviewWnd(CInsSymb* pTool)
- {
- EnableAutomation();
- m_FirstStart = TRUE;
- m_pIApp = NULL;
- m_pDwgs = NULL;
- m_pPreviewDrawing = NULL;
- m_pPreviewGrs = NULL;
- m_pPreviewView = NULL;
- m_pViewsCol = NULL;
- m_hCurActDr = NULL;
-
- {
- m_pTool = pTool;
- }
- }
-
- CPreviewWnd::~CPreviewWnd()
- {
- }
-
- void CPreviewWnd::OnFinalRelease()
- {
- // When the last reference for an automation object is released
- // OnFinalRelease is called. The base class will automatically
- // deletes the object. Add additional cleanup required for your
- // object before calling the base class.
-
- CWnd::OnFinalRelease();
- }
-
-
- BEGIN_MESSAGE_MAP(CPreviewWnd, CWnd)
- //{{AFX_MSG_MAP(CPreviewWnd)
- ON_WM_PAINT()
- ON_WM_ERASEBKGND()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- BEGIN_DISPATCH_MAP(CPreviewWnd, CWnd)
- //{{AFX_DISPATCH_MAP(CPreviewWnd)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_DISPATCH_MAP
- END_DISPATCH_MAP()
-
- // Note: we add support for IID_IViewWnd to support typesafe binding
- // from VBA. This IID must match the GUID that is attached to the
- // dispinterface in the .ODL file.
-
- static const IID IID_IViewWnd =
- { 0x4b1aa263, 0x851c, 0x11d2, { 0x8b, 0xea, 0x0, 0x40, 0x33, 0x38, 0xc5, 0x4 } };
-
-
- const IID IID_ITcApp = {0x6A481200,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
- const IID IID_ITcDrawing = {0x6A481201,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
-
- BEGIN_INTERFACE_MAP(CPreviewWnd, CWnd)
- INTERFACE_PART(CPreviewWnd, IID_IViewWnd, Dispatch)
- END_INTERFACE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CPreviewWnd message handlers
-
- BOOL CPreviewWnd::CreatePreview()
- {
- HRESULT hRes = E_FAIL;
- COleVariant varType((const long)imsiPolyline);
- COleVariant varOptional(varMissing);
-
-
- try
- {
- ClearAll();
- HMODULE hDBAPI = NULL;
- hDBAPI = GetModuleHandle(DBAPI80);
- if (hDBAPI == NULL)
- {
- hDBAPI = GetModuleHandle(DBAPI70);
-
- if (hDBAPI == NULL)
- {
- hDBAPI = GetModuleHandle(DBAPI60);
- }
- }
-
- if (hDBAPI == NULL)
- return FALSE;
- else
- m_pfGetApp = (APPGETCURRENTAPP)GetProcAddress(hDBAPI, _T("AppGetCurrentApp"));
- if (m_pfGetApp == NULL)
- return FALSE;
-
- m_lApp = (*m_pfGetApp)();
- if (m_lApp == 0)
- return FALSE;
-
- m_pfFileOpen = (GRAPHICFILEOPENEX)GetProcAddress(hDBAPI, _T("GraphicFileOpenEx"));
- if (m_pfFileOpen == NULL)
- return FALSE;
-
- m_pfAppDwgNew = (APPDRAWINGNEWEX)GetProcAddress(hDBAPI, _T("AppDrawingNewEx"));
- if (m_pfAppDwgNew == NULL)
- return FALSE;
-
- BOOL i;
- i = TRUE;
- COleVariant varItem = (0L);
- long nDrawings = 0;
-
- m_lDwg = (*m_pfAppDwgNew)(m_lApp, i, NULL, NULL);
-
- hRes = ((CTDialog*)GetParent())->m_pThisTool->get_Application(&m_pIApp);
- CHECK_HRESULT(hRes)
-
- hRes = m_pIApp->get_Drawings(&m_pDwgs);
- CHECK_HRESULT(hRes)
-
- hRes = m_pDwgs->get_Count(&nDrawings);
- CHECK_HRESULT(hRes)
-
- varItem = nDrawings - 1L;
-
- hRes = m_pDwgs->get_Item(&varItem, &m_pPreviewDrawing);
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewDrawing->get_Views(&m_pViewsCol);
- CHECK_HRESULT(hRes)
-
-
- HWND hWnd = ::GetDlgItem(GetParent()->m_hWnd, IDC_PREVIEW);
- COleVariant varHwnd((long)hWnd);
- long nViews = 0;
-
- hRes = m_pViewsCol->Add(&varHwnd, &varOptional, &m_pPreviewView );
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->put_Update(FALSE);
- CHECK_HRESULT(hRes)
-
-
- hRes = m_pPreviewView->put_MappingMode(MM_TEXT);
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->put_FixedAspectRatio(TRUE);
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->put_Margins(FALSE);
- CHECK_HRESULT(hRes)
-
- CPreviewWnd *pPreview = (CPreviewWnd *) (((CTDialog*)GetParent())->GetDlgItem(IDC_PREVIEW));
-
- AFX_MANAGE_STATE(m_pTool->m_pTCState);
-
- CRect rcBounds;
- pPreview->GetClientRect(&rcBounds);
- pPreview->Invalidate();
-
- hRes = m_pPreviewView->put_ScreenLeft(rcBounds.left);
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->put_ScreenTop(rcBounds.top);
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->put_ScreenWidth(rcBounds.Width());
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->put_ScreenHeight(rcBounds.Height());
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->ZoomToExtents();
- CHECK_HRESULT(hRes)
-
- VariantClear(&varType);
- VariantClear(&varOptional);
-
- }
- catch (...)
- {
-
- TRACE_EXCEPTION("CPreviewWnd::CreatePreview")
- ClearAll();
- _clearfp();
-
- }
- if(m_pIApp != NULL)
- {
- m_pIApp->Release();
- m_pIApp = NULL;
- }
- return TRUE;
- }
-
- BOOL CPreviewWnd::DoPreview()
- {
- HRESULT hRes = E_FAIL;
- BOOL bRes = FALSE;
- COleVariant varType((const long)imsiGroup);
- COleVariant varOptional(varMissing);
- CString cstrError;
- BOOL curMode;
- BOOL i;
- i = TRUE;
- long IDwg1 = 0;
- COleVariant varItem = (0L);
- long nDrawings = 0;
- IDrawing* pTmpDwg = NULL;
-
- Properties *pProps = NULL;
- Property *pProp = NULL;
- Properties *pProps1 = NULL;
- Property *pProp1 = NULL;
- CMerge merge;
- IGraphic* pIGrTmp = NULL;
- IGraphic* pIGrTmp1 = NULL;
-
- ITcDrawing* pITcDr = NULL;
- ITcApp* pTcApp = NULL;
- IDrawing* pIDwg = NULL;
-
- try
- {
- CButton *pCheckBox = (CButton *) (GetParent()->GetDlgItem(IDC_SPACEMODE));
-
-
- CSymbolsList *pList = (CSymbolsList *) (GetParent()->GetDlgItem(IDC_SYMBOLSLIST));
-
- int index = pList->GetCurSel();
-
- pList->GetText(index, m_selected);
-
- IDwg1 = (*m_pfAppDwgNew)(m_lApp, i, NULL, NULL);
-
- hRes = m_pDwgs->get_Count(&nDrawings);
- CHECK_HRESULT(hRes)
-
- varItem = nDrawings - 1L;
-
- hRes = m_pDwgs->get_Item(&varItem, &pTmpDwg);
- CHECK_HRESULT(hRes)
-
- AFX_MANAGE_STATE(m_pTool->m_pTCState);
-
- DWORD dwRes = (*m_pfFileOpen)(0, IDwg1, m_lApp, (LPTSTR)(LPCSTR)m_selected, NULL, cstrError.GetBuffer(256), 255, GF_OPENMODE, 0, NULL );
-
- if (dwRes == NULL)
- return FALSE;
-
- CString cstrName("TileMode");//# Non-localizable string#
- BSTR bstrName = cstrName.AllocSysString();
-
- ::VariantInit(&varItem);
- varItem.vt = VT_BSTR;
- varItem.bstrVal = bstrName;
-
- hRes = pTmpDwg->get_Properties(&pProps);
- CHECK_HRESULT(hRes)
-
- hRes = pProps->get_Item(&varItem, &pProp);
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewDrawing->get_Properties(&pProps1);
- CHECK_HRESULT(hRes)
-
- hRes = pProps1->get_Item(&varItem, &pProp1);
- CHECK_HRESULT(hRes)
-
- COleVariant varVal;
- varVal.vt = VT_I2;
-
- pProp->get_Value(NULL, &varVal);
- long dd = varVal.iVal;
-
- if (varVal.iVal == 1)
- {
- curMode = 1;//imsiModelSpace;
- }
- else
- {
- curMode = 0;//imsiPaperSpace;
-
- }
-
-
-
- // switch the Preview drawing and temp drawing to paper space.
- varVal.iVal = 0;
- hRes = pProp1->put_Value(NULL, &varVal);
- CHECK_HRESULT(hRes)
-
- hRes = pProp->put_Value(NULL, &varVal);
- CHECK_HRESULT(hRes)
-
- BOOL bGrsOnly;
- bGrsOnly = FALSE;
- // merge the paper space graphics collection and blocks, styles, layers...
- hRes = merge.Init(pTmpDwg, m_pPreviewDrawing, FALSE);
- CHECK_HRESULT(hRes)
-
- hRes = merge.Run(&pIGrTmp, bGrsOnly);
- CHECK_HRESULT(hRes)
-
-
- // switch the Preview drawing and temp drawing to model space.
-
- varVal.iVal = 1;
-
- hRes = pProp1->put_Value(NULL, &varVal);
- CHECK_HRESULT(hRes)
-
- hRes = pProp->put_Value(NULL, &varVal);
- CHECK_HRESULT(hRes)
-
- // merge the model space graphics collection
-
- bGrsOnly = FALSE;
- hRes = merge.Init(pTmpDwg, m_pPreviewDrawing, FALSE);
- CHECK_HRESULT(hRes)
-
- hRes = merge.Run(&pIGrTmp1, bGrsOnly);
- CHECK_HRESULT(hRes)
-
-
-
- // set the space mode for Preview drawing the same like in file that is open.
- if (curMode == 0) //imsiPaperSpace
- {
- varVal.iVal = 0;
-
- hRes = pProp1->put_Value(NULL, &varVal);
- CHECK_HRESULT(hRes)
-
- }
- else
- {
-
- // curMode = imsiModelSpace;
- varVal.iVal = 1;
-
- hRes = pProp1->put_Value(NULL, &varVal);
- CHECK_HRESULT(hRes)
-
- }
-
- hRes = m_pPreviewDrawing->get_Application(&m_pIApp);
- CHECK_HRESULT(hRes)
-
-
- hRes = m_pIApp->QueryInterface(IID_ITcApp, (void **) &pTcApp);
- CHECK_HRESULT(hRes)
-
- hRes = pTcApp->GetActiveDrawing(&pITcDr);
- CHECK_HRESULT(hRes)
-
-
- hRes = pITcDr->QueryInterface(IID_IDrawing, (void **) &pIDwg);
- CHECK_HRESULT(hRes)
-
- hRes = pIDwg->get__Handle((long*)&m_hCurActDr);
- CHECK_HRESULT(hRes)
-
- if (pProp != NULL)
- {
- pProp->Release();
- pProp = NULL;
- }
-
- if (pProps != NULL)
- {
- pProps->Release();
- pProps = NULL;
- }
-
- if(pIGrTmp !=NULL)
- {
- pIGrTmp->Release();
- pIGrTmp = NULL;
- }
-
- COleVariant varOptional(varMissing);
- pTmpDwg->Close(varOptional, varOptional, varOptional);
-
- if (m_hCurActDr != NULL)
- {
- hRes = m_pIApp->QueryInterface(IID_ITcApp, (void **) &pTcApp);
- CHECK_HRESULT(hRes)
-
- hRes = pTcApp->SetActiveDrawing(m_hCurActDr, NULL);
- CHECK_HRESULT(hRes)
-
- m_hCurActDr = NULL;
- }
-
-
- hRes = m_pPreviewView->ZoomToExtents();
- CHECK_HRESULT(hRes)
-
- if(pCheckBox == NULL)
- return FALSE;
-
- if (curMode == 1) //imsiModelSpace
- pCheckBox->SetCheck(1);
-
- else
- pCheckBox->SetCheck(0);
-
- bRes = TRUE;
-
- }
- catch (...)
- {
- _clearfp();
- TRACE_EXCEPTION("CPreviewWnd::DoPreview")
- hRes = E_FAIL;
- }
-
- if(pIDwg !=NULL)
- {
- pIDwg->Release();
- pIDwg = NULL;
- }
-
- if(pITcDr != NULL)
- {
- pITcDr->Release();
- pITcDr = NULL;
- }
- if(pTcApp != NULL)
- {
- pTcApp->Release();
- pTcApp = NULL;
- }
-
- if (pProp1 != NULL)
- {
- pProp1->Release();
- pProp1 = NULL;
- }
- if (pProps1 != NULL)
- {
- pProps1->Release();
- pProps1 = NULL;
- }
-
- if(pTmpDwg != NULL)
- {
- pTmpDwg->Release();
- pTmpDwg = NULL;
- }
- if(pTcApp != NULL)
- {
- pTcApp->Release();
- pTcApp = NULL;
- }
- if(m_pIApp != NULL)
- {
- m_pIApp->Release();
- m_pIApp = NULL;
- }
-
- return bRes;
- }
-
- void CPreviewWnd::RefreshList()
- {
-
- }
-
- void CPreviewWnd::Clear()
- {
- Invalidate();
- }
-
- void CPreviewWnd::ClearAll()
- {
- try
- {
-
-
- if (m_pPreviewGrs != NULL)
- {
- m_pPreviewGrs->Release();
- m_pPreviewGrs = NULL;
-
- }
- if (m_pPreviewView != NULL)
- {
- m_pPreviewView->Delete();
- m_pPreviewView->Release();
- m_pPreviewView = NULL;
-
- }
- if (m_pViewsCol != NULL)
- {
- m_pViewsCol->Release();
- m_pViewsCol = NULL;
-
- }
- if (m_pPreviewDrawing != NULL)
- {
-
- COleVariant varOptional(varMissing);
- HRESULT hRes = m_pPreviewDrawing->Close(varOptional, varOptional, varOptional);
- CHECK_HRESULT(hRes)
- m_pPreviewDrawing->Release();
- m_pPreviewDrawing = NULL;
- }
-
- m_FirstStart = TRUE;
- }
-
- catch (...)
- {
- _clearfp();
- TRACE_EXCEPTION("CPreviewWnd::ClearAll")
- }
-
- if (m_pDwgs != NULL)
- {
- m_pDwgs->Release();
- m_pDwgs = NULL;
- }
-
- if (m_pIApp != NULL)
- {
- m_pIApp->Release();
- m_pIApp = NULL;
- }
-
- }
-
- void CPreviewWnd::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- // TODO: Add your message handler code here
- if (m_pPreviewView == NULL)
- return;
-
- // Force redraw of view window
- try
- {
- HRESULT hRes = m_pPreviewView->Refresh();
- CHECK_HRESULT(hRes)
-
- }
- catch (...)
- {
- _clearfp();
- TRACE_EXCEPTION("CPreviewWnd::Paint")
- }
-
- // Do not call CWnd::OnPaint() for painting messages
- }
-
- BOOL CPreviewWnd::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: Add your message handler code here and/or call default
- CRect rect;
- GetClientRect(rect);
- pDC->FillSolidRect(rect, ::GetSysColor(COLOR_WINDOW));
- return TRUE;
- }
-
-