Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / XGUI / XGUI_MainWindow.cpp
index 729f1869bcc76703835c51436da5703481cb1a41..b675c5fd7d59639c83e5075dec96d6d27092df76 100644 (file)
@@ -1,15 +1,20 @@
 #include "XGUI_MainWindow.h"
+#include "XGUI_Constants.h"
 #include "XGUI_MainMenu.h"
+#include "XGUI_ViewWindow.h"
+#include "XGUI_Viewer.h"
+#include "XGUI_ObjectsBrowser.h"
+
+#include <PyConsole_Console.h>
+#include <PyConsole_EnhInterp.h>
 
 #include <QMdiArea>
 #include <QTreeWidget>
 #include <QDockWidget>
 #include <QTextEdit>
-#include <QMdiSubWindow>
 #include <QLabel>
 #include <QToolBar>
 #include <QToolButton>
-#include <QAction>
 #include <QTreeWidgetItem>
 #include <QLayout>
 #include <QLineEdit>
 #include <QFormLayout>
 #include <QDoubleSpinBox>
 #include <QPushButton>
+#include <QScrollArea>
+#include <QComboBox>
+#include <QAction>
 
-XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) :
-    QMainWindow(parent), myObjectBrowser(0)
+XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
+    : QMainWindow(parent), 
+    myObjectBrowser(0),
+    myPythonConsole(0),
+    myPropertyPanelDock(0)
 {
-    //menuBar();
-    myMenuBar = new XGUI_MainMenu(this);
+  setWindowTitle(tr("New Geom"));
+  myMenuBar = new XGUI_MainMenu(this);
 
-    QDockWidget* aDoc = new QDockWidget(this);
-    aDoc->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
-    aDoc->setWindowTitle(tr("OBJECT_BROWSER_TITLE"));
-    myObjectBrowser = new QTreeWidget(aDoc);
-    myObjectBrowser->setColumnCount(1);
-    myObjectBrowser->setHeaderHidden(true);
-    aDoc->setWidget(myObjectBrowser);
-    addDockWidget(Qt::LeftDockWidgetArea, aDoc);
-    //aDoc->hide();
-
-    aDoc = new QDockWidget(this);
-    aDoc->setFeatures(QDockWidget::AllDockWidgetFeatures | QDockWidget::DockWidgetVerticalTitleBar);
-    aDoc->setMinimumHeight(20);
-    aDoc->setWindowTitle("Console");
-    QTextEdit* aTextEdt = new QTextEdit(aDoc);
-    aTextEdt->setText(">>>");
-    aTextEdt->setMinimumHeight(20);
-    aDoc->setWidget(aTextEdt);
-    addDockWidget(Qt::BottomDockWidgetArea, aDoc);
-
-    QMdiArea* aMdiArea = new QMdiArea(this);
-    setCentralWidget(aMdiArea);
+  QMdiArea* aMdiArea = new QMdiArea(this);
+  setCentralWidget(aMdiArea);
 
-    aMdiArea->addSubWindow(getSubWindow(), Qt::FramelessWindowHint);
+  myViewer = new XGUI_Viewer(this);
 
-    fillObjectBrowser();
-    addPropertyPanel();
+  //createDockWidgets();
 }
 
