home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / v8trial / TurboCADv8ProfessionalNoReg.exe / Data.Cab / F37601_TDialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-21  |  21.4 KB  |  1,028 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 2001                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10.  
  11. // TDialog.cpp : implementation file
  12. //
  13. #include <afxwin.h>
  14. #include "stdafx.h"
  15. #include "InsTool.h"
  16. #include "InsSymb.h"
  17. #include "ViewWnd.h"
  18. #include "TDialog.h"
  19. #include "TDialog1.h"
  20. #include "Dirdialog.h"
  21.  
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27.  
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. BEGIN_MESSAGE_MAP(CTDialog, CDialog)
  31.     //{{AFX_MSG_MAP(CTDialog)
  32.     ON_BN_CLICKED(ID_CLOSE, OnClose)
  33.     ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
  34.     ON_BN_CLICKED(IDC_MODIFY, OnModify)
  35.     ON_BN_CLICKED(IDC_SPACEMODE, OnChangeSpaceMode)
  36.     ON_BN_CLICKED(ID_INSERTSYMB, OnInsertsymb)
  37.     ON_WM_SYSCOMMAND()
  38.     //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40.  
  41. BEGIN_DISPATCH_MAP(CTDialog, CDialog)
  42.     //{{AFX_DISPATCH_MAP(CTDialog)
  43.         // NOTE - the ClassWizard will add and remove mapping macros here.
  44.     DISP_FUNCTION(CTDialog, "MouseDown", MouseDown, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH VTS_I2 VTS_I4 VTS_I4 VTS_I4 VTS_PBOOL)
  45.     DISP_FUNCTION(CTDialog, "MouseUp", MouseUp, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH VTS_I2 VTS_I4 VTS_I4 VTS_I4 VTS_PBOOL)
  46.     DISP_FUNCTION(CTDialog, "MouseMove", MouseMove, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH VTS_I4 VTS_I4 VTS_I4 VTS_PBOOL)
  47.     DISP_FUNCTION(CTDialog,    "DrawingBeforeClose", DrawingBeforeClose, VT_EMPTY, VTS_DISPATCH VTS_PBOOL)
  48.     //}}AFX_DISPATCH_MAP
  49.  
  50. END_DISPATCH_MAP()
  51.  
  52. // Note: we add support for IID_ITDialog 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.  
  56.  
  57. BEGIN_INTERFACE_MAP(CTDialog, CDialog)
  58.     INTERFACE_PART(CTDialog, IID_IAppEvents, Dispatch)
  59. END_INTERFACE_MAP()
  60.  
  61. /////////////////////////////////////////////////////////////////////////////
  62.  
  63.  
  64.  
  65. // CTDialog dialog
  66.  
  67.  
  68. CTDialog::CTDialog(CInsSymb* pTool, CWnd* pParent, /*=NULL*/Tool *pThisTool)
  69.     : CDialog(CTDialog::IDD, pParent),
  70.     m_dwEventConnection(0),
  71.     m_dwEventMask(~0UL),
  72.     m_pIApplication(NULL),
  73.     m_FirstClick(FALSE),
  74.     m_bDragging(FALSE),
  75.     m_pDragGraphic(NULL),
  76.     m_pTCADView(NULL),
  77.     m_pThisTool(NULL),
  78.     m_wndView(pTool)
  79.  
  80. {
  81.     EnableAutomation();
  82.  
  83.     //{{AFX_DATA_INIT(CTDialog)
  84.         // NOTE: the ClassWizard will add member initialization here
  85.     //}}AFX_DATA_INIT
  86.  
  87.     m_pTool = pTool;
  88.     m_pTool->AddRef();
  89.  
  90.     m_pTool->m_bRunned = TRUE;
  91.  
  92.     m_pThisTool = pThisTool;
  93.     m_pThisTool->AddRef();
  94. }
  95.  
  96. void CTDialog::DoDataExchange(CDataExchange* pDX)
  97. {
  98.     CDialog::DoDataExchange(pDX);
  99.     //{{AFX_DATA_MAP(CTDialog)
  100.         // NOTE: the ClassWizard will add DDX and DDV calls here
  101.     //}}AFX_DATA_MAP
  102. }
  103.  
  104.  
  105. // CTDialog message handlers
  106. BOOL CTDialog::OnInitDialog() 
  107. {
  108.     
  109.     CString cstrPropName;
  110.     CString cstrInitPath;
  111.     COleVariant varItem;
  112.     COleVariant varVal;
  113.     Properties *pProps = NULL;
  114.     Property *pProp = NULL;
  115.     HRESULT hRes = E_FAIL;
  116.     BOOL bRet = FALSE;
  117.  
  118.     CDialog::OnInitDialog();
  119.     m_list.SubclassDlgItem( IDC_SYMBOLSLIST , this );
  120.     CSymbolsList *pList = (CSymbolsList *)GetDlgItem(IDC_SYMBOLSLIST);
  121.     
  122.     try
  123.     {
  124.  
  125.         HMODULE hHdl = NULL;
  126.         char path[256];
  127.  
  128.         DWORD dBufSize = 256;
  129.         DWORD dW = 0; 
  130.  
  131.         hHdl = GetModuleHandle(NULL);
  132.  
  133.         dW = GetModuleFileName(hHdl, path, dBufSize);  
  134.         hHdl = NULL;
  135.  
  136.         cstrInitPath = path;
  137.         cstrInitPath = cstrInitPath.Left(cstrInitPath.GetLength () - 10); // delete module name from path
  138.  
  139.         pList->RefreshFileList(cstrInitPath);
  140.  
  141.         CEdit *pPath = (CEdit *) GetDlgItem(IDC_EDITPATH);
  142.         pPath->SetWindowText(cstrInitPath);
  143.         CString selected;
  144.  
  145.         
  146.         m_wndView.SubclassDlgItem(IDC_PREVIEW, this);
  147.         CPreviewWnd *pViewWnd = (CPreviewWnd *)GetDlgItem(IDC_PREVIEW);
  148.         if(pList->SetCurSel(0) != LB_ERR)
  149.         {
  150.  
  151.             pList->GetText(0 ,(pList->m_cstrCurSelected));
  152.  
  153.             pViewWnd->CreatePreview();
  154.             pViewWnd->DoPreview();            
  155.             ConnectEvents();
  156.         
  157.         }
  158.         else
  159.         {
  160.             ConnectEvents();
  161.         }
  162.         bRet = TRUE;
  163.     }
  164.  
  165.     catch (...)
  166.     {
  167.         TRACE_EXCEPTION("CTDialog::OnInitDialog")
  168.         _clearfp();
  169.     }
  170.     
  171.     return bRet;  // return TRUE unless you set the focus to a control
  172.                   // EXCEPTION: OCX Property Pages should return FALSE
  173. }
  174.  
  175. void CTDialog::OnClose() 
  176. {
  177.     if(m_dwEventConnection != 0)
  178.         DisconectEvents();
  179.  
  180.     CPreviewWnd *pViewWnd = (CPreviewWnd *)GetDlgItem(IDC_PREVIEW);
  181.     pViewWnd->ClearAll();
  182.  
  183.     m_pTool->m_bRunned = FALSE;
  184.     if(m_pTool != NULL)
  185.     {
  186.         m_pTool->Release();
  187.         m_pTool = NULL;
  188.         
  189.     }
  190.     if(m_pThisTool != NULL)
  191.     {
  192.         m_pThisTool->Release();
  193.         m_pThisTool = NULL;
  194.         
  195.     }
  196.  
  197.     CDialog::OnClose();
  198.     DestroyWindow();
  199.     
  200. }
  201.  
  202. void CTDialog::OnSysCommand(UINT nID, LPARAM lParam )
  203. {
  204.     if (nID == SC_CLOSE)
  205.     {
  206.         if(m_dwEventConnection != 0)
  207.         DisconectEvents();
  208.     
  209.         CPreviewWnd *pViewWnd = (CPreviewWnd *)GetDlgItem(IDC_PREVIEW);
  210.         pViewWnd->ClearAll();
  211.         m_pTool->m_bRunned = FALSE;
  212.         if(m_pTool != NULL)
  213.         {
  214.             m_pTool->Release();
  215.             m_pTool = NULL;
  216.         
  217.         }
  218.         if(m_pThisTool != NULL)
  219.         {
  220.             m_pThisTool->Release();
  221.             m_pThisTool = NULL;
  222.         
  223.         }
  224.  
  225.     }
  226.     CDialog::OnSysCommand(nID, lParam );
  227.  
  228. }
  229.  
  230. void CTDialog::OnModify() 
  231. {
  232.         CWnd *pMainWnd = AfxGetMainWnd();
  233.         CModifyDlg *pModifydlg = new CModifyDlg(m_pTool, pMainWnd);
  234.         int i =    pModifydlg->DoModal();
  235. }
  236.  
  237. void CTDialog::OnChangeSpaceMode() 
  238. {
  239.  
  240.     CPreviewWnd *pViewWnd = (CPreviewWnd *)GetDlgItem(IDC_PREVIEW);
  241.     AFX_MANAGE_STATE(m_pTool->m_pTCState);
  242.  
  243.  
  244.     Properties *pProps = NULL;
  245.     Property *pProp = NULL;
  246.     VARIANT varVal;//(0L);
  247.     varVal.vt = VT_I2;
  248. //    TileMode - Property of drawing that store current drawing mode (PaperSpace or ModelSpace)
  249. //    imsiModelSpace = 1, imsiPaperSpace = 0
  250.  
  251.     CString cstrName("TileMode");//# Non-localizable string#
  252.     BSTR bstrName = cstrName.AllocSysString();
  253.  
  254.     VARIANT varItem;
  255.   ::VariantInit(&varItem);
  256.     varItem.vt = VT_BSTR;
  257.     varItem.bstrVal = bstrName;
  258.     try
  259.     {
  260.  
  261.         if(pViewWnd->m_pPreviewDrawing != NULL)
  262.         {
  263.             HRESULT hRes = pViewWnd->m_pPreviewDrawing->get_Properties(&pProps);
  264.             CHECK_HRESULT(hRes)
  265.  
  266.             hRes = pProps->get_Item(&varItem, &pProp);
  267.             CHECK_HRESULT(hRes)
  268.  
  269.             pProp->get_Value(NULL, &varVal);
  270.  
  271.             if (varVal.iVal == 0) // cur drawing mode is paper space
  272.             {
  273.                 varVal.iVal = 1;
  274.                 hRes = pProp->put_Value(NULL, &varVal);
  275.                 CHECK_HRESULT(hRes)
  276.                     
  277.             }
  278.             else  // cur drawing mode is model space
  279.             {
  280.                 varVal.iVal = 0;
  281.                 hRes = pProp->put_Value(NULL, &varVal); // switch the preview drawing to paper space
  282.                 CHECK_HRESULT(hRes)
  283.  
  284.             }
  285.             
  286.             pViewWnd->Invalidate();
  287.  
  288.             hRes = pViewWnd->m_pPreviewView->ZoomToExtents();
  289.             CHECK_HRESULT(hRes)
  290.  
  291.             hRes = pViewWnd->m_pPreviewView->Refresh();
  292.             CHECK_HRESULT(hRes)
  293.             ::VariantClear(&varItem);
  294.         }
  295.     }
  296.     catch (...)
  297.     {
  298.         _clearfp();
  299.  
  300.         TRACE_EXCEPTION("TDialog::OnChangeSpaceMode")
  301.     }
  302.     
  303.     if (pProp != NULL)
  304.     {
  305.         pProp->Release();
  306.         pProp = NULL;
  307.     }
  308.     if (pProps != NULL)
  309.     {
  310.         pProps->Release();
  311.         pProps = NULL;
  312.     }
  313.  
  314. }
  315. void CTDialog::DrawingBeforeClose(LPDISPATCH WhichDrawing, BOOL FAR* Cancel)
  316. {
  317.     *Cancel = FALSE;
  318.     Drawings *pDrs = NULL;
  319.     long n = 0;
  320.  
  321.     try
  322.     {
  323.         HRESULT hRes = m_pIApplication->get_Drawings(&pDrs);
  324.         CHECK_HRESULT(hRes)
  325.         hRes = pDrs->get_Count(&n);
  326.         CHECK_HRESULT(hRes)
  327.         if (n == 2)
  328.         {
  329.             if(m_dwEventConnection != 0)
  330.                 DisconectEvents();
  331.  
  332.             CPreviewWnd *m_wndView = (CPreviewWnd *)GetDlgItem(IDC_PREVIEW);
  333.             m_wndView->ClearAll();
  334.  
  335.             m_pTool->m_bRunned = FALSE;
  336.  
  337.             CDialog::OnClose();
  338.             DestroyWindow();
  339.         }
  340.  
  341.  
  342.     }
  343.  
  344.     catch (...)
  345.     {
  346.         _clearfp();
  347.  
  348.         TRACE_EXCEPTION("TDialog::DrawingBeforeClose")
  349.     }
  350.     if (pDrs != NULL)
  351.     {
  352.         pDrs->Release();
  353.         pDrs = NULL;
  354.     }
  355.  
  356.  
  357. }
  358. void CTDialog::MouseDown(LPDISPATCH WhichDrawing, LPDISPATCH WhichView, LPDISPATCH WhichWindow, short Button, long Shift, long X, long Y, IMSI_BOOL* pbCancel)
  359. {
  360. // do nothing on this event
  361.     *pbCancel = FALSE;
  362. }
  363.  
  364. void CTDialog::MouseUp(LPDISPATCH WhichDrawing, LPDISPATCH WhichView, LPDISPATCH WhichWindow, short Button, long Shift, long X, long Y, IMSI_BOOL* pbCancel)
  365. {
  366.     *pbCancel = FALSE;
  367.     HRESULT hRes = E_FAIL;
  368.     CMerge merge;
  369.     IDrawing *pIDwgTrg = NULL;
  370.     Graphics *pGrs = NULL;
  371.     COleVariant varOptional(varMissing);
  372.  
  373.     CPreviewWnd *pViewWnd = (CPreviewWnd *)GetDlgItem(IDC_PREVIEW);
  374.  
  375.     AFX_MANAGE_STATE(m_pTool->m_pTCState);
  376.  
  377.     try
  378.     {
  379.         if(m_pDragGraphic != 0)
  380.         {
  381.  
  382.             pIDwgTrg = (IDrawing*)WhichDrawing;
  383.  
  384.             pIDwgTrg->AddRef();
  385.     
  386.             
  387.             hRes = merge.InitA(pViewWnd->m_pPreviewDrawing, pIDwgTrg);
  388.             CHECK_HRESULT(hRes)
  389.  
  390.             hRes = merge.RunA();
  391.             CHECK_HRESULT(hRes)
  392.  
  393.             hRes = pIDwgTrg->get_Graphics(&pGrs); // get current drawing graphic collection
  394.             CHECK_HRESULT(hRes)
  395.     
  396.             hRes = pGrs->AddGraphic(m_pDragGraphic, varOptional, varOptional);
  397.             CHECK_HRESULT(hRes)
  398.             
  399.             hRes = merge.CorrectGraphic(m_pDragGraphic);
  400.             CHECK_HRESULT(hRes)
  401.  
  402.             hRes = m_pDragGraphic->Update();
  403.             CHECK_HRESULT(hRes)
  404.  
  405.             pIDwgTrg->Release();
  406.             pIDwgTrg = NULL;
  407.  
  408.                     
  409.             CPoint point;
  410.             point.x = X;
  411.             point.y = Y;
  412.  
  413.             m_pTCADView = (View*) WhichView;
  414.             m_pTCADView->AddRef();
  415.  
  416.             EndDrag(point);
  417.  
  418.             hRes = m_pTCADView->Refresh();
  419.             CHECK_HRESULT(hRes)
  420.  
  421.             m_FirstClick = FALSE;    
  422.         }
  423.     }
  424.     catch (...)
  425.     {
  426.         _clearfp();
  427.  
  428.         TRACE_EXCEPTION("TDialog::MouseUp")
  429.     }
  430.  
  431.     if (m_pTCADView != NULL)
  432.     {
  433.         m_pTCADView->Release();
  434.         m_pTCADView = NULL;
  435.     }
  436.     if (pGrs != NULL)
  437.     {
  438.         pGrs->Release();
  439.         pGrs = NULL;
  440.     }
  441.  
  442.  
  443. }
  444. void CTDialog::MouseMove(LPDISPATCH WhichDrawing, LPDISPATCH WhichView, LPDISPATCH WhichWindow, long Shift, long X, long Y, IMSI_BOOL* pbCancel)
  445. {
  446.     *pbCancel = FALSE;
  447.  
  448.  
  449.     CPoint point;
  450.     point.x = X;
  451.     point.y = Y;
  452.     Graphics* GrsTmp = NULL;;
  453.     Graphics* pPreviewGrs = NULL;;
  454.     IGraphic* Gr1 = NULL;
  455.     long c = 0;
  456.     IDrawing *pIDwgTrg = NULL;
  457.     Graphics *pGrs = NULL;
  458.     View *pTCADCurrentView = NULL;
  459.  
  460.     try 
  461.     {
  462.  
  463.         if (m_FirstClick == TRUE)/// && m_bDragging != FALSE) 
  464.         {
  465.             
  466.             if(m_pTCADView != NULL)
  467.             {
  468.                 m_pTCADView->Release();
  469.             }
  470.             m_pTCADView = (View *)WhichView;
  471.             m_pTCADView->AddRef();
  472.  
  473.             CPreviewWnd *pPreview = (CPreviewWnd *) (GetDlgItem(IDC_PREVIEW));
  474.             
  475.             COleVariant varItem = (1L);
  476.             
  477.             HRESULT hRes = pPreview->m_pPreviewDrawing->get_Graphics(&pPreviewGrs);
  478.             CHECK_HRESULT(hRes)
  479.  
  480. #ifdef _DEBUG
  481.             hRes = pPreviewGrs->get_Count(&c);
  482.             CHECK_HRESULT(hRes)
  483. #endif
  484.  
  485.             varItem = 0L;
  486.  
  487.             hRes = pPreviewGrs->get_Item(varItem, &Gr1);
  488.             CHECK_HRESULT(hRes)
  489. // check if the graphic that we drag is empty            
  490.             hRes = Gr1->get_Graphics(&GrsTmp);
  491.             CHECK_HRESULT(hRes)
  492.  
  493.             long b = 0;
  494.             hRes = GrsTmp->get_Count(&b);
  495.             CHECK_HRESULT(hRes)
  496.             
  497.             if (b == 0) //if it is empty then return;
  498.             {
  499.                 
  500.                 GrsTmp->Release();
  501.                 GrsTmp = NULL;
  502.  
  503.                 Gr1->Release();
  504.                 Gr1 = NULL;
  505.  
  506.                 pPreviewGrs->Release();
  507.                 pPreviewGrs = NULL;
  508.  
  509.                 m_FirstClick = TRUE;    
  510.                 return;
  511.             }
  512.  
  513.  
  514.             hRes = Gr1->Duplicate(&m_pDragGraphic);
  515.             CHECK_HRESULT(hRes)
  516.             
  517.             m_pDragGraphic->Release();
  518.             m_pDragGraphic = NULL;
  519.     
  520.             hRes = pPreviewGrs->get_Count(&c);
  521.             CHECK_HRESULT(hRes)
  522.             varItem = c -1L;
  523.             hRes = pPreviewGrs->Remove(&varItem, &m_pDragGraphic);
  524.             CHECK_HRESULT(hRes)
  525.             m_FirstClick = FALSE;
  526.             BeginDrag(point);
  527.         }
  528.         else 
  529.         {
  530.             if (m_pDragGraphic != NULL && !m_bDragging)/// aalb && (nFlags & MK_LBUTTON))
  531.             {
  532.                 if (!BeginDrag(point))
  533.                 {
  534.                     m_pDragGraphic->Release();
  535.                     m_pDragGraphic = NULL;
  536.                 }
  537.             }
  538.             else if (m_bDragging)
  539.             {
  540.  
  541.                 pTCADCurrentView = (View *)WhichView;
  542.                 pTCADCurrentView->AddRef();
  543.                 if (pTCADCurrentView != m_pTCADView) // if view is changed (user drag symbol over another view(window)) then restart drag
  544.                 {
  545.                     m_pTCADView = pTCADCurrentView;
  546.                     pTCADCurrentView->Release();
  547.                     pTCADCurrentView = NULL;
  548.                     RestartDrag(point);                
  549.  
  550.                 }
  551.  
  552.                 Drag(point);
  553.             }    
  554.             
  555.         }
  556.     }    
  557.     catch (...)
  558.     {
  559.         TRACE_EXCEPTION("CTDialog::OnMouseMove")
  560.         _clearfp();
  561.     }
  562.  
  563.     if(GrsTmp != NULL)
  564.     {
  565.         GrsTmp->Release();
  566.         GrsTmp = NULL;
  567.     }
  568.     if(Gr1 != NULL)
  569.     {
  570.         Gr1->Release();
  571.         Gr1 = NULL;
  572.     }
  573.     if(pPreviewGrs != NULL)
  574.     {
  575.         pPreviewGrs->Release();
  576.         pPreviewGrs = NULL;
  577.     }
  578.  
  579.  
  580. }
  581.  
  582. void CTDialog::ConnectEvents()
  583. {
  584.     HRESULT hRes = S_OK;
  585.  
  586.     if (m_dwEventConnection != 0)
  587.     {
  588.         return;
  589.     }
  590.     
  591.     m_pIApplication = NULL;
  592.  
  593.     try
  594.     {
  595.         hRes = m_pThisTool->get_Application(&m_pIApplication);
  596.         CHECK_HRESULT(hRes)
  597.  
  598.         if (m_pIApplication == NULL)
  599.             return;
  600.  
  601.         IDispatch* pUnkEventSink = GetIDispatch(TRUE);
  602.  
  603.         UpdateData(TRUE);
  604.         COleVariant var((long)m_dwEventMask);
  605.         hRes = m_pIApplication->ConnectEvents(pUnkEventSink,
  606.             &var,
  607.             (long*)&m_dwEventConnection);
  608.         
  609.         if (FAILED(hRes))
  610.             return;
  611.     }
  612.     catch (...)
  613.     {
  614.         TRACE_EXCEPTION("CTDialog::ConnectEvents")
  615.         _clearfp();
  616.     }
  617. }
  618.  
  619. void CTDialog::DisconectEvents()
  620. {
  621.     if (m_pIApplication == NULL || m_dwEventConnection == 0)
  622.         return;
  623.  
  624.     try
  625.     {
  626.         HRESULT    hRes = m_pIApplication->DisconnectEvents(m_dwEventConnection);
  627.         if (FAILED(hRes))
  628.         {
  629.             return;
  630.         }
  631.         m_pIApplication->Release(); // possibility problem
  632.         m_pIApplication = NULL;
  633.  
  634.         m_dwEventConnection = 0;
  635.     }
  636.     catch (...)
  637.     {
  638.         TRACE_EXCEPTION("CTDialog::DisconectEvents")
  639.         _clearfp();
  640.     }
  641.  
  642.  
  643. }
  644.  
  645. BOOL CTDialog::BeginDrag(const CPoint& point)
  646. {
  647.     BOOL bRes = FALSE;
  648.     HRESULT hRes = E_FAIL;
  649.     BoundingBox* Box = NULL;
  650.     IVertex* vMax = NULL;
  651.     IVertex* vMin = NULL;
  652.     double x, y, x1, y1;
  653.  
  654.     if (m_pTCADView == NULL)
  655.         return bRes;
  656.     try
  657.     {
  658.         VariantClear(&m_dragOutline);
  659.         SAFEARRAYBOUND bound;
  660.         bound.cElements = 0;
  661.         bound.lLbound = 0;
  662.         m_dragOutline.vt = VT_ARRAY|VT_R8;
  663.         m_dragOutline.parray = ::SafeArrayCreate(VT_R8, 1, &bound);
  664.         hRes = m_pDragGraphic->CreateDragOutline(&m_dragOutline);
  665.         CHECK_HRESULT(hRes);
  666.  
  667.         m_bDragging = TRUE;
  668.         m_pDragGraphic->put_Visible(FALSE);
  669.         VARIANT varState;
  670.         varState.vt = VT_I4;
  671.         varState.lVal = imsiDragBegin;
  672.  
  673.         hRes = m_pDragGraphic->CalcBoundingBox(NULL, &Box);
  674.         CHECK_HRESULT(hRes)
  675.  
  676.         hRes = Box->get_Max(&vMax);
  677.         CHECK_HRESULT(hRes)
  678.  
  679.         hRes = Box->get_Min(&vMin);
  680.         CHECK_HRESULT(hRes)
  681.  
  682.         hRes = vMax->get_X(&x);
  683.         CHECK_HRESULT(hRes)
  684.  
  685.         hRes = vMax->get_Y(&y);
  686.         CHECK_HRESULT(hRes)
  687.  
  688.         hRes = vMin->get_X(&x1);
  689.         CHECK_HRESULT(hRes)
  690.  
  691.         hRes = vMin->get_Y(&y1);
  692.         CHECK_HRESULT(hRes)
  693.  
  694.         x = x1 + (x - x1)/2;
  695.         y = y1 + (y - y1)/2;
  696.         hRes = m_pTCADView->ViewToScreen(x, y, &x1, &y1, NULL);
  697.         CHECK_HRESULT(hRes)
  698.  
  699.         hRes = m_pTCADView->DragOutline(&m_dragOutline, x1, y1, &varState);
  700.         CHECK_HRESULT(hRes)
  701.         
  702.         varState.lVal = imsiDragContinue;
  703.         hRes = m_pTCADView->DragOutline(&m_dragOutline, point.x, point.y, &varState);
  704.         CHECK_HRESULT(hRes)
  705.  
  706.         bRes = TRUE;
  707.     }
  708.     catch (...)
  709.     {
  710.         TRACE_EXCEPTION("CTDialog::BeginDrag")
  711.         _clearfp();
  712.     }
  713.  
  714.     if (vMin != NULL)
  715.     {
  716.         vMin->Release();
  717.         vMin = NULL;
  718.     }
  719.     if (vMax != NULL)
  720.     {
  721.         vMax->Release();
  722.         vMax = NULL;
  723.     }
  724.     if (Box != NULL)
  725.     {
  726.         Box->Release();
  727.         Box = NULL;
  728.     }
  729.  
  730.     return bRes;
  731. }
  732.  
  733. BOOL CTDialog::Drag(const CPoint& point)
  734. {
  735.     BOOL bRes = FALSE;
  736.     if (m_pTCADView == NULL)
  737.         return bRes;
  738.  
  739.     try
  740.     {
  741.         VARIANT varState;
  742.         varState.vt = VT_I4;
  743.         varState.lVal = imsiDragContinue;
  744.         HRESULT hRes = m_pTCADView->DragOutline(&m_dragOutline, point.x, point.y, &varState);
  745.         CHECK_HRESULT(hRes)
  746.         bRes = TRUE;
  747.     }
  748.     catch (...)
  749.     {
  750.         TRACE_EXCEPTION("CTDialog::Drag")
  751.         _clearfp();
  752.     }
  753.     return bRes;
  754. }
  755.  
  756. BOOL CTDialog::EndDrag(const CPoint& point)
  757. {
  758.     BOOL bRes = FALSE;
  759.     m_bDragging = FALSE;
  760.     IMatrix *pMat = NULL;
  761.     if (m_pTCADView == NULL || m_pDragGraphic == NULL)
  762.         return bRes;
  763.  
  764.  
  765.     IDrawing *pIDwg = NULL;
  766.     Properties *pProps = NULL;
  767.     Property *pProp = NULL;
  768.  
  769.     try
  770.     {
  771.         VARIANT varState;
  772.         varState.vt = VT_I4;
  773.         varState.lVal = imsiDragEnd;
  774.         HRESULT hRes = m_pTCADView->DragOutline(&m_dragOutline, point.x, point.y, &varState);
  775.         CHECK_HRESULT(hRes)
  776.  
  777.         VariantClear(&m_dragOutline);
  778.  
  779.         double dx, dy, dz;
  780.         dx = dy = dz = 0;
  781.  
  782.         double dxWorld, dyWorld, dzWorld;
  783.         dxWorld = dyWorld = dzWorld = 0;
  784.  
  785.         hRes = m_pTCADView->ScreenToView(point.x, point.y, &dx, &dy);
  786.         CHECK_HRESULT(hRes)
  787.  
  788.         dxWorld = dx;
  789.         dyWorld = dy; 
  790.  
  791.         VARIANT var;
  792.         var.vt = VT_ERROR;
  793.         var.scode = DISP_E_PARAMNOTFOUND;
  794.  
  795.         CString cstrName("TileMode");//# Non-localizable string#
  796.         BSTR bstrName = cstrName.AllocSysString();
  797.  
  798.         VARIANT varItem;
  799.       ::VariantInit(&varItem);
  800.         varItem.vt = VT_BSTR;
  801.         varItem.bstrVal = bstrName;
  802.         hRes = m_pTCADView->get_Drawing(&pIDwg);
  803.         CHECK_HRESULT(hRes)
  804.         
  805.         hRes = pIDwg->get_Properties(&pProps);
  806.         CHECK_HRESULT(hRes)
  807.  
  808.         hRes = pProps->get_Item(&varItem, &pProp);
  809.         CHECK_HRESULT(hRes)
  810.  
  811.         COleVariant varVal;
  812.         varVal.vt = VT_I2;
  813.         hRes = pProp->get_Value(NULL, &varVal);
  814.         CHECK_HRESULT(hRes)
  815.  
  816.         if(varVal.iVal == imsiModelSpace) //ModelSpace
  817.         {
  818.             hRes = m_pTCADView->ViewToWorld(dx, dy, dz, &dxWorld, &dyWorld, &dzWorld);
  819.             CHECK_HRESULT(hRes)
  820.         }
  821.  
  822.         hRes = m_pDragGraphic->MoveAbsolute(dxWorld, dyWorld, 0, &var, &var, &var, &pMat);
  823.         CHECK_HRESULT(hRes)
  824.  
  825.         hRes = m_pDragGraphic->put_Visible(TRUE);
  826.         CHECK_HRESULT(hRes)
  827.  
  828.         bRes = TRUE;
  829.     }
  830.     catch (...)
  831.     {
  832.         TRACE_EXCEPTION("CTDialog::EndDrag")
  833.         _clearfp();
  834.     }
  835.  
  836.     if(pMat != NULL)
  837.     {
  838.         pMat->Release();
  839.         pMat = NULL;
  840.     }
  841.     
  842.     if (m_pDragGraphic != NULL)
  843.     {
  844.         m_pDragGraphic->Release();
  845.         m_pDragGraphic = NULL;
  846.     }
  847.  
  848.     if (pProp != NULL)
  849.     {
  850.         pProp->Release();
  851.         pProp = NULL;
  852.     }
  853.  
  854.     if (pProps != NULL)
  855.     {
  856.         pProps->Release();
  857.         pProps = NULL;
  858.     }
  859.     if (pIDwg != NULL)
  860.     {
  861.         pIDwg->Release();
  862.         pIDwg = NULL;
  863.     }
  864.  
  865.     return bRes;
  866. }
  867.  
  868. BOOL CTDialog::RestartDrag(const CPoint& point)
  869. {
  870.     try
  871.     {
  872.         m_bDragging = FALSE;
  873.         VARIANT varState;
  874.         varState.vt = VT_I4;
  875.         varState.lVal = imsiDragEnd;
  876.         HRESULT hRes = m_pTCADView->DragOutline(&m_dragOutline, point.x, point.y, &varState);
  877.         CHECK_HRESULT(hRes)
  878.  
  879.         VariantClear(&m_dragOutline);
  880.         BeginDrag(point);
  881.     }
  882.     catch (...)
  883.     {
  884.         TRACE_EXCEPTION("CTDialog::RestartDrag")
  885.         _clearfp();
  886.     }
  887.  
  888.     return TRUE;
  889. }
  890.  
  891. void CTDialog::OnBrowse()
  892. {
  893.  
  894.     CSymbolsList *pList = (CSymbolsList *)GetDlgItem(IDC_SYMBOLSLIST);
  895.     CPreviewWnd *pViewWnd = (CPreviewWnd *)GetDlgItem(IDC_PREVIEW);
  896.     CEdit *pPath = (CEdit *) GetDlgItem(IDC_EDITPATH);
  897.  
  898.     
  899.     CDirDialog* pDirDlg = new CDirDialog;
  900.     pDirDlg->m_strTitle.LoadString(IDS_STRING104);
  901.     pPath->GetWindowText(pDirDlg->m_strSelDir);     
  902.     CString strtmp;
  903.     pPath->GetWindowText(strtmp); 
  904.     int i = pDirDlg->DoBrowse (m_hWnd); 
  905.     if(i == 0)
  906.         return;
  907.     
  908.     HCURSOR hOC = ::SetCursor(::LoadCursor(NULL,IDC_WAIT));
  909.  
  910.     if (strtmp != pDirDlg->m_strPath)
  911.     {
  912.  
  913.         pPath->SetWindowText ((LPCTSTR) pDirDlg->m_strPath);
  914.         pViewWnd->ClearAll ();
  915.         pViewWnd->Invalidate ();
  916.         pList->RefreshFileList(pDirDlg->m_strPath);
  917.         if(pList->SetCurSel(0) != LB_ERR)
  918.         {
  919.  
  920.             pList->GetText(0 ,(pList->m_cstrCurSelected));
  921.             pViewWnd->CreatePreview();
  922.             pViewWnd->DoPreview();            
  923.         
  924.         }
  925.     }
  926.     ::SetCursor(hOC);
  927. }
  928.  
  929. void CTDialog::OnInsertsymb() 
  930. {
  931.     HRESULT hRes = E_FAIL;
  932.     IGraphic *pIGr = NULL;
  933.     IGraphic *pIGrTmp = NULL;
  934.     IDrawing *pActDr = NULL;
  935.     Graphics *pPreviewGrs = NULL;
  936.     Graphics *pGrs = NULL;
  937.     View *pActView = NULL;
  938.     COleVariant varItem = (0L);
  939.     COleVariant varOptional(varMissing);
  940.     CMerge merge;
  941.  
  942.     try
  943.     {
  944.             CPreviewWnd *pPreview = (CPreviewWnd *)GetDlgItem(IDC_PREVIEW);
  945.             if (m_pIApplication)
  946.             {
  947.                 hRes = m_pIApplication->get_ActiveDrawing(&pActDr);
  948.                 if (SUCCEEDED(hRes) && pActDr)
  949.                 {
  950.  
  951.                     hRes = pActDr->get_Graphics(&pGrs);
  952.                     if (SUCCEEDED(hRes) && pGrs)
  953.                     {
  954.  
  955.                         if (pPreview->m_pPreviewDrawing)
  956.                         {
  957.                             hRes = pPreview->m_pPreviewDrawing->get_Graphics(&pPreviewGrs);
  958.                             if (SUCCEEDED(hRes) && pPreviewGrs)
  959.                             {
  960.                                 
  961.                                 hRes = pPreviewGrs->get_Item(&varItem, &pIGrTmp);
  962.  
  963.                                 if (SUCCEEDED(hRes) && pIGrTmp)
  964.                                 {
  965.                                     hRes = pIGrTmp->Duplicate(&pIGr);
  966.                                     CHECK_HRESULT(hRes)
  967.                                     
  968.                                     RELEASE(pIGr)
  969.                                     RELEASE(pIGrTmp)
  970.  
  971.                                     long n;
  972.                                     n = 0;
  973.                                     hRes = pPreviewGrs->get_Count(&n);
  974.                                     if (SUCCEEDED(hRes))
  975.                                     {
  976.                                         varItem = n -1L;
  977.                                     }
  978.                                     hRes = pPreviewGrs->Remove(&varItem, &pIGr);
  979.                                     CHECK_HRESULT(hRes)
  980.                                     
  981.  
  982.                                     hRes = merge.InitA(pPreview->m_pPreviewDrawing, pActDr);
  983.                                     CHECK_HRESULT(hRes)
  984.  
  985.                                     hRes = merge.RunA();
  986.                                     CHECK_HRESULT(hRes)
  987.  
  988.                                     hRes = pIGr->put_ID(0);
  989.                     
  990.                                     hRes = pGrs->AddGraphic(pIGr, varOptional, varOptional);
  991.                                     CHECK_HRESULT(hRes)
  992.                                     
  993.                                     hRes = merge.CorrectGraphic(pIGr);
  994.                                     CHECK_HRESULT(hRes)
  995.  
  996.                                     hRes = pIGr->Update();
  997.                                     CHECK_HRESULT(hRes)
  998.  
  999.                                     RELEASE(pIGr);
  1000.                                     RELEASE(pIGrTmp)
  1001.                                     
  1002.                                     hRes = pActDr->get_ActiveView(&pActView);
  1003.                                     if (SUCCEEDED(hRes) && pActView)
  1004.                                     {
  1005.                                         pActView->Refresh();
  1006.                                         RELEASE(pActView);
  1007.                                     }
  1008.                                 
  1009.                                 }
  1010.                                 RELEASE(pPreviewGrs);
  1011.                             }                        
  1012.                         }
  1013.                         RELEASE(pGrs)
  1014.                     }
  1015.                     RELEASE(pActDr)
  1016.                 }        
  1017.             }
  1018.  
  1019.     }
  1020.     catch(...)
  1021.     {
  1022.         TRACE("void TDialog::OnInsertsymb() ");
  1023.     }
  1024.  
  1025.  
  1026.  
  1027. }
  1028.