for ( int i = 0, aNb = aNo2dActions.size(); i < aNb; i++ ) {
anAction = aToolMgr->action( aNo2dActions[i] );
if ( anAction )
+ {
anAction->setEnabled( !is2dMode );
+ anAction->setVisible( !is2dMode );
+ }
}
QAction* aTop = aToolMgr->action( OCCViewer_ViewWindow::TopId );
QtxMultiAction* aMulti = dynamic_cast<QtxMultiAction*>( aTop->parent() );
return true;
}
+
+bool OCCViewer_Utilities::computeSceneBBCenter( const Handle(V3d_View) theView,
+ double& theX, double& theY, double& theZ )
+{
+ theX = 0, theY = 0, theZ = 0;
+ Bnd_Box aBox = theView->View()->MinMaxValues();
+ if (!aBox.IsVoid())
+ {
+ double Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
+ aBox.Get (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
+ gp_Pnt aPnts[8] =
+ {
+ gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
+ gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
+ gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
+ gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
+ };
+
+ for (Standard_Integer i = 0; i < 8; i++)
+ {
+ const gp_Pnt& aCornPnt = aPnts[i];
+ theX += aCornPnt.X();
+ theY += aCornPnt.Y();
+ theZ += aCornPnt.Z();
+ }
+
+ theX /= 8;
+ theY /= 8;
+ theZ /= 8;
+ return true;
+ }
+ return false;
+}
#include <Graphic3d_ExportFormat.hxx>
#include <Graphic3d_StereoMode.hxx>
#include <Graphic3d_RenderingParams.hxx>
+#include <Graphic3d_BndBox3d.hxx>
#include <V3d_Plane.hxx>
#include <V3d_Light.hxx>
"................................",
"................................"};
-
-/*!
+
+ /*!
\brief Constructor
\param theDesktop main window of application
\param theModel OCC 3D viewer
mySelectionEnabled = true;
myCursorIsHand = false;
+ myPanningByBtn = false;
+ myAutomaticZoom = true;
clearViewAspects();
}
}
+void OCCViewer_ViewWindow::onPanning()
+{
+ OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
+ bool isChained = aMgr->isChainedOperations();
+ bool isReset = ( myPanningByBtn && isChained );
+ if( isReset )
+ {
+ resetState();
+ }
+ else
+ {
+ myPanningByBtn = true;
+ activatePanning();
+ }
+}
+
/*!
\brief Start panning operation.
if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
continue;
- Bnd_Box aBox = aStructure->MinMaxValues();
- aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
- aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
- aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
- aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
- aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
- aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
+ Bnd_Box aBox1 = aStructure->MinMaxValues();
+ const Graphic3d_BndBox3d& aBox = aStructure->CStructure()->BoundingBox();
+ if (!aBox.IsValid())
+ continue;
+ aXmin = /*aBox.IsVoid() ? RealFirst() :*/ aBox.CornerMin().x();
+ aYmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().y();
+ aZmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().z();
+ aXmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().x();
+ aYmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().y();
+ aZmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().z();
// Infinite structures are skipped
Standard_Real aLIM = ShortRealLast() - 1.0;
theX /= aPointsNb;
theY /= aPointsNb;
theZ /= aPointsNb;
+ return true;
}
- return true;
+ else
+ return false;
}
/*!
case PANVIEW:
case ZOOMVIEW:
- resetState();
- break;
+ {
+ OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
+ bool isChained = aMgr->isChainedOperations();
+ bool isReset = !( myOperation==PANVIEW && myPanningByBtn && isChained ) || theEvent->button() == Qt::RightButton;
+ if( isReset )
+ resetState();
+ break;
+ }
case PANGLOBAL:
if ( theEvent->button() == Qt::LeftButton ) {
setTransformInProcess( false );
setTransformRequested( NOTHING );
+
+ myPanningByBtn = false;
}
aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
tr( "MNU_PAN_VIEW" ), 0, this);
aAction->setStatusTip(tr("DSC_PAN_VIEW"));
- connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
+ connect(aAction, SIGNAL(triggered()), this, SLOT(onPanning()));
toolMgr()->registerAction( aAction, PanId );
// Global Panning
{
emit vpTransformationStarted ( FRONTVIEW );
Handle(V3d_View) aView3d = myViewPort->getView();
- if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
- onViewFitAll();
+ if (myAutomaticZoom)
+ {
+ if ( !aView3d.IsNull() )
+ aView3d->SetProj (V3d_Xpos);
+ onViewFitAll();
+ }
+ else
+ projAndPanToGravity(V3d_Xpos);
emit vpTransformationFinished ( FRONTVIEW );
}
{
emit vpTransformationStarted ( BACKVIEW );
Handle(V3d_View) aView3d = myViewPort->getView();
- if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
- onViewFitAll();
+ if (myAutomaticZoom)
+ {
+ if ( !aView3d.IsNull() )
+ aView3d->SetProj (V3d_Xneg);
+ onViewFitAll();
+ }
+ else
+ projAndPanToGravity(V3d_Xneg);
emit vpTransformationFinished ( BACKVIEW );
}
{
emit vpTransformationStarted ( TOPVIEW );
Handle(V3d_View) aView3d = myViewPort->getView();
- if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
- onViewFitAll();
+ if (myAutomaticZoom)
+ {
+ if ( !aView3d.IsNull() )
+ aView3d->SetProj (V3d_Zpos);
+ onViewFitAll();
+ }
+ else
+ projAndPanToGravity(V3d_Zpos);
emit vpTransformationFinished ( TOPVIEW );
}
{
emit vpTransformationStarted ( BOTTOMVIEW );
Handle(V3d_View) aView3d = myViewPort->getView();
- if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
- onViewFitAll();
+ if (myAutomaticZoom)
+ {
+ if ( !aView3d.IsNull() )
+ aView3d->SetProj (V3d_Zneg);
+ onViewFitAll();
+ }
+ else
+ projAndPanToGravity(V3d_Zneg);
emit vpTransformationFinished ( BOTTOMVIEW );
}
{
emit vpTransformationStarted ( LEFTVIEW );
Handle(V3d_View) aView3d = myViewPort->getView();
- if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
- onViewFitAll();
+ if (myAutomaticZoom)
+ {
+ if ( !aView3d.IsNull() )
+ aView3d->SetProj (V3d_Yneg);
+ onViewFitAll();
+ }
+ else
+ projAndPanToGravity(V3d_Yneg);
emit vpTransformationFinished ( LEFTVIEW );
}
{
emit vpTransformationStarted ( RIGHTVIEW );
Handle(V3d_View) aView3d = myViewPort->getView();
- if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
- onViewFitAll();
+ if (myAutomaticZoom)
+ {
+ if ( !aView3d.IsNull() )
+ aView3d->SetProj (V3d_Ypos);
+ onViewFitAll();
+ }
+ else
+ projAndPanToGravity(V3d_Ypos);
emit vpTransformationFinished ( RIGHTVIEW );
}
return enable;
}
-
bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
{
GLboolean support[1];
aDlg->show();
}
}
+
+bool OCCViewer_ViewWindow::isActionVisible( ActionId theId ) const
+{
+ QAction* a = toolMgr()->action( theId );
+ return a && a->isVisible();
+}
+
+void OCCViewer_ViewWindow::setActionVisible( ActionId theId, bool isVisible )
+{
+ QAction* a = toolMgr()->action( theId );
+ if( a )
+ a->setVisible( isVisible );
+}
+
+void OCCViewer_ViewWindow::projAndPanToGravity(V3d_TypeOfOrientation CamOri)
+{
+ const bool USE_XY = true;
+
+ Handle(V3d_View) aView3d = myViewPort->getView();
+ if (aView3d.IsNull())
+ return;
+
+ bool IsGr = false;
+ double X = 0, Y = 0, Z = 0;
+ if( USE_XY )
+ {
+ const double EPS = 1E-6;
+ int xp = myViewPort->width()/2, yp = myViewPort->height()/2, xp1, yp1;
+ aView3d->Convert( xp, yp, X, Y, Z );
+
+ gp_Dir d = aView3d->Camera()->Direction();
+ if( fabs( d.Z() ) > EPS )
+ {
+ double t = -Z/d.Z();
+ X += t*d.X();
+ Y += t*d.Y();
+ Z += t*d.Z();
+ }
+ }
+
+ // It is really necessary to compute gravity center even if it is not used in part of code below.
+ // Without this calculation the SetProj() method and other methods are not correct.
+ double X2, Y2, Z2;
+ IsGr = computeGravityCenter(X2, Y2, Z2);
+ if ( !IsGr )
+ IsGr = OCCViewer_Utilities::computeSceneBBCenter(aView3d, X2, Y2, Z2);
+
+ aView3d->SetProj(CamOri);
+ if (IsGr)
+ {
+ //aView3d->Update();
+ Handle(Graphic3d_Camera) Cam = aView3d->Camera();
+ gp_XYZ gp(X, Y, Z);
+ gp_Vec dir (Cam->Direction());
+ gp_Pnt eye = Cam->Eye();
+ gp_Vec V1(eye, gp);
+ Standard_Real D = dir.Dot(V1);
+ gp_Pnt ppdir = eye.Translated(D*dir);
+ gp_Vec V2(ppdir, gp);
+ gp_XYZ trEye = eye.XYZ() + V2.XYZ();
+
+ double xat, yat, zat;
+ aView3d->At(xat, yat, zat);
+ gp_Pnt At(xat, yat, zat);
+ gp_XYZ trAt = At.XYZ() + V2.XYZ();
+ aView3d->SetEye(trEye.X(), trEye.Y(), trEye.Z());
+ aView3d->SetAt(trAt.X(), trAt.Y(), trAt.Z());
+ }
+}
+
+
+bool OCCViewer_ViewWindow::isAutomaticZoom() const
+{
+ return myAutomaticZoom;
+}
+
+void OCCViewer_ViewWindow::setAutomaticZoom(const bool isOn)
+{
+ myAutomaticZoom = isOn;
+}
+
Q_OBJECT
public:
- enum { DumpId, FitAllId, FitRectId, FitSelectionId, ZoomId, PanId, GlobalPanId,
+ enum ActionId { DumpId, FitAllId, FitRectId, FitSelectionId, ZoomId, PanId, GlobalPanId,
ChangeRotationPointId, RotationId,
FrontId, BackId, TopId, BottomId, LeftId, RightId, ClockWiseId, AntiClockWiseId,
ResetId, CloneId, ClippingId, MemId, RestoreId,
virtual bool isQuadBufferSupport() const;
virtual void setQuadBufferSupport( const bool );
+ virtual bool isAutomaticZoom() const;
+ virtual void setAutomaticZoom( const bool );
+
void setTransformEnabled( const OperationType, const bool );
bool transformEnabled( const OperationType ) const;
virtual SUIT_CameraProperties cameraProperties();
+ bool isActionVisible( ActionId theId ) const;
+ void setActionVisible( ActionId theId, bool isVisible );
+
+ void resetState();
+
public slots:
virtual void onFrontView();
virtual void onViewFitAll();
virtual void onRayTracing();
virtual void onEnvTexture();
virtual void onLightSource();
+ virtual void onPanning();
virtual void activateSetRotationGravity();
virtual void activateSetRotationSelected( double theX, double theY, double theZ );
void vpMouseReleaseEvent(QMouseEvent* theEvent);
void vpMouseMoveEvent(QMouseEvent* theEvent);
- void resetState();
void drawRect();
void endDrawRect();
bool computeGravityCenter( double& theX, double& theY, double& theZ );
+ void projAndPanToGravity(V3d_TypeOfOrientation CamOri);
+
virtual void onSketchingStarted();
virtual void onSketchingFinished();
bool myPaintersRedrawing; // set to draw with external painters
bool IsSketcherStyle;
bool myIsKeyFree;
-
+ bool myAutomaticZoom;
QCursor myCursor;
double myCurScale;
Handle(V3d_Plane) myReserveClipPlane;
viewAspectList myViewAspects;
+ bool myPanningByBtn;
};
#ifdef WIN32