-
-QWidget* XGUI_MainWindow::getSubWindow()
+XGUI_MainWindow::~XGUI_MainWindow(void)
 {
-    QMdiSubWindow* aSub = new QMdiSubWindow(this);
-    aSub->setGeometry(0,0, 600, 400);
-    QLabel* aLbl = new QLabel(aSub);
-    aLbl->setFrameStyle(QFrame::Sunken);
-    aLbl->setFrameShape(QFrame::Panel);
-    aLbl->setPixmap(QPixmap(":pictures/ViewPort.png"));
-    aLbl->setScaledContents(true);
-    aSub->setWidget(aLbl);
-
-    QStringList aPictures;
-    aPictures<<":pictures/occ_view_camera_dump.png"<<":pictures/occ_view_style_switch.png";
-    aPictures<<":pictures/occ_view_triedre.png"<<":pictures/occ_view_fitall.png";
-    aPictures<<":pictures/occ_view_fitarea.png"<<":pictures/occ_view_zoom.png";
-    aPictures<<":pictures/occ_view_pan.png"<<":pictures/occ_view_glpan.png";
-    aPictures<<":pictures/occ_view_rotate.png"<<":pictures/occ_view_front.png";
-    aPictures<<":pictures/occ_view_back.png"<<":pictures/occ_view_left.png";
-    aPictures<<":pictures/occ_view_right.png"<<":pictures/occ_view_top.png";
-    aPictures<<":pictures/occ_view_bottom.png"<<":pictures/occ_view_clone.png";
-
-    QToolBar* aBar = new QToolBar(aSub);
-    aBar->setGeometry(0,0,500,30);
-
-    QAction* aBtn;
-    foreach(QString aName, aPictures) {
-        aBtn = new QAction(aBar);
-        aBtn->setIcon(QIcon(aName));
-        aBar->addAction(aBtn);
-    }
-    
-    aBar = new QToolBar(aSub);
-    aBar->setGeometry(615,0,100,25);
-    QStringList aWndIcons;
-    aWndIcons<<":pictures/wnd_minimize.png"<<":pictures/wnd_maximize.png"<<":pictures/wnd_close.png";
-    foreach(QString aName, aWndIcons) {
-        aBtn = new QAction(aBar);
-        aBtn->setIcon(QIcon(aName));
-        aBar->addAction(aBtn);
-    }
-
-    return aSub;
 }
 
-
-XGUI_MainWindow::~XGUI_MainWindow(void)
+//******************************************************
+QMdiArea* XGUI_MainWindow::mdiArea() const
 {
+  return static_cast<QMdiArea*>(centralWidget());
 }
 
 //******************************************************
 void XGUI_MainWindow::showObjectBrowser()
 {
-    myObjectBrowser->parentWidget()->show();
+  myObjectBrowser->parentWidget()->show();
 }
 
 //******************************************************
 void XGUI_MainWindow::hideObjectBrowser()
 {
-    myObjectBrowser->parentWidget()->hide();
+  myObjectBrowser->parentWidget()->hide();
+}
+
+//******************************************************
+void XGUI_MainWindow::showPythonConsole()
+{
+  if (!myPythonConsole) {
+
+    QDockWidget* aDoc = new QDockWidget(this);
+    aDoc->setFeatures(QDockWidget::AllDockWidgetFeatures | QDockWidget::DockWidgetVerticalTitleBar);
+    aDoc->setMinimumHeight(0);
+    aDoc->setWindowTitle("Console");
+    myPythonConsole = new PyConsole_EnhConsole( aDoc, new PyConsole_EnhInterp());
+    aDoc->setWidget(myPythonConsole);
+    addDockWidget(Qt::TopDockWidgetArea, aDoc);
+    tabifyDockWidget(myMenuBar->getLastDockWindow(), aDoc);
+  }
+  myPythonConsole->parentWidget()->show();
 }
 
 //******************************************************
