Salome HOME
Update copyrights 2014.
[samples/light.git] / src / LIGHTGUI / LIGHTGUI_TextPrs.cxx
1 // Copyright (C) 2005-2014  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
20 // LIGHT : sample (no-corba-engine) SALOME module
21 // File   : LIGHTGUI_TextPrs.cxx
22 // Author : Natalia DONIS
23 //
24 #include "LIGHTGUI_TextPrs.hxx"
25
26 #include <Prs3d_Root.hxx>
27 #include <Graphic3d_Group.hxx>
28 #include <Graphic3d_Vertex.hxx>
29 #include <SelectMgr_Selection.hxx>
30 #include <SelectMgr_EntityOwner.hxx>
31 #include <Select3D_SensitivePoint.hxx>
32
33 #include <Basics_OCCTVersion.hxx>
34
35 #if OCC_VERSION_LARGE > 0x060505
36 #include <Graphic3d_ArrayOfPoints.hxx>
37 #endif
38
39 /*!
40   \class LIGHTGUI_TextPrs
41   \brief Presentation object for the string line.
42 */
43
44 IMPLEMENT_STANDARD_HANDLE( LIGHTGUI_TextPrs, AIS_InteractiveObject )
45 IMPLEMENT_STANDARD_RTTIEXT( LIGHTGUI_TextPrs, AIS_InteractiveObject )
46
47 const Standard_Integer aCharSize = 16;
48
49 /*!
50   \brief Contructor.
51   \param theString text string
52   \param thePos text position in the viewer
53 */
54 LIGHTGUI_TextPrs::LIGHTGUI_TextPrs( const char* theString, const gp_Pnt& thePos )
55 : myPos( thePos )
56 {
57   myString = new char[strlen( theString ) + 1];
58   strcpy( myString, theString );
59 }
60
61 /*!
62   \brief Destructor.
63 */
64 LIGHTGUI_TextPrs::~LIGHTGUI_TextPrs()
65 {
66   delete myString;
67 }
68
69 /*!
70   \brief Get presentation text size.
71 */
72 int LIGHTGUI_TextPrs::TextSize()
73 {
74   return aCharSize;
75 }
76
77 /*!
78   \brief Compute the presentation.
79   \param prsMgr presentation manager (not used)
80   \param thePrs presentation
81   \param mode display mode
82 */
83 void LIGHTGUI_TextPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& /*prsMgr*/,
84                                 const Handle(Prs3d_Presentation)& thePrs,
85                                 const Standard_Integer /*mode*/ )
86 {
87   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( thePrs );
88 #if OCC_VERSION_LARGE <= 0x060504
89   aGroup->BeginPrimitives();
90 #endif
91   Graphic3d_Vertex aTextPos;
92   //  aTextPos.SetCoord( myPos.X(), aPos.Y(), aPos.Z() );
93   aTextPos.SetCoord( myPos.X(), myPos.Y(), myPos.Z() );
94 #if OCC_VERSION_LARGE <= 0x060505
95   aGroup->Marker( aTextPos );
96 #else
97   Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
98   anArrayOfPoints->AddVertex(myPos.X(), myPos.Y(), myPos.Z());
99   aGroup->AddPrimitiveArray(anArrayOfPoints);
100 #endif
101   //  aGroup->Text( aNodeIter.Value().ToCString(), aTextPos, aCharSize );
102   aGroup->Text( myString, aTextPos, aCharSize );
103 #if OCC_VERSION_LARGE <= 0x060504
104   aGroup->EndPrimitives();
105 #endif
106 }
107
108 /*!
109   \brief Compute selection of the presentation.
110   \param theSelection current selection object
111   \param mode display mode
112 */
113 void LIGHTGUI_TextPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
114                                          const Standard_Integer /*mode*/ )
115 {
116   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
117   eown -> SelectBasics_EntityOwner::Set( aCharSize );
118   Handle(Select3D_SensitivePoint) seg = new Select3D_SensitivePoint(eown, myPos);
119   //  Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown, myPos, 
120   //                                myPos.Translated( gp_Vec( strlen( myString ) * aCharSize, 0, 0 ) ) );
121   theSelection->Add(seg);
122 }