7 #include "uiReconstructionQt/OrganMaterialEditor.hpp" 9 #include <fwCore/base.hpp> 11 #include <fwData/Material.hpp> 12 #include <fwData/Mesh.hpp> 13 #include <fwData/Reconstruction.hpp> 15 #include <fwGuiQt/container/QtContainer.hpp> 17 #include <fwRuntime/ConfigurationElement.hpp> 18 #include <fwRuntime/operations.hpp> 20 #include <fwServices/IService.hpp> 21 #include <fwServices/macros.hpp> 22 #include <fwServices/op/Get.hpp> 25 #include <QColorDialog> 26 #include <QHBoxLayout> 29 #include <QPushButton> 32 #include <QVBoxLayout> 40 static const ::fwServices::IService::KeyType s_RECONSTRUCTION_INOUT =
"reconstruction";
59 ::fwGuiQt::container::QtContainer::sptr qtContainer
60 = ::fwGuiQt::container::QtContainer::dynamicCast(this->getContainer() );
62 m_colourButton =
new QPushButton(tr(
"Color"));
63 m_colourButton->setToolTip(tr(
"Selected organ's color"));
64 m_colourButton->setMinimumSize(m_colourButton->sizeHint());
66 QLabel* transparencyLabel =
new QLabel(tr(
"Transparency : "));
67 m_opacitySlider =
new QSlider( Qt::Horizontal);
68 m_opacitySlider->setToolTip(tr(
"Selected organ's opacity"));
69 m_opacitySlider->setRange(0, 100);
70 m_opacitySlider->setTickInterval(20);
71 m_opacitySlider->setTickPosition(QSlider::TicksBelow);
72 m_opacitySlider->setMinimumSize(m_opacitySlider->sizeHint());
74 m_transparencyValue =
new QLabel(
"");
75 m_transparencyValue->setMinimumSize(m_transparencyValue->sizeHint());
77 QVBoxLayout* layout =
new QVBoxLayout();
78 layout->addWidget( m_colourButton, 0 );
80 QHBoxLayout* transparencyLayout =
new QHBoxLayout( );
81 transparencyLayout->addWidget( transparencyLabel, 0);
82 transparencyLayout->addWidget( m_opacitySlider, 1 );
83 transparencyLayout->addWidget( m_transparencyValue, 0);
84 layout->addLayout( transparencyLayout, 0);
86 qtContainer->setLayout( layout );
87 qtContainer->setEnabled(
false);
89 QObject::connect(m_opacitySlider, SIGNAL(valueChanged(
int)),
this, SLOT(onOpacitySlider(
int)));
90 QObject::connect(m_colourButton, SIGNAL(clicked()),
this, SLOT(onColorButton()));
101 QObject::disconnect(m_opacitySlider, SIGNAL(valueChanged(
int)),
this, SLOT(onOpacitySlider(
int)));
102 QObject::disconnect(m_colourButton, SIGNAL(clicked()),
this, SLOT(onColorButton()));
124 void OrganMaterialEditor::onColorButton()
126 ::fwData::Reconstruction::sptr reconstruction = this->getInOut< ::fwData::Reconstruction >(s_RECONSTRUCTION_INOUT);
130 reconstruction = this->getObject< ::fwData::Reconstruction >();
132 SLM_ASSERT(
"No Reconstruction!", reconstruction);
134 ::fwData::Material::sptr material = reconstruction->getMaterial();
135 int red = material->diffuse()->red()*255;
136 int green = material->diffuse()->green()*255;
137 int blue = material->diffuse()->blue()*255;
140 ::fwGuiQt::container::QtContainer::sptr qtContainer = ::fwGuiQt::container::QtContainer::dynamicCast(
141 this->getContainer() );
142 QWidget*
const container = qtContainer->getQtContainer();
143 SLM_ASSERT(
"container not instanced", container);
145 QColor oldColor(red, green, blue);
146 QColor color = QColorDialog::getColor(oldColor, container);
149 material->diffuse()->red() = color.redF();
150 material->diffuse()->green() = color.greenF();
151 material->diffuse()->blue() = color.blueF();
160 void OrganMaterialEditor::onOpacitySlider(
int value )
162 ::fwData::Reconstruction::sptr reconstruction = this->getInOut< ::fwData::Reconstruction >(s_RECONSTRUCTION_INOUT);
166 reconstruction = this->getObject< ::fwData::Reconstruction >();
168 SLM_ASSERT(
"No Reconstruction!", reconstruction);
170 ::fwData::Material::sptr material = reconstruction->getMaterial();
171 material->diffuse()->alpha() = value/100.0;
172 std::stringstream ss;
174 m_transparencyValue->setText(QString::fromStdString(ss.str()));
183 ::fwData::Reconstruction::csptr reconstruction = this->getInOut< ::fwData::Reconstruction >(s_RECONSTRUCTION_INOUT);
187 reconstruction = this->getObject< ::fwData::Reconstruction >();
189 SLM_ASSERT(
"No Reconstruction!", reconstruction);
191 ::fwGuiQt::container::QtContainer::sptr qtContainer = ::fwGuiQt::container::QtContainer::dynamicCast(
192 this->getContainer() );
193 QWidget*
const container = qtContainer->getQtContainer();
194 SLM_ASSERT(
"container not instanced", container);
196 container->setEnabled(!reconstruction->getOrganName().empty());
198 ::fwData::Material::csptr material = reconstruction->getMaterial();
199 QColor materialColor = QColor(
200 material->diffuse()->red()*255,
201 material->diffuse()->green()*255,
202 material->diffuse()->blue()*255,
203 material->diffuse()->alpha()*255
206 int iconSize = m_colourButton->style()->pixelMetric(QStyle::PM_LargeIconSize);
207 QPixmap pix(iconSize, iconSize);
208 pix.fill(materialColor);
210 m_colourButton->setIcon(QIcon(pix));
212 int a = material->diffuse()->alpha()*100;
213 m_opacitySlider->setValue( a );
214 std::stringstream ss;
216 m_transparencyValue->setText(QString::fromStdString(ss.str()));
223 ::fwData::Reconstruction::csptr reconstruction = this->getInOut< ::fwData::Reconstruction >(s_RECONSTRUCTION_INOUT);
227 reconstruction = this->getObject< ::fwData::Reconstruction >();
229 SLM_ASSERT(
"No Reconstruction!", reconstruction);
231 ::fwData::Object::ModifiedSignalType::sptr sig;
244 if (this->getInOut< ::fwData::Reconstruction >(s_RECONSTRUCTION_INOUT))
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
This class is a helper to define the connections of a service and its data.
virtual KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
The namespace uiReconstructionQt contains several editors using Qt related on reconstruction.
This class defines a reconstruction object.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
virtual void stopping() override
Clean the UI.
Defines the service interface managing the editor service for object.
virtual void starting() override
Initialize the UI.
FWGUI_API void destroy()
Stops sub-views and toobar services. Destroys view, sub-views and toolbar containers.
virtual void updating() override
Update the UI according to the material (color and transparency widgets)
void materialNotification()
Notify the material changes.
virtual UIRECONSTRUCTIONQT_API ~OrganMaterialEditor() noexcept
Destructor. Do nothing.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWGUI_API void create()
Creates view, sub-views and toolbar containers. Manages sub-views and toobar services.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
virtual void configuring() override
Do nothing.
UIRECONSTRUCTIONQT_API OrganMaterialEditor() noexcept
Constructor. Do nothing.
Display a widget to change the reconstruction material (color and transparency).
void refreshMaterial()
Update the UI according to the material (color and transparency widgets)
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
FWGUI_API void initialize()
Initialize managers.