Salome HOME
Issue #1079: Make Apply and Cancel buttons independent on enable/disable of complex...
[modules/shaper.git] / src / NewGeom / NewGeom_SalomeViewer.cpp
index deb1723311fb636eb94e078b08d21d7d6023d140..ebdff924986ed86f28a14f6e8c75b0c6cd3f92a0 100644 (file)
@@ -8,6 +8,8 @@
 
 #include <SUIT_ViewManager.h>
 
+#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+
 #include <QMouseEvent>
 #include <QContextMenuEvent>
 
@@ -116,8 +118,8 @@ void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
           this, SLOT(onDeleteView(SUIT_ViewWindow*)));
   connect(aMgr, SIGNAL(viewCreated(SUIT_ViewWindow*)), 
           this, SLOT(onViewCreated(SUIT_ViewWindow*)));
-  connect(aMgr, SIGNAL(activated(SUIT_ViewWindow*)), 
-          this, SLOT(onActivated(SUIT_ViewWindow*)));
+  connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)), 
+          this, SLOT(onActivated(SUIT_ViewManager*)));
 
   connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this,
           SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
@@ -172,10 +174,6 @@ void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow* theView, QMouseEv
 void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow* theView, QMouseEvent* theEvent)
 {
   myView->setCurrentView(theView);
-  OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(theView);
-  Handle(AIS_InteractiveContext) aContext = AISContext();
-  if (aContext->HasDetected()) // Set focus to provide key events in the view
-    aViewWnd->getViewPort()->setFocus(Qt::MouseFocusReason);
   emit mouseMove(myView, theEvent);
 }
 
@@ -195,16 +193,6 @@ bool NewGeom_SalomeViewer::canDragByMouse() const
 //**********************************************
 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow* theView, QKeyEvent* theEvent)
 {
-  OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(theView);
-  Handle(AIS_InteractiveContext) aContext = AISContext();
-  Handle(V3d_View) aView = aViewWnd->getViewPort()->getView();
-
-  bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
-  if ((theEvent->key() == Qt::Key_N) && noModifiers) {
-    aContext->HilightNextDetected(aView);
-  } else if ((theEvent->key() == Qt::Key_P) && noModifiers) {
-    aContext->HilightPreviousDetected(aView);
-  }
   emit keyPress(myView, theEvent);
 }
 
@@ -246,9 +234,9 @@ void NewGeom_SalomeViewer::onViewCreated(SUIT_ViewWindow* theView)
 }
 
 //**********************************************
-void NewGeom_SalomeViewer::onActivated(SUIT_ViewWindow* theView)
+void NewGeom_SalomeViewer::onActivated(SUIT_ViewManager* theMgr)
 {
-  myView->setCurrentView(theView);
+  myView->setCurrentView(theMgr->getActiveView());
   emit activated(myView);
 }
 
@@ -256,7 +244,8 @@ void NewGeom_SalomeViewer::onActivated(SUIT_ViewWindow* theView)
 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
 {
   if (mySelector)
-    mySelector->viewer()->enableSelection(isEnabled);
+    if (mySelector->viewer()->isSelectionEnabled() != isEnabled)
+      mySelector->viewer()->enableSelection(isEnabled);
   // The enableSelection() in SALOME 7.5 cause of forced Viewer update(we have blinking)
   // After this is corrected, the first row should be recommented, the last - removed
     //mySelector->viewer()->setInteractionStyle(isEnabled ? SUIT_ViewModel::STANDARD
@@ -268,6 +257,7 @@ bool NewGeom_SalomeViewer::isSelectionEnabled() const
 {
   if (mySelector)
     return mySelector->viewer()->isSelectionEnabled();
+  return false;
 }
 
 //**********************************************
@@ -285,6 +275,15 @@ bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
   return false;
 }
 
+//**********************************************
+bool NewGeom_SalomeViewer::enableDrawMode(bool isEnabled)
+{
+  // TODO: Has to be replaced when SALOME patch become available
+  if (mySelector)
+    return mySelector->viewer()->enableDrawMode(isEnabled);
+  return false;
+}
+
 //**********************************************
 void NewGeom_SalomeViewer::fitAll()
 {
@@ -298,7 +297,7 @@ void NewGeom_SalomeViewer::fitAll()
 }
 
 //**********************************************
-void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ)
+void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ, double theTwist)
 {
   if (!mySelector) 
     return;
@@ -309,8 +308,11 @@ void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double th
     Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView();
     if (!aView3d.IsNull()) {
       aView3d->SetProj(theX, theY, theZ);
+      aView3d->SetTwist( theTwist );
       aView3d->FitAll(0.01, true);
       aView3d->SetZSize(0.);
+      if (aView3d->Depth() < 0.1)
+        aView3d->DepthFitAll();
     }
   }
 }
@@ -333,6 +335,21 @@ void NewGeom_SalomeViewer::removeSelectionFilter(const Handle(SelectMgr_Filter)&
   }
 }
 
+//***************************************
+bool NewGeom_SalomeViewer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+  bool aFoundFilter = false;
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (!aContext.IsNull()) {
+    const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
+    SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
+    for (; aIt.More() && !aFoundFilter; aIt.Next()) {
+      aFoundFilter = theFilter.Access() == aIt.Value().Access();
+    }
+  }
+  return aFoundFilter;
+}
+
 //***************************************
 void NewGeom_SalomeViewer::clearSelectionFilters()
 {
@@ -379,4 +396,19 @@ void NewGeom_SalomeViewer::activateViewer(bool toActivate)
         this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType)));
     }
   }
+}
+
+void NewGeom_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