Salome HOME
Merge remote-tracking branch 'origin/hydro/imps_2017_salome_83' into hydro/imps_2017
[modules/gui.git] / src / OCCViewer / OCCViewer_Utilities.cxx
index 5a6594281a1c8eec1b7dc841b5e68a6ce73c1bec..8ee02c3b1eb535028dd0b59b88fb829a23dacdbe 100755 (executable)
@@ -27,9 +27,6 @@
 #include "QtxActionToolMgr.h"
 #include "QtxMultiAction.h"
 
-// KERNEL includes
-#include <Basics_OCCTVersion.hxx>
-
 // OCC includes
 #include <V3d_View.hxx>
 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
@@ -49,7 +46,6 @@ Handle(Image_PixMap) OCCViewer_Utilities::imageToPixmap( const QImage& anImage )
     const uchar* aImageBytes = anImage.bits();
       
     for ( int aLine = anImage.height() - 1; aLine >= 0; --aLine ) {
-#if OCC_VERSION_LARGE > 0x06070100
       // convert pixels from ARGB to renderer-compatible RGBA
       for ( int aByte = 0; aByte < anImage.width(); ++aByte ) {
            Image_ColorBGRA& aPixmapBytes = aPixmap->ChangeValue<Image_ColorBGRA>(aLine, aByte);
@@ -59,18 +55,6 @@ 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<Image_ColorBGRA>().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;
@@ -113,7 +97,10 @@ OCCViewer_ViewWindow::Mode2dType OCCViewer_Utilities::setViewer2DMode
   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() );
@@ -167,7 +154,6 @@ bool OCCViewer_Utilities::computeVisibleBounds( const Handle(V3d_View) theView,
          aStructure->IsInfinite() || aStructure->CStructure()->IsForHighlight )
       continue;
     double aBounds[6];
-#if OCC_VERSION_LARGE > 0x06070100
     Bnd_Box aBox = aStructure->MinMaxValues();
     aBounds[0] = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
     aBounds[2] = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
@@ -175,10 +161,6 @@ bool OCCViewer_Utilities::computeVisibleBounds( const Handle(V3d_View) theView,
     aBounds[1] = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().X();
     aBounds[3] = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().Y();
     aBounds[5] = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().Z();
-#else
-    aStructure->MinMaxValues( aBounds[0], aBounds[2], aBounds[4],
-                              aBounds[1], aBounds[3], aBounds[5] );
-#endif
 
     if ( aBounds[0] > -DBL_MAX && aBounds[1] < DBL_MAX &&
          aBounds[2] > -DBL_MAX && aBounds[3] < DBL_MAX &&
@@ -229,3 +211,36 @@ bool OCCViewer_Utilities::computeVisibleBBCenter( const Handle(V3d_View) theView
 
   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;
+}