From: vsv Date: Tue, 1 Apr 2014 06:15:12 +0000 (+0400) Subject: Merge branch 'master' of newgeom:newgeom X-Git-Tag: V_0.1~43 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e1f8fb3cfc1ee565db16fbbd9fe6f65121c4577c;p=modules%2Fshaper.git Merge branch 'master' of newgeom:newgeom Conflicts: 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 --- e1f8fb3cfc1ee565db16fbbd9fe6f65121c4577c diff --cc src/XGUI/XGUI_ViewPort.cpp index abcb6a3dd,997845808..2202683d5 --- a/src/XGUI/XGUI_ViewPort.cpp +++ b/src/XGUI/XGUI_ViewPort.cpp @@@ -706,27 -717,13 +717,27 @@@ void XGUI_ViewPort::zoom(int x0, int y0 } /*! - Sets the background data - */ - void XGUI_ViewPort::setBackground( const XGUI_ViewBackground& bgData ) + Sets the background data + */ + void XGUI_ViewPort::setBackground(const XGUI_ViewBackground& bgData) { - if ( bgData.isValid() ) { - myBackground = bgData; - updateBackground(); - emit vpChangeBackground( myBackground ); - } + if (bgData.isValid()) { + myBackground = bgData; + updateBackground(); + 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( ); +} diff --cc src/XGUI/XGUI_ViewPort.h index 10dd2356a,e03dad5d0..ccffe4f1a --- a/src/XGUI/XGUI_ViewPort.h +++ b/src/XGUI/XGUI_ViewPort.h @@@ -11,76 -10,87 +10,88 @@@ class XGUI_ViewWindow; - class XGUI_ViewPort : public QWidget + class XGUI_ViewPort: public QWidget { - Q_OBJECT + Q_OBJECT public: - XGUI_ViewPort(XGUI_ViewWindow* theParent, - const Handle(V3d_Viewer)& theViewer, - V3d_TypeOfView theType = V3d_ORTHOGRAPHIC); - ~XGUI_ViewPort(); - - virtual QPaintEngine* paintEngine() const { return 0; } + XGUI_ViewPort(XGUI_ViewWindow* theParent, const Handle(V3d_Viewer)& theViewer, + V3d_TypeOfView theType = V3d_ORTHOGRAPHIC); + ~XGUI_ViewPort(); + + virtual QPaintEngine* paintEngine() const + { + return 0; + } + + QImage dumpView(QRect theRect = QRect(), bool toUpdate = true); + + Handle(V3d_View) getView() const + { + return activeView(); + } + + void startRotation(int x, int y, int theRotationPointType, const gp_Pnt& theSelectedPoint); + void rotate(int, int, int, const gp_Pnt&); + void endRotation(); + + // TRANSFORMATIONS + void pan(int dx, int dy); + void setCenter(int x, int y); + 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); - QImage dumpView(QRect theRect = QRect(), bool toUpdate = true); + void setAdvancedZoomingEnabled(const bool theState) + { + myIsAdvancedZoomingEnabled = theState; + } + bool isAdvancedZoomingEnabled() const + { + return myIsAdvancedZoomingEnabled; + } + + XGUI_ViewBackground background() const + { + return myBackground; + } + void setBackground(const XGUI_ViewBackground& bgData); - Handle(V3d_View) getView() const { return activeView(); } + signals: + void vpChangeBackground(const XGUI_ViewBackground&); + void vpClosed(); + void vpMapped(); + void vpTransformed(); + void vpUpdated(); - void startRotation( int x, int y, int theRotationPointType, const gp_Pnt& theSelectedPoint ); - void rotate( int, int, int, const gp_Pnt& ); - void endRotation(); + protected: + virtual void paintEvent(QPaintEvent*); + virtual void resizeEvent(QResizeEvent*); - // TRANSFORMATIONS - void pan( int dx, int dy ); - void setCenter( int x, int y ); - 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); + private: + Handle(V3d_View) activeView() const + { + return myActiveView; + } - void setAdvancedZoomingEnabled( const bool theState ) { myIsAdvancedZoomingEnabled = theState; } - bool isAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; } + bool mapView(const Handle(V3d_View)& theView); + bool setWindow(const Handle(V3d_View)& theView); + bool mapped(const Handle(V3d_View)& theView) const; + void updateBackground(); + void attachWindow(const Handle(V3d_View)& theView, const Handle(Aspect_Window)& theWnd); - XGUI_ViewBackground background() const { return myBackground; } - void setBackground( const XGUI_ViewBackground& bgData ); + Handle(V3d_View) myOrthoView;Handle(V3d_View) myPerspView;Handle(V3d_View) myActiveView; - signals: - void vpChangeBackground( const XGUI_ViewBackground& ); - void vpClosed(); - void vpMapped(); - void vpTransformed( ); - void vpUpdated(); + Handle(Aspect_Window) myWindow; - protected: - virtual void paintEvent( QPaintEvent* ); - virtual void resizeEvent( QResizeEvent* ); + bool myPaintersRedrawing; + bool myIsAdvancedZoomingEnabled; + double myScale; - private: - Handle(V3d_View) activeView() const { return myActiveView; } - - bool mapView( const Handle(V3d_View)& theView); - bool setWindow( const Handle(V3d_View)& theView); - bool mapped( const Handle(V3d_View)& theView) const; - void updateBackground(); - void attachWindow( const Handle(V3d_View)& theView, const Handle(Aspect_Window)& theWnd); - - - Handle(V3d_View) myOrthoView; - Handle(V3d_View) myPerspView; - Handle(V3d_View) myActiveView; - - Handle(Aspect_Window) myWindow; - - bool myPaintersRedrawing; - bool myIsAdvancedZoomingEnabled; - - double myScale; - - XGUI_ViewBackground myBackground; - int myBgImgHeight; - int myBgImgWidth; + XGUI_ViewBackground myBackground; + int myBgImgHeight; + int myBgImgWidth; }; - - #endif + #endif diff --cc src/XGUI/XGUI_ViewWindow.cpp index 8370775d9,7d410b874..74356cac6 --- a/src/XGUI/XGUI_ViewWindow.cpp +++ b/src/XGUI/XGUI_ViewWindow.cpp @@@ -170,141 -109,87 +111,140 @@@ void ViewerLabel::paintEvent(QPaintEven //************************************************************************** //************************************************************************** //************************************************************************** - XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, - V3d_TypeOfView theType): - QFrame(), - myViewer(theViewer), - myMoving(false), - MinimizeIco(":pictures/wnd_minimize.png"), - MaximizeIco(":pictures/wnd_maximize.png"), - CloseIco(":pictures/wnd_close.png"), - RestoreIco(":pictures/wnd_restore.png"), - myInteractionStyle(XGUI::STANDARD), - myRectBand(0), - myIsKeyFree(false), - my2dMode(XGUI::No2dMode), - myCurrPointType(XGUI::GRAVITY), - myPrevPointType(XGUI::GRAVITY), + XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType) - : QFrame(), myViewer(theViewer), myMoving(false), MinimizeIco(":pictures/wnd_minimize.png"), MaximizeIco( - ":pictures/wnd_maximize.png"), CloseIco(":pictures/wnd_close.png"), RestoreIco( - ":pictures/wnd_restore.png"), myInteractionStyle(XGUI::STANDARD), myRectBand(0), myIsKeyFree( - false), my2dMode(XGUI::No2dMode), myCurrPointType(XGUI::GRAVITY), myPrevPointType( - XGUI::GRAVITY), myRotationPointSelection(false) ++ : QFrame(), ++ myViewer(theViewer), ++ myMoving(false), ++ MinimizeIco(":pictures/wnd_minimize.png"), ++ MaximizeIco(":pictures/wnd_maximize.png"), ++ CloseIco(":pictures/wnd_close.png"), ++ RestoreIco(":pictures/wnd_restore.png"), ++ myInteractionStyle(XGUI::STANDARD), ++ myRectBand(0), ++ myIsKeyFree(false), ++ my2dMode(XGUI::No2dMode), ++ myCurrPointType(XGUI::GRAVITY), ++ myPrevPointType(XGUI::GRAVITY), + myRotationPointSelection(false), + myClosable(false) { - mySelectedPoint = gp_Pnt(0.,0.,0.); - setFrameStyle(QFrame::Raised); - setFrameShape(QFrame::Panel); - setLineWidth(BORDER_SIZE); - setMouseTracking(true); - - QVBoxLayout* aLay = new QVBoxLayout(this); - aLay->setContentsMargins(BORDER_SIZE,BORDER_SIZE,BORDER_SIZE,BORDER_SIZE); - myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType); - myViewPort->installEventFilter(this); - aLay->addWidget(myViewPort); - - myPicture = new QLabel(this); - myPicture->setFrameStyle(QFrame::Sunken); - myPicture->setFrameShape(QFrame::Panel); - myPicture->setMouseTracking(true); - myPicture->installEventFilter(this); - aLay->addWidget(myPicture); - myPicture->hide(); - - myGripWgt = new ViewerLabel(this, myViewPort); - myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png")); - myGripWgt->setGeometry(BORDER_SIZE + 2, BORDER_SIZE + 2, 19, 32); - myGripWgt->setMouseTracking(true); - myGripWgt->installEventFilter(this); - connect(myViewPort, SIGNAL(vpTransformed()), myGripWgt, SLOT(update())); - connect(myViewPort, SIGNAL(vpUpdated()), myGripWgt, SLOT(update())); + mySelectedPoint = gp_Pnt(0., 0., 0.); + setFrameStyle(QFrame::Raised); + setFrameShape(QFrame::Panel); + setLineWidth(BORDER_SIZE); + setMouseTracking(true); + + QVBoxLayout* aLay = new QVBoxLayout(this); + aLay->setContentsMargins(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE); + myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType); + 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); + myGripWgt->setMouseTracking(true); + myGripWgt->installEventFilter(this); + connect(myViewPort, SIGNAL(vpTransformed()), myGripWgt, SLOT(update())); + connect(myViewPort, SIGNAL(vpUpdated()), myGripWgt, SLOT(update())); + // Create Viewer management buttons - myViewBar = new ViewerToolbar(this, myViewPort); + myViewBar = new ViewerToolbar(this, myViewPort); - QAction* aBtn; + QAction* aBtn; - for(int i = 0; i < aTitles.length(); i++) { - aBtn = new QAction(QIcon(aPictures.at(i)), aTitles.at(i), myViewBar); + + // 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())); + 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())); + myWindowBar = new ViewerToolbar(this, myViewPort); + connect(myViewPort, SIGNAL(vpTransformed()), myWindowBar, SLOT(update())); + connect(myViewPort, SIGNAL(vpUpdated()), myWindowBar, SLOT(update())); - myMinimizeBtn = new QAction(myWindowBar); - myMinimizeBtn->setIcon(MinimizeIco); - myWindowBar->addAction(myMinimizeBtn); - connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize())); + myMinimizeBtn = new QAction(myWindowBar); + myMinimizeBtn->setIcon(MinimizeIco); + myWindowBar->addAction(myMinimizeBtn); + connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize())); - myMaximizeBtn = new QAction(myWindowBar); - myMaximizeBtn->setIcon(MaximizeIco); - myWindowBar->addAction(myMaximizeBtn); - connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize())); + myMaximizeBtn = new QAction(myWindowBar); + myMaximizeBtn->setIcon(MaximizeIco); + myWindowBar->addAction(myMaximizeBtn); + connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize())); - aBtn = new QAction(myWindowBar); - aBtn->setIcon(CloseIco); - myWindowBar->addAction(aBtn); - connect(aBtn, SIGNAL(triggered()), SLOT(onClose())); + aBtn = new QAction(myWindowBar); + aBtn->setIcon(CloseIco); + myWindowBar->addAction(aBtn); + connect(aBtn, SIGNAL(triggered()), SLOT(onClose())); - myViewBar->hide(); - myWindowBar->hide(); - myGripWgt->hide(); + myViewBar->hide(); + myWindowBar->hide(); + myGripWgt->hide(); } //**************************************************************** @@@ -330,26 -216,26 +271,26 @@@ void XGUI_ViewWindow::resizeEvent(QResi void XGUI_ViewWindow::changeEvent(QEvent* theEvent) { - if (theEvent->type() == QEvent::WindowStateChange) { - if (isMinimized()) { + if (theEvent->type() == QEvent::WindowStateChange) { + if (isMinimized()) { - if (!myPicture->parentWidget()) { - QMdiSubWindow* aParent = static_cast(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(); + myPicture->show(); + } else { + myPicture->hide(); + myViewPort->show(); - if (isMaximized()) { - myMinimizeBtn->setIcon(MinimizeIco); - myMaximizeBtn->setIcon(RestoreIco); - } - } - } else - QWidget::changeEvent(theEvent); + if (isMaximized()) { + myMinimizeBtn->setIcon(MinimizeIco); + myMaximizeBtn->setIcon(RestoreIco); + } + } + } else + QWidget::changeEvent(theEvent); } + //**************************************************************** void XGUI_ViewWindow::onClose() { @@@ -365,12 -247,12 +306,12 @@@ //**************************************************************** void XGUI_ViewWindow::enterEvent(QEvent* theEvent) { - if (!isMinimized()) { - myViewBar->show(); + if (!isMinimized()) { + myViewBar->show(); + myWindowBar->show(); - if (!isMaximized()) - myGripWgt->show(); - } + if (!isMaximized()) + myGripWgt->show(); + } - myWindowBar->show(); } //**************************************************************** @@@ -384,17 -266,14 +325,17 @@@ void XGUI_ViewWindow::leaveEvent(QEvent //**************************************************************** void XGUI_ViewWindow::onMinimize() { - QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView()); - int aW = width(); - int aH = height(); - double aR = aW / 100.; + QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView()); + 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(); + + myLastState = isMaximized() ? MaximizedState : NormalState; + showMinimized(); + parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), + 100, aNewH); } //**************************************************************** @@@ -415,91 -294,77 +356,88 @@@ void XGUI_ViewWindow::onMaximize( //**************************************************************** bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent) { - switch (theEvent->type()) { - case QEvent::MouseButtonPress: - { - QMouseEvent* aEvent = static_cast(theEvent); - if ((aEvent->button() == Qt::LeftButton) && (!myMoving)){ - myMoving = true; - myMousePnt = aEvent->globalPos(); - return true; - } - } - break; - case QEvent::MouseButtonRelease: - { - QMouseEvent* aEvent = static_cast(theEvent); - if ((aEvent->button() == Qt::LeftButton) && myMoving) { - myMoving = false; - return true; - } - } - break; - case QEvent::MouseMove: - { - QMouseEvent* aEvent = static_cast(theEvent); - if (myMoving) { - QMdiSubWindow* aParent = static_cast(parentWidget()); - QMdiArea* aMDIArea = aParent->mdiArea(); - - QPoint aPnt = aEvent->globalPos(); - QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt); - if (aMDIArea->rect().contains(aMDIPnt)) { - QWidget* aWgt = (theObj == myPicture) ? myPicture : static_cast(parentWidget()); + switch(theEvent->type()) { + case QEvent::MouseButtonPress: { + QMouseEvent* aEvent = static_cast(theEvent); + if ((aEvent->button() == Qt::LeftButton) && (!myMoving)) { + myMoving = true; + myMousePnt = aEvent->globalPos(); + return true; + } + } + break; + case QEvent::MouseButtonRelease: { + QMouseEvent* aEvent = static_cast(theEvent); + if ((aEvent->button() == Qt::LeftButton) && myMoving) { + myMoving = false; + return true; + } + } + break; + case QEvent::MouseMove: { + QMouseEvent* aEvent = static_cast(theEvent); + if (myMoving) { + QMdiSubWindow* aParent = static_cast(parentWidget()); + QMdiArea* aMDIArea = aParent->mdiArea(); + + 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; - } - } - break; - case QEvent::MouseButtonDblClick: - if (theObj == myPicture) { - myMoving = false; - if (myLastState == MaximizedState) - showMaximized(); - else - showNormal(); - return true; - } + myMousePnt = aPnt; + } + return true; + } + } + break; + case QEvent::MouseButtonDblClick: + if (theObj == myPicture) { + myMoving = false; + if (myLastState == MaximizedState) + showMaximized(); + else + showNormal(); + return true; } - return false; + } + return false; } //**************************************************************** bool XGUI_ViewWindow::processViewPort(QEvent *theEvent) { - switch(theEvent->type()) { - case QEvent::MouseButtonPress: - vpMousePressEvent((QMouseEvent*) theEvent); - return true; + switch(theEvent->type()) { + case QEvent::MouseButtonPress: + vpMousePressEvent((QMouseEvent*) theEvent); + return true; - case QEvent::MouseButtonRelease: - vpMouseReleaseEvent((QMouseEvent*) theEvent); - return true; + case QEvent::MouseButtonRelease: + vpMouseReleaseEvent((QMouseEvent*) theEvent); + return true; - case QEvent::MouseMove: - vpMouseMoveEvent((QMouseEvent*) theEvent); - return true; + case QEvent::MouseMove: + vpMouseMoveEvent((QMouseEvent*) theEvent); + return true; - case QEvent::MouseButtonDblClick: - emit mouseDoubleClicked(this, (QMouseEvent*)theEvent); - return true; + 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; + } + return false; } //**************************************************************** @@@ -888,67 -752,46 +825,66 @@@ void XGUI_ViewWindow::setTransformEnabl } /*! - \return enabled state of transformation (rotate, zoom, etc) - */ - bool XGUI_ViewWindow::transformEnabled( const OperationType id ) const + \return enabled state of transformation (rotate, zoom, etc) + */ + bool XGUI_ViewWindow::transformEnabled(const OperationType id) const { - return myStatus.contains( id ) ? myStatus[ id ] : true; + return myStatus.contains(id) ? myStatus[id] : true; } - /*! - \brief Start panning operation. + \brief Start panning operation. - Sets the corresponding cursor for the widget. - */ + Sets the corresponding cursor for the widget. + */ void XGUI_ViewWindow::activatePanning() { - if ( !transformRequested() && !myCursorIsHand ) - myCursor = cursor(); // save old cursor + if (!transformRequested() && !myCursorIsHand) + myCursor = cursor(); // save old cursor - if ( myOperation != PANVIEW ) { - QCursor panCursor (Qt::SizeAllCursor); - if( setTransformRequested ( PANVIEW ) ) - myViewPort->setCursor( panCursor ); - } + if (myOperation != PANVIEW) { + QCursor panCursor(Qt::SizeAllCursor); + if (setTransformRequested(PANVIEW)) + myViewPort->setCursor(panCursor); + } } +/*! + \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 + \brief Start rotation operation - Sets the corresponding cursor for the widget. - */ + Sets the corresponding cursor for the widget. + */ void XGUI_ViewWindow::activateRotation() { - if ( !transformRequested() && !myCursorIsHand ) - myCursor = cursor(); // save old cursor + if (!transformRequested() && !myCursorIsHand) + myCursor = cursor(); // save old cursor - if ( myOperation != ROTATE ) { - QPixmap rotatePixmap (imageRotateCursor); - QCursor rotCursor (rotatePixmap); - if( setTransformRequested ( ROTATE ) ) - myViewPort->setCursor( rotCursor ); - } + if (myOperation != ROTATE) { + QPixmap rotatePixmap(imageRotateCursor); + QCursor rotCursor(rotatePixmap); + if (setTransformRequested(ROTATE)) + myViewPort->setCursor(rotCursor); + } } /*! @@@ -979,144 -822,9 +915,145 @@@ XGUI_ViewBackground XGUI_ViewWindow::ba { return myViewPort ? myViewPort->background() : XGUI_ViewBackground(); } - - void XGUI_ViewWindow::setBackground( const XGUI_ViewBackground& theBackground ) + + void XGUI_ViewWindow::setBackground(const XGUI_ViewBackground& theBackground) { - if ( myViewPort ) myViewPort->setBackground( theBackground ); - if (myViewPort) - myViewPort->setBackground(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 ); } diff --cc src/XGUI/XGUI_ViewWindow.h index 0938e1b97,e77a4ee60..de6837a5a --- a/src/XGUI/XGUI_ViewWindow.h +++ b/src/XGUI/XGUI_ViewWindow.h @@@ -18,183 -18,193 +18,211 @@@ class XGUI_Viewer class ViewerToolbar; class ViewerLabel; class XGUI_RectRubberBand; +class QMdiSubWindow; - class XGUI_ViewWindow : public QFrame + class XGUI_ViewWindow: public QFrame { - Q_OBJECT + Q_OBJECT public: - enum OperationType{ NOTHING, PANVIEW, ZOOMVIEW, ROTATE, - PANGLOBAL, WINDOWFIT, FITALLVIEW, RESETVIEW, - FRONTVIEW, BACKVIEW, TOPVIEW, BOTTOMVIEW, LEFTVIEW, RIGHTVIEW, - CLOCKWISEVIEW, ANTICLOCKWISEVIEW }; - - XGUI_ViewWindow(XGUI_Viewer* theViewer, - V3d_TypeOfView theType); - - virtual ~XGUI_ViewWindow(); - - XGUI_ViewPort* viewPort() const { return myViewPort; } - - - XGUI::InteractionStyle interactionStyle() const { return myInteractionStyle; } - - void setTransformEnabled( const OperationType, const bool ); - bool transformEnabled( const OperationType ) const; - - XGUI_ViewBackground background() const; - void setBackground( const XGUI_ViewBackground& theBackground ); + enum OperationType + { + NOTHING, + PANVIEW, + ZOOMVIEW, + ROTATE, + PANGLOBAL, + WINDOWFIT, + FITALLVIEW, + RESETVIEW, + FRONTVIEW, + BACKVIEW, + TOPVIEW, + BOTTOMVIEW, + LEFTVIEW, + RIGHTVIEW, + CLOCKWISEVIEW, + ANTICLOCKWISEVIEW + }; + + XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType); + + virtual ~XGUI_ViewWindow(); + + XGUI_ViewPort* viewPort() const + { + return myViewPort; + } + + XGUI::InteractionStyle interactionStyle() const + { + return myInteractionStyle; + } + + void setTransformEnabled(const OperationType, const bool); + bool transformEnabled(const OperationType) const; + + 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 Show( QShowEvent * ); - void Hide( QHideEvent * ); - void maximized( XGUI_ViewWindow*, bool ); - void returnedTo3d( ); + void vpTransformationStarted(XGUI_ViewWindow::OperationType type); + void vpTransformationFinished(XGUI_ViewWindow::OperationType type); - //void viewCloned( XGUI_ViewWindow* ); + void Show(QShowEvent *); + void Hide(QHideEvent *); + void maximized(XGUI_ViewWindow*, bool); + void returnedTo3d(); - void tryClosing( XGUI_ViewWindow* ); + 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 keyPressed( XGUI_ViewWindow*, QKeyEvent* ); - void keyReleased( XGUI_ViewWindow*, QKeyEvent* ); - void contextMenuRequested( QContextMenuEvent *e ); - - void viewModified( XGUI_ViewWindow* ); + 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 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); + virtual void resizeEvent(QResizeEvent* theEvent); - virtual void changeEvent(QEvent* theEvent); + virtual void changeEvent(QEvent* theEvent); - virtual void enterEvent(QEvent* theEvent); - virtual void leaveEvent(QEvent* theEvent); + virtual void enterEvent(QEvent* theEvent); + virtual void leaveEvent(QEvent* theEvent); - virtual bool eventFilter(QObject *theObj, QEvent *theEvent); + virtual bool eventFilter(QObject *theObj, QEvent *theEvent); private slots: - void onClose(); - void onMinimize(); - void onMaximize(); + void onClose(); + void onMinimize(); + void onMaximize(); private: - enum WindowState { MinimizedState, MaximizedState, NormalState }; + enum WindowState + { + MinimizedState, MaximizedState, NormalState + }; + + bool processWindowControls(QObject *theObj, QEvent *theEvent); + bool processViewPort(QEvent *theEvent); - bool processWindowControls(QObject *theObj, QEvent *theEvent); - bool processViewPort(QEvent *theEvent); + void vpMousePressEvent(QMouseEvent* theEvent); + void vpMouseReleaseEvent(QMouseEvent* theEvent); + void vpMouseMoveEvent(QMouseEvent* theEvent); - void vpMousePressEvent(QMouseEvent* theEvent); - void vpMouseReleaseEvent(QMouseEvent* theEvent); - void vpMouseMoveEvent(QMouseEvent* theEvent); + OperationType getButtonState(QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle); - OperationType getButtonState(QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle); - - void resetState(); - void drawRect(); - void endDrawRect(); + void resetState(); + void drawRect(); + void endDrawRect(); - bool transformRequested() const; - bool setTransformRequested ( OperationType ); + bool transformRequested() const; + bool setTransformRequested(OperationType); - // Transformation is selected and already started - bool transformInProcess() const { return myEventStarted; } - void setTransformInProcess( bool bOn ) { myEventStarted = bOn; } + // Transformation is selected and already started + bool transformInProcess() const + { + return myEventStarted; + } + void setTransformInProcess(bool bOn) + { + myEventStarted = bOn; + } private: - XGUI_Viewer* myViewer; - - QLabel* myPicture; - ViewerLabel* myGripWgt; - XGUI_ViewPort* myViewPort; - ViewerToolbar* myViewBar; - ViewerToolbar* myWindowBar; - QAction* myMinimizeBtn; - QAction* myMaximizeBtn; - - QIcon MinimizeIco; - QIcon MaximizeIco; - QIcon CloseIco; - QIcon RestoreIco; - - bool myMoving; - QPoint myMousePnt; - - WindowState myLastState; - - int myStartX; - int myStartY; - int myCurrX; - int myCurrY; - - XGUI::InteractionStyle myInteractionStyle; - OperationType myOperation; - XGUI::Mode2dType my2dMode; - - int myCurSketch; - bool myDrawRect; // set when a rect is used for selection or magnify - bool myEnableDrawMode; - bool myRotationPointSelection; - bool myCursorIsHand; - bool myIsKeyFree; - bool myEventStarted; // set when transformation is in process + XGUI_Viewer* myViewer; + + QLabel* myPicture; + ViewerLabel* myGripWgt; + XGUI_ViewPort* myViewPort; + ViewerToolbar* myViewBar; + ViewerToolbar* myWindowBar; + QAction* myMinimizeBtn; + QAction* myMaximizeBtn; + + QIcon MinimizeIco; + QIcon MaximizeIco; + QIcon CloseIco; + QIcon RestoreIco; + + bool myMoving; + QPoint myMousePnt; + + WindowState myLastState; + + int myStartX; + int myStartY; + int myCurrX; + int myCurrY; + + XGUI::InteractionStyle myInteractionStyle; + OperationType myOperation; + XGUI::Mode2dType my2dMode; + + int myCurSketch; + bool myDrawRect; // set when a rect is used for selection or magnify + bool myEnableDrawMode; + bool myRotationPointSelection; + bool myCursorIsHand; + bool myIsKeyFree; + bool myEventStarted; // set when transformation is in process + bool myClosable; - QCursor myCursor; - - XGUI::RotationPointType myCurrPointType; - XGUI::RotationPointType myPrevPointType; + QCursor myCursor; - gp_Pnt mySelectedPoint; + XGUI::RotationPointType myCurrPointType; + XGUI::RotationPointType myPrevPointType; - XGUI_RectRubberBand* myRectBand; //!< selection rectangle rubber band + gp_Pnt mySelectedPoint; - typedef QMap MapOfTransformStatus; - MapOfTransformStatus myStatus; + XGUI_RectRubberBand* myRectBand; //!< selection rectangle rubber band - double myCurScale; - }; + typedef QMap MapOfTransformStatus; + MapOfTransformStatus myStatus; + double myCurScale; + }; //****************************************************** - class ViewerToolbar : public QToolBar + class ViewerToolbar: public QToolBar { - Q_OBJECT + Q_OBJECT public: - ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort) : - QToolBar(theParent), myVPort(thePort) {} + ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort) + : QToolBar(theParent), myVPort(thePort) + { + } protected: - virtual void paintEvent( QPaintEvent* theEvent); + virtual void paintEvent(QPaintEvent* theEvent); private: - XGUI_ViewPort* myVPort; + XGUI_ViewPort* myVPort; }; //****************************************************** diff --cc src/XGUI/XGUI_Viewer.cpp index c8cd002b9,8053c9712..147c7937e --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@@ -80,113 -74,100 +74,109 @@@ QString XGUI_Viewer::backgroundData(QSt return tr("BG_IMAGE_FILES"); } - - - XGUI_Viewer::XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron) : - QObject(theParent), - myMainWindow(theParent), - myPreselectionEnabled(true), - mySelectionEnabled(true), - myMultiSelectionEnabled(true), - myIsRelative(true), - myInteractionStyle(XGUI::STANDARD), + XGUI_Viewer::XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron) - : QObject(theParent), myMainWindow(theParent), myPreselectionEnabled(true), mySelectionEnabled( - true), myMultiSelectionEnabled(true), myIsRelative(true), myInteractionStyle( - XGUI::STANDARD), myTrihedronSize(100) ++ : QObject(theParent), ++ myMainWindow(theParent), ++ myPreselectionEnabled(true), ++ mySelectionEnabled(true), ++ myMultiSelectionEnabled(true), ++ myIsRelative(true), ++ myInteractionStyle(XGUI::STANDARD), + myTrihedronSize(100), + myActiveView(0) { - if ( !isInitialized ) { - isInitialized = true; + if (!isInitialized) { + isInitialized = true; - // standard interaction style - XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::ZOOM] = Qt::ControlModifier; - XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::ZOOM] = Qt::LeftButton; + // standard interaction style + XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::ZOOM] = Qt::ControlModifier; + XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::ZOOM] = Qt::LeftButton; - XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::PAN] = Qt::ControlModifier; - XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::PAN] = Qt::MidButton; + XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::PAN] = Qt::ControlModifier; + XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::PAN] = Qt::MidButton; - XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::ROTATE] = Qt::ControlModifier; - XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::ROTATE] = Qt::RightButton; + XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::ROTATE] = Qt::ControlModifier; + XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::ROTATE] = Qt::RightButton; - XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::FIT_AREA] = Qt::ControlModifier; - XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::FIT_AREA] = Qt::RightButton; + XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::FIT_AREA] = Qt::ControlModifier; + XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::FIT_AREA] = Qt::RightButton; - // "key free" interaction style - XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::ZOOM] = Qt::NoModifier; - XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::ZOOM] = Qt::RightButton; + // "key free" interaction style + XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::ZOOM] = Qt::NoModifier; + XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::ZOOM] = Qt::RightButton; - XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::PAN] = Qt::NoModifier; - XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::PAN] = Qt::MidButton; + XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::PAN] = Qt::NoModifier; + XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::PAN] = Qt::MidButton; - XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::ROTATE] = Qt::NoModifier; - XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::ROTATE] = Qt::LeftButton; + XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::ROTATE] = Qt::NoModifier; + XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::ROTATE] = Qt::LeftButton; - XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::FIT_AREA] = Qt::NoModifier; // unused - XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::FIT_AREA] = Qt::NoButton; // unused - } + XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::FIT_AREA] = Qt::NoModifier; // unused + XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::FIT_AREA] = Qt::NoButton; // unused + } - // init CasCade viewers - myV3dViewer = CreateViewer(TCollection_ExtendedString("Viewer3d").ToExtString(), - "", "", 1000.0, V3d_XposYnegZpos, Standard_True, Standard_True ); - myV3dViewer->SetDefaultLights(); - - // init selector - myAISContext = new AIS_InteractiveContext( myV3dViewer ); - myAISContext->SelectionColor( Quantity_NOC_WHITE ); - - // display isoline on planar faces (box for ex.) - myAISContext->IsoOnPlane( true ); - - if ( DisplayTrihedron ) { - Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY()); - myTrihedron = new AIS_Trihedron(anAxis); - myTrihedron->SetInfiniteState( Standard_True ); - - Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB); - myTrihedron->SetArrowColor( Col.Name() ); - myTrihedron->SetSize(myTrihedronSize); - Handle(AIS_Drawer) drawer = myTrihedron->Attributes(); - if (drawer->HasDatumAspect()) { - Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect(); - daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB)); - daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB)); - daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB)); - } + // init CasCade viewers + myV3dViewer = CreateViewer(TCollection_ExtendedString("Viewer3d").ToExtString(), "", "", 1000.0, + V3d_XposYnegZpos, Standard_True, Standard_True); + myV3dViewer->SetDefaultLights(); + + // init selector + myAISContext = new AIS_InteractiveContext(myV3dViewer); + myAISContext->SelectionColor(Quantity_NOC_WHITE); + + // display isoline on planar faces (box for ex.) + myAISContext->IsoOnPlane(true); + + if (DisplayTrihedron) { + Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY()); + myTrihedron = new AIS_Trihedron(anAxis); + myTrihedron->SetInfiniteState( Standard_True); + + Quantity_Color Col(193 / 255., 205 / 255., 193 / 255., Quantity_TOC_RGB); + myTrihedron->SetArrowColor(Col.Name()); + myTrihedron->SetSize(myTrihedronSize); + Handle(AIS_Drawer) drawer = myTrihedron->Attributes(); + if (drawer->HasDatumAspect()) { + Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect(); + daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB)); + daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB)); + daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB)); } - // set zooming style to standard - //myZoomingStyle = 0; + } + // set zooming style to standard + //myZoomingStyle = 0; } - XGUI_Viewer::~XGUI_Viewer(void) { - myAISContext.Nullify(); - myV3dViewer.Nullify(); + myAISContext.Nullify(); + myV3dViewer.Nullify(); } - QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType) { - // create view frame - XGUI_ViewWindow* view = new XGUI_ViewWindow(this, theType); - // get main view window (created by view frame) - //OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW); - // initialize main view window - //initView( vw ); - // 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 + // create view frame + XGUI_ViewWindow* view = new XGUI_ViewWindow(this, theType); + // get main view window (created by view frame) + //OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW); + // initialize main view window + //initView( vw ); + // 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)); + view->setBackground(XGUI_ViewBackground(XGUI::VerticalGradient, Qt::green, Qt::blue)); - QMdiArea* aMDI = myMainWindow->mdiArea(); - QMdiSubWindow* aWnd = aMDI->addSubWindow(view, Qt::FramelessWindowHint); + 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; + aWnd->setGeometry(0, 0, aMDI->width() / 2, aMDI->height() / 2); + aWnd->show(); + return aWnd; } /*! Sets hot button @@@ -332,91 -318,23 +327,89 @@@ bool XGUI_Viewer::computeTrihedronSize( theSize = trihedron()->Size(); //theNewSize = aMaxSide*aSizeInPercents / 100.0; - return fabs( theNewSize - theSize ) > theSize * EPS || - fabs( theNewSize - theSize) > theNewSize * EPS; + return fabs(theNewSize - theSize) > theSize * EPS || fabs(theNewSize - theSize) > theNewSize * EPS; } - -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(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(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 ); + setTrihedronShown(true); +}*/ + + +void XGUI_Viewer::addView(QMdiSubWindow* theView) +{ + XGUI_ViewWindow* aWindow = dynamic_cast(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; +} diff --cc src/XGUI/XGUI_Viewer.h index 92bc53192,a5b43311f..654221a59 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@@ -14,97 -12,81 +13,108 @@@ class XGUI_MainWindow; class QMdiSubWindow; +class XGUI_ViewWindow; +class QMouseEvent; +class QKeyEvent; - class XGUI_Viewer : public QObject + class XGUI_Viewer: public QObject { - Q_OBJECT + Q_OBJECT public: - static QString backgroundData( QStringList&, QIntList&, QIntList& ); - - XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron = true); - ~XGUI_Viewer(); - - QMdiSubWindow* createView(V3d_TypeOfView theType = V3d_ORTHOGRAPHIC); - - XGUI_MainWindow* mainWindow() const { return myMainWindow; } - - Handle(V3d_Viewer) v3dViewer() const { return myV3dViewer; } - - Handle(AIS_InteractiveContext) AISContext() const { return myAISContext; } - - Handle(AIS_Trihedron) trihedron() const { return myTrihedron; } - - void toggleTrihedron(); - bool isTrihedronVisible() const; - void setTrihedronShown( const bool on ); - double trihedronSize() const; - void setTrihedronSize( const double sz, bool isRelative ); - bool trihedronRelative() const { return myIsRelative; } - void updateTrihedron(); - bool computeTrihedronSize( double& theNewSize, double& theSize ); - - - - static void setHotButton( XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper, - Qt::KeyboardModifiers theState, Qt::MouseButtons theButton ); - static void getHotButton( XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper, - Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton ); - - typedef QMap StatesMap; - typedef QMap ButtonsMap; - - typedef QMap InteractionStyle2StatesMap; - typedef QMap InteractionStyle2ButtonsMap; - - static InteractionStyle2StatesMap myStateMap; - static InteractionStyle2ButtonsMap myButtonMap; + static QString backgroundData(QStringList&, QIntList&, QIntList&); + + XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron = true); + ~XGUI_Viewer(); + + QMdiSubWindow* createView(V3d_TypeOfView theType = V3d_ORTHOGRAPHIC); + + XGUI_MainWindow* mainWindow() const + { + return myMainWindow; + } + + Handle(V3d_Viewer) v3dViewer() const + { + return myV3dViewer; + } + + Handle(AIS_InteractiveContext) AISContext() const + { + return myAISContext; + } + + Handle(AIS_Trihedron) trihedron() const + { + return myTrihedron; + } + + void toggleTrihedron(); + bool isTrihedronVisible() const; + void setTrihedronShown(const bool on); + double trihedronSize() const; + void setTrihedronSize(const double sz, bool isRelative); + bool trihedronRelative() const + { + return myIsRelative; + } + void updateTrihedron(); + bool computeTrihedronSize(double& theNewSize, double& theSize); + + static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper, + Qt::KeyboardModifiers theState, Qt::MouseButtons theButton); + static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper, + Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton); + + typedef QMap StatesMap; + typedef QMap ButtonsMap; + + typedef QMap InteractionStyle2StatesMap; + typedef QMap InteractionStyle2ButtonsMap; + + 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; + XGUI_MainWindow* myMainWindow; - Handle(V3d_Viewer) myV3dViewer; - Handle(AIS_Trihedron) myTrihedron; - Handle(AIS_InteractiveContext) myAISContext; - - XGUI::InteractionStyle myInteractionStyle; - - bool myPreselectionEnabled; - bool mySelectionEnabled; - bool myMultiSelectionEnabled; - bool myIsRelative; + Handle(V3d_Viewer) myV3dViewer;Handle(AIS_Trihedron) myTrihedron;Handle(AIS_InteractiveContext) myAISContext; + + XGUI::InteractionStyle myInteractionStyle; + + bool myPreselectionEnabled; + bool mySelectionEnabled; + bool myMultiSelectionEnabled; + bool myIsRelative; - double myTrihedronSize; + double myTrihedronSize; + + QList myViews; + + QMdiSubWindow* myActiveView; }; - #endif + #endif