Salome HOME
#1136 - hidden axis are selected in sketch
authornds <nds@opencascade.com>
Thu, 17 Dec 2015 11:39:23 +0000 (14:39 +0300)
committernds <nds@opencascade.com>
Thu, 17 Dec 2015 11:39:51 +0000 (14:39 +0300)
src/ModuleBase/ModuleBase_IViewer.h
src/NewGeom/NewGeom_SalomeViewer.cpp
src/NewGeom/NewGeom_SalomeViewer.h
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_ViewerProxy.cpp
src/XGUI/XGUI_ViewerProxy.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 4dce665cee53dc8572cd005d66a81fbd8b3ec3fe..30c233969e81d99f803e5883d11de3d16534a53c 100644 (file)
@@ -8,6 +8,7 @@
 #include <QMap>
 #include <AIS_InteractiveContext.hxx>
 #include <V3d_View.hxx>
+#include <AIS_Trihedron.hxx>
 
 class QMouseEvent;
 class QKeyEvent;
@@ -30,6 +31,9 @@ Q_OBJECT
   //! Returns AIS_InteractiveContext from current OCCViewer
   virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
 
+  //! Trihedron 3d object shown in the viewer
+  virtual Handle(AIS_Trihedron) trihedron() const = 0;
+
   //! Retrurns V3d_Vioewer from current viewer
   virtual Handle(V3d_Viewer) v3dViewer() const = 0;
 
@@ -149,6 +153,9 @@ signals:
   /// \param theTransformation type of transformation (see AppElements_ViewWindow::OperationType)
   void viewTransformed(int theTransformation);
 
+  /// Signal emited on selection changed
+  void trihedronVisibilityChanged(bool theState);
+
   protected:
     /// A map for storing a scale factors dependent on view object
     QMap<Handle(V3d_View), double> myWindowScale;
index ac0b1c3b0991baf6790557fa78a983b7edf6eca7..f116db2333d94f09e03568feb2945f5f11c8d614 100644 (file)
@@ -8,6 +8,8 @@
 
 #include <SUIT_ViewManager.h>
 
+#include <QtxActionToolMgr.h>
+
 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
 
 #include <QMouseEvent>
@@ -76,6 +78,12 @@ Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const
   return Handle(V3d_Viewer)();
 }
 
+//**********************************************
+Handle(AIS_Trihedron) NewGeom_SalomeViewer::trihedron() const
+{
+  return mySelector->viewer()->getTrihedron();
+}
+
 //**********************************************
 Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
 {
@@ -237,13 +245,20 @@ void NewGeom_SalomeViewer::onViewCreated(SUIT_ViewWindow* theView)
   OCCViewer_ViewFrame* aView = dynamic_cast<OCCViewer_ViewFrame*>(theView);
 
   OCCViewer_ViewWindow* aWnd = aView->getView(OCCViewer_ViewFrame::MAIN_VIEW);
-  if (aWnd)
+  if (aWnd) {
     connect(aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)),
       this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType)));
+    OCCViewer_ViewPort3d* aViewPort = aWnd->getViewPort();
+    if (aViewPort)
+      connect(aViewPort, SIGNAL(vpMapped(OCCViewer_ViewPort3d*)), this, SLOT(onViewPortMapped()));
+  }
+  reconnectActions(aWnd, true);
 
   myWindowScale.insert (aView->getViewPort()->getView(), aView->getViewPort()->getView()->Camera()->Scale());
 
   emit viewCreated(myView);
+
+
 }
 
 //**********************************************
@@ -297,6 +312,32 @@ bool NewGeom_SalomeViewer::enableDrawMode(bool isEnabled)
   return false;
 }
 
