7 #include "uiReconstructionQt/RepresentationEditor.hpp" 9 #include <fwCom/Signal.hxx> 11 #include <fwData/Material.hpp> 12 #include <fwData/Mesh.hpp> 13 #include <fwData/Reconstruction.hpp> 15 #include <fwGuiQt/container/QtContainer.hpp> 17 #include <fwRuntime/operations.hpp> 19 #include <fwServices/macros.hpp> 20 #include <fwServices/op/Get.hpp> 22 #include <QAbstractButton> 23 #include <QButtonGroup> 25 #include <QRadioButton> 26 #include <QVBoxLayout> 36 static const ::fwServices::IService::KeyType s_RECONSTRUCTION_INOUT =
"reconstruction";
56 ::fwGuiQt::container::QtContainer::sptr qtContainer = ::fwGuiQt::container::QtContainer::dynamicCast(
57 this->getContainer() );
59 QVBoxLayout* layout =
new QVBoxLayout();
61 QGroupBox* groupBox =
new QGroupBox(tr(
"Representation"));
62 QVBoxLayout* layoutGroupBox =
new QVBoxLayout();
63 groupBox->setLayout(layoutGroupBox);
65 m_buttonGroup =
new QButtonGroup(groupBox);
67 QRadioButton* buttonSurface =
new QRadioButton( tr(
"Surface"), groupBox );
68 buttonSurface->setMinimumSize(buttonSurface->sizeHint());
69 m_buttonGroup->addButton(buttonSurface, 0);
70 layoutGroupBox->addWidget(buttonSurface);
71 buttonSurface->setChecked(
true);
73 QRadioButton* buttonPoint =
new QRadioButton( tr(
"Point"), groupBox );
74 buttonPoint->setMinimumSize(buttonPoint->sizeHint());
75 m_buttonGroup->addButton(buttonPoint, 1);
76 layoutGroupBox->addWidget(buttonPoint);
78 QRadioButton* buttonWireframe =
new QRadioButton( tr(
"Wireframe"), groupBox );
79 buttonWireframe->setMinimumSize(buttonWireframe->sizeHint());
80 m_buttonGroup->addButton(buttonWireframe, 2);
81 layoutGroupBox->addWidget(buttonWireframe);
83 QRadioButton* buttonEdge =
new QRadioButton( tr(
"Edge"), groupBox );
84 buttonEdge->setMinimumSize(buttonEdge->sizeHint());
85 m_buttonGroup->addButton(buttonEdge, 3);
86 layoutGroupBox->addWidget(buttonEdge);
89 QGroupBox* groupBoxShading =
new QGroupBox(tr(
"Shading"));
90 QVBoxLayout* layoutGroupBoxShading =
new QVBoxLayout();
91 groupBoxShading->setLayout(layoutGroupBoxShading);
92 m_buttonGroupShading =
new QButtonGroup(groupBoxShading);
94 QRadioButton* buttonAmbient =
new QRadioButton( tr(
"Ambient"), groupBoxShading );
95 buttonAmbient->setMinimumSize(buttonAmbient->sizeHint());
96 m_buttonGroupShading->addButton(buttonAmbient, 0);
97 layoutGroupBoxShading->addWidget(buttonAmbient);
98 buttonAmbient->setChecked(
true);
100 QRadioButton* buttonFlat =
new QRadioButton( tr(
"Flat"), groupBoxShading );
101 buttonFlat->setMinimumSize(buttonFlat->sizeHint());
102 m_buttonGroupShading->addButton(buttonFlat, 1);
103 layoutGroupBoxShading->addWidget(buttonFlat);
104 buttonFlat->setChecked(
true);
106 QRadioButton* buttonGouraud =
new QRadioButton( tr(
"Gouraud"), groupBoxShading );
107 buttonGouraud->setMinimumSize(buttonGouraud->sizeHint());
108 m_buttonGroupShading->addButton(buttonGouraud, 2);
109 layoutGroupBoxShading->addWidget(buttonGouraud);
111 QRadioButton* buttonPhong =
new QRadioButton( tr(
"Phong"), groupBoxShading );
112 buttonPhong->setMinimumSize(buttonPhong->sizeHint());
113 m_buttonGroupShading->addButton(buttonPhong, 3);
114 layoutGroupBoxShading->addWidget(buttonPhong);
116 layout->addWidget( groupBox);
117 layout->addWidget( groupBoxShading);
119 QGroupBox* groupBoxNormals =
new QGroupBox(tr(
"Normals"));
120 QVBoxLayout* layoutGroupBoxNormals =
new QVBoxLayout(groupBoxNormals);
121 m_normalsRadioBox =
new QButtonGroup();
122 QRadioButton* pointNormalsButton =
new QRadioButton(tr(
"Show point normals"));
123 QRadioButton* cellNormalsButton =
new QRadioButton(tr(
"Show cell normals"));
124 QRadioButton* hideNormalsButton =
new QRadioButton(tr(
"Hide normals"));
126 m_normalsRadioBox->addButton(pointNormalsButton, 1);
127 m_normalsRadioBox->addButton(cellNormalsButton, 2);
128 m_normalsRadioBox->addButton(hideNormalsButton, 0);
130 layoutGroupBoxNormals->addWidget( pointNormalsButton);
131 layoutGroupBoxNormals->addWidget( cellNormalsButton);
132 layoutGroupBoxNormals->addWidget( hideNormalsButton);
134 layout->addWidget(groupBoxNormals);
136 QObject::connect(m_normalsRadioBox, SIGNAL(buttonClicked(
int)),
this, SLOT(onShowNormals(
int)));
138 qtContainer->setLayout( layout );
139 qtContainer->setEnabled(
false);
141 QObject::connect(m_buttonGroup, SIGNAL(buttonClicked(
int)),
this, SLOT(onChangeRepresentation(
int)));
142 QObject::connect(m_buttonGroupShading, SIGNAL(buttonClicked(
int)),
this, SLOT(onChangeShading(
int)));
153 QObject::disconnect(m_buttonGroup, SIGNAL(buttonClicked(
int)),
this, SLOT(onChangeRepresentation(
int)));
154 QObject::disconnect(m_buttonGroupShading, SIGNAL(buttonClicked(
int)),
this, SLOT(onChangeShading(
int)));
156 QObject::connect(m_normalsRadioBox, SIGNAL(buttonClicked(
int)),
this, SLOT(onShowNormals(
int)));
173 ::fwData::Reconstruction::sptr reconstruction = this->getInOut< ::fwData::Reconstruction >(s_RECONSTRUCTION_INOUT);
177 reconstruction = this->getObject< ::fwData::Reconstruction >();
179 SLM_ASSERT(
"No Reconstruction!", reconstruction);
180 ::fwGuiQt::container::QtContainer::sptr qtContainer = ::fwGuiQt::container::QtContainer::dynamicCast(
181 this->getContainer() );
182 QWidget*
const container = qtContainer->getQtContainer();
183 SLM_ASSERT(
"container not instanced", container);
185 m_material = reconstruction->getMaterial();
186 container->setEnabled(!reconstruction->getOrganName().empty());
188 this->refreshRepresentation();
189 this->refreshNormals();
190 this->refreshShading();
195 void RepresentationEditor::onChangeRepresentation(
int id )
204 selectedMode = ::fwData::Material::SURFACE;
209 selectedMode = ::fwData::Material::POINT;
214 selectedMode = ::fwData::Material::WIREFRAME;
219 selectedMode = ::fwData::Material::EDGE;
224 m_material->setRepresentationMode( selectedMode );
230 void RepresentationEditor::onChangeShading(
int id )
238 selectedMode = ::fwData::Material::AMBIENT;
243 selectedMode = ::fwData::Material::FLAT;
248 selectedMode = ::fwData::Material::GOURAUD;
253 selectedMode = ::fwData::Material::PHONG;
258 m_material->setShadingMode( selectedMode );
264 void RepresentationEditor::refreshRepresentation()
266 int representationMode = m_material->getRepresentationMode();
267 QAbstractButton* button;
269 switch(representationMode)
271 case ::fwData::Material::SURFACE:
273 button = m_buttonGroup->button(0);
274 button->setChecked(
true);
277 case ::fwData::Material::POINT:
279 button = m_buttonGroup->button(1);
280 button->setChecked(
true);
283 case ::fwData::Material::WIREFRAME:
285 button = m_buttonGroup->button(2);
286 button->setChecked(
true);
289 case ::fwData::Material::EDGE:
291 button = m_buttonGroup->button(3);
292 button->setChecked(
true);
296 button = m_buttonGroup->button(0);
297 button->setChecked(
true);
303 void RepresentationEditor::refreshShading()
305 int shadingMode = m_material->getShadingMode();
306 QAbstractButton* button;
310 case ::fwData::Material::AMBIENT:
312 button = m_buttonGroupShading->button(0);
313 button->setChecked(
true);
316 case ::fwData::Material::FLAT:
318 button = m_buttonGroupShading->button(1);
319 button->setChecked(
true);
322 case ::fwData::Material::GOURAUD:
324 button = m_buttonGroupShading->button(2);
325 button->setChecked(
true);
328 case ::fwData::Material::PHONG:
330 button = m_buttonGroupShading->button(3);
331 button->setChecked(
true);
335 button = m_buttonGroupShading->button(2);
336 button->setChecked(
true);
342 void RepresentationEditor::refreshNormals()
344 QAbstractButton* buttonHide = m_normalsRadioBox->button(0);
345 buttonHide->setChecked(m_material->getOptionsMode() == ::fwData::Material::STANDARD);
346 QAbstractButton* buttonNormals = m_normalsRadioBox->button(1);
347 buttonNormals->setChecked(m_material->getOptionsMode() == ::fwData::Material::NORMALS);
352 void RepresentationEditor::onShowNormals(
int state )
354 ::fwData::Reconstruction::sptr reconstruction = this->getInOut< ::fwData::Reconstruction >(s_RECONSTRUCTION_INOUT);
358 reconstruction = this->getObject< ::fwData::Reconstruction >();
360 SLM_ASSERT(
"No Reconstruction!", reconstruction);
365 m_material->setOptionsMode( ::fwData::Material::STANDARD );
368 m_material->setOptionsMode( ::fwData::Material::NORMALS );
371 m_material->setOptionsMode( ::fwData::Material::CELLS_NORMALS );
380 sig->asyncEmit(reconstruction->getMesh());
387 ::fwData::Reconstruction::sptr reconstruction = this->getInOut< ::fwData::Reconstruction >(s_RECONSTRUCTION_INOUT);
391 reconstruction = this->getObject< ::fwData::Reconstruction >();
393 SLM_ASSERT(
"No Reconstruction!", reconstruction);
395 ::fwData::Object::ModifiedSignalType::sptr sig;
408 if (this->getInOut< ::fwData::Reconstruction >(s_RECONSTRUCTION_INOUT))
virtual void updating() override
Update the UI according to the reconstruction.
#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.
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.
Defines the service interface managing the editor service for object.
FWGUI_API void destroy()
Stops sub-views and toobar services. Destroys view, sub-views and toolbar containers.
UIRECONSTRUCTIONQT_API RepresentationEditor() noexcept
Constructor. Do nothing.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MESH_CHANGED_SIG
Key in m_signals map of signal m_sigMeshModified.
virtual void configuring() override
Do nothing.
virtual void stopping() override
Clean the UI.
#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.
Display a widget to change the reconstruction representation (surface, point, edge, ...).
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
virtual void starting() override
Initialize the UI.
virtual KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
void notifyMaterial()
Notify the changes.
RepresentationType
Representation models.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
ShadingType
Shading models.
virtual UIRECONSTRUCTIONQT_API ~RepresentationEditor() noexcept
Destructor. Do nothing.
FWGUI_API void initialize()
Initialize managers.