-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// 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.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include <BRep_Tool.hxx>
#include <BRepBndLib.hxx>
+#include <BRepGProp.hxx>
+#include <GProp_GProps.hxx>
#include <TopoDS.hxx>
#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
#include <gp_Dir.hxx>
#include <gp_Pln.hxx>
+#include <gp_GTrsf.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
-#if OCC_VERSION_LARGE > 0x06060000
#include <Graphic3d_SequenceOfHClipPlane.hxx>
#include <Graphic3d_ClipPlane.hxx>
-#endif
+#include <Image_PixMap.hxx>
#include <Standard_Version.hxx>
case QEvent::Wheel:
{
QWheelEvent* aEvent = (QWheelEvent*) e;
- myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
- double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
- int x = aEvent->x();
- int y = aEvent->y();
- int x1 = (int)( aEvent->x() + width()*delta/100 );
- int y1 = (int)( aEvent->y() + height()*delta/100 );
- myViewPort->zoom( x, y, x1, y1 );
+
+ if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
+ Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
+ if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
+ if ( aEvent->delta() > 0 ) {
+ ic->HilightNextDetected( myViewPort->getView() );
+ } else {
+ ic->HilightPreviousDetected( myViewPort->getView() );
+ }
+ }
+ } else {
+ myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
+ double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
+ int x = aEvent->x();
+ int y = aEvent->y();
+ int x1 = (int)( aEvent->x() + width()*delta/100 );
+ int y1 = (int)( aEvent->y() + height()*delta/100 );
+ myViewPort->zoom( x, y, x1, y1 );
+ myViewPort->getView()->ZFitAll();
+ }
}
return true;
for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
{
TopoDS_Shape aShape = ic->SelectedShape();
+ GProp_GProps aSystem;
+ gp_Pnt aPnt;
if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
{
- gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
- if ( mySetRotationPointDlg )
- {
- myRotationPointSelection = false;
- mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
- }
+ aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
+ }
+ else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
+ {
+ BRepGProp::LinearProperties( aShape, aSystem );
+ aPnt = aSystem.CentreOfMass();
+ }
+ else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
+ {
+ BRepGProp::SurfaceProperties( aShape, aSystem );
+ aPnt = aSystem.CentreOfMass();
+ }
+ else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
+ {
+ BRepGProp::VolumeProperties( aShape, aSystem );
+ aPnt = aSystem.CentreOfMass();
}
else
{
myCurrPointType = myPrevPointType;
break;
}
+
+ if ( mySetRotationPointDlg )
+ {
+ myRotationPointSelection = false;
+ mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
+ }
}
if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
*/
bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
{
- Handle(Visual3d_View) aView = myViewPort->getView()->View();
+ Handle(V3d_View) aView3d = myViewPort->getView();
+
+ // Project boundaries points and add to avergae gravity
+ // the ones which lie within the screen limits
+ Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
+
+#if OCC_VERSION_LARGE > 0x06070100
+ // NDC space screen limits
+ aScreenLimits[0] = -1.0;
+ aScreenLimits[1] = 1.0;
+ aScreenLimits[2] = -1.0;
+ aScreenLimits[3] = 1.0;
+#else
+ aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
+ aScreenLimits[1],
+ aScreenLimits[2],
+ aScreenLimits[3] );
+#endif
- Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
- Standard_Real Umin,Vmin,Umax,Vmax ;
- Standard_Integer Nstruct,Npoint ;
- Graphic3d_MapOfStructure MySetOfStructures;
+ Standard_Integer aPointsNb = 0;
- aView->DisplayedStructures (MySetOfStructures);
- Nstruct = MySetOfStructures.Extent() ;
+ Standard_Real aXmin = 0.0;
+ Standard_Real aYmin = 0.0;
+ Standard_Real aZmin = 0.0;
+ Standard_Real aXmax = 0.0;
+ Standard_Real aYmax = 0.0;
+ Standard_Real aZmax = 0.0;
- Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
- aView->ViewMapping().WindowLimit(Umin,Vmin,Umax,Vmax) ;
- Npoint = 0 ; theX = theY = theZ = 0. ;
- for( ; MyIterator.More(); MyIterator.Next()) {
- if (!(MyIterator.Key())->IsEmpty()) {
- (MyIterator.Key())->MinMaxValues(Xmin,Ymin,Zmin,
- Xmax,Ymax,Zmax) ;
+ Graphic3d_MapOfStructure aSetOfStructures;
+ aView3d->View()->DisplayedStructures( aSetOfStructures );
+ Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
- Standard_Real LIM = ShortRealLast() -1.;
- if (! (fabs(Xmin) > LIM || fabs(Ymin) > LIM || fabs(Zmin) > LIM
- || fabs(Xmax) > LIM || fabs(Ymax) > LIM || fabs(Zmax) > LIM )) {
+ for( ; aStructureIt.More(); aStructureIt.Next() ) {
+ const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
+ if ( aStructure->IsEmpty() ) {
+ continue;
+ }
- aView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
- if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
- Npoint++ ; theX += Xmin ; theY += Ymin ; theZ += Zmin ;
- }
- aView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
- if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
- Npoint++ ; theX += Xmax ; theY += Ymin ; theZ += Zmin ;
- }
- aView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
- if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
- Npoint++ ; theX += Xmin ; theY += Ymax ; theZ += Zmin ;
- }
- aView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
- if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
- Npoint++ ; theX += Xmax ; theY += Ymax ; theZ += Zmin ;
- }
- aView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
- if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
- Npoint++ ; theX += Xmin ; theY += Ymin ; theZ += Zmax ;
- }
- aView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
- if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
- Npoint++ ; theX += Xmax ; theY += Ymin ; theZ += Zmax ;
- }
- aView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
- if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
- Npoint++ ; theX += Xmin ; theY += Ymax ; theZ += Zmax ;
- }
- aView->Projects(Xmax,Ymax,Zmax,U,V,W) ;
- if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
- Npoint++ ; theX += Xmax ; theY += Ymax ; theZ += Zmax ;
- }
+#if OCC_VERSION_LARGE > 0x06070100
+ 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();
+#else
+ aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
+#endif
+
+ // Infinite structures are skipped
+ Standard_Real aLIM = ShortRealLast() - 1.0;
+ if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
+ || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
+ continue;
+ }
+
+ gp_Pnt aPoints[8] = {
+ gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
+ gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
+ gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
+ gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
+ };
+
+ for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
+ const gp_Pnt& aBBPoint = aPoints[aPointIt];
+
+#if OCC_VERSION_LARGE > 0x06070100
+ gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
+ const Standard_Real& U = aProjected.X();
+ const Standard_Real& V = aProjected.Y();
+#else
+ Standard_Real U = 0.0;
+ Standard_Real V = 0.0;
+ Standard_Real W = 0.0;
+ aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
+#endif
+
+ if (U >= aScreenLimits[0]
+ && U <= aScreenLimits[1]
+ && V >= aScreenLimits[2]
+ && V <= aScreenLimits[3])
+ {
+ aPointsNb++;
+ theX += aBBPoint.X();
+ theY += aBBPoint.Y();
+ theZ += aBBPoint.Z();
}
}
}
- if( Npoint > 0 ) {
- theX /= Npoint ; theY /= Npoint ; theZ /= Npoint ;
+
+ if ( aPointsNb > 0 )
+ {
+ theX /= aPointsNb;
+ theY /= aPointsNb;
+ theZ /= aPointsNb;
}
return true;
}
}
/*!
- \brief Start the point selection process.
+ \brief Start the shape selection process.
*/
-void OCCViewer_ViewWindow::activateStartPointSelection()
+void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
{
myPrevPointType = myCurrPointType;
myCurrPointType = SELECTED;
anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
{
ic->Load(anObj,-1);
- ic->Activate(anObj,AIS_Shape::SelectionMode(TopAbs_VERTEX));
+ ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
}
}
// activate selection <------
case PANVIEW:
case ZOOMVIEW:
+ myViewPort->getView()->ZFitAll();
resetState();
break;
connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
toolMgr()->registerAction( aAction, CloneId );
- aAction = new QtxAction (tr ("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr ("ICON_OCCVIEWER_CLIPPING")),
- tr ("MNU_CLIPPING"), 0, this);
- aAction->setStatusTip (tr ("DSC_CLIPPING"));
+ aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
+ tr("MNU_CLIPPING"), 0, this);
+ aAction->setStatusTip (tr("DSC_CLIPPING"));
aAction->setCheckable (true);
connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
toolMgr()->registerAction (aAction, ClippingId);
if (myModel->trihedronActivated()) {
aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
+ aAction->setCheckable( true );
+ aAction->setChecked( true );
aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
- connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihedronShow()));
+ connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
toolMgr()->registerAction( aAction, TrihedronShowId );
}
*/
void OCCViewer_ViewWindow::createToolBar()
{
- QString aToolbarName;
- switch (my2dMode) {
- case XYPlane:
- aToolbarName = tr( "LBL_XYTOOLBAR_LABEL" );
- break;
- case XZPlane:
- aToolbarName = tr( "LBL_XZTOOLBAR_LABEL" );
- break;
- case YZPlane:
- aToolbarName = tr( "LBL_YZTOOLBAR_LABEL" );
- break;
- default:
- aToolbarName = tr( "LBL_3DTOOLBAR_LABEL" );
- }
-
- int tid = toolMgr()->createToolBar( aToolbarName, false );
+ static const char* titles[] = {
+ "LBL_3DTOOLBAR_LABEL",
+ "LBL_XYTOOLBAR_LABEL",
+ "LBL_XZTOOLBAR_LABEL",
+ "LBL_YZTOOLBAR_LABEL",
+ };
+ static const char* names[] = {
+ "OCCViewer3DViewOperations",
+ "OCCViewerXYViewOperations",
+ "OCCViewerXZViewOperations",
+ "OCCViewerYZViewOperations",
+ };
+ int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
+ QString( names[my2dMode] ), // name (language-independant)
+ false ); // disable floatable toolbar
if ( my2dMode != No2dMode ){
toolMgr()->append( ReturnTo3dViewId, tid );
toolMgr()->append( toolMgr()->separator(), tid );
}
toolMgr()->append( DumpId, tid );
toolMgr()->append( SwitchInteractionStyleId, tid );
-#if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
toolMgr()->append( SwitchZoomingStyleId, tid );
-#endif
toolMgr()->append( SwitchPreselectionId, tid );
toolMgr()->append( SwitchSelectionId, tid );
if( myModel->trihedronActivated() )
toolMgr()->append( toolMgr()->separator(), tid );
toolMgr()->append( ClippingId, tid );
toolMgr()->append( AxialScaleId, tid );
-#if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
toolMgr()->append( GraduatedAxesId, tid );
-#endif
toolMgr()->append( AmbientId, tid );
toolMgr()->append( MaximizedId, tid );
Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
aView3d->SetScale( anItem.scale );
- aView3d->SetCenter( anItem.centerX, anItem.centerY );
aView3d->SetTwist( anItem.twist );
aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
aView3d->SetImmediateUpdate( prev );
aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
+#if OCC_VERSION_LARGE > 0x06070100
+ if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
+ {
+ double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
+
+ // "eye" and "at" require conversion to represent center panning
+ // up direction is only available after setting angle of twist and
+ // other view parameters
+ aView3d->Up( anUpX, anUpY, anUpZ );
+
+ gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
+ gp_Dir anUp( anUpX, anUpY, anUpZ );
+ gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
+ gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
+ gp_Dir aSide = aProj ^ anUp;
+
+ anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
+ anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
+
+ aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
+ aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
+ }
+#else
+ aView3d->SetCenter( anItem.centerX, anItem.centerY );
+#endif
+
if ( !baseParamsOnly ) {
myModel->setTrihedronShown( anItem.isVisible );
myModel->setTrihedronSize( anItem.size );
-#if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
// graduated trihedron
bool anIsVisible = anItem.gtIsVisible;
OCCViewer_AxisWidget::AxisData anAxisData[3];
myCubeAxesDlg->SetData( anIsVisible, anAxisData );
myCubeAxesDlg->ApplyData( aView3d );
-#endif
} // if ( !baseParamsOnly )
/*!
\brief Called when action "show/hide trihedron" is activated.
*/
-void OCCViewer_ViewWindow::onTrihedronShow()
+void OCCViewer_ViewWindow::onTrihedronShow(bool show)
{
- myModel->toggleTrihedron();
+ myModel->setTrihedronShown(show);
}
/*!
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();
glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
data);
+ */
+
+ Image_PixMap aPix;
+ view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
- QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
+ QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
anImage = anImage.mirrored();
- anImage = anImage.rgbSwapped();
return anImage;
}
pln.Coefficients(a, b, c, d);
Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
- Handle(Graphic3d_ClipPlane) aClipPlane;
if(aPlanes.Size() > 0 ) {
Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
- aClipPlane = anIter.Value();
+ Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
aClipPlane->SetEquation(pln);
aClipPlane->SetOn(Standard_True);
} else {
- aClipPlane = new Graphic3d_ClipPlane(pln);
- view->AddClipPlane(aClipPlane);
- aClipPlane->SetOn(Standard_True);
+ view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
}
}
else {
*/
viewAspect OCCViewer_ViewWindow::getViewParams() const
{
- double centerX, centerY, projX, projY, projZ, twist;
+ double projX, projY, projZ, twist;
double atX, atY, atZ, eyeX, eyeY, eyeZ;
double aScaleX, aScaleY, aScaleZ;
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 );
viewAspect params;
params.scale = aView3d->Scale();
- params.centerX = centerX;
- params.centerY = centerY;
params.projX = projX;
params.projY = projY;
params.projZ = projZ;
params.isVisible= isShown;
params.size = size;
-#if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
+#if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
+ aView3d->Center( params.centerX, params.centerY );
+#endif
+
// graduated trihedron
bool anIsVisible = false;
OCCViewer_AxisWidget::AxisData anAxisData[3];
params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
-#endif
return params;
}
QStringList data;
data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
+#if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
+#endif
data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
ClipPlanesList aPlanes = myModel->getClipPlanes();
- for ( int i=0; i < aPlanes.size(); i++ ) {
+ for ( int i=0; i < aPlanes.size(); i++ )
+ {
OCCViewer_ClipPlane& aPlane = aPlanes[i];
QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
- ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.PlaneMode );
+ ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
- ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.Orientation );
- ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.IsInvert );
+ switch ( aPlane.Mode )
+ {
+ case OCCViewer_ClipPlane::Absolute :
+ {
+ ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
+
+ if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
+ {
+ ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
+ ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
+ ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
+ }
+ else
+ {
+ ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
+ }
+ }
+ break;
+
+ case OCCViewer_ClipPlane::Relative :
+ {
+ ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
+ ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
+ ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
+ }
+ break;
+ }
+
ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
- ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.Dx );
- ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.Dy );;
- ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.Dz );
- ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.RelativeMode.Orientation );
- ClippingPlane += QString( "Distance~%1;" ).arg( aPlane.RelativeMode.Distance );
- ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeMode.Rotation1 );
- ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeMode.Rotation2 );
data << ClippingPlane;
}
-
-#if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 or newer version
// graduated trihedron
data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
-#endif
QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
data << QString( "background=%1" ).arg( bg );
else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
else if ( paramName == "size" ) params.size = paramValue.toDouble();
- else if ( paramName.contains( "ClippingPlane" ) ) {
+ else if ( paramName.contains( "ClippingPlane" ) )
+ {
QStringList ClipPlaneData = paramValue.split( ';' );
OCCViewer_ClipPlane aPlane;
- foreach( QString ClipPlaneParam, ClipPlaneData ) {
- QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
- QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
- if ( ClipPlane_paramName == "Mode" ) aPlane.PlaneMode = ( ClipPlaneMode )ClipPlane_paramValue.toInt();
- else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
- else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.Orientation = ClipPlane_paramValue.toInt();
- else if ( ClipPlane_paramName == "IsInvert" ) aPlane.IsInvert = ClipPlane_paramValue.toInt();
- else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
- else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
- else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
- else if ( ClipPlane_paramName == "Dx" ) aPlane.Dx = ClipPlane_paramValue.toDouble();
- else if ( ClipPlane_paramName == "Dy" ) aPlane.Dy = ClipPlane_paramValue.toDouble();
- else if ( ClipPlane_paramName == "Dz" ) aPlane.Dz = ClipPlane_paramValue.toDouble();
- else if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.RelativeMode.Orientation = ClipPlane_paramValue.toInt();
- else if ( ClipPlane_paramName == "Distance" ) aPlane.RelativeMode.Distance = ClipPlane_paramValue.toDouble();
- else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeMode.Rotation1 = ClipPlane_paramValue.toDouble();
- else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeMode.Rotation2 = ClipPlane_paramValue.toDouble();
+ foreach( QString ClipPlaneParam, ClipPlaneData )
+ {
+ QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
+ QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
+ if ( ClipPlane_paramName == "Mode" )
+ {
+ aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
+ }
+ else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
+ else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
+ else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
+ else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
+ else
+ {
+ switch ( aPlane.Mode )
+ {
+ case OCCViewer_ClipPlane::Absolute :
+ if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
+ else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
+ else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
+ else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
+ else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
+ break;
+
+ case OCCViewer_ClipPlane::Relative :
+ if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
+ else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
+ else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
+ break;
+ }
+ }
}
- aClipPlanes.push_back(aPlane);
+ aClipPlanes.push_back(aPlane);
}
// graduated trihedron
else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
if ( myViewPort ) myViewPort->setBackground( theBackground );
}
+void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
+{
+ if ( myViewPort ) myViewPort->showStaticTrihedron( on );
+}
+
/*!
Clears view aspects
*/
aProps.setDimension( SUIT_CameraProperties::Dim2D );
aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
}
-
+
// read common properites of the view
- Standard_Real anUpDir[3];
- Standard_Real aPrjDir[3];
- Standard_Real aMapScale[2];
- Standard_Real aTranslation[3];
+ Standard_Real anUp[3];
+ Standard_Real anAt[3];
+ Standard_Real anEye[3];
+ Standard_Real aProj[3];
Standard_Real anAxialScale[3];
-
- aSourceView->Up(anUpDir[0], anUpDir[1], anUpDir[2]);
- aSourceView->Proj(aPrjDir[0], aPrjDir[1], aPrjDir[2]);
- aSourceView->At(aTranslation[0], aTranslation[1], aTranslation[2]);
- aSourceView->Size(aMapScale[0], aMapScale[1]);
- getViewPort()->getAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
+ aSourceView->Up( anUp[0], anUp[1], anUp[2] );
+ aSourceView->At( anAt[0], anAt[1], anAt[2] );
+ aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
+ getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
- // we use similar depth to the one used in perspective projection
- // to proivde a convinience synchronization with other camera views that
- // can switch between orthogonal & perspective projection. otherwise,
- // the camera will get to close when switching from orthogonal to perspective.
+ aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
+ aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
+
+#if OCC_VERSION_LARGE > 0x06070100
+ aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
+
+ // store camera properties "as is": it is up to synchronized
+ // view classes to provide necessary property conversion.
+ aProps.setPosition( anEye[0], anEye[1], anEye[2] );
+ aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
+
+ if ( aSourceView->Camera()->IsOrthographic() )
+ {
+ aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
+ aProps.setViewAngle( 0.0 );
+ }
+ else
+ {
+ aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
+ aProps.setViewAngle( aSourceView->Camera()->FOVy() );
+ }
+ aProps.setMappingScale( aSourceView->Camera()->Scale() );
+#else
Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
- // store common props
- aProps.setViewUp(anUpDir[0], anUpDir[1], anUpDir[2]);
- aProps.setMappingScale(aMapScale[1] / 2.0);
- aProps.setAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
-
// generate view orientation matrix for transforming OCC projection reference point
// into a camera (eye) position.
- gp_Dir aLeftDir = gp_Dir(anUpDir[0], anUpDir[1], anUpDir[2]).Crossed(
- gp_Dir(aPrjDir[0], aPrjDir[1], aPrjDir[2]));
+ gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
+
+ gp_GTrsf aTrsf;
+ aTrsf.SetValue( 1, 1, aLeftDir.X() );
+ aTrsf.SetValue( 2, 1, aLeftDir.Y() );
+ aTrsf.SetValue( 3, 1, aLeftDir.Z() );
+
+ aTrsf.SetValue( 1, 2, anUp[0] );
+ aTrsf.SetValue( 2, 2, anUp[1] );
+ aTrsf.SetValue( 3, 2, anUp[2] );
+
+ aTrsf.SetValue( 1, 3, aProj[0] );
+ aTrsf.SetValue( 2, 3, aProj[1] );
+ aTrsf.SetValue( 3, 3, aProj[2] );
- gp_Trsf aTrsf;
- aTrsf.SetValues( aLeftDir.X(), anUpDir[0], aPrjDir[0], aTranslation[0],
- aLeftDir.Y(), anUpDir[1], aPrjDir[1], aTranslation[1],
- aLeftDir.Z(), anUpDir[2], aPrjDir[2], aTranslation[2],
- Precision::Confusion(),
- Precision::Confusion() );
+ aTrsf.SetValue( 1, 4, anAt[0] );
+ aTrsf.SetValue( 2, 4, anAt[1] );
+ aTrsf.SetValue( 3, 4, anAt[2] );
- // get projection reference point in view coordinates
Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
-
+
// transform to world-space coordinate system
- gp_Pnt aPosition = gp_Pnt(aProjRef.X(), aProjRef.Y(), aCameraDepth).Transformed(aTrsf);
-
+ gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
+ aTrsf.Transforms( aPosition );
+
// compute focal point
double aFocalPoint[3];
- aFocalPoint[0] = aPosition.X() - aPrjDir[0] * aCameraDepth;
- aFocalPoint[1] = aPosition.Y() - aPrjDir[1] * aCameraDepth;
- aFocalPoint[2] = aPosition.Z() - aPrjDir[2] * aCameraDepth;
+ aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
+ aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
+ aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
- aProps.setFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
- aProps.setPosition(aPosition.X(), aPosition.Y(), aPosition.Z());
+ aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
+ aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
+
+ Standard_Real aViewScale[2];
+ aSourceView->Size( aViewScale[0], aViewScale[1] );
+ aProps.setMappingScale( aViewScale[1] );
+#endif
return aProps;
}
double anUpDir[3];
double aPosition[3];
double aFocalPoint[3];
- double aMapScaling;
double anAxialScale[3];
// get common properties
- aProps.getFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
- aProps.getPosition(aPosition[0], aPosition[1], aPosition[2]);
- aProps.getViewUp(anUpDir[0], anUpDir[1], anUpDir[2]);
- aProps.getAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
- aMapScaling = aProps.getMappingScale() * 2.0;
-
- gp_Dir aProjDir(aPosition[0] - aFocalPoint[0],
- aPosition[1] - aFocalPoint[1],
- aPosition[2] - aFocalPoint[2]);
-
+ aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
+ aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
+ aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
+ aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
+
+#if OCC_VERSION_LARGE > 0x06070100
+ aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
+ aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
+ aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
+ aDestView->Camera()->SetScale( aProps.getMappingScale() );
+#else
+ gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
+ aPosition[1] - aFocalPoint[1],
+ aPosition[2] - aFocalPoint[2] );
+
// get custom view translation
Standard_Real aTranslation[3];
- aDestView->At(aTranslation[0], aTranslation[1], aTranslation[2]);
-
- gp_Dir aLeftDir = gp_Dir(anUpDir[0], anUpDir[1], anUpDir[2]).Crossed(
- gp_Dir(aProjDir.X(), aProjDir.Y(), aProjDir.Z()));
-
- // convert camera position into a view reference point
- gp_Trsf aTrsf;
- aTrsf.SetValues( aLeftDir.X(), anUpDir[0], aProjDir.X(), aTranslation[0],
- aLeftDir.Y(), anUpDir[1], aProjDir.Y(), aTranslation[1],
- aLeftDir.Z(), anUpDir[2], aProjDir.Z(), aTranslation[2],
- Precision::Confusion(),
- Precision::Confusion() );
+ aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
+
+ gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
+ ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
+
+ gp_GTrsf aTrsf;
+ aTrsf.SetValue( 1, 1, aLeftDir.X() );
+ aTrsf.SetValue( 2, 1, aLeftDir.Y() );
+ aTrsf.SetValue( 3, 1, aLeftDir.Z() );
+
+ aTrsf.SetValue( 1, 2, anUpDir[0] );
+ aTrsf.SetValue( 2, 2, anUpDir[1] );
+ aTrsf.SetValue( 3, 2, anUpDir[2] );
+
+ aTrsf.SetValue( 1, 3, aProjDir.X() );
+ aTrsf.SetValue( 2, 3, aProjDir.Y() );
+ aTrsf.SetValue( 3, 3, aProjDir.Z() );
+
+ aTrsf.SetValue( 1, 4, aTranslation[0] );
+ aTrsf.SetValue( 2, 4, aTranslation[1] );
+ aTrsf.SetValue( 3, 4, aTranslation[2] );
aTrsf.Invert();
// transform to view-space coordinate system
- gp_Pnt aProjRef(aPosition[0], aPosition[1], aPosition[2]);
- aProjRef.Transform(aTrsf);
+ gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
+ aTrsf.Transforms( aProjRef );
// set view camera properties using low-level approach. this is done
// in order to avoid interference with static variables in v3d view used
Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
- Graphic3d_Vector aMappingProj(aProjDir.X(), aProjDir.Y(), aProjDir.Z());
- Graphic3d_Vector aMappingUp(anUpDir[0], anUpDir[1], anUpDir[2]);
+ Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
+ Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
aMappingProj.Normalize();
aMappingUp.Normalize();
- anOrientation.SetViewReferencePlane(aMappingProj);
- anOrientation.SetViewReferenceUp(aMappingUp);
+ anOrientation.SetViewReferencePlane( aMappingProj );
+ anOrientation.SetViewReferenceUp( aMappingUp );
- aDestView->SetViewMapping(aMapping);
- aDestView->SetViewOrientation(anOrientation);
+ aDestView->SetViewMapping( aMapping );
+ aDestView->SetViewOrientation( anOrientation );
// set panning
- aDestView->SetCenter(aProjRef.X(), aProjRef.Y());
+ aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
// set mapping scale
+ double aMapScaling = aProps.getMappingScale();
Standard_Real aWidth, aHeight;
- aDestView->Size(aWidth, aHeight);
-
- if ( aWidth > aHeight )
- aDestView->SetSize (aMapScaling * (aWidth / aHeight));
- else
- aDestView->SetSize (aMapScaling);
+ aDestView->Size( aWidth, aHeight );
+ aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
+#endif
- getViewPort()->setAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
+ getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
aDestView->ZFitAll();
aDestView->SetImmediateUpdate( Standard_True );