]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Improve sketcher popup menu processing
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 1 Apr 2015 11:44:27 +0000 (14:44 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 1 Apr 2015 11:44:27 +0000 (14:44 +0300)
src/ModuleBase/ModuleBase_IModule.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/SketcherPrs/SketcherPrs_Coincident.cpp
src/SketcherPrs/SketcherPrs_Coincident.h
src/XGUI/XGUI_ContextMenuMgr.cpp

index c7cd377cc26d7c778d5c7f7e15f980043aa4fb01..1d68372056ca961735560524bc0ada42b8c2c029 100644 (file)
@@ -10,6 +10,7 @@
 \r
 #include <QString>\r
 #include <QObject>\r
+#include <QMap>\r
 \r
 #include <string>\r
 #include <map>\r
@@ -75,7 +76,9 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
 \r
   /// Add menu atems for viewer into the given menu\r
   /// \param theMenu a popup menu to be shown in the viewer\r
-  virtual void addViewerItems(QMenu* theMenu) const {}\r
+  /// \param theStdActions a map of standard actions\r
+  /// \return true if items are added and there is no necessity to provide standard menu\r
+  virtual bool addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const { return false; }\r
 \r
   /// Add menu atems for object browser into the given menu\r
   /// \param theMenu a popup menu to be shown in the object browser\r
index 841387209216913943061197202e97cb03f22a97..4c685683578f2cd490d3964e314fca495da18414 100644 (file)
@@ -288,12 +288,12 @@ bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
   return aCanDisplay;
 }
 
-void PartSet_Module::addViewerItems(QMenu* theMenu) const
+bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
 {
   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
   if (!PartSet_SketcherMgr::isSketchOperation(anOperation) &&
       !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
-    return;
+    return false;
 
   ModuleBase_ISelection* aSelection = myWorkshop->selection();
   QObjectPtrList aObjects = aSelection->selectedPresentations();
@@ -307,10 +307,7 @@ void PartSet_Module::addViewerItems(QMenu* theMenu) const
       }
     }
     if (hasFeature) {
-      XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
-      XGUI_Workshop* aWorkshop = aConnector->workshop();
-      QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD");
-      theMenu->addAction(anAction);
+      theMenu->addAction(theStdActions["DELETE_CMD"]);
     }
   }
   bool isAuxiliary;
@@ -319,6 +316,7 @@ void PartSet_Module::addViewerItems(QMenu* theMenu) const
     theMenu->addAction(anAction);
     anAction->setChecked(isAuxiliary);
   }
+  return true;
 }
 
 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
index 891759c36b34bb51dd9071fcc0bc70a7c449d280..5264352dc98b0563d12877f826f862cce2cd67dd 100644 (file)
@@ -103,7 +103,9 @@ public:
 
   /// Add menu atems for viewer into the given menu
   /// \param theMenu a popup menu to be shown in the viewer
-  virtual void addViewerItems(QMenu* theMenu) const;
+  /// \param theStdActions a map of standard actions
+  /// \return true if items are added and there is no necessity to provide standard menu
+  virtual bool addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
 
 public slots:
   /// SLOT, that is called by no more widget signal emitted by property panel
index 60c2e451a1df0b7da64d621f447c292ec4c9bef0..86f1a1f3e53fee0ca76d99dfa9c9b1ab4ed8b056 100644 (file)
@@ -25,6 +25,9 @@
 #include <Graphic3d_ArrayOfPoints.hxx>
 #include <Prs3d_PointAspect.hxx>
 #include <Prs3d_Root.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <SelectMgr_Selection.hxx>
+#include <Select3D_SensitivePoint.hxx>
 
 
 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject);
@@ -34,6 +37,7 @@ SketcherPrs_Coincident::SketcherPrs_Coincident(SketchPlugin_Constraint* theConst
                                                const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
  : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
 {
+  
 }  
 
 
@@ -48,11 +52,15 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)&
     return;
 
   std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y());
-
-  static Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d ();
-  aPtA->SetType(Aspect_TOM_RING1);
-  aPtA->SetScale(2.);
-  aPtA->SetColor(myOwnColor);
+  myPoint = aPoint->impl<gp_Pnt>();
+
+  static Handle(Graphic3d_AspectMarker3d) aPtA;
+  if (aPtA.IsNull()) {
+    aPtA = new Graphic3d_AspectMarker3d ();
+    aPtA->SetType(Aspect_TOM_RING1);
+    aPtA->SetScale(2.);
+    aPtA->SetColor(myOwnColor);
+  }
   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
   aGroup->SetPrimitivesAspect(aPtA);
   Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
@@ -64,6 +72,9 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)&
 void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
                                             const Standard_Integer aMode)
 {
+  Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this, 10);
+  Handle(Select3D_SensitivePoint) aSp = new Select3D_SensitivePoint(aOwn, myPoint);
+  aSelection->Add(aSp);
 }
 
 void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
index 9b9c4cd8acc347825b1e22fef1aebac86e6b6a7f..72c7ec5d01a9494ab707016fc3bc8fae66e0b9d0 100644 (file)
@@ -47,6 +47,7 @@ protected:
 private:
   SketchPlugin_Constraint* myConstraint;
   std::shared_ptr<GeomAPI_Ax3> myPlane;
+  gp_Pnt myPoint;
 };
 
 
index 282b1a31cce1b9206fab121f02b79a98005e5d38..91d5c2f7cc99c9831aea1cf8e7e85844c6e57d5a 100644 (file)
@@ -227,40 +227,49 @@ QMenu* XGUI_ContextMenuMgr::viewerMenu() const
 
 void XGUI_ContextMenuMgr::addViewerItems(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->addViewerItems(theMenu, myActions);
+
+  if (!aIsDone) {
+    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;
+        }
       }
+      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 (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->canChangeColor())
+      theMenu->addAction(action("COLOR_CMD"));
+    if (myWorkshop->displayer()->objectsCount() > 0)
+      theMenu->addAction(action("HIDEALL_CMD"));
   }
-  if (myWorkshop->displayer()->objectsCount() > 0)
-    theMenu->addAction(action("HIDEALL_CMD"));
   if (!myWorkshop->isSalomeMode()) {
     theMenu->addSeparator();
     QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
@@ -269,12 +278,7 @@ void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const
       aSubMenu->addActions(aMDI->actions());
     }
   }
-  if (myWorkshop->canChangeColor())
-    theMenu->addAction(action("COLOR_CMD"));
 
-  ModuleBase_IModule* aModule = myWorkshop->module();
-  if (aModule)
-    aModule->addViewerItems(theMenu);
 }
 
 void XGUI_ContextMenuMgr::connectObjectBrowser() const