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("GEN_MENU_TITLE"));
42 // File commands group
43 IMenuGroup* aGroup = aPage->addGroup();
45 IFeatureMenu* aCommand;
47 aCommand = aGroup->addFeature("SAVE_CMD", tr("SAVE_MENU"), tr("SAVE_MENU_TIP"),
48 QIcon(":pictures/save.png"), QKeySequence::Save);
49 aCommand->connectTo(this, SLOT(onSave()));
50 //aCommand->disable();
52 aCommand = aGroup->addFeature("UNDO_CMD", tr("UNDO_MENU"), tr("UNDO_MENU_TIP"),
53 QIcon(":pictures/undo.png"), QKeySequence::Undo);
55 aCommand = aGroup->addFeature("REDO_CMD", tr("REDO_MENU"), tr("REDO_MENU_TIP"),
56 QIcon(":pictures/redo.png"), QKeySequence::Redo);
58 aCommand = aGroup->addFeature("REBUILD_CMD", tr("REBUILD_MENU"), tr("REBUILD_MENU_TIP"),
59 QIcon(":pictures/rebuild.png"));
61 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("SAVEAS_MENU"), tr("SAVEAS_MENU_TIP"),
62 QIcon(":pictures/save.png"));
63 aCommand->connectTo(this, SLOT(onSaveAs()));
64 //aCommand->disable();
66 aCommand = aGroup->addFeature("OPEN_CMD", tr("OPEN_MENU"), tr("OPEN_MENU_TIP"),
67 QIcon(":pictures/open.png"), QKeySequence::Open);
68 aCommand->connectTo(this, SLOT(onOpen()));
71 aCommand = aGroup->addFeature("NEW_CMD", tr("NEW_MENU"), tr("NEW_MENU_TIP"),
72 QIcon(":pictures/new.png"), QKeySequence::New);
73 aCommand->connectTo(this, SLOT(onNew()));
75 aCommand = aGroup->addFeature("EXIT_CMD", tr("EXIT_MENU"), tr("EXIT_MENU_TIP"),
76 QIcon(":pictures/close.png"), QKeySequence::Close);
77 aCommand->connectTo(this, SLOT(onExit()));
81 //******************************************************
82 IWorkbench* XGUI_Workshop::addWorkbench(const QString& theName)
84 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
85 return aMenuBar->addWorkbench(theName);
88 //******************************************************
89 void XGUI_Workshop::onExit()
94 //******************************************************
95 void XGUI_Workshop::onNew()
97 myMainWindow->showObjectBrowser();
100 //******************************************************
101 void XGUI_Workshop::onOpen()
103 QString aFileName = QFileDialog::getOpenFileName(mainWindow());
106 //******************************************************
107 void XGUI_Workshop::onSave()
111 //******************************************************
112 void XGUI_Workshop::onSaveAs()
114 QString aFileName = QFileDialog::getSaveFileName(mainWindow());
117 //******************************************************
118 IModule* XGUI_Workshop::loadModule(const QString& theModule)
120 QString libName = library( theModule );
121 if ( libName.isEmpty() )
123 qWarning( qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) ) );
128 CREATE_FUNC crtInst = 0;
132 HINSTANCE modLib = ::LoadLibrary( (LPTSTR) qPrintable(libName) );
136 ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
137 FORMAT_MESSAGE_IGNORE_INSERTS, 0, ::GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, 0 );
138 QString aMsg((char*)&lpMsgBuf);
139 err = QString( "Failed to load %1. %2" ).arg( libName ).arg( aMsg );
140 ::LocalFree( lpMsgBuf );
144 crtInst = (CREATE_FUNC)::GetProcAddress( modLib, CREATE_MODULE );
148 ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
149 FORMAT_MESSAGE_IGNORE_INSERTS, 0, ::GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, 0 );
150 QString aMsg((char*)&lpMsgBuf);
151 err = QString( "Failed to find %1 function. %2" ).arg( CREATE_MODULE ).arg(aMsg );
152 ::LocalFree( lpMsgBuf );
156 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY );
158 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
161 crtInst = (CREATE_FUNC)dlsym( modLib, GET_MODULE_NAME );
163 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
167 IModule* aModule = crtInst ? crtInst(this) : 0;
169 if ( !err.isEmpty() ) {
170 if ( mainWindow() && mainWindow()->isVisible() )
171 QMessageBox::warning( mainWindow(), tr( "Error" ), err );
173 qWarning( qPrintable( err ) );
178 //******************************************************
179 bool XGUI_Workshop::activateModule()
181 // Test of modules loading
182 IModule* aModule = loadModule("GeomModule");
185 aModule->createFeatures();