[qet] [3495] Merge branch 'conductor2-svn' into conductor2 |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 3495
Author: runsys
Date: 2014-11-16 21:55:39 +0100 (Sun, 16 Nov 2014)
Log Message:
-----------
Merge branch 'conductor2-svn' into conductor2
INIT BRANCH
Modified Paths:
--------------
branches/conductor2/examples/affuteuse_250h.qet
branches/conductor2/sources/diagram.cpp
branches/conductor2/sources/diagram.h
branches/conductor2/sources/diagramview.cpp
branches/conductor2/sources/qetapp.cpp
branches/conductor2/sources/qetapp.h
branches/conductor2/sources/qetarguments.cpp
branches/conductor2/sources/qetgraphicsitem/conductor.cpp
branches/conductor2/sources/qetgraphicsitem/conductor.h
branches/conductor2/sources/qetgraphicsitem/conductortextitem.h
branches/conductor2/sources/qetgraphicsitem/diagramtextitem.cpp
branches/conductor2/sources/qetgraphicsitem/diagramtextitem.h
branches/conductor2/sources/qetgraphicsitem/element.cpp
branches/conductor2/sources/qetgraphicsitem/element.h
branches/conductor2/sources/qetgraphicsitem/terminal.cpp
Added Paths:
-----------
branches/conductor2/sources/qetgraphicsitem/Mathlib.h
branches/conductor2/sources/qetgraphicsitem/binarygrid.cpp
branches/conductor2/sources/qetgraphicsitem/binarygrid.h
branches/conductor2/sources/qetgraphicsitem/waypoint.cpp
branches/conductor2/sources/qetgraphicsitem/waypoint.h
Modified: branches/conductor2/examples/affuteuse_250h.qet
===================================================================
--- branches/conductor2/examples/affuteuse_250h.qet 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/examples/affuteuse_250h.qet 2014-11-16 20:55:39 UTC (rev 3495)
@@ -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>
@@ -2731,18 +2731,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="0"/>
<elements>
@@ -3557,10 +3557,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"/>
@@ -4908,6 +4908,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/conductor2/sources/diagram.cpp
===================================================================
--- branches/conductor2/sources/diagram.cpp 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/diagram.cpp 2014-11-16 20:55:39 UTC (rev 3495)
@@ -31,6 +31,7 @@
#include "qetgraphicsitem/independenttextitem.h"
#include "qetapp.h"
#include "qetgraphicsitem/diagramimageitem.h"
+#include "qetgraphicsitem/conductor.h"
#include "qetgraphicsitem/qetshapeitem.h"
#include "terminal.h"
#include "elementtextsmover.h"
@@ -78,6 +79,8 @@
&border_and_titleblock, SIGNAL(diagramTitleChanged(const QString &)),
this, SLOT(titleChanged(const QString &))
);
+
+ _binaryGrid = new BinaryGrid(this);
}
/**
@@ -105,6 +108,8 @@
}
qDeleteAll (deletable_items);
+
+ delete _binaryGrid;
}
/**
@@ -189,6 +194,35 @@
bool transmit_event = true;
if (!isReadOnly()) {
// detecte le relachement d'une touche de direction ( = deplacement d'elements)
+ if ( e -> key() == Qt::Key_C) {
+ Conductor::bDebugGrid= !Conductor::bDebugGrid;
+ update();
+ }
+ else if ( e -> key() == Qt::Key_P) {
+ Conductor::bAffPoint = !Conductor::bAffPoint;
+ 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/conductor2/sources/diagram.h
===================================================================
--- branches/conductor2/sources/diagram.h 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/diagram.h 2014-11-16 20:55:39 UTC (rev 3495)
@@ -27,6 +27,7 @@
#include "numerotationcontext.h"
#include "qetproject.h"
#include "properties/xrefproperties.h"
+#include "binarygrid.h"
class Conductor;
class CustomElement;
@@ -43,6 +44,7 @@
class ConductorTextItem;
class DiagramImageItem;
class ElementTextsMover;
+class BinaryGrid;
/**
This class represents an electric diagram. It manages its various child
elements, conductors and texts and handles their graphic rendering.
@@ -224,6 +226,9 @@
void editElementRequired(const ElementsLocation &);
void reportPropertiesChanged(QString);
void XRefPropertiesChanged();
+
+ public:
+ BinaryGrid* _binaryGrid;
};
Q_DECLARE_METATYPE(Diagram *)
Modified: branches/conductor2/sources/diagramview.cpp
===================================================================
--- branches/conductor2/sources/diagramview.cpp 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/diagramview.cpp 2014-11-16 20:55:39 UTC (rev 3495)
@@ -447,6 +447,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/conductor2/sources/qetapp.cpp
===================================================================
--- branches/conductor2/sources/qetapp.cpp 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/qetapp.cpp 2014-11-16 20:55:39 UTC (rev 3495)
@@ -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/conductor2/sources/qetapp.h
===================================================================
--- branches/conductor2/sources/qetapp.h 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/qetapp.h 2014-11-16 20:55:39 UTC (rev 3495)
@@ -131,6 +131,7 @@
static QList<QETTitleBlockTemplateEditor *> titleBlockTemplateEditors(QETProject *);
static QTextOrientationSpinBoxWidget *createTextOrientationSpinBoxWidget();
static TitleBlockTemplate *defaultTitleBlockTemplate();
+ static bool bConductor2;
protected:
#ifdef Q_OS_DARWIN
Modified: branches/conductor2/sources/qetarguments.cpp
===================================================================
--- branches/conductor2/sources/qetarguments.cpp 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/qetarguments.cpp 2014-11-16 20:55:39 UTC (rev 3495)
@@ -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"
/**
@@ -249,6 +250,9 @@
print_license_ = true;
options_ << option;
return;
+ } else if (option == QString("--conductor2")) {
+ QETApp::bConductor2 = true;
+ return;
}
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
Added: branches/conductor2/sources/qetgraphicsitem/Mathlib.h
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/Mathlib.h (rev 0)
+++ branches/conductor2/sources/qetgraphicsitem/Mathlib.h 2014-11-16 20:55:39 UTC (rev 3495)
@@ -0,0 +1,231 @@
+/***************************************************************************
+ * 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>
+
+#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 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/conductor2/sources/qetgraphicsitem/binarygrid.cpp
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/binarygrid.cpp (rev 0)
+++ branches/conductor2/sources/qetgraphicsitem/binarygrid.cpp 2014-11-16 20:55:39 UTC (rev 3495)
@@ -0,0 +1,409 @@
+/*
+ * binarygrid.cpp
+ *
+ * Created on: 8 nov. 2014
+ * Author: rene
+ */
+
+
+
+#include <QtDebug>
+#include "element.h"
+#include "binarygrid.h"
+
+
+/*
+ *
+ */
+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 printVec2d( QString str, vec2d v ) {
+ qDebug() << str <<" ("<< v.x <<","<< v.y <<")";
+}
+
+
+/*
+ *
+ */
+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;
+}
+
+
+
+
+
+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
+ */
+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
+ *
+ * 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 result = 0111 1111 0000
+ *
+ */
+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]) ) return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+/*
+ *
+ */
+bool BinaryGrid::test( vec2d p1, vec2d p2 ) {
+ qDebug() <<"BinaryGrid::test";
+
+ 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 );
+}
+
+
+
+
+/*
+ *
+ */
+bool BinaryGrid::computeMinSegment( vec2d p1, vec2d p2 ) {
+ qDebug() <<"BinaryGrid::test";
+
+ 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 );
+}
+
+
+
+
Added: branches/conductor2/sources/qetgraphicsitem/binarygrid.h
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/binarygrid.h (rev 0)
+++ branches/conductor2/sources/qetgraphicsitem/binarygrid.h 2014-11-16 20:55:39 UTC (rev 3495)
@@ -0,0 +1,52 @@
+/*
+ * 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 unsigned long long U64;
+
+#define HORI 0x01
+#define VERT 0x02
+
+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/conductor2/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/conductor.cpp 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/qetgraphicsitem/conductor.cpp 2014-11-16 20:55:39 UTC (rev 3495)
@@ -27,12 +27,31 @@
#include "terminal.h"
#include "conductorautonumerotation.h"
#include "conductorpropertiesdialog.h"
-#define PR(x) qDebug() << #x " = " << x;
+#include "../qetapp.h"
+#include "binarygrid.h"
+#define PR(x) qDebug() << #x " = " << x;extend
+
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::bAffPoint = true;
+bool Conductor::bSmooth = false;
+Conductor* Conductor::lastConductor = NULL;
+QPointF Conductor::P1;
+Qet::Orientation Conductor::O1;
+QPointF Conductor::P2;
+Qet::Orientation Conductor::O2;
+bool Conductor::bDebug = false;
+bool Conductor::bDebugGrid = false;
+int Conductor::iIndiceDebug = 0;
+
+
/**
Constructeur
@param p1 Premiere Borne a laquelle le conducteur est lie
@@ -99,6 +118,7 @@
this,
SLOT(displayedTextChanged())
);
+ bMouseOver = false;
}
/**
@@ -171,6 +191,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");
@@ -296,6 +321,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;
@@ -391,6 +421,477 @@
segmentsToPath();
}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void Conductor::addPoint( vec2d p ) {
+ vec2d vScenePos = vec2d(scenePos());
+ p -= vScenePos;
+
+ qDebug() << "Test Point : "<< currentIndice;
+ if ( currentIndice > 1 ){
+ vec2d ori = vec2d( vec2ds[currentIndice-1] );
+ if ( diagram() ) {
+ if ( diagram() -> _binaryGrid ->test( ori, p ) )
+ qDebug()<< "Test droie OK de "<< currentIndice-1 <<" à "<< currentIndice;
+ else
+ qDebug()<< "Test droie NOK de "<< currentIndice-1 <<" à "<< currentIndice;
+ }
+ }
+
+ if ( bDebug ) {
+ qDebug() << "--------------------------";
+ qDebug() << " point no : " << currentIndice;
+ printVec2d( " Ajout de : ", p );
+ qDebug() << "--------------------------";
+ }
+ vec2ds << p;
+ currentIndice++;
+ if ( currentIndice == iIndiceDebug ) bDebug = true;
+ else bDebug = false;
+}
+
+void Conductor::printVec2d( QString str, vec2d v ) {
+ qDebug() << str <<" ("<< v.x <<","<< v.y <<")";
+}
+
+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 orientation;
+
+
+ vec2d vDir = vec2d( orig, dest ).vnormalize();
+ double sign = vDir.addCoord();
+
+ if ( vDir.dot(south) == 0.0 ) orientation = east;
+ else orientation = south;
+
+ if ( bDebug ) {
+ printVec2d( " orig : ", orig );
+ printVec2d( " dest : ", orig );
+ printVec2d( " dir : ", orientation);
+ }
+
+ vec2d vOL = vec2d( orig, topLeft ).mul(orientation);
+ vec2d vOR = vec2d( orig, bottomRight).mul(orientation);
+
+ double dOL = vOL.addCoord() * sign;
+ double dOR = vOR.addCoord() * sign;
+
+ if ( bDebug ) {
+ printDoubl( " dOL : ", dOL );
+ printDoubl( " dOR : ", dOR );
+ }
+
+ double res;
+ if ( dOL < dOR ) {
+ res = dOL;
+ res -= 10.0;
+ }
+ else {
+ res = dOR;
+ res += 10.0;
+ }
+
+
+ dest = orig + res * vDir;
+ snapOnGrid(dest);
+ if ( bDebug ) {
+ printVec2d( " dest : ", dest);
+ }
+
+}
+
+
+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();
+ printVec2d( " topLeft : ", topLeft );
+ printVec2d( " bottomRgiht : ", bottomRight );
+ }
+
+ if ( isInsideRect( ori, pt, topLeft, bottomRight ) ) {
+
+ if ( bDebug ) {
+ qDebug() <<" *** Intersection ";
+ 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());
+ }
+
+ if ( fabs(test) > 400.0 ) return;
+
+
+ vOrtho = vOrtho.vabs();
+
+ vec2d o = pt + test * vOrtho;
+ vec2d p = o + 50.0 * vDir;
+
+ if ( bDebug ) {
+ printDoubl( " evaluate t : ", test );
+ printVec2d( " evaluate p : ", p );
+ printVec2d( " evaluate o : ", o );
+ }
+
+ intersectionElement( p, o, element );
+
+ if ( bDebug ) {
+ printVec2d( " evaluate p : ", p );
+ printVec2d( " evaluate o : ", o );
+ }
+
+ test += sign(test) * 10.0;
+
+ if ( p == o )
+ 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);
+
+
+ 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 );
+ // 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 );
+ 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
@@ -413,11 +914,337 @@
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) );
+ 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() << "-------------------------------";
+ 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 );
+ addPoint( newp1 );
+
+ 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();
+// printVec2d( "P1", P1);
+// printVec2d( "P2", P2);
+// printVec2d( "DI", vDir);
+// printVec2d( "NO", vNor);
+// printDoubl( "dot1", fabs(vNor.dot(vDir1)) );
+// printDoubl( "dot2", fabs(vNor.dot(vDir2)) );
+// printDoubl( "leng", vDir.length() );
+ //if ( vDir != vec2d(0.0,0.0) && ( fabs(vNor.dot(vDir1)) != 1.0 || fabs(vNor.dot(vDir2)) != 1.0 || vDir.length() > 45.0 ) ) {
+ 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( " vers : ", newp2 );
+ }
+
+ newPt = findNextPoint( newPt, vo, newp2, orientation2vec2d(o2) );
+ addPoint( newPt );
+
+ if( currentIndice>=30 ) break;
+ }
+ }
+ else {
+ qDebug()<<"Tout droit";
+ vec2ds.removeAt(1);
+ }
+
+ //vec2ds << newp2;
+ addPoint( vec2d(sp2) + vScenePos );
+ if ( bSmooth ) smooth();
+
+ // change vec2d to QPointF
+ int nb = vec2ds.size();
+ for( int i=0; i<nb; i++ ) {
+ points << vec2ds[i].toQPointF();
+ }
+
+ pointsToSegments(points);
+ segmentsToPath();
+
+ diagram() -> _binaryGrid -> add2grid(this);
+ if ( Conductor::bDebugGrid ) diagram() -> _binaryGrid -> debugGrid();
+}
+
+
+
+
+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);
+
+ QList<vec2d> removePoints;
+
+ 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;
+
+// qDebug() << "------------------------------";
+// qDebug() << "i = "<< i;
+
+ vec2d v1 = vec2d( vec2ds[ip0], vec2ds[ip1] );
+ vec2d v2 = vec2d( vec2ds[ip2], vec2ds[ip3] );
+
+ vec2d v3 = vec2d( vec2ds[ip1], vec2ds[ip2] );
+ vec2d v4 = vec2d( vec2ds[ip3], vec2ds[ip4] );
+
+// printVec2d( "v1 : ", v1 );
+// printVec2d( "v2 : ", v2 );
+// printVec2d( "v3 : ", v3 );
+// printVec2d( "v4 : ", v4 );
+
+ if ( (v1 == vNull) || (v2 == vNull) || (v3 == vNull) || (v4 == vNull) ) continue;
+
+ v1.normalize();
+ v2.normalize();
+ v3.normalize();
+ v4.normalize();
+
+// printVec2d( "v1 : ", v1 );
+// printVec2d( "v2 : ", v2 );
+// printVec2d( "v3 : ", v3 );
+// printVec2d( "v4 : ", v4 );
+
+ if ( v1 == v2 && v3 == v4 ) {
+ vec2d P1 = vec2d( vec2ds[ip1] ) + vec2d( vec2ds[ip2], vec2ds[ip3] );
+// printVec2d( "P0 : ", vec2ds[ip0] );
+// printVec2d( "P1 : ", P1 );
+// printVec2d( "P4 : ", vec2ds[ip4] );
+
+ Element * element1 = intersectionElements( P1, vec2ds[ip1] );
+ Element * element2 = intersectionElements( P1, vec2ds[ip3] );
+
+ if ( element1 == NULL && element2 == NULL ){
+// removePoints << vec2d( vec2ds[ip1] );
+// removePoints << vec2d( vec2ds[ip2] );
+ //i += 3;
+
+// qDebug() <<"Remove point : "<< ip1 <<", "<< ip2 <<", "<< ip3;
+ vec2ds[ip1] = P1;
+ vec2ds[ip2] = P1;
+ vec2ds[ip3] = P1;
+ vec2ds.removeAt(ip1);
+ vec2ds.removeAt(ip1);
+ smooth();
+ break;
+ }
+ else {
+ if ( bDebug ) {
+ if ( element1 ) qDebug() <<"Intersection 1 avec : "<< element1 -> name();
+ if ( element2 ) qDebug() <<"Intersection 2 avec : "<< element2 -> name();
+ }
+ }
+ }
+
+ }
+}
+
+
+
+/*
+"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
@@ -451,6 +1278,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
@@ -515,6 +1346,35 @@
qp -> drawEllipse(QRectF(point.x() - pretty_offset, point.y() - pretty_offset, 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 = QString::number(i,10) +":"+ QString::number( (int)pt.x ) +", "+ QString::number( (int)pt.y );
+ qp -> drawText( coordText, text );
+ prevPt = pt;
+ }
+ }
+
qp -> restore();
}
@@ -712,9 +1572,9 @@
@param e Le QGraphicsSceneHoverEvent decrivant l'evenement
*/
void Conductor::hoverMoveEvent(QGraphicsSceneHoverEvent *e) {
- /*
+
if (isSelected()) {
- QPointF hover_point = mapFromScene(e -> pos());
+ QPointF hover_point = mapFromScene(e -> pos()) + scenePos();
ConductorSegment *segment = segments;
bool cursor_set = false;
while (segment -> hasNextSegment()) {
@@ -729,7 +1589,7 @@
}
if (!cursor_set) setCursor(Qt::ArrowCursor);
}
- */
+
QGraphicsPathItem::hoverMoveEvent(e);
}
Modified: branches/conductor2/sources/qetgraphicsitem/conductor.h
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/conductor.h 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/qetgraphicsitem/conductor.h 2014-11-16 20:55:39 UTC (rev 3495)
@@ -19,6 +19,7 @@
#define CONDUCTOR_H
#include "conductorproperties.h"
+#include "Mathlib.h"
class ConductorProfile;
class ConductorSegmentProfile;
@@ -171,6 +172,35 @@
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);
+ 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 updateConductorPath2(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation);
+
uint segmentsCount(QET::ConductorSegmentType = QET::Both) const;
QList<QPointF> segmentsToPoints() const;
QList<ConductorBend> bends() const;
@@ -187,6 +217,29 @@
static qreal conductor_bound(qreal, qreal, bool);
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 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/conductor2/sources/qetgraphicsitem/conductortextitem.h
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/conductortextitem.h 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/qetgraphicsitem/conductortextitem.h 2014-11-16 20:55:39 UTC (rev 3495)
@@ -68,5 +68,8 @@
bool moved_by_user_;
bool rotate_by_user_;
QPointF before_mov_pos_;
+
+
+
};
#endif
Modified: branches/conductor2/sources/qetgraphicsitem/diagramtextitem.cpp
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/diagramtextitem.cpp 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/qetgraphicsitem/diagramtextitem.cpp 2014-11-16 20:55:39 UTC (rev 3495)
@@ -73,6 +73,7 @@
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
#endif
connect(this, SIGNAL(lostFocus()), this, SLOT(setNonFocusable()));
+ setAcceptHoverEvents(true);
}
/**
@@ -213,7 +214,8 @@
@param widget Le QWidget sur lequel on dessine
*/
void DiagramTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
- painter -> setRenderHint(QPainter::Antialiasing, false);
+ painter -> setRenderHint(QPainter::Antialiasing, true);
+ //option->
QGraphicsTextItem::paint(painter, option, widget);
if ( bMouseOver ) {
@@ -232,7 +234,6 @@
painter -> drawRoundRect(boundingRect().adjusted(0, 0, 0, 0), 10, 10);
painter -> restore();
}
-
}
/**
Modified: branches/conductor2/sources/qetgraphicsitem/diagramtextitem.h
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/diagramtextitem.h 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/qetgraphicsitem/diagramtextitem.h 2014-11-16 20:55:39 UTC (rev 3495)
@@ -101,5 +101,6 @@
bool no_editable;
bool m_first_move;
QPointF m_mouse_to_origin_movement;
+
};
#endif
Modified: branches/conductor2/sources/qetgraphicsitem/element.cpp
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/element.cpp 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/qetgraphicsitem/element.cpp 2014-11-16 20:55:39 UTC (rev 3495)
@@ -85,7 +85,7 @@
@param widget Le widget sur lequel on dessine
*/
void Element::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget) {
-
+
#ifndef Q_WS_WIN
// corrige un bug de rendu ne se produisant que lors du rendu sur QGraphicsScene sous X11 au zoom par defaut
static bool must_correct_rendering_bug = QETApp::settings().value("correct-rendering", false).toBool();
@@ -100,6 +100,7 @@
}
}
#endif
+
if (must_highlight_) drawHighlight(painter, options);
// Dessin de l'element lui-meme
@@ -115,10 +116,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.
@@ -195,6 +205,7 @@
* @param angle
*/
void Element::rotateBy(const qreal &angle) {
+ qDebug() << "Rotation : " << angle;
qreal applied_angle = QET::correctAngle(angle);
applyRotation(applied_angle + rotation());
@@ -263,7 +274,8 @@
t.setStyle(Qt::DashDotLine);
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();
}
@@ -289,7 +301,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/conductor2/sources/qetgraphicsitem/element.h
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/element.h 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/qetgraphicsitem/element.h 2014-11-16 20:55:39 UTC (rev 3495)
@@ -150,6 +150,7 @@
virtual void setHighlighted(bool);
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
QRectF boundingRect() const;
+ QRectF boundingRectTrue() const;
QSize setSize(int, int);
QSize size() const;
QPixmap pixmap();
@@ -181,6 +182,7 @@
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
private:
+ bool bMouseHover;
bool internal_connections_;
bool must_highlight_;
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
Modified: branches/conductor2/sources/qetgraphicsitem/terminal.cpp
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/terminal.cpp 2014-11-16 20:51:46 UTC (rev 3494)
+++ branches/conductor2/sources/qetgraphicsitem/terminal.cpp 2014-11-16 20:55:39 UTC (rev 3495)
@@ -405,7 +405,8 @@
// on s'arrete la s'il n'est pas possible de relier les bornes
if (!canBeLinkedTo(other_terminal)) return;
// autrement, on pose un conducteur
- Conductor *new_conductor = new Conductor(this, other_terminal);
+ //Conductor *new_conductor = new Conductor(this, other_terminal);
+ Conductor *new_conductor = new Conductor(this, other_terminal, d);
new_conductor -> setProperties(d -> defaultConductorProperties);
d -> undoStack().push(new AddItemCommand<Conductor *>(new_conductor, d));
new_conductor -> autoText();
Added: branches/conductor2/sources/qetgraphicsitem/waypoint.cpp
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/waypoint.cpp (rev 0)
+++ branches/conductor2/sources/qetgraphicsitem/waypoint.cpp 2014-11-16 20:55:39 UTC (rev 3495)
@@ -0,0 +1,28 @@
+/*
+ * waypoint.cpp
+ *
+ * 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/conductor2/sources/qetgraphicsitem/waypoint.h
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/waypoint.h (rev 0)
+++ branches/conductor2/sources/qetgraphicsitem/waypoint.h 2014-11-16 20:55:39 UTC (rev 3495)
@@ -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_ */