vm->setTrihedronSize( resMgr->doubleValue( "3DViewer", "trihedron_size", vm->trihedronSize() ),
resMgr->booleanValue( "3DViewer", "relative_size", vm->trihedronRelative() ));
vm->setInteractionStyle( resMgr->integerValue( "3DViewer", "navigation_mode", vm->interactionStyle() ) );
+ vm->setProjectionType( resMgr->integerValue( "OCCViewer", "projection_mode", vm->projectionType() ) );
vm->setZoomingStyle( resMgr->integerValue( "3DViewer", "zooming_mode", vm->zoomingStyle() ) );
vm->enablePreselection( resMgr->booleanValue( "OCCViewer", "enable_preselection", vm->isPreselectionEnabled() ) );
vm->enableSelection( resMgr->booleanValue( "OCCViewer", "enable_selection", vm->isSelectionEnabled() ) );
// .. "OCC viewer" group <<start>>
int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), salomeCat );
+ // .... -> projection mode
+ int occProjMode = pref->addPreference( tr( "PREF_PROJECTION_MODE" ), occGroup,
+ LightApp_Preferences::Selector, "OCCViewer", "projection_mode" );
+ aValuesList.clear();
+ anIndicesList.clear();
+ aValuesList << tr("PREF_ORTHOGRAPHIC") << tr("PREF_PERSPECTIVE");
+ anIndicesList << 0 << 1;
+ pref->setItemProperty( "strings", aValuesList, occProjMode );
+ pref->setItemProperty( "indexes", anIndicesList, occProjMode );
// ... "Background" group <<start>>
int bgGroup = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup );
// pref->setItemProperty( "columns", 2, bgGroup );
}
#endif
+#ifndef DISABLE_OCCVIEWER
+ if ( sec == QString( "OCCViewer" ) && param == QString( "projection_mode" ) )
+ {
+ int mode = resMgr->integerValue( "OCCViewer", "projection_mode", 0 );
+ QList<SUIT_ViewManager*> lst;
+ viewManagers( OCCViewer_Viewer::Type(), lst );
+ QListIterator<SUIT_ViewManager*> it( lst );
+ while ( it.hasNext() )
+ {
+ SUIT_ViewModel* vm = it.next()->getViewModel();
+ if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
+ continue;
+
+ OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
+ occVM->setProjectionType( mode );
+ }
+ }
+#endif
+
if ( sec == QString( "3DViewer" ) && param == QString( "zooming_mode" ) )
{
int mode = resMgr->integerValue( "3DViewer", "zooming_mode", 0 );
#include <QKeyEvent>
#include <QMouseEvent>
#include <QApplication>
+#include <QActionGroup>
#include <QMenu>
#include <AIS_ListOfInteractive.hxx>
myScalingDlg = 0;
mySetRotationPointDlg = 0;
myRectBand = 0;
-
+
IsSketcherStyle = false;
myIsKeyFree = false;
myCursorIsHand = false;
clearViewAspects();
-
+
}
/*!
QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
myCubeAxesDlg->initialize();
-
+
connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
}
case QEvent::Wheel:
{
QWheelEvent* aEvent = (QWheelEvent*) e;
-
+
if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
int anInteractionStyle = interactionStyle();
// in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
- // which are assigned for pan and rotate - these operations are activated immediately after pressing
+ // which are assigned for pan and rotate - these operations are activated immediately after pressing
// of the first button, so it is necessary to switch to zoom when the second button is pressed
bool aSwitchToZoom = false;
- if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
+ if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
( myOperation == PANVIEW || myOperation == ROTATE ) ) {
aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
}
{
bool ok = transformEnabled( op );
myOperation = ok ? op : NOTHING;
- myViewPort->setMouseTracking( myOperation == NOTHING );
+ myViewPort->setMouseTracking( myOperation == NOTHING );
return ok;
}
//myRectBand->setPalette(palette);
}
//myRectBand->hide();
-
+
myRectBand->setUpdatesEnabled ( false );
QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
myRectBand->initGeometry( aRect );
{
if( !toolMgr()->isEmpty() )
return;
-
+
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
QtxAction* aAction;
aAction->setStatusTip(tr("DSC_FITRECT"));
connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
toolMgr()->registerAction( aAction, FitRectId );
-
+
// FitSelection
aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
tr( "MNU_FITSELECTION" ), 0, this);
connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
this->addAction(aAction);
toolMgr()->registerAction( aAction, BottomId );
-
+
aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
this->addAction(aAction);
toolMgr()->registerAction( aAction, ClockWiseId );
+ // Projection mode group
+
+ // - orthographic projection
+ aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
+ tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
+ aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
+ aAction->setCheckable(true);
+ //connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onProjectionType()));
+ toolMgr()->registerAction( aAction, OrthographicId );
+
+ // - perspective projection
+ aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
+ tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
+ aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
+ aAction->setCheckable(true);
+ //connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onProjectionType()));
+ toolMgr()->registerAction( aAction, PerspectiveId );
+
+ // - add exclusive action group
+ QActionGroup* aProjectionGroup = new QActionGroup( this );
+ aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
+ aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
+ connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType()));
+
// Reset
aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
toolMgr()->registerAction( aAction, SwitchSelectionId );
- // Graduated axes
+ // Graduated axes
aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
tr( "MNU_GRADUATED_AXES" ), 0, this);
aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
toolMgr()->registerAction( aAction, ReturnTo3dViewId );
}
- // Synchronize View
+ // Synchronize View
toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
}
toolMgr()->append( AntiClockWiseId, tid );
toolMgr()->append( ClockWiseId, tid );
+ toolMgr()->append( OrthographicId, tid );
+ toolMgr()->append( PerspectiveId, tid );
+
toolMgr()->append( ResetId, tid );
}
toolMgr()->append( toolMgr()->separator(), tid );
toolMgr()->append( CloneId, tid );
-
+
toolMgr()->append( toolMgr()->separator(), tid );
toolMgr()->append( ClippingId, tid );
toolMgr()->append( AxialScaleId, tid );
myViewPort->getView()->Reset( false );
myViewPort->fitAll( false, true, false );
myViewPort->getView()->SetImmediateUpdate( upd );
+ onProjectionType(); // needed to apply projection type properly after reset
myViewPort->getView()->Update();
emit vpTransformationFinished( RESETVIEW );
}
+/*!
+ \brief Perform "reset view" transformation.
+
+ Sets default orientation of the viewport camera.
+*/
+void OCCViewer_ViewWindow::onProjectionType()
+{
+ emit vpTransformationStarted( PROJECTION );
+ setProjectionType( toolMgr()->action( OrthographicId )->isChecked() ? Orthographic : Perspective );
+ emit vpTransformationFinished( PROJECTION );
+}
+
/*!
\brief Perform "fit all" transformation.
*/
{
if ( !myScalingDlg )
myScalingDlg = new OCCViewer_AxialScaleDlg( this );
-
+
if ( !myScalingDlg->isVisible() )
{
myScalingDlg->Update();
myModel->setTrihedronShown( anItem.isVisible );
myModel->setTrihedronSize( anItem.size );
-
+
// graduated trihedron
bool anIsVisible = anItem.gtIsVisible;
OCCViewer_AxisWidget::AxisData anAxisData[3];
{
mySelectionEnabled = on;
myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
-
+
// update action state if method is called outside
// preselection
Handle(V3d_View) view = myViewPort->getView();
if ( view.IsNull() )
return QImage();
-
+
int aWidth = myViewPort->width();
int aHeight = myViewPort->height();
// rnv: An old approach to dump the OCCViewer content
// Now used OCCT built-in procedure.
- /*
+ /*
QApplication::syncX();
view->Redraw(); // In order to reactivate GL context
//view->Update();
if( aFrameBuffer.init( aWidth, aHeight ) )
{
QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
-
+
glPushAttrib( GL_VIEWPORT_BIT );
glViewport( 0, 0, aWidth, aHeight );
aFrameBuffer.bind();
glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
data);
*/
-
+
Image_PixMap aPix;
view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
return anImage;
}
-bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
- const QString& fileName,
+bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
+ const QString& fileName,
const QString& format )
{
if ( format != "PS" && format != "EPS")
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();
if(aPlanes.Size() > 0 ) {
Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
}
- performRestoring( params );
+ performRestoring( params );
setBackground( bgData );
myModel->setClipPlanes(aClipPlanes);
}
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->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 );
}
}
else {
- anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
- anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
+ 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 );
}
void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
-{
- IsSketcherStyle = enable;
+{
+ IsSketcherStyle = enable;
}
-bool OCCViewer_ViewWindow::isSketcherStyle() const
-{
- return IsSketcherStyle;
+bool OCCViewer_ViewWindow::isSketcherStyle() const
+{
+ return IsSketcherStyle;
}
my2dMode = theType;
}
-// obsolete
+void OCCViewer_ViewWindow::setProjectionType( int mode )
+{
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
+ aCamera->SetProjectionType( mode == Perspective ? Graphic3d_Camera::Projection_Perspective : Graphic3d_Camera::Projection_Orthographic );
+ onViewFitAll();
+ }
+ // update action state if method is called outside
+ QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( mode == Orthographic ? OrthographicId : PerspectiveId ) );
+ if ( ! a->isChecked() )
+ a->setChecked( true );
+}
+
+int OCCViewer_ViewWindow::projectionType() const
+{
+ int mode = Orthographic;
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if ( !aView3d.IsNull() ) {
+ Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
+ mode = aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective ? Perspective : Orthographic;
+ }
+ return mode;
+}
+
+// obsolete
QColor OCCViewer_ViewWindow::backgroundColor() const
{
return myViewPort ? myViewPort->backgroundColor() : Qt::black;
}
-
+
// obsolete
void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
{
{
return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
}
-
+
void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
{
if ( myViewPort ) myViewPort->setBackground( theBackground );
{
if(!myModel) return;
OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
-
+
if (theIsOn) {
if (!aClippingDlg) {
aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);