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_TYPE(HYDROGUI_ImagePrs)
37 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY()
38 STANDARD_TYPE(AIS_InteractiveObject),
39 STANDARD_TYPE(SelectMgr_SelectableObject),
40 STANDARD_TYPE(PrsMgr_PresentableObject),
41 STANDARD_TYPE(MMgt_TShared),
42 STANDARD_TYPE(Standard_Transient),
43 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END()
44 IMPLEMENT_STANDARD_TYPE_END(HYDROGUI_ImagePrs)
46 IMPLEMENT_DOWNCAST(HYDROGUI_ImagePrs,Standard_Transient)
47 IMPLEMENT_STANDARD_RTTI(HYDROGUI_ImagePrs)
49 HYDROGUI_ImagePrs::HYDROGUI_ImagePrs()
50 : AIS_InteractiveObject()
54 HYDROGUI_ImagePrs::HYDROGUI_ImagePrs( const Handle(Image_PixMap)& theImage, const QPolygonF& theContour )
55 : AIS_InteractiveObject(),
57 myContour( theContour )
61 HYDROGUI_ImagePrs::~HYDROGUI_ImagePrs()
65 QPolygonF HYDROGUI_ImagePrs::GetContour() const
70 void HYDROGUI_ImagePrs::SetContour( const QPolygonF& theRect )
72 if ( myContour != theRect )
78 Handle(Image_PixMap) HYDROGUI_ImagePrs::GetImage() const
83 void HYDROGUI_ImagePrs::SetImage( const Handle(Image_PixMap)& theImage )
85 if ( myImage != theImage )
91 void HYDROGUI_ImagePrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection, const Standard_Integer theMode )
93 if ( myContour.isEmpty() )
98 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner( this );
100 TColgp_Array1OfPnt aPoints( 0, myContour.size() - 1 );
101 for ( int i = 0; i < myContour.size(); i++ )
102 aPoints.SetValue( aPoints.Lower() + i, convert( myContour[i] ) );
104 Handle(Select3D_SensitiveFace) aSensitiveFace = new Select3D_SensitiveFace( anOwner, aPoints, Select3D_TOS_INTERIOR );
105 theSelection->Add( aSensitiveFace );
109 void HYDROGUI_ImagePrs::Compute( const Handle(PrsMgr_PresentationManager3d)&,
110 const Handle(Prs3d_Presentation)& aPrs,
111 const Standard_Integer aMode )
114 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aPrs );
118 Handle(Graphic3d_ArrayOfPolylines) aSegments = new Graphic3d_ArrayOfPolylines( 5 );
119 aSegments->AddVertex( convert( myContour[0] ) );
120 aSegments->AddVertex( convert( myContour[1] ) );
121 aSegments->AddVertex( convert( myContour[2] ) );
122 aSegments->AddVertex( convert( myContour[3] ) );
123 aSegments->AddVertex( convert( myContour[0] ) );
125 aGroup->AddPrimitiveArray( aSegments );
129 Graphic3d_MaterialAspect aMat( Graphic3d_NOM_PLASTIC );
130 Handle(Graphic3d_AspectFillArea3d) aFillAspect =
131 new Graphic3d_AspectFillArea3d( Aspect_IS_SOLID, Quantity_NOC_WHITE, Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0, aMat, aMat );
133 Handle(Graphic3d_TextureMap) aTex = new Graphic3d_Texture2Dmanual( myImage );
134 aTex->DisableModulate();
135 aFillAspect->SetTextureMapOn();
136 aFillAspect->SetTextureMap( aTex );
138 aGroup->SetGroupPrimitivesAspect( aFillAspect );
140 Handle(Graphic3d_ArrayOfTriangles) aTriangles = new Graphic3d_ArrayOfTriangles( 6, 0, Standard_False, Standard_False, Standard_True );
142 aTriangles->AddVertex( convert( myContour[0] ), gp_Pnt2d( 0, myImage->IsTopDown() ? 0 : 1 ) );
143 aTriangles->AddVertex( convert( myContour[1] ), gp_Pnt2d( 1, myImage->IsTopDown() ? 0 : 1 ) );
144 aTriangles->AddVertex( convert( myContour[2] ), gp_Pnt2d( 1, myImage->IsTopDown() ? 1 : 0 ) );
146 aTriangles->AddVertex( convert( myContour[2] ), gp_Pnt2d( 1, myImage->IsTopDown() ? 1 : 0 ) );
147 aTriangles->AddVertex( convert( myContour[3] ), gp_Pnt2d( 0, myImage->IsTopDown() ? 1 : 0 ) );
148 aTriangles->AddVertex( convert( myContour[0] ), gp_Pnt2d( 0, myImage->IsTopDown() ? 0 : 1 ) );
150 aGroup->AddPrimitiveArray( aTriangles );
154 gp_Pnt HYDROGUI_ImagePrs::convert( const QPointF& thePoint ) const
156 return gp_Pnt( thePoint.x(), thePoint.y(), 0 );