+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// 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/
+//
// OCCViewer_ViewWindow.cxx: implementation of the OCCViewer_ViewWindow class.
//
//////////////////////////////////////////////////////////////////////
#include "OCCViewer_ViewModel.h"
#include "OCCViewer_ViewPort3d.h"
#include "OCCViewer_CreateRestoreViewDlg.h"
+#include "OCCViewer_ClippingDlg.h"
#include "SUIT_Desktop.h"
#include "SUIT_Session.h"
#include <qpainter.h>
#include <qapplication.h>
#include <qdatetime.h>
+#include <qimage.h>
+
+#include <V3d_Plane.hxx>
+#include <gp_Dir.hxx>
+#include <gp_Pln.hxx>
const char* imageZoomCursor[] = {
"32 32 3 1",
"................................",
"................................",
"................................"};
-
-
-QPixmap zoomPixmap(imageZoomCursor);
-QPixmap rotatePixmap(imageRotateCursor);
-QPixmap globalPanPixmap(imageCrossCursor);
-
-QCursor defCursor(Qt::ArrowCursor);
-QCursor handCursor(Qt::PointingHandCursor);
-QCursor panCursor(Qt::SizeAllCursor);
-QCursor zoomCursor(zoomPixmap);
-QCursor rotCursor(rotatePixmap);
-QCursor glPanCursor(globalPanPixmap);
-
//////////////////////////////////////////////////////////////////////
: SUIT_ViewWindow(theDesktop)
{
myModel = theModel;
- myEnableDrawMode = true;
myRestoreFlag = 0;
+ myEnableDrawMode = false;
+ updateEnabledDrawMode();
+ myClippingDlg = 0;
}
//****************************************************************
return SUIT_ViewWindow::eventFilter(watched, e);
}
+void OCCViewer_ViewWindow::updateEnabledDrawMode()
+{
+ if ( myModel )
+ myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
+}
//****************************************************************
void OCCViewer_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
myCursor = cursor(); /* save old cursor */
if ( myOperation != ZOOMVIEW ) {
+ QPixmap zoomPixmap (imageZoomCursor);
+ QCursor zoomCursor (zoomPixmap);
setTransformRequested ( ZOOMVIEW );
setCursor( zoomCursor );
}
myCursor = cursor(); // save old cursor
if ( myOperation != PANVIEW ) {
+ QCursor panCursor (Qt::SizeAllCursor);
setTransformRequested ( PANVIEW );
setCursor( panCursor );
}
myCursor = cursor(); // save old cursor
if ( myOperation != ROTATE ) {
+ QPixmap rotatePixmap (imageRotateCursor);
+ QCursor rotCursor (rotatePixmap);
setTransformRequested ( ROTATE );
setCursor( rotCursor );
}
{
Handle(V3d_View) aView3d = myViewPort->getView();
if ( !aView3d.IsNull() ) {
+ QPixmap globalPanPixmap (imageCrossCursor);
+ QCursor glPanCursor (globalPanPixmap);
myCurScale = aView3d->Scale();
aView3d->FitAll(0.01, false);
myCursor = cursor(); // save old cursor
myCursor = cursor(); /* save old cursor */
if ( myOperation != WINDOWFIT ) {
+ QCursor handCursor (Qt::PointingHandCursor);
setTransformRequested ( WINDOWFIT );
setCursor ( handCursor );
myCursorIsHand = true;
if ( myDrawRect ) {
drawRect();
if ( !myCursorIsHand ) { // we are going to sketch a rectangle
+ QCursor handCursor (Qt::PointingHandCursor);
myCursorIsHand = true;
myCursor = cursor();
setCursor( handCursor );
theEvent->pos(), theEvent->globalPos(),
theEvent->state() );
emit contextMenuRequested( &aEvent );
- break;
}
}
+ break;
case ROTATE:
myViewPort->endRotation();
resetState();
connect(aAction, SIGNAL(activated()), this, SLOT(onCloneView()));
myActionsMap[ CloneId ] = aAction;
+ aAction = 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;
+
aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
tr( "MNU_SHOOT_VIEW" ), 0, this);
aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
//****************************************************************
void OCCViewer_ViewWindow::createToolBar()
{
- myActionsMap[DumpId]->addTo(myToolBar);
- myActionsMap[TrihedronShowId]->addTo(myToolBar);
+ myActionsMap[DumpId]->addTo(myToolBar);
+ if ( myModel->trihedronActivated() )
+ myActionsMap[TrihedronShowId]->addTo(myToolBar);
SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar, "scale");
aScaleBtn->AddAction(myActionsMap[FitAllId]);
myToolBar->addSeparator();
myActionsMap[CloneId]->addTo(myToolBar);
+
+ myToolBar->addSeparator();
+ myActionsMap[ClippingId]->addTo(myToolBar);
}
//****************************************************************
void OCCViewer_ViewWindow::onResetView()
{
emit vpTransformationStarted( RESETVIEW );
- myViewPort->getView()->Reset();
- myViewPort->fitAll();
+ bool upd = myViewPort->getView()->SetImmediateUpdate( false );
+ myViewPort->getView()->Reset( false );
+ myViewPort->fitAll( false, true, false );
+ myViewPort->getView()->SetImmediateUpdate( upd );
+ myViewPort->getView()->Update();
}
//****************************************************************
//****************************************************************
void OCCViewer_ViewWindow::onCloneView()
{
- myManager->createView();
+ SUIT_ViewWindow* vw = myManager->createViewWindow();
+ vw->show();
}
//****************************************************************
-void OCCViewer_ViewWindow::onMemorizeView()
+void OCCViewer_ViewWindow::onClipping( bool on )
{
- 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;
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+ if ( on )
+ myActionsMap[ ClippingId ]->setIconSet(aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING_PRESSED" )));
+ else
+ myActionsMap[ ClippingId ]->setIconSet(aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING" )));
+
+ if ( on )
+ {
+ if ( !myClippingDlg )
+ myClippingDlg = new OCCViewer_ClippingDlg( this, myDesktop );
- myModel->appendViewAspect( params );
+ if ( !myClippingDlg->isShown() )
+ myClippingDlg->show();
+ }
+ else
+ {
+ if ( myClippingDlg->isShown() )
+ myClippingDlg->hide();
+ setCuttingPlane(false);
+ }
+}
+//****************************************************************
+void OCCViewer_ViewWindow::onMemorizeView()
+{
+ myModel->appendViewAspect( getViewParams() );
}
//****************************************************************
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;
}
QPixmap px = QPixmap::grabWindow( myViewPort->winId() );
return px.convertToImage();
}
+
+void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
+ const double dx, const double dy, const double dz )
+{
+ 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;
+ view->InitActivePlanes();
+ if ( view->MoreActivePlanes() )
+ clipPlane = view->ActivePlane();
+ else
+ clipPlane = new V3d_Plane( viewer );
+
+ // set 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 );
+ clipPlane->SetPlane( a, b, c, d );
+
+ Handle(V3d_View) v = myViewPort->getView();
+ v->SetPlaneOn( clipPlane );
+ v->Update();
+ v->Redraw();
+ }
+ else {
+ Handle(V3d_View) view = myViewPort->getView();
+
+ // 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();
+ }
+
+ Handle(V3d_View) v = myViewPort->getView();
+ v->Update();
+ v->Redraw();
+}
+
+/*! 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 );
+ }
+}