33 #include <boost/property_tree/detail/ptree_implementation.hpp>
34 #include <boost/property_tree/detail/xml_parser_error.hpp>
36 #include <QCloseEvent>
37 #include <QDockWidget>
38 #include <QFileDialog>
39 #include <QGraphicsItem>
41 #include <QMessageBox>
58 m_current_path(QDir().homePath().toStdString()),
59 m_actions(new
EditorActions(this, m_graphics_view, m_ptree_panels, m_undo_stack)),
62 setWindowTitle(
"simPT - Tissue Editor");
63 setMenuBar(m_actions);
64 setMinimumSize(800, 600);
69 connect(m_graphics_view, SIGNAL(ItemsSelected(
unsigned int)),
70 m_actions, SLOT(ItemsSelected(
unsigned int)));
71 connect(m_graphics_view, SIGNAL(ModeChanged()), m_actions, SLOT(ModeChanged()));
76 void TissueEditor::closeEvent(QCloseEvent* event)
87 if (e->mimeData()->hasUrls() ) {
88 if (e->mimeData()->urls().size()==1) {
89 const QString &fileName = e->mimeData()->urls().first().toLocalFile();
91 e->acceptProposedAction();
98 if (e->mimeData()->urls().size()==1) {
99 const QString &fileName = e->mimeData()->urls().first().toLocalFile();
104 bool TissueEditor::CloseLeaf()
109 void TissueEditor::CreateLayout()
111 m_graphics_view->setHidden(
true);
112 setCentralWidget(m_graphics_view);
121 m_status_info =
new QLabel(
"");
122 statusBar()->addWidget(m_status_info);
125 void TissueEditor::GenerateRegularPattern()
127 m_actions->
Show(
false);
129 m_actions->
Show(
true);
132 void TissueEditor::GenerateVoronoiPattern()
134 m_actions->
Show(
false);
136 m_actions->
Show(
true);
139 void TissueEditor::InternalForceClose()
145 m_graphics_view->setHidden(
true);
151 m_status_info->setText(
"");
154 bool TissueEditor::InternalIsClean()
const
159 bool TissueEditor::InternalSave()
167 return (m_tissue !=
nullptr);
170 void TissueEditor::NewLeaf()
173 m_actions->
Show(
false);
175 string fileName = QFileDialog::getOpenFileName(
this,
176 "Select a template file with the attributes of the new tissue",
177 QString::fromStdString(m_current_path),
"XML files (*.xml *.xml.gz);;All files (*.*)",
178 nullptr, QFileDialog::DontUseNativeDialog | QFileDialog::ReadOnly).toStdString();
179 m_actions->
Show(
true);
181 if (fileName !=
"") {
182 if (m_tissue !=
nullptr) {
186 if (PTreeFile::IsGzipped(fileName)){
187 PTreeFile::ReadXmlGz(fileName, m_ptree);
189 PTreeFile::ReadXml(fileName, m_ptree);
192 if (m_ptree.find(
"vleaf2") == m_ptree.not_found()
193 || m_ptree.get_child(
"vleaf2").find(
"mesh") == m_ptree.not_found()
194 || m_ptree.get_child(
"vleaf2.mesh").find(
"cells") == m_ptree.not_found()
195 || m_ptree.get_child(
"vleaf2.mesh.cells").find(
"chemical_count") == m_ptree.not_found()) {
197 QMessageBox messageBox(
this);
198 messageBox.critical(
this,
"Invalid ptree error",
"Property tree doesn't contain valid sim data.");
201 m_tissue = std::make_shared<EditControlLogic>(
202 m_ptree.get<
unsigned int>(
"vleaf2.mesh.cells.chemical_count"));
203 m_ptree.get_child(
"vleaf2.mesh").clear();
205 m_undo_stack->
Initialize(m_tissue->ToPTree());
208 connect(m_tissue.get(), SIGNAL(Moved(Node*,
double,
double)),
209 this, SLOT(SetModifiedWithoutUndo()));
210 connect(m_tissue.get(), SIGNAL(Modified()),
this, SLOT(SetModified()));
211 connect(m_tissue.get(), SIGNAL(Modified()), m_actions, SLOT(Modified()));
212 connect(m_tissue.get(), SIGNAL(StatusInfoChanged(
const std::string&)),
213 this, SLOT(SetStatusBar(
const std::string&)));
215 m_current_path = fileName;
220 catch (boost::property_tree::xml_parser::xml_parser_error& e) {
221 QMessageBox messageBox(
this);
222 messageBox.critical(
this,
"XML parsing error",
"Sim data file doesn't contain valid property tree.");
226 void TissueEditor::OpenLeaf()
229 m_actions->
Show(
false);
231 string fileName = QFileDialog::getOpenFileName(
this,
232 "Open sim data file", QString::fromStdString(m_current_path),
233 "XML files (*.xml *.xml.gz);;All files (*.*)",
nullptr,
234 QFileDialog::DontUseNativeDialog | QFileDialog::ReadOnly).toStdString();
235 m_actions->
Show(
true);
239 catch (boost::property_tree::xml_parser::xml_parser_error& e) {
240 QMessageBox messageBox(
this);
241 messageBox.critical(
this,
"XML parsing error",
"Sim data file doesn't contain a valid property tree.");
243 catch (boost::property_tree::ptree_error& e) {
244 QMessageBox messageBox(
this);
245 messageBox.critical(
this,
"Invalid ptree error",
"Property tree doesn't contain sim data.");
253 if (m_tissue !=
nullptr) {
256 if (PTreeFile::IsGzipped(path)){
257 PTreeFile::ReadXmlGz(path, m_ptree);
259 PTreeFile::ReadXml(path, m_ptree);
262 m_tissue = make_shared<EditControlLogic>(m_ptree.get_child(
"vleaf2"));
264 m_undo_stack->
Initialize(m_tissue->ToPTree());
267 connect(m_tissue.get(), SIGNAL(Moved(
Node*,
double,
double)),
268 this, SLOT(SetModifiedWithoutUndo()));
269 connect(m_tissue.get(), SIGNAL(Modified()),
this, SLOT(SetModified()));
270 connect(m_tissue.get(), SIGNAL(Modified()), m_actions, SLOT(Modified()));
271 connect(m_tissue.get(), SIGNAL(StatusInfoChanged(
const std::string&)),
272 this, SLOT(SetStatusBar(
const std::string&)));
274 m_current_path = path;
280 catch (boost::property_tree::xml_parser::xml_parser_error& e) {
281 QMessageBox messageBox(
this);
282 messageBox.critical(
this,
"XML parsing error",
"Sim data file doesn't contain a valid property tree.");
284 catch (boost::property_tree::ptree_error& e) {
285 QMessageBox messageBox(
this);
286 messageBox.critical(
this,
"Invalid ptree error",
"Property tree doesn't contain valid sim data.");
288 catch (std::runtime_error& e) {
289 QMessageBox messageBox(
this);
290 messageBox.critical(
this,
"File not found",
"File doesn't exist.");
296 void TissueEditor::Redo()
298 assert(m_undo_stack->
CanRedo() &&
"Tried to redo when it can't be done.");
300 m_tissue = std::make_shared<EditControlLogic>(m_undo_stack->
Redo());
301 connect(m_tissue.get(), SIGNAL(Moved(
Node*,
double,
double)),
302 this, SLOT(SetModifiedWithoutUndo()));
303 connect(m_tissue.get(), SIGNAL(Modified()),
this, SLOT(SetModified()));
304 connect(m_tissue.get(), SIGNAL(Modified()), m_actions, SLOT(Modified()));
305 connect(m_tissue.get(), SIGNAL(StatusInfoChanged(
const std::string&)),
306 this, SLOT(SetStatusBar(
const std::string&)));
310 m_graphics_view->
SetMode(mode);
315 void TissueEditor::SaveLeaf()
317 m_actions->
Show(
false);
319 string fileName = QFileDialog::getSaveFileName(
this,
320 "Save sim data file", QString::fromStdString(m_current_path),
321 "XML files (*.xml *.xml.gz);;All files (*.*)",
nullptr,
322 QFileDialog::DontUseNativeDialog).toStdString();
323 m_actions->
Show(
true);
325 if (fileName !=
"") {
326 boost::property_tree::ptree pt = m_tissue->ToPTree();
327 m_ptree.put_child(
"vleaf2.mesh", pt.get_child(
"mesh"));
328 m_ptree.put_child(
"vleaf2.parameters", pt.get_child(
"parameters"));
329 if (PTreeFile::IsGzipped(fileName)){
330 PTreeFile::WriteXmlGz(fileName, m_ptree);
332 PTreeFile::WriteXml(fileName, m_ptree);
336 m_current_path = fileName;
341 void TissueEditor::SetCellMode()
343 if (m_graphics_view->
GetMode() == Mode::CELL) {
344 m_graphics_view->
SetMode(Mode::DISPLAY);
346 m_graphics_view->
SetMode(Mode::CELL);
350 void TissueEditor::SetEdgeMode()
352 if (m_graphics_view->
GetMode() == Mode::EDGE) {
353 m_graphics_view->
SetMode(Mode::DISPLAY);
355 m_graphics_view->
SetMode(Mode::EDGE);
359 void TissueEditor::SetNodeMode()
361 if (m_graphics_view->
GetMode() == Mode::NODE) {
362 m_graphics_view->
SetMode(Mode::DISPLAY);
364 m_graphics_view->
SetMode(Mode::NODE);
368 void TissueEditor::SetStatusBar(
const std::string& info)
370 m_status_info->setText(QString::fromStdString(info));
373 void TissueEditor::SetModified()
375 m_undo_stack->
Push(m_tissue->ToPTree());
379 void TissueEditor::SetModifiedWithoutUndo()
384 void TissueEditor::Undo()
386 assert(m_undo_stack->
CanUndo() &&
"Tried to undo when it can't be done.");
388 m_tissue = std::make_shared<EditControlLogic>(m_undo_stack->
Undo());
389 connect(m_tissue.get(), SIGNAL(Moved(Node*,
double,
double)),
390 this, SLOT(SetModifiedWithoutUndo()));
391 connect(m_tissue.get(), SIGNAL(Modified()),
this, SLOT(SetModified()));
392 connect(m_tissue.get(), SIGNAL(Modified()), m_actions, SLOT(Modified()));
393 connect(m_tissue.get(), SIGNAL(StatusInfoChanged(
const std::string&)),
394 this, SLOT(SetStatusBar(
const std::string&)));
398 m_graphics_view->
SetMode(mode);
403 void TissueEditor::UpdateViews()
405 assert(m_tissue !=
nullptr &&
"The tissue isn't initialized.");
409 m_graphics_view->setHidden(
false);
const boost::property_tree::ptree & Redo()
Redo an action.
void Cleanup()
Cleans the scene.
void dragEnterEvent(QDragEnterEvent *e)
Receive a message when something is dragged over the window.
Namespace for SimPT tissue editor package.
void Push(const boost::property_tree::ptree &tissue)
Push a tissue to the stack.
Namespace for miscellaneous utilities.
The graphical view on the tissue.
HasUnsavedChanges with the ability of displaying a "save-discard-cancel" dialog to the user before cl...
Mode
Different modes for the graphicsview.
Interface for PTreePanels.
Interface for the TissueEditor.
void Initialize(const boost::property_tree::ptree &tissue)
Initialize the undo stack with a given tissue.
Gui::PTreeContainer * ParametersPanel() const
Get the parameters panel.
virtual ~TissueEditor()
Destructor.
Namespace for graphical interface classes.
virtual bool IsOpened() const
True if tissue has been opened, false otherwise.
Interface for EditorActions.
const boost::property_tree::ptree & Undo()
Undo an action.
void Show(bool visible)
Show or hide the menubar.
bool OpenPath(const std::string &path)
True iff file has been successfully opened (if another file is open, it is closed first)...
void GenerateRegularPattern()
Generates a regular cell pattern in the selected cell.
bool PromptClose(QWidget *parent=nullptr)
Display dialog window containing a list (or tree) of widgets that contain unsaved changes...
Undo Stack for actions performed on a tissue.
Manages the attribute and geometric ptree panel for a given tissue.
TissueEditor(QWidget *parent=nullptr)
Constructor with the parent of the window.
void SetColorComponent(const boost::property_tree::ptree ¶meters)
Set the colorizer map for coloring the cells in 'NONE'-mode.
QDockWidget * GetDock() const
Get the associated dock widget, containing the ptree editor.
see the online Qt documentation
Interface for GraphicsView of tissue.
static bool IsPTreeFile(const std::string &path)
Indicates whether the file has the appropriate extension.
void Initialize(std::shared_ptr< EditControlLogic > tissue)
Initializes the panels with a given tissue.
ProjectController header.
bool CanUndo() const
True if the current action can be undone.
void LeafOpened()
A tissue has been opened.
see the online Qt documentation
void LeafClosed()
The tissue has been closed.
The actions in the menu bar of the workspace.
void SetMode(Mode mode)
Set the editing mode of the view.
void Modified()
The tissue has been modified.
void dropEvent(QDropEvent *e)
Recive a message when a file is dropped on the window.
void GenerateVoronoiPattern()
Generates a cell pattern using Voronoi Tesselation in the selected cell.
Gui::PTreeContainer * AttributePanel() const
Get the attribute panel.
bool CanRedo() const
True if the current action can be redone.
Mode GetMode() const
Returns the current mode.
Interface for LeafControlLogic.
void Initialize(std::shared_ptr< EditControlLogic > tissue, Mode mode=Mode::DISPLAY)
Adds the items in the tissue to the scene.
Gui::PTreeContainer * GeometricPanel() const
Get the geometric panel.
Interface for PTreeContainer.