]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Connection of view management buttons to operations
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 1 Apr 2014 05:57:09 +0000 (09:57 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 1 Apr 2014 05:57:09 +0000 (09:57 +0400)
src/XGUI/XGUI_ViewPort.cpp
src/XGUI/XGUI_ViewPort.h
src/XGUI/XGUI_ViewWindow.cpp
src/XGUI/XGUI_ViewWindow.h
src/XGUI/XGUI_Viewer.cpp
src/XGUI/XGUI_Viewer.h
src/XGUI/XGUI_msg_en.ts

index b8ec9158268f38a4ce6b82efad1f23c5c52dc8a5..abcb6a3dd59531409573a5fc42b48f5985faa761 100644 (file)
@@ -716,3 +716,17 @@ void XGUI_ViewPort::setBackground( const XGUI_ViewBackground& bgData )
         emit vpChangeBackground( myBackground );
     }
 }
+
+void XGUI_ViewPort::fitAll(bool theKeepScale, bool theWithZ, bool theUpd)
+{
+  if ( activeView().IsNull() )
+    return;
+
+  if ( theKeepScale )
+    myScale = activeView()->Scale();
+
+  Standard_Real aMargin = 0.01;
+  activeView()->FitAll( aMargin, theWithZ, theUpd );
+  activeView()->SetZSize(0.);
+  emit vpTransformed( );
+}
index cd79d564eb9ac39830d2b60a6fd2581d307e7a21..10dd2356a6f46b439f8dc1b2308272d8d4dabde0 100644 (file)
@@ -36,6 +36,7 @@ public:
     void fitRect( const QRect& rect );
     void startZoomAtPoint( int x, int y );
     void zoom( int x0, int y0, int x, int y );
+    void fitAll(bool theKeepScale = false, bool theWithZ = true, bool theUpd = true);
 
     void setAdvancedZoomingEnabled( const bool theState ) { myIsAdvancedZoomingEnabled = theState; }
     bool isAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; }
index eb851c8005c8d585358c53b0d53ad3c21e7dbf55..8370775d9a813b8af9c8fcb950df90563c9241b7 100644 (file)
 #include <QMdiArea>
 #include <QMdiSubWindow>
 #include <QPainter>
-#include <QTime>
+//#include <QTime>
+#include <QFileDialog>
 
 #include <TopoDS_Shape.hxx>
 #include <BRep_Tool.hxx>
 #include <TopoDS.hxx>
+#include <Visual3d_View.hxx>
 
 #define BORDER_SIZE 2
 
@@ -183,7 +185,8 @@ QFrame(),
     my2dMode(XGUI::No2dMode),
     myCurrPointType(XGUI::GRAVITY),
     myPrevPointType(XGUI::GRAVITY),