-void XGUI_MainWindow::fillObjectBrowser()
+void XGUI_MainWindow::hidePythonConsole()
+{
+  if (myPythonConsole)
+    myPythonConsole->parentWidget()->hide();
+}
+
+void XGUI_MainWindow::showPropertyPanel()
+{
+  QAction* aViewAct = myPropertyPanelDock->toggleViewAction();
+  //<! Restore ability to close panel from the window's menu
+  aViewAct->setEnabled(true);
+  myPropertyPanelDock->show();
+  myPropertyPanelDock->raise();
+}
+
+void XGUI_MainWindow::hidePropertyPanel()
+{
+  QAction* aViewAct = myPropertyPanelDock->toggleViewAction();
+  //<! Do not allow to show empty property panel
+  aViewAct->setEnabled(false);
+  myPropertyPanelDock->hide();
+}
+
+/*
+ * Creates dock widgets, places them in corresponding area
+ * and tabifies if necessary.
+ */
+void XGUI_MainWindow::createDockWidgets()
+{
+  QDockWidget* aObjDock = createObjectBrowser();
+  addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
+  myPropertyPanelDock = createPropertyPanel();
+  addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanelDock);
+  hidePropertyPanel(); //<! Invisible by default
+  hideObjectBrowser();
+  tabifyDockWidget(aObjDock, myPropertyPanelDock);
+}
+
+void XGUI_MainWindow::setPropertyPannelTitle(const QString& theTitle)
 {
-    QStringList aNames;
-    aNames << "Parameters" << "Constructions";
-    aNames << "Part 1" << "Part 2" << "Part 3";
-    aNames << "Properties";
-
-    QStringList aIcons;
-    aIcons << ":pictures/params_folder.png";
-    aIcons << ":pictures/constr_folder.png";
-    aIcons << ":pictures/part_ico.png";
-    aIcons << ":pictures/part_ico.png";
-    aIcons << ":pictures/part_ico.png";
-    aIcons << ":pictures/properties.png";
-
-    QList<QTreeWidgetItem*> aItems;
-    foreach(QString aName, aNames) {
-        QTreeWidgetItem* aItem = new QTreeWidgetItem(myObjectBrowser);
-        aItem->setText(0, aName);
-        aItems.append(aItem);
-    }
-    for(int i = 0; i < aItems.length(); i++) {
-        aItems[i]->setIcon(0, QIcon(aIcons[i]));
-    }
-    myObjectBrowser->addTopLevelItems(aItems);
-
-    for (int i = 2; i < 5; i++) {
-        QTreeWidgetItem* aItem = new QTreeWidgetItem(aItems[i]);
-        aItem->setText(0, "Parameters");
-        aItem->setIcon(0, QIcon(":pictures/params_folder.png"));
-
-        aItem = new QTreeWidgetItem(aItems[i]);
-        aItem->setText(0, "Construction");
-        aItem->setIcon(0, QIcon(":pictures/constr_folder.png"));
-
-        aItem = new QTreeWidgetItem(aItems[i]);
-        aItem->setText(0, "Bodies");
-        aItem->setIcon(0, QIcon(":pictures/part_ico.png"));
-
-        aItem = new QTreeWidgetItem(aItems[i]);
-        aItem->setText(0, "Features");
-        aItem->setIcon(0, QIcon(":pictures/features.png"));
-    }
+  myPropertyPanelDock->setWindowTitle(theTitle);
 }
 
 
-void XGUI_MainWindow::addPropertyPanel()
+QDockWidget* XGUI_MainWindow::createPropertyPanel()
 {
-    QDockWidget* aPropPanel = new QDockWidget(this);
-    aPropPanel->setWindowTitle("Property panel");
-
-    QWidget* aContent = new QWidget(aPropPanel);
-    QVBoxLayout* aMainLay = new QVBoxLayout(aContent);
-    aMainLay->setContentsMargins(3,3,3,3);
-    aPropPanel->setWidget(aContent);
-
-    QWidget* aNameWgt = new QWidget(aContent);
-    QHBoxLayout* aNameLay = new QHBoxLayout(aNameWgt);
-    aNameLay->setContentsMargins(0,0,0,0);
-    aMainLay->addWidget(aNameWgt);
-
-    aNameLay->addWidget(new QLabel("Name", aNameWgt));
-    aNameLay->addWidget(new QLineEdit(aNameWgt));
-
-    QGroupBox* aGrpBox1 = new QGroupBox("Point", aContent);
-    aGrpBox1->setFlat(true);
-    QFormLayout* aFrmLay = new QFormLayout(aGrpBox1);
-    aFrmLay->setContentsMargins(0, 6, 0, 0);
-    aMainLay->addWidget(aGrpBox1);
-
-    QLabel* aLbl = new QLabel(aGrpBox1);
-    aLbl->setPixmap(QPixmap(":pictures/x_point.png"));
-    aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
-
-    aLbl = new QLabel(aGrpBox1);
-    aLbl->setPixmap(QPixmap(":pictures/y_point.png"));
-    aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
-
-    aLbl = new QLabel(aGrpBox1);
-    aLbl->setPixmap(QPixmap(":pictures/z_point.png"));
-    aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
-    
-
-    aGrpBox1 = new QGroupBox("Normal vector", aContent);
-    aGrpBox1->setFlat(true);
-    aFrmLay = new QFormLayout(aGrpBox1);
-    aFrmLay->setContentsMargins(0, 6, 0, 0);
-    aMainLay->addWidget(aGrpBox1);
-
-    aLbl = new QLabel(aGrpBox1);
-    aLbl->setPixmap(QPixmap(":pictures/x_size.png"));
-    aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
-
-    aLbl = new QLabel(aGrpBox1);
-    aLbl->setPixmap(QPixmap(":pictures/y_size.png"));
-    aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
-
-    aLbl = new QLabel(aGrpBox1);
-    aLbl->setPixmap(QPixmap(":pictures/z_size.png"));
-    aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
-    
-    aMainLay->addStretch(1);
-
-    QFrame* aFrm = new QFrame(aContent);
-    aFrm->setFrameStyle(QFrame::Sunken);
-    aFrm->setFrameShape(QFrame::Panel);
-    QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
-    aBtnLay->setContentsMargins(0, 0, 0, 0);
-    aMainLay->addWidget(aFrm);
-
-    QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
-    aBtn->setFlat(true);
-    aBtnLay->addWidget(aBtn);
-    aBtnLay->addStretch(1);
-    aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
-    aBtn->setFlat(true);
-    aBtnLay->addWidget(aBtn);
-    aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
-    aBtn->setFlat(true);
-    aBtnLay->addWidget(aBtn);
-
-    addDockWidget(Qt::RightDockWidgetArea, aPropPanel);
-}
\ No newline at end of file
+  QDockWidget* aPropPanel = new QDockWidget(this);
+  aPropPanel->setWindowTitle(tr("Property Panel"));
+  QAction* aViewAct = aPropPanel->toggleViewAction();
+  aPropPanel->setObjectName(XGUI::PROP_PANEL);
+
+  QWidget* aContent = new QWidget(aPropPanel);
+  QVBoxLayout* aMainLay = new QVBoxLayout(aContent);
+  aMainLay->setContentsMargins(3, 3, 3, 3);
+  aPropPanel->setWidget(aContent);
+
+  QFrame* aFrm = new QFrame(aContent);
+  aFrm->setFrameStyle(QFrame::Sunken);
+  aFrm->setFrameShape(QFrame::Panel);
+  QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
+  aBtnLay->setContentsMargins(0, 0, 0, 0);
+  aMainLay->addWidget(aFrm);
+
+  QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
+  aBtn->setFlat(true);
+  //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyHelpPressed()));
+  aBtnLay->addWidget(aBtn);
+  aBtnLay->addStretch(1);
+  aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
+  aBtn->setObjectName(XGUI::PROP_PANEL_OK);
+  aBtn->setFlat(true);
+  //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyOkPressed()));
+  aBtnLay->addWidget(aBtn);
+  aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
+  aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL);
+  aBtn->setFlat(true);
+  //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyClosePressed()));
+  aBtnLay->addWidget(aBtn);
+
+  QWidget* aCustomWidget = new QWidget(aContent);
+  aCustomWidget->setObjectName(XGUI::PROP_PANEL_WDG);
+  aMainLay->addWidget(aCustomWidget);
+  aMainLay->addStretch(1);
+
+  return aPropPanel;
+}
+
+QDockWidget* XGUI_MainWindow::createObjectBrowser()
+{
+  QDockWidget* aObjDock = new QDockWidget(this);
+  aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+  aObjDock->setWindowTitle(tr("Object browser"));
+  myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
+  aObjDock->setWidget(myObjectBrowser);
+  return aObjDock;
+}