theX /= aPointsNb;
theY /= aPointsNb;
theZ /= aPointsNb;
+ return true;
}
- return true;
+ else
+ return false;
}
-bool OCCViewer_ViewWindow::computeGravityCenter1(gp_XYZ& gravityCenter)
-{
- Handle(V3d_View) aView3d = myViewPort->getView();
- Graphic3d_MapOfStructure aSetOfStructures;
- aView3d->View()->DisplayedStructures (aSetOfStructures);
-
- Standard_Boolean hasSelection = Standard_False;
- for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
- aStructIter.More(); aStructIter.Next())
- {
- if (aStructIter.Key()->IsHighlighted()
- && aStructIter.Key()->IsVisible())
- {
- hasSelection = Standard_True;
- break;
- }
- }
-
- Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
- Standard_Integer aNbPoints = 0;
- gravityCenter.SetCoord(0,0,0);
- for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
- aStructIter.More(); aStructIter.Next())
- {
- const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
- if (!aStruct->IsVisible()
- || aStruct->IsInfinite()
- || (hasSelection && !aStruct->IsHighlighted()))
- {
- continue;
- }
-
- const Graphic3d_BndBox3d& aBox = aStruct->CStructure()->BoundingBox();
- if (!aBox.IsValid())
- {
- continue;
- }
-
- // skip transformation-persistent objects
- if (!aStruct->TransformPersistence().IsNull())
- continue;
-
- // use camera projection to find gravity point
- Xmin = aBox.CornerMin().x();
- Ymin = aBox.CornerMin().y();
- Zmin = aBox.CornerMin().z();
- Xmax = aBox.CornerMax().x();
- Ymax = aBox.CornerMax().y();
- Zmax = aBox.CornerMax().z();
- 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 aPntIt = 0; aPntIt < 8; ++aPntIt)
- {
- const gp_Pnt& aBndPnt = aPnts[aPntIt];
- const gp_Pnt aProjected = aView3d->Camera()->Project (aBndPnt);
- if (Abs (aProjected.X()) <= 1.0
- && Abs (aProjected.Y()) <= 1.0)
- {
- gravityCenter += aBndPnt.XYZ();
- ++aNbPoints;
- }
- }
- }
- if (aNbPoints > 0)
- return true;
- else
- return false;
-}
-
/*!
\brief Set the gravity center as a rotation point.
*/
{
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);
++ 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);
++ 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);
++ 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);
++ 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);
++ 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);
++ projAndPanToGravity(V3d_Ypos);
emit vpTransformationFinished ( RIGHTVIEW );
}
aDlg->show();
}
}
-void OCCViewer_ViewWindow::ProjAndPanToGravity(V3d_TypeOfOrientation CamOri)
+
+ 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;
+ }
+