#include <QMdiArea>
#include <QMdiSubWindow>
#include <QPainter>
-//#include <QTime>
+#include <QTimer>
#include <QFileDialog>
#include <TopoDS_Shape.hxx>
"................................", "................................" };
//**************************************************************************
-void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
+void ViewerToolbar::repaintBackground()
{
- //QTime aTime;
- //aTime.start();
QRect aRect = rect();
QRect aVPRect = myVPort->rect();
QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
- QRect aImgRect(
- QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height()));
+ QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
+ aRect.width(), aRect.height()));
QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
- //QString aMsg = QString("### Painted in %1").arg(aTime.elapsed());
- //qDebug(qPrintable(aMsg));
+}
+
+void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
+{
+ repaintBackground();
+ QToolBar::paintEvent(theEvent);
}
//**************************************************************************
-void ViewerLabel::paintEvent(QPaintEvent* theEvent)
+void ViewerLabel::repaintBackground()
{
QRect aRect = rect();
QRect aVPRect = myVPort->rect();
QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
- QRect aImgRect(
- QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height()));
+ QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
+ aRect.width(), aRect.height()));
QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
+}
+
+void ViewerLabel::paintEvent(QPaintEvent* theEvent)
+{
+ repaintBackground();
QLabel::paintEvent(theEvent);
}
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);
QAction* 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()));
+ // 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);
+ // Reset
+ aBtn = new QAction(QIcon(":pictures/occ_view_reset.png"), tr("RESET_VIEW"), myViewBar);
+ connect(aBtn, SIGNAL(triggered()), SLOT(reset()));
+ 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);
// Create Window management buttons
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);
myViewBar->hide();
myWindowBar->hide();
myGripWgt->hide();
+
+ //Support copy of background on updating of viewer
+ connect(myViewPort, SIGNAL(vpTransformed()), this, SLOT(updateToolBar()));
+ connect(myViewPort, SIGNAL(vpUpdated()), this, SLOT(updateToolBar()));
+ connect(this, SIGNAL(vpTransformationFinished(XGUI_ViewWindow::OperationType)),
+ this, SLOT(updateToolBar()));
+
}
//****************************************************************
//****************************************************************
void XGUI_ViewWindow::onClose()
{
- if (parentWidget()) {
- emit tryClosing(this);
- if (closable()) {
- emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
- parentWidget()->close();
- }
+ if (parentWidget()) {
+ emit tryClosing(this);
+ if (closable()) {
+ emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
+ parentWidget()->close();
}
+ }
}
//****************************************************************
{
if (!isMinimized()) {
myViewBar->show();
- myWindowBar->show();
+ myWindowBar->show();
if (!isMaximized())
myGripWgt->show();
}
if (processWindowControls(theObj, theEvent))
return true;
} else if (theObj == myViewPort) {
- if (processViewPort(theEvent))
+ if (processViewPort(theEvent)) {
return true;
+ }
}
return QFrame::eventFilter(theObj, theEvent);
}
void XGUI_ViewWindow::cloneView()
{
QMdiSubWindow* vw = myViewer->createView();
- //vw->show();
+ XGUI_ViewWindow* aNewWnd = static_cast<XGUI_ViewWindow*>(vw->widget());
+ aNewWnd->viewPort()->syncronizeWith(myViewPort);
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();
- }
+ 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 );
+ emit vpTransformationStarted( FITALLVIEW );
+ myViewPort->fitAll();
+ emit vpTransformationFinished( FITALLVIEW );
}
/*!
if ( myOperation != WINDOWFIT ) {
QCursor handCursor (Qt::PointingHandCursor);
- if( setTransformRequested ( WINDOWFIT ) )
- {
+ if( setTransformRequested ( WINDOWFIT ) ) {
myViewPort->setCursor ( handCursor );
myCursorIsHand = true;
}
{
emit vpTransformationStarted ( FRONTVIEW );
Handle(V3d_View) aView3d = myViewPort->getView();
- if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
+ if ( !aView3d.IsNull() )
+ aView3d->SetProj (V3d_Xpos);
myViewPort->fitAll();
emit vpTransformationFinished ( FRONTVIEW );
}
{
emit vpTransformationStarted ( BACKVIEW );
Handle(V3d_View) aView3d = myViewPort->getView();
- if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
+ if ( !aView3d.IsNull() )
+ aView3d->SetProj (V3d_Xneg);
myViewPort->fitAll();
emit vpTransformationFinished ( BACKVIEW );
}
{
emit vpTransformationStarted ( TOPVIEW );
Handle(V3d_View) aView3d = myViewPort->getView();
- if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
+ if ( !aView3d.IsNull() )
+ aView3d->SetProj (V3d_Zpos);
myViewPort->fitAll();
emit vpTransformationFinished ( TOPVIEW );
}
{
emit vpTransformationStarted ( BOTTOMVIEW );
Handle(V3d_View) aView3d = myViewPort->getView();
- if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
+ if ( !aView3d.IsNull() )
+ aView3d->SetProj (V3d_Zneg);
myViewPort->fitAll();
emit vpTransformationFinished ( BOTTOMVIEW );
}
{
emit vpTransformationStarted ( LEFTVIEW );
Handle(V3d_View) aView3d = myViewPort->getView();
- if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
+ if ( !aView3d.IsNull() )
+ aView3d->SetProj (V3d_Yneg);
myViewPort->fitAll();
emit vpTransformationFinished ( LEFTVIEW );
}
{
emit vpTransformationStarted ( RIGHTVIEW );
Handle(V3d_View) aView3d = myViewPort->getView();
- if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
+ if ( !aView3d.IsNull() )
+ aView3d->SetProj (V3d_Ypos);
myViewPort->fitAll();
emit vpTransformationFinished ( RIGHTVIEW );
}
+
+void XGUI_ViewWindow::reset()
+{
+ emit vpTransformationStarted( RESETVIEW );
+ bool upd = myViewPort->getView()->SetImmediateUpdate( false );
+ myViewPort->getView()->Reset( false );
+ myViewPort->fitAll( false, true, false );
+ myViewPort->getView()->SetImmediateUpdate( upd );
+ myViewPort->getView()->Update();
+ emit vpTransformationFinished( RESETVIEW );
+}
+
+
+void XGUI_ViewWindow::updateToolBar()
+{
+ myGripWgt->repaint();
+ myViewBar->repaint();
+ myWindowBar->repaint();
+ //QTimer::singleShot(300, this, SLOT(repaintToolBar()));
+}
+
+/*void XGUI_ViewWindow::repaintToolBar()
+{
+ myGripWgt->repaint();
+ myViewBar->repaint();
+ myWindowBar->repaint();
+}*/