diff --git a/sources/factory/elementfactory.cpp b/sources/factory/elementfactory.cpp index c30188744..221900235 100644 --- a/sources/factory/elementfactory.cpp +++ b/sources/factory/elementfactory.cpp @@ -20,10 +20,11 @@ #include "elementscollectionitem.h" #include "qetapp.h" #include "QDomElement" -#include "qetgraphicsitem/simpleelement.h" -#include "qetgraphicsitem/reportelement.h" -#include "qetgraphicsitem/masterelement.h" -#include "qetgraphicsitem/slaveelement.h" +#include "simpleelement.h" +#include "reportelement.h" +#include "masterelement.h" +#include "slaveelement.h" +#include "terminalelement.h" ElementFactory* ElementFactory::factory_ = 0; /** @@ -48,8 +49,9 @@ Element * ElementFactory::createElement(const ElementsLocation &location, QGraph if (element_definition->xml().hasAttribute("link_type")) { QString link_type = element_definition->xml().attribute("link_type"); if (link_type == "next_report" || link_type == "previous_report") return (new ReportElement(location, link_type, qgi, s, state)); - if (link_type == "master") return (new MasterElement(location, qgi, s, state)); - if (link_type == "slave") return (new SlaveElement (location, qgi, s, state)); + if (link_type == "master") return (new MasterElement (location, qgi, s, state)); + if (link_type == "slave") return (new SlaveElement (location, qgi, s, state)); + if (link_type == "terminal") return (new TerminalElement (location, qgi, s, state)); } //default if nothing match for link_type diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index a9caf2b58..1b83573ed 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -1325,6 +1325,13 @@ QSet Conductor::relatedConductors() const { * @return les conducteurs avec lesquels ce conducteur partage * le meme potentiel electrique a l'exception de lui même */ +/** + * @brief Conductor::relatedPotentialConductors + * Return all conductors at the same potential of this conductor, this conductor isn't + * part of the returned QSet. + * @param t_list, a list of terminal already cheched for the serach of potential. + * @return a QSet of conductor at the same potential. + */ QSet Conductor::relatedPotentialConductors(QList *t_list) { bool declar_t_list = false; if (t_list == 0) { @@ -1333,46 +1340,31 @@ QSet Conductor::relatedPotentialConductors(QList *t_li } QSet other_conductors; - //renvoie tous les conducteurs du terminal 1 - if (!t_list -> contains(terminal1)) { - t_list -> append(terminal1); - QList other_conductors_list_t1 = terminal1 -> conductors(); + QList this_terminal{terminal1, terminal2}; - //get terminal share the same potential of terminal1 - Terminal *t1_bis = relatedPotentialTerminal(terminal1); - if (t1_bis && !t_list->contains(t1_bis)) { - t_list -> append(t1_bis); - other_conductors_list_t1 += t1_bis->conductors(); - } + // Return all conductor of terminal 1 and 2 + foreach (Terminal *terminal, this_terminal) { + if (!t_list -> contains(terminal)) { + t_list -> append(terminal); + QList other_conductors_list_t = terminal -> conductors(); - other_conductors_list_t1.removeAll(this); - //recherche les conducteurs connecté au conducteur déjà trouvé - foreach (Conductor *c, other_conductors_list_t1) { - other_conductors += c -> relatedPotentialConductors(t_list); + //get terminal share the same potential of @terminal, of parent element + Terminal *t1_bis = relatedPotentialTerminal(terminal); + if (t1_bis && !t_list->contains(t1_bis)) { + t_list -> append(t1_bis); + other_conductors_list_t += t1_bis->conductors(); + } + + other_conductors_list_t.removeAll(this); + // Research the conductors connected to conductors already found + foreach (Conductor *c, other_conductors_list_t) { + other_conductors += c -> relatedPotentialConductors(t_list); + } + other_conductors += other_conductors_list_t.toSet(); } - other_conductors += other_conductors_list_t1.toSet(); } - //renvoie tous les conducteurs du terminal 2 - if (!t_list -> contains(terminal2)) { - t_list -> append(terminal2); - QList other_conductors_list_t2 = terminal2 -> conductors(); - - //get terminal share the same potential of terminal1 - Terminal *t2_bis = relatedPotentialTerminal(terminal2); - if (t2_bis && !t_list->contains(t2_bis)) { - t_list -> append(t2_bis); - other_conductors_list_t2 += t2_bis->conductors(); - } - - other_conductors_list_t2.removeAll(this); - //recherche les conducteurs connecté au conducteur déjà trouvé - foreach (Conductor *c, other_conductors_list_t2) { - other_conductors += c -> relatedPotentialConductors(t_list); - } - other_conductors += other_conductors_list_t2.toSet(); - } - other_conductors.remove(const_cast(this)); + other_conductors.remove(this); if (declar_t_list) delete t_list; return(other_conductors); @@ -1380,17 +1372,30 @@ QSet Conductor::relatedPotentialConductors(QList *t_li /** * @brief Conductor::relatedPotentialTerminal - * find another terminal in the same electric potential of terminal @t + * Return terminal at the same potential from the same + * parent element of @t. + * For folio report, return the terminal of linked other report. + * For Terminal element, return the other terminal of terminal element. + * @param t terminal to start search + * @return */ Terminal * Conductor::relatedPotentialTerminal (Terminal *t) { - //terminal must have a folio report parent. + // If terminal parent element is a folio report. if (t->parentElement()->linkType() & Element::AllReport) { QList elmt_list = t->parentElement()->linkedElements(); if (!elmt_list.isEmpty()) { return (elmt_list.first()->terminals().first()); } } - return 0; + // If terminal parent element is a Terminal element. + if (t->parentElement() -> linkType() & Element::Terminale) { + QList terminals = t->parentElement()->terminals(); + terminals.removeAll(t); + if (!terminals.isEmpty()) return terminals.first(); + else return nullptr; + } + + return nullptr; } /** diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 67af0168b..5ab65aecf 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -53,7 +53,7 @@ class Element : public QetGraphicsItem { AllReport = 6, Master = 8, Slave = 16, - Bornier = 32}; + Terminale = 32}; private: QSize dimensions; diff --git a/sources/qetgraphicsitem/terminalelement.cpp b/sources/qetgraphicsitem/terminalelement.cpp new file mode 100644 index 000000000..c5b0a563f --- /dev/null +++ b/sources/qetgraphicsitem/terminalelement.cpp @@ -0,0 +1,34 @@ +/* + Copyright 2006-2014 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "terminalelement.h" + +/** + * @brief TerminalElement::TerminalElement + * Default constructor + * @param location location of xml definition + * @param qgi parent QGraphicItem + * @param s parent diagram + * @param state int used to know if the creation of element have error + */ +TerminalElement::TerminalElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) : + CustomElement(location, qgi, s, state) +{ + link_type_ = Terminale; +} + +TerminalElement::~TerminalElement() {} diff --git a/sources/qetgraphicsitem/terminalelement.h b/sources/qetgraphicsitem/terminalelement.h new file mode 100644 index 000000000..287005db1 --- /dev/null +++ b/sources/qetgraphicsitem/terminalelement.h @@ -0,0 +1,31 @@ +/* + Copyright 2006-2014 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef TERMINALELEMENT_H +#define TERMINALELEMENT_H + +#include "customelement.h" + +class TerminalElement : public CustomElement +{ + Q_OBJECT + public: + TerminalElement(const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0); + ~TerminalElement(); +}; + +#endif // TERMINALELEMENT_H diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertieswidget.cpp index f4fd16702..aa8003190 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertieswidget.cpp @@ -131,7 +131,7 @@ void elementpropertieswidget::buildInterface() { lsew_ = new LinkSingleElementWidget(element_, this); tab_ -> addTab(lsew_, tr("R\351f\351rence crois\351e (esclave)")); break; - case Element::Bornier: + case Element::Terminale: break; default: break;