From a21c6f9d24c7f0c4bf4f52927905c880fce67e8f Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 12 Mar 2015 10:49:45 +0300 Subject: [PATCH] Constraint sketch entity attribute. The created sketch entity should not disappear in the viewer by context popup menu show. --- src/PartSet/PartSet_SketcherMgr.cpp | 19 ++++++--- src/PartSet/PartSet_SketcherMgr.h | 3 ++ src/SketchPlugin/SketchPlugin_SketchEntity.h | 41 +++++++++----------- src/XGUI/XGUI_ContextMenuMgr.cpp | 5 +++ src/XGUI/XGUI_ContextMenuMgr.h | 3 ++ 5 files changed, 43 insertions(+), 28 deletions(-) diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 8ecc6bde0..178cf792f 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -237,8 +237,6 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE { get2dPoint(theWnd, theEvent, myClickedPoint); - myIsPopupMenuActive = theEvent->buttons() & Qt::RightButton; - if (!(theEvent->buttons() & Qt::LeftButton)) return; @@ -318,9 +316,6 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { - if (myIsPopupMenuActive) - myIsPopupMenuActive = false; - ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); ModuleBase_IViewer* aViewer = aWorkshop->viewer(); if (!aViewer->canDragByMouse()) @@ -494,6 +489,10 @@ void PartSet_SketcherMgr::onApplicationStarted() XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer(); connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort())); connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort())); + + XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr(); + connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu())); + connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu())); } void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget) @@ -514,6 +513,16 @@ void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWid } } +void PartSet_SketcherMgr::onBeforeContextMenu() +{ + myIsPopupMenuActive = true; +} + +void PartSet_SketcherMgr::onAfterContextMenu() +{ + myIsPopupMenuActive = false; +} + void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, Point& thePoint) { diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 6f7cbc8f5..36f91db2d 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -171,6 +171,9 @@ private slots: void onApplicationStarted(); void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget); + void onBeforeContextMenu(); + void onAfterContextMenu(); + private: /// Launches the operation from current highlighting void launchEditing(); diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.h b/src/SketchPlugin/SketchPlugin_SketchEntity.h index b1b74b519..489d23345 100644 --- a/src/SketchPlugin/SketchPlugin_SketchEntity.h +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.h @@ -20,9 +20,8 @@ #include -#define SKETCH_EDGE_COLOR "#ff0000" -#define SKETCH_POINT_COLOR "#ff0000" -#define SKETCH_EXTERNAL_EDGE_COLOR "#00ff00" +#define SKETCH_ENTITY_COLOR "#ff0000" +#define SKETCH_EXTERNAL_COLOR "#00ff00" #define SKETCH_CONSTRUCTION_COLOR "#000000" /**\class SketchPlugin_SketchEntity @@ -69,42 +68,38 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/) return false; + // set color from preferences std::vector aColor; std::shared_ptr aConstructionAttr = data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID()); bool isConstruction = aConstructionAttr.get() != NULL && aConstructionAttr->value(); + if (isConstruction) { + aColor = Config_PropManager::color("Visualization", "sketch_construction_color", + SKETCH_CONSTRUCTION_COLOR); + } + else if (isExternal()) { + aColor = Config_PropManager::color("Visualization", "sketch_external_color", + SKETCH_EXTERNAL_COLOR); + } + else { + aColor = Config_PropManager::color("Visualization", "sketch_entity_color", + SKETCH_ENTITY_COLOR); + } + if (!aColor.empty()) + isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]) || isCustomized; + if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound if (isConstruction) { isCustomized = thePrs->setWidth(1) || isCustomized; isCustomized = thePrs->setLineStyle(3) || isCustomized; - - aColor = Config_PropManager::color("Visualization", "sketch_construction_color", - SKETCH_CONSTRUCTION_COLOR); } else { isCustomized = thePrs->setWidth(3) || isCustomized; isCustomized = thePrs->setLineStyle(0) || isCustomized; - - if (isExternal()) { - // Set color from preferences - aColor = Config_PropManager::color("Visualization", "sketch_external_color", - SKETCH_EXTERNAL_EDGE_COLOR); - } - else { - // Set color from preferences - aColor = Config_PropManager::color("Visualization", "sketch_edge_color", - SKETCH_EDGE_COLOR); - } } } else if (aShapeType == 7) { // otherwise this is a vertex // thePrs->setPointMarker(6, 2.); - aColor = Config_PropManager::color("Visualization", "sketch_point_color", - SKETCH_POINT_COLOR); - } - - if (!aColor.empty()) { - isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]) || isCustomized; } return isCustomized; } diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index ece5d2d2b..282b1a31c 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -121,7 +121,12 @@ void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent) } 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; } } diff --git a/src/XGUI/XGUI_ContextMenuMgr.h b/src/XGUI/XGUI_ContextMenuMgr.h index a263c9697..570fe912e 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.h +++ b/src/XGUI/XGUI_ContextMenuMgr.h @@ -55,6 +55,9 @@ signals: /// \param isChecked is checked flag void actionTriggered(const QString& theId, bool isChecked); + void beforeContextMenu(); + void afterContextMenu(); + private slots: /// Process action event /// \param isChecked a checked action flag -- 2.39.2