]> SALOME platform Git repositories - samples/light.git/blob - src/LIGHTGUI/LIGHTGUI_TextPrs.cxx
Salome HOME
Copyright update: 2016
[samples/light.git] / src / LIGHTGUI / LIGHTGUI_TextPrs.cxx
1 // Copyright (C) 2005-2016  OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File   : LIGHTGUI_TextPrs.cxx
20 // Author : Natalia DONIS
21
22 #include "LIGHTGUI_TextPrs.h"
23
24 #include <Graphic3d_ArrayOfPoints.hxx>
25 #include <Graphic3d_Group.hxx>
26 #include <Graphic3d_Vertex.hxx>
27 #include <Prs3d_Root.hxx>
28 #include <Select3D_SensitivePoint.hxx>
29 #include <SelectMgr_EntityOwner.hxx>
30 #include <SelectMgr_Selection.hxx>
31
32 /*!
33   \class LIGHTGUI_TextPrs
34   \brief Presentation object for the string line.
35
36   This class is used to display a text line in the OCC 3D viewer.
37 */
38
39 IMPLEMENT_STANDARD_HANDLE( LIGHTGUI_TextPrs, AIS_InteractiveObject )
40 IMPLEMENT_STANDARD_RTTIEXT( LIGHTGUI_TextPrs, AIS_InteractiveObject )
41
42 const Standard_Integer aCharSize = 16;
43
44 /*!
45   \brief Contructor.
46   \param theString text string
47   \param thePos text position in the viewer
48 */
49 LIGHTGUI_TextPrs::LIGHTGUI_TextPrs( const char* theString, const gp_Pnt& thePos )
50 : myPos( thePos )
51 {
52   myString = new char[strlen( theString ) + 1];
53   strcpy( myString, theString );
54 }
55
56 /*!
57   \brief Destructor.
58 */
59 LIGHTGUI_TextPrs::~LIGHTGUI_TextPrs()
60 {
61   delete myString;
62 }
63
64 /*!
65   \brief Get presentation text size.
66 */
67 int LIGHTGUI_TextPrs::TextSize()
68 {
69   return aCharSize;
70 }
71
72 /*!
73   \brief Compute the presentation.
74   \param prsMgr presentation manager (not used)
75   \param thePrs presentation
76   \param mode display mode
77 */
78 void LIGHTGUI_TextPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& /*prsMgr*/,
79                                 const Handle(Prs3d_Presentation)& thePrs,
80                                 const Standard_Integer /*mode*/ )
81 {
82   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( thePrs );
83   Graphic3d_Vertex aTextPos;
84   aTextPos.SetCoord( myPos.X(), myPos.Y(), myPos.Z() );
85   Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
86   anArrayOfPoints->AddVertex(myPos.X(), myPos.Y(), myPos.Z());
87   aGroup->AddPrimitiveArray(anArrayOfPoints);
88   aGroup->Text( myString, aTextPos, aCharSize );
89 }
90
91 /*!
92   \brief Compute selection of the presentation.
93   \param theSelection current selection object
94   \param mode display mode
95 */
96 void LIGHTGUI_TextPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
97                                          const Standard_Integer /*mode*/ )
98 {
99   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
100   eown -> SelectBasics_EntityOwner::Set( aCharSize );
101   Handle(Select3D_SensitivePoint) seg = new Select3D_SensitivePoint(eown, myPos);
102   theSelection->Add(seg);
103 }