7 #include "scene2D/adaptor/SAxis.hpp" 9 #include <fwRenderQt/data/InitQtPen.hpp> 11 #include <fwServices/macros.hpp> 13 #include <QGraphicsItemGroup> 23 static const ::fwServices::IService::KeyType s_VIEWPORT_INPUT =
"viewport";
25 SAxis::SAxis() noexcept :
39 SAxis::~SAxis() noexcept
64 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
67 if (config.count(
"color"))
73 m_align = config.get<std::string>(
"align");
74 SLM_ASSERT(
"'align' attribute is missing. Please add an 'align' attribute " 75 "with value 'left', 'right', 'top' or 'bottom'", !m_align.empty());
76 SLM_ASSERT(
"Unsupported value for 'align' attribute.",
77 m_align ==
"left" || m_align ==
"right" || m_align ==
"top" || m_align ==
"bottom");
80 SLM_ASSERT(
"'min' attribute is missing.", config.count(
"min"));
81 SLM_ASSERT(
"'max' attribute is missing.", config.count(
"max"));
82 m_min = config.get<
float>(
"min");
83 m_max = config.get<
float>(
"max");
86 m_tickSize = config.get<
float>(
"tickSize", 1.0f);
89 m_interval = config.get<
float>(
"interval", 1.0f);
94 void SAxis::buildAxis()
96 m_color.setCosmetic(
true);
97 const int nbValues = (m_max - m_min) / m_interval + 1;
98 m_layer =
new QGraphicsItemGroup();
100 for(
int i = 0; i < nbValues; ++i)
102 QGraphicsLineItem* tick =
new QGraphicsLineItem(0, 0, 0, 0);
103 tick->setCacheMode( QGraphicsItem::DeviceCoordinateCache );
104 tick->setPen( m_color );
106 m_ticks.push_back( tick );
107 m_layer->addToGroup( tick );
110 m_line =
new QGraphicsLineItem();
111 m_line->setCacheMode( QGraphicsItem::DeviceCoordinateCache );
112 m_line->setPen( m_color );
116 m_layer->addToGroup( m_line );
129 double SAxis::getStartVal()
131 return (
int)( m_min / m_interval ) * m_interval;
136 double SAxis::getEndVal()
138 return (
int)( m_max / m_interval ) * m_interval;
150 ::fwRenderQt::data::Viewport::sptr viewport = this->
getScene2DRender()->getViewport();
151 const double viewportHeight = viewport->getHeight();
152 const double viewportWidth = viewport->getWidth();
154 const double viewportSizeRatio = viewportHeight / viewportWidth;
159 double scaleX = m_tickSize;
160 double scaleY = m_tickSize * viewportSizeRatio;
161 scaleY /= viewportWidthRatio;
162 scaleY *= viewInitialSizeRatio;
164 scaleX = scaleX * ratio.first;
165 scaleY = scaleY * ratio.second;
167 const size_t nbValues = m_ticks.size();
169 const double min = this->getStartVal();
170 const double max = this->getEndVal();
179 if(m_align ==
"bottom")
183 const double tickPosY = viewport->getY();
185 for(
int i = 0; i < nbValues; ++i)
187 pos = min + i * m_interval;
189 m_ticks.at(i)->setLine(
190 tickPos.first, tickPos.second,
191 tickPos.first, tickPos.second - tickSize.second * scaleY);
194 m_line->setLine(min, tickPos.second, max, tickPos.second);
196 else if(m_align ==
"top")
200 const double tickPosY = viewport->getHeight() * 0.9;
202 for(
int i = 0; i < nbValues; ++i)
204 pos = min + i * m_interval;
207 m_ticks.at(i)->setLine(
208 tickPos.first, tickPos.second,
209 tickPos.first, tickPos.second - tickSize.second * scaleY);
212 m_line->setLine(min, tickPos.second, max, tickPos.second);
214 else if(m_align ==
"left")
218 const double tickPosX = viewport->getX();
220 for(
int i = 0; i < nbValues; ++i)
222 pos = min + i * m_interval;
224 m_ticks.at(i)->setLine(
225 tickPos.first, tickPos.second,
226 tickPos.first + tickSize.first * scaleX, tickPos.second);
229 m_line->setLine( tickPos.first, min, tickPos.first, tickPos.second);
231 else if(m_align ==
"right")
235 const double tickPosX = viewport->getX() + viewport->getWidth();
237 for(
int i = 0; i < nbValues; ++i)
239 pos = min + i * m_interval;
243 m_ticks.at(i)->setLine(
244 tickPos.first - tickSize.first * scaleX, tickPos.second,
245 tickPos.first, tickPos.second);
248 m_line->setLine(tickPos.first, min, tickPos.first, tickPos.second);
256 if( _event.getType() == ::fwRenderQt::data::Event::Resize)
Root class for all scene2d adaptors.
void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
::fwRenderQt::data::Axis::sptr m_xAxis
The x Axis.
SCENE2D_API void processInteraction(::fwRenderQt::data::Event &_event) override
Manage the given events.
This class is a helper to define the connections of a service and its data.
SCENE2D_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated objects signals, this method is used for obj...
std::pair< float, float > Scene2DRatio
<width, height>
FWRENDERQT_API void initializeViewSize()
Initialize the source values used for computing view's size ratio.
ViewSizeRatio m_viewInitialSize
FWRENDERQT_API Point2DType mapAdaptorToScene(const Point2DType &_xy, const ::fwRenderQt::data::Axis::sptr &_xAxis, const ::fwRenderQt::data::Axis::sptr &_yAxis) const
FWRENDERQT_API std::shared_ptr< ::fwRenderQt::SRender > getScene2DRender() const
Get the render that manages the IAdaptor.
std::pair< double, double > Point2DType
Point2D coordinate <X, Y>
static FWRENDERQT_API void setPenColor(QPen &_pen, std::string _color)
Set a pen a color.
This bundles contains data and services used to display a 2D Qt scene.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWRENDERQT_API void initializeViewportSize()
Initialize the source values used for computing viewport's size ratio.
::fwRenderQt::data::Axis::sptr m_yAxis
The y Axis.
void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
FWRENDERQT_API ViewportSizeRatio getViewportSizeRatio() const
Return the ratio between viewport's initial size and its current size.
FWRENDERQT_API void configureParams()
Parse the xml configuration for Axis, z value and opacity.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
void configuring() override
Configure the service before starting. Apply the configuration to service.
This class manage events on the scene 2D (mouse event, keyboard event , ...).
void starting() override
Initialize the service activity.
Render an axis on the scene2d.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.