Vector Load and Save

Start with the project you created in Tutorial 1: Implementing Vector Automation

Take the following steps to add vector load and save functionality:

  1. Click on the "Class View" Tab.

  2. Right-click on the CVecAutDoc branch and select Properties.

  3. Click on the "Override" button of the Properties toolbar.

  4. Click on the empty area next to OnOpenDocument then click on the arrow and select "OnOpenDocument".

  5. Add the following code to CVecAutDoc::OnOpenDocument():

    BOOL CVecAutDoc::OnOpenDocument(LPCTSTR lpszPathName) 
    { 
       L_TCHAR szTemp[_MAX_PATH]; 
       L_BOOL bRet; 
       L_INT  nRet; 
       if (!CDocument::OnOpenDocument(lpszPathName)) 
          return FALSE; 
       lstrcpy(szTemp, lpszPathName); 
       nRet = m_VectorWindow. Load (szTemp); 
       if (nRet == SUCCESS) 
       { 
          m_VectorWindow. EnableAutoScroll (TRUE); 
          m_VectorWindow. Reset (); 
       } 
       else 
       { 
          CString strTmp; 
          strTmp.Format(TEXT("Error Loading File[%d]"), nRet); 
          AfxMessageBox(strTmp); 
          bRet = FALSE; 
       } 
       return bRet; 
    } 

  6. Click on the "Class View" Tab.

  7. Right-click on the CvecAutDoc branch and select Properties.

  8. Click on the "Override" button of the Properties toolbar.

  9. Click on the empty area next to OnSaveDocument then click on the arrow and select "OnSaveDocument".

  10. Add the following code to CTutorialDoc::OnSaveDocument():

    BOOL CVecAutDoc::OnSaveDocument(LPCTSTR lpszPathName) 
    { 
       L_TCHAR       szFileName[_MAX_PATH]; 
       L_INT        nRet = 0; 
        
       lstrcpy(szFileName, lpszPathName); 
        
       //Apply any transformation before the save 
       m_VectorWindow. ApplyTransformation(); 
       nRet = m_VectorWindow. Save ( szFileName, m_iFileSaveType); 
       if (nRet != SUCCESS) 
       { 
          CString strTmp; 
           
          strTmp.Format(TEXT("Error Saving File[%d]"), nRet); 
          AfxMessageBox(strTmp); 
       } 
        
       if (nRet == SUCCESS) 
          SetModifiedFlag(FALSE); 
       return (nRet == SUCCESS); 
    } 

  11. Click on the "Class View" tab, right-click CVecAutDoc, and choose Add "Add Variable..."

  12. For "Variable Type" enter:

    L_INT 

  13. For "Variable Name" enter:

    m_iFileSaveType 

  14. Leave "Access" as public and click "Ok".

  15. Open "Resource View" tab. And double click IDR_MAINFRAME menu. Then From "File" menu, right click on "Save" item, and choose "Add Event Handler"

  16. In the Class Name drop down box, select CVecAutView.

  17. In the Messages drop down box, select COMMAND.

  18. Click the Add And Edit button.

  19. Add the following code to CVecAutView::OnFileSave():

    void CVecAutView::OnFileSave() 
    { 
       L_TCHAR szSaveFileFilter[_MAX_PATH]; 
       L_UINT uNotUsed; 
       L_TCHAR szFileName[_MAX_PATH], *pszFileName; 
       L_INT  nRet; 
       lstrcpy((LPTSTR)szSaveFileFilter, TEXT("DXF(*.dxf)|*.dxf|WMF(*.wmf)|*.wmf|EMF(*.emf)|*.emf|DRW(*.drw)|*.drw|CGM(*.cgm)|*.cgm|PLT(*.plt)|*.plt|PCT(*.pct)|*.pct|Intergraph Vector(*.vec)|*.vec|TIF DXF(*.tif)|*.tif||")); 
       nRet = GetDocument()->m_VectorWindow. GetFileName (szFileName, &uNotUsed); 
       pszFileName = (nRet == SUCCESS) ? szFileName : NULL; 
       CFileDialog SaveDialog( 
       FALSE, 
       TEXT("dxf"), 
       (LPCTSTR)pszFileName, 
       OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 
       (LPCTSTR)szSaveFileFilter, 
       this 
       ); 
       nRet = (L_INT)SaveDialog.DoModal(); 
       if (IDOK == nRet) 
       { 
          CString strFilename; 
          strFilename = SaveDialog.GetPathName(); 
          L_INT nIndex = SaveDialog.m_ofn.nFilterIndex; 
          switch (nIndex) 
          { 
             case 1: 
             GetDocument()->m_iFileSaveType = FILE_DXF; 
             break; 
             case 2: 
             GetDocument()->m_iFileSaveType = FILE_WMF; 
             break; 
             case 3: 
             GetDocument()->m_iFileSaveType = FILE_EMF; 
             break; 
             case 4: 
             GetDocument()->m_iFileSaveType = FILE_DRW; 
             break; 
              
             case 5 : 
             GetDocument()->m_iFileSaveType = FILE_CGM; 
             break; 
              
             case 6: 
             GetDocument()->m_iFileSaveType = FILE_PLT; 
             break; 
              
             case 7: 
             GetDocument()->m_iFileSaveType = FILE_PCT; 
             break; 
              
             case 8: 
             GetDocument()->m_iFileSaveType = FILE_INTERGRAPH_VECTOR; 
             break; 
              
             case 9: 
             GetDocument()->m_iFileSaveType = FILE_TIF_DXF; 
             break; 
              
          } 
          GetDocument()->OnSaveDocument(strFilename); 
       } 
    } 

  20. Open "Resource View" tab. And double click IDR_MAINFRAME menu. Then From "File" menu, right click on "Save As" item, and choose "Add Event Handler"

  21. In the Class Name drop down box, select CVecAutView.

  22. In the Messages drop down box, select COMMAND.

  23. Click the "Add and Edit"

  24. Add the following code to CVecAutView::OnFileSaveAs():

    void CVecAutView::OnFileSaveAs() 
    { 
       OnFileSave(); 
    } 

  25. Compile and run the project. You will be able to view, load and save vector files as you browse your local hard disk. You can also use the numeric keypad to zoom in (+ key) and zoom out (- key).

Help Version 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Container and Automation C++ Class Library Help