+//**********************************************
+void NewGeom_SalomeViewer::reconnectActions(SUIT_ViewWindow* theWindow,
+                                            const bool theUseNewGeomSlot)
+{
+  OCCViewer_ViewWindow* aWindow = dynamic_cast<OCCViewer_ViewWindow*>(theWindow);
+  if (!aWindow)
+    return;
+
+  QAction* anAction = theWindow->toolMgr()->action(OCCViewer_ViewWindow::TrihedronShowId);
+  if (!anAction)
+    return;
+
+  if (theUseNewGeomSlot) {
+    anAction->disconnect(anAction, SIGNAL(toggled(bool)),
+                         theWindow, SLOT(onTrihedronShow(bool)));
+    anAction->connect(anAction, SIGNAL(toggled(bool)),
+                      this, SIGNAL(trihedronVisibilityChanged(bool)));
+  }
+  else {
+    anAction->connect(anAction, SIGNAL(toggled(bool)),
+                      theWindow, SLOT(onTrihedronShow(bool)));
+    anAction->disconnect(anAction, SIGNAL(toggled(bool)),
+                         this, SIGNAL(trihedronVisibilityChanged(bool)));
+  }
+}
+
 //**********************************************
 void NewGeom_SalomeViewer::fitAll()
 {
@@ -387,6 +428,12 @@ void NewGeom_SalomeViewer::onViewTransformed(OCCViewer_ViewWindow::OperationType
   emit viewTransformed((int) theType);
 }
 
+//***************************************
+void NewGeom_SalomeViewer::onViewPortMapped()
+{
+  emit trihedronVisibilityChanged(true);
+}
+
 //***************************************
 void NewGeom_SalomeViewer::activateViewer(bool toActivate)
 {
@@ -400,6 +447,7 @@ void NewGeom_SalomeViewer::activateViewer(bool toActivate)
       OCCViewer_ViewWindow* aWnd = aOCCView->getView(OCCViewer_ViewFrame::MAIN_VIEW);
       connect(aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)),
         this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType)));
+      reconnectActions(aWnd, true);
     }
   } else {
     foreach (SUIT_ViewWindow* aView, aViews) {
@@ -407,6 +455,7 @@ void NewGeom_SalomeViewer::activateViewer(bool toActivate)
       OCCViewer_ViewWindow* aWnd = aOCCView->getView(OCCViewer_ViewFrame::MAIN_VIEW);
       disconnect((OCCViewer_ViewWindow*)aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)),
         this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType)));
+      reconnectActions(aWnd, false);
     }
   }
 }
index a9e9d19e2e8501d1386b1c18a1240963c7b76eec..e32cfbbdf9c8526bb6590b8b383f112a71d89136 100644 (file)
@@ -12,6 +12,7 @@
 #include <OCCViewer_ViewWindow.h>
 
 #include <V3d_View.hxx>
+#include <AIS_Trihedron.hxx>
 
 class SUIT_ViewWindow;
 class QMouseEvent;
@@ -76,6 +77,9 @@ Q_OBJECT
   //! Retrurns V3d_Vioewer from current viewer
   virtual Handle(V3d_Viewer) v3dViewer() const;
 
+  //! Trihedron 3d object shown in the viewer
+  virtual Handle(AIS_Trihedron) trihedron() const;
+
   //! Returns Vsd_View object from currently active view window
   virtual Handle(V3d_View) activeView() const;
 
@@ -97,6 +101,9 @@ Q_OBJECT
   //! Enable or disable draw mode in the viewer
   virtual bool enableDrawMode(bool isEnabled);
 
+  //! For some signals it disconnects the window from usual signal and connect it to the module ones
+  void reconnectActions(SUIT_ViewWindow* theWindow, const bool theUseNewGeomSlot);
+
   //! Perfroms the fit all for the active view
   virtual void fitAll();
 
@@ -161,6 +168,10 @@ Q_OBJECT
   void onSelectionChanged();
   void onViewTransformed(OCCViewer_ViewWindow::OperationType);
 
+  /// Emit signal about trihedron visiblity change because SALOME sets the trihedron visible by this signal.
+  /// It is necessary to activate the viewer trihedron in the current selection mode
+  void onViewPortMapped();
+
  private:
   NewGeom_OCCSelector* mySelector;
   NewGeom_SalomeView* myView;
index 4fb6a729bdba4c794c1beda317f8bda876aeb36f..2c24b774aac73afaf0a3bd47a1ae06e540e3084c 100644 (file)
@@ -38,6 +38,9 @@
 #include <AIS_Shape.hxx>
 #include <AIS_Dimension.hxx>
 #include <AIS_Trihedron.hxx>
+#include <AIS_Axis.hxx>
+#include <AIS_Plane.hxx>
+#include <AIS_Point.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 #include <SelectMgr_ListOfFilter.hxx>
 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
@@ -457,7 +460,7 @@ void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrL
   Handle(AIS_InteractiveObject) aTrihedron;
   if (isTrihedronActive()) {
     aTrihedron = getTrihedron();
-    if (!aTrihedron.IsNull())
+    if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
       aPrsList.Append(aTrihedron);
   }
   if (aPrsList.Extent() == 0)
@@ -574,42 +577,47 @@ bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
   return aErased;
 }
 
