[qet] qet/qet: [5307] Function for search conductor at the same potential.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 5307
Author:   blacksun
Date:     2018-04-07 15:25:05 +0200 (Sat, 07 Apr 2018)
Log Message:
-----------
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 

Modified Paths:
--------------
    trunk/sources/qetgraphicsitem/conductor.cpp
    trunk/sources/qetgraphicsitem/terminal.cpp
    trunk/sources/qetgraphicsitem/terminal.h

Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp	2018-04-06 20:27:39 UTC (rev 5306)
+++ trunk/sources/qetgraphicsitem/conductor.cpp	2018-04-07 13:25:05 UTC (rev 5307)
@@ -1538,12 +1538,14 @@
  * 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 *> Conductor::relatedPotentialConductors(const bool all_diagram, QList <Terminal *> *t_list) {
+QSet<Conductor *> Conductor::relatedPotentialConductors(const bool all_diagram, QList <Terminal *> *t_list)
+{
 	bool declar_t_list = false;
-	if (t_list == nullptr) {
+	if (t_list == nullptr)
+	{
 		declar_t_list = true;
 		t_list = new QList <Terminal *>;
 	}
@@ -1552,23 +1554,29 @@
 	QList <Terminal *> 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 <Conductor *> 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 <Conductor *> 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();
 		}

Modified: trunk/sources/qetgraphicsitem/terminal.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/terminal.cpp	2018-04-06 20:27:39 UTC (rev 5306)
+++ trunk/sources/qetgraphicsitem/terminal.cpp	2018-04-07 13:25:05 UTC (rev 5307)
@@ -765,24 +765,27 @@
  * @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<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 <Element *> 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 <Terminal *> terminals = terminal -> parentElement() -> terminals();
-		terminals.removeAll(const_cast<Terminal *> (terminal));
-		if (!terminals.isEmpty())
-			return terminals.first();
+		// If terminal parent element is a Terminal element.
+	else if (terminal -> parentElement() -> linkType() & Element::Terminale)
+	{
+		QList <Terminal *> terminals = terminal->parentElement()->terminals();
+		terminals.removeAll(const_cast<Terminal *>(terminal));
+		return terminals;
 	}
 
-	return nullptr;
+	return QList<Terminal *>();
 }
 

Modified: trunk/sources/qetgraphicsitem/terminal.h
===================================================================
--- trunk/sources/qetgraphicsitem/terminal.h	2018-04-06 20:27:39 UTC (rev 5306)
+++ trunk/sources/qetgraphicsitem/terminal.h	2018-04-07 13:25:05 UTC (rev 5307)
@@ -169,6 +169,6 @@
 	return(name_terminal_);
 }
 
-Terminal * relatedPotentialTerminal (const Terminal *terminal, const bool all_diagram = true);
+QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal, const bool all_diagram = true);
 
 #endif


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/