+{
+ appendViewAspect( getViewParams() );
+}
+
+/*!
+ \brief Restore view parameters.
+*/
+void OCCViewer_ViewWindow::onRestoreView()
+{
+ OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
+ connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
+ aDlg->exec();
+ updateViewAspects( aDlg->parameters() );
+ if( myRestoreFlag && aDlg->parameters().count() )
+ performRestoring( aDlg->currentItem() );
+}
+
+/*!
+ \brief Restore view parameters.
+ \param anItem view parameters
+*/
+void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
+{
+ Handle(V3d_View) aView3d = myViewPort->getView();
+
+ Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
+ aView3d->SetScale( anItem.scale );
+ aView3d->SetCenter( anItem.centerX, anItem.centerY );
+ aView3d->SetTwist( anItem.twist );
+ aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
+ aView3d->SetImmediateUpdate( prev );
+ aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
+ aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
+ aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
+
+ if ( !baseParamsOnly ) {
+
+ myModel->setTrihedronShown( anItem.isVisible );
+ myModel->setTrihedronSize( anItem.size );
+
+#if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
+ // graduated trihedron
+ bool anIsVisible = anItem.gtIsVisible;
+ OCCViewer_AxisWidget::AxisData anAxisData[3];
+ anAxisData[0].DrawName = anItem.gtDrawNameX;
+ anAxisData[1].DrawName = anItem.gtDrawNameZ;
+ anAxisData[2].DrawName = anItem.gtDrawNameZ;
+ anAxisData[0].Name = anItem.gtNameX;
+ anAxisData[1].Name = anItem.gtNameZ;
+ anAxisData[2].Name = anItem.gtNameZ;
+ anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
+ anItem.gtNameColorGX,
+ anItem.gtNameColorBX );
+ anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
+ anItem.gtNameColorGY,
+ anItem.gtNameColorBY );
+ anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
+ anItem.gtNameColorGZ,
+ anItem.gtNameColorBZ );
+ anAxisData[0].DrawValues = anItem.gtDrawValuesX;
+ anAxisData[1].DrawValues = anItem.gtDrawValuesY;
+ anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
+ anAxisData[0].NbValues = anItem.gtNbValuesX;
+ anAxisData[1].NbValues = anItem.gtNbValuesY;
+ anAxisData[2].NbValues = anItem.gtNbValuesZ;
+ anAxisData[0].Offset = anItem.gtOffsetX;
+ anAxisData[1].Offset = anItem.gtOffsetY;
+ anAxisData[2].Offset = anItem.gtOffsetZ;
+ anAxisData[0].Color = QColor( anItem.gtColorRX,
+ anItem.gtColorGX,
+ anItem.gtColorBX );
+ anAxisData[1].Color = QColor( anItem.gtColorRY,
+ anItem.gtColorGY,
+ anItem.gtColorBY );
+ anAxisData[2].Color = QColor( anItem.gtColorRZ,
+ anItem.gtColorGZ,
+ anItem.gtColorBZ );
+ anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
+ anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
+ anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
+ anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
+ anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
+ anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
+
+ myCubeAxesDlg->SetData( anIsVisible, anAxisData );
+ myCubeAxesDlg->ApplyData( aView3d );
+#endif
+
+ } // if ( !baseParamsOnly )
+
+ myRestoreFlag = 0;
+}
+
+/*!
+ \brief Set restore flag.
+*/
+void OCCViewer_ViewWindow::setRestoreFlag()
+{
+ myRestoreFlag = 1;
+}
+
+/*!
+ \brief Called when action "show/hide trihedron" is activated.
+*/
+void OCCViewer_ViewWindow::onTrihedronShow()
+{
+ myModel->toggleTrihedron();
+}
+
+/*!
+ \brief Toggles preselection (highlighting) on/off
+*/
+void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
+{
+ myPreselectionEnabled = on;
+ myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
+
+ // unhighlight all highlighted objects
+ /*if ( !on ) {
+ myModel->unHighlightAll( true, false );
+ }*/
+
+ // update action state if method is called outside
+ QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
+ if ( a && a->isChecked() != on ) {
+ a->setChecked( on );
+ }
+}
+
+/*!
+ \brief Toggles selection on/off
+*/
+void OCCViewer_ViewWindow::onSwitchSelection( bool on )
+{
+ mySelectionEnabled = on;
+ myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
+
+ // update action state if method is called outside
+
+ // preselection
+ QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
+ if ( a ) {
+ a->setEnabled( on );
+ }
+
+ // selection
+ a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
+ if ( a && a->isChecked() != on ) {
+ a->setChecked( on );
+ }
+}
+
+/*!
+ \brief Switches "keyboard free" interaction style on/off
+*/
+void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
+{
+ myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
+
+ // update action state if method is called outside
+ QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
+ if ( a->isChecked() != on )
+ a->setChecked( on );
+}
+
+/*!
+ \brief Toogles advanced zooming style (relatively to the cursor position) on/off
+*/
+void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
+{
+ myViewPort->setAdvancedZoomingEnabled( on );
+
+ // update action state if method is called outside
+ QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
+ if ( a->isChecked() != on )
+ a->setChecked( on );
+}
+
+/*!
+ \brief Get current interaction style
+ \return interaction style
+*/
+int OCCViewer_ViewWindow::interactionStyle() const
+{
+ return myInteractionStyle;
+}
+
+/*!
+ \brief Set current interaction style
+ \param theStyle interaction style
+*/
+void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
+{
+ onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
+}
+
+/*!
+ \brief Get current zooming style
+ \return zooming style
+*/
+int OCCViewer_ViewWindow::zoomingStyle() const
+{
+ return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
+}
+
+/*!
+ \brief Set current zooming style
+ \param theStyle zooming style
+*/
+void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
+{
+ onSwitchZoomingStyle( theStyle == 1 );
+}
+
+/*!
+ \brief Dump view window contents to the pixmap.
+ \return pixmap containing all scene rendered in the window
+*/
+QImage OCCViewer_ViewWindow::dumpView()
+{
+ Handle(V3d_View) view = myViewPort->getView();
+ if ( view.IsNull() )
+ return QImage();
+
+ int aWidth = myViewPort->width();
+ int aHeight = myViewPort->height();
+ QApplication::syncX();
+ view->Redraw(); // In order to reactivate GL context
+ //view->Update();
+
+ OpenGLUtils_FrameBuffer aFrameBuffer;
+ if( aFrameBuffer.init( aWidth, aHeight ) )
+ {
+ QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
+
+ glPushAttrib( GL_VIEWPORT_BIT );
+ glViewport( 0, 0, aWidth, aHeight );
+ aFrameBuffer.bind();
+
+ // draw scene
+ view->Redraw();
+
+ aFrameBuffer.unbind();
+ glPopAttrib();
+
+ aFrameBuffer.bind();
+ glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
+ aFrameBuffer.unbind();
+
+ anImage = anImage.rgbSwapped();
+ anImage = anImage.mirrored();
+ return anImage;
+ }
+ // if frame buffers are unsupported, use old functionality
+ //view->Redraw();
+
+ unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
+
+ QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
+
+ glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
+ data);
+
+ QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
+ anImage = anImage.mirrored();
+ anImage = anImage.rgbSwapped();
+ return anImage;
+}
+
+bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
+ const QString& fileName,
+ const QString& format )
+{
+ if ( format != "PS" && format != "EPS")
+ return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
+
+ Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
+
+ if (format == "PS")
+ a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
+ else if (format == "EPS")
+ a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
+
+ return true;
+}
+
+
+QString OCCViewer_ViewWindow::filter() const
+{
+ return tr( "OCC_IMAGE_FILES" );
+}
+
+
+/*!
+ \brief Set parameters of the cutting plane
+ \param on if \c true, cutting plane is enabled
+ \param x X position of plane point
+ \param y Y position of plane point
+ \param z Z position of plane point
+ \param dx X coordinate of plane normal
+ \param dy Y coordinate of plane normal
+ \param dz Z coordinate of plane normal
+*/
+void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
+ const double dx, const double dy, const double dz )
+{
+ Handle(V3d_View) view = myViewPort->getView();
+ if ( view.IsNull() )
+ return;
+
+ if ( on ) {
+ Handle(V3d_Viewer) viewer = myViewPort->getViewer();
+
+ // try to use already existing plane or create a new one
+ Handle(V3d_Plane) clipPlane;
+
+ // calculate new a,b,c,d values for the plane
+ gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
+ double a, b, c, d;
+ pln.Coefficients(a, b, c, d);
+
+ Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
+ Handle(Graphic3d_ClipPlane) aClipPlane;
+ if(aPlanes.Size() > 0 ) {
+ Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
+ aClipPlane = anIter.Value();
+ aClipPlane->SetEquation(pln);
+ aClipPlane->SetOn(Standard_True);
+ } else {
+ aClipPlane = new Graphic3d_ClipPlane(pln);
+ view->AddClipPlane(aClipPlane);
+ aClipPlane->SetOn(Standard_True);
+ }
+ }
+ else {
+ Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
+ Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
+ for( ;anIter.More();anIter.Next() ){
+ Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
+ aClipPlane->SetOn(Standard_False);
+ }
+ }
+
+ view->Update();
+ view->Redraw();
+}
+
+void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
+{
+ gp_Dir aDir = pln.Axis().Direction();
+ gp_Pnt aPnt = pln.Location();
+ setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
+}
+
+
+/*!
+ \brief Check if any cutting plane is enabled
+ \return \c true if at least one cutting plane is enabled
+*/
+bool OCCViewer_ViewWindow::isCuttingPlane()
+{
+ Handle(V3d_View) view = myViewPort->getView();
+ bool res = false;
+ Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
+ Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
+ for( ;anIter.More();anIter.Next() ) {
+ Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
+ if(aClipPlane->IsOn()) {
+ res = true;
+ break;
+ }
+ }
+ return res;
+}
+
+/*!
+ \brief Get the visual parameters of the view window.
+ \return visual parameters of view window
+*/
+viewAspect OCCViewer_ViewWindow::getViewParams() const