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_ImagePrs.h"
21 #include <Prs3d_Root.hxx>
23 #include <SelectMgr_Selection.hxx>
24 #include <SelectMgr_EntityOwner.hxx>
25 #include <Select3D_SensitiveFace.hxx>
27 #include <Graphic3d_Group.hxx>
28 #include <Graphic3d_AspectLine3d.hxx>
29 #include <Graphic3d_Texture2Dmanual.hxx>
30 #include <Graphic3d_ArrayOfPolylines.hxx>
31 #include <Graphic3d_ArrayOfTriangles.hxx>
32 #include <Graphic3d_AspectFillArea3d.hxx>
34 #include <TColgp_Array1OfPnt.hxx>
36 IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_ImagePrs, AIS_InteractiveObject)
38 HYDROGUI_ImagePrs::HYDROGUI_ImagePrs()
39 : AIS_InteractiveObject()
43 HYDROGUI_ImagePrs::HYDROGUI_ImagePrs( const Handle(Image_PixMap)& theImage, const QPolygonF& theContour )
44 : AIS_InteractiveObject(),
46 myContour( theContour )
50 HYDROGUI_ImagePrs::~HYDROGUI_ImagePrs()
54 QPolygonF HYDROGUI_ImagePrs::GetContour() const
59 void HYDROGUI_ImagePrs::SetContour( const QPolygonF& theRect )
61 if ( myContour != theRect )
67 Handle(Image_PixMap) HYDROGUI_ImagePrs::GetImage() const
72 void HYDROGUI_ImagePrs::SetImage( const Handle(Image_PixMap)& theImage )
74 if ( myImage != theImage )
80 void HYDROGUI_ImagePrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection, const Standard_Integer theMode )
82 if ( myContour.isEmpty() )
87 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner( this );
89 TColgp_Array1OfPnt aPoints( 0, myContour.size() - 1 );
90 for ( int i = 0; i < myContour.size(); i++ )
91 aPoints.SetValue( aPoints.Lower() + i, convert( myContour[i] ) );
93 Handle(Select3D_SensitiveFace) aSensitiveFace = new Select3D_SensitiveFace( anOwner, aPoints, Select3D_TOS_INTERIOR );
94 theSelection->Add( aSensitiveFace );
98 void HYDROGUI_ImagePrs::Compute( const Handle(PrsMgr_PresentationManager3d)&,
99 const Handle(Prs3d_Presentation)& aPrs,
100 const Standard_Integer aMode )
103 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aPrs );
105 if( myImage.IsNull() )
110 Handle(Graphic3d_ArrayOfPolylines) aSegments = new Graphic3d_ArrayOfPolylines( 5 );
111 aSegments->AddVertex( convert( myContour[0] ) );
112 aSegments->AddVertex( convert( myContour[1] ) );
113 aSegments->AddVertex( convert( myContour[2] ) );
114 aSegments->AddVertex( convert( myContour[3] ) );
115 aSegments->AddVertex( convert( myContour[0] ) );
117 aGroup->AddPrimitiveArray( aSegments );
121 Graphic3d_MaterialAspect aMat( Graphic3d_NOM_PLASTIC );
122 Handle(Graphic3d_AspectFillArea3d) aFillAspect =
123 new Graphic3d_AspectFillArea3d( Aspect_IS_SOLID, Quantity_NOC_WHITE, Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0, aMat, aMat );
125 Handle(Graphic3d_TextureMap) aTex = new Graphic3d_Texture2Dmanual( myImage );
126 aTex->DisableModulate();
127 aFillAspect->SetTextureMapOn();
128 aFillAspect->SetTextureMap( aTex );
130 aGroup->SetGroupPrimitivesAspect( aFillAspect );
132 Handle(Graphic3d_ArrayOfTriangles) aTriangles = new Graphic3d_ArrayOfTriangles( 6, 0, Standard_False, Standard_False, Standard_True );
134 aTriangles->AddVertex( convert( myContour[0] ), gp_Pnt2d( 0, myImage->IsTopDown() ? 0 : 1 ) );
135 aTriangles->AddVertex( convert( myContour[1] ), gp_Pnt2d( 1, myImage->IsTopDown() ? 0 : 1 ) );
136 aTriangles->AddVertex( convert( myContour[2] ), gp_Pnt2d( 1, myImage->IsTopDown() ? 1 : 0 ) );
138 aTriangles->AddVertex( convert( myContour[2] ), gp_Pnt2d( 1, myImage->IsTopDown() ? 1 : 0 ) );
139 aTriangles->AddVertex( convert( myContour[3] ), gp_Pnt2d( 0, myImage->IsTopDown() ? 1 : 0 ) );
140 aTriangles->AddVertex( convert( myContour[0] ), gp_Pnt2d( 0, myImage->IsTopDown() ? 0 : 1 ) );
142 aGroup->AddPrimitiveArray( aTriangles );
146 gp_Pnt HYDROGUI_ImagePrs::convert( const QPointF& thePoint ) const
148 return gp_Pnt( thePoint.x(), thePoint.y(), 0 );