// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// OCCViewer_ViewWindow.cxx: implementation of the OCCViewer_ViewWindow class.
-//
-//////////////////////////////////////////////////////////////////////
+
#include "OCCViewer_ViewWindow.h"
#include "OCCViewer_ViewModel.h"
"................................"};
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
+/*!
+ Constructor
+ \param theDesktop - main window of application
+ \param theModel - OCC 3D viewer
+*/
OCCViewer_ViewWindow::OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel)
: SUIT_ViewWindow(theDesktop)
{
myClippingDlg = 0;
}
-//****************************************************************
+/*!
+ Initialization of view window
+*/
void OCCViewer_ViewWindow::initLayout()
{
myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
createToolBar();
}
-//****************************************************************
+/*!
+ \return type of operation by states of mouse and keyboard buttons
+ \param theEvent - mouse event
+*/
OCCViewer_ViewWindow::OperationType OCCViewer_ViewWindow::getButtonState(QMouseEvent* theEvent)
{
OperationType aOp = NOTHING;
return aOp;
}
-//****************************************************************
+/*!
+ Custom event handler
+*/
bool OCCViewer_ViewWindow::eventFilter(QObject* watched, QEvent* e)
{
if ( watched == myViewPort ) {
return SUIT_ViewWindow::eventFilter(watched, e);
}
+/*!
+ Updates state of enable draw mode state
+*/
void OCCViewer_ViewWindow::updateEnabledDrawMode()
{
if ( myModel )
myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
}
-//****************************************************************
+/*!
+ Handler of mouse press event
+*/
void OCCViewer_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
{
myStartX = theEvent->x();
}
-//****************************************************************
+/*!
+ Starts zoom operation, sets corresponding cursor
+*/
void OCCViewer_ViewWindow::activateZoom()
{
if ( !transformRequested() && !myCursorIsHand )
}
-//****************************************************************
/*!
- Activates 'panning' transformation
+ Starts panning operation, sets corresponding cursor
*/
void OCCViewer_ViewWindow::activatePanning()
{
}
}
-//****************************************************************
/*!
- Activates 'rotation' transformation
+ Starts rotation operation, sets corresponding cursor
*/
void OCCViewer_ViewWindow::activateRotation()
{
}
}
-//****************************************************************
+/*!
+ Starts global panning operation, sets corresponding cursor
+*/
void OCCViewer_ViewWindow::activateGlobalPanning()
{
Handle(V3d_View) aView3d = myViewPort->getView();
}
}
-//****************************************************************
/*!
- Activates 'fit' transformation
+ Starts fit operation, sets corresponding cursor
*/
void OCCViewer_ViewWindow::activateWindowFit()
{
}
}
-//****************************************************************
/*!
- Sets the active operation 'op'
+ Stores which viewer operation is requesting
*/
void OCCViewer_ViewWindow::setTransformRequested ( OperationType op )
{
}
-//****************************************************************/
+/*!
+ Handler of mouse move event
+*/
void OCCViewer_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
{
myCurrX = theEvent->x();
}
}
-//****************************************************************/
+/*!
+ Handler of mouse release event
+*/
void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
{
switch ( myOperation ) {
}
}
-//****************************************************************
/*!
- Sets the viewport to its initial state
- ( no transformations in process etc. )
+ Sets the viewport to its initial state
+ ( no transformations in process etc. )
*/
void OCCViewer_ViewWindow::resetState()
{
}
-//****************************************************************/
+/*!
+ Draws rectangle by starting and current points
+*/
void OCCViewer_ViewWindow::drawRect()
{
QPainter aPainter(myViewPort);
myRect = aRect;
}
-//****************************************************************/
+/*!
+ Creates actions of OCC view window
+*/
void OCCViewer_ViewWindow::createActions()
{
if (!myActionsMap.isEmpty()) return;
connect(aAction, SIGNAL(activated()), this, SLOT(onCloneView()));
myActionsMap[ CloneId ] = aAction;
- aAction = new QtxAction(tr("MNU_CLIPPING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING" ) ),
+ myClippingAction = new QtxAction(tr("MNU_CLIPPING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING" ) ),
tr( "MNU_CLIPPING" ), 0, this);
- aAction->setStatusTip(tr("DSC_CLIPPING"));
- aAction->setToggleAction( true );
- connect(aAction, SIGNAL(toggled( bool )), this, SLOT(onClipping( bool )));
- myActionsMap[ ClippingId ] = aAction;
+ myClippingAction->setStatusTip(tr("DSC_CLIPPING"));
+ myClippingAction->setToggleAction( true );
+ connect(myClippingAction, SIGNAL(toggled( bool )), this, SLOT(onClipping( bool )));
+ myActionsMap[ ClippingId ] = myClippingAction;
aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
tr( "MNU_SHOOT_VIEW" ), 0, this);
}
}
-//****************************************************************
+/*!
+ Creates toolbar of OCC view window
+*/
void OCCViewer_ViewWindow::createToolBar()
{
myActionsMap[DumpId]->addTo(myToolBar);
myActionsMap[ClippingId]->addTo(myToolBar);
}
-//****************************************************************
+/*!
+ Processes operation fit all
+*/
void OCCViewer_ViewWindow::onViewFitAll()
{
myViewPort->fitAll();
}
-//****************************************************************
+/*!
+ Processes transformation "front view"
+*/
void OCCViewer_ViewWindow::onFrontView()
{
emit vpTransformationStarted ( FRONTVIEW );
onViewFitAll();
}
-//****************************************************************
+/*!
+ Processes transformation "back view"
+*/
void OCCViewer_ViewWindow::onBackView()
{
emit vpTransformationStarted ( BACKVIEW );
onViewFitAll();
}
-//****************************************************************
+/*!
+ Processes transformation "top view"
+*/
void OCCViewer_ViewWindow::onTopView()
{
emit vpTransformationStarted ( TOPVIEW );
onViewFitAll();
}
-//****************************************************************
+/*!
+ Processes transformation "bottom view"
+*/
void OCCViewer_ViewWindow::onBottomView()
{
emit vpTransformationStarted ( BOTTOMVIEW );
onViewFitAll();
}
-//****************************************************************
+/*!
+ Processes transformation "left view"
+*/
void OCCViewer_ViewWindow::onLeftView()
{
emit vpTransformationStarted ( LEFTVIEW );
onViewFitAll();
}
-//****************************************************************
+/*!
+ Processes transformation "right view"
+*/
void OCCViewer_ViewWindow::onRightView()
{
emit vpTransformationStarted ( RIGHTVIEW );
onViewFitAll();
}
-//****************************************************************
+/*!
+ Processes transformation "reset view": sets default orientation of viewport camera
+*/
void OCCViewer_ViewWindow::onResetView()
{
emit vpTransformationStarted( RESETVIEW );
myViewPort->getView()->Update();
}
-//****************************************************************
+/*!
+ Processes transformation "fit all"
+*/
void OCCViewer_ViewWindow::onFitAll()
{
emit vpTransformationStarted( FITALLVIEW );
myViewPort->fitAll();
}
-//****************************************************************
+/*!
+ Creates one more window with same content
+*/
void OCCViewer_ViewWindow::onCloneView()
{
SUIT_ViewWindow* vw = myManager->createViewWindow();
vw->show();
}
-//****************************************************************
+/*!
+ SLOT: called if clipping operation is activated, enables/disables of clipping plane
+*/
void OCCViewer_ViewWindow::onClipping( bool on )
{
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
if ( on )
{
if ( !myClippingDlg )
- myClippingDlg = new OCCViewer_ClippingDlg( this, myDesktop );
+ {
+ myClippingDlg = new OCCViewer_ClippingDlg( this, myDesktop );
+ myClippingDlg->SetAction( myClippingAction );
+ }
if ( !myClippingDlg->isShown() )
myClippingDlg->show();
}
}
-//****************************************************************
+/*!
+ Stores view parameters
+*/
void OCCViewer_ViewWindow::onMemorizeView()
{
- double centerX, centerY, projX, projY, projZ, twist;
- double atX, atY, atZ, eyeX, eyeY, eyeZ;
-
- Handle(V3d_View) aView3d = myViewPort->getView();
-
- aView3d->Center( centerX, centerY );
- aView3d->Proj( projX, projY, projZ );
- aView3d->At( atX, atY, atZ );
- aView3d->Eye( eyeX, eyeY, eyeZ );
- twist = aView3d->Twist();
-
- viewAspect params;
- QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
-
- params.scale = aView3d->Scale();
- params.centerX = centerX;
- params.centerY = centerY;
- params.projX = projX;
- params.projY = projY;
- params.projZ = projZ;
- params.twist = twist;
- params.atX = atX;
- params.atY = atY;
- params.atZ = atZ;
- params.eyeX = eyeX;
- params.eyeY = eyeY;
- params.eyeZ = eyeZ;
- params.name = aName;
-
- myModel->appendViewAspect( params );
-
+ myModel->appendViewAspect( getViewParams() );
}
-//****************************************************************
+/*!
+ Restores view parameters
+*/
void OCCViewer_ViewWindow::onRestoreView()
{
OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), myModel );
performRestoring( aDlg->currentItem() );
}
-//****************************************************************
-
+/*!
+ Restores view parameters from structure viewAspect
+*/
void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem )
{
Handle(V3d_View) aView3d = myViewPort->getView();
Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
aView3d->SetScale( anItem.scale );
aView3d->SetCenter( anItem.centerX, anItem.centerY );
- aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
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 );
myRestoreFlag = 0;
}
+/*!
+ Sets restore flag
+*/
void OCCViewer_ViewWindow::setRestoreFlag()
{
myRestoreFlag = 1;
}
-//****************************************************************
+/*!
+ SLOT: called when action "show/hide" trihedron is activated
+*/
void OCCViewer_ViewWindow::onTrihedronShow()
{
myModel->toggleTrihedron();
}
-//****************************************************************
+/*!
+ \return QImage, containing all scene rendering in window
+*/
QImage OCCViewer_ViewWindow::dumpView()
{
QPixmap px = QPixmap::grabWindow( myViewPort->winId() );
return px.convertToImage();
}
-
+
+/*!
+ Sets parameters of cutting plane
+ \param on - is cutting plane 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();
- Handle(V3d_View) view = myViewPort->getView();
// try to use already existing plane or create a new one
Handle(V3d_Plane) clipPlane;
pln.Coefficients( a, b, c, d );
clipPlane->SetPlane( a, b, c, d );
- Handle(V3d_View) v = myViewPort->getView();
- v->SetPlaneOn( clipPlane );
- v->Update();
- v->Redraw();
+ view->SetPlaneOn( clipPlane );
}
- else {
- Handle(V3d_View) view = myViewPort->getView();
+ else
+ view->SetPlaneOff();
+
+ view->Update();
+ view->Redraw();
+}
- // try to use already existing plane
- Handle(V3d_Plane) clipPlane;
- view->InitActivePlanes();
- if ( view->MoreActivePlanes() )
- clipPlane = view->ActivePlane();
-
- Handle(V3d_View) v = myViewPort->getView();
- if ( !clipPlane.IsNull() )
- v->SetPlaneOff( clipPlane );
- else
- v->SetPlaneOff();
-
- v->Update();
- v->Redraw();
+/*!
+ \return true if there is at least one cutting plane
+*/
+bool OCCViewer_ViewWindow::isCuttingPlane()
+{
+ Handle(V3d_View) view = myViewPort->getView();
+ view->InitActivePlanes();
+ return (view->MoreActivePlanes());
+}
+
+/*!
+ The method returns the visual parameters of this view as a viewAspect object
+*/
+viewAspect OCCViewer_ViewWindow::getViewParams() const
+{
+ double centerX, centerY, projX, projY, projZ, twist;
+ double atX, atY, atZ, eyeX, eyeY, eyeZ;
+
+ Handle(V3d_View) aView3d = myViewPort->getView();
+
+ aView3d->Center( centerX, centerY );
+ aView3d->Proj( projX, projY, projZ );
+ aView3d->At( atX, atY, atZ );
+ aView3d->Eye( eyeX, eyeY, eyeZ );
+ twist = aView3d->Twist();
+
+ QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
+
+ viewAspect params;
+ params.scale = aView3d->Scale();
+ params.centerX = centerX;
+ params.centerY = centerY;
+ params.projX = projX;
+ params.projY = projY;
+ params.projZ = projZ;
+ params.twist = twist;
+ params.atX = atX;
+ params.atY = atY;
+ params.atZ = atZ;
+ params.eyeX = eyeX;
+ params.eyeY = eyeY;
+ params.eyeZ = eyeZ;
+ params.name = aName;
+
+ return params;
+}
+
+
+/*!
+ The method returns the visual parameters of this view as a formated string
+*/
+QString OCCViewer_ViewWindow::getVisualParameters()
+{
+ viewAspect params = getViewParams();
+ QString retStr;
+ retStr.sprintf( "%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e", params.scale,
+ params.centerX, params.centerY, params.projX, params.projY, params.projZ, params.twist,
+ params.atX, params.atY, params.atZ, params.eyeX, params.eyeY, params.eyeZ );
+ return retStr;
+}
+
+/*!
+ The method restors visual parameters of this view from a formated string
+*/
+void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
+{
+ QStringList paramsLst = QStringList::split( '*', parameters, true );
+ if ( paramsLst.size() == 13 ) {
+ viewAspect params;
+ params.scale = paramsLst[0].toDouble();
+ params.centerX = paramsLst[1].toDouble();
+ params.centerY = paramsLst[2].toDouble();
+ params.projX = paramsLst[3].toDouble();
+ params.projY = paramsLst[4].toDouble();
+ params.projZ = paramsLst[5].toDouble();
+ params.twist = paramsLst[6].toDouble();
+ params.atX = paramsLst[7].toDouble();
+ params.atY = paramsLst[8].toDouble();
+ params.atZ = paramsLst[9].toDouble();
+ params.eyeX = paramsLst[10].toDouble();
+ params.eyeY = paramsLst[11].toDouble();
+ params.eyeZ = paramsLst[12].toDouble();
+
+ performRestoring( params );
}
-
- Handle(V3d_View) v = myViewPort->getView();
- v->Update();
- v->Redraw();
}