[qet] [3501] Netotyage de code |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 3501
Author: runsys
Date: 2014-11-22 10:22:41 +0100 (Sat, 22 Nov 2014)
Log Message:
-----------
Netotyage de code
Modified Paths:
--------------
branches/conductor2/sources/diagram.cpp
branches/conductor2/sources/qetgraphicsitem/Mathlib.h
branches/conductor2/sources/qetgraphicsitem/binarygrid.cpp
branches/conductor2/sources/qetgraphicsitem/conductor.cpp
branches/conductor2/sources/qetgraphicsitem/conductor.h
branches/conductor2/sources/qetgraphicsitem/waypoint.cpp
Modified: branches/conductor2/sources/diagram.cpp
===================================================================
--- branches/conductor2/sources/diagram.cpp 2014-11-20 05:38:02 UTC (rev 3500)
+++ branches/conductor2/sources/diagram.cpp 2014-11-22 09:22:41 UTC (rev 3501)
@@ -194,7 +194,7 @@
bool transmit_event = true;
if (!isReadOnly()) {
// detecte le relachement d'une touche de direction ( = deplacement d'elements)
- if ( e -> key() == Qt::Key_C) {
+ if ( e -> key() == Qt::Key_G) {
Conductor::bDebugGrid= !Conductor::bDebugGrid;
update();
}
@@ -202,6 +202,10 @@
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();
Modified: branches/conductor2/sources/qetgraphicsitem/Mathlib.h
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/Mathlib.h 2014-11-20 05:38:02 UTC (rev 3500)
+++ branches/conductor2/sources/qetgraphicsitem/Mathlib.h 2014-11-22 09:22:41 UTC (rev 3501)
@@ -45,6 +45,7 @@
#include <math.h>
#include <stdlib.h>
#include <QPointF>
+#include <QtDebug>
#define EPSILON 0.00000001
//#define M_PI 3.141592653589793238462643383279f // PI
@@ -171,7 +172,13 @@
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); }
Modified: branches/conductor2/sources/qetgraphicsitem/binarygrid.cpp
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/binarygrid.cpp 2014-11-20 05:38:02 UTC (rev 3500)
+++ branches/conductor2/sources/qetgraphicsitem/binarygrid.cpp 2014-11-22 09:22:41 UTC (rev 3501)
@@ -1,17 +1,53 @@
/*
- * binarygrid.cpp
- *
- * Created on: 8 nov. 2014
- * Author: rene
- */
+ 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
+ *
+ */
+
/*
*
*/
@@ -44,14 +80,7 @@
}
-/*
- *
- */
-void printVec2d( QString str, vec2d v ) {
- qDebug() << str <<" ("<< v.x <<","<< v.y <<")";
-}
-
/*
*
*/
@@ -79,6 +108,24 @@
+/*
+ *
+ */
+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() );
@@ -170,12 +217,15 @@
* for example x = 90
* mask = 0001 1111 1111
*
+ * it's a same result than computeFirstMask ... it's not a error !!!
+ * don't modify the function
+ *
* 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
+ * xor result = 0111 1111 0000 ..... magical
*
*/
void BinaryGrid::computeSecondMask( double d, U64* mask ) {
@@ -310,7 +360,12 @@
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;
+ 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;
@@ -323,11 +378,8 @@
*
*/
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();
@@ -337,8 +389,8 @@
int map;
vec2d vDir = vec2d( p1, p2 );
- if ( vDir.dot( vec2d(0.0,1.0) ) == 0 ) map = HORI;
- else map = VERT;
+ if ( vDir.dot( vec2d(0.0,1.0) ) == 0 ) map = VERT;
+ else map = HORI;
// compute mask 0 and mask 1
@@ -352,12 +404,15 @@
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 );
+ 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;
}
@@ -367,7 +422,6 @@
*
*/
bool BinaryGrid::computeMinSegment( vec2d p1, vec2d p2 ) {
- qDebug() <<"BinaryGrid::test";
orderVect( p1, p2 );
// printVec2d( "p1 : ", p1 );
Modified: branches/conductor2/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/conductor.cpp 2014-11-20 05:38:02 UTC (rev 3500)
+++ branches/conductor2/sources/qetgraphicsitem/conductor.cpp 2014-11-22 09:22:41 UTC (rev 3501)
@@ -27,7 +27,7 @@
#include "terminal.h"
#include "conductorautonumerotation.h"
#include "conductorpropertiesdialog.h"
-#include "../qetapp.h"
+#include "qetapp.h"
#include "binarygrid.h"
#define PR(x) qDebug() << #x " = " << x;extend
@@ -40,16 +40,17 @@
int vec2d::count = 0;
-bool Conductor::bAffPoint = true;
-bool Conductor::bSmooth = false;
-Conductor* Conductor::lastConductor = NULL;
+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;
-bool Conductor::bDebug = false;
-bool Conductor::bDebugGrid = false;
-int Conductor::iIndiceDebug = 0;
/**
@@ -437,18 +438,18 @@
-void Conductor::addPoint( vec2d p ) {
+void Conductor::addPoint( vec2d p, bool bTest ) {
vec2d vScenePos = vec2d(scenePos());
p -= vScenePos;
qDebug() << "Test Point : "<< currentIndice;
- if ( currentIndice > 1 ){
+ if ( currentIndice >= 2 && bTest ){
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;
+ qDebug()<< "Test TRUE intersection de "<< currentIndice-1 <<" à "<< currentIndice;
+// else
+// qDebug()<< "Test FALSE pas d'intersection de "<< currentIndice-1 <<" à "<< currentIndice;
}
}
@@ -464,10 +465,6 @@
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;
}
@@ -749,6 +746,8 @@
if ( bDebug ) {
qDebug() << "EvaluatePath : "<< test <<" sign "<< sign(vDir.addCoord());
+ printVec2d( " ori : ", ori );
+ printVec2d( " pt : ", pt );
}
if ( fabs(test) > 400.0 ) return;
@@ -757,7 +756,7 @@
vOrtho = vOrtho.vabs();
vec2d o = pt + test * vOrtho;
- vec2d p = o + 50.0 * vDir;
+ vec2d p = o + 10.0 * vDir;
if ( bDebug ) {
printDoubl( " evaluate t : ", test );
@@ -765,7 +764,7 @@
printVec2d( " evaluate o : ", o );
}
- intersectionElement( p, o, element );
+ Element * ret = intersectionElement( p, o, element );
if ( bDebug ) {
printVec2d( " evaluate p : ", p );
@@ -774,7 +773,8 @@
test += sign(test) * 10.0;
- if ( p == o )
+ //if ( p == o )
+ if ( ret )
evaluatePath( ori, pt, element, test );
else
pt = o;
@@ -855,7 +855,7 @@
double first = computeSensEvaluatePath( p1, newPoint, p2) * 10.0;
evaluatePath( p1, newPoint, element, first );
if ( svgEvalPt != newPoint ) {
- addPoint( svgEvalPt );
+ addPoint( svgEvalPt, true );
// on conserve la direction
return newPoint;
}
@@ -875,7 +875,7 @@
if ( newD1 == vec2d(0.0,0.0) ) {
newD1 = vD1.exch();
- addPoint( newPoint );
+ addPoint( newPoint,true );
newPoint += 60.0 * newD1;
newD1 = vD1;
@@ -977,6 +977,10 @@
*/
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);
@@ -1046,8 +1050,8 @@
//--------------------------
currentIndice = 0;
- addPoint( vec2d(sp1) + vScenePos );
- addPoint( newp1 );
+ addPoint( vec2d(sp1) + vScenePos, true );
+ addPoint( newp1, false );
vec2d newPt = newp1;
vec2d vo = orientation2vec2d(o1);
@@ -1076,7 +1080,7 @@
}
newPt = findNextPoint( newPt, vo, newp2, orientation2vec2d(o2) );
- addPoint( newPt );
+ addPoint( newPt, true );
if( currentIndice>=30 ) break;
}
@@ -1087,7 +1091,7 @@
}
//vec2ds << newp2;
- addPoint( vec2d(sp2) + vScenePos );
+ addPoint( vec2d(sp2) + vScenePos, false );
if ( bSmooth ) smooth();
// change vec2d to QPointF
@@ -1101,6 +1105,8 @@
diagram() -> _binaryGrid -> add2grid(this);
if ( Conductor::bDebugGrid ) diagram() -> _binaryGrid -> debugGrid();
+
+ qDebug() << "ComputeTime : "<< (double) timer.nsecsElapsed() / 1000000.0 << "ms";
}
@@ -1369,8 +1375,12 @@
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 );
+ QString text;
+ if ( Conductor::bAffCoord )
+ text = QString::number(i,10) +":"+ QString::number( (int)pt.x ) +", "+ QString::number( (int)pt.y );
+ else
+ text = QString::number(i,10);
+ qp -> drawText( coordText, text );
prevPt = pt;
}
}
@@ -1553,6 +1563,8 @@
Q_UNUSED(e);
segments_squares_scale_ = 2.0;
bMouseOver = true;
+ Conductor::lastConductor = this;
+
update();
}
Modified: branches/conductor2/sources/qetgraphicsitem/conductor.h
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/conductor.h 2014-11-20 05:38:02 UTC (rev 3500)
+++ branches/conductor2/sources/qetgraphicsitem/conductor.h 2014-11-22 09:22:41 UTC (rev 3501)
@@ -173,8 +173,8 @@
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 addPoint(vec2d, bool);
+ //void printVec2d( QString, vec2d );
void printDoubl( QString, double );
vec2d qPointF2vec2d( QPointF );
QPointF vec2d2qPointF( vec2d );
@@ -229,6 +229,7 @@
// Element elementParent2;
public:
static bool bAffPoint;
+ static bool bAffCoord;
static bool bSmooth;
static bool bDebug;
static bool bDebugGrid;
Modified: branches/conductor2/sources/qetgraphicsitem/waypoint.cpp
===================================================================
--- branches/conductor2/sources/qetgraphicsitem/waypoint.cpp 2014-11-20 05:38:02 UTC (rev 3500)
+++ branches/conductor2/sources/qetgraphicsitem/waypoint.cpp 2014-11-22 09:22:41 UTC (rev 3501)
@@ -1,8 +1,23 @@
/*
- * waypoint.cpp
- *
- * Created on: 6 nov. 2014
- * Author: rene
+ 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
*/