1 // Copyright (C) 2014-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "OCCViewer_Utilities.h"
22 #include "OCCViewer_ViewFrame.h"
23 #include "OCCViewer_ViewModel.h"
24 #include "OCCViewer_ViewPort3d.h"
26 #include "SUIT_ViewManager.h"
27 #include "QtxActionToolMgr.h"
28 #include "QtxMultiAction.h"
31 #include <Basics_OCCTVersion.hxx>
34 #include <V3d_View.hxx>
40 Handle(Image_PixMap) OCCViewer_Utilities::imageToPixmap( const QImage& anImage )
42 Handle(Image_PixMap) aPixmap = new Image_PixMap();
43 if ( !anImage.isNull() ) {
44 aPixmap->InitTrash( Image_PixMap::ImgBGRA, anImage.width(), anImage.height() );
45 aPixmap->SetTopDown( Standard_True );
47 const uchar* aImageBytes = anImage.bits();
49 for ( int aLine = anImage.height() - 1; aLine >= 0; --aLine ) {
50 #if OCC_VERSION_LARGE > 0x06070100
51 // convert pixels from ARGB to renderer-compatible RGBA
52 for ( int aByte = 0; aByte < anImage.width(); ++aByte ) {
53 Image_ColorBGRA& aPixmapBytes = aPixmap->ChangeValue<Image_ColorBGRA>(aLine, aByte);
55 aPixmapBytes.b() = (Standard_Byte) *aImageBytes++;
56 aPixmapBytes.g() = (Standard_Byte) *aImageBytes++;
57 aPixmapBytes.r() = (Standard_Byte) *aImageBytes++;
58 aPixmapBytes.a() = (Standard_Byte) *aImageBytes++;
61 Image_ColorBGRA* aPixmapBytes = aPixmap->EditData<Image_ColorBGRA>().ChangeRow(aLine);
63 // convert pixels from ARGB to renderer-compatible RGBA
64 for ( int aByte = 0; aByte < anImage.width(); ++aByte ) {
65 aPixmapBytes->b() = (Standard_Byte) *aImageBytes++;
66 aPixmapBytes->g() = (Standard_Byte) *aImageBytes++;
67 aPixmapBytes->r() = (Standard_Byte) *aImageBytes++;
68 aPixmapBytes->a() = (Standard_Byte) *aImageBytes++;
77 OCCViewer_ViewWindow::Mode2dType OCCViewer_Utilities::setViewer2DMode
78 ( OCCViewer_Viewer* theViewer,
79 const OCCViewer_ViewWindow::Mode2dType& theMode )
81 OCCViewer_ViewWindow::Mode2dType anOldMode = OCCViewer_ViewWindow::No2dMode;
82 OCCViewer_ViewFrame* aFrame = dynamic_cast<OCCViewer_ViewFrame*>
83 ( theViewer->getViewManager()->getActiveView() );
84 OCCViewer_ViewWindow* aView = aFrame ? aFrame->getView( OCCViewer_ViewFrame::MAIN_VIEW ) : 0;
89 anOldMode = aView->get2dMode();
90 aView->set2dMode( theMode );
91 bool is2dMode = theMode != OCCViewer_ViewWindow::No2dMode;
93 // enable/disable view actions
94 QList<int> aNo2dActions;
95 aNo2dActions << OCCViewer_ViewWindow::ChangeRotationPointId
96 << OCCViewer_ViewWindow::RotationId
97 << OCCViewer_ViewWindow::FrontId
98 << OCCViewer_ViewWindow::BackId
99 //<< OCCViewer_ViewWindow::TopId
100 << OCCViewer_ViewWindow::BottomId
101 << OCCViewer_ViewWindow::LeftId
102 << OCCViewer_ViewWindow::RightId
103 << OCCViewer_ViewWindow::AntiClockWiseId
104 << OCCViewer_ViewWindow::ClockWiseId
105 << OCCViewer_ViewWindow::ResetId;
107 QtxActionToolMgr* aToolMgr = aView->toolMgr();
109 for ( int i = 0, aNb = aNo2dActions.size(); i < aNb; i++ ) {
110 anAction = aToolMgr->action( aNo2dActions[i] );
112 anAction->setEnabled( !is2dMode );
114 QAction* aTop = aToolMgr->action( OCCViewer_ViewWindow::TopId );
115 QtxMultiAction* aMulti = dynamic_cast<QtxMultiAction*>( aTop->parent() );
116 aMulti->setActiveAction( aTop );
118 // change view position
119 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
120 if ( !aView3d.IsNull() ) {
122 case OCCViewer_ViewWindow::XYPlane:
123 aView3d->SetProj (V3d_Zpos);
125 case OCCViewer_ViewWindow::XZPlane:
126 aView3d->SetProj (V3d_Yneg);
128 case OCCViewer_ViewWindow::YZPlane:
129 aView3d->SetProj (V3d_Xpos);