diff --git a/sources/diagramcontent.cpp b/sources/diagramcontent.cpp index 398013c83..3ea10715a 100644 --- a/sources/diagramcontent.cpp +++ b/sources/diagramcontent.cpp @@ -59,7 +59,15 @@ DiagramContent::DiagramContent(Diagram *diagram, bool selected) : { switch (item->type()) { - case Element::Type: { m_elements << qgraphicsitem_cast(item); break;} + case Element::Type: + { + auto element = qgraphicsitem_cast(item); + m_elements << element; + if (element->elementData().m_type == ElementData::Terminale) { + m_terminal_elements << static_cast(element); + } + break; + } case IndependentTextItem::Type: { m_text_fields << qgraphicsitem_cast(item); break;} case Conductor::Type: { diff --git a/sources/diagramcontent.h b/sources/diagramcontent.h index 1525fbedc..1eff2ed55 100644 --- a/sources/diagramcontent.h +++ b/sources/diagramcontent.h @@ -21,6 +21,8 @@ #include #include +#include "../qetgraphicsitem/terminalelement.h" + class QGraphicsItem; class Conductor; class Element; @@ -81,6 +83,7 @@ class DiagramContent QList m_selected_items; QVector m_tables; QVector m_terminal_strip; + QVector> m_terminal_elements; QList selectedTexts() const; diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 5e7c3982a..c94e92c91 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -1468,12 +1468,21 @@ void QETDiagramEditor::selectionGroupTriggered(QAction *action) if (!dv || value.isEmpty()) return; - if (value == "delete_selection") - { - diagram->clearSelection(); - diagram->undoStack().push(new DeleteQGraphicsItemCommand(diagram, dc)); - dv->adjustSceneRect(); - } + if (value == "delete_selection") + { + if (DeleteQGraphicsItemCommand::hasNonDeletableTerminal(dc)) { + QET::QetMessageBox::information(this, + tr("Suppression de borne impossible"), + tr("La suppression ne peut être effectué car la selection " + "possède une ou plusieurs bornes ponté et/ou appartenant à une borne à niveau multiple.\n" + "Déponter et/ou supprimer les niveaux des bornes concerné " + "afin de pouvoir les supprimer")); + } else { + diagram->clearSelection(); + diagram->undoStack().push(new DeleteQGraphicsItemCommand(diagram, dc)); + dv->adjustSceneRect(); + } + } else if (value == "rotate_selection") { RotateSelectionCommand *c = new RotateSelectionCommand(diagram); diff --git a/sources/undocommand/deleteqgraphicsitemcommand.cpp b/sources/undocommand/deleteqgraphicsitemcommand.cpp index 24e407b17..074a04607 100644 --- a/sources/undocommand/deleteqgraphicsitemcommand.cpp +++ b/sources/undocommand/deleteqgraphicsitemcommand.cpp @@ -28,6 +28,8 @@ #include "../qetgraphicsitem/elementtextitemgroup.h" #include "../qetgraphicsitem/terminal.h" #include "addelementtextcommand.h" +#include "../TerminalStrip/realterminal.h" +#include "../TerminalStrip/physicalterminal.h" /** @brief DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand @@ -115,6 +117,36 @@ DeleteQGraphicsItemCommand::~DeleteQGraphicsItemCommand() m_diagram->qgiManager().release(m_removed_contents.items(DiagramContent::All)); } +/** + * @brief DeleteQGraphicsItemCommand::hasNonDeletableTerminal + * Return true if @content have terminal element which can't be deleted. + * The reason why a terminal can't be deleted is because they have bridge + * or belong to a physical terminal with more than one level. + * @param diagram + * @param content + * @param dialog + * @return + */ +bool DeleteQGraphicsItemCommand::hasNonDeletableTerminal(const DiagramContent &content) +{ + if (!content.m_terminal_elements.isEmpty()) + { + for (const auto &terminal : content.m_terminal_elements) + { + if (!terminal.isNull()) + { + if (terminal->parentTerminalStrip() + && (terminal->realTerminal()->isBridged() + || terminal->realTerminal()->physicalTerminal()->levelCount() != 1)) { + return true; + } + } + } + } + + return false; +} + /** @brief DeleteQGraphicsItemCommand::setPotentialsOfRemovedElements This function creates new conductors (if needed) for conserve the electrical potentials diff --git a/sources/undocommand/deleteqgraphicsitemcommand.h b/sources/undocommand/deleteqgraphicsitemcommand.h index 370d1565c..53bb4d091 100644 --- a/sources/undocommand/deleteqgraphicsitemcommand.h +++ b/sources/undocommand/deleteqgraphicsitemcommand.h @@ -34,10 +34,10 @@ class DeleteQGraphicsItemCommand : public QUndoCommand public: DeleteQGraphicsItemCommand(Diagram *diagram, const DiagramContent &content, QUndoCommand * parent = nullptr); ~DeleteQGraphicsItemCommand() override; + static bool hasNonDeletableTerminal(const DiagramContent &content); private: DeleteQGraphicsItemCommand(const DeleteQGraphicsItemCommand &); - void setPotentialsOfRemovedElements(); Terminal *terminalInSamePotential(Terminal *terminal, Conductor *conductor_to_exclude);