7 #include "scene2D/adaptor/SGrid2D.hpp" 9 #include <fwCom/Slots.hxx> 11 #include <fwRenderQt/data/InitQtPen.hpp> 12 #include <fwRenderQt/Scene2DGraphicsView.hpp> 14 #include <fwServices/macros.hpp> 16 #include <QGraphicsItemGroup> 27 const ::fwCom::Slots::SlotKeyType SGrid2D::s_SET_GRID_SPACING_SLOT =
"setGridSpacing";
40 newSlot(s_SET_GRID_SPACING_SLOT, &::scene2D::adaptor::SGrid2D::setGridSpacing,
this);
55 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
57 SLM_ASSERT(
"Attribute 'xMin' is missing", config.count(
"xMin"));
58 SLM_ASSERT(
"Attribute 'xMax' is missing", config.count(
"xMax"));
59 SLM_ASSERT(
"Attribute 'yMin' is missing", config.count(
"yMin"));
60 SLM_ASSERT(
"Attribute 'yMax' is missing", config.count(
"yMax"));
63 m_xMin = config.get<
float>(
"xMin");
64 m_xMax = config.get<
float>(
"xMax");
65 m_yMin = config.get<
float>(
"yMin");
66 m_yMax = config.get<
float>(
"yMax");
70 if (config.count(
"xSpacing"))
72 m_xSpacing = config.get<
float>(
"xSpacing");
75 if (config.count(
"ySpacing"))
77 m_ySpacing = config.get<
float>(
"ySpacing");
80 if (config.count(
"color"))
90 SLM_ASSERT(
"m_xSpacing can not be equal to 0", m_xSpacing != 0.f);
91 SLM_ASSERT(
"m_ySpacing can not be equal to 0", m_ySpacing != 0.f);
94 for (
const auto& line : m_lines)
102 m_layer =
new QGraphicsItemGroup();
105 const float xStartVal = getXStartVal();
106 const float xEndVal = getXEndVal();
109 const float yStartVal = getYStartVal();
110 const float yEndVal = getYEndVal();
116 for (
float yVal = yStartVal; yVal <= yEndVal; yVal += m_ySpacing )
121 QGraphicsLineItem* line =
new QGraphicsLineItem(coord1.first, coord1.second, coord2.first, coord2.second);
125 m_lines.push_back(line);
129 for (
float xVal = xStartVal; xVal <= xEndVal; xVal += m_xSpacing )
134 QGraphicsLineItem* line =
new QGraphicsLineItem(coord1.first, coord1.second, coord2.first, coord2.second);
138 m_lines.push_back(line);
142 for (
unsigned int i = 0; i < m_lines.size(); i++)
144 m_layer->addToGroup(m_lines.at(i));
160 m_layer =
new QGraphicsItemGroup();
163 m_pen.setStyle(Qt::DashLine);
164 m_pen.setCosmetic(
true);
171 float SGrid2D::getXStartVal()
173 return (
int)( m_xMin / m_xSpacing ) * m_xSpacing;
178 float SGrid2D::getXEndVal()
180 return (
int)( m_xMax / m_xSpacing ) * m_xSpacing;
185 float SGrid2D::getYStartVal()
187 return (
int)( m_yMin / m_ySpacing ) * m_ySpacing;
192 float SGrid2D::getYEndVal()
194 return (
int)( m_yMax / m_ySpacing ) * m_ySpacing;
199 void SGrid2D::setGridSpacing(
double _x,
double _y, std::string _key)
201 if(_key ==
"spacing")
203 m_xSpacing =
static_cast<float>(_x);
204 m_ySpacing =
static_cast<float>(_y);
220 if( _event.getType() == ::fwRenderQt::data::Event::Resize)
Root class for all scene2d adaptors.
::fwRenderQt::data::Axis::sptr m_xAxis
The x Axis.
SCENE2D_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
SCENE2D_API void configuring() override
Configure the service before starting. Apply the configuration to service.
SCENE2D_API void starting() override
Initialize the layer, set the pen style to DashLine and call the draw() function. ...
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.
Render grid on the scene2d.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
::fwRenderQt::data::Axis::sptr m_yAxis
The y Axis.
float m_opacity
Opacity of the adaptor. Default value set to 1 (opaque).
virtual SCENE2D_API ~SGrid2D() noexcept
Basic destructor, do nothing.
FWRENDERQT_API void configureParams()
Parse the xml configuration for Axis, z value and opacity.
SCENE2D_API void stopping() override
Clean the lines vector and remove the layer from the scene.
SCENE2D_API SGrid2D() noexcept
Constructor, set the x and y spacing to 10.
This class manage events on the scene 2D (mouse event, keyboard event , ...).
SCENE2D_API void processInteraction(::fwRenderQt::data::Event &_event) override
Manage the given events.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.