mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Revert r3492
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3493 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -27,31 +27,12 @@
|
||||
#include "terminal.h"
|
||||
#include "conductorautonumerotation.h"
|
||||
#include "conductorpropertiesdialog.h"
|
||||
#include "../qetapp.h"
|
||||
#include "binarygrid.h"
|
||||
|
||||
#define PR(x) qDebug() << #x " = " << x;extend
|
||||
#define PR(x) qDebug() << #x " = " << x;
|
||||
|
||||
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
|
||||
@@ -118,7 +99,6 @@ Conductor::Conductor(Terminal *p1, Terminal* p2, Diagram *parent_diagram) :
|
||||
this,
|
||||
SLOT(displayedTextChanged())
|
||||
);
|
||||
bMouseOver = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,11 +171,6 @@ void Conductor::updateConductorPath(const QPointF &p1, Qet::Orientation o1, cons
|
||||
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");
|
||||
@@ -321,11 +296,6 @@ QHash<ConductorSegmentProfile *, qreal> Conductor::shareOffsetBetweenSegments(
|
||||
@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;
|
||||
|
||||
@@ -421,477 +391,6 @@ void Conductor::generateConductorPath(const QPointF &p1, Qet::Orientation o1, co
|
||||
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
|
||||
@@ -914,336 +413,10 @@ QPointF Conductor::extendTerminal(const QPointF &terminal, Qet::Orientation term
|
||||
case Qet::West:
|
||||
extended_terminal = QPointF(terminal.x() - ext_size, terminal.y());
|
||||
break;
|
||||
default: extended_terminal = terminal; break;
|
||||
default: extended_terminal = terminal;
|
||||
}
|
||||
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.
|
||||
@@ -1278,10 +451,6 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi
|
||||
|
||||
// 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
|
||||
@@ -1346,35 +515,6 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -1572,9 +712,9 @@ void Conductor::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) {
|
||||
@param e Le QGraphicsSceneHoverEvent decrivant l'evenement
|
||||
*/
|
||||
void Conductor::hoverMoveEvent(QGraphicsSceneHoverEvent *e) {
|
||||
|
||||
/*
|
||||
if (isSelected()) {
|
||||
QPointF hover_point = mapFromScene(e -> pos()) + scenePos();
|
||||
QPointF hover_point = mapFromScene(e -> pos());
|
||||
ConductorSegment *segment = segments;
|
||||
bool cursor_set = false;
|
||||
while (segment -> hasNextSegment()) {
|
||||
@@ -1589,7 +729,7 @@ void Conductor::hoverMoveEvent(QGraphicsSceneHoverEvent *e) {
|
||||
}
|
||||
if (!cursor_set) setCursor(Qt::ArrowCursor);
|
||||
}
|
||||
|
||||
*/
|
||||
QGraphicsPathItem::hoverMoveEvent(e);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user