1 #include "XGUI_Workshop.h"
2 #include "XGUI_MainWindow.h"
3 #include "XGUI_MainMenu.h"
4 #include "XGUI_Command.h"
5 #include "XGUI_Tools.h"
7 #include <QApplication>
18 XGUI_Workshop::XGUI_Workshop() :
21 myMainWindow = new XGUI_MainWindow();
24 //******************************************************
25 XGUI_Workshop::~XGUI_Workshop(void)
29 //******************************************************
30 void XGUI_Workshop::startApplication()
37 //******************************************************
38 void XGUI_Workshop::initMenu()
40 IWorkbench* aPage = addWorkbench(tr("HOME_MENU_TITLE"));
42 // File commands group
43 IMenuGroup* aGroup = aPage->addGroup();
45 IFeatureMenu* aCommand;
47 aCommand = aGroup->addFeature("NEW_CMD", tr("NEW_MENU"), tr("NEW_MENU_TIP"),
48 QIcon(":pictures/new.png"), QKeySequence::New);
49 aCommand->connectTo(this, SLOT(onNew()));
51 aCommand = aGroup->addFeature("OPEN_CMD", tr("OPEN_MENU"), tr("OPEN_MENU_TIP"),
52 QIcon(":pictures/open.png"), QKeySequence::Open);
53 aCommand->connectTo(this, SLOT(onOpen()));
55 aCommand = aGroup->addFeature("SAVE_CMD", tr("SAVE_MENU"), tr("SAVE_MENU_TIP"),
56 QIcon(":pictures/save.png"), QKeySequence::Save);
57 aCommand->connectTo(this, SLOT(onSave()));
61 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("SAVEAS_MENU"), tr("SAVEAS_MENU_TIP"),
62 QIcon(":pictures/save.png"));
63 aCommand->connectTo(this, SLOT(onSaveAs()));
66 // Edit commands group
67 //aGroup = aPage->addGroup();
69 aCommand = aGroup->addFeature("UNDO_CMD", tr("UNDO_MENU"), tr("UNDO_MENU_TIP"),
70 QIcon(":pictures/undo.png"), QKeySequence::Undo);
72 aCommand = aGroup->addFeature("REDO_CMD", tr("REDO_MENU"), tr("REDO_MENU_TIP"),
73 QIcon(":pictures/redo.png"), QKeySequence::Redo);
75 aCommand = aGroup->addFeature("REBUILD_CMD", tr("REBUILD_MENU"), tr("REBUILD_MENU_TIP"),
76 QIcon(":pictures/rebuild.png"));
78 aCommand = aGroup->addFeature("EXIT_CMD", tr("EXIT_MENU"), tr("EXIT_MENU_TIP"),
79 QIcon(":pictures/close.png"), QKeySequence::Close);
80 aCommand->connectTo(this, SLOT(onExit()));
84 //******************************************************
85 IWorkbench* XGUI_Workshop::addWorkbench(const QString& theName)
87 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
88 return aMenuBar->addWorkbench(theName);
91 //******************************************************
92 void XGUI_Workshop::onExit()
97 //******************************************************
98 void XGUI_Workshop::onNew()
100 myMainWindow->showObjectBrowser();
103 //******************************************************
104 void XGUI_Workshop::onOpen()
106 QString aFileName = QFileDialog::getOpenFileName(mainWindow());
109 //******************************************************
110 void XGUI_Workshop::onSave()
114 //******************************************************
115 void XGUI_Workshop::onSaveAs()
117 QString aFileName = QFileDialog::getSaveFileName(mainWindow());
120 //******************************************************
121 IModule* XGUI_Workshop::loadModule(const QString& theModule)
123 QString libName = library( theModule );
124 if ( libName.isEmpty() )
126 qWarning( qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) ) );
131 CREATE_FUNC crtInst = 0;
135 HINSTANCE modLib = ::LoadLibrary( (LPTSTR) qPrintable(libName) );
139 ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
140 FORMAT_MESSAGE_IGNORE_INSERTS, 0, ::GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, 0 );
141 QString aMsg((char*)&lpMsgBuf);
142 err = QString( "Failed to load %1. %2" ).arg( libName ).arg( aMsg );
143 ::LocalFree( lpMsgBuf );
147 crtInst = (CREATE_FUNC)::GetProcAddress( modLib, CREATE_MODULE );
151 ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
152 FORMAT_MESSAGE_IGNORE_INSERTS, 0, ::GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, 0 );
153 QString aMsg((char*)&lpMsgBuf);
154 err = QString( "Failed to find %1 function. %2" ).arg( CREATE_MODULE ).arg(aMsg );
155 ::LocalFree( lpMsgBuf );
159 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY );
161 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
164 crtInst = (CREATE_FUNC)dlsym( modLib, GET_MODULE_NAME );
166 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
170 IModule* aModule = crtInst ? crtInst(this) : 0;
172 if ( !err.isEmpty() ) {
173 if ( mainWindow() && mainWindow()->isVisible() )
174 QMessageBox::warning( mainWindow(), tr( "Error" ), err );
176 qWarning( qPrintable( err ) );
181 //******************************************************
182 bool XGUI_Workshop::activateModule()
184 // Test of modules loading
185 IModule* aModule = loadModule("GeomModule");
188 aModule->createFeatures();