]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Merge from SKV_CCreator_from_HYDRO branch
authorvsr <vsr@opencascade.com>
Fri, 10 Oct 2014 09:37:00 +0000 (13:37 +0400)
committervsr <vsr@opencascade.com>
Fri, 10 Oct 2014 09:37:00 +0000 (13:37 +0400)
1  2 
src/OCCViewer/OCCViewer_Utilities.cxx
src/OCCViewer/OCCViewer_Utilities.h

index 5b9a8797d077148187591c840534cf07d675cc56,fd9c9242c9f19df55ae21e925b6bad7d61e87c97..51c38836558f9c4a08c47fe8896aff39498fc52f
mode 100755,100644..100755
@@@ -1,23 -1,4 +1,23 @@@
 +// Copyright (C) 2014  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
 +// License as published by the Free Software Foundation; either
 +// 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
 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 +// Lesser General Public License for more details.
 +//
 +// You should have received a copy of the GNU Lesser General Public
 +// License along with this library; if not, write to the Free Software
 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 +//
 +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 +//
  
 +// internal includes
  #include "OCCViewer_Utilities.h"
  #include "OCCViewer_ViewFrame.h"
  #include "OCCViewer_ViewModel.h"
  
  #include "SUIT_ViewManager.h"
  #include "QtxActionToolMgr.h"
 +#include "QtxMultiAction.h"
  
 +// KERNEL includes
 +#include <Basics_OCCTVersion.hxx>
 +
 +// OCC includes
  #include <V3d_View.hxx>
  
 +// QT includes
 +#include <QImage>
  #include <QAction>
  
- void OCCViewer_Utilities::setViewer2DMode( OCCViewer_Viewer* theViewer,
 +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() );
 +    aPixmap->SetTopDown( Standard_True );
 +
 +    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);
 +
 +          aPixmapBytes.b() = (Standard_Byte) *aImageBytes++;
 +          aPixmapBytes.g() = (Standard_Byte) *aImageBytes++;
 +          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;
 +}
 +
+ 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<OCCViewer_ViewFrame*>
                                       ( 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;
  
@@@ -93,7 -33,7 +96,7 @@@
                 << OCCViewer_ViewWindow::RotationId
                 << OCCViewer_ViewWindow::FrontId
                 << OCCViewer_ViewWindow::BackId
 -               << OCCViewer_ViewWindow::TopId
 +               //<< OCCViewer_ViewWindow::TopId
                 << OCCViewer_ViewWindow::BottomId
                 << OCCViewer_ViewWindow::LeftId
                 << OCCViewer_ViewWindow::RightId
      if ( anAction )
        anAction->setEnabled( !is2dMode );
    }
 +  QAction* aTop = aToolMgr->action( OCCViewer_ViewWindow::TopId );
 +  QtxMultiAction* aMulti = dynamic_cast<QtxMultiAction*>( aTop->parent() );
 +  aMulti->setActiveAction( aTop );
  
    // change view position
    Handle(V3d_View) aView3d = aView->getViewPort()->getView();
          break;
      }
    }
+   return anOldMode;
  }
index 1cbbacf2442a7c4239ef38d9ba9e52dd112aa934,8319bf74d6ba155eb120c045a1c4ccc9a9af0575..fee76863f4f44c140d755b243956e2ab7d521e4e
mode 100755,100644..100755
@@@ -1,33 -1,9 +1,33 @@@
 +// Copyright (C) 2014  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
 +// License as published by the Free Software Foundation; either
 +// 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
 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 +// Lesser General Public License for more details.
 +//
 +// You should have received a copy of the GNU Lesser General Public
 +// License along with this library; if not, write to the Free Software
 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 +//
 +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 +//
 +
  #ifndef OCCVIEWER_UTILITIES_H
  #define OCCVIEWER_UTILITIES_H
  
 +// internal includes
  #include "OCCViewer.h"
  #include "OCCViewer_ViewWindow.h"
  
 +// OCC includes
 +#include <Image_PixMap.hxx>
 +
 +class QImage;
  class OCCViewer_Viewer;
  
  #ifdef WIN32
@@@ -38,21 -14,16 +38,23 @@@ class OCCVIEWER_EXPORT OCCViewer_Utilit
  {
  public:
  
 +  /*!
 +   * Convert Qt image to OCCT pixmap
 +   * \param theImage Qt source image
 +   * \return resulting OCCT pixmap
 +   */
 +  static Handle(Image_PixMap) imageToPixmap( const QImage& theImage );
 +
    /*!
     * Set 2D mode for the viewer. Hide or show 3D actions.
     * \param theViewer an OCC viewer
     * \param theMode OCC view window mode
+    * \return the old 2d mode.
     */
-   static void setViewer2DMode( OCCViewer_Viewer* theViewer,
+   static OCCViewer_ViewWindow::Mode2dType
+               setViewer2DMode( OCCViewer_Viewer* theViewer,
                                 const OCCViewer_ViewWindow::Mode2dType& theMode );
  
  };
  
 -#endif
 +#endif // OCCVIEWER_UTILITIES_H