20 #include "../editor/PTreePanels.h"
27 #include <boost/lexical_cast.hpp>
28 #include <boost/property_tree/ptree.hpp>
30 #include <QDockWidget>
31 #include <QMessageBox>
40 : m_attribute_panel(new Gui::
PTreeContainer(
"Attribute panel", parent)),
41 m_attribute_panel_toggled(true),
42 m_geometric_panel(new Gui::
PTreeContainer(
"Geometric panel", parent)),
43 m_geometric_panel_toggled(true),
44 m_parameters_panel(new Gui::
PTreeContainer(
"Parameters panel", parent)),
45 m_parameters_panel_toggled(true)
47 connect(m_attribute_panel->
GetDock()->toggleViewAction(), SIGNAL(toggled(
bool)),
48 this, SLOT(ToggleAttributePanel(
bool)));
49 connect(m_geometric_panel->
GetDock()->toggleViewAction(), SIGNAL(toggled(
bool)),
50 this, SLOT(ToggleGeometricPanel(
bool)));
51 connect(m_parameters_panel->
GetDock()->toggleViewAction(), SIGNAL(toggled(
bool)),
52 this, SLOT(ToggleParametersPanel(
bool)));
54 connect(m_attribute_panel, SIGNAL(Applied(
const boost::property_tree::ptree&)),
55 this, SLOT(ApplyAttributePanel(
const boost::property_tree::ptree&)));
56 connect(m_geometric_panel, SIGNAL(Applied(
const boost::property_tree::ptree&)),
57 this, SLOT(ApplyGeometricPanel(
const boost::property_tree::ptree&)));
58 connect(m_parameters_panel, SIGNAL(Applied(
const boost::property_tree::ptree&)),
59 this, SLOT(ApplyParametersPanel(
const boost::property_tree::ptree&)));
67 void PTreePanels::ApplyAttributePanel(
const ptree& pt)
70 m_tissue->ChangeAttributes(pt);
73 QMessageBox messageBox(m_attribute_panel->
GetDock());
74 messageBox.critical(m_attribute_panel->
GetDock(),
75 "Attribute parsing error",
"This value isn't allowed for this attribute.");
76 UpdateAttributePanel();
80 void PTreePanels::ApplyGeometricPanel(
const ptree& pt)
83 if (m_tissue->SelectedNodes().size() == 1) {
84 if (!m_tissue->MoveNode(m_tissue->SelectedNodes().front(),
85 pt.get<
double>(
"x"), pt.get<
double>(
"y"))) {
86 UpdateGeometricPanel();
87 }
else if (m_tissue->SelectedNodes().front()->IsAtBoundary() != pt.get<
bool>(
"boundary")) {
88 UpdateGeometricPanel();
91 UpdateGeometricPanel();
94 catch (ptree_bad_data& e) {
95 QMessageBox messageBox(m_geometric_panel->
GetDock());
96 messageBox.critical(m_geometric_panel->
GetDock(),
97 "Geometry parsing error",
"This value isn't allowed for this property.");
98 UpdateGeometricPanel();
102 void PTreePanels::ApplyParametersPanel(
const ptree& pt)
104 m_tissue->SetParameters(pt);
109 return m_attribute_panel;
115 connect(m_tissue.get(), SIGNAL(SelectionChanged()),
this, SLOT(UpdatePanels()));
116 connect(m_tissue.get(), SIGNAL(StoppedMoving()),
this, SLOT(UpdateGeometricPanel()));
121 return m_geometric_panel;
124 ptree PTreePanels::MergeJoin(ptree pt1, ptree pt2)
127 if (pt1.data() != pt2.data()) {
130 pt = ptree(pt1.data());
133 if (pt1.size() == 0) {
136 ptree::const_iterator it1 = pt1.begin();
137 ptree::const_iterator it2 = pt2.begin();
138 while (it1 != pt1.end() && it2 != pt2.end()) {
139 if (it1->first == it2->first) {
140 pt.add_child(it1->first, MergeJoin(it1->second, it2->second));
144 else if (it1->first < it2->first) {
145 pt.add_child(it1->first, SetDataToUnknown(it1->second));
149 pt.add_child(it2->first, SetDataToUnknown(it2->second));
153 for (ptree::const_iterator it = it1; it != pt1.end(); ++it) {
154 pt.add_child(it->first, SetDataToUnknown(it->second));
156 for (ptree::const_iterator it = it2; it != pt2.end(); ++it) {
157 pt.add_child(it->first, SetDataToUnknown(it->second));
166 return m_parameters_panel;
169 ptree PTreePanels::SetDataToUnknown(
const ptree& pt)
172 for (
const auto& v : pt) {
173 new_pt.add_child(v.first, SetDataToUnknown(v.second));
178 void PTreePanels::ToggleAttributePanel(
bool toggled)
180 m_attribute_panel_toggled = toggled;
181 UpdateAttributePanel();
184 void PTreePanels::ToggleGeometricPanel(
bool toggled)
186 m_geometric_panel_toggled = toggled;
187 UpdateGeometricPanel();
190 void PTreePanels::ToggleParametersPanel(
bool toggled)
192 m_parameters_panel_toggled = toggled;
193 UpdateParametersPanel();
196 void PTreePanels::UpdateAttributePanel()
198 if (!m_attribute_panel_toggled) {
202 std::string title =
"Attribute panel";
203 if (m_tissue->SelectedNodes().size() > 0) {
204 auto nodes = m_tissue->SelectedNodes();
205 ptree pt = nodes.front()->ToPtree();
206 for (
auto it =
std::next(nodes.begin()); it != nodes.end(); ++it) {
207 pt = MergeJoin(pt, (*it)->ToPtree());
212 pt.erase(
"boundary");
213 m_attribute_panel->
Open(pt.get_child(
"attributes"));
215 if (nodes.size() == 1) {
217 + boost::lexical_cast<std::string>(nodes.front()->GetIndex());
221 }
else if (!m_tissue->SelectedWalls().empty()) {
222 auto walls = m_tissue->SelectedWalls();
223 ptree pt = walls.front()->WallAttributes::ToPtree();
224 for (
auto it =
std::next(walls.begin()); it != walls.end(); ++it) {
225 pt = MergeJoin(pt, (*it)->WallAttributes::ToPtree());
227 m_attribute_panel->
Open(pt);
229 if (walls.size() == 1) {
231 + boost::lexical_cast<std::string>(walls.front()->GetIndex());
235 }
else if (m_tissue->SelectedCells().size() > 0) {
236 auto cells = m_tissue->SelectedCells();
237 ptree pt = cells.front()->CellAttributes::ToPtree();
239 for (
auto it =
std::next(cells.begin()); it != cells.end(); ++it) {
240 pt = MergeJoin(pt, (*it)->CellAttributes::ToPtree());
242 m_attribute_panel->
Open(pt);
244 if (cells.size() == 1) {
246 + boost::lexical_cast<std::string>(cells.front()->GetIndex());
251 m_attribute_panel->
Open(m_tissue->ToPTree().get_child(
"mesh"));
254 m_attribute_panel->
GetDock()->setWindowTitle(QString::fromStdString(title));
257 void PTreePanels::UpdateGeometricPanel()
259 if (!m_geometric_panel_toggled) {
263 std::string title =
"Geometric panel";
264 if (m_tissue->SelectedNodes().size() > 0) {
265 auto nodes = m_tissue->SelectedNodes();
268 pt.add(
"x", (*nodes.front())[0]);
269 pt.add(
"y", (*nodes.front())[1]);
270 pt.add(
"boundary", nodes.front()->IsAtBoundary());
271 for (
auto it =
std::next(nodes.begin()); it != nodes.end(); ++it) {
272 ptree node_pt = (*it)->ToPtree();
273 if (pt.get<std::string>(
"x") !=
"?") {
274 if (pt.get<
double>(
"x") != node_pt.get<
double>(
"x")) {
278 if (pt.get<std::string>(
"y") !=
"?") {
279 if (pt.get<
double>(
"y") != node_pt.get<
double>(
"y")) {
283 if (pt.get<std::string>(
"boundary") !=
"?") {
284 if (pt.get<
bool>(
"boundary") != node_pt.get<
bool>(
"boundary")) {
285 pt.put(
"boundary",
"?");
289 m_geometric_panel->
Open(pt);
291 if (nodes.size() == 1) {
292 title +=
" - node " + boost::lexical_cast<std::string>(nodes.front()->GetIndex());
296 }
else if (m_tissue->SelectedWalls().size() > 0) {
297 auto walls = m_tissue->SelectedWalls();
299 ptree pt = walls.front()->ToPtree();
301 for (
auto it =
std::next(walls.begin()); it != walls.end(); ++it) {
302 pt = MergeJoin(pt, (*it)->ToPtree());
305 pt.erase(
"attributes");
306 m_geometric_panel->
Open(pt);
308 if (walls.size() == 1) {
309 title +=
" - wall " + boost::lexical_cast<std::string>(walls.front()->GetIndex());
314 }
else if (m_tissue->SelectedCells().size() > 0) {
315 auto cells = m_tissue->SelectedCells();
317 ptree pt = cells.front()->GeometryToPtree();
318 for (
auto it =
std::next(cells.begin()); it != cells.end(); ++it) {
319 pt = MergeJoin(pt, (*it)->GeometryToPtree());
322 m_geometric_panel->
Open(pt);
324 if (cells.size() == 1) {
325 title +=
" - cell " + boost::lexical_cast<std::string>(cells.front()->GetIndex());
331 m_geometric_panel->
Open(m_tissue->ToPTree().get_child(
"mesh"));
334 m_geometric_panel->
GetDock()->setWindowTitle(QString::fromStdString(title));
337 void PTreePanels::UpdateParametersPanel()
339 m_parameters_panel->
Open(m_tissue->GetParameters());
342 void PTreePanels::UpdatePanels()
344 UpdateAttributePanel();
345 UpdateGeometricPanel();
void SetOnlyEditData(bool)
If true, the user can't insert, move, delete or edit keys.
Namespace for SimPT tissue editor package.
Gui::PTreeContainer * ParametersPanel() const
Get the parameters panel.
Namespace for graphical interface classes.
bool Open(boost::property_tree::ptree const &pt, QString const &edit_path="")
Open ptree with given edit path.
Extremely simple Exception root class.
QDockWidget * GetDock() const
Get the associated dock widget, containing the ptree editor.
void Initialize(std::shared_ptr< EditControlLogic > tissue)
Initializes the panels with a given tissue.
see the online Qt documentation
virtual ~PTreePanels()
Destructor.
CircularIterator< T > next(CircularIterator< T > i)
Helper yields the position the iterator would have if moved forward (in circular fashion) by 1 positi...
Header file for Exception class.
Gui::PTreeContainer * AttributePanel() const
Get the attribute panel.
Namespace for generic graphical shell for simulators.
Gui::PTreeContainer * GeometricPanel() const
Get the geometric panel.
For a given ptree, constructs PTreeMenu, QDockWidget, PTreeEditorWindow.