-#define DEACTVATE_COMP(TheComp) \
-  if (!TheComp.IsNull()) \
-    aContext->Deactivate(TheComp);
+void deactivateObject(Handle(AIS_InteractiveContext) theContext,
+                      Handle(AIS_InteractiveObject) theObject,
+                      const bool theClear = true)
+{
+  if (!theObject.IsNull()) {
+    theContext->Deactivate(theObject);
+    //if (theClear) {
+      //theObject->ClearSelected();
+      //  theContext->LocalContext()->ClearOutdatedSelection(theObject, true);
+    //}
+  }
+}
 
-void XGUI_Displayer::deactivateTrihedron() const
+void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
 {
   Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
-  if (!aTrihedron.IsNull()) {
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
     Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
-    Handle(AIS_InteractiveContext) aContext = AISContext();
-    aContext->Deactivate(aTrie);
-    DEACTVATE_COMP(aTrie->XAxis());
-    DEACTVATE_COMP(aTrie->YAxis());
-    DEACTVATE_COMP(aTrie->Axis());
-    DEACTVATE_COMP(aTrie->Position());
-    DEACTVATE_COMP(aTrie->XYPlane());
-    DEACTVATE_COMP(aTrie->XZPlane());
-    DEACTVATE_COMP(aTrie->YZPlane());
+    deactivateObject(aContext, aTrie);
+
+    /// #1136 hidden axis are selected in sketch
+    /// workaround for Cascade: there is a crash in AIS_LocalContext::ClearOutdatedSelection
+    /// for Position AIS object in SelectionModes.
+    deactivateObject(aContext, aTrie->XAxis());
+    deactivateObject(aContext, aTrie->YAxis());
+    deactivateObject(aContext, aTrie->Axis());
+    deactivateObject(aContext, aTrie->Position());
+
+    deactivateObject(aContext, aTrie->XYPlane());
+    deactivateObject(aContext, aTrie->XZPlane());
+    deactivateObject(aContext, aTrie->YZPlane());
+
+    if (theUpdateViewer)
+      updateViewer();
   }
 }
 
 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
 {
-  Handle(AIS_InteractiveContext) aContext = AISContext();
-  if (!aContext.IsNull()) {
-    AIS_ListOfInteractive aList;
-    aContext->DisplayedObjects(aList, true);
-    AIS_ListIteratorOfListOfInteractive aIt;
-    for (aIt.Initialize(aList); aIt.More(); aIt.Next()) {
-      Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aIt.Value());
-      if (!aTrihedron.IsNull()) {
-        return aTrihedron;
-      }
-    }
-  }
-  return Handle(AIS_InteractiveObject)();
+  return myWorkshop->viewer()->trihedron();
 }
 
 void XGUI_Displayer::openLocalContext()
@@ -795,7 +803,7 @@ Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
   if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
     aContext->OpenLocalContext();
     if (!isTrihedronActive())
-      deactivateTrihedron();
+      deactivateTrihedron(true);
     aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
     aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
   }
@@ -1141,6 +1149,38 @@ void XGUI_Displayer::activateTrihedron(bool theIsActive)
 {  
   myIsTrihedronActive = theIsActive; 
   if (!myIsTrihedronActive) {
-    deactivateTrihedron();
+    deactivateTrihedron(true);
   }
 }
+
+void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return;
+
+  Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
+
+  if (theToDisplay) {
+    if (!aContext->IsDisplayed(aTrihedron))
+      aContext->Display(aTrihedron,
+                        0 /*wireframe*/,
+                        -1 /* selection mode */,
+                        Standard_True /* update viewer*/,
+                        Standard_False /* allow decomposition */,
+                        AIS_DS_Displayed /* xdisplay status */);
+
+    if (!isTrihedronActive())
+      deactivateTrihedron(false);
+    else
+      activate(aTrihedron, myActiveSelectionModes, false);
+  } else {
+    deactivateTrihedron(false);
+    //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true);
+    // the selection from the previous activation modes should be cleared manually (#26172)
+
+    aContext->Erase(aTrihedron);
+  }
+
+  updateViewer();
+}
index 78da19457d11969a3d4cdf34a811dd04829fced3..5ad16e6bcc00bcbca8be10123dc301481f67ff87 100644 (file)
@@ -231,9 +231,14 @@ class XGUI_EXPORT XGUI_Displayer: public QObject
   /// Returns Trihedron object if it is displayed
   Handle(AIS_InteractiveObject) getTrihedron() const;
   
-  // Set trihedron active (used in selection) or non active
+  /// Set trihedron active (used in selection) or non active
   void activateTrihedron(bool theIsActive);
 
+  /// Displays/erases thrihedron in current modes. It will be activated or deactivated
+  /// depending on the trihedron visible state and displayer active trihedron state
+  void displayTrihedron(bool theToDisplay) const;
+
+  /// Returns true if the trihedron should be activated in current selection modes
   bool isTrihedronActive() const { return myIsTrihedronActive; }
 
   /// Converts shape type (TopAbs_ShapeEnum) to selection mode
@@ -281,7 +286,8 @@ private:
   void deactivate(ObjectPtr theObject, const bool theUpdateViewer);
 
   /// Find a trihedron in a list of displayed presentations and deactivate it.
-  void deactivateTrihedron() const;
+  /// \param theUpdateViewer an update viewer flag
+  void deactivateTrihedron(const bool theUpdateViewer) const;
 
   /// Opens local context. Does nothing if it is already opened.
   void openLocalContext();
index caeaff5aa94e871f57900ec56b8ffa08a0a8f165..d0b6779e83112c582d5ffbe7b00b57a3303c2e2b 100644 (file)
@@ -22,6 +22,17 @@ XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
 {
 }
 
+void XGUI_ViewerProxy::connectViewProxy()
+{
+#ifdef HAVE_SALOME
+  connect(myWorkshop->salomeConnector()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)),
+         SIGNAL(trihedronVisibilityChanged(bool)));
+#else
+  connect(myWorkshop->mainWindow()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)),
+         SLOT(trihedronVisibilityChanged(bool)));
+#endif
+}
+
 Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
 {
 #ifdef HAVE_SALOME
@@ -31,6 +42,15 @@ Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
 #endif
 }
 
+Handle(AIS_Trihedron) XGUI_ViewerProxy::trihedron() const
+{
+#ifdef HAVE_SALOME
+  return myWorkshop->salomeConnector()->viewer()->trihedron();
+#else
+  return myWorkshop->mainWindow()->viewer()->trihedron();
+#endif
+}
+
 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
 {
 #ifdef HAVE_SALOME
index bce1db650127e232a9a7c1a272add53edfbcbc76..1e13f70cd589c06e7084fb7041c09160f5c8ea2b 100644 (file)
@@ -6,6 +6,8 @@
 #include "XGUI.h"
 #include <ModuleBase_IViewer.h>
 
+#include <AIS_Trihedron.hxx>
+
 #ifndef HAVE_SALOME
   #include <AppElements_ViewWindow.h>
 #endif
@@ -26,9 +28,15 @@ Q_OBJECT
    /// \param theParent a parent object
   XGUI_ViewerProxy(XGUI_Workshop* theParent);
 
+  /// Connects some signals to the viewer from the module connector
+  void connectViewProxy();
+
   //! Returns AIS_InteractiveContext from current OCCViewer
   virtual Handle(AIS_InteractiveContext) AISContext() const;
 
+  //! Trihedron 3d object shown in the viewer
+  virtual Handle(AIS_Trihedron) trihedron() const;
+
   //! Retrurns V3d_Vioewer from current viewer
   virtual Handle(V3d_Viewer) v3dViewer() const;
 
@@ -96,6 +104,9 @@ signals:
   /// Emits by mouse leaving of the view port
   void leaveViewPort();
 
+  /// Signal emited on selection changed
+  void trihedronVisibilityChanged(bool theState);
+
 protected:
   /// processes the application signals to catch the mouse leaving state of the main window
   /// \param theObject
index 5f7303a78a29de2cf1a78ba4bdb4661282c790ca..948f258fa11229f445545749dbf8f7c141fe6911 100755 (executable)
@@ -216,6 +216,10 @@ void XGUI_Workshop::startApplication()
   
   onNew();
 
+  myViewerProxy->connectViewProxy();
+  connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
+          SLOT(onTrihedronVisibilityChanged(bool)));
+
   emit applicationStarted();
 }
 
@@ -731,6 +735,14 @@ void XGUI_Workshop::onPreferences()
 }
 #endif
 
+//******************************************************
+void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
+{
+  XGUI_Displayer* aDisplayer = displayer();
+  if (aDisplayer)
+    aDisplayer->displayTrihedron(theState);
+}
+
 //******************************************************
 bool XGUI_Workshop::onSave()
 {
index c032b932411363d9a8d69dfaede0effb664ddddb..9f02d44621f0bf91fa28322d60fa8d192ff083c8 100755 (executable)
@@ -337,6 +337,9 @@ signals:
   void onPreferences();
 #endif
 
+  /// Activates/deactivates the trihedron in the viewer AIS context
+  void onTrihedronVisibilityChanged(bool theState);
+
  protected:
   /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
   /// and set them into the operation. Secondly, it asks the module about ids of granted operations.