[qet] [4373] Merge branch 'conductor2' into conductor3 |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4373
Author: runsys
Date: 2016-03-06 17:39:56 +0100 (Sun, 06 Mar 2016)
Log Message:
-----------
Merge branch 'conductor2' into conductor3
Modified Paths:
--------------
branches/conductor3/examples/affuteuse_250h.qet
branches/conductor3/sources/diagram.cpp
branches/conductor3/sources/diagram.h
branches/conductor3/sources/diagramview.cpp
branches/conductor3/sources/qetapp.cpp
branches/conductor3/sources/qetapp.h
branches/conductor3/sources/qetarguments.cpp
branches/conductor3/sources/qetgraphicsitem/conductor.cpp
branches/conductor3/sources/qetgraphicsitem/conductor.h
branches/conductor3/sources/qetgraphicsitem/conductortextitem.h
branches/conductor3/sources/qetgraphicsitem/diagramtextitem.cpp
branches/conductor3/sources/qetgraphicsitem/element.cpp
branches/conductor3/sources/qetgraphicsitem/element.h
Added Paths:
-----------
branches/conductor3/sources/qetgraphicsitem/Mathlib.h
branches/conductor3/sources/qetgraphicsitem/binarygrid.cpp
branches/conductor3/sources/qetgraphicsitem/binarygrid.h
branches/conductor3/sources/qetgraphicsitem/waypoint.cpp
branches/conductor3/sources/qetgraphicsitem/waypoint.h
Modified: branches/conductor3/examples/affuteuse_250h.qet
===================================================================
--- branches/conductor3/examples/affuteuse_250h.qet 2016-03-06 16:29:29 UTC (rev 4372)
+++ branches/conductor3/examples/affuteuse_250h.qet 2016-03-06 16:39:56 UTC (rev 4373)
@@ -1013,20 +1013,20 @@
</newdiagrams>
<diagram title="page de garde" displayrows="true" version="0.4" cols="17" folio="%id/%total" displaycols="true" height="660" colsize="60" order="1" rows="8" author="TDP" filename="250 H" titleblocktemplate="DIN_A4_copy" date="20140310" rowsize="80">
<properties>
- <property name="date2" show="1"></property>
- <property name="label1" show="1"></property>
- <property name="title" show="1"></property>
- <property name="label2" show="1"></property>
- <property name="label3" show="1"></property>
- <property name="label4" show="1"></property>
- <property name="label5" show="1"></property>
- <property name="dessin" show="1"></property>
- <property name="control" show="1"></property>
- <property name="rev" show="1"></property>
- <property name="aprouv" show="1"></property>
- <property name="filename" show="1"></property>
- <property name="date" show="1"></property>
- <property name="date1" show="1"></property>
+ <property name="date2" show="1"/>
+ <property name="label1" show="1"/>
+ <property name="title" show="1"/>
+ <property name="label2" show="1"/>
+ <property name="label3" show="1"/>
+ <property name="label4" show="1"/>
+ <property name="label5" show="1"/>
+ <property name="dessin" show="1"/>
+ <property name="control" show="1"/>
+ <property name="rev" show="1"/>
+ <property name="aprouv" show="1"/>
+ <property name="filename" show="1"/>
+ <property name="date" show="1"/>
+ <property name="date1" show="1"/>
</properties>
<defaultconductor num="_" vertirotatetext="270" displaytext="1" type="multi" horizrotatetext="0" numsize="7" onetextperfolio="0"/>
<elements>
@@ -1091,10 +1091,10 @@
<property name="label3" show="1">250 H</property>
<property name="label4" show="1">QE01</property>
<property name="label5" show="1">*</property>
- <property name="dessin" show="1"></property>
- <property name="control" show="1"></property>
+ <property name="dessin" show="1"/>
+ <property name="control" show="1"/>
<property name="rev" show="1">1</property>
- <property name="aprouv" show="1"></property>
+ <property name="aprouv" show="1"/>
</properties>
<defaultconductor num="" vertirotatetext="270" displaytext="1" type="multi" horizrotatetext="0" numsize="7" onetextperfolio="0"/>
<elements>
@@ -2719,18 +2719,18 @@
<properties>
<property name="date2" show="1">2005</property>
<property name="label1" show="1">SDST IL:</property>
- <property name="title" show="1"></property>
+ <property name="title" show="1"/>
<property name="label2" show="1">SDST AD:</property>
<property name="label3" show="1">250 H</property>
<property name="label4" show="1">QE01</property>
<property name="label5" show="1">*</property>
- <property name="dessin" show="1"></property>
- <property name="control" show="1"></property>
+ <property name="dessin" show="1"/>
+ <property name="control" show="1"/>
<property name="rev" show="1">1</property>
- <property name="aprouv" show="1"></property>
- <property name="filename" show="1"></property>
- <property name="date" show="1"></property>
- <property name="date1" show="1"></property>
+ <property name="aprouv" show="1"/>
+ <property name="filename" show="1"/>
+ <property name="date" show="1"/>
+ <property name="date1" show="1"/>
</properties>
<defaultconductor num="_" vertirotatetext="270" displaytext="1" type="multi" horizrotatetext="0" numsize="7" onetextperfolio="1"/>
<elements>
@@ -3543,10 +3543,10 @@
<property name="label3" show="1">250 H</property>
<property name="label4" show="1">QE01</property>
<property name="label5" show="1">*</property>
- <property name="dessin" show="1"></property>
- <property name="control" show="1"></property>
+ <property name="dessin" show="1"/>
+ <property name="control" show="1"/>
<property name="rev" show="1">1</property>
- <property name="aprouv" show="1"></property>
+ <property name="aprouv" show="1"/>
<property name="date1" show="1">2014</property>
</properties>
<defaultconductor num="_" vertirotatetext="270" displaytext="1" type="multi" horizrotatetext="0" numsize="7" onetextperfolio="0"/>
@@ -4894,6 +4894,48 @@
<name lang="es">Elementos importados</name>
<name lang="cs">Zavedené prvky</name>
</names>
+ <category name="import">
+ <names>
+ <name lang="ru">Импортированные элементы</name>
+ <name lang="en">Imported elements</name>
+ <name lang="fr">Éléments importés</name>
+ <name lang="es">Elementos importados</name>
+ <name lang="cs">Zavedené prvky</name>
+ </names>
+ <category name="automate">
+ <names>
+ <name lang="fr">Automate</name>
+ </names>
+ <category name="relais">
+ <names>
+ <name lang="fr">relais</name>
+ </names>
+ <element name="contacteur.elmt">
+ <definition width="50" version="0.2" hotspot_x="20" hotspot_y="45" height="80" type="element" orientation="dnny">
+ <names>
+ <name lang="ru">Обмотка</name>
+ <name lang="en">Coil</name>
+ <name lang="fr">Contacteur</name>
+ <name lang="es">Bobina</name>
+ </names>
+ <description>
+ <input x="4" y="20" size="6" rotate="true" text="_"/>
+ <input x="4" y="-22" size="6" rotate="true" text="_"/>
+ <line length1="1,5" length2="1,5" antialias="false" end1="none" end2="none" style="line-style:normal;line-weight:normal;filling:none;color:black" y1="-21" x1="0" y2="-8" x2="0"/>
+ <line length1="1,5" length2="1,5" antialias="false" end1="none" end2="none" style="line-style:normal;line-weight:normal;filling:none;color:black" y1="9" x1="0" y2="21" x2="0"/>
+ <line length1="1,5" length2="1,5" antialias="false" end1="none" end2="none" style="line-style:normal;line-weight:normal;filling:none;color:black" y1="8" x1="16" y2="-8" x2="16"/>
+ <line length1="1,5" length2="1,5" antialias="false" end1="none" end2="none" style="line-style:normal;line-weight:normal;filling:none;color:black" y1="8" x1="-16" y2="8" x2="16"/>
+ <input x="-18" y="1.05" size="8" text="KM1"/>
+ <line length1="1,5" length2="1,5" antialias="false" end1="none" end2="none" style="line-style:normal;line-weight:normal;filling:none;color:black" y1="-8" x1="16" y2="-8" x2="-16"/>
+ <line length1="1,5" length2="1,5" antialias="false" end1="none" end2="none" style="line-style:normal;line-weight:normal;filling:none;color:black" y1="-8" x1="-16" y2="8" x2="-16"/>
+ <terminal x="0" y="-20" orientation="n"/>
+ <terminal x="0" y="21" orientation="s"/>
+ </description>
+ </definition>
+ </element>
+ </category>
+ </category>
+ </category>
<category name="01sources">
<names>
<name lang="ar">مصادر</name>
Modified: branches/conductor3/sources/diagram.cpp
===================================================================
--- branches/conductor3/sources/diagram.cpp 2016-03-06 16:29:29 UTC (rev 4372)
+++ branches/conductor3/sources/diagram.cpp 2016-03-06 16:39:56 UTC (rev 4373)
@@ -30,6 +30,7 @@
#include "qetgraphicsitem/ghostelement.h"
#include "qetgraphicsitem/independenttextitem.h"
#include "qetgraphicsitem/diagramimageitem.h"
+#include "qetgraphicsitem/conductor.h"
#include "qetgraphicsitem/qetshapeitem.h"
#include "terminal.h"
#include "elementtextsmover.h"
@@ -75,6 +76,8 @@
connect(&border_and_titleblock, SIGNAL(diagramTitleChanged(const QString &)), this, SLOT(titleChanged(const QString &)));
connect(&border_and_titleblock, SIGNAL(borderChanged(QRectF,QRectF)), this, SLOT(adjustSceneRect()));
adjustSceneRect();
+
+ _binaryGrid = new BinaryGrid(this);
}
/**
@@ -104,6 +107,8 @@
}
qDeleteAll (deletable_items);
+
+ delete _binaryGrid;
}
/**
@@ -266,6 +271,40 @@
bool transmit_event = true;
if (!isReadOnly()) {
// detecte le relachement d'une touche de direction ( = deplacement d'elements)
+ if ( e -> key() == Qt::Key_G) {
+ Conductor::bDebugGrid= !Conductor::bDebugGrid;
+ Conductor::reBuild();
+ update();
+ }
+ else if ( e -> key() == Qt::Key_P) {
+ Conductor::bAffPoint = !Conductor::bAffPoint;
+ update();
+ }
+ else if ( e -> key() == Qt::Key_C) {
+ Conductor::bAffCoord = !Conductor::bAffCoord;
+ update();
+ }
+ else if ( e -> key() == Qt::Key_S) {
+ Conductor::bSmooth = !Conductor::bSmooth;
+ Conductor::reBuild();
+ update();
+ }
+ else if ( e -> key() == Qt::Key_D) {
+ Conductor::bDebug = !Conductor::bDebug;
+ Conductor::reBuild();
+ update();
+ }
+ else if ( e -> key() == Qt::Key_Plus) {
+ Conductor::iIndiceDebug++;
+ Conductor::reBuild();
+ update();
+ }
+ else if ( e -> key() == Qt::Key_Minus) {
+ Conductor::iIndiceDebug--;
+ Conductor::reBuild();
+ update();
+ }
+
if (
(e -> key() == Qt::Key_Left || e -> key() == Qt::Key_Right ||
e -> key() == Qt::Key_Up || e -> key() == Qt::Key_Down) &&
Modified: branches/conductor3/sources/diagram.h
===================================================================
--- branches/conductor3/sources/diagram.h 2016-03-06 16:29:29 UTC (rev 4372)
+++ branches/conductor3/sources/diagram.h 2016-03-06 16:39:56 UTC (rev 4373)
@@ -27,6 +27,7 @@
#include "numerotationcontext.h"
#include "qetproject.h"
#include "properties/xrefproperties.h"
+#include "binarygrid.h"
class Conductor;
class CustomElement;
@@ -44,6 +45,7 @@
class DiagramImageItem;
class ElementTextsMover;
class DiagramEventInterface;
+class BinaryGrid;
/**
This class represents an electric diagram. It manages its various child
@@ -222,6 +224,9 @@
void editElementRequired(const ElementsLocation &); /// Signal emitted when users wish to edit an element from the diagram
void reportPropertiesChanged(QString);
void XRefPropertiesChanged();
+
+ public:
+ BinaryGrid* _binaryGrid;
};
Q_DECLARE_METATYPE(Diagram *)
Modified: branches/conductor3/sources/diagramview.cpp
===================================================================
--- branches/conductor3/sources/diagramview.cpp 2016-03-06 16:29:29 UTC (rev 4372)
+++ branches/conductor3/sources/diagramview.cpp 2016-03-06 16:39:56 UTC (rev 4373)
@@ -430,6 +430,7 @@
// objet pour recuperer le contenu ajoute au schema par le coller
DiagramContent content_pasted;
scene -> fromXml(document_xml, pos, false, &content_pasted);
+ qDebug()<< "PASTE" << texte_presse_papier;
// si quelque chose a effectivement ete ajoute au schema, on cree un objet d'annulation
if (content_pasted.count()) {
Modified: branches/conductor3/sources/qetapp.cpp
===================================================================
--- branches/conductor3/sources/qetapp.cpp 2016-03-06 16:29:29 UTC (rev 4372)
+++ branches/conductor3/sources/qetapp.cpp 2016-03-06 16:39:56 UTC (rev 4373)
@@ -59,6 +59,7 @@
RecentFiles *QETApp::elements_recent_files_ = 0;
AboutQET *QETApp::about_dialog_ = 0;
TitleBlockTemplate *QETApp::default_titleblock_template_ = 0;
+bool QETApp::bConductor2 = false;
/**
Constructeur
Modified: branches/conductor3/sources/qetapp.h
===================================================================
--- branches/conductor3/sources/qetapp.h 2016-03-06 16:29:29 UTC (rev 4372)
+++ branches/conductor3/sources/qetapp.h 2016-03-06 16:39:56 UTC (rev 4373)
@@ -132,6 +132,7 @@
static QList<QETTitleBlockTemplateEditor *> titleBlockTemplateEditors(QETProject *);
static QTextOrientationSpinBoxWidget *createTextOrientationSpinBoxWidget();
static TitleBlockTemplate *defaultTitleBlockTemplate();
+ static bool bConductor2;
protected:
#ifdef Q_OS_DARWIN
Modified: branches/conductor3/sources/qetarguments.cpp
===================================================================
--- branches/conductor3/sources/qetarguments.cpp 2016-03-06 16:29:29 UTC (rev 4372)
+++ branches/conductor3/sources/qetarguments.cpp 2016-03-06 16:39:56 UTC (rev 4373)
@@ -16,6 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qetarguments.h"
+#include "qetapp.h"
#include "titleblock/templatescollection.h"
/**
@@ -237,7 +238,7 @@
* --license
*/
void QETArguments::handleOptionArgument(const QString &option) {
- if (option == QString("--help")) {
+ if (option == QString("--help")) {
print_help_ = true;
options_ << option;
return;
@@ -249,6 +250,10 @@
print_license_ = true;
options_ << option;
return;
+ } else if (option == QString("--conductor2")) {
+ QETApp::bConductor2 = true;
+ qDebug() << "CONDUCTOR2";
+ return;
}
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
Added: branches/conductor3/sources/qetgraphicsitem/Mathlib.h
===================================================================
--- branches/conductor3/sources/qetgraphicsitem/Mathlib.h (rev 0)
+++ branches/conductor3/sources/qetgraphicsitem/Mathlib.h 2016-03-06 16:39:56 UTC (rev 4373)
@@ -0,0 +1,238 @@
+/***************************************************************************
+ * Mathlib
+ *
+ * Copyright (C) 2003-2004, Alexander Zaprjagaev <frustum@xxxxxxxxxxx>
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ ***************************************************************************
+ * Update 2004/08/19
+ *
+ * added ivec2, ivec3 & ivec4 methods
+ * vec2d, vec3d & vec4d data : added texture coords (s,t,p,q) and color enums (r,g,b,a)
+ * mat3d & mat4d : added multiple double constructor ad modified methods returning mat3d or mat4d
+ * optimisations like "x / 2.0f" replaced by faster "x * 0.5f"
+ * defines of multiples usefull maths values and radian/degree conversions
+ * vec2d : added methods : set, reset, compare, dot, closestPointOnLine, closestPointOnSegment,
+ * projectionOnLine, lerp, angle
+ * vec3d : added methods : set, reset, compare, dot, cross, closestPointOnLine, closestPointOnSegment,
+ * projectionOnLine, lerp, angle
+ * vec4d : added methods : set, reset, compare
+ ***************************************************************************
+ * Update 2014/08/20
+ *
+ * Transform float to double
+ * for using with QT program
+ * author : Rene Negre <runsys@xxxxxxxxxxxxxxx>
+ ***************************************************************************
+ */
+
+#ifndef __HMATHLIB_D__
+#define __HMATHLIB_D__
+
+#include <math.h>
+#include <stdlib.h>
+#include <QPointF>
+#include <QtDebug>
+
+#define EPSILON 0.00000001
+//#define M_PI 3.141592653589793238462643383279f // PI
+#define M_PIDIV2 1.570796326794896619231321691639f // PI / 2
+#define M_2PI 6.283185307179586476925286766559f // 2 * PI
+#define M_PI2 9.869604401089358618834490999876f // PI au carre
+#define M_PIDIV180 0.01745329251994329576923690768488f // PI / 180
+#define M_180DIVPI 57.295779513082320876798154814105f // 180 / PI
+
+#define DegToRadd(a) (a)*=M_PIDIV180
+#define RadToDegd(a) (a)*=M_180DIVPI
+#define DEG2RADd(a) ((a)*M_PIDIV180)
+#define RAD2DEGd(a) ((a)*M_180DIVPI)
+#define RADIANSd(a) ((a)*M_PIDIV180)
+#define DEGRESd(a) ((a)*M_180DIVPI)
+#define DegToRad DEG2RADd
+
+
+const double INV_RAND_MAX = 1.0 / (RAND_MAX);
+const double INV_RAND_MAXd = 1.0 / (RAND_MAX );
+inline double randomd(double max=1.0) { return max * rand() * INV_RAND_MAX; }
+inline double randomd(double min, double max) { return min + (max - min) * INV_RAND_MAX * rand(); }
+inline int randomd(int max=RAND_MAX) { return rand()%(max+1); }
+
+class vec2d;
+class ivec2;
+
+
+/*****************************************************************************/
+/* */
+/* vec2d */
+/* */
+/*****************************************************************************/
+
+class vec2d {
+public:
+ static int count;
+ vec2d(void) : x(0), y(0) { count++; }
+ vec2d(double _x,double _y) : x(_x), y(_y) { count++; }
+ vec2d(const double *_v) : x(_v[0]), y(_v[1]) { count++; }
+ vec2d(const vec2d &_p1, const vec2d & _p2) : x(_p2.x-_p1.x), y(_p2.y-_p1.y) { count++; }
+ vec2d(const QPointF &_qp) : x(_qp.x()), y(_qp.y()) { count++; }
+
+ ~vec2d() { count--; }
+
+ bool operator==(const vec2d &_v) { return (fabs(this->x - _v.x) < EPSILON && fabs(this->y - _v.y) < EPSILON); }
+ int operator!=(const vec2d &_v) { return !(*this == _v); }
+
+ vec2d &operator=(double _f) { this->x=_f; this->y=_f; return (*this); }
+ const vec2d operator*(double _f) const { return vec2d(this->x * _f,this->y * _f); }
+ const vec2d operator/(double _f) const {
+ if(fabs(_f) < EPSILON) return *this;
+ _f = 1.0f / _f;
+ return (*this) * _f;
+ }
+ const vec2d operator+(const vec2d &_v) const { return vec2d(this->x + _v.x,this->y + _v.y); }
+ const vec2d operator-() const { return vec2d(-this->x,-this->y); }
+ const vec2d operator-(const vec2d &_v) const { return vec2d(this->x - _v.x,this->y - _v.y); }
+
+ vec2d &operator*=(double _f) { return *this = *this * _f; }
+ vec2d &operator/=(double _f) { return *this = *this / _f; }
+ vec2d &operator+=(const vec2d &_v) { return *this = *this + _v; }
+ vec2d &operator-=(const vec2d &_v) { return *this = *this - _v; }
+
+ double operator*(const vec2d &_v) const { return this->x * _v.x + this->y * _v.y; }
+
+ operator double*() { return this->v; }
+ operator const double*() const { return this->v; }
+// double &operator[](int _i) { return this->v[_i]; }
+// const double &operator[](int _i) const { return this->v[_i]; }
+
+ void set(double _x,double _y) { this->x = _x; this->y = _y; }
+ void reset(void) { this->x = this->y = 0; }
+ double length(void) const { return sqrtf(this->x * this->x + this->y * this->y); }
+ double normalize(void) {
+ double inv,l = this->length();
+ if(l < EPSILON) return 0.0f;
+ inv = 1.0f / l;
+ this->x *= inv;
+ this->y *= inv;
+ return l;
+ }
+ double dot(const vec2d &v) { return ((this->x*v.x) + (this->y*v.y)); } // Produit scalaire
+ bool compare(const vec2d &_v,double epsi=EPSILON) { return (fabs(this->x - _v.x) < epsi && fabs(this->y - _v.y) < epsi); }
+ // retourne les coordonnée du point le plus proche de *this sur la droite passant par vA et vB
+ vec2d closestPointOnLine(const vec2d &vA, const vec2d &vB) { return (((vB-vA) * this->projectionOnLine(vA, vB)) + vA); }
+ // retourne les coordonnée du point le plus proche de *this sur le segment vA,vB
+ vec2d closestPointOnSegment(const vec2d &vA, const vec2d &vB) {
+ double factor = this->projectionOnLine(vA, vB);
+ if (factor <= 0.0f) return vA;
+ if (factor >= 1.0f) return vB;
+ return (((vB-vA) * factor) + vA);
+ }
+ // retourne le facteur de la projection de *this sur la droite passant par vA et vB
+ double projectionOnLine(const vec2d &vA, const vec2d &vB) {
+ vec2d v(vB - vA);
+ return v.dot(*this - vA) / v.dot(v);
+ }
+ // Fonction d'interpolation linéaire entre 2 vecteurs
+ vec2d lerp(vec2d &u, vec2d &v, double factor) { return ((u * (1 - factor)) + (v * factor)); }
+ vec2d lerp(vec2d &u, vec2d &v, vec2d& factor) { return (vec2d((u.x * (1 - factor.x)) + (v.x * factor.x), (u.y * (1 - factor.y)) + (v.y * factor.y))); }
+ double angle(void) { return (double)atan2(this->y,this->x); }
+ double angle(const vec2d &v) { return (double)atan2(v.y-this->y,v.x-this->x); }
+
+ vec2d mul(const vec2d &v) { return vec2d(this->x*=v.x, this->y*=v.y); } // Produit des ccordonnes
+ vec2d& mulCoord(const vec2d &v) { this->x*=v.x, this->y*=v.y; return *this; } // Produit des ccordonnes
+ double addCoord() { return this->x + this->y; } // Produit des ccordonnes
+ vec2d vabs(void) { return vec2d( fabs(this->x), fabs(this->y) ); }
+ void abs(void) { this->x = fabs(this->x); this->y = fabs(this->y); }
+ vec2d exch(void) { return vec2d( this->y, this->x ); }
+ QPointF toQPointF() { return QPointF(this->x, this->y); }
+
+ vec2d vnormalize(void) {
+ double inv,l = this->length();
+ if(l < EPSILON) return vec2d(0.0,0.0);
+ inv = 1.0f / l;
+ return vec2d(this->x * inv, this->y * inv);
+ }
+
+
+ union {
+ struct {double x,y;};
+ struct {double s,t;};
+ double v[2];
+ };
+};
+/*
+ *
+ */
+inline void printVec2d( QString str, vec2d v ) {qDebug() << str <<" ("<< v.x <<","<< v.y <<")";}
+inline void printVec2d( vec2d v ) {qDebug() <<" ("<< v.x <<","<< v.y <<")";}
+
+
+inline vec2d operator*(double fl, const vec2d& v) { return vec2d(v.x*fl, v.y*fl);}
+
+inline double Dot(const vec2d& a, const vec2d& b) { return(a.x*b.x+a.y*b.y); }
+
+
+/*****************************************************************************/
+/* */
+/* ivec2 */
+/* */
+/*****************************************************************************/
+
+class ivec2 {
+public:
+ ivec2(void) : a(0), b(0) { }
+ ivec2(long _a,long _b) : a(_a), b(_b) { }
+ ivec2(const long *iv) : a(iv[0]), b(iv[1]) { }
+ ivec2(const ivec2 &iv) : a(iv.a), b(iv.b) { }
+ ivec2(const vec2d &v) : x((int)v.x), y((int)v.y) { }
+
+ int operator==(const ivec2 &iv) { return ((this->a == iv.a) && (this->b == iv.b)); }
+ int operator!=(const ivec2 &iv) { return !(*this == iv); }
+
+ ivec2 &operator=(long _i) { this->x=_i; this->y=_i; return (*this); }
+ const ivec2 operator*(long _i) const { return ivec2(this->a * _i,this->b * _i); }
+ const ivec2 operator/(long _i) const { return ivec2(this->a / _i,this->b / _i); }
+ const ivec2 operator+(const ivec2 &iv) const { return ivec2(this->a + iv.a,this->b + iv.b); }
+ const ivec2 operator-() const { return ivec2(-this->a,-this->b); }
+ const ivec2 operator-(const ivec2 &iv) const { return ivec2(this->a - iv.a,this->b - iv.b); }
+
+ ivec2 &operator*=(long _i) { return *this = *this * _i; }
+ ivec2 &operator/=(long _i) { return *this = *this / _i; }
+ ivec2 &operator+=(const ivec2 &iv) { return *this = *this + iv; }
+ ivec2 &operator-=(const ivec2 &iv) { return *this = *this - iv; }
+
+ long operator*(const ivec2 &iv) const { return this->a * iv.a + this->b * iv.b; }
+
+ operator long*() { return this->i; }
+ operator const long*() const { return this->i; }
+// long &operator[](int _i) { return this->i[_i]; }
+// const long &operator[](int _i) const { return this->i[_i]; }
+
+ void set(long _a,long _b) { this->a = _a; this->b = _b; }
+ void reset(void) { this->a = this->b = 0; }
+ void swap(ivec2 &iv) { long tmp=a; a=iv.a; iv.a=tmp; tmp=b; b=iv.b; iv.b=tmp; }
+ void swap(ivec2 *iv) { this->swap(*iv); }
+
+ union {
+ struct {long a,b;};
+ struct {long x,y;};
+ long i[2];
+ };
+};
+
+
+
+#endif // __HMATHLIB_D__
+
Added: branches/conductor3/sources/qetgraphicsitem/binarygrid.cpp
===================================================================
--- branches/conductor3/sources/qetgraphicsitem/binarygrid.cpp (rev 0)
+++ branches/conductor3/sources/qetgraphicsitem/binarygrid.cpp 2016-03-06 16:39:56 UTC (rev 4373)
@@ -0,0 +1,523 @@
+/*
+ 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 <http://www.gnu.org/licenses/>.
+
+ binarygrid.cpp
+ Created on: 8 nov. 2014
+ Author: rene
+*/
+
+
+
+#include <QtDebug>
+#include "element.h"
+#include "binarygrid.h"
+
+/*
+ * BinaryGrid
+ * ------------
+ * This file manage a binary representation of screen grid . The grid is 10x10 pixel espacement
+ * Each bit is a grid's point. If this point is occupied by a element ( only if this have one or more
+ * terminal ) by conductor, the bit is one otherwise is zero
+ *
+ * For example : the first 64bits word of this buffer
+ * bit 63 ---------------------------------------------------------------------------------bit 0
+ * 0000 0010 0000 0100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+ * in hexa 0x0204000000000000 (in C/C++ convention it's a unsigned long long)
+ *
+ * In this example two points are occupied. Coordinate are (610,0) and (540,0)
+ *
+ * For a line :
+ * ------------
+ * two functions calculate a binary mask : computeFirstMask and computeSecondMask
+ * a logical xor beetwen this masks calculate the enter mask
+ *
+ */
+
+
+/*
+ *
+ */
+BinaryGrid::BinaryGrid( Diagram* d ) {
+ diagram = d;
+ reset();
+}
+
+
+/*
+ *
+ */
+BinaryGrid::~BinaryGrid() {
+}
+
+
+
+
+
+/*
+ *
+ */
+QString reverse( QString s ) {
+ QString ret = "";
+ const int nb = s.count();
+ for(int i=0; i<nb; i++) {
+ ret.append(s.at(nb-i-1));
+ }
+ return ret;
+}
+
+
+
+/*
+ *
+ */
+void printDoubl( QString str, double d ) {
+ qDebug() << str <<" "<< d;
+}
+
+/*
+ *
+ */
+QString getStringLine( U64 * line ) {
+ QString ret = "";
+ for ( int i=0; i<1; i++ ) {
+ U64 mask = 1;
+ for( int j=0; j<64; j++ ) {
+ if ( (line[i] & mask) == 0 ) ret += ".";
+ else ret += "1";
+ mask <<= 1;
+ }
+ }
+ return ret;
+}
+
+
+
+
+
+/*
+ *
+ */
+QString getStringBit( U64 val) {
+ QString ret = "";
+ U64 mask = 1;
+ for( int j=0; j<64; j++ ) {
+ if ( (val & mask) == 0 ) ret += ".";
+ else ret += "1";
+ mask <<= 1;
+ }
+ return ret;
+}
+
+
+
+
+
+void rect2side( vec2d* topLeft, vec2d* bottomRight, QRectF qRectF ) {
+ *topLeft = vec2d( qRectF.topLeft() );
+ *bottomRight = vec2d( qRectF.bottomRight() );
+}
+
+
+/*
+ *
+ */
+void BinaryGrid::reset() {
+ for( int i=0; i<400; i++ ) {
+ for( int j=0; j<5; j++ ) {
+ bitHrzt [i][j] = 0ULL;
+ bitVrtc [i][j] = 0ULL;
+ }
+ }
+}
+
+
+/*
+ *
+ */
+void BinaryGrid::build( Conductor* pExceptConductor) {
+ if ( diagram ){
+ QList<Element *> elements = diagram -> elements();
+ for ( int i=0; i<elements.size(); i++ ) {
+ Element* element = elements[i];
+ if ( element -> terminals().size() == 0 ) continue;
+
+ vec2d topLeft, bottomRight;
+ rect2side( &topLeft, &bottomRight, element -> boundingRectTrue() );
+
+ add2grid( topLeft, bottomRight, 3 );
+
+ QList<Conductor*> conductors = element->conductors();
+ const int nb = conductors.size();
+
+ for( int i=0; i<nb; i++ ) {
+ if ( conductors[i] == pExceptConductor ) continue;
+ add2grid( conductors[i] );
+ }
+
+ }
+ }
+}
+
+
+
+
+/*
+ *
+ */
+void BinaryGrid::reBuild(Conductor* pExceptConductor) {
+ reset();
+ build(pExceptConductor);
+}
+
+
+
+
+/*
+ * bit 0 for x = 0
+ * bit 1 for x = 10
+ * bit 2 for x = 20
+ * ....
+ *
+ * Compute mask until haven't point (one more)
+ * for example x = 100
+ * mask = 0001 1111 1111
+ *
+ * bit0 to bit9
+ */
+void BinaryGrid::computeFirstMask( double d, U64* mask ) {
+ int n = (int)(d) /640;
+ d = fmod(d, 640);
+ U64 uMask = (U64)(d - 1.0) / 10;
+ mask[n] = 1ULL << ++uMask;
+ (U64)(mask[n]--);
+ // Because at umask = 64 the result is mask[n]=256 why ???? 64bits => 8 bits ???
+ if ( uMask == 64 ) mask[n] = (U64)-1;
+
+ for( int i=0; i<n; i++) mask[i] = (U64)-1;
+ for( int i=n+1; i<5; i++) mask[i] = (U64)0;
+}
+
+
+
+/*
+ *
+ * Compute mask until haven't point
+ * for example x = 90
+ * mask = 0001 1111 1111
+ * bit0 to bit9
+ *
+ * it's a same result than computeFirstMask ... it's not a error !!!
+ * don't modify the function
+ *
+ * Computing a line
+ * -------------------
+ * result :
+ * for a horizontal line from 50 to 110
+ * first mask = 0000 0000 1111 (compute from 50)
+ * second mask = 0111 1111 1111 (compute from 110)
+ *
+ * xor masks = 0111 1111 0000 ..... mgical
+ *
+ */
+void BinaryGrid::computeSecondMask( double d, U64* mask ) {
+ int n = (int)d /640;
+ d = fmod(d, 640);
+ U64 uMask = (U64)(d) / 10;
+ mask[n] = 1ULL << ++uMask;
+ (U64)(mask[n]--);
+ // Because at umask = 64 the result is mask[n]=256 why ???? 64bits => 8 bits ???
+ if ( uMask == 64 ) mask[n] = (U64)-1;
+
+ for( int i=0; i<n; i++) mask[i] = (U64)-1;
+ for( int i=n+1; i<5; i++) mask[i] = (U64)0;
+}
+
+
+
+
+/*
+ *
+ */
+int BinaryGrid::computeFirstLine( double d) {
+ return (int) (((d-1)/10)+1);
+}
+
+/*
+ *
+ */
+int BinaryGrid::computeLastLine( double d) {
+ return (int) d/10;
+}
+
+
+/*
+ *
+ */
+void BinaryGrid::debugGrid(int deb, int fin) {
+ for ( int i=deb; i<=fin; i++ ) {
+// char * binary0 = getStringLine( bitHrzt[i] ).toStdString();
+// qDebug( "line : %02d %s %s", i, getStringLine( bitHrzt[i] ).toStdString(), getStringLine( bitVrtc[i] ).toStdString() );
+
+ qDebug() <<"line "<< (i+10) <<" "<< getStringLine( bitHrzt[i] ) <<" "<< getStringLine( bitVrtc[i] );
+ }
+}
+
+
+/*
+ *
+ */
+void BinaryGrid::debugGrid() {
+ debugGrid(2,45);
+}
+
+
+
+/*
+ *
+ */
+void BinaryGrid::add2grid( vec2d topLeft, vec2d bottomRight, int map ) {
+ double left = vec2d(topLeft).mul(vec2d(1.0,0.0)).addCoord();
+ double right = vec2d(bottomRight).mul(vec2d(1.0,0.0)).addCoord();
+
+ double top = vec2d(topLeft).mul(vec2d(0.0,1.0)).addCoord();
+ double bottom = vec2d(bottomRight).mul(vec2d(0.0,1.0)).addCoord();
+
+ // mask 0 and mask 1
+ U64 M0[5];
+ computeFirstMask( left, M0 );
+ U64 M1[5];
+ computeSecondMask( right, M1 );
+
+ // mask = mask0 xor mask1
+
+ U64 mask[5];
+ for( int i=0; i<5; i++ ) mask[i] = M0[i] ^ M1[i];
+
+ int idx0 = computeFirstLine(top);
+ int idx1 = computeLastLine(bottom);
+
+ for ( int i= idx0; i<idx1+1; i++ ) {
+ for ( int j=0; j<5; j++ ) {
+ if ( map & HORI ) bitHrzt[i][j] |= mask[j];
+ if ( map & VERT ) bitVrtc[i][j] |= mask[j];
+ }
+ }
+}
+
+
+
+
+/*
+ *
+ */
+void BinaryGrid::orderVect( vec2d& v1, vec2d& v2 ) {
+ if ( v1.x > v2.x || v1.y > v2.y ) {
+ vec2d v = vec2d( v1 );
+ v1 = v2;
+ v2 = v;
+ }
+}
+
+
+
+/*
+ *
+ */
+void BinaryGrid::add2grid( Conductor* pConductor ) {
+ QList <vec2d> vec2ds = pConductor -> getVec2ds();
+
+ const int nb = vec2ds.size() - 1;
+ for( int i=0; i<nb; i++ ) {
+ vec2d v1 = vec2d( vec2ds[i] + vec2d(pConductor->scenePos()) );
+ vec2d v2 = vec2d( vec2ds[i+1] + vec2d(pConductor->scenePos()) );
+
+ orderVect( v1, v2 );
+
+ vec2d vDir = vec2d( v1, v2 );
+ if ( vDir.dot( vec2d(0.0,1.0) ) == 0 ) add2grid( v1, v2, VERT);
+ else add2grid( v1, v2, HORI );
+ }
+}
+
+
+
+/*
+ *
+ */
+bool BinaryGrid::testMask( U64* mask, int lineBeg, int lineEnd, int map ) {
+ for ( int i=lineBeg; i<=lineEnd; i++ ) {
+ for( int j=0; j<5; j++ ) {
+ U64 val = 0;
+ if ( (map & HORI) == HORI ) val = bitHrzt[i][j];
+ if ( (map & VERT) == VERT ) val = bitVrtc[i][j];
+
+ if ( (val|mask[j]) != (val^mask[j]) ) {
+ qDebug() << "mask : "<< getStringLine( mask );
+ qDebug() << "HORZ : "<< getStringBit( bitHrzt[i][j] );
+ qDebug() << "VERT : "<< getStringBit( bitVrtc[i][j] );
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+
+
+
+/*
+ *
+ */
+bool BinaryGrid::test( vec2d p1, vec2d p2 ) {
+
+ orderVect( p1, p2 );
+
+ double left = vec2d(p1).mul(vec2d(1.0,0.0)).addCoord();
+ double right = vec2d(p2).mul(vec2d(1.0,0.0)).addCoord();
+
+ double top = vec2d(p1).mul(vec2d(0.0,1.0)).addCoord();
+ double bottom = vec2d(p2).mul(vec2d(0.0,1.0)).addCoord();
+
+ int map;
+ vec2d vDir = vec2d( p1, p2 );
+ if ( vDir.dot( vec2d(0.0,1.0) ) == 0 ) map = VERT;
+ else map = HORI;
+
+
+ // compute mask 0 and mask 1
+ U64 M0[5]; computeFirstMask( left, M0 );
+ U64 M1[5]; computeSecondMask( right, M1 );
+
+ // mask = mask0 xor mask1
+ U64 mask[5];
+ for( int i=0; i<5; i++ ) mask[i] = M0[i] ^ M1[i];
+
+ int idx0 = computeFirstLine(top);
+ int idx1 = computeLastLine(bottom);
+
+ if ( testMask( mask, idx0, idx1, map ) ) {
+ qDebug() <<"BinaryGrid::test";
+ printVec2d( "p1 : ", p1 );
+ printVec2d( "p2 : ", p2 );
+ qDebug() << "idx 0 : "<< idx0;
+ qDebug() << "idx 1 : "<< idx1;
+ return true;
+ }
+ return false;
+}
+
+
+
+
+/*
+ *
+ */
+bool BinaryGrid::computeMinSegment( vec2d p1, vec2d p2 ) {
+
+ orderVect( p1, p2 );
+// printVec2d( "p1 : ", p1 );
+// printVec2d( "p2 : ", p2 );
+
+ double left = vec2d(p1).mul(vec2d(1.0,0.0)).addCoord();
+ double right = vec2d(p2).mul(vec2d(1.0,0.0)).addCoord();
+
+ double top = vec2d(p1).mul(vec2d(0.0,1.0)).addCoord();
+ double bottom = vec2d(p2).mul(vec2d(0.0,1.0)).addCoord();
+
+ int map;
+ vec2d vDir = vec2d( p1, p2 );
+ if ( vDir.dot( vec2d(0.0,1.0) ) == 0 ) map = HORI;
+ else map = VERT;
+
+
+ // compute mask 0 and mask 1
+ U64 M0[5]; computeFirstMask( left, M0 );
+ U64 M1[5]; computeSecondMask( right, M1 );
+
+ // mask = mask0 xor mask1
+ U64 mask[5];
+ for( int i=0; i<5; i++ ) mask[i] = M0[i] ^ M1[i];
+
+ int idx0 = computeFirstLine(top);
+ int idx1 = computeLastLine(bottom);
+
+// qDebug() << "idx 0 : "<< idx0;
+// qDebug() << "idx 1 : "<< idx1;
+//
+// debugGrid( idx0-2, idx1+2);
+
+ return testMask( mask, idx0, idx1, map );
+}
+
+
+
+
+
+
+
+
+
+
+
+
+/*
+u is a vector
+and length in mathematic notation is : ||u||
+
+two vectors u and v have a dot product
+u dot v = ||u|| x ||v|| x cos(alpha)
+alpha is angle between u and v
+
+if u is a special vector a "normalized vector"
+lenght is one : ||u|| = 1
+
+and if u and v are normalized vectors
+u dot v = cos(alpha)
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Added: branches/conductor3/sources/qetgraphicsitem/binarygrid.h
===================================================================
--- branches/conductor3/sources/qetgraphicsitem/binarygrid.h (rev 0)
+++ branches/conductor3/sources/qetgraphicsitem/binarygrid.h 2016-03-06 16:39:56 UTC (rev 4373)
@@ -0,0 +1,53 @@
+/*
+ * binarygrid.h
+ *
+ * Created on: 8 nov. 2014
+ * Author: rene
+ */
+
+#ifndef BINARYGRID_H_
+#define BINARYGRID_H_
+
+#include "diagram.h"
+#include "conductor.h"
+#include "Mathlib.h"
+
+typedef qulonglong U64;
+
+#define HORI 0x01
+#define VERT 0x02
+#define ALL 0x03
+
+class BinaryGrid {
+
+ public:
+ BinaryGrid(Diagram * diagram);
+ ~BinaryGrid();
+
+ void reset();
+ void build(Conductor*);
+ void reBuild(Conductor*);
+
+ void computeFirstMask( double, U64* );
+ void computeSecondMask( double, U64*);
+ int computeFirstLine( double );
+ int computeLastLine( double );
+
+ void debugGrid(int, int);
+ void debugGrid();
+ void add2grid( vec2d, vec2d, int );
+ void orderVect( vec2d&, vec2d& );
+ void add2grid( Conductor* );
+
+ bool testMask( U64*, int, int, int );
+ bool test( vec2d, vec2d );
+ bool computeMinSegment( vec2d, vec2d );
+
+ private:
+ U64 bitHrzt[400][5];
+ U64 bitVrtc[400][5];
+
+ Diagram* diagram;
+};
+
+#endif /* BINARYGRID_H_ */
Modified: branches/conductor3/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- branches/conductor3/sources/qetgraphicsitem/conductor.cpp 2016-03-06 16:29:29 UTC (rev 4372)
+++ branches/conductor3/sources/qetgraphicsitem/conductor.cpp 2016-03-06 16:39:56 UTC (rev 4373)
@@ -31,10 +31,31 @@
#define PR(x) qDebug() << #x " = " << x;
+#include "qetapp.h"
+#include "binarygrid.h"
+
bool Conductor::pen_and_brush_initialized = false;
QPen Conductor::conductor_pen = QPen();
QBrush Conductor::conductor_brush = QBrush();
+QBrush Conductor::square_brush = QBrush(Qt::darkGreen);
+
+int vec2d::count = 0;
+
+
+bool Conductor::bDebug = true;
+bool Conductor::bAffPoint = true;
+bool Conductor::bAffCoord = false;
+bool Conductor::bDebugGrid = false;
+bool Conductor::bSmooth = false;
+int Conductor::iIndiceDebug = 0;
+Conductor* Conductor::lastConductor= NULL;
+QPointF Conductor::P1;
+Qet::Orientation Conductor::O1;
+QPointF Conductor::P2;
+Qet::Orientation Conductor::O2;
+
+
/**
* @brief Conductor::Conductor
* Default constructor.
@@ -99,7 +120,17 @@
text_item = new ConductorTextItem(properties_.text, this);
text_item -> setFlag(QGraphicsItem::ItemStacksBehindParent);
- connect(text_item, &ConductorTextItem::diagramTextChanged, this, &Conductor::displayedTextChanged);
+ calculateTextItemPosition();
+ connect(
+ text_item,
+ SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
+ this,
+ SLOT(displayedTextChanged())
+ );
+ bMouseOver = false;
+
+ //connect(text_item, &ConductorTextItem::diagramTextChanged, this, &Conductor::displayedTextChanged);
+
}
/**
@@ -179,6 +210,11 @@
Q_UNUSED(o1);
Q_UNUSED(o2);
+ if ( QETApp::bConductor2 ) {
+ //qDebug() << "updateConductorPath2";
+ generateConductorPath2(p1, o1, p2, o2 );
+ return;
+ }
ConductorProfile &conductor_profile = conductor_profiles[currentPathType()];
Q_ASSERT_X(conductor_profile.segmentsCount(QET::Both) > 1, "Conductor::priv_modifieConductor", "pas de points a modifier");
@@ -304,6 +340,11 @@
@param o2 Orientation de la borne 2
*/
void Conductor::generateConductorPath(const QPointF &p1, Qet::Orientation o1, const QPointF &p2, Qet::Orientation o2) {
+ if ( QETApp::bConductor2 ){
+ //qDebug() << "generateConductorPath2";
+ generateConductorPath2(p1, o1, p2, o2 );
+ return;
+ }
QPointF sp1, sp2, depart, newp1, newp2, arrivee, depart0, arrivee0;
Qet::Orientation ori_depart, ori_arrivee;
@@ -399,6 +440,464 @@
segmentsToPath();
}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void Conductor::addPoint( vec2d p, bool bTest ) {
+ vec2d vScenePos = vec2d(scenePos());
+ p -= vScenePos;
+
+ qDebug() << "Test Point : "<< currentIndice;
+ if ( currentIndice >= 2 && bTest ){
+ vec2d ori = vec2d( vec2ds[currentIndice-1] );
+ if ( diagram() ) {
+ if ( diagram() -> _binaryGrid ->test( ori, p ) )
+ qDebug()<< "Test TRUE intersection de "<< currentIndice-1 <<" à "<< currentIndice;
+// else
+// qDebug()<< "Test FALSE pas d'intersection de "<< currentIndice-1 <<" à "<< currentIndice;
+ }
+ }
+
+ if ( bDebug ) {
+ qDebug() << "--------------------------";
+ qDebug() << " point no : " << currentIndice;
+ printVec2d( " Ajout de : ", p + vec2d( scenePos() ) );
+ qDebug() << "--------------------------";
+ }
+ vec2ds << p;
+ currentIndice++;
+ if ( currentIndice == iIndiceDebug ) bDebug = true;
+ else bDebug = false;
+}
+
+void Conductor::printDoubl( QString str, double d ) {
+ qDebug() << str <<" "<< d;
+}
+
+
+
+/*
+ *
+ */
+vec2d Conductor::orientation2vec2d( Qet::Orientation orientation ) {
+ switch(orientation) {
+ case Qet::North: return vec2d( 0.0,-1.0 );
+ case Qet::East: return vec2d( 1.0, 0.0 );
+ case Qet::South: return vec2d( 0.0, 1.0 );
+ case Qet::West: return vec2d(-1.0, 0.0 );
+ }
+ return vec2d(0.0,0.0);
+}
+
+
+
+void Conductor::rect2corner( vec2d* topLeft, vec2d* topRight, vec2d*bottomLeft, vec2d* bottomRight, QRectF qRectF, QPointF pos ) {
+ *topLeft = vec2d( pos + qRectF.topLeft() ) + vec2d(1.0,1.0);
+ *topRight = vec2d( pos + qRectF.topRight() ) + vec2d(-1.0,1.0);
+ *bottomLeft = vec2d( pos + qRectF.bottomLeft() ) + vec2d(1.0,-1.0);
+ *bottomRight = vec2d( pos + qRectF.bottomRight() ) + vec2d(-1.0,-1.0);
+}
+
+void Conductor::rect2side( vec2d* topLeft, vec2d* bottomRight, QRectF qRectF, QPointF pos ) {
+ *topLeft = vec2d( pos + qRectF.topLeft() );
+ *bottomRight = vec2d( pos + qRectF.bottomRight() );
+}
+
+
+void Conductor::rect2side( vec2d* topLeft, vec2d* bottomRight, QRectF qRectF ) {
+ *topLeft = vec2d( qRectF.topLeft() );
+ *bottomRight = vec2d( qRectF.bottomRight() );
+}
+
+
+int Conductor::sign( double d ) { return d==0.0 ? 0 : d<-EPSILON ? -1: 1;}
+
+int Conductor::computeSign( vec2d p1, vec2d p2, vec2d vDir ) {
+ vec2d c_p1 = vec2d( p1 ).mulCoord( vDir );
+ vec2d c_p2 = vec2d( p2 ).mulCoord( vDir );
+
+// qDebug() << " computeSign()";
+// printVec2d( " p1 : ", c_p1 );
+// printVec2d( " p2 : ", c_p2 );
+
+ int ret = sign( vec2d( c_p1, c_p2 ).addCoord() );
+
+// printDoubl( " Sign : ", ret );
+
+ return ret;
+
+}
+
+bool Conductor::isInsideRect( vec2d pt, vec2d topLeft, vec2d bottomRight ) {
+
+ int s_ol = computeSign( pt, topLeft , east );
+ int s_or = computeSign( pt, bottomRight , east );
+ if ( s_ol == s_or ) return false;
+
+ s_ol = computeSign( pt, topLeft , south );
+ s_or = computeSign( pt, bottomRight , south );
+ if ( s_ol == s_or ) return false;
+
+ return true;
+}
+
+bool Conductor::isInsideRect( vec2d orig, vec2d dest, vec2d topLeft, vec2d bottomRight ) {
+
+ int s_ol = computeSign( orig, topLeft , east );
+ int s_or = computeSign( orig, bottomRight , east );
+ int s_dl = computeSign( dest, topLeft , east );
+ int s_dr = computeSign( dest, bottomRight , east );
+
+
+ if ( s_ol == s_or && s_ol == s_dl && s_ol == s_dr ) {
+ return false;
+ }
+
+ s_ol = computeSign( orig, topLeft , south );
+ s_or = computeSign( orig, bottomRight , south );
+ s_dl = computeSign( dest, topLeft , south );
+ s_dr = computeSign( dest, bottomRight , south );
+
+
+ if ( s_ol == s_or && s_ol == s_dl && s_ol == s_dr ) {
+ return false;
+ }
+
+ return true;
+}
+
+
+void Conductor::computeIntersection( vec2d orig, vec2d& dest, vec2d topLeft, vec2d bottomRight ) {
+ vec2d vDir = vec2d( orig, dest ).vnormalize();
+
+ vec2d newPt = orig + 10.0 * vDir;
+ dest = orig;
+ int n = 0;
+ while( !isInsideRect( newPt, topLeft, bottomRight) ) {
+ dest += +10.0 * vDir;
+ newPt+= +10.0 * vDir;
+ n++;
+ if ( n == 80 ) {
+ qDebug()<< "****** TIMEOUT ********";
+ dest = orig + 10.0 * vDir;
+ break;
+ }
+ }
+ // if error
+ if ( dest == orig ) {
+ dest = orig + 10.0 * vDir;
+ }
+}
+
+
+bool Conductor::isInsideElement( vec2d pt, Element* element) {
+
+ vec2d topLeft, bottomRight;
+ rect2side( &topLeft, &bottomRight, element -> boundingRectTrue() );
+
+ return isInsideRect( pt, topLeft, bottomRight );
+}
+
+
+Element* Conductor::intersectionElement( vec2d &pt, vec2d ori, Element* element ) {
+ if ( element == NULL ) return NULL;
+
+ vec2d topLeft, bottomRight;
+ rect2side( &topLeft, &bottomRight, element -> boundingRectTrue() );
+
+ if ( bDebug ) {
+ qDebug() << " test intersection avec : "<< element -> name();
+ }
+
+ if ( isInsideRect( ori, pt, topLeft, bottomRight ) ) {
+
+ if ( bDebug ) {
+ qDebug() <<" *** Intersection ";
+ printVec2d(" ori : ", ori );
+ printVec2d(" pt : ", pt );
+ printVec2d(" topLeft : ", topLeft );
+ printVec2d(" bottomRgiht : ", bottomRight );
+ qDebug() <<" *** computeInstersection";
+ }
+ computeIntersection( ori, pt, topLeft, bottomRight );
+ return element;
+ }
+ else {
+ if ( bDebug ) {
+ qDebug() <<" Pas d'intersection ";
+ //intersection( pt, ori, topLeft, bottomRight );
+ }
+ }
+ return NULL;
+}
+
+
+Element* Conductor::intersectionElements( vec2d &pt, vec2d ori ) {
+ Element* returnElement = NULL;
+ if ( bDebug ) {
+ qDebug() << "Intersection Elements";
+ }
+
+ if ( diagram() ){
+ QList<Element *> elements = diagram() -> elements();
+ for ( int i=0; i<elements.size(); i++ ) {
+ Element* element = elements[i];
+ //if ( element -> terminals() != null ) continue;
+ if ( element -> terminals().size() == 0 ) continue;
+ Element* ret = intersectionElement( pt, ori, element );
+ if ( ret ) returnElement = ret;
+ }
+ }
+ return returnElement;
+}
+
+
+void Conductor::intersectionConductors( vec2d &pt, vec2d ori ) {
+ if ( bDebug ) {
+ qDebug() << "Intersection Conductor";
+ }
+
+ if ( diagram() ){
+ QList<Element *> elements = diagram() -> elements();
+ int nbElem = elements.size();
+ for ( int i=0; i<nbElem; i++ ) {
+ Element* element = elements[i];
+
+ QList<Terminal *> terminals = element -> terminals();
+ int nbTerm = terminals.size();
+
+ for( int j=0; j<nbTerm; j++ ) {
+ Terminal * terminal = terminals[j];
+
+ QList<Conductor *> conductors = terminal -> conductors();
+ int nbCond = conductors.size();
+
+ for( int k=0; k<nbCond; k++ ) {
+ Conductor* conductor = conductors[k];
+
+ QList<vec2d> vec2ds = conductor -> vec2ds;
+ int nbVec2d= vec2ds.size() - 1 ;
+
+ vec2d vDir = vec2d(ori, pt).vnormalize();
+ //return;
+
+ for( int l=0; l<nbVec2d; l++ ) {
+ vec2d topLeft = vec2ds[l];
+ vec2d bottomRight = vec2ds[l+1];
+ vec2d vDirConductor = vec2d(topLeft, bottomRight).vnormalize();
+
+ if ( vDirConductor.dot(east) < 0.0 || vDirConductor.dot(south) <0.0 ) {
+ bottomRight = vec2ds[l];
+ topLeft = vec2ds[l+1];
+ }
+ topLeft -= vec2d( 2.0, 2.0 );
+ bottomRight += vec2d( 2.0, 2.0 );
+ /*
+
+ vec2d oldPt = vec2d(pt);
+
+ while( ori != pt ) {
+ isInsideRect(ori, pt, topLeft, bottomRight);
+ //pt = ori + 10.0 * vDir;
+ pt -= 10.0 * vDir;
+ qDebug() <<" pt dans conducteur Changement... idx : "<< currentIndice << " "<< pt.addCoord();
+ }
+ */
+ }
+ }
+ }
+ }
+ }
+ bDebug = false;
+}
+
+
+
+
+
+
+
+
+void Conductor::evaluatePath( vec2d ori, vec2d& pt, Element * element, double test ) {
+ if ( element == NULL ) return;
+
+ vec2d vDir = vec2d(ori, pt).vnormalize();
+ vec2d vOrtho = vec2d(vDir).exch();
+
+ if ( vDir == vec2d(0.0,0.0) ) return;
+
+ if ( bDebug ) {
+ qDebug() << "EvaluatePath : "<< test <<" sign "<< sign(vDir.addCoord());
+ printVec2d( " ori : ", ori );
+ printVec2d( " pt : ", pt );
+ }
+
+ if ( fabs(test) > 400.0 ) return;
+
+
+ vOrtho = vOrtho.vabs();
+
+ vec2d o = pt + test * vOrtho;
+ vec2d p = o + 10.0 * vDir;
+
+ if ( bDebug ) {
+ printDoubl( " evaluate t : ", test );
+ printVec2d( " evaluate p : ", p );
+ printVec2d( " evaluate o : ", o );
+ }
+
+ Element * ret = intersectionElement( p, o, element );
+
+ if ( bDebug ) {
+ printVec2d( " evaluate p : ", p );
+ printVec2d( " evaluate o : ", o );
+ }
+
+ test += sign(test) * 10.0;
+
+ //if ( p == o )
+ if ( ret )
+ evaluatePath( ori, pt, element, test );
+ else
+ pt = o;
+}
+
+double Conductor::computeSensEvaluatePath( vec2d ori, vec2d pt, vec2d dest ) {
+ vec2d vDir = vec2d( ori, dest );
+ vec2d vNew = vec2d( ori, pt ).exch().vabs();
+ vDir = vDir.mul(vNew);
+
+ double ret = vDir.addCoord();
+ ret = ret >= 0.0 ? 1.0 : -1.0;
+ return ret;
+}
+
+
+
+
+
+
+vec2d Conductor::previousDir() {
+ if ( currentIndice > 2 ) {
+ vec2d p2 = vec2ds[currentIndice - 1];
+ vec2d p1 = vec2ds[currentIndice - 2];
+
+ vec2d vDir = vec2d( p1, p2 ).vnormalize();
+ return vDir;
+ }
+ return vec2d(0.0,0.0);
+}
+
+
+
+vec2d Conductor::findNextPoint( vec2d p1, vec2d& vD1, vec2d p2, vec2d vD2 ) {
+
+
+ vec2d vP1P2n = vec2d(p1, p2).vnormalize();
+
+ double dot = vD1.dot(vD2);
+ double coef = 1.0;
+
+ vec2d v = vec2d( p1, p2 );
+ vec2d vnorm = v.vnormalize();
+ // if direction are opposite the next point is in the middle
+ // and not in the same line
+ if ( dot < -0.9 && vnorm.dot(vD1) != 1.0) { coef = 0.5; }
+ // tout droit
+ if ( vP1P2n == vD1 ) {
+ /*
+ vec2d newPoint = vec2d( p2 );
+ Element* element = intersectionElements( newPoint, p1 );
+ if ( element == NULL ) {
+ addPoint( p2 );
+ return p2;
+ }
+ */
+ coef = 1.0;
+ }
+ // New point follow first direction horizontal or vertical
+ v.x *= coef * fabs(vD1.x);
+ v.y *= coef * fabs(vD1.y);
+
+ if ( vD1 == vD2 && currentIndice == 2 ) {
+ qDebug() << "Changement automatique de la direction";
+ vec2d newDir = vec2d( vD1 ).exch();
+ newDir.abs();
+ printVec2d( "old dir : ", vD1 );
+ vD1.x = newDir.x;
+ vD1.y = newDir.y;
+ printVec2d( "new dir : ", newDir );
+ return p1;
+ }
+
+
+ vec2d newPoint = p1 + v;
+ // snap on grid
+ snapOnGrid( newPoint );
+
+
+ vec2d svgPt = newPoint;
+
+ //intersectionConductors( newPoint, p1 );
+ Element* element = intersectionElements( newPoint, p1 );
+
+ if ( newPoint != svgPt ) {
+ //vec2d newDir;
+ vec2d svgEvalPt = newPoint;
+ // compute sens
+ double first = computeSensEvaluatePath( p1, newPoint, p2) * 10.0;
+ evaluatePath( p1, newPoint, element, first );
+ if ( svgEvalPt != newPoint ) {
+ addPoint( svgEvalPt, true );
+ // on conserve la direction
+ return newPoint;
+ }
+ }
+ else {
+ if ( vP1P2n == vD1 && newPoint == p2 )
+ return p2;
+ }
+
+
+
+ // compute new direction
+ vec2d newD1 = vec2d( newPoint, p2 );
+ newD1.mul(vD1.exch().vabs());
+ newD1.normalize();
+
+ if ( newD1 == vec2d(0.0,0.0) ) {
+ newD1 = vD1.exch();
+
+ addPoint( newPoint,true );
+ newPoint += 60.0 * newD1;
+ newD1 = vD1;
+
+ }
+ // normalize vector 1 unit lenght
+ newD1.normalize();
+ //Change vD1 (it's a reference) isn't it
+ vD1.x = newD1.x;
+ vD1.y = newD1.y;
+// printVec2d(" New dir : ", vD1);
+// printVec2d("New point : ", newPoint);
+
+ // printVec2d("New point : ", newPoint);
+ return newPoint;
+}
+
/**
Prolonge une borne.
@param terminal Le point correspondant a la borne
@@ -421,11 +920,370 @@
case Qet::West:
extended_terminal = QPointF(terminal.x() - ext_size, terminal.y());
break;
- default: extended_terminal = terminal;
+ default: extended_terminal = terminal; break;
}
return(extended_terminal);
}
+
+
+
+vec2d Conductor::extendOutOfElement( vec2d pt, vec2d vDir, Element* element) {
+ vec2d newPt = pt;
+
+ if ( element ) {
+ while( isInsideElement( newPt , element )) {
+ newPt += 10.0 * vDir;
+ }
+ }
+ return newPt;
+}
+
+
+
+
+void Conductor::snapOnGrid( vec2d& pt ) {
+ vec2d newPt;
+ //pt += vec2d(5.0,5.0);
+
+ int x = (int) pt.x % 10;
+ int X = (int) pt.x / 10;
+
+ if ( x >= 5 ) X++;
+ newPt.x = 10.0 * X;
+
+ int y = (int) pt.y % 10;
+ int Y = (int) pt.y / 10;
+
+ if ( y >= 5 ) Y++;
+ newPt.y = 10.0 * Y;
+
+ pt = newPt;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/*
+ *
+ */
+void Conductor::generateConductorPath2( const QPointF &p1, Qet::Orientation o1, const QPointF &p2, Qet::Orientation o2) {
+ //diagram() -> _binaryGrid -> add2grid( vec2d(25.0,10.0), vec2d(405.0,45.0) );
+ QElapsedTimer timer;
+ timer.start();
+
+
+ if ( diagram() )
+ if ( diagram()->_binaryGrid)
+ diagram() -> _binaryGrid -> reBuild(this);
+
+
+ QPointF sp1, sp2, depart;
+ vec2d newp1, newp2;
+ vec2d vScenePos = vec2d(scenePos());
+
+ Conductor::lastConductor = this;
+ Conductor::P1 = p1;
+ Conductor::O1 = o1;
+ Conductor::P2 = p2;
+ Conductor::O2 = o2;
+ //Qet::Orientation ori_depart, ori_arrivee;
+
+ qDebug() << "-------------------------------";
+ qDebug() << "-------------------------------";
+ qDebug() << "-------------------------------";
+ if ( diagram() ){
+ qDebug() <<"Diagram title : "<< diagram() -> title();
+ }
+
+
+
+ // s'assure qu'il n'y a ni points
+ QList<QPointF> points;
+ vec2ds.clear();
+
+ // mappe les points par rapport a la scene
+ if ( p1.x() < p2.x() ) {
+ sp1 = mapFromScene(p1);
+ sp2 = mapFromScene(p2);
+ }
+ else {
+ sp1 = mapFromScene(p2);
+ sp2 = mapFromScene(p1);
+ Qet::Orientation o = o1;
+ o1 = o2;
+ o2 = o;
+ }
+
+ // prolonge les bornes
+ Element* element;
+ Element* element1 = terminal1 -> parentElement();
+ Element* element2 = terminal2 -> parentElement();
+
+ newp1 = vec2d(sp1) + vScenePos;
+ snapOnGrid( newp1 );
+ vec2d vDir1 = orientation2vec2d(o1);
+
+ element = NULL;
+ if ( isInsideElement( newp1, element1 ) ) element = element1;
+ else if ( isInsideElement( newp1, element2 ) ) element = element2;
+ if ( element ) qDebug() <<"Intersection terminal1 : "<< element -> name();
+ else qDebug() <<"*** Erreur Intersection terminal1 : ";
+
+ newp1 = extendOutOfElement( newp1, vDir1, element );
+
+ newp2 = vec2d(sp2) + vScenePos;
+ snapOnGrid( newp2 );
+ vec2d vDir2 = orientation2vec2d(o2);
+
+ element = NULL;
+ if ( isInsideElement( newp2, element1 ) ) element = element1;
+ else if ( isInsideElement( newp2, element2 ) ) element = element2;
+
+ newp2 = extendOutOfElement( newp2, vDir2, element );
+
+ //--------------------------
+ currentIndice = 0;
+ addPoint( vec2d(sp1) + vScenePos, true );
+ addPoint( newp1, false );
+
+ vec2d newPt = newp1;
+ vec2d vo = orientation2vec2d(o1);
+
+ // tout droit petite distance
+ vec2d P1 = vec2d(sp1);
+ vec2d P2 = vec2d(sp2);
+ vec2d vDir = vec2d( P1, P2 );
+ vec2d vNor = vDir.vnormalize();
+
+ if ( vDir != vec2d(0.0,0.0) && ( vDir.length() > 45.0 ) ) {
+
+
+ while ( newPt != newp2 ) {
+ if ( bDebug ) {
+ qDebug() << "**** Point suivant :"<< currentIndice;
+ printVec2d( " a partir de newPt : ", newPt );
+ printVec2d( " direction : ", vo );
+ printVec2d( " vers : ", newp2 );
+ printVec2d( " direction : ", orientation2vec2d(o2) );
+ }
+
+ newPt = findNextPoint( newPt, vo, newp2, orientation2vec2d(o2) );
+ addPoint( newPt, true );
+
+ if( currentIndice>=30 ) break;
+ }
+ }
+ else {
+ qDebug()<<"Tout droit";
+ vec2ds.removeAt(1);
+ }
+
+ //vec2ds << newp2;
+ addPoint( vec2d(sp2) + vScenePos, false );
+ if ( bSmooth ) {
+ smooth();
+ removeDouble();
+ }
+
+ // change vec2d to QPointF
+ int nb = vec2ds.size();
+ for( int i=0; i<nb; i++ ) {
+ points << vec2ds[i].toQPointF();
+ }
+
+ pointsToSegments(points);
+ segmentsToPath();
+ qDebug() << diagram();
+ if ( diagram() ) {
+ diagram() -> _binaryGrid -> add2grid(this);
+ if ( Conductor::bDebugGrid ) diagram() -> _binaryGrid -> debugGrid();
+ }
+
+ qDebug() << "ComputeTime : "<< (double) timer.nsecsElapsed() / 1000000.0 << "ms";
+}
+
+
+
+
+void Conductor::reBuild() {
+ if ( ! lastConductor ) return;
+ lastConductor -> generateConductorPath2( P1, O1, P2, O2 );
+
+}
+
+
+
+void Conductor::smooth(){
+ int nb = vec2ds.size()-4;
+ vec2d vNull = vec2d(0.0,0.0);
+
+ for ( int i=1; i<nb; i++ ) {
+ int ip0 = i;
+ int ip1 = i+1;
+ int ip2 = i+2;
+ int ip3 = i+3;
+ int ip4 = i+4;
+
+ vec2d v1 = vec2d( vec2ds[ip0], vec2ds[ip1] );
+ vec2d v2 = vec2d( vec2ds[ip1], vec2ds[ip2] );
+ vec2d v3 = vec2d( vec2ds[ip2], vec2ds[ip3] );
+ vec2d v4 = vec2d( vec2ds[ip3], vec2ds[ip4] );
+
+ if ( (v1 == vNull) || (v2 == vNull) || (v3 == vNull) || (v4 == vNull) ) continue;
+
+ vec2d vDir1 = vec2d( v1 ).vnormalize();
+ vec2d vDir2 = vec2d( v2 ).vnormalize();
+ vec2d vDir3 = vec2d( v3 ).vnormalize();
+ vec2d vDir4 = vec2d( v4 ).vnormalize();
+
+ /*
+ * ----+
+ * |
+ * +-----+
+ * |
+ * |
+ */
+ if ( vDir1 == vDir3 && vDir2 == vDir4 ) {
+ vec2d P1 = vec2d( vec2ds[ip1] ) + vec2d( vec2ds[ip2], vec2ds[ip3] );
+
+ vec2d vsp = vec2d( scenePos() );
+ bool bIntersection = false;
+
+ bIntersection |= diagram() -> _binaryGrid -> test(P1+vsp, vec2ds[ip1]+vsp );
+ bIntersection |= diagram() -> _binaryGrid -> test(P1+vsp, vec2ds[ip3]+vsp );
+
+ if ( !bIntersection ) {
+ vec2ds[ip1] = P1;
+ vec2ds[ip2] = P1;
+ vec2ds[ip3] = P1;
+ vec2ds.removeAt(ip1);
+ vec2ds.removeAt(ip1);
+ smooth();
+ break;
+ }
+ }
+
+ /*
+ * ----+ +------
+ * | |
+ * +-------+
+ */
+ if ( vDir1 == (-1.0*vDir3 ) ) {
+ vec2d vDiff;
+ if ( v1.length() < v2.length() ) vDiff = -1.0 * v1;
+ else vDiff = v3;
+
+ vec2d p0 = vec2d( vec2ds[ip0] );
+ vec2d p1 = vec2d( vec2ds[ip1] + vDiff );
+ vec2d p2 = vec2d( vec2ds[ip2] + vDiff );
+ vec2d p3 = vec2d( vec2ds[ip3] );
+
+ vec2d vsp = vec2d( scenePos() );
+ bool bIntersection = false;
+
+ bIntersection |= diagram() -> _binaryGrid -> test( p0+vsp, p1+vsp );
+ bIntersection |= diagram() -> _binaryGrid -> test( p1+vsp, p2+vsp );
+ bIntersection |= diagram() -> _binaryGrid -> test( p2+vsp, p3+vsp );
+// qDebug() << "test vDir1 == - vDir3";
+ if ( !bIntersection ) {
+// qDebug() << "on modifie";
+ vec2ds[ip1] = p1;
+ vec2ds[ip2] = p2;
+ smooth();
+ break;
+ }
+ }
+
+ }
+}
+
+void Conductor::removeDouble( void ) {
+ int nb = vec2ds.size()-1;
+
+ for ( int i=1; i<nb; i++ ) {
+ int ip0 = i;
+ int ip1 = i+1;
+
+ if ( vec2ds[ip0] == vec2ds[ip1] ) {
+ vec2ds.removeAt(ip0);
+ removeDouble();
+ break;
+ }
+ }
+}
+
+
+/*
+"P0 : " ( 220 , 290 )
+"P1 : " ( 220 , 470 )
+"P4 : " ( 540 , 470 )
+ */
+
+
+
+
+
+
+
+void Conductor::updateConductorPath2(const QPointF &p1, Qet::Orientation o1, const QPointF &p2, Qet::Orientation o2) {
+ generateConductorPath2( p1, o1, p2, o2);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/**
Dessine le conducteur sans antialiasing.
@param qp Le QPainter a utiliser pour dessiner le conducteur
@@ -459,6 +1317,10 @@
// affectation du QPen et de la QBrush modifies au QPainter
qp -> setBrush(conductor_brush);
+
+ if ( bMouseOver ) conductor_pen.setWidthF(3.0);
+ else conductor_pen.setWidthF(1.0);
+
QPen final_conductor_pen = conductor_pen;
// modification du QPen generique pour lui affecter la couleur et le style adequats
@@ -501,6 +1363,39 @@
qp -> drawEllipse(QRectF(point.x() - 1, point.y() - 1, 2.0, 2.0));
}
}
+
+ //Dessine tous les points
+ QFont font = qp -> font() ;
+ font.setPointSize ( 8 );
+ //font.setWeight(QFont::DemiBold);
+ qp -> setFont(font);
+
+ if ( Conductor::bAffPoint ) {
+ int nb = vec2ds.size();
+ vec2d prevPt = vec2d(0.0,0.0);
+ double nbPt = 0.0;
+ for (int i = 0 ; i < nb ; i++) {
+ vec2d pt = vec2ds[i];
+ vec2d vtl = vec2d(pt) - vec2d( 2.0, 2.0 ); // topLeft
+ vec2d vbr = vec2d(pt) + vec2d( 2.0, 2.0 ); // bottomRight
+
+ if ( prevPt == pt ) nbPt += 1.0;
+ else nbPt = 0.0;
+
+ // Point
+ QPointF coordText = vec2d( pt + nbPt * vec2d(10.0,0.0) + vec2d(2.0,-1.0) ).toQPointF();
+ qp -> fillRect( QRectF( vtl.toQPointF(), vbr.toQPointF() ) , square_brush );
+ // Texte
+ QString text;
+ if ( Conductor::bAffCoord )
+ text = QString::number(i,10) +":"+ QString::number( (int)(pt.x+scenePos().x()) ) +", "+ QString::number( (int)(pt.y+scenePos().y()) );
+ else
+ text = QString::number(i,10);
+ qp -> drawText( coordText, text );
+ prevPt = pt;
+ }
+ }
+
qp -> restore();
}
@@ -633,6 +1528,8 @@
void Conductor::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
Q_UNUSED(event);
bMouseOver = true;
+ Conductor::lastConductor = this;
+
update();
}
Modified: branches/conductor3/sources/qetgraphicsitem/conductor.h
===================================================================
--- branches/conductor3/sources/qetgraphicsitem/conductor.h 2016-03-06 16:29:29 UTC (rev 4372)
+++ branches/conductor3/sources/qetgraphicsitem/conductor.h 2016-03-06 16:39:56 UTC (rev 4373)
@@ -21,6 +21,7 @@
#include "conductorproperties.h"
#include <QGraphicsPathItem>
#include "QetGraphicsItemModeler/qetgraphicshandlerutility.h"
+#include "Mathlib.h"
class ConductorProfile;
class ConductorSegmentProfile;
@@ -156,7 +157,8 @@
/// QPen et QBrush objects used to draw conductors
static QPen conductor_pen;
static QBrush conductor_brush;
- static bool pen_and_brush_initialized;
+ static QBrush square_brush;
+ static bool pen_and_brush_initialized;
/// Define whether and how the conductor should be highlighted
Highlight must_highlight_;
bool m_valid;
@@ -166,6 +168,36 @@
void saveProfile(bool = true);
void generateConductorPath(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation);
void updateConductorPath(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation);
+
+ void addPoint(vec2d, bool);
+ //void printVec2d( QString, vec2d );
+ void printDoubl( QString, double );
+ vec2d qPointF2vec2d( QPointF );
+ QPointF vec2d2qPointF( vec2d );
+ vec2d orientation2vec2d( Qet::Orientation );
+ void rect2side( vec2d*, vec2d*, QRectF, QPointF );
+ void rect2side( vec2d*, vec2d*, QRectF );
+ void rect2corner( vec2d*, vec2d*, vec2d*, vec2d*, QRectF, QPointF );
+ int sign( double );
+ int computeSign( vec2d, vec2d, vec2d );
+ bool isInsideRect( vec2d, vec2d, vec2d );
+ bool isInsideRect( vec2d, vec2d, vec2d, vec2d );
+ void computeIntersection( vec2d, vec2d&, vec2d, vec2d );
+ bool isInsideElement( vec2d, Element* );
+ Element* intersectionElement( vec2d&, vec2d, Element* );
+ Element* intersectionElements( vec2d&, vec2d );
+ void intersectionConductors( vec2d&, vec2d );
+ void evaluatePath( vec2d, vec2d&, Element*, double = 10.0 );
+ double computeSensEvaluatePath( vec2d, vec2d, vec2d );
+ vec2d previousDir();
+ vec2d findNextPoint( vec2d, vec2d&, vec2d, vec2d );
+ vec2d extendOutOfElement( vec2d, vec2d, Element* );
+ void snapOnGrid( vec2d& );
+ void generateConductorPath2(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation);
+ void smooth( void );
+ void removeDouble( void );
+ void updateConductorPath2(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation);
+
uint segmentsCount(QET::ConductorSegmentType = QET::Both) const;
QList<QPointF> segmentsToPoints() const;
QList<ConductorBend> bends() const;
@@ -179,6 +211,30 @@
static QPointF extendTerminal(const QPointF &, Qet::Orientation, qreal = 9.0);
static Qt::Corner movementType(const QPointF &, const QPointF &);
static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &);
+
+ QList <vec2d> vec2ds;
+ vec2d north = vec2d( 0.0,-1.0);
+ vec2d south = vec2d( 0.0, 1.0);
+ vec2d east = vec2d( 1.0, 0.0);
+ vec2d west = vec2d(-1.0, 0.0);
+
+ int currentIndice;
+// Element elementParent1;
+// Element elementParent2;
+ public:
+ static bool bAffPoint;
+ static bool bAffCoord;
+ static bool bSmooth;
+ static bool bDebug;
+ static bool bDebugGrid;
+ static int iIndiceDebug;
+ static Conductor* lastConductor;
+ static QPointF P1;
+ static Qet::Orientation O1;
+ static QPointF P2;
+ static Qet::Orientation O2;
+ static void reBuild(void);
+ inline QList<vec2d> getVec2ds() { return vec2ds; }
};
Conductor * longuestConductorInPotential (Conductor *conductor, bool all_diagram = false);
Modified: branches/conductor3/sources/qetgraphicsitem/conductortextitem.h
===================================================================
--- branches/conductor3/sources/qetgraphicsitem/conductortextitem.h 2016-03-06 16:29:29 UTC (rev 4372)
+++ branches/conductor3/sources/qetgraphicsitem/conductortextitem.h 2016-03-06 16:39:56 UTC (rev 4373)
@@ -68,5 +68,8 @@
bool moved_by_user_;
bool rotate_by_user_;
QPointF before_mov_pos_;
+
+
+
};
#endif
Modified: branches/conductor3/sources/qetgraphicsitem/diagramtextitem.cpp
===================================================================
--- branches/conductor3/sources/qetgraphicsitem/diagramtextitem.cpp 2016-03-06 16:29:29 UTC (rev 4372)
+++ branches/conductor3/sources/qetgraphicsitem/diagramtextitem.cpp 2016-03-06 16:39:56 UTC (rev 4373)
@@ -222,7 +222,6 @@
painter -> restore();
}
-
}
/**
Modified: branches/conductor3/sources/qetgraphicsitem/element.cpp
===================================================================
--- branches/conductor3/sources/qetgraphicsitem/element.cpp 2016-03-06 16:29:29 UTC (rev 4372)
+++ branches/conductor3/sources/qetgraphicsitem/element.cpp 2016-03-06 16:39:56 UTC (rev 4373)
@@ -109,10 +109,19 @@
@return Le rectangle delimitant le contour de l'element
*/
QRectF Element::boundingRect() const {
+// qDebug() << QRectF(QPointF(-hotspot_coord.x(), -hotspot_coord.y()), dimensions);
+// qDebug() << "orientation : " << orientation();
return(QRectF(QPointF(-hotspot_coord.x(), -hotspot_coord.y()), dimensions));
}
/**
+ @return Le rectangle delimitant le contour de l'element
+*/
+QRectF Element::boundingRectTrue() const {
+ return mapRectToScene( boundingRect() );
+}
+
+/**
Definit la taille de l'element sur le schema. Les tailles doivent etre
des multiples de 10 ; si ce n'est pas le cas, les dimensions indiquees
seront arrrondies aux dizaines superieures.
@@ -189,6 +198,7 @@
* @param angle
*/
void Element::rotateBy(const qreal &angle) {
+ qDebug() << "Rotation : " << angle;
qreal applied_angle = QET::correctAngle(angle);
applyRotation(applied_angle + rotation());
@@ -258,7 +268,8 @@
t.setCosmetic(true);
painter -> setPen(t);
// Le dessin se fait a partir du rectangle delimitant
- painter -> drawRoundRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10);
+ //painter -> drawRoundRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10);
+ painter -> drawRoundRect(boundingRect().adjusted(0, 0, 0, 0), 10, 10);
painter -> restore();
}
@@ -284,7 +295,8 @@
painter -> setPen(Qt::NoPen);
painter -> setBrush(brush);
// Le dessin se fait a partir du rectangle delimitant
- painter -> drawRoundRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10);
+ //painter -> drawRoundRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10);
+ painter -> drawRoundRect(boundingRect().adjusted(0, 0, 0, 0), 10, 10);
painter -> restore();
}
Modified: branches/conductor3/sources/qetgraphicsitem/element.h
===================================================================
--- branches/conductor3/sources/qetgraphicsitem/element.h 2016-03-06 16:29:29 UTC (rev 4372)
+++ branches/conductor3/sources/qetgraphicsitem/element.h 2016-03-06 16:39:56 UTC (rev 4373)
@@ -150,8 +150,9 @@
virtual void setHighlighted(bool);
void displayHelpLine(bool b = true);
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
- QRectF boundingRect() const;
- QSize setSize(int, int);
+ QRectF boundingRect() const;
+ QRectF boundingRectTrue() const;
+ QSize setSize(int, int);
QSize size() const;
QPixmap pixmap();
Added: branches/conductor3/sources/qetgraphicsitem/waypoint.cpp
===================================================================
--- branches/conductor3/sources/qetgraphicsitem/waypoint.cpp (rev 0)
+++ branches/conductor3/sources/qetgraphicsitem/waypoint.cpp 2016-03-06 16:39:56 UTC (rev 4373)
@@ -0,0 +1,43 @@
+/*
+ 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 <http://www.gnu.org/licenses/>.
+
+
+ Created on: 6 nov. 2014
+ Author: rene
+ */
+
+
+
+
+#include "waypoint.h"
+
+
+
+
+Waypoint::Waypoint( vec2d o, vec2d d) {
+ orig = o;
+ dest = d;
+
+ vDir = vec2d( orig, dest );
+ vNor = vDir.vnormalize();
+
+ nexttLeft = NULL;
+ nexttRight = NULL;
+}
+
+
+
Added: branches/conductor3/sources/qetgraphicsitem/waypoint.h
===================================================================
--- branches/conductor3/sources/qetgraphicsitem/waypoint.h (rev 0)
+++ branches/conductor3/sources/qetgraphicsitem/waypoint.h 2016-03-06 16:39:56 UTC (rev 4373)
@@ -0,0 +1,33 @@
+/*
+ * waypoint.h
+ *
+ * Created on: 6 nov. 2014
+ * Author: rene
+ */
+
+#ifndef WAYPOINT_H_
+#define WAYPOINT_H_
+
+#include "Mathlib.h"
+
+class Waypoint;
+
+
+class Waypoint {
+ public:
+ Waypoint(vec2d, vec2d);
+ ~Waypoint();
+
+ private:
+ vec2d next;
+
+ vec2d orig;
+ vec2d dest;
+ vec2d vDir;
+ vec2d vNor;
+
+ Waypoint* nexttLeft;
+ Waypoint* nexttRight;
+};
+
+#endif /* WAYPOINT_H_ */