From 8d56e7809c7331a1e3aa18334d25583c4034391c Mon Sep 17 00:00:00 2001 From: blacksun Date: Sat, 7 Apr 2018 13:25:05 +0000 Subject: [PATCH] Function for search conductor at the same potential. When the search function is searching in a terminal element, they search only for the first terminal found, no matter if the terminal element have more than two terminals. So the list of conductors at the same potential is missing some conductors. This commit fix it, now the search function search for every terminals of a terminal element git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5307 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/qetgraphicsitem/conductor.cpp | 40 ++++++++++++++++----------- sources/qetgraphicsitem/terminal.cpp | 29 ++++++++++--------- sources/qetgraphicsitem/terminal.h | 2 +- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 7f19df165..21855b5d1 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -1538,12 +1538,14 @@ void Conductor::displayedTextChanged() * part of the returned QSet. * @param all_diagram : if true search in all diagram of the project, * false search only in the parent diagram of this conductor - * @param t_list, a list of terminal already cheched for the serach of potential. + * @param t_list, a list of terminal already found for this potential. * @return a QSet of conductor at the same potential. */ -QSet Conductor::relatedPotentialConductors(const bool all_diagram, QList *t_list) { +QSet Conductor::relatedPotentialConductors(const bool all_diagram, QList *t_list) +{ bool declar_t_list = false; - if (t_list == nullptr) { + if (t_list == nullptr) + { declar_t_list = true; t_list = new QList ; } @@ -1552,23 +1554,29 @@ QSet Conductor::relatedPotentialConductors(const bool all_diagram, QList this_terminal; this_terminal << terminal1 << terminal2; - // 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(); + // Return all conductors of terminal 1 and 2 + for (Terminal *terminal : this_terminal) + { + if (!t_list->contains(terminal)) + { + t_list->append(terminal); + QList other_conductors_list_t = terminal->conductors(); - //get terminal share the same potential of @terminal, of parent element - Terminal *t1_bis = relatedPotentialTerminal(terminal, all_diagram); - if (t1_bis && !t_list->contains(t1_bis)) { - t_list -> append(t1_bis); - other_conductors_list_t += t1_bis->conductors(); + //Get the other terminals of the parent element of @terminal, who share the same potential + //This is use for element type "folio report" and "terminal element" + for (Terminal *t : relatedPotentialTerminal(terminal, all_diagram)) + { + if (!t_list->contains(t)) + { + t_list -> append(t); + other_conductors_list_t += t->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(all_diagram, t_list); + //Get the conductors at the same potential for each conductors of other_conductors_list_t + for (Conductor *c : other_conductors_list_t) { + other_conductors += c->relatedPotentialConductors(all_diagram, t_list); } other_conductors += other_conductors_list_t.toSet(); } diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index 25c3a7b22..e53d55b8e 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -765,24 +765,27 @@ Element *Terminal::parentElement() const { * @param t terminal to start search * @param all_diagram :if true return all related terminal, * false return only terminal in the same diagram of @t - * @return + * @return the list of terminal at the same potential */ -Terminal * relatedPotentialTerminal (const Terminal *terminal, const bool all_diagram) { - // If terminal parent element is a folio report. - if (all_diagram && terminal -> parentElement() -> linkType() & Element::AllReport) { +QList relatedPotentialTerminal (const Terminal *terminal, const bool all_diagram) +{ + // If terminal parent element is a folio report. + if (all_diagram && terminal -> parentElement() -> linkType() & Element::AllReport) + { QList elmt_list = terminal -> parentElement() -> linkedElements(); - if (!elmt_list.isEmpty()) { - return (elmt_list.first() -> terminals().first()); + if (!elmt_list.isEmpty()) + { + return (elmt_list.first()->terminals()); } } - // If terminal parent element is a Terminal element. - else if (terminal -> parentElement() -> linkType() & Element::Terminale) { - QList terminals = terminal -> parentElement() -> terminals(); - terminals.removeAll(const_cast (terminal)); - if (!terminals.isEmpty()) - return terminals.first(); + // If terminal parent element is a Terminal element. + else if (terminal -> parentElement() -> linkType() & Element::Terminale) + { + QList terminals = terminal->parentElement()->terminals(); + terminals.removeAll(const_cast(terminal)); + return terminals; } - return nullptr; + return QList(); } diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h index bc9b5466d..a19816e11 100644 --- a/sources/qetgraphicsitem/terminal.h +++ b/sources/qetgraphicsitem/terminal.h @@ -169,6 +169,6 @@ inline QString Terminal::name() const { return(name_terminal_); } -Terminal * relatedPotentialTerminal (const Terminal *terminal, const bool all_diagram = true); +QList relatedPotentialTerminal (const Terminal *terminal, const bool all_diagram = true); #endif