X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FOCCViewer%2FOCCViewer_Utilities.cxx;h=506b9dc15f0e5e678cfd941d66046d07cf2c34ce;hb=9f3acb9230f025863cce18d4c865c1227ea97afc;hp=5b9a8797d077148187591c840534cf07d675cc56;hpb=949661e3432745e77dfc32ac83ee7d06c7e57ced;p=modules%2Fgui.git diff --git a/src/OCCViewer/OCCViewer_Utilities.cxx b/src/OCCViewer/OCCViewer_Utilities.cxx old mode 100755 new mode 100644 index 5b9a8797d..506b9dc15 --- a/src/OCCViewer/OCCViewer_Utilities.cxx +++ b/src/OCCViewer/OCCViewer_Utilities.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2014 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2014-2021 CEA/DEN, EDF R&D, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -27,27 +27,33 @@ #include "QtxActionToolMgr.h" #include "QtxMultiAction.h" -// KERNEL includes #include // OCC includes #include +#include // QT includes #include #include +#include Handle(Image_PixMap) OCCViewer_Utilities::imageToPixmap( const QImage& anImage ) { Handle(Image_PixMap) aPixmap = new Image_PixMap(); if ( !anImage.isNull() ) { aPixmap->InitTrash( Image_PixMap::ImgBGRA, anImage.width(), anImage.height() ); +#if OCC_VERSION_LARGE < 0x07050000 aPixmap->SetTopDown( Standard_True ); +#endif const uchar* aImageBytes = anImage.bits(); - + +#if OCC_VERSION_LARGE < 0x07050000 for ( int aLine = anImage.height() - 1; aLine >= 0; --aLine ) { -#if OCC_VERSION_LARGE > 0x06070100 +#else + for ( int aLine = 0; aLine < anImage.height(); ++aLine ) { +#endif // convert pixels from ARGB to renderer-compatible RGBA for ( int aByte = 0; aByte < anImage.width(); ++aByte ) { Image_ColorBGRA& aPixmapBytes = aPixmap->ChangeValue(aLine, aByte); @@ -57,33 +63,24 @@ Handle(Image_PixMap) OCCViewer_Utilities::imageToPixmap( const QImage& anImage ) aPixmapBytes.r() = (Standard_Byte) *aImageBytes++; aPixmapBytes.a() = (Standard_Byte) *aImageBytes++; } -#else - Image_ColorBGRA* aPixmapBytes = aPixmap->EditData().ChangeRow(aLine); - - // convert pixels from ARGB to renderer-compatible RGBA - for ( int aByte = 0; aByte < anImage.width(); ++aByte ) { - aPixmapBytes->b() = (Standard_Byte) *aImageBytes++; - aPixmapBytes->g() = (Standard_Byte) *aImageBytes++; - aPixmapBytes->r() = (Standard_Byte) *aImageBytes++; - aPixmapBytes->a() = (Standard_Byte) *aImageBytes++; - aPixmapBytes++; - } -#endif } } return aPixmap; } -void OCCViewer_Utilities::setViewer2DMode( OCCViewer_Viewer* theViewer, +OCCViewer_ViewWindow::Mode2dType OCCViewer_Utilities::setViewer2DMode + ( OCCViewer_Viewer* theViewer, const OCCViewer_ViewWindow::Mode2dType& theMode ) { + OCCViewer_ViewWindow::Mode2dType anOldMode = OCCViewer_ViewWindow::No2dMode; OCCViewer_ViewFrame* aFrame = dynamic_cast ( theViewer->getViewManager()->getActiveView() ); OCCViewer_ViewWindow* aView = aFrame ? aFrame->getView( OCCViewer_ViewFrame::MAIN_VIEW ) : 0; if ( !aView ) - return; + return anOldMode; // set a view mode + anOldMode = aView->get2dMode(); aView->set2dMode( theMode ); bool is2dMode = theMode != OCCViewer_ViewWindow::No2dMode; @@ -99,6 +96,8 @@ void OCCViewer_Utilities::setViewer2DMode( OCCViewer_Viewer* theViewer, << OCCViewer_ViewWindow::RightId << OCCViewer_ViewWindow::AntiClockWiseId << OCCViewer_ViewWindow::ClockWiseId + << OCCViewer_ViewWindow::OrthographicId + << OCCViewer_ViewWindow::PerspectiveId << OCCViewer_ViewWindow::ResetId; QtxActionToolMgr* aToolMgr = aView->toolMgr(); @@ -106,7 +105,10 @@ void OCCViewer_Utilities::setViewer2DMode( OCCViewer_Viewer* theViewer, 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( aTop->parent() ); @@ -125,6 +127,130 @@ void OCCViewer_Utilities::setViewer2DMode( OCCViewer_Viewer* theViewer, case OCCViewer_ViewWindow::YZPlane: aView3d->SetProj (V3d_Xpos); break; + default: + break; } } + + return anOldMode; +} + +bool OCCViewer_Utilities::isDialogOpened( OCCViewer_ViewWindow* theView, const QString& theName ) +{ + bool isFound = false; + OCCViewer_ViewFrame* aViewFrame = dynamic_cast( theView->parent()->parent() ); + QList allDialogs = aViewFrame->findChildren(); + foreach ( QDialog* d, allDialogs ) + if ( d->objectName() == theName ) + isFound = true; + return isFound; +} + +bool OCCViewer_Utilities::computeVisibleBounds( const Handle(V3d_View) theView, + double theBounds[6] ) +{ + bool isAny = false; + + theBounds[0] = theBounds[2] = theBounds[4] = DBL_MAX; + theBounds[1] = theBounds[3] = theBounds[5] = -DBL_MAX; + + Graphic3d_MapOfStructure aSetOfStructures; + theView->View()->DisplayedStructures( aSetOfStructures ); + Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures ); + + for( ; aStructureIt.More(); aStructureIt.Next() ) { + const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key(); + if ( aStructure->IsEmpty() || !aStructure->IsVisible() || + aStructure->IsInfinite() || aStructure->CStructure()->IsForHighlight ) + continue; + double aBounds[6]; + Bnd_Box aBox = aStructure->MinMaxValues(); + aBounds[0] = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X(); + aBounds[2] = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y(); + aBounds[4] = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z(); + aBounds[1] = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X(); + aBounds[3] = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y(); + aBounds[5] = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z(); + + if ( aBounds[0] > -DBL_MAX && aBounds[1] < DBL_MAX && + aBounds[2] > -DBL_MAX && aBounds[3] < DBL_MAX && + aBounds[4] > -DBL_MAX && aBounds[5] < DBL_MAX ) + { + isAny = true; + for ( int i = 0; i < 5; i = i + 2 ) { + theBounds[i] = std::min( theBounds[i], aBounds[i] ); + theBounds[i+1] = std::max( theBounds[i+1], aBounds[i+1] ); + } + } + } + return isAny; +} + +bool OCCViewer_Utilities::computeVisibleBBCenter( const Handle(V3d_View) theView, + double& theX, double& theY, double& theZ ) +{ + double aBounds[6]; + if ( !computeVisibleBounds( theView, aBounds ) ) + { + // null bounding box => the center is (0,0,0) + theX = 0.0; + theY = 0.0; + theZ = 0.0; + return true; + } + + static double aMinDistance = 1.0 / DBL_MAX; + + double aLength = aBounds[1]-aBounds[0]; + aLength = std::max( ( aBounds[3]-aBounds[2]), aLength ); + aLength = std::max( ( aBounds[5]-aBounds[4]), aLength ); + + if ( aLength < aMinDistance ) + return false; + + double aWidth = sqrt( ( aBounds[1] - aBounds[0] ) * ( aBounds[1] - aBounds[0] ) + + ( aBounds[3] - aBounds[2] ) * ( aBounds[3] - aBounds[2] ) + + ( aBounds[5] - aBounds[4] ) * ( aBounds[5] - aBounds[4] ) ); + + if(aWidth < aMinDistance) + return false; + + theX = (aBounds[0] + aBounds[1])/2.0; + theY = (aBounds[2] + aBounds[3])/2.0; + theZ = (aBounds[4] + aBounds[5])/2.0; + + 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; }