|
From: <ma...@us...> - 2011-01-14 20:52:58
|
Revision: 246
http://openautomation.svn.sourceforge.net/openautomation/?rev=246&view=rev
Author: mayerch
Date: 2011-01-14 20:52:51 +0000 (Fri, 14 Jan 2011)
Log Message:
-----------
Inital (not final!) support for extending unconnected connections
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-11 21:40:10 UTC (rev 245)
+++ PyWireGate/trunk/logic_editor/gle/gle.block.js 2011-01-14 20:52:51 UTC (rev 246)
@@ -222,7 +222,8 @@
}
$.each( inPorts, function(i){
- if( 'connection' in this )
+ //if( 'connection' in this )
+ if( this.connection !== undefined )
{
this.connection.lastMove( that.inPortPos( i ), true );
}
Modified: PyWireGate/trunk/logic_editor/gle/gle.connection.js
===================================================================
--- PyWireGate/trunk/logic_editor/gle/gle.connection.js 2011-01-11 21:40:10 UTC (rev 245)
+++ PyWireGate/trunk/logic_editor/gle/gle.connection.js 2011-01-14 20:52:51 UTC (rev 246)
@@ -40,6 +40,7 @@
var canvas = svg || $('#editor').svg('get');
var addEvent = interactive !== undefined ? interactive : true;
+ var inEdit = false;
var g = undefined; // link to the representation of the block in the DOM
// the private functions
@@ -70,8 +71,114 @@
parameter['stroke-dasharray'] = 'none';
var x = canvas.polyline( g, paths[i].path, parameter );
}
+
+ // shotcut
+ function connectionDrag( obj, handle )
+ {
+ $(handle).bind( 'mousedown', {obj:obj}, connectionDragMouseDown );
+ }
+
+ // Draw the handles
+ for( var i in paths )
+ {
+ for( var j in paths[i].path )
+ {
+ var x = paths[i].path[j][0];
+ var y = paths[i].path[j][1];
+ var style = '';
+ if( j == 0 || j == paths[i].path.length-1 ) style = 'opacity:0;';
+ if( inEdit && j == paths[i].path.length-1 ) style += 'display:none';
+ connectionDrag( [g,i,j], canvas.rect( g, x-outset, y-outset, 1+inset+outset, 1+inset+outset, {class:'move',style:style} ) );
+ }
+ }
+
}
+ function connectionDragMouseDown( event )
+ {
+ console.log( 'cDMD', event );
+ var classList = this.getAttribute('class').split(' ');
+ console.log( 'cDMD', classList );
+ console.log( 'cDMD', event.data.obj );
+
+ var path = paths[ event.data.obj[1] ].path;
+ var extend = event.data.obj[2] == path.length - 1
+ var parameter = {
+ obj : event.data.obj,
+ origx : path[ event.data.obj[2] ][0],
+ origy : path[ event.data.obj[2] ][1],
+ extend : extend,
+ startx : event.pageX,
+ starty : event.pageY
+ };
+
+ lastFixed = path.length - 1;
+
+ /*
+ if( extend )
+ {
+ this.style.display = 'none';
+ }
+ */
+ inEdit = true;
+
+ $(document).bind( 'mousemove', parameter, editorDragMouseMove );
+ $(document).bind( 'mouseup' , editorDragMouseUp );
+ return false;
+ }
+
+ function editorDragMouseMove( event )
+ {
+ var ed = event.data;
+ console.log('cDMM', ed );
+ if( ed.extend )
+ {
+ that.lastMove( [ed.origx - ed.startx + event.pageX, ed.origy - ed.starty + event.pageY], false );
+ } else {
+ paths[ed.obj[1]].path[ed.obj[2]][0] = ed.origx - ed.startx + event.pageX;
+ paths[ed.obj[1]].path[ed.obj[2]][1] = ed.origy - ed.starty + event.pageY;
+ draw();
+ }
+ /*
+ if( 'move' == event.data.type )
+ {
+ relocate(); // shortcut
+ } else {
+ if( width < 10 ) width = 10; // sanity...
+ if( height < 10 ) height = 10; // sanity...
+ draw();
+ }
+
+ $.each( inPorts, function(i){
+ if( 'connection' in this )
+ {
+ this.connection.lastMove( that.inPortPos( i ), true );
+ }
+ });
+
+ $.each( outPorts, function(i){
+ if( 'connection' in this )
+ {
+ this.connection.firstMove( that.outPortPos( i ) );
+ }
+ });
+ */
+ }
+
+ function editorDragMouseUp( event )
+ {
+ $(document).unbind( 'mousemove', editorDragMouseMove );
+ $(document).unbind( 'mouseup' , editorDragMouseUp );
+ inEdit = false;
+ var target = that.lastTarget();
+ if( target )
+ {
+ target.block.setConnection( target.type, target.number, that ); //event.data.con );
+ }
+ draw();
+ }
+
+
this.firstMove = function( pos )
{
if( paths[0].path[0][1] == paths[0].path[1][1] ) // keep horizontal line
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2011-01-23 17:45:59
|
Revision: 269
http://openautomation.svn.sourceforge.net/openautomation/?rev=269&view=rev
Author: mayerch
Date: 2011-01-23 17:45:51 +0000 (Sun, 23 Jan 2011)
Log Message:
-----------
First step at unification of connection moving
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 14:49:21 UTC (rev 268)
+++ PyWireGate/trunk/logic_editor/gle/gle.block.js 2011-01-23 17:45:51 UTC (rev 269)
@@ -270,7 +270,7 @@
$.each( outPorts, function(i){
if( 'connection' in this )
{
- this.connection.firstMove( that.outPortPos( i )[0] );
+ this.connection.move( 0, 0, that.outPortPos( i )[0] );
}
});
}
Modified: PyWireGate/trunk/logic_editor/gle/gle.connection.js
===================================================================
--- PyWireGate/trunk/logic_editor/gle/gle.connection.js 2011-01-23 14:49:21 UTC (rev 268)
+++ PyWireGate/trunk/logic_editor/gle/gle.connection.js 2011-01-23 17:45:51 UTC (rev 269)
@@ -142,36 +142,7 @@
{
that.lastMove( pos, false );
} else {
- var path = paths[ed.obj[1]].path;
- var i = parseInt( ed.obj[2] );
- 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;
- // simplify path, i.e. delete double points
- for( var j = path.length-1; j > 0; j-- )
- {
- if( i == j || i == j-1 ) continue; // don't delete current point
- if( Math.abs( path[j-1][0] - path[j][0] ) < 1.0 &&
- Math.abs( path[j-1][1] - path[j][1] ) < 1.0 )
- {
- path.splice( j-1, 2 );
- if( j < i ) ed.obj[2] -= 2;
- }
- }
- draw();
+ that.move( ed.obj[1], ed.obj[2], pos, false );
}
}
@@ -188,33 +159,62 @@
draw();
}
-
- this.firstMove = function( pos )
+ /**
+ * Move the selected point
+ * path : the path number
+ * i : the number of the point (-1 = last point)
+ * pos : the new position
+ * freely: if true, ignore line alignment
+ */
+ this.move = function( path, i, pos, freely )
{
- pos = [ pos.x, pos.y ]; // convert
- if( Math.abs( paths[0].path[0][1] - paths[0].path[1][1] ) < 1.0 ) // keep horizontal line
+ // FIXME: convert doring the transition period
+ if( ! 'x' in pos ) pos = { x: pos[0], y: pos[1] };
+
+ if( freely )
{
- paths[0].path[0] = pos;
- paths[0].path[1][1] = pos[1];
- } else {
- paths[0].path[0] = pos;
+ if( i < 0 ) i = paths[ path ].path.length - 1;
+ paths[ path ].path[ i ] = [ pos.x, pos.y ];
+ draw();
+ return;
}
- // remove obsolete points if the are the same now
- if( paths[0].path.length > 3 &&
- Math.abs( paths[0].path[1][0] - paths[0].path[2][0] ) < 1.0 &&
- Math.abs( paths[0].path[1][1] - paths[0].path[2][1] ) < 1.0 )
+
+ var path = paths[ path ].path; // recycle
+ var i = parseInt( i ); // force cast
+ if( path[i-1] !== undefined )
{
- //console.log( 'firstMove', paths[0].path.length );
- lastFixed -= 2;
- paths[0].path.shift(); // remove front
- paths[0].path.shift(); // remove first identical
- paths[0].path[0] = pos; // remove second identical by setting it to the first
+ 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;
+
+ // simplify path, i.e. delete double points
+ for( var j = path.length-1; j > 0; j-- )
+ {
+ if( i == j || i == j-1 ) continue; // don't delete current point
+ if( Math.abs( path[j-1][0] - path[j][0] ) < 1.0 &&
+ Math.abs( path[j-1][1] - path[j][1] ) < 1.0 )
+ {
+ path.splice( j-1, 2 );
+ //if( j < i ) ed.obj[2] -= 2;
+ }
+ }
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();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <ma...@us...> - 2011-01-23 21:17:43
|
Revision: 271
http://openautomation.svn.sourceforge.net/openautomation/?rev=271&view=rev
Author: mayerch
Date: 2011-01-23 21:17:35 +0000 (Sun, 23 Jan 2011)
Log Message:
-----------
clean up
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 20:19:55 UTC (rev 270)
+++ PyWireGate/trunk/logic_editor/gle/gle.block.js 2011-01-23 21:17:35 UTC (rev 271)
@@ -376,7 +376,6 @@
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 );
Modified: PyWireGate/trunk/logic_editor/gle/gle.connection.js
===================================================================
--- PyWireGate/trunk/logic_editor/gle/gle.connection.js 2011-01-23 20:19:55 UTC (rev 270)
+++ PyWireGate/trunk/logic_editor/gle/gle.connection.js 2011-01-23 21:17:35 UTC (rev 271)
@@ -33,8 +33,10 @@
var outset = 3; // how far should the handle stick out
// setup the private variables
- var origin = JSON.origin || undefined;
+ var origin = JSON.origin;
+ var originPortNumber = JSON.originPortNumber;
var paths = JSON.paths || [];
+ JSON = 0; // not needed anymore - get it out of the closure
var branch = 0; // the current branch to edit
var lastFixed = 0; // the last fixed position
@@ -173,9 +175,14 @@
{
// 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);
+ var path = paths[ branch ].path;
+ var orig_pos = origin.outPortPos( originPortNumber );
+ var i = parseInt( i ); // force cast
+
+ if( i < 0 ) i = path.length - 1;
+ //var isLast = (i == paths[ branch ].path.length - 1);
+
if( freely )
{
paths[ branch ].path[ i ] = [ pos.x, pos.y ];
@@ -183,8 +190,6 @@
return;
}
- var path = paths[ branch ].path; // recycle
- var i = parseInt( i ); // force cast
if( extend )
{
if( lastPoint === undefined ) lastPoint = [ path[ i ][0], path[ i ][1] ];
@@ -280,7 +285,7 @@
for( var j = path.length-1; j > 0; j-- )
{
if( i == j || i == j-1 ) continue; // don't delete current point
- if( Math.abs( path[j-1][0] - path[j][0] ) < 1.0 &&
+ if( Math.abs( path[j-1][0] - path[j][0] ) < 1.0 &&
Math.abs( path[j-1][1] - path[j][1] ) < 1.0 )
{
path.splice( j-1, 2 );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|