Salome HOME
Process history pointer
[modules/shaper.git] / src / NewGeom / NewGeom_SalomeViewer.cpp
index 3a7ee6c78163a14dc8d786be723f5e8c06cd77e4..6803bfe8c910d1d64672832c4c29af4d5c6fe480 100644 (file)
@@ -3,29 +3,41 @@
 #include "NewGeom_SalomeViewer.h"
 #include "NewGeom_OCCSelector.h"
 
-#include <OCCViewer_ViewWindow.h>
 #include <OCCViewer_ViewPort3d.h>
 #include <OCCViewer_ViewFrame.h>
 
 #include <SUIT_ViewManager.h>
 
+#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+
 #include <QMouseEvent>
 #include <QContextMenuEvent>
 
+NewGeom_SalomeView::NewGeom_SalomeView(OCCViewer_Viewer* theViewer)
+: ModuleBase_IViewWindow(), myCurrentView(0)
+{
+  myViewer = theViewer;
+}
+
 
 Handle(V3d_View) NewGeom_SalomeView::v3dView() const
 {
-  SUIT_ViewManager* aMgr = myViewer->getViewManager();
-  OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
-  Handle(V3d_View) aView = aWnd->getViewPort()->getView();
+  Handle(V3d_View) aView;
+  if (myCurrentView) {
+    OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(myCurrentView);
+    aView = aWnd->getViewPort()->getView();
+  }
   return aView;
 }
 
 QWidget* NewGeom_SalomeView::viewPort() const
 {
-  SUIT_ViewManager* aMgr = myViewer->getViewManager();
-  OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
-  return aWnd->getViewPort();
+  QWidget* aViewPort = 0;
+  if (myCurrentView) {
+    OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(myCurrentView);
+    aViewPort = aWnd->getViewPort();
+  }
+  return aViewPort;
 }
 
 //**********************************************
@@ -106,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*)));
@@ -134,14 +146,16 @@ void NewGeom_SalomeViewer::onSelectionChanged()
 }
 
 //**********************************************
-void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
+void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow* theView, QMouseEvent* theEvent)
 {
+  myView->setCurrentView(theView);
   emit mousePress(myView, theEvent);
 }
 
 //**********************************************
-void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
+void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow* theView, QMouseEvent* theEvent)
 {
+  myView->setCurrentView(theView);
   emit mouseRelease(myView, theEvent);
   if (myIsSelectionChanged) {
     emit selectionChanged();
@@ -150,14 +164,16 @@ void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEven
 }
 
 //**********************************************
-void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
+void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow* theView, QMouseEvent* theEvent)
 {
+  myView->setCurrentView(theView);
   emit mouseDoubleClick(myView, theEvent);
 }
 
 //**********************************************
 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
@@ -209,18 +225,32 @@ void NewGeom_SalomeViewer::onTryCloseView(SUIT_ViewWindow*)
 //**********************************************
 void NewGeom_SalomeViewer::onDeleteView(SUIT_ViewWindow*)
 {
+  if(myWindowScale.contains(myView->v3dView()))
+    myWindowScale.remove(myView->v3dView());
   emit deleteView(myView);
 }
 
 //**********************************************
-void NewGeom_SalomeViewer::onViewCreated(SUIT_ViewWindow*)
+void NewGeom_SalomeViewer::onViewCreated(SUIT_ViewWindow* theView)
 {
+  myView->setCurrentView(theView);
+
+  OCCViewer_ViewFrame* aView = dynamic_cast<OCCViewer_ViewFrame*>(theView);
+
+  OCCViewer_ViewWindow* aWnd = aView->getView(OCCViewer_ViewFrame::MAIN_VIEW);
+  if (aWnd)
+    connect(aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)),
+      this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType)));
+
+  myWindowScale.insert (aView->getViewPort()->getView(), aView->getViewPort()->getView()->Camera()->Scale());
+
   emit viewCreated(myView);
 }
 
 //**********************************************
-void NewGeom_SalomeViewer::onActivated(SUIT_ViewWindow*)
+void NewGeom_SalomeViewer::onActivated(SUIT_ViewManager* theMgr)
 {
+  myView->setCurrentView(theMgr->getActiveView());
   emit activated(myView);
 }
 
@@ -305,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()
 {
@@ -322,3 +367,45 @@ void NewGeom_SalomeViewer::update()
     aContext->UpdateCurrentViewer();
   }
 }
+
+//***************************************
+void NewGeom_SalomeViewer::onViewTransformed(OCCViewer_ViewWindow::OperationType theType)
+{
+  emit viewTransformed((int) theType);
+}
+
+//***************************************
+void NewGeom_SalomeViewer::activateViewer(bool toActivate)
+{
+  if (!mySelector || !mySelector->viewer())
+    return;
+  SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
+  QVector<SUIT_ViewWindow*> aViews = aMgr->getViews();
+  if (toActivate) {
+    foreach (SUIT_ViewWindow* aView, aViews) {
+      OCCViewer_ViewFrame* aOCCView = dynamic_cast<OCCViewer_ViewFrame*>(aView);
+      OCCViewer_ViewWindow* aWnd = aOCCView->getView(OCCViewer_ViewFrame::MAIN_VIEW);
+      connect(aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)),
+        this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType)));
+    }
+  } else {
+    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)),
+        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);
+    aWnd->getViewPort()->getView()->ZFitAll();
+  }
+}
\ No newline at end of file