#include "XGUI_Displayer.h"
#include "XGUI_ViewerProxy.h"
#include "XGUI_Selection.h"
+#include "XGUI_SalomeConnector.h"
#include <AppElements_MainWindow.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Object.h>
-#include <ModelAPI_ResultPart.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_ResultGroup.h>
+#include <ModelAPI_ResultParameter.h>
#include <ModuleBase_IModule.h>
+#include <ModuleBase_Tools.h>
#include <QAction>
#include <QContextMenuEvent>
void XGUI_ContextMenuMgr::createActions()
{
- QAction* aAction = new QAction(QIcon(":pictures/edit.png"), tr("Edit..."), this);
- addAction("EDIT_CMD", aAction);
+ QAction* aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this);
+ QMainWindow* aDesktop = myWorkshop->mainWindow();
+ if (!aDesktop)
+ aDesktop = myWorkshop->salomeConnector()->desktop();
+ aDesktop->addAction(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);
-
- aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this);
- myWorkshop->mainWindow()->addAction(aAction);
addAction("DELETE_CMD", aAction);
aAction->setShortcut(Qt::Key_Delete);
aAction->setShortcutContext(Qt::ApplicationShortcut);
+ aAction = new QAction(QIcon(":pictures/color.png"), tr("Color"), this);
+ addAction("COLOR_CMD", aAction);
+
aAction = new QAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), this);
addAction("SHOW_CMD", aAction);
return 0;
}
+QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
+{
+ foreach(QAction* eachAction, myActions) {
+ if (eachAction->text() == theName) {
+ return eachAction;
+ }
+ }
+ return NULL;
+}
+
QStringList XGUI_ContextMenuMgr::actionIds() const
{
return myActions.keys();
}
if (aMenu && (aMenu->actions().size() > 0)) {
+ // it is possible that some objects should do something before and after the popup menu exec
+ // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
+ // a created entity
+ emit beforeContextMenu();
aMenu->exec(theEvent->globalPos());
+ emit afterContextMenu();
delete aMenu;
}
}
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
bool hasResult = false;
bool hasFeature = false;
- foreach(ObjectPtr aObj, aObjects)
- {
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
- if (aResult)
- hasResult = true;
- if (aFeature)
- hasFeature = true;
- if (hasFeature && hasResult) // && hasGroup)
- break;
- }
+ bool hasParameter = false;
+ ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter);
+
//Process Feature
if (aSelected == 1) {
ObjectPtr aObject = aObjects.first();
if (aObject) {
- ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
- if (aPart) {
- if (aMgr->activeDocument() == aPart->partDoc())
- aMenu->addAction(action("DEACTIVATE_PART_CMD"));
- else
- aMenu->addAction(action("ACTIVATE_PART_CMD"));
- } else if (hasFeature && aObject->document() == aMgr->activeDocument()) {
- aMenu->addAction(action("EDIT_CMD"));
- } else {
- if (aDisplayer->isVisible(aObject)) {
+ if (!hasFeature) {
+ if (aObject->isDisplayed()) {
if (aDisplayer->canBeShaded(aObject)) {
if (aDisplayer->displayMode(aObject) == XGUI_Displayer::Shading)
aMenu->addAction(action("WIREFRAME_CMD"));
}
aMenu->addSeparator();
aMenu->addAction(action("HIDE_CMD"));
- } else {
+ } else if (hasResult && (!hasParameter)) {
+ aMenu->addAction(action("SHOW_CMD"));
+ }
+
+ ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
+ if (aPartRes) {
aMenu->addAction(action("SHOW_CMD"));
}
- aMenu->addAction(action("SHOW_ONLY_CMD"));
+
+ if (!(hasParameter || hasFeature))
+ aMenu->addAction(action("SHOW_ONLY_CMD"));
}
- } else { // If feature is 0 the it means that selected root object (document)
- if (aMgr->activeDocument() != aMgr->moduleDocument())
- aMenu->addAction(action("ACTIVATE_PART_CMD"));
- }
+ }
} else {
- if (hasResult) {
+ if (hasResult && (!hasParameter)) {
aMenu->addAction(action("SHOW_CMD"));
aMenu->addAction(action("HIDE_CMD"));
aMenu->addAction(action("SHOW_ONLY_CMD"));
aMenu->addAction(action("WIREFRAME_CMD"));
}
}
- if (hasFeature)
+ if (hasFeature || hasParameter)
aMenu->addAction(action("DELETE_CMD"));
}
+ if (myWorkshop->canChangeColor())
+ aMenu->addAction(action("COLOR_CMD"));
+
aMenu->addSeparator();
+ ModuleBase_IModule* aModule = myWorkshop->module();
+ if (aModule) {
+ aModule->addObjectBrowserMenu(aMenu);
+ aMenu->addSeparator();
+ }
aMenu->addActions(myWorkshop->objectBrowser()->actions());
- ModuleBase_IModule* aModule = myWorkshop->module();
- if (aModule)
- aModule->addObjectBrowserItems(aMenu);
if (aMenu->actions().size() > 0) {
return aMenu;
QMenu* XGUI_ContextMenuMgr::viewerMenu() const
{
QMenu* aMenu = new QMenu();
- addViewerItems(aMenu);
+ addViewerMenu(aMenu);
if (aMenu->actions().size() > 0) {
return aMenu;
}
return 0;
}
-void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const
+void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
{
- XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
- QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
- if (aObjects.size() > 0) {
- //if (aObjects.size() == 1)
- // theMenu->addAction(action("EDIT_CMD"));
- bool isVisible = false;
- bool isShading = false;
- bool canBeShaded = false;
- foreach(ObjectPtr aObject, aObjects)
- {
- ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
- if (aRes && myWorkshop->displayer()->isVisible(aRes)) {
- isVisible = true;
- canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
- isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
- break;
+ bool aIsDone = false;
+ ModuleBase_IModule* aModule = myWorkshop->module();
+ if (aModule)
+ aIsDone = aModule->addViewerMenu(theMenu, myActions);
+
+ if (!aIsDone) {
+ XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
+ QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
+ if (aObjects.size() > 0) {
+ bool isVisible = false;
+ bool isShading = false;
+ bool canBeShaded = false;
+ foreach(ObjectPtr aObject, aObjects)
+ {
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
+ if (aRes && aRes->isDisplayed()) {
+ isVisible = true;
+ canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
+ isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
+ break;
+ }
}
+ if (isVisible) {
+ if (canBeShaded) {
+ if (isShading)
+ theMenu->addAction(action("WIREFRAME_CMD"));
+ else
+ theMenu->addAction(action("SHADING_CMD"));
+ }
+ theMenu->addSeparator();
+ theMenu->addAction(action("SHOW_ONLY_CMD"));
+ theMenu->addAction(action("HIDE_CMD"));
+ } else
+ theMenu->addAction(action("SHOW_CMD"));
}
- if (isVisible) {
- if (canBeShaded) {
- if (isShading)
- theMenu->addAction(action("WIREFRAME_CMD"));
- else
- theMenu->addAction(action("SHADING_CMD"));
- }
- theMenu->addSeparator();
- theMenu->addAction(action("SHOW_ONLY_CMD"));
- theMenu->addAction(action("HIDE_CMD"));
- } else
- theMenu->addAction(action("SHOW_CMD"));
- //theMenu->addAction(action("DELETE_CMD"));
+ if (myWorkshop->displayer()->objectsCount() > 0)
+ theMenu->addAction(action("HIDEALL_CMD"));
+ if (myWorkshop->canChangeColor())
+ theMenu->addAction(action("COLOR_CMD"));
}
- if (myWorkshop->displayer()->objectsCount() > 0)
- theMenu->addAction(action("HIDEALL_CMD"));
if (!myWorkshop->isSalomeMode()) {
theMenu->addSeparator();
QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
}
}
- ModuleBase_IModule* aModule = myWorkshop->module();
- if (aModule)
- aModule->addViewerItems(theMenu);
}
void XGUI_ContextMenuMgr::connectObjectBrowser() const