NorMIT-nav  22.09
An IGT application
cxDisplayTextRep.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 #include "cxDisplayTextRep.h"
14 
15 #include <vtkRenderer.h>
16 #include <vtkActor2D.h>
17 #include <vtkTextProperty.h>
18 #include <vtkTextMapper.h>
19 
20 #include "cxView.h"
21 #include "cxVtkHelperClasses.h"
22 #include "cxTypeConversions.h"
23 
24 namespace cx
25 {
26 
28  RepImpl("")
29 {
30 }
31 
33 {
34 
35 }
37 {
38  return wrap_new(new DisplayTextRep(), uid);
39 }
41 {
42  for(unsigned i =0; i<mDisplayText.size(); ++i)
43  mDisplayText[i]->setRenderer(view->getRenderer());
44 }
45 
47 {
48  for(unsigned i =0; i<mDisplayText.size(); ++i)
49  mDisplayText[i]->setRenderer(NULL);
50 }
51 
55 TextDisplayPtr DisplayTextRep::addText(const QColor& color, const QString& text, const Vector3D& pos, int maxWidth, vtkViewport *vp)
56 {
57 // Vector3D c = color;
58  TextDisplayPtr textRep;
59  textRep.reset( new TextDisplay( text, color, 20) );
60  textRep->getActor()->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
61  textRep->setPosition(pos);
62  textRep->textProperty()->SetJustificationToLeft();
63  if( pos[0]>0.5 )
64  {
65  textRep->textProperty()->SetJustificationToRight();
66  }
67  textRep->textProperty()->SetVerticalJustificationToBottom();
68  if (pos[1] > 0.5)
69  {
70  textRep->textProperty()->SetVerticalJustificationToTop();
71  }
72 
73  textRep->setRenderer(this->getRenderer());
74 
75  //textRep->setCentered();
76  mDisplayText.push_back( textRep );
77 
78  if (maxWidth != 0 && vp)
79  {
80  textRep->setMaxWidth(maxWidth, vp);
81  }
82  return textRep;
83 }
84 
88 void DisplayTextRep::setText(unsigned i, const QString& text)
89 {
90  if (i<mDisplayText.size())
91  mDisplayText[i]->updateText(text);
92 }
93 
97 void DisplayTextRep::setColor(const QColor& color )
98 {
99  for(unsigned i =0; i<mDisplayText.size(); ++i)
100  {
101  mDisplayText.at(i)->textProperty()->SetColor(getColorAsVector3D(color).begin()) ;
102  }
103 
104 }
105 
107 {
108  for(unsigned i =0; i<mDisplayText.size(); ++i)
109  {
110  mDisplayText.at(i)->textProperty()->SetFontSize(size) ;
111  if (size != mDisplayText[i]->textProperty()->GetFontSize())
112  mDisplayText.at(i)->textProperty()->SetFontSize(size) ;
113  }
114 }
115 
116 //-----------------------------------------------------------------------
117 }//end namespace
118 //-----------------------------------------------------------------------
cx::DisplayTextRep::New
static DisplayTextRepPtr New(const QString &uid="")
Definition: cxDisplayTextRep.cpp:36
cx::DisplayTextRep::setFontSize
void setFontSize(int size)
Definition: cxDisplayTextRep.cpp:106
cx::DisplayTextRep::setText
void setText(unsigned i, const QString &text)
Definition: cxDisplayTextRep.cpp:88
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::RepImpl::getRenderer
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:88
cxDisplayTextRep.h
begin
Scalar * begin()
Definition: cxPlainObjectEigenAddons.h:22
cx::TextDisplayPtr
boost::shared_ptr< class TextDisplay > TextDisplayPtr
Definition: cxForwardDeclarations.h:102
cx::DisplayTextRepPtr
boost::shared_ptr< class DisplayTextRep > DisplayTextRepPtr
Definition: cxForwardDeclarations.h:66
cx::getColorAsVector3D
Vector3D getColorAsVector3D(QColor color)
Definition: cxVtkHelperClasses.cpp:40
cx::DisplayTextRep::mDisplayText
std::vector< TextDisplayPtr > mDisplayText
Definition: cxDisplayTextRep.h:58
cx::DisplayTextRep::setColor
void setColor(const QColor &color)
Definition: cxDisplayTextRep.cpp:97
cxTypeConversions.h
cxView.h
cx::DisplayTextRep::addText
TextDisplayPtr addText(const QColor &color, const QString &text, const Vector3D &pos, int maxWidth=0, vtkViewport *vp=NULL)
Definition: cxDisplayTextRep.cpp:55
cx::DisplayTextRep::removeRepActorsFromViewRenderer
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxDisplayTextRep.cpp:46
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::RepImpl
Default implementation of Rep.
Definition: cxRepImpl.h:42
cx::DisplayTextRep::addRepActorsToViewRenderer
virtual void addRepActorsToViewRenderer(ViewPtr view)
Definition: cxDisplayTextRep.cpp:40
cxVtkHelperClasses.h
cx::DisplayTextRep::DisplayTextRep
DisplayTextRep()
Definition: cxDisplayTextRep.cpp:27
cx::RepImpl::wrap_new
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cx::TextDisplay
Helper for drawing text in 2D.
Definition: cxVtkHelperClasses.h:111
cx::DisplayTextRep::~DisplayTextRep
virtual ~DisplayTextRep()
Definition: cxDisplayTextRep.cpp:32