-    myRotationPointSelection(false)
+    myRotationPointSelection(false),
+    myClosable(false)
 {
     mySelectedPoint = gp_Pnt(0.,0.,0.);
     setFrameStyle(QFrame::Raised);
@@ -197,28 +200,14 @@ QFrame(),
     myViewPort->installEventFilter(this);
     aLay->addWidget(myViewPort);
 
-    myPicture = new QLabel();
+    myPicture = new QLabel(this);
     myPicture->setFrameStyle(QFrame::Sunken);
     myPicture->setFrameShape(QFrame::Panel);
     myPicture->setMouseTracking(true);
     myPicture->installEventFilter(this);
+    aLay->addWidget(myPicture);
     myPicture->hide();
 
-    QStringList aPictures;
-    aPictures<<":pictures/occ_view_camera_dump.png"<<":pictures/occ_view_style_switch.png";
-    aPictures<<":pictures/occ_view_triedre.png"<<":pictures/occ_view_fitall.png";
-    aPictures<<":pictures/occ_view_fitarea.png"<<":pictures/occ_view_zoom.png";
-    aPictures<<":pictures/occ_view_pan.png"<<":pictures/occ_view_glpan.png";
-    aPictures<<":pictures/occ_view_rotate.png"<<":pictures/occ_view_front.png";
-    aPictures<<":pictures/occ_view_back.png"<<":pictures/occ_view_left.png";
-    aPictures<<":pictures/occ_view_right.png"<<":pictures/occ_view_top.png";
-    aPictures<<":pictures/occ_view_bottom.png"<<":pictures/occ_view_clone.png";
-
-    QStringList aTitles;
-    aTitles << "Dump view" << "Mouse style switch" << "Show trihedron" << "Fit all";
-    aTitles << "Fit area" << "Zoom" << "Panning" << "Global panning" << "Rotate";
-    aTitles << "Front" << "Back" << "Left" << "Right" << "Top" << "Bottom" << "Clone view";
-
     myGripWgt = new ViewerLabel(this, myViewPort);
     myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
     myGripWgt->setGeometry(BORDER_SIZE + 2, BORDER_SIZE + 2, 19, 32);
@@ -227,16 +216,73 @@ QFrame(),
     connect(myViewPort, SIGNAL(vpTransformed()), myGripWgt, SLOT(update()));
     connect(myViewPort, SIGNAL(vpUpdated()), myGripWgt, SLOT(update()));
 
+    // Create Viewer management buttons
     myViewBar = new ViewerToolbar(this, myViewPort);
 
     QAction* aBtn;
-    for (int i = 0; i < aTitles.length(); i++) {
-        aBtn = new QAction(QIcon(aPictures.at(i)), aTitles.at(i), myViewBar);
-        myViewBar->addAction(aBtn);
-    }
+
+    // Dump view
+    aBtn = new QAction(QIcon(":pictures/occ_view_camera_dump.png"), tr("DUMP_VIEW"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(dumpView()));
+    myViewBar->addAction(aBtn);
+    // Fit all
+    aBtn = new QAction(QIcon(":pictures/occ_view_fitall.png"), tr("FIT_ALL"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(fitAll()));
+    myViewBar->addAction(aBtn);
+    // Fit area
+    aBtn = new QAction(QIcon(":pictures/occ_view_fitarea.png"), tr("FIT_AREA"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(activateWindowFit()));
+    myViewBar->addAction(aBtn);
+    // Zoom
+    aBtn = new QAction(QIcon(":pictures/occ_view_zoom.png"), tr("ZOOM_VIEW"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(activateZoom()));
+    myViewBar->addAction(aBtn);
+    // Pan
+    aBtn = new QAction(QIcon(":pictures/occ_view_pan.png"), tr("PAN_VIEW"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(activatePanning()));
+    myViewBar->addAction(aBtn);
+    // Global Panning
+    aBtn = new QAction(QIcon(":pictures/occ_view_glpan.png"), tr("GLOB_PAN_VIEW"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(activateGlobalPanning()));
+    myViewBar->addAction(aBtn);
+    // Rotation
+    aBtn = new QAction(QIcon(":pictures/occ_view_rotate.png"), tr("ROTATE_VIEW"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(activateRotation()));
+    myViewBar->addAction(aBtn);
+    // Front view
+    aBtn = new QAction(QIcon(":pictures/occ_view_front.png"), tr("FRONT_VIEW"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(frontView()));
+    myViewBar->addAction(aBtn);
+    // Back view
+    aBtn = new QAction(QIcon(":pictures/occ_view_back.png"), tr("BACK_VIEW"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(backView()));
+    myViewBar->addAction(aBtn);
+    // Top view
+    aBtn = new QAction(QIcon(":pictures/occ_view_top.png"), tr("TOP_VIEW"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(topView()));
+    myViewBar->addAction(aBtn);
+    // Bottom view
+    aBtn = new QAction(QIcon(":pictures/occ_view_bottom.png"), tr("BOTTOM_VIEW"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(bottomView()));
+    myViewBar->addAction(aBtn);
+    // Left view
+    aBtn = new QAction(QIcon(":pictures/occ_view_left.png"), tr("LEFT_VIEW"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(leftView()));
+    myViewBar->addAction(aBtn);
+    // Right view
+    aBtn = new QAction(QIcon(":pictures/occ_view_right.png"), tr("RIGHT_VIEW"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(rightView()));
+    myViewBar->addAction(aBtn);
+    // Clone view
+    aBtn = new QAction(QIcon(":pictures/occ_view_clone.png"), tr("CLONE_VIEW"), myViewBar);
+    connect(aBtn, SIGNAL(triggered()), SLOT(cloneView()));
+    myViewBar->addAction(aBtn);
+
+    //Support copy of background on updating of viewer
     connect(myViewPort, SIGNAL(vpTransformed()), myViewBar, SLOT(update()));
     connect(myViewPort, SIGNAL(vpUpdated()), myViewBar, SLOT(update()));
 
+    // Create Window management buttons
     myWindowBar = new ViewerToolbar(this, myViewPort);
     connect(myViewPort, SIGNAL(vpTransformed()), myWindowBar, SLOT(update()));
     connect(myViewPort, SIGNAL(vpUpdated()), myWindowBar, SLOT(update()));
@@ -286,15 +332,14 @@ void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
 
     if (theEvent->type() == QEvent::WindowStateChange) {
         if (isMinimized()) {
-            if (!myPicture->parentWidget()) {
-                QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
-                QMdiArea* aMDIArea = aParent->mdiArea();
-                myPicture->setParent(aMDIArea);
-            }
-            myPicture->move(parentWidget()->x(), parentWidget()->y());
+            myViewBar->hide();
+            myGripWgt->hide(); 
+            myWindowBar->hide();
+            myViewPort->hide();
             myPicture->show();
         } else {
             myPicture->hide();
+            myViewPort->show();
             if (isMaximized()) {
                 myMinimizeBtn->setIcon(MinimizeIco);
                 myMaximizeBtn->setIcon(RestoreIco);
@@ -304,12 +349,17 @@ void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
         QWidget::changeEvent(theEvent);
 }
 
+
 //****************************************************************
 void XGUI_ViewWindow::onClose()
 {
-    if (parentWidget())
-        parentWidget()->close();
-
+    if (parentWidget()) {
+        emit tryClosing(this);
+        if (closable()) {
+            emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
+            parentWidget()->close();
+        }
+    }
 }
 
 //****************************************************************
@@ -317,10 +367,10 @@ void XGUI_ViewWindow::enterEvent(QEvent* theEvent)
 {
     if (!isMinimized()) {
         myViewBar->show();
+        myWindowBar->show();
         if (!isMaximized())
             myGripWgt->show(); 
     }
-    myWindowBar->show();
 }
 
 //****************************************************************
@@ -338,10 +388,13 @@ void XGUI_ViewWindow::onMinimize()
     int aW = width();
     int aH = height();
     double aR = aW / 100.;
-    myPicture->setPixmap(aPMap.scaled(100,  int(aH / aR)));
+    int aNewH = int(aH / aR);
+    myPicture->setPixmap(aPMap.scaled(100,  aNewH));
     
     myLastState = isMaximized()? MaximizedState : NormalState;
     showMinimized();
+    parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(),
+                                100, aNewH);
 }
 
 //****************************************************************
@@ -362,7 +415,6 @@ void XGUI_ViewWindow::onMaximize()
 //****************************************************************
 bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
 {
-    QWidget* aWgt = (theObj == myPicture)? myPicture : static_cast<QWidget*>(parentWidget());
     switch (theEvent->type()) {
     case QEvent::MouseButtonPress: 
         {
@@ -393,9 +445,9 @@ bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
                 QPoint aPnt = aEvent->globalPos();
                 QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
                 if (aMDIArea->rect().contains(aMDIPnt)) {
-                    int aX = aWgt->x() + (aPnt.x() - myMousePnt.x());
-                    int aY = aWgt->y() + (aPnt.y() - myMousePnt.y());
-                    aWgt->move(aX, aY);
+                    int aX = aParent->x() + (aPnt.x() - myMousePnt.x());
+                    int aY = aParent->y() + (aPnt.y() - myMousePnt.y());
+                    aParent->move(aX, aY);
                     myMousePnt = aPnt;
                 }
                 return true;
@@ -434,6 +486,18 @@ bool XGUI_ViewWindow::processViewPort(QEvent *theEvent)
     case QEvent::MouseButtonDblClick:
         emit mouseDoubleClicked(this, (QMouseEvent*)theEvent);
         return true;
+    case QEvent::Wheel:
+        {
+            QWheelEvent* aEvent = (QWheelEvent*) theEvent;
+            myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
+            double aDelta = (double)( aEvent->delta() ) / ( 15 * 8 );
+            int x  = aEvent->x();
+            int y  = aEvent->y();
+            int x1 = (int)( aEvent->x() + width()*aDelta/100 );
+            int y1 = (int)( aEvent->y() + height()*aDelta/100 );
+            myViewPort->zoom( x, y, x1, y1 );
+        }
+        return true;
     }
     return false;
 }
@@ -849,6 +913,26 @@ void XGUI_ViewWindow::activatePanning()
     }
 }
 
+/*!
+  \brief Start global panning operation
+
+  Sets the corresponding cursor for the widget.
+*/
+void XGUI_ViewWindow::activateGlobalPanning()
+{
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if ( !aView3d.IsNull() ) {
+    QPixmap globalPanPixmap (imageCrossCursor);
+    QCursor glPanCursor (globalPanPixmap);
+    myCurScale = aView3d->Scale();
+    aView3d->FitAll(0.01, false);
+    myCursor = cursor();                // save old cursor
+    myViewPort->fitAll(); // fits view before selecting a new scene center
+    if( setTransformRequested( PANGLOBAL ) )
+      myViewPort->setCursor( glPanCursor );
+  }
+}
+
 /*!
   \brief Start rotation operation
 
@@ -900,3 +984,139 @@ void XGUI_ViewWindow::setBackground( const XGUI_ViewBackground& theBackground )
 {
   if ( myViewPort ) myViewPort->setBackground( theBackground );
 }
+
+/*!
+   \brief Create one more window with same content.
+*/
+void XGUI_ViewWindow::cloneView()
+{
+  QMdiSubWindow* vw = myViewer->createView();
+  //vw->show();
+  emit viewCloned( vw );
+}
+
+void XGUI_ViewWindow::dumpView()
+{
+    QString aFilter(tr("OCC_IMAGE_FILES"));
+    QString aSelectedFilter;
+    QString aFileName = QFileDialog::getSaveFileName(this, "Save picture", QString(), aFilter, &aSelectedFilter);
+    if (!aFileName.isNull()) {
+        QApplication::setOverrideCursor( Qt::WaitCursor );
+        QImage aPicture = myViewPort->dumpView();
+
+        QString aFmt = extension(aFileName).toUpper();
+        if( aFmt.isEmpty() )
+            aFmt = QString( "BMP" ); // default format
+        else if( aFmt == "JPG" )
+            aFmt = "JPEG";
+          
+        Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
+        if (aFmt == "PS")
+            a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
+        else if (aFmt == "EPS")
+            a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
+        else
+            aPicture.save( aFileName, aFmt.toLatin1() );
+        QApplication::restoreOverrideCursor();
+    }
+}
+
+void XGUI_ViewWindow::fitAll()
+{
+    emit vpTransformationStarted( FITALLVIEW );
+    myViewPort->fitAll();
+    emit vpTransformationFinished( FITALLVIEW );
+}
+
+/*!
+  \brief Starts fit operation.
+
+  Sets the corresponding cursor for the widget.
+*/
+void XGUI_ViewWindow::activateWindowFit()
+{
+  if ( !transformRequested() && !myCursorIsHand )
+    myCursor = cursor();                /* save old cursor */
+
+  if ( myOperation != WINDOWFIT ) {
+    QCursor handCursor (Qt::PointingHandCursor);
+    if( setTransformRequested ( WINDOWFIT ) )
+    {
+      myViewPort->setCursor ( handCursor );
+      myCursorIsHand = true;
+    }
+  }
+}
+
+
+/*!
+  \brief Perform "front view" transformation.
+*/
+void XGUI_ViewWindow::frontView()
+{
+  emit vpTransformationStarted ( FRONTVIEW );
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
+  myViewPort->fitAll();
+  emit vpTransformationFinished ( FRONTVIEW );
+}
+
+/*!
+  \brief Perform "back view" transformation.
+*/
+void XGUI_ViewWindow::backView()
+{
+  emit vpTransformationStarted ( BACKVIEW );
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
+  myViewPort->fitAll();
+  emit vpTransformationFinished ( BACKVIEW );
+}
+
+/*!
+  \brief Perform "top view" transformation.
+*/
+void XGUI_ViewWindow::topView()
+{
+  emit vpTransformationStarted ( TOPVIEW );
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
+  myViewPort->fitAll();
+  emit vpTransformationFinished ( TOPVIEW );
+}
+
+/*!
+  \brief Perform "bottom view" transformation.
+*/
+void XGUI_ViewWindow::bottomView()
+{
+  emit vpTransformationStarted ( BOTTOMVIEW );
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
+  myViewPort->fitAll();
+  emit vpTransformationFinished ( BOTTOMVIEW );
+}
+
+/*!
+  \brief Perform "left view" transformation.
+*/
+void XGUI_ViewWindow::leftView()
+{
+  emit vpTransformationStarted ( LEFTVIEW );
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
+  myViewPort->fitAll();
+  emit vpTransformationFinished ( LEFTVIEW );
+}
+
+/*!
+  \brief Perform "right view" transformation.
+*/
+void XGUI_ViewWindow::rightView()
+{
+  emit vpTransformationStarted ( RIGHTVIEW );
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
+  myViewPort->fitAll();
+  emit vpTransformationFinished ( RIGHTVIEW );
+}
index 1d794e94d6a4a57f93854e2289ac54909312e2d0..0938e1b97c23297ebe52411ea33438928b10c28f 100644 (file)
@@ -18,6 +18,7 @@ class XGUI_Viewer;
 class ViewerToolbar;
 class ViewerLabel;
 class XGUI_RectRubberBand;
+class QMdiSubWindow;
 
 class XGUI_ViewWindow : public QFrame
 {
@@ -44,10 +45,12 @@ public:
     XGUI_ViewBackground background() const;
     void setBackground( const XGUI_ViewBackground& theBackground );
 
+    bool closable() const { return myClosable; }
+    void setClosable( const bool isClosable ) { myClosable = isClosable; }
+
 signals:
     void vpTransformationStarted(XGUI_ViewWindow::OperationType type);
     void vpTransformationFinished(XGUI_ViewWindow::OperationType type);
-    //void viewCloned( XGUI_ViewWindow* );
 
     void Show( QShowEvent * );
     void Hide( QHideEvent * );
@@ -56,21 +59,35 @@ signals:
 
 
     void tryClosing( XGUI_ViewWindow* );
-    void closing( XGUI_ViewWindow* );
+    void closed( QMdiSubWindow* );
     void mousePressed( XGUI_ViewWindow*, QMouseEvent* );
     void mouseReleased( XGUI_ViewWindow*, QMouseEvent* );
     void mouseDoubleClicked( XGUI_ViewWindow*, QMouseEvent* );
     void mouseMoving( XGUI_ViewWindow*, QMouseEvent* );
-    void wheeling( XGUI_ViewWindow*, QWheelEvent* );
     void keyPressed( XGUI_ViewWindow*, QKeyEvent* );
     void keyReleased( XGUI_ViewWindow*, QKeyEvent* );
     void contextMenuRequested( QContextMenuEvent *e );
+
     void viewModified( XGUI_ViewWindow* );
+    void viewCloned( QMdiSubWindow* theView );
 
 public slots:
     void activateZoom();
     void activateRotation();
     void activatePanning();
+    void activateWindowFit();
+    void activateGlobalPanning();
+
+    void cloneView();
+    void dumpView();
+    void fitAll();
+    
+    void frontView();
+    void backView();
+    void topView();
+    void bottomView();
+    void leftView();
+    void rightView();
 
 protected:
     virtual void resizeEvent(QResizeEvent* theEvent);
@@ -147,6 +164,7 @@ private:
     bool myCursorIsHand;                 
     bool myIsKeyFree;
     bool myEventStarted;       // set when transformation is in process 
+    bool myClosable;
 
     QCursor myCursor;
   
index 77b61accaf6fe7d7f38c01183e33e98a3c6cb573..c8cd002b9b9a3bab4ca329b42979b8174d684be1 100644 (file)
@@ -90,7 +90,8 @@ QObject(theParent),
     myMultiSelectionEnabled(true),
     myIsRelative(true),
     myInteractionStyle(XGUI::STANDARD),
-    myTrihedronSize(100)
+    myTrihedronSize(100),
+    myActiveView(0)
 {
     if ( !isInitialized ) {
         isInitialized = true;
@@ -173,13 +174,16 @@ QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType)
     // set default background for view window
     //vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
     //// connect signal from viewport
-    connect(view->viewPort(), SIGNAL(vpClosed()), this, SLOT(onViewClosed()));
-    connect(view->viewPort(), SIGNAL(vpMapped()), this, SLOT(onViewMapped()));
+    //connect(view->viewPort(), SIGNAL(vpClosed()), this, SLOT(onViewClosed()));
+    //connect(view->viewPort(), SIGNAL(vpMapped()), this, SLOT(onViewMapped()));
+    if (myViews.size() == 0) 
+        setTrihedronShown(true);
 
     view->setBackground(XGUI_ViewBackground(XGUI::VerticalGradient, Qt::green, Qt::blue));
 
     QMdiArea* aMDI = myMainWindow->mdiArea();
     QMdiSubWindow* aWnd = aMDI->addSubWindow(view, Qt::FramelessWindowHint);
+    addView(aWnd);
     aWnd->setGeometry(0,0, aMDI->width() / 2, aMDI->height() / 2);
     aWnd->show();
     return aWnd;
@@ -333,19 +337,86 @@ bool XGUI_Viewer::computeTrihedronSize( double& theNewSize, double& theSize )
 }
 
 
-void XGUI_Viewer::onViewClosed()
+void XGUI_Viewer::onViewClosed(QMdiSubWindow* theView)
 {
-  Standard_Integer aViewsNb = 0;
-  for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews())
-    ++aViewsNb;
-  if ( aViewsNb < 2 ) {
-    //clean up presentations before last view is closed
-    myAISContext->RemoveAll(Standard_False);
-  }
+    if ( !theView )
+        return;
+
+    emit deleteView( static_cast<XGUI_ViewWindow*>(theView->widget()) );
+    removeView( theView );
+
+    // if this is last view
+    if (myViews.size() == 0) {
+        Standard_Integer aViewsNb = 0;
+        for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews())
+            ++aViewsNb;
+        if ( aViewsNb < 2 ) {
+            //clean up presentations before last view is closed
+            myAISContext->RemoveAll(Standard_False);
+        }
+    }
+}
+
+/*!Remove view window \a theView from view manager.
+ *And close the last view, if it has \a theView.
+*/
+void XGUI_Viewer::removeView( QMdiSubWindow* theView )
+{
+    XGUI_ViewWindow* aWindow = static_cast<XGUI_ViewWindow*>(theView->widget());
+
+    aWindow->disconnect( this );
+    myViews.removeAt( myViews.indexOf( theView ) );
+    if ( myActiveView == theView )
+        myActiveView = 0;
+    if ( myViews.size() == 0 )
+        emit lastViewClosed();
 }
 
-void XGUI_Viewer::onViewMapped()
+
+/*void XGUI_Viewer::onViewMapped()
 {
   setTrihedronShown( true );
+}*/
+
+
+void XGUI_Viewer::addView(QMdiSubWindow* theView)
+{
+    XGUI_ViewWindow* aWindow = dynamic_cast<XGUI_ViewWindow*>(theView->widget());
+
+    connect(aWindow, SIGNAL(closed(QMdiSubWindow*)),
+            this,    SLOT(onViewClosed(QMdiSubWindow*)));
+
+    connect(aWindow, SIGNAL(tryClosing(XGUI_ViewWindow*)),
+            this,    SIGNAL(tryCloseView(XGUI_ViewWindow*)));
+
+    connect(aWindow, SIGNAL(mousePressed(XGUI_ViewWindow*, QMouseEvent*)),
+            this,    SLOT(onMousePressed(XGUI_ViewWindow*, QMouseEvent*)));
+
+    connect(aWindow, SIGNAL(mouseReleased(XGUI_ViewWindow*, QMouseEvent*)),
+            this,    SIGNAL(mouseRelease(XGUI_ViewWindow*, QMouseEvent*)));
+
+    connect(aWindow, SIGNAL(mouseDoubleClicked(XGUI_ViewWindow*, QMouseEvent*)),
+            this,    SIGNAL(mouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)));
+
+    connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)),
+            this,    SIGNAL(mouseMove(XGUI_ViewWindow*, QMouseEvent*)));
+
+    connect(aWindow, SIGNAL(keyPressed(XGUI_ViewWindow*, QKeyEvent*)),
+            this,    SIGNAL(keyPress(XGUI_ViewWindow*, QKeyEvent*)));
+
+    connect(aWindow, SIGNAL(keyReleased(XGUI_ViewWindow*, QKeyEvent*)),
+            this,    SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*)));
+
+    connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )),
+            this,    SLOT  (onContextMenuRequested( QContextMenuEvent* )));
+
+    myViews.append(theView);
 }
 
+/*!
+    Emit activated for view \a view.
+*/
+void XGUI_Viewer::onWindowActivated(QMdiSubWindow* view)
+{
+    myActiveView = view;
+}
index 78cfe55a55774c691e18f1e8ea1dcace83dd4df7..92bc5319220d46ce48d005dc215d39f1c811e205 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <QObject>
 #include <QMap>
+#include <QList>
 
 #include <V3d_Viewer.hxx>
 #include <AIS_InteractiveContext.hxx>
@@ -13,6 +14,9 @@
 
 class XGUI_MainWindow;
 class QMdiSubWindow;
+class XGUI_ViewWindow;
+class QMouseEvent;
+class QKeyEvent;
 
 class XGUI_Viewer : public QObject
 {
@@ -58,9 +62,29 @@ public:
     static InteractionStyle2StatesMap  myStateMap;
     static InteractionStyle2ButtonsMap myButtonMap;
 
+signals:
+    void lastViewClosed();
+    void tryCloseView(XGUI_ViewWindow* theWindow);
+    void deleteView(XGUI_ViewWindow* theWindow);
+    void viewCreated(XGUI_ViewWindow* theWindow);
+    void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
+    void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
+    void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
+    void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
+    void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
+    void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
+    void activated(XGUI_ViewWindow* theWindow);
+
 private slots:
-    void onViewClosed();
-    void onViewMapped();
+    void onViewClosed(QMdiSubWindow*);
+    //void onViewMapped();
+    void onWindowActivated(QMdiSubWindow*);
+
+private:
+    void addView(QMdiSubWindow* theView);
+
+    /*! Removes the View from internal Views list.*/
+    void removeView(QMdiSubWindow* theView);
 
 private:
     XGUI_MainWindow* myMainWindow;
@@ -77,6 +101,10 @@ private:
     bool myIsRelative;
 
     double myTrihedronSize;
+  
+    QList<QMdiSubWindow*> myViews;
+
+    QMdiSubWindow* myActiveView;
 };
 
 #endif
\ No newline at end of file
index 55984e58040a72237d1f5161fc843df45020c647..f9090d15d24e2465561be66ac6b35824d9f5944d 100644 (file)
         <translation>Image files (*.bmp *.gif *.pix *.xwd *.rgb *.rs)</translation>
     </message>
 </context>
+<context>
+    <name>XGUI_ViewWindow</name>
+    <message>
+        <source>OCC_IMAGE_FILES</source>
+        <translation>Images Files (*.bmp *.png *.jpg *.jpeg *.eps *.ps)</translation>
+    </message>
+    <message>
+        <source>DUMP_VIEW</source>
+        <translation>Dump view</translation>
+    </message>
+    <message>
+        <source>FIT_ALL</source>
+        <translation>Fit all</translation>
+    </message>
+    <message>
+        <source>FIT_AREA</source>
+        <translation>Fit area</translation>
+    </message>
+    <message>
+        <source>CLONE_VIEW</source>
+        <translation>Clone view</translation>
+    </message>
+    <message>
+        <source>ZOOM_VIEW</source>
+        <translation>Zoom</translation>
+    </message>
+    <message>
+        <source>PAN_VIEW</source>
+        <translation>Panning</translation>
+    </message>
+    <message>
+        <source>GLOB_PAN_VIEW</source>
+        <translation>Global panning</translation>
+    </message>
+    <message>
+        <source>ROTATE_VIEW</source>
+        <translation>Rotate</translation>
+    </message>
+    <message>
+        <source>FRONT_VIEW</source>
+        <translation>Front</translation>
+    </message>
+    <message>
+        <source>BACK_VIEW</source>
+        <translation>Back</translation>
+    </message>
+    <message>
+        <source>TOP_VIEW</source>
+        <translation>Top</translation>
+    </message>
+    <message>
+        <source>BOTTOM_VIEW</source>
+        <translation>Bottom</translation>
+    </message>
+    <message>
+        <source>LEFT_VIEW</source>
+        <translation>Left</translation>
+    </message>
+    <message>
+        <source>RIGHT_VIEW</source>
+        <translation>Right</translation>
+    </message>
+</context>
 </TS>