Salome HOME
Merge from BR_V5_DEV 17Feb09
[samples/light.git] / src / LIGHTGUI / LIGHTGUI_TextPrs.cxx
1 //  Copyright (C) 2005-2008  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.
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 // LIGHT : sample (no-corba-engine) SALOME module
20 // File   : LIGHTGUI_TextPrs.cxx
21 // Author : Natalia DONIS
22 //
23 #include "LIGHTGUI_TextPrs.hxx"
24
25 #include <Prs3d_Root.hxx>
26 #include <Graphic3d_Group.hxx>
27 #include <Graphic3d_Vertex.hxx>
28 #include <SelectMgr_Selection.hxx>
29 #include <SelectMgr_EntityOwner.hxx>
30 #include <Select3D_SensitivePoint.hxx>
31
32 /*!
33   \class LIGHTGUI_TextPrs
34   \brief Presentation object for the string line.
35 */
36
37 IMPLEMENT_STANDARD_HANDLE( LIGHTGUI_TextPrs, AIS_InteractiveObject )
38 IMPLEMENT_STANDARD_RTTIEXT( LIGHTGUI_TextPrs, AIS_InteractiveObject )
39
40 const Standard_Integer aCharSize = 16;
41
42 /*!
43   \brief Contructor.
44   \param theString text string
45   \param thePos text position in the viewer
46 */
47 LIGHTGUI_TextPrs::LIGHTGUI_TextPrs( const char* theString, const gp_Pnt& thePos )
48 : myPos( thePos )
49 {
50   myString = new char[strlen( theString ) + 1];
51   strcpy( myString, theString );
52 }
53
54 /*!
55   \brief Destructor.
56 */
57 LIGHTGUI_TextPrs::~LIGHTGUI_TextPrs()
58 {
59   delete myString;
60 }
61
62 /*!
63   \brief Get presentation text size.
64 */
65 int LIGHTGUI_TextPrs::TextSize()
66 {
67   return aCharSize;
68 }
69
70 /*!
71   \brief Compute the presentation.
72   \param prsMgr presentation manager (not used)
73   \param thePrs presentation
74   \param mode display mode
75 */
76 void LIGHTGUI_TextPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& /*prsMgr*/,
77                                 const Handle(Prs3d_Presentation)& thePrs,
78                                 const Standard_Integer /*mode*/ )
79 {
80   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( thePrs );
81   aGroup->BeginPrimitives();
82   Graphic3d_Vertex aTextPos;
83   //  aTextPos.SetCoord( myPos.X(), aPos.Y(), aPos.Z() );
84   aTextPos.SetCoord( myPos.X(), myPos.Y(), myPos.Z() );
85   aGroup->Marker( aTextPos );
86   //  aGroup->Text( aNodeIter.Value().ToCString(), aTextPos, aCharSize );
87   aGroup->Text( myString, aTextPos, aCharSize );
88   aGroup->EndPrimitives();
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   //  Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown, myPos, 
103   //                                myPos.Translated( gp_Vec( strlen( myString ) * aCharSize, 0, 0 ) ) );
104   theSelection->Add(seg);
105 }