]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkText2D.cxx
#3485 New box AddStringToVector
[bbtk.git] / packages / vtk / src / bbvtkText2D.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbvtkText2D.h"
5 #include "bbvtkPackage.h"
6
7 #include "vtkTextProperty.h"
8
9 namespace bbvtk
10 {
11
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,Text2D)
13 BBTK_BLACK_BOX_IMPLEMENTATION(Text2D,bbtk::AtomicBlackBox);
14 //===== 
15 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
16 //===== 
17 void Text2D::Process()
18 {
19
20 // THE MAIN PROCESSING METHOD BODY
21 //   Here we simply set the input 'In' value to the output 'Out'
22 //   And print out the output value
23 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
24 //    void bbSet{Input|Output}NAME(const TYPE&)
25 //    const TYPE& bbGet{Input|Output}NAME() const 
26 //    Where :
27 //    * NAME is the name of the input/output
28 //      (the one provided in the attribute 'name' of the tag 'input')
29 //    * TYPE is the C++ type of the input/output
30 //      (the one provided in the attribute 'type' of the tag 'input')
31
32 //    bbSetOutputOut( bbGetInputIn() );
33 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
34   
35
36  if (_textActor==NULL)
37  { 
38    _textActor = vtkTextActor::New();
39    _textActor->GetPositionCoordinate()->SetCoordinateSystemToWorld();
40
41 //   _textActor->GetPositionCoordinate()->SetCoordinateSystemToDisplay ();
42 //   _textActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedDisplay ();
43 //   _textActor->GetPositionCoordinate()->SetCoordinateSystemToViewport ();
44 //   _textActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport ();
45 //   _textActor->GetPositionCoordinate()->SetCoordinateSystemToView ();
46 //   _textActor->GetPositionCoordinate()->SetCoordinateSystemToWorld ();
47
48
49    if (bbGetInputRenderer()!=NULL)
50    {
51       bbGetInputRenderer()->AddActor2D(_textActor);
52    }
53  }
54
55  _textActor->SetInput(bbGetInputIn().c_str());
56
57 // textActor->SetTextScaleModeToProp();
58 // textActor->SetDisplayPosition(90, 50);
59 // textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
60
61  double px=0;
62  double py=0;
63  double spx=1;
64  double spy=1;
65  if (bbGetInputPoint().size()>=2)
66  {
67     px=bbGetInputPoint()[0];
68     py=bbGetInputPoint()[1];
69         
70     if (bbGetInputSpacing().size()>=2)
71     {
72         spx=bbGetInputSpacing()[0];
73         spy=bbGetInputSpacing()[1];
74     }    
75
76  }
77 // _textActor->SetTextScaleModeToProp();
78  _textActor->SetPosition( px*spx , py*spy );
79
80 // _textActor->SetPosition( 150,150 );
81 // _textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
82 // _textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
83 // textActor->GetPosition2Coordinate()->SetValue(0.6, 0.1);
84
85     vtkTextProperty *tprop = _textActor->GetTextProperty();
86     tprop->SetFontSize( bbGetInputFontSize() );
87     tprop->SetFontFamilyToArial();
88     tprop->SetJustificationToCentered();
89     if (bbGetInputFontBold()==true) tprop->BoldOn(); else tprop->BoldOff();
90     if (bbGetInputFontItalic()==true) tprop->ItalicOn(); else tprop->ItalicOff();
91     if (bbGetInputFontShadow()==true) tprop->ShadowOn(); else tprop->ShadowOff();
92     if (bbGetInputColor().size()>=3)
93     {
94         tprop->SetColor( bbGetInputColor()[0] , bbGetInputColor()[1] , bbGetInputColor()[2] );
95     }
96     tprop->SetOpacity( bbGetInputOpacity() );
97   
98 }
99 //===== 
100 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
101 //===== 
102 void Text2D::bbUserSetDefaultValues()
103 {
104 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
105 //    Here we initialize the input 'In' to 0
106     _textActor=NULL;
107     bbSetInputIn("VOID");
108     bbSetInputOpacity(1);
109     bbSetInputFontSize(14);
110     bbSetInputFontBold(false);
111     bbSetInputFontItalic(false);
112     bbSetInputFontShadow(false);
113     std::vector<double> spc;
114     spc.push_back(1);
115     spc.push_back(1);
116     spc.push_back(1);
117     bbSetInputSpacing(spc);
118     std::vector<double> color;
119     color.push_back(0);
120     color.push_back(0);
121     color.push_back(1);
122     bbSetInputColor(color);
123     bbSetInputRenderer(NULL);
124 }
125 //===== 
126 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
127 //===== 
128 void Text2D::bbUserInitializeProcessing()
129 {
130
131 //  THE INITIALIZATION METHOD BODY :
132 //    Here does nothing 
133 //    but this is where you should allocate the internal/output pointers 
134 //    if any 
135
136   
137 }
138 //===== 
139 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
140 //===== 
141 void Text2D::bbUserFinalizeProcessing()
142 {
143
144 //  THE FINALIZATION METHOD BODY :
145 //    Here does nothing 
146 //    but this is where you should desallocate the internal/output pointers 
147 //    if any
148   
149 }
150 }
151 // EO namespace bbvtk
152
153