1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <HYDROGUI_ShapeImage.h>
25 #include <HYDROGUI_Tool.h>
26 #include <HYDROGUI_ImagePrs.h>
28 #include <HYDROData_Image.h>
29 #include <HYDROData_Document.h>
33 HYDROGUI_ShapeImage::HYDROGUI_ShapeImage( const Handle(AIS_InteractiveContext)& theContext,
34 const Handle_HYDROData_Image& theImage,
36 : HYDROGUI_Shape( theContext, theImage, theZLayer )
40 HYDROGUI_ShapeImage::~HYDROGUI_ShapeImage()
44 void HYDROGUI_ShapeImage::update( bool theIsUpdateViewer, bool isDeactivateSelection )
46 setIsToUpdate( false );
50 HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection );
53 Handle(AIS_InteractiveObject) HYDROGUI_ShapeImage::createShape() const
55 Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( getObject() );
56 if ( anImageObj.IsNull() )
57 return Handle_AIS_InteractiveObject();
59 Handle(HYDROGUI_ImagePrs) aPrs = new HYDROGUI_ImagePrs( imagePixMap( anImageObj ), imageContour( anImageObj ) );
63 Handle(Image_PixMap) HYDROGUI_ShapeImage::imagePixMap( const Handle(HYDROData_Image)& theImageObj ) const
65 Handle(Image_PixMap) aPix;
66 if ( !theImageObj.IsNull() )
68 QTransform aTrsf = theImageObj->Trsf();
69 QImage anImage = theImageObj->Image();
70 // anImage = anImage.transformed( QTransform::fromScale( -1, -1 ) * aTrsf, Qt::SmoothTransformation );
72 if ( !anImage.isNull() )
74 // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813
75 int aTrsfWidth = anImage.width();
76 int aDelta = aTrsfWidth % 4;
78 aTrsfWidth += ( 4 - aDelta );
80 anImage = anImage.scaledToWidth( aTrsfWidth );
82 aPix = HYDROGUI_Tool::Pixmap( anImage );
88 QPolygonF HYDROGUI_ShapeImage::imageContour( const Handle_HYDROData_Image& theImageObj ) const
91 if ( !theImageObj.IsNull() )
93 QTransform aTrsf = theImageObj->Trsf();
94 QImage anImage = theImageObj->Image();
96 QPolygonF aPolygon = QPolygonF() << QPointF( 0, 0 ) << QPointF( anImage.width(), 0 )
97 << QPointF( anImage.width(), anImage.height() ) << QPointF( 0, anImage.height() );
98 aPolygon = aTrsf.map( aPolygon );
100 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( theImageObj->Label() );
101 for ( QPolygonF::iterator it = aPolygon.begin(); it != aPolygon.end(); ++it )
103 gp_Pnt aPnt( (*it).x(), (*it).y(), 0 );
104 aDoc->Transform( aPnt, true );
105 aContour.append( QPointF( aPnt.X(), aPnt.Y() ) );