+ if ( !vp->isSketchingEnabled() )
+ return;
+
+ /* Finish current sketching */
+ if ( type == NoSketching )
+ {
+ if ( mypSketcher )
+ {
+ onSketchingFinished();
+ mypSketcher->deactivate();
+ mypSketcher = 0;
+ }
+ }
+ /* Activate new sketching */
+ else
+ {
+ activateSketching( NoSketching ); /* concurrency not suported */
+ mypSketcher = getSketcher( type );
+ if ( mypSketcher )
+ {
+ mypSketcher->activate();
+ onSketchingStarted();
+ }
+ }
+}
+
+/*!
+ Unhilights detected entities. [ virtual protected ]
+*/
+void OCCViewer_ViewWindow::onSketchingStarted()
+{
+}
+
+/*!
+ Selection by rectangle or polygon. [ virtual protected ]
+*/
+void OCCViewer_ViewWindow::onSketchingFinished()
+{
+ MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
+ if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
+ {
+ Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
+ bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
+ switch( mypSketcher->type() )
+ {
+ case Rect:
+ {
+ QRect* aRect = (QRect*)mypSketcher->data();
+ if( aRect )
+ {
+ int aLeft = aRect->left();
+ int aRight = aRect->right();
+ int aTop = aRect->top();
+ int aBottom = aRect->bottom();
+// myRect = aRect;
+
+ if( append )
+ ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
+ else
+ ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
+ }
+ }
+ break;
+ case Polygon:
+ {
+ QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
+ if( aPolygon )
+ {
+ int size = aPolygon->size();
+ TColgp_Array1OfPnt2d anArray( 1, size );
+
+ QPolygon::Iterator it = aPolygon->begin();
+ QPolygon::Iterator itEnd = aPolygon->end();
+ for( int index = 1; it != itEnd; ++it, index++ )
+ {
+ QPoint aPoint = *it;
+ anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
+ }
+
+ if( append )
+ ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
+ else
+ ic->Select( anArray, getViewPort()->getView(), Standard_False );
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
+ aViewMgr->getOCCViewer()->performSelectionChanged();
+ }
+}
+
+OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
+{
+ return myViewPort;
+}
+
+bool OCCViewer_ViewWindow::transformRequested() const
+{
+ return ( myOperation != NOTHING );
+}
+
+bool OCCViewer_ViewWindow::transformInProcess() const
+{
+ return myEventStarted;
+}
+
+void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
+{
+ myEventStarted = bOn;
+}
+
+/*!
+ Set enabled state of transformation (rotate, zoom, etc)
+*/
+void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
+{
+ if ( id != NOTHING ) myStatus.insert( id, on );
+}
+
+/*!
+ \return enabled state of transformation (rotate, zoom, etc)
+*/
+bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
+{
+ return myStatus.contains( id ) ? myStatus[ id ] : true;
+}
+
+void OCCViewer_ViewWindow::onMaximizedView()
+{
+ setMaximized(!isMaximized());
+}
+
+void OCCViewer_ViewWindow::returnTo3dView()
+{
+ setReturnedTo3dView( true );
+}
+
+void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
+{
+ if ( !toolMgr()->action( ReturnTo3dViewId ) ||
+ toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
+ if ( !isVisible3dView )
+ toolMgr()->show( ReturnTo3dViewId );
+ else
+ toolMgr()->hide( ReturnTo3dViewId );
+ if ( isVisible3dView ) emit returnedTo3d( );
+}
+
+
+void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
+{
+ QAction* anAction = toolMgr()->action( MaximizedId );
+ QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+ if ( toMaximize ) {
+ anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
+ anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
+ anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
+ anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
+ if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
+ if (toSendSignal) {
+ emit maximized( this, true );
+ }
+ }
+ else {
+ anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
+ anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
+ anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
+ anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
+ if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
+ if (toSendSignal) {
+ emit maximized( this, false );
+ }
+ }
+}
+
+bool OCCViewer_ViewWindow::isMaximized() const
+{
+ return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
+}
+
+void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
+{
+ IsSketcherStyle = enable;
+}
+
+bool OCCViewer_ViewWindow::isSketcherStyle() const
+{
+ return IsSketcherStyle;
+}
+
+
+void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
+{
+ my2dMode = theType;
+}
+
+void OCCViewer_ViewWindow::setProjectionType( int mode )
+{
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
+ if (mode == Perspective) {
+ myModel->setProjectionType(Perspective);
+ aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
+ }
+ if (mode == Orthographic) {
+ myModel->setProjectionType(Orthographic);
+ aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
+ }
+ #if OCC_VERSION_LARGE > 0x06090000
+ if (mode == Stereo) {
+ aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+ setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
+ setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
+ setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
+ setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
+ setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
+ }
+ #endif
+ aView3d->Redraw();
+ onViewFitAll();
+ }
+ // update action state if method is called outside
+ QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
+ QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
+#if OCC_VERSION_LARGE > 0x06090000
+ QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
+#endif
+ if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
+ anOrthographicAction->setChecked( true );
+ #if OCC_VERSION_LARGE > 0x06090000
+ aStereoAction->setChecked( false );
+ #endif
+ }
+ if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
+ aPerspectiveAction->setChecked( true );
+ #if OCC_VERSION_LARGE > 0x06090000
+ aStereoAction->setChecked( false );
+ #endif
+ }
+#if OCC_VERSION_LARGE > 0x06090000
+ if ( mode == Stereo ) {
+ aStereoAction->setChecked( true );
+ if ( anOrthographicAction->isEnabled() ) {
+ anOrthographicAction->setEnabled( false );
+ anOrthographicAction->setChecked( false );
+ aStereoAction->setChecked( false );
+ }
+ else {
+ anOrthographicAction->setEnabled( true );
+ aStereoAction->setChecked( false );
+ anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
+ }
+ if ( aPerspectiveAction->isEnabled() ) {
+ aPerspectiveAction->setEnabled( false );
+ aPerspectiveAction->setChecked( true );
+ #if OCC_VERSION_LARGE > 0x06090000
+ if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer )
+ SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
+ #endif
+ }
+ else {
+ aPerspectiveAction->setEnabled( true );
+ aStereoAction->setChecked( false );
+ aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
+ onProjectionType();
+ }
+ }
+ else {
+ if ( !anOrthographicAction->isEnabled() )
+ anOrthographicAction->setEnabled( true );
+ if ( !aPerspectiveAction->isEnabled() )
+ aPerspectiveAction->setEnabled( true );
+ }
+#endif
+}
+
+int OCCViewer_ViewWindow::projectionType() const
+{
+ int mode = Orthographic;
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
+ if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
+ mode = Perspective;
+ if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
+ mode = Orthographic;
+ #if OCC_VERSION_LARGE > 0x06090000
+ if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
+ mode = Stereo;
+ #endif
+ }
+ return mode;
+}
+
+void OCCViewer_ViewWindow::setStereoType( int type )
+{
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
+ aParams->StereoMode = (Graphic3d_StereoMode)type;
+ #endif
+ }
+}
+
+int OCCViewer_ViewWindow::stereoType() const
+{
+ int type = QuadBuffer;
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
+ type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
+ #endif
+ }
+ return type;
+}
+
+void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
+{
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
+ if (type == RedCyan)
+ aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
+ if (type == YellowBlue)
+ aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
+ if (type == GreenMagenta)
+ aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
+ #endif
+ }
+}
+
+int OCCViewer_ViewWindow::anaglyphFilter() const
+{
+ int type = RedCyan;
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
+ if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
+ type = RedCyan;
+ if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
+ type = YellowBlue;
+ if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
+ type = GreenMagenta;
+ #endif
+ }
+ return type;
+}
+
+void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
+{
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
+ aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
+ #endif
+ }
+}
+
+int OCCViewer_ViewWindow::stereographicFocusType() const
+{
+ int type = Relative;
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
+ type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
+ #endif
+ }
+ return type;
+}
+
+double OCCViewer_ViewWindow::stereographicFocusValue() const
+{
+ double value = 1.0;
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
+ value = aCamera->ZFocus();
+ #endif
+ }
+ return value;
+}
+
+void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
+{
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
+ aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
+ #endif
+ }
+}
+
+int OCCViewer_ViewWindow::interocularDistanceType() const
+{
+ int type = Relative;
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
+ type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
+ #endif
+ }
+ return type;
+}
+
+double OCCViewer_ViewWindow::interocularDistanceValue() const
+{
+ double value = 0.05;
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
+ value = aCamera->IOD();
+ #endif
+ }
+ return value;
+}
+
+void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
+{
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
+ aParams->ToReverseStereo = reverse;
+ #endif
+ }
+}
+
+bool OCCViewer_ViewWindow::isReverseStereo() const
+{
+ int reverse = false;
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
+ reverse = aParams->ToReverseStereo;
+ #endif
+ }
+ return reverse;
+}
+
+void OCCViewer_ViewWindow::setVSync( bool enable )
+{
+ Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
+ if ( !anIntCont.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
+ OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
+ aCaps->swapInterval = enable;
+ #endif
+ }
+}
+
+bool OCCViewer_ViewWindow::isVSync() const
+{
+ int enable = true;
+ Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
+ if ( !anIntCont.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
+ OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
+ enable = aCaps->swapInterval;
+ #endif
+ }
+ return enable;
+}
+
+void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
+{
+ Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
+ if ( !anIntCont.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
+ OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
+ aCaps->contextStereo = enable;
+ #endif
+ }
+}
+
+bool OCCViewer_ViewWindow::isQuadBufferSupport() const
+{
+ int enable = true;
+ Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
+ if ( !anIntCont.IsNull() ) {
+ #if OCC_VERSION_LARGE > 0x06090000
+ Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
+ OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
+ enable = aCaps->contextStereo;
+ #endif
+ }
+ return enable;
+}
+
+
+bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
+{
+ GLboolean support[1];
+ glGetBooleanv (GL_STEREO, support);
+ if ( support[0] )
+ return true;
+ return false;
+}
+
+// obsolete
+QColor OCCViewer_ViewWindow::backgroundColor() const
+{
+ return myViewPort ? myViewPort->backgroundColor() : Qt::black;
+}
+
+// obsolete
+void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
+{
+ if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
+}
+
+Qtx::BackgroundData OCCViewer_ViewWindow::background() const
+{
+ return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
+}
+
+void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
+{
+ if ( myViewPort ) myViewPort->setBackground( theBackground );
+}
+
+void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
+{
+ if ( myViewPort ) myViewPort->showStaticTrihedron( on );
+}
+
+/*!
+ Clears view aspects
+*/
+void OCCViewer_ViewWindow::clearViewAspects()
+{
+ myViewAspects.clear();
+}
+
+/*!
+ \return const reference to list of view aspects
+*/
+const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
+{
+ return myViewAspects;
+}
+
+/*!
+ Appends new view aspect
+ \param aParams - new view aspects
+*/
+void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
+{
+ myViewAspects.append( aParams );
+}
+
+/*!
+ Replaces old view aspects by new ones
+ \param aViewList - list of new view aspects
+*/
+void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
+{
+ myViewAspects = aViewList;
+}
+
+/*!
+ Get camera properties for the OCC view window.
+ \return shared pointer on camera properties.
+*/
+SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
+{
+ SUIT_CameraProperties aProps;
+
+ Handle(V3d_View) aSourceView = getViewPort()->getView();
+ if ( aSourceView.IsNull() )
+ return aProps;
+
+ if ( get2dMode() == No2dMode ) {
+ aProps.setDimension( SUIT_CameraProperties::Dim3D );
+ }
+ else {
+ aProps.setDimension( SUIT_CameraProperties::Dim2D );
+ aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
+ }
+
+ // read common properites of the view
+ Standard_Real anUp[3];
+ Standard_Real anAt[3];
+ Standard_Real anEye[3];
+ Standard_Real aProj[3];
+ Standard_Real anAxialScale[3];
+
+ aSourceView->Up( anUp[0], anUp[1], anUp[2] );
+ aSourceView->At( anAt[0], anAt[1], anAt[2] );
+ aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
+ getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
+
+ aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
+ aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
+
+#if OCC_VERSION_LARGE > 0x06070100
+ aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
+
+ // store camera properties "as is": it is up to synchronized
+ // view classes to provide necessary property conversion.
+ aProps.setPosition( anEye[0], anEye[1], anEye[2] );
+ aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
+
+ if ( aSourceView->Camera()->IsOrthographic() )
+ {
+ aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
+ aProps.setViewAngle( 0.0 );
+ }
+ else
+ {
+ aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
+ aProps.setViewAngle( aSourceView->Camera()->FOVy() );
+ }
+ aProps.setMappingScale( aSourceView->Camera()->Scale() );
+#else
+ Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
+
+ // generate view orientation matrix for transforming OCC projection reference point
+ // into a camera (eye) position.
+ gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
+
+ gp_GTrsf aTrsf;
+ aTrsf.SetValue( 1, 1, aLeftDir.X() );
+ aTrsf.SetValue( 2, 1, aLeftDir.Y() );
+ aTrsf.SetValue( 3, 1, aLeftDir.Z() );
+
+ aTrsf.SetValue( 1, 2, anUp[0] );
+ aTrsf.SetValue( 2, 2, anUp[1] );
+ aTrsf.SetValue( 3, 2, anUp[2] );
+
+ aTrsf.SetValue( 1, 3, aProj[0] );
+ aTrsf.SetValue( 2, 3, aProj[1] );
+ aTrsf.SetValue( 3, 3, aProj[2] );
+
+ aTrsf.SetValue( 1, 4, anAt[0] );
+ aTrsf.SetValue( 2, 4, anAt[1] );
+ aTrsf.SetValue( 3, 4, anAt[2] );
+
+ Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
+
+ // transform to world-space coordinate system
+ gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
+ aTrsf.Transforms( aPosition );
+
+ // compute focal point
+ double aFocalPoint[3];
+
+ aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
+ aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
+ aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
+
+ aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
+ aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
+
+ Standard_Real aViewScale[2];
+ aSourceView->Size( aViewScale[0], aViewScale[1] );
+ aProps.setMappingScale( aViewScale[1] );
+#endif
+
+ return aProps;
+}
+
+/*!
+ Synchronize views.
+ This implementation synchronizes OCC view's camera propreties.
+*/
+void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
+{
+ bool blocked = blockSignals( true );
+
+ SUIT_CameraProperties aProps = theView->cameraProperties();
+ if ( !cameraProperties().isCompatible( aProps ) ) {
+ // other view, this one is being currently synchronized to, seems has become incompatible
+ // we have to break synchronization
+ updateSyncViews();
+ return;
+ }
+
+ Handle(V3d_View) aDestView = getViewPort()->getView();
+
+ aDestView->SetImmediateUpdate( Standard_False );
+
+ double anUpDir[3];
+ double aPosition[3];
+ double aFocalPoint[3];
+ double anAxialScale[3];
+
+ // get common properties
+ aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
+ aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
+ aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
+ aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
+
+#if OCC_VERSION_LARGE > 0x06070100
+ aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
+ aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
+ aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
+ aDestView->Camera()->SetScale( aProps.getMappingScale() );
+#else
+ gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
+ aPosition[1] - aFocalPoint[1],
+ aPosition[2] - aFocalPoint[2] );
+
+ // get custom view translation
+ Standard_Real aTranslation[3];
+ aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
+
+ gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
+ ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
+
+ gp_GTrsf aTrsf;
+ aTrsf.SetValue( 1, 1, aLeftDir.X() );
+ aTrsf.SetValue( 2, 1, aLeftDir.Y() );
+ aTrsf.SetValue( 3, 1, aLeftDir.Z() );
+
+ aTrsf.SetValue( 1, 2, anUpDir[0] );
+ aTrsf.SetValue( 2, 2, anUpDir[1] );
+ aTrsf.SetValue( 3, 2, anUpDir[2] );
+
+ aTrsf.SetValue( 1, 3, aProjDir.X() );
+ aTrsf.SetValue( 2, 3, aProjDir.Y() );
+ aTrsf.SetValue( 3, 3, aProjDir.Z() );
+
+ aTrsf.SetValue( 1, 4, aTranslation[0] );
+ aTrsf.SetValue( 2, 4, aTranslation[1] );
+ aTrsf.SetValue( 3, 4, aTranslation[2] );
+ aTrsf.Invert();
+
+ // transform to view-space coordinate system
+ gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
+ aTrsf.Transforms( aProjRef );
+
+ // set view camera properties using low-level approach. this is done
+ // in order to avoid interference with static variables in v3d view used
+ // when rotation is in process in another view.
+ Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
+ Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
+
+ Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
+ Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
+
+ aMappingProj.Normalize();
+ aMappingUp.Normalize();
+
+ anOrientation.SetViewReferencePlane( aMappingProj );
+ anOrientation.SetViewReferenceUp( aMappingUp );
+
+ aDestView->SetViewMapping( aMapping );
+ aDestView->SetViewOrientation( anOrientation );
+
+ // set panning
+ aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
+
+ // set mapping scale
+ double aMapScaling = aProps.getMappingScale();
+ Standard_Real aWidth, aHeight;
+ aDestView->Size( aWidth, aHeight );
+ aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
+#endif
+
+ getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
+
+ aDestView->ZFitAll();
+ aDestView->SetImmediateUpdate( Standard_True );
+ aDestView->Redraw();
+
+ blockSignals( blocked );
+}
+
+/*!
+ \brief Indicates whether preselection is enabled
+ \return true if preselection is enabled
+*/
+bool OCCViewer_ViewWindow::isPreselectionEnabled() const
+{
+ return myPreselectionEnabled;
+}
+
+/*!
+ \brief Enables/disables preselection
+ \param theIsToEnable if true - preselection will be enabled
+*/
+void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
+{
+ onSwitchPreselection( theIsToEnable );
+}
+
+/*!
+ \brief Indicates whether selection is enabled
+ \return true if selection is enabled
+*/
+bool OCCViewer_ViewWindow::isSelectionEnabled() const
+{
+ return mySelectionEnabled;
+}
+
+/*!
+ \brief Enables/disables selection
+ \param theIsToEnable if true - selection will be enabled
+*/
+void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
+{
+ onSwitchSelection( theIsToEnable );
+}
+
+
+/*!
+ \brief called if clipping operation is activated / deactivated.
+
+ Enables/disables clipping plane displaying.
+
+ \parma on action state
+*/
+void OCCViewer_ViewWindow::onClipping (bool theIsOn)
+{
+ if(!myModel) return;
+ OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
+
+ if (theIsOn) {
+ if (!aClippingDlg) {
+ aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
+ myModel->setClippingDlg(aClippingDlg);
+ }
+ if (!aClippingDlg->isVisible())
+ aClippingDlg->show();
+ } else {
+ if ( aClippingDlg ) {
+ aClippingDlg->close();
+ myModel->setClippingDlg(0);
+ }
+ }
+
+ SUIT_ViewManager* mgr = getViewManager();
+ if( mgr ) {
+ QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
+ for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
+ if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
+ QtxActionToolMgr* mgr = aViewWindow->toolMgr();
+ if(!mgr) continue;
+ QAction* a = toolMgr()->action( ClippingId );
+ if(!a) continue;
+ if(theIsOn != a->isChecked()){
+ disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
+ a->setChecked(theIsOn);
+ connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
+ }
+ }
+ }
+ }