7 #include "visuVTKAdaptor/SText.hpp" 9 #include <fwData/Color.hpp> 10 #include <fwData/GenericFieldBase.hpp> 12 #include <fwDataCamp/getObject.hpp> 14 #include <fwServices/macros.hpp> 16 #include <vtkActor2D.h> 17 #include <vtkTextMapper.h> 18 #include <vtkTextProperty.h> 25 static const ::fwServices::IService::KeyType s_OBJECT_IN =
"object";
28 m_actor(vtkActor2D::New()),
29 m_mapper(vtkTextMapper::New()),
31 m_fontFamily(
"courier"),
37 m_textColor(
"#ffffffff")
39 m_mapper->GetTextProperty()->SetFontFamilyToCourier();
40 m_mapper->GetTextProperty()->ShadowOn();
41 m_mapper->GetTextProperty()->BoldOn();
43 m_actor->SetMapper(m_mapper);
44 m_actor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
45 m_actor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
50 SText::~SText() noexcept
61 void SText::configuring()
63 this->configureParams();
65 const ConfigType srvconfig = this->getConfigTree();
66 const ConfigType config = srvconfig.get_child(
"config.<xmlattr>");
68 std::string text = config.get<std::string>(
"text",
"");
72 text = srvconfig.get<std::string>(
"text",
"");
74 else if(text[0] ==
'@')
84 m_fontSize = config.get<
unsigned int>(
"fontSize", 20);
85 m_fontFamily = config.get<std::string>(
"fontFamily",
"courier");
87 m_italic = config.get<
bool>(
"italic",
false);
88 m_bold = config.get<
bool>(
"bold",
false);
89 m_shadow = config.get<
bool>(
"shadow",
false);
91 m_hAlign = config.get<std::string>(
"hAlign",
"left");
92 SLM_ASSERT(
"'hAlign' value must be 'left', 'center' or 'right'",
94 || m_hAlign ==
"center" 95 || m_hAlign ==
"right" 98 m_vAlign = config.get<std::string>(
"vAlign",
"bottom");
99 SLM_ASSERT(
"'vAlign' value must be 'top', 'center' or 'bottom'",
101 || m_hAlign ==
"center" 102 || m_vAlign ==
"bottom");
104 m_textColor = config.get<std::string>(
"color",
"#ffffffff");
109 void SText::starting()
115 this->setText(m_text);
117 this->addToRenderer(m_actor);
118 this->requestRender();
123 void SText::updating()
126 this->setText(m_text);
128 this->requestRender();
133 void SText::stopping()
135 this->removeAllPropFromRenderer();
140 void SText::setAlignment()
142 vtkTextProperty* textprop = m_mapper->GetTextProperty();
147 textprop->SetJustificationToCentered();
148 textprop->SetVerticalJustificationToCentered();
150 if(m_hAlign ==
"left")
152 textprop->SetJustificationToLeft();
155 else if(m_hAlign ==
"right")
157 textprop->SetJustificationToRight();
161 if(m_vAlign ==
"top")
163 textprop->SetVerticalJustificationToTop();
166 else if(m_vAlign ==
"bottom")
168 textprop->SetVerticalJustificationToBottom();
172 m_actor->SetPosition(x, y);
177 void SText::setStyle()
179 vtkTextProperty* textprop = m_mapper->GetTextProperty();
181 textprop->SetFontSize(
int(m_fontSize) );
182 textprop->SetItalic(m_italic);
183 textprop->SetBold(m_bold);
184 textprop->SetShadow(m_shadow);
186 if( m_textColor[0] ==
'#')
188 ::fwData::Color::sptr color = ::fwData::Color::New();
189 color->setRGBA(m_textColor);
190 textprop->SetColor(color->getRGBA()[0], color->getRGBA()[1], color->getRGBA()[2]);
195 double color = std::stod(m_textColor);
196 textprop->SetColor(color, color, color);
199 if(m_fontFamily ==
"arial")
201 textprop->SetFontFamilyToArial();
203 else if(m_fontFamily ==
"courier")
205 textprop->SetFontFamilyToCourier();
207 else if(m_fontFamily ==
"times")
209 textprop->SetFontFamilyToTimes();
213 OSLM_FATAL(
"Unknown font family : '" << m_fontFamily <<
"'");
219 void SText::updateText()
221 ::fwData::Object::csptr obj = this->getInput< ::fwData::Object >(s_OBJECT_IN);
225 ::fwData::GenericFieldBase::csptr field;
229 field = ::fwData::GenericFieldBase::dynamicCast(obj);
233 field = ::fwDataCamp::getObject< ::fwData::GenericFieldBase >(obj, m_path);
238 m_text = field->toString();
245 void SText::setText(
const std::string& str)
248 m_mapper->SetInput(m_text.c_str());
249 this->setAlignment();
250 this->setVtkPipelineModified();
This class is a helper to define the connections of a service and its data.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
#define OSLM_FATAL(message)
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
Base class for VTK adaptors.