]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Constraint sketch entity attribute.
authornds <natalia.donis@opencascade.com>
Thu, 12 Mar 2015 07:49:45 +0000 (10:49 +0300)
committernds <natalia.donis@opencascade.com>
Thu, 12 Mar 2015 07:49:45 +0000 (10:49 +0300)
The created sketch entity should not disappear in the viewer by context popup menu show.

src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/SketchPlugin/SketchPlugin_SketchEntity.h
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_ContextMenuMgr.h

index 8ecc6bde02b07a9e6968e518ac3558a97e61778f..178cf792fcbcf2acd4b9805370480fafe133608e 100644 (file)
@@ -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)
 {
index 6f7cbc8f510b4b352b6d0dd9f65fa4259706f734..36f91db2d6d382d54a2a3e34d7b0ec59623b27a5 100644 (file)
@@ -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();
index b1b74b519c9d9824dcc1b37009784a17070139a2..489d233455a26c77aa803488d1d79d933faff6bb 100644 (file)
@@ -20,9 +20,8 @@
 
 #include <Config_PropManager.h>
 
-#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<int> aColor;
     std::shared_ptr<ModelAPI_AttributeBoolean> 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;
   }
index ece5d2d2bafb64b118d6c1ea1e006ff4ef1452c2..282b1a31cce1b9206fab121f02b79a98005e5d38 100644 (file)
@@ -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;
   }
 }
index a263c96979ce76c5e6d83b3bff37d52b73014f46..570fe912e1ac7b544f4200ba5b58929999f20468 100644 (file)
@@ -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