Salome HOME
Bos #24226, pb #3: Clipping faces texture is lost.
[modules/gui.git] / src / OCCViewer / OCCViewer_Utilities.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 9a560d7..506b9dc
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2016  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,6 +27,8 @@
 #include "QtxActionToolMgr.h"
 #include "QtxMultiAction.h"
 
+#include <Basics_OCCTVersion.hxx>
+
 // OCC includes
 #include <V3d_View.hxx>
 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
@@ -41,11 +43,17 @@ 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 ) {
+#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<Image_ColorBGRA>(aLine, aByte);
@@ -97,7 +105,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() );
@@ -116,6 +127,8 @@ OCCViewer_ViewWindow::Mode2dType OCCViewer_Utilities::setViewer2DMode
       case OCCViewer_ViewWindow::YZPlane:
         aView3d->SetProj (V3d_Xpos);
         break;
+      default:
+        break;
     }
   }
 
@@ -208,3 +221,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;
+}