void PartSet_Module::featureCreated(XGUI_Command* theFeature)
{
- QString aFtId = theFeature->getId();
+ QString aFtId = theFeature->id();
theFeature->connectTo(this, SLOT(onFeatureTriggered()));
}
Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginName);
aWdgReader.readAll();
XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
- QString aCmdId = aCmd->getId();
+ QString aCmdId = aCmd->id();
std::string aXmlCfg = aWdgReader.featureWidgetCfg(aCmdId.toStdString());
//TODO(sbh): Implement static method to extract event id [SEID]
static Event_ID aModuleEvent = Event_Loop::eventByName("PartSetModuleEvent");
virtual void disable();
//! Returns Id of the command
- virtual QString getId() const
+ virtual QString id() const
{
return myId;
}
#include <QTabWidget>
#include <QLabel>
#include <QDockWidget>
+#include <QEvent>
XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent)
: QObject(parent), myDesktop(parent)
{
parent->setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North);
myGeneralPage = addWorkbench(tr("General"));
+ myGeneralPage->parentWidget()->setMaximumWidth(200);
+ myGeneralPage->installEventFilter(this);
}
XGUI_MainMenu::~XGUI_MainMenu(void)
{
return myDesktop->findChild<XGUI_Workbench*>(theObjName);
}
+
+
+bool XGUI_MainMenu::eventFilter(QObject *theWatched, QEvent *theEvent)
+{
+ if (theWatched == myGeneralPage) {
+ if (theEvent->type() == QEvent::Show) {
+ myGeneralPage->parentWidget()->setMaximumWidth(16777215);
+ myGeneralPage->removeEventFilter(this);
+ }
+ }
+ return QObject::eventFilter(theWatched, theEvent);
+}
+
+XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const
+{
+ QList<QDockWidget*>::const_iterator aIt;
+ for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) {
+ XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>((*aIt)->widget());
+ XGUI_Command* aCmd = aWbn->feature(theId);
+ if (aCmd)
+ return aCmd;
+ }
+ return 0;
+}
+
+QList<XGUI_Command*> XGUI_MainMenu::features() const
+{
+ QList<XGUI_Command*> aList;
+ QList<QDockWidget*>::const_iterator aIt;
+ for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) {
+ XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>((*aIt)->widget());
+ aList.append(aWbn->features());
+ }
+ return aList;
+}
\ No newline at end of file
class QLabel;
class QAction;
class QDockWidget;
+class QEvent;
/**\class XGUI_MainMenu
* \ingroup GUI
//! Rerturns last created workbench in dock widget container
QDockWidget* getLastDockWindow() const { return myMenuTabs.last(); }
+ //! Returns already created command by its ID
+ XGUI_Command* feature(const QString& theId) const;
+
+ //! Returns list of created commands
+ QList<XGUI_Command*> features() const;
+
+protected:
+ virtual bool eventFilter(QObject *theWatched, QEvent *theEvent);
+
private:
XGUI_MainWindow* myDesktop;
QList<QDockWidget*> myMenuTabs;
XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
: QMainWindow(parent),
- myObjectBrowser(NULL),
- myPythonConsole(NULL),
- myPropertyPanelDock(NULL)
+ myObjectBrowser(0),
+ myPythonConsole(0),
+ myPropertyPanelDock(0)
{
setWindowTitle(tr("New Geom"));
myMenuBar = new XGUI_MainMenu(this);
myViewer = new XGUI_Viewer(this);
- createDockWidgets();
+ //createDockWidgets();
}
XGUI_MainWindow::~XGUI_MainWindow(void)
aDoc->setMinimumHeight(0);
aDoc->setWindowTitle("Console");
myPythonConsole = new PyConsole_EnhConsole( aDoc, new PyConsole_EnhInterp());
- //myPythonConsole = new QTextEdit(aDoc);
- //myPythonConsole->setGeometry(0,0,200, 50);
- //myPythonConsole->setText(">>>");
aDoc->setWidget(myPythonConsole);
- //myPythonConsole->setMinimumHeight(0);
addDockWidget(Qt::TopDockWidgetArea, aDoc);
tabifyDockWidget(myMenuBar->getLastDockWindow(), aDoc);
}
return myViewer;
}
+ // Creates Dock widgets: Object broewser and Property panel
+ void createDockWidgets();
+
public slots:
void showPythonConsole();
void hidePythonConsole();
void hideObjectBrowser();
private:
- void createDockWidgets();
QDockWidget* createObjectBrowser();
QDockWidget* createPropertyPanel();
addCommand(aCommand);
return aCommand;
}
+
+
+XGUI_Command* XGUI_MenuGroupPanel::feature(const QString& theId) const
+{
+ QList<XGUI_Command*>::const_iterator aIt;
+ for (aIt = myActions.constBegin(); aIt != myActions.constEnd(); ++aIt)
+ if ((*aIt)->id() == theId)
+ return (*aIt);
+ return 0;
+}
\ No newline at end of file
XGUI_Command* addFeature(const QString& theId, const QString& theTitle, const QString& theTip,
const QIcon& theIcon, const QKeySequence& theKeys = QKeySequence());
+ //! Returns already created command by its ID
+ XGUI_Command* feature(const QString& theId) const;
+
+ //! Returns list of created commands
+ QList<XGUI_Command*> features() const { return myActions; }
+
protected:
virtual void resizeEvent(QResizeEvent *theEvent);
}
}
return QWidget::eventFilter(theObj, theEvent);
+}
+
+XGUI_Command* XGUI_Workbench::feature(const QString& theId) const
+{
+ QList<XGUI_MenuGroupPanel*>::const_iterator aIt;
+ for (aIt = myGroups.constBegin(); aIt != myGroups.constEnd(); ++aIt) {
+ XGUI_Command* aCmd = (*aIt)->feature(theId);
+ if (aCmd)
+ return aCmd;
+ }
+ return 0;
+}
+
+QList<XGUI_Command*> XGUI_Workbench::features() const
+{
+ QList<XGUI_Command*> aList;
+ QList<XGUI_MenuGroupPanel*>::const_iterator aIt;
+ for (aIt = myGroups.constBegin(); aIt != myGroups.constEnd(); ++aIt)
+ aList.append((*aIt)->features());
+ return aList;
}
\ No newline at end of file
XGUI_MenuGroupPanel* addGroup(const QString& theId);
XGUI_MenuGroupPanel* findGroup(const QString& theName);
+ //! Returns already created command by its ID
+ XGUI_Command* feature(const QString& theId) const;
+
+ //! Returns list of created commands
+ QList<XGUI_Command*> features() const;
+
private slots:
void onLeftScroll();
void onRightScroll();
virtual void resizeEvent(QResizeEvent * theEvent);
virtual bool eventFilter(QObject *theObj, QEvent *theEvent);
+
private:
void addSeparator();
bool isExceedsLeft();
activateModule();
myMainWindow->show();
+ updateCommandStatus();
// Testing of document creation
//std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
//std::shared_ptr<ModelAPI_Feature> aPoint1 = aMgr->rootDocument()->addFeature("Point");
aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
QIcon(":pictures/undo.png"), QKeySequence::Undo);
+ aCommand->connectTo(this, SLOT(onUndo()));
aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
QIcon(":pictures/redo.png"), QKeySequence::Redo);
+ aCommand->connectTo(this, SLOT(onRedo()));
aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
QIcon(":pictures/rebuild.png"));
if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel
myCurrentOperation->start();
myCurrentOperation->commit();
+ updateCommandStatus();
} else {
fillPropertyPanel(aOperation);
}
void XGUI_Workshop::onNew()
{
QApplication::setOverrideCursor(Qt::WaitCursor);
+ if (myMainWindow->objectBrowser() == 0)
+ myMainWindow->createDockWidgets();
myMainWindow->showObjectBrowser();
myMainWindow->showPythonConsole();
QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
aWnd->showMaximized();
+ updateCommandStatus();
QApplication::restoreOverrideCursor();
}
//******************************************************
void XGUI_Workshop::onOpen()
{
- QString aFileName = QFileDialog::getOpenFileName(mainWindow());
+ //QString aFileName = QFileDialog::getOpenFileName(mainWindow());
+ updateCommandStatus();
}
//******************************************************
void XGUI_Workshop::onSave()
{
+ updateCommandStatus();
}
//******************************************************
void XGUI_Workshop::onSaveAs()
{
- QString aFileName = QFileDialog::getSaveFileName(mainWindow());
+ //QString aFileName = QFileDialog::getSaveFileName(mainWindow());
+ updateCommandStatus();
}
+//******************************************************
+void XGUI_Workshop::onUndo()
+{
+ std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+ std::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
+ aDoc->undo();
+ updateCommandStatus();
+}
+
+//******************************************************
+void XGUI_Workshop::onRedo()
+{
+ std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+ std::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
+ aDoc->redo();
+ updateCommandStatus();
+}
+
+
//******************************************************
XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule)
{
myPartSetModule->createFeatures();
return true;
}
+
+//******************************************************
+void XGUI_Workshop::updateCommandStatus()
+{
+ XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
+
+ QList<XGUI_Command*> aCommands = aMenuBar->features();
+ QList<XGUI_Command*>::const_iterator aIt;
+
+ std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+ if (aMgr->hasRootDocument()) {
+ XGUI_Command* aUndoCmd;
+ XGUI_Command* aRedoCmd;
+ for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) {
+ if ((*aIt)->id() == "UNDO_CMD")
+ aUndoCmd = (*aIt);
+ else if ((*aIt)->id() == "REDO_CMD")
+ aRedoCmd = (*aIt);
+ else // Enable all commands
+ (*aIt)->enable();
+ }
+ std::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
+ aUndoCmd->setEnabled(aDoc->canUndo());
+ aRedoCmd->setEnabled(aDoc->canRedo());
+ } else {
+ for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) {
+ if ((*aIt)->id() == "NEW_CMD")
+ (*aIt)->enable();
+ else if ((*aIt)->id() == "EXIT_CMD")
+ (*aIt)->enable();
+ else
+ (*aIt)->disable();
+ }
+ }
+}
\ No newline at end of file
virtual void processEvent(const Event_Message* theMessage);
public slots:
+ void updateCommandStatus();
+
void onNew();
void onOpen();
void onSave();
void onSaveAs();
void onExit();
+ void onUndo();
+ void onRedo();
protected:
//Event-loop processing methods: