Salome HOME
Fix compilation error.
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI_SalomeViewer.cpp
index b4a65ead87a200e4461b9420f3638b637b3ecd7c..37148b5a3b9025ec68fcd0aa1d7d04a55c093ddf 100644 (file)
@@ -1,20 +1,41 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #include "SHAPERGUI_SalomeViewer.h"
 #include "SHAPERGUI_OCCSelector.h"
 
 #include <OCCViewer_ViewPort3d.h>
 #include <OCCViewer_ViewFrame.h>
-
+#include <SOCC_ViewModel.h>
 #include <SUIT_ViewManager.h>
 
 #include <QtxActionToolMgr.h>
+#include <SALOME_AISShape.hxx>
 
 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
 
 #include <QMouseEvent>
 #include <QContextMenuEvent>
 
+#define SALOME_PATCH_FOR_CTRL_WHEEL
+
 SHAPERGUI_SalomeView::SHAPERGUI_SalomeView(OCCViewer_Viewer* theViewer)
 : ModuleBase_IViewWindow(), myCurrentView(0)
 {
@@ -133,13 +154,13 @@ void SHAPERGUI_SalomeViewer::setSelector(SHAPERGUI_OCCSelector* theSel)
   // TODO: Provide ModuleBase_IViewWindow interface
   connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed()));
 
-  connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewWindow*)), 
+  connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewWindow*)),
           this, SLOT(onTryCloseView(SUIT_ViewWindow*)));
-  connect(aMgr, SIGNAL(deleteView(SUIT_ViewWindow*)), 
+  connect(aMgr, SIGNAL(deleteView(SUIT_ViewWindow*)),
           this, SLOT(onDeleteView(SUIT_ViewWindow*)));
-  connect(aMgr, SIGNAL(viewCreated(SUIT_ViewWindow*)), 
+  connect(aMgr, SIGNAL(viewCreated(SUIT_ViewWindow*)),
           this, SLOT(onViewCreated(SUIT_ViewWindow*)));
-  connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)), 
+  connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)),
           this, SLOT(onActivated(SUIT_ViewManager*)));
 
   connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this,
@@ -254,7 +275,8 @@ void SHAPERGUI_SalomeViewer::onViewCreated(SUIT_ViewWindow* theView)
   }
   reconnectActions(aWnd, true);
 
-  myWindowScale.insert (aView->getViewPort()->getView(), aView->getViewPort()->getView()->Camera()->Scale());
+  myWindowScale.insert(aView->getViewPort()->getView(),
+                       aView->getViewPort()->getView()->Camera()->Scale());
 
   emit viewCreated(myView);
 
@@ -314,7 +336,7 @@ bool SHAPERGUI_SalomeViewer::enableDrawMode(bool isEnabled)
 
 //**********************************************
 void SHAPERGUI_SalomeViewer::reconnectActions(SUIT_ViewWindow* theWindow,
-                                            const bool theUseNewGeomSlot)
+                                            const bool theUseSHAPERSlot)
 {
   OCCViewer_ViewWindow* aWindow = dynamic_cast<OCCViewer_ViewWindow*>(theWindow);
   if (!aWindow)
@@ -324,7 +346,7 @@ void SHAPERGUI_SalomeViewer::reconnectActions(SUIT_ViewWindow* theWindow,
   if (!anAction)
     return;
 
-  if (theUseNewGeomSlot) {
+  if (theUseSHAPERSlot) {
     anAction->disconnect(anAction, SIGNAL(toggled(bool)),
                          theWindow, SLOT(onTrihedronShow(bool)));
     anAction->connect(anAction, SIGNAL(toggled(bool)),
@@ -351,9 +373,27 @@ void SHAPERGUI_SalomeViewer::fitAll()
 }
 
 //**********************************************
-void SHAPERGUI_SalomeViewer::setViewProjection(double theX, double theY, double theZ, double theTwist)
+void SHAPERGUI_SalomeViewer::eraseAll()
 {
-  if (!mySelector) 
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  AIS_ListOfInteractive aList;
+  aContext->DisplayedObjects(aList);
+  AIS_ListIteratorOfListOfInteractive aLIt;
+  Handle(AIS_InteractiveObject) anAISIO;
+  for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
+    anAISIO = aLIt.Value();
+    Handle(Standard_Type) aType = anAISIO->DynamicType();
+    if (anAISIO->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
+      aContext->Erase(anAISIO, false);
+    }
+  }
+}
+
+//**********************************************
+void SHAPERGUI_SalomeViewer::setViewProjection(double theX, double theY,
+                                               double theZ, double theTwist)
+{
+  if (!mySelector)
     return;
 
   SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
@@ -398,7 +438,7 @@ bool SHAPERGUI_SalomeViewer::hasSelectionFilter(const Handle(SelectMgr_Filter)&
     const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
     SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
     for (; aIt.More() && !aFoundFilter; aIt.Next()) {
-      aFoundFilter = theFilter.Access() == aIt.Value().Access();
+      aFoundFilter = theFilter.get() == aIt.Value().get();
     }
   }
   return aFoundFilter;
@@ -440,6 +480,11 @@ void SHAPERGUI_SalomeViewer::activateViewer(bool toActivate)
   if (!mySelector || !mySelector->viewer())
     return;
   SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
+#ifdef SALOME_PATCH_FOR_CTRL_WHEEL
+  OCCViewer_Viewer* aViewer = dynamic_cast<OCCViewer_Viewer*>(aMgr->getViewModel());
+  if (aViewer)
+    aViewer->setUseLocalSelection(toActivate);
+#endif
   QVector<SUIT_ViewWindow*> aViews = aMgr->getViews();
   if (toActivate) {
     foreach (SUIT_ViewWindow* aView, aViews) {
@@ -453,24 +498,29 @@ void SHAPERGUI_SalomeViewer::activateViewer(bool toActivate)
     foreach (SUIT_ViewWindow* aView, aViews) {
       OCCViewer_ViewFrame* aOCCView = dynamic_cast<OCCViewer_ViewFrame*>(aView);
       OCCViewer_ViewWindow* aWnd = aOCCView->getView(OCCViewer_ViewFrame::MAIN_VIEW);
-      disconnect((OCCViewer_ViewWindow*)aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)),
+      disconnect((OCCViewer_ViewWindow*)aWnd,
+                 SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)),
         this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType)));
       reconnectActions(aWnd, false);
     }
   }
 }
 
-void SHAPERGUI_SalomeViewer::Zfitall()
-{
-  if (!mySelector || !mySelector->viewer())
-    return;
-  SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
-  OCCViewer_ViewFrame* aView = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
-  if (aView) {
-    OCCViewer_ViewWindow* aWnd = aView->getView(OCCViewer_ViewFrame::MAIN_VIEW);
-    Handle(V3d_View) aView3d = aWnd->getViewPort()->getView();
-    aView3d->ZFitAll();
-    if (aView3d->Depth() < 0.1)
-      aView3d->DepthFitAll();
-  }
-}
\ No newline at end of file
+//void SHAPERGUI_SalomeViewer::Zfitall()
+//{
+//  if (!mySelector || !mySelector->viewer())
+//    return;
+//  SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
+//  /// WORKAROUND for issue #1798. SUIT_ViewManager::closeAllViews() should nullify myActiveView
+//  /// As a result, we need to check views count in manager
+//  if (aMgr->getViews().size() > 0) {
+//    OCCViewer_ViewFrame* aView = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
+//    if (aView) {
+//      OCCViewer_ViewWindow* aWnd = aView->getView(OCCViewer_ViewFrame::MAIN_VIEW);
+//      Handle(V3d_View) aView3d = aWnd->getViewPort()->getView();
+//      aView3d->ZFitAll();
+//      if (aView3d->Depth() < 0.1)
+//        aView3d->DepthFitAll();
+//    }
+//  }
+//}
\ No newline at end of file