|
From: <ma...@us...> - 2011-01-23 20:20:02
|
Revision: 270
http://openautomation.svn.sourceforge.net/openautomation/?rev=270&view=rev
Author: mayerch
Date: 2011-01-23 20:19:55 +0000 (Sun, 23 Jan 2011)
Log Message:
-----------
Even more unification of the connection moving code
Modified Paths:
--------------
PyWireGate/trunk/logic_editor/gle/gle.block.js
PyWireGate/trunk/logic_editor/gle/gle.connection.js
Modified: PyWireGate/trunk/logic_editor/gle/gle.block.js
===================================================================
--- PyWireGate/trunk/logic_editor/gle/gle.block.js 2011-01-23 17:45:51 UTC (rev 269)
+++ PyWireGate/trunk/logic_editor/gle/gle.block.js 2011-01-23 20:19:55 UTC (rev 270)
@@ -263,7 +263,7 @@
//if( 'connection' in this )
if( this.connection !== undefined )
{
- this.connection.lastMove( that.inPortPos( i )[0], true );
+ this.connection.move( 0, -1, that.inPortPos( i )[0], false, false );
}
});
@@ -376,7 +376,7 @@
that.setConnection( pt, pn,c );
///???
var parameter = {con:c};
-
+ console.log('editorConnectionPointDrag', [op.x, op.y]);
$(document).bind( 'mousemove', parameter, editorConnectionPointMouseMove );
$(document).bind( 'mouseup' , parameter, editorConnectionPointMouseUp );
@@ -385,7 +385,7 @@
function editorConnectionPointMouseMove( event )
{
- event.data.con.lastMove( getCoordinate( event ) );
+ event.data.con.move( 0, -1, getCoordinate( event ), false, true );
}
function editorConnectionPointMouseUp( event )
Modified: PyWireGate/trunk/logic_editor/gle/gle.connection.js
===================================================================
--- PyWireGate/trunk/logic_editor/gle/gle.connection.js 2011-01-23 17:45:51 UTC (rev 269)
+++ PyWireGate/trunk/logic_editor/gle/gle.connection.js 2011-01-23 20:19:55 UTC (rev 270)
@@ -119,6 +119,7 @@
};
lastFixed = path.length - 1;
+ lastPoint = undefined;
/*
if( extend )
@@ -140,9 +141,9 @@
//console.log('cDMM', ed );
if( ed.extend )
{
- that.lastMove( pos, false );
+ that.move( ed.obj[1], -1, pos, false, true );
} else {
- that.move( ed.obj[1], ed.obj[2], pos, false );
+ that.move( ed.obj[1], ed.obj[2], pos, false, false );
}
}
@@ -161,43 +162,120 @@
/**
* Move the selected point
- * path : the path number
+ * branch: the path number
* i : the number of the point (-1 = last point)
* pos : the new position
* freely: if true, ignore line alignment
+ * extend: continue connection to pos
*/
- this.move = function( path, i, pos, freely )
+ var lastPoint = undefined;
+ this.move = function( branch, i, pos, freely, extend )
{
// FIXME: convert doring the transition period
if( ! 'x' in pos ) pos = { x: pos[0], y: pos[1] };
+ if( i < 0 ) i = paths[ branch ].path.length - 1;
+ var isLast = (i == paths[ branch ].path.length - 1);
if( freely )
{
- if( i < 0 ) i = paths[ path ].path.length - 1;
- paths[ path ].path[ i ] = [ pos.x, pos.y ];
+ paths[ branch ].path[ i ] = [ pos.x, pos.y ];
draw();
return;
}
- var path = paths[ path ].path; // recycle
+ var path = paths[ branch ].path; // recycle
var i = parseInt( i ); // force cast
- if( path[i-1] !== undefined )
+ if( extend )
{
- if( Math.abs( path[i-1][0] - path[i][0] ) < 1.0 )
- path[i-1][0] = pos.x;
- if( Math.abs( path[i-1][1] - path[i][1] ) < 1.0 )
- path[i-1][1] = pos.y;
+ if( lastPoint === undefined ) lastPoint = [ path[ i ][0], path[ i ][1] ];
+ while( path.length > lastFixed+1 )
+ path.pop();
+ i = path.length - 1;
+ var dir = 0; // 0 = lr, 1 = td, 2 = rl, 3 = dt
+ if( path[i-1] !== undefined )
+ {
+ if( Math.abs( path[i-1][0] - path[i][0] ) < 1.0 ) // vertical
+ {
+ if( path[i-1][1] < path[i][1] )
+ dir = 1;
+ else
+ dir = 3;
+ } else { // assume horizontal
+ if( path[i-1][0] < path[i][0] )
+ dir = 0;
+ else
+ dir = 2;
+ }
+ } else { // this is the staring point => query block!
+ // FIXME - implement!
+ path[1] = [ path[0][0], path[0][1] ]; i++;
+ }
+ //console.log( 'extend', dir, i, path.length, lastFixed, path, lastPoint );
+ var op = overPort;
+ if( op && op.type == 'inPort' )
+ {
+ pos = op.block.inPortPos( op.number )[0];
+ paths[branch].target = op;
+ } else
+ paths[branch].target = undefined;
+
+ switch( dir )
+ {
+ case 0:
+ if( pos.x < lastPoint[0] )
+ {
+ path[i][0] = lastPoint[0];
+ path.push( [ lastPoint[0], pos.y ] );
+ } else
+ path[i][0] = pos.x;
+ break;
+
+ case 1:
+ if( pos.y < lastPoint[1] )
+ {
+ path[i][1] = lastPoint[1];
+ path.push( [ pos.x, lastPoint[1] ] );
+ } else
+ path[i][1] = pos.y;
+ break;
+
+ case 2:
+ if( pos.x > lastPoint[0] )
+ {
+ path[i][0] = lastPoint[0];
+ path.push( [ lastPoint[0], pos.y ] );
+ } else
+ path[i][0] = pos.x;
+ break;
+
+ case 3:
+ if( pos.y > lastPoint[1] )
+ {
+ path[i][1] = lastPoint[1];
+ path.push( [ pos.x, lastPoint[1] ] );
+ } else
+ path[i][1] = pos.y;
+ break;
+ }
+ path.push( [ pos.x, pos.y ] );
+ } else {
+ if( path[i-1] !== undefined )
+ {
+ if( Math.abs( path[i-1][0] - path[i][0] ) < 1.0 )
+ path[i-1][0] = pos.x;
+ if( Math.abs( path[i-1][1] - path[i][1] ) < 1.0 )
+ path[i-1][1] = pos.y;
+ }
+ if( path[i+1] !== undefined )
+ {
+ if( Math.abs( path[i+1][0] - path[i][0] ) < 1.0 )
+ path[i+1][0] = pos.x;
+ if( Math.abs( path[i+1][1] - path[i][1] ) < 1.0 )
+ path[i+1][1] = pos.y;
+ }
+ path[i][0] = pos.x;
+ path[i][1] = pos.y;
}
- if( path[i+1] !== undefined )
- {
- if( Math.abs( path[i+1][0] - path[i][0] ) < 1.0 )
- path[i+1][0] = pos.x;
- if( Math.abs( path[i+1][1] - path[i][1] ) < 1.0 )
- path[i+1][1] = pos.y;
- }
- path[i][0] = pos.x;
- path[i][1] = pos.y;
-
// simplify path, i.e. delete double points
for( var j = path.length-1; j > 0; j-- )
{
@@ -212,33 +290,6 @@
draw();
}
- this.lastMove = function( pos, force )
- {
- //this.move( 0, -1, pos, false ); return; // FIXME: change to move and then delete method
- if( lastFixed < 0 ) lastFixed = 0; // sanity check...
- while( paths[branch].path.length > lastFixed+1 )
- paths[branch].path.pop();
- var start = paths[branch].path[ paths[branch].path.length - 1 ];
- var op = overPort;
- if( !force && op && op.type == 'inPort' )
- {
- pos = op.block.inPortPos( op.number )[0];
- }
- if( force || (op && op.type == 'inPort') )
- {
- paths[branch].target = op;
- if( Math.abs( start[1] - pos.y ) > 1.0 )
- paths[branch].path.push( [ (pos.x+start[0])/2, start[1] ] );
- paths[branch].path.push( [ (pos.x+start[0])/2, pos.y ] );
- } else {
- paths[branch].target = undefined;
- if( Math.abs( start[1] - pos.y ) > 1.0 )
- paths[branch].path.push( [ pos.x, start[1] ] );
- }
- paths[branch].path.push( [pos.x, pos.y] );
- draw();
- }
-
this.lastTarget = function()
{
return paths[branch].target;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|