1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROGUI_ShapeImage.h>
21 #include <HYDROGUI_Tool.h>
22 #include <HYDROGUI_ImagePrs.h>
24 #include <HYDROData_Image.h>
25 #include <HYDROData_Document.h>
29 HYDROGUI_ShapeImage::HYDROGUI_ShapeImage( const Handle(AIS_InteractiveContext)& theContext,
30 const Handle(HYDROData_Image)& theImage,
32 : HYDROGUI_Shape( theContext, theImage, theZLayer )
36 HYDROGUI_ShapeImage::~HYDROGUI_ShapeImage()
40 void HYDROGUI_ShapeImage::update( bool theIsUpdateViewer, bool isDeactivateSelection )
42 setIsToUpdate( false );
46 HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection );
49 QList<Handle(AIS_InteractiveObject)> HYDROGUI_ShapeImage::createShape() const
51 QList<Handle(AIS_InteractiveObject)> shapes;
53 Handle(HYDROGUI_ImagePrs) aPrs;
55 Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( getObject() );
56 if ( !anImageObj.IsNull() )
58 aPrs = new HYDROGUI_ImagePrs( imagePixMap( anImageObj ), imageContour( anImageObj ) );
59 shapes.append( aPrs );
65 Handle(Image_PixMap) HYDROGUI_ShapeImage::imagePixMap( const Handle(HYDROData_Image)& theImageObj ) const
67 Handle(Image_PixMap) aPix;
68 if ( !theImageObj.IsNull() )
70 QTransform aTrsf = theImageObj->Trsf();
71 QImage anImage = theImageObj->Image();
72 // anImage = anImage.transformed( QTransform::fromScale( -1, -1 ) * aTrsf, Qt::SmoothTransformation );
74 if ( !anImage.isNull() )
76 // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813
77 int aTrsfWidth = anImage.width();
78 int aDelta = aTrsfWidth % 4;
80 aTrsfWidth += ( 4 - aDelta );
82 anImage = anImage.scaledToWidth( aTrsfWidth );
84 aPix = HYDROGUI_Tool::Pixmap( anImage );
90 QPolygonF HYDROGUI_ShapeImage::imageContour( const Handle(HYDROData_Image)& theImageObj ) const
93 if ( !theImageObj.IsNull() )
95 QTransform aTrsf = theImageObj->Trsf();
96 QImage anImage = theImageObj->Image();
98 QPolygonF aPolygon = QPolygonF() << QPointF( 0, 0 ) << QPointF( anImage.width(), 0 )
99 << QPointF( anImage.width(), anImage.height() ) << QPointF( 0, anImage.height() );
100 aPolygon = aTrsf.map( aPolygon );
102 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( theImageObj->Label() );
103 for ( QPolygonF::iterator it = aPolygon.begin(); it != aPolygon.end(); ++it )
105 gp_Pnt aPnt( (*it).x(), (*it).y(), 0 );
106 aDoc->Transform( aPnt, true );
107 aContour.append( QPointF( aPnt.X(), aPnt.Y() ) );