// Vector.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "Vector.h" #include "MainFrm.h" #include "ChildFrm.h" #include "VecDoc.h" #include "VecView.h" #include "VecDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CVectorApp BEGIN_MESSAGE_MAP(CVectorApp, CWinApp) //{{AFX_MSG_MAP(CVectorApp) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) ON_UPDATE_COMMAND_UI(ID_VIEW_VECTORTOOLBAR, OnUpdateViewVectortoolbar) ON_COMMAND(ID_VIEW_VECTORTOOLBAR, OnViewVectortoolbar) ON_COMMAND(ID_PREFERENCES_VECTORTOOLBARCOLOR, OnPreferencesVectortoolbarcolor) ON_COMMAND(ID_FILE_OPEN, OnFileOpen) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_VECTORTOOLBARCOLOR, OnUpdatePreferencesVectortoolbarcolor) ON_UPDATE_COMMAND_UI(ID_FILE_NEW, OnUpdateFileNew) ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave) ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs) //}}AFX_MSG_MAP // Standard file based document commands ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) // Standard print setup command ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CVectorApp construction L_UINT uLibs = LT_KRN|LT_FIL|LV_KRN|LV_DLG|LT_TLB|LT_AUT|LT_CON|LT_DLG; CVectorApp::CVectorApp() { m_bSupportLocked = FALSE; m_nOpenIndex = 0; L_UINT uLibsLoaded = LBase::LoadLibraries(uLibs); if((uLibsLoaded & uLibs) != uLibs) { AfxMessageBox(TEXT("Not all LEAD libraries could be loaded!\n")); m_bSupportLocked = TRUE; } // Unlock support here, must at least unlock L_SUPPORT_VECTOR or L_SUPPORT_VECTOR_VIEW WRPUNLOCKSUPPORT(); if (LSettings::IsSupportLocked(L_SUPPORT_VECTOR)) { if (LSettings::IsSupportLocked(L_SUPPORT_VECTOR)) { AfxMessageBox(TEXT("Vector Support Is Locked!")); m_bSupportLocked = TRUE; } else m_bViewOnly = TRUE; // View only mode! } else m_bViewOnly = FALSE; // Edit mode! m_bUseAutomation = !m_bViewOnly; } ///////////////////////////////////////////////////////////////////////////// // The one and only CVectorApp object CVectorApp theApp; ///////////////////////////////////////////////////////////////////////////// // CVectorApp initialization BOOL CVectorApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Change the registry key under which our settings are stored. // TODO: You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate( IDR_VECTORTYPE, RUNTIME_CLASS(CVectorDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CVectorView)); AddDocTemplate(pDocTemplate); // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); //Don't create a document at startup cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing; // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // The main window has been initialized, so show and update it. pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); if (m_bSupportLocked) return FALSE; ((CMainFrame *)AfxGetMainWnd())->DragAcceptFiles(TRUE); LDialogBase::Initialize(DLG_INIT_COLOR); return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) // No message handlers //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() // App command to run the dialog void CVectorApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } ///////////////////////////////////////////////////////////////////////////// // CVectorApp message handlers CVectorApp::~CVectorApp() { LDialogBase::Free(); LSettings::UnloadLibraries(uLibs); } void CVectorApp::OnUpdateViewVectortoolbar(CCmdUI* pCmdUI) { if (m_bUseAutomation) { pCmdUI->Enable(TRUE); pCmdUI->SetCheck(m_Toolbar.IsVisible()); } else { pCmdUI->Enable(FALSE); pCmdUI->SetCheck(FALSE); } } void CVectorApp::OnPreferencesVectortoolbarcolor() { AUTOMATIONVECTORPROPERTIES AutVecProps; COLORDLGPARAMS DlgParams; LDialogColor DlgClr; //Get current automation PEN properties AutVecProps.nSize = sizeof(AUTOMATIONVECTORPROPERTIES); AutVecProps.dwMask = AUTOMATION_VECTOR_PEN; m_Automation.GetVectorProperty(&AutVecProps); //Display color picker dialog to select new color DlgParams.crColor = AutVecProps.Pen.NewPen.ExtLogPen.elpColor ;// LogPen.lopnColor; DlgParams.uColorSpace = DLG_COLOR_COLORSPACE_SHOW_RGB; DlgParams.uColorModel = 0; DlgParams.uStructSize = sizeof( COLORDLGPARAMS ); DlgParams.uDlgFlags = (DLG_COLOR_SHOW_OLDCOLOR | DLG_COLOR_SHOW_NEWCOLOR | DLG_COLOR_SHOW_NAME | DLG_COLOR_COLORSPACE_SHOW_HUE | DLG_COLOR_COLORSPACE_SHOW_BRIGHTNESS | DLG_COLOR_COLORSPACE_SHOW_WHEEL | DLG_COLOR_COLORSPACE_SHOW_RGB | DLG_COLOR_COLORSPACE_SHOW_CMY | DLG_COLOR_COLORSPACE_SHOW_CMYK | DLG_COLOR_COLORSPACE_SHOW_LAB | DLG_COLOR_COLORMODEL_SHOW_RGB | DLG_COLOR_COLORMODEL_SHOW_HSB | DLG_COLOR_COLORMODEL_SHOW_HLS | DLG_COLOR_COLORMODEL_SHOW_CMY | DLG_COLOR_COLORMODEL_SHOW_CMYK | DLG_COLOR_COLORMODEL_SHOW_LAB ); DlgClr.SetColorParams (&DlgParams); if (SUCCESS_DLG_OK == DlgClr.DoModalColor (AfxGetApp()->GetMainWnd()->m_hWnd)) { DlgClr.GetColorParams(&DlgParams,sizeof(COLORDLGPARAMS)); AutVecProps.Pen.NewPen.ExtLogPen.elpColor = DlgParams.crColor ; } m_Automation.SetVectorProperty(&AutVecProps); } void CVectorApp::OnViewVectortoolbar() { L_BOOL bVisible; bVisible = m_Toolbar.IsVisible(); m_Toolbar.SetVisible(!bVisible); } L_VOID CVectorApp::StartAutomation(HWND hWnd, LPPOINT pToolbarPoint) { m_Automation.Initialize(); m_Automation.Create(AUTOMATION_MODE_VECTOR); m_Toolbar.Initialize(); m_Toolbar.Create(hWnd, TEXT("Vector"), TOOLBAR_VECTOR); m_Toolbar.SetRows(8); m_Toolbar.SetPosition( pToolbarPoint, TOOLBAR_POSITION_TOP | TOOLBAR_POSITION_LEFT ); m_Automation.SetToolbar(&m_Toolbar); m_Toolbar.SetVisible(TRUE); } L_VOID CVectorApp::StopAutomation() { if (m_Automation.IsValid()) { m_Toolbar.Free(); m_Automation.Free(); } } void CVectorApp::OnFileOpen() { // TODO: Add your command handler code here //AfxMessageBox( "here!" ); static L_TCHAR szFilter[] = TEXT( "All Files (*.*)|" ) TEXT( "*.*|" ) TEXT( "AutoCAD (*.dxf;*.dwg;*.dwf)|" ) TEXT( "*.dxf;*.dwg;*.dwf|" ) TEXT( "Computer Graphics Metafile (*.cgm)|" ) TEXT( "*.cgm|" ) TEXT( "Corel Presentation Exchange (CMX)|" ) TEXT( "*.cmx|" ) TEXT( "HP-GL/HP-GL2 (*.plt)|" ) TEXT( "*.plt|" ) TEXT( "LEAD Vector (*.vec)|" ) TEXT( "*.vec|" ) TEXT( "Mac PICT (*.pct)|" ) TEXT( "*.pct|" ) TEXT( "Micrografx DRW (*.drw)|" ) TEXT( "*.drw|" ) TEXT( "MicroStation DGN (*.dgn)|" ) TEXT( "*.dgn|" ) TEXT( "Windows Metafile (*.wmf;*.emf)|" ) TEXT( "*.wmf;*.emf|" ) TEXT( "Gerber File Format (*.gbr)|" ) TEXT( "*.gbr|" ) TEXT( "ESRI (*.shp)|" ) TEXT( "*.shp|" ) TEXT( "Printer Command Language(*.pcl;*.prn;*.prt)|" ) TEXT( "*.pcl;*.prn;*.prt|" ) TEXT( "Scalable Vector Graphics (*.svg)|" ) TEXT( "*.svg|" ) TEXT( "Word Perfect Graphics (*.wpg)|" ) TEXT( "*.wpg|" ) TEXT( "Compressed Windows Metafile (WMZ)|") TEXT( "*.wmz||" ); CFileDialog FileDialog( TRUE, NULL, NULL, OFN_HIDEREADONLY, szFilter ); FileDialog.m_ofn.nFilterIndex = m_nOpenIndex; if( FileDialog.DoModal() == IDOK ) { m_nOpenIndex = FileDialog.m_ofn.nFilterIndex; CWinApp::OpenDocumentFile( FileDialog.GetPathName() ); } } void CVectorApp::OnUpdatePreferencesVectortoolbarcolor(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bViewOnly); } void CVectorApp::OnUpdateFileNew(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bViewOnly); } void CVectorApp::OnUpdateFileSave(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bViewOnly); } void CVectorApp::OnUpdateFileSaveAs(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bViewOnly); }