[qet] [4218] Bug fix : When user try to connect two differents potential together, the dialog box display a weird numbers of wire in the potential

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


Revision: 4218
Author:   blacksun
Date:     2015-09-27 14:26:59 +0200 (Sun, 27 Sep 2015)
Log Message:
-----------
Bug fix : When user try to connect two differents potential together, the dialog box display a weird numbers of wire in the potential

Modified Paths:
--------------
    trunk/sources/qetgraphicsitem/element.h
    trunk/sources/qetgraphicsitem/ghostelement.h
    trunk/sources/ui/potentialselectordialog.cpp
    trunk/sources/ui/potentialselectordialog.h

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2015-09-26 14:59:06 UTC (rev 4217)
+++ trunk/sources/qetgraphicsitem/element.h	2015-09-27 12:26:59 UTC (rev 4218)
@@ -109,7 +109,7 @@
 		virtual void unlinkElement     (Element *) {}
 		virtual void initLink          (QETProject *);
 		QList<Element *> linkedElements ();
-		virtual int linkType() const {return link_type_;} // @return the linkable type
+		virtual kind linkType() const {return link_type_;} // @return the linkable type
 		void newUuid() {uuid_ = QUuid::createUuid();} 	//create new uuid for this element
 
 		//ATTRIBUTES related to linked element

Modified: trunk/sources/qetgraphicsitem/ghostelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/ghostelement.h	2015-09-26 14:59:06 UTC (rev 4217)
+++ trunk/sources/qetgraphicsitem/ghostelement.h	2015-09-27 12:26:59 UTC (rev 4218)
@@ -42,7 +42,7 @@
 	// methods
 	public:
 	virtual bool fromXml(QDomElement &, QHash<int, Terminal *> &, bool = false);
-	virtual int linkType() const {return Simple;}
+	virtual kind linkType() const {return Simple;}
 	
 	protected:
 	QRectF minimalBoundingRect() const;

Modified: trunk/sources/ui/potentialselectordialog.cpp
===================================================================
--- trunk/sources/ui/potentialselectordialog.cpp	2015-09-26 14:59:06 UTC (rev 4217)
+++ trunk/sources/ui/potentialselectordialog.cpp	2015-09-27 12:26:59 UTC (rev 4218)
@@ -25,7 +25,7 @@
 #include "element.h"
 #include "reportelement.h"
 
-//### PRIVATE CLASS ###//
+//### BEGIN PRIVATE CLASS ###//
 
 /**
  * @brief The NewConductorPotentialSelector class
@@ -43,12 +43,11 @@
 			terminal_1->removeConductor(conductor);
 			terminal_2->removeConductor(conductor);
 
-			if (terminal_1->conductors().isEmpty() || terminal_2->conductors().isEmpty()) return;
+			getPotential(terminal_1, m_properties_1, m_conductor_number_1);
+			getPotential(terminal_2, m_properties_2, m_conductor_number_2);
 
-			m_properties_1 = terminal_1->conductors().first()->properties();
-			m_conductor_number_1 = terminal_1->conductors().first()->relatedPotentialConductors().size() + 1;
-			m_properties_2 = terminal_2->conductors().first()->properties();
-			m_conductor_number_2 = terminal_2->conductors().first()->relatedPotentialConductors().size() + 1;
+				//There isn't a potential at terminal 1 or 2.
+			if (m_conductor_number_1 == 0 && m_conductor_number_2 == 0) return;
 
 				//Re-add conductor to his terminals.
 			terminal_1->addConductor(conductor);
@@ -58,6 +57,51 @@
 
 		bool isValid() const {return m_is_valid;}
 
+		/**
+		 * @brief getPotential
+		 * Get the conductor propertie of the potential at terminal, and the number of wire in this potential.
+		 * @param terminal
+		 * @param properties
+		 * @param number
+		 */
+		void getPotential(Terminal *terminal, ConductorProperties &properties, int &number)
+		{
+			Conductor *conductor_in_potential = nullptr;
+
+				//Terminal have conductor linked to, we get it.
+			if (!terminal->conductors().isEmpty())
+				conductor_in_potential = terminal->conductors().first();
+
+				//Terminal haven't got a conductor, but if parent element is a folio report or a terminal element, we search a potential
+				//through the report or in another terminal of the terminal element.
+			else if (terminal->parentElement()->linkType() & (Element::Terminale | Element::AllReport))
+			{
+				Element *elmt_ = terminal->parentElement();
+
+				if ((elmt_->linkType() & Element::Terminale) && !elmt_->terminals().isEmpty())
+				{
+					foreach(Terminal *t, elmt_->terminals())
+					{
+						if (t->conductors().isEmpty()) continue;
+						conductor_in_potential = t->conductors().first();
+						break;
+					}
+				}
+				else if ((elmt_->linkType() & Element::AllReport) && !elmt_->isFree())
+				{
+					Element *other_report = elmt_->linkedElements().first();
+					if (other_report->terminals().isEmpty()) return;
+					Terminal *t = other_report->terminals().first();
+					if (t->conductors().isEmpty()) return;
+					conductor_in_potential= t->conductors().first();
+				}
+			}
+
+			if (!conductor_in_potential) return;
+			properties = conductor_in_potential->properties();
+			number = conductor_in_potential->relatedPotentialConductors().size()+1; //We add +1 because conductor_in_potential isn't count by relatedPotentialConductors
+		}
+
 		~NewConductorPotentialSelector() {}
 
 	private :
@@ -74,7 +118,7 @@
 		LinkReportPotentialSelector(Element *report) :
 			m_is_valid(false)
 		{
-			if (report->linkType() & Element::AllReport)
+			if ((report->linkType() & Element::AllReport) && !report->isFree())
 			{
 					//We temporarily unlink report to get the two existing potential
 				Element *other_report = report->linkedElements().first();
@@ -101,7 +145,7 @@
 		bool m_is_valid;
 };
 
-//### PRIVATE CLASS ###//
+//### END PRIVATE CLASS ###//
 
 /**
  * @brief PotentialSelectorDialog::PotentialSelectorDialog

Modified: trunk/sources/ui/potentialselectordialog.h
===================================================================
--- trunk/sources/ui/potentialselectordialog.h	2015-09-26 14:59:06 UTC (rev 4217)
+++ trunk/sources/ui/potentialselectordialog.h	2015-09-27 12:26:59 UTC (rev 4218)
@@ -27,6 +27,7 @@
 class AbstractPotentialSelector
 {
 	public:
+		AbstractPotentialSelector() : m_conductor_number_1(0), m_conductor_number_2(0) {}
 		virtual ~AbstractPotentialSelector() {}
 		virtual bool isValid() const = 0;
 


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