{
QAction* aAction = new QAction(QIcon(":pictures/edit.png"), tr("Edit..."), this);
addAction("EDIT_CMD", aAction);
+
+ aAction = new QAction(QIcon(":pictures/activate.png"), tr("Activate"), this);
+ addAction("ACTIVATE_PART_CMD", aAction);
+
+ aAction = new QAction(QIcon(":pictures/assembly.png"), tr("Deactivate"), this);
+ addAction("DEACTIVATE_PART_CMD", aAction);
}
void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
QFeatureList aFeatures = aSelMgr->selectedFeatures();
if (aFeatures.size() == 1) {
FeaturePtr aFeature = aFeatures.first();
- if (aFeature->getKind() != "Part") {
- QMenu* aMenu = new QMenu();
+ QMenu* aMenu = new QMenu();
+ if (aFeature->getKind() == "Part") {
+ //TODO: Check that feature is active
+ aMenu->addAction(action("ACTIVATE_PART_CMD"));
+ } else {
aMenu->addAction(action("EDIT_CMD"));
- return aMenu;
}
+ return aMenu;
}
return 0;
}
// if this is root node (Part item index)
if (!aIndex->parent().isValid()) {
if (myActivePart) myActivePart->setItemsColor(PASSIVE_COLOR);
- myActivePart = (myActivePart == aModel)? 0 : (XGUI_PartModel*)aModel;
+
+ if (myActivePart == aModel) {
+ myActivePart = 0;
+ myActivePartIndex = QModelIndex();
+ } else {
+ myActivePart = (XGUI_PartModel*)aModel;
+ myActivePartIndex = theIndex;
+ }
+
if (myActivePart) {
myActivePart->setItemsColor(ACTIVE_COLOR);
myModel->setItemsColor(PASSIVE_COLOR);
if (myActivePart)
return myActivePart->part();
return FeaturePtr();
-}
\ No newline at end of file
+}
+
+void XGUI_DocumentDataModel::deactivatePart()
+{
+ if (myActivePart)
+ myActivePart->setItemsColor(PASSIVE_COLOR);
+ myActivePart = 0;
+ myModel->setItemsColor(ACTIVE_COLOR);
+}
FeaturePtr activePart() const;
+ QModelIndex activePartIndex() const { return myActivePartIndex; }
+
+ //! Deactivates a Part
+ void deactivatePart();
+
private:
enum {PartsFolder, HistoryNode};
//! Active part in part editing mode
XGUI_PartModel* myActivePart;
+ QModelIndex myActivePartIndex;
+
//! List of saved QModelIndexes created by sub-models
QList<QModelIndex*> myIndexes;
#include "XGUI_ObjectsBrowser.h"
#include "XGUI_DocumentDataModel.h"
-XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
+#include <ModelAPI_Data.h>
+
+#include <QLayout>
+#include <QLabel>
+#include <QPixmap>
+#include <QEvent>
+#include <QMouseEvent>
+
+
+
+XGUI_DataTree::XGUI_DataTree(QWidget* theParent)
: QTreeView(theParent)
{
setHeaderHidden(true);
- myDocModel = new XGUI_DocumentDataModel(this);
- setModel(myDocModel);
+ setModel(new XGUI_DocumentDataModel(this));
connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
- this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
+ this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
}
-
-XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser()
+XGUI_DataTree::~XGUI_DataTree()
{
}
+XGUI_DocumentDataModel* XGUI_DataTree::dataModel() const
+{
+ return static_cast<XGUI_DocumentDataModel*>(model());
+}
-void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected,
+void XGUI_DataTree::onSelectionChanged(const QItemSelection& theSelected,
const QItemSelection& theDeselected)
{
mySelectedData.clear();
QModelIndexList aIndexes = selectionModel()->selectedIndexes();
+ XGUI_DocumentDataModel* aModel = dataModel();
QModelIndexList::const_iterator aIt;
for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) {
- FeaturePtr aFeature = myDocModel->feature(*aIt);
+ FeaturePtr aFeature = aModel->feature(*aIt);
if (aFeature)
mySelectedData.append(aFeature);
}
emit selectionChanged();
}
-void XGUI_ObjectsBrowser::mouseDoubleClickEvent(QMouseEvent* theEvent)
+void XGUI_DataTree::mouseDoubleClickEvent(QMouseEvent* theEvent)
{
- QModelIndex aIndex = currentIndex();
- bool isChanged = myDocModel->activatedIndex(aIndex);
- QTreeView::mouseDoubleClickEvent(theEvent);
- if (isChanged) {
- emit activePartChanged(myDocModel->activePart());
- }
+ if (theEvent->button() == Qt::LeftButton) {
+ QModelIndex aIndex = currentIndex();
+ XGUI_DocumentDataModel* aModel = dataModel();
+
+ if ((aModel->activePartIndex() != aIndex) && aModel->activePartIndex().isValid()) {
+ setExpanded(aModel->activePartIndex(), false);
+ }
+ bool isChanged = aModel->activatedIndex(aIndex);
+ QTreeView::mouseDoubleClickEvent(theEvent);
+ if (isChanged) {
+ if (aModel->activePartIndex().isValid())
+ setExpanded(aIndex, true);
+ emit activePartChanged(aModel->activePart());
+ }
+ } else
+ QTreeView::mouseDoubleClickEvent(theEvent);
}
-void XGUI_ObjectsBrowser::contextMenuEvent(QContextMenuEvent* theEvent)
+void XGUI_DataTree::contextMenuEvent(QContextMenuEvent* theEvent)
{
emit contextMenuRequested(theEvent);
+}
+
+//********************************************************************
+//********************************************************************
+//********************************************************************
+XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
+ : QWidget(theParent)
+{
+ QVBoxLayout* aLayout = new QVBoxLayout(this);
+ aLayout->setContentsMargins(0, 0, 0, 0);
+ aLayout->setSpacing(0);
+
+ QWidget* aLabelWgt = new QWidget(this);
+ aLayout->addWidget(aLabelWgt);
+ QHBoxLayout* aLabelLay = new QHBoxLayout(aLabelWgt);
+ aLabelLay->setContentsMargins(3, 3, 3, 3);
+
+ QLabel* aLbl = new QLabel(aLabelWgt);
+ aLbl->setPixmap(QPixmap(":pictures/assembly.png"));
+ aLabelLay->addWidget(aLbl);
+
+ myActiveDocLbl = new QLabel("", aLabelWgt);
+ myActiveDocLbl->setAlignment(Qt::AlignHCenter);
+
+ QFont aFnt = myActiveDocLbl->font();
+ aFnt.setBold(true);
+ myActiveDocLbl->setFont(aFnt);
+
+ myActiveDocLbl->installEventFilter(this);
+
+ aLabelLay->addWidget(myActiveDocLbl);
+ aLabelLay->setStretch(1,1);
+
+ myTreeView = new XGUI_DataTree(this);
+ aLayout->addWidget(myTreeView);
+
+ myDocModel = myTreeView->dataModel();
+
+ connect(myTreeView, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
+ connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(onActivePartChanged(FeaturePtr)));
+ connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SIGNAL(activePartChanged(FeaturePtr)));
+ connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)),
+ this, SIGNAL(contextMenuRequested(QContextMenuEvent*)));
+
+ onActivePartChanged(FeaturePtr());
+}
+
+
+XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser()
+{
+}
+
+
+void XGUI_ObjectsBrowser::onActivePartChanged(FeaturePtr thePart)
+{
+ QPalette aPalet = myActiveDocLbl->palette();
+ if (thePart) {
+ myActiveDocLbl->setText(tr("Activate Part set"));
+ aPalet.setColor(QPalette::Foreground, Qt::black);
+ myActiveDocLbl->setCursor(Qt::PointingHandCursor);
+ } else {
+ myActiveDocLbl->setText(tr("Part set is active"));
+ aPalet.setColor(QPalette::Foreground, QColor(0, 72, 140));
+ myActiveDocLbl->unsetCursor();
+ }
+ myActiveDocLbl->setPalette(aPalet);
+}
+
+bool XGUI_ObjectsBrowser::eventFilter(QObject* obj, QEvent* theEvent)
+{
+ if (obj == myActiveDocLbl) {
+ if (theEvent->type() == QEvent::MouseButtonDblClick) {
+ if (myDocModel->activePartIndex().isValid()) {
+ myTreeView->setExpanded(myDocModel->activePartIndex(), false);
+ }
+ myDocModel->deactivatePart();
+ onActivePartChanged(FeaturePtr());
+ emit activePartChanged(FeaturePtr());
+ }
+ }
+ return QWidget::eventFilter(obj, theEvent);
+}
+
+void XGUI_ObjectsBrowser::activateCurrentPart(bool toActivate)
+{
+ if (toActivate) {
+ QModelIndex aIndex = myTreeView->currentIndex();
+
+ if ((myDocModel->activePartIndex() != aIndex) && myDocModel->activePartIndex().isValid()) {
+ myTreeView->setExpanded(myDocModel->activePartIndex(), false);
+ }
+ bool isChanged = myDocModel->activatedIndex(aIndex);
+ if ((isChanged) && (myDocModel->activePartIndex().isValid())) {
+ myTreeView->setExpanded(aIndex, true);
+ onActivePartChanged(myDocModel->feature(aIndex));
+ }
+ } else {
+ QModelIndex aIndex = myDocModel->activePartIndex();
+ if (aIndex.isValid()) {
+ myDocModel->activatedIndex(aIndex);
+ myTreeView->setExpanded(aIndex, false);
+ onActivePartChanged(FeaturePtr());
+ }
+ }
}
\ No newline at end of file
#include "XGUI.h"
#include "XGUI_Constants.h"
+#include <QWidget>
#include <QTreeView>
class XGUI_DocumentDataModel;
+class QLabel;
+
+
+class XGUI_DataTree: public QTreeView
+{
+ Q_OBJECT
+public:
+ XGUI_DataTree(QWidget* theParent);
+ virtual ~XGUI_DataTree();
+
+ //! Returns list of currently selected features
+ QFeatureList selectedFeatures() const { return mySelectedData; }
+
+ XGUI_DocumentDataModel* dataModel() const;
+
+signals:
+ //! Emited when selection is changed
+ void selectionChanged();
+ void activePartChanged(FeaturePtr thePart);
+
+ //! Emited on context menu request
+ void contextMenuRequested(QContextMenuEvent* theEvent);
+
+protected:
+ virtual void mouseDoubleClickEvent(QMouseEvent* theEvent);
+ virtual void contextMenuEvent(QContextMenuEvent* theEvent);
+
+private slots:
+ //! Called when selection in Data Tree is changed
+ void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
+
+private:
+ //! List of currently selected data
+ QFeatureList mySelectedData;
+};
+
/**\class XGUI_ObjectsBrowser
* \ingroup GUI
* \brief Object browser window object. Represents data tree of current data structure
*/
- class XGUI_EXPORT XGUI_ObjectsBrowser : public QTreeView
+ class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
{
Q_OBJECT
public:
XGUI_DocumentDataModel* dataModel() const { return myDocModel; }
//! Returns list of currently selected features
- QFeatureList selectedFeatures() const { return mySelectedData; }
+ QFeatureList selectedFeatures() const { return myTreeView->selectedFeatures(); }
+
+ //! Returns currently selected indexes
+ QModelIndexList selectedIndexes() const { return myTreeView->selectionModel()->selectedIndexes(); }
+
+ //! Returns TreeView widget
+ XGUI_DataTree* treeView() const { return myTreeView; }
+
+ //! Activates currently selected part. Signal activePartChanged will not be sent
+ void activateCurrentPart(bool toActivate);
signals:
//! Emited when selection is changed
void selectionChanged();
+
+ //! Emited when current active document is changed
void activePartChanged(FeaturePtr thePart);
//! Emited on context menu request
void contextMenuRequested(QContextMenuEvent* theEvent);
protected:
- virtual void mouseDoubleClickEvent(QMouseEvent* theEvent);
- virtual void contextMenuEvent(QContextMenuEvent* theEvent);
+ virtual bool eventFilter(QObject* obj, QEvent* theEvent);
private slots:
- //! Called when selection in Data Tree is changed
- void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
+ void onActivePartChanged(FeaturePtr thePart);
private:
//! Internal model
XGUI_DocumentDataModel* myDocModel;
- //! List of currently selected data
- QFeatureList mySelectedData;
-
- //QModelIndex myActivePartIndex;
+ QLabel* myActiveDocLbl;
+ XGUI_DataTree* myTreeView;
};
#endif
\ No newline at end of file
//**************************************************************
QModelIndexList XGUI_SelectionMgr::selectedIndexes() const
{
- return myWorkshop->objectBrowser()->selectionModel()->selectedIndexes();
+ return myWorkshop->objectBrowser()->selectedIndexes();
}
//**************************************************************
myActionsMgr = new XGUI_ActionsMgr(this);
myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
myContextMenuMgr = new XGUI_ContextMenuMgr(this);
+ connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)),
+ this, SLOT(onContextMenuCommand(const QString&, bool)));
myViewerProxy = new XGUI_ViewerProxy(this);
//******************************************************
void XGUI_Workshop::onUndo()
{
- objectBrowser()->setCurrentIndex(QModelIndex());
+ objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
if (aDoc->isOperation())
//******************************************************
void XGUI_Workshop::onRedo()
{
- objectBrowser()->setCurrentIndex(QModelIndex());
+ objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
aDoc->redo();
{
return mySalomeConnector->viewer();
}
+
+//**************************************************************
+void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
+{
+ if (theId == "ACTIVATE_PART_CMD")
+ activatePart(true);
+ else if (theId == "DEACTIVATE_PART_CMD")
+ activatePart(false);
+
+}
+
+//**************************************************************
+void XGUI_Workshop::activatePart(bool toActivate)
+{
+ if (toActivate) {
+ QFeatureList aFeatures = mySelector->selectedFeatures();
+ if (aFeatures.size() > 0) {
+ changeCurrentDocument(aFeatures.first());
+ myObjectBrowser->activateCurrentPart(true);
+ }
+ } else {
+ changeCurrentDocument(FeaturePtr());
+ myObjectBrowser->activateCurrentPart(false);
+ }
+}
+
/// \param theOpertion a stopped operation
void onOperationStopped(ModuleBase_Operation* theOperation);
+ void onContextMenuCommand(const QString& theId, bool isChecked);
+
private:
void initMenu();
// Creates Dock widgets: Object browser and Property panel
void createDockWidgets();
+ //! Activates or deactivates currently selected part
+ void activatePart(bool toActivate);
+
QString myCurrentFile;
XGUI_MainWindow* myMainWindow;
XGUI_Module* myPartSetModule;
<file>pictures/tile_views.png</file>
<file>pictures/new_view.png</file>
<file>pictures/edit.png</file>
+ <file>pictures/assembly.png</file>
+ <file>pictures/activate.png</file>
</qresource>
</RCC>