@ -1861,16 +1861,89 @@ function onMouseDown(event) {
//movePath = ;
//if( movePath ) MaskProject.activeLayer.addChild(hitResult.item);
}
function onMouseMove ( event ) {
MaskProject . activeLayer . selected = false ;
if ( event . item ) {
//event.item.selected = true;
event . item . fullySelected = true ;
var c_m_X = 0 ;
var c_m_Y = 0 ;
function onMouseMove ( e ) {
//e.preventDefault();
//e.stopPropagation();
var mx = parseInt ( e . offsetX - deviceMapLeftShift ) ;
var my = parseInt ( e . offsetY - deviceMapTopShift ) ;
if ( ( mx != c_m_X ) || ( my != c_m_Y ) ) {
c_m_X = mx ;
c_m_Y = my ;
var t = Ext . getCmp ( 'me_coords_panel' ) ;
if ( t != undefined ) {
var k = 2048 / ( cMapImageWidth ) ;
var j = 2048 / ( cMapImageHeight ) ;
var jaja = parseInt ( mx * k - 1024 ) ;
var juju = parseInt ( my * j - 1024 ) ;
if ( juju != 0 ) {
if ( juju < 0 ) {
az = ( Math . atan ( jaja / juju ) * ( 180 / Math . PI ) + 90 ) . toFixed ( 1 ) ;
} else {
az = ( Math . atan ( jaja / juju ) * ( 180 / Math . PI ) + 270 ) . toFixed ( 1 ) ;
} ;
} else {
if ( jaja < 0 ) {
az = 90 ;
} else {
az = 270 ;
} ;
} ;
range = ( ( ME_max_range / 1024 ) * Math . sqrt ( Math . pow ( jaja , 2 ) + Math . pow ( juju , 2 ) ) ) . toFixed ( 2 ) ;
t . update ( '<b>Range:' + range + ' m. Azimuth:' + az + '°</b>' ) ;
} ;
} ;
}
function onPathMouseMove ( event ) {
//event.preventDefault();
//event.stopPropagation();
var mx = event . point . x - deviceMapLeftShift ;
var my = event . point . y - deviceMapTopShift ;
if ( ( mx != c_m_X ) || ( my != c_m_Y ) ) {
c_m_X = mx ;
c_m_Y = my ;
var t = Ext . getCmp ( 'me_coords_panel' ) ;
if ( t != undefined ) {
t . update ( '<b>' + c_m_X + 'x' + c_m_Y + '</b>' ) ;
} ;
} ;
//MaskProject.activeLayer.selected = false;
//if( event.item ) {
//event.item.selected = true;
// event.item.fullySelected = true;
//};
}
function onMouseDrag ( event ) {
var mx = event . point . x - deviceMapLeftShift ;
var my = event . point . y - deviceMapTopShift ;
if ( ( mx != c_m_X ) || ( my != c_m_Y ) ) {
c_m_X = mx ;
c_m_Y = my ;
var t = Ext . getCmp ( 'me_coords_panel' ) ;
if ( t != undefined ) {
var k = 2048 / ( cMapImageWidth ) ;
var j = 2048 / ( cMapImageHeight ) ;
var jaja = parseInt ( c_m_X * k - 1024 ) ;
var juju = parseInt ( c_m_Y * j - 1024 ) ;
if ( juju != 0 ) {
if ( juju < 0 ) {
az = ( Math . atan ( jaja / juju ) * ( 180 / Math . PI ) + 90 ) . toFixed ( 1 ) ;
} else {
az = ( Math . atan ( jaja / juju ) * ( 180 / Math . PI ) + 270 ) . toFixed ( 1 ) ;
} ;
} else {
if ( jaja < 0 ) {
az = 90 ;
} else {
az = 270 ;
} ;
} ;
range = ( ( ME_max_range / 1024 ) * Math . sqrt ( Math . pow ( jaja , 2 ) + Math . pow ( juju , 2 ) ) ) . toFixed ( 2 ) ;
t . update ( '<b>Range:' + range + ' m. Azimuth:' + az + '°</b>' ) ;
} ;
} ;
if ( segment ) {
//segment.point += event.delta;
segment . point = event . point ;
@ -1930,13 +2003,12 @@ function doMaskOperation( NodeID, Cmd, Mid = 0, LRFID = 0 ){
LID : LRFID
} ,
success : function ( response , opts ) {
//var data = Ext.decode(response.responseText);
//hideMaskEditor();
load2DMasks ( NodeID ) ;
} ,
failure : failureAJAXFunction
} ) ;
}
var ME_max_range = 100 ;
function showMaskEditor ( fromDevTool , DevType , NodeID ) {
//alert( "DevType: "+DevType + " Dev Map size: "+ absDrawMapSizes[DevType][0]+"x"+absDrawMapSizes[DevType][1] );
cMapType = DevType ;
@ -1965,6 +2037,7 @@ function showMaskEditor( fromDevTool, DevType, NodeID ){
maskEditorDiv = document . createElement ( "div" ) ;
maskEditorDiv . style . height = "200px" ;
maskEditorDiv . style . width = "200px" ;
maskEditorDiv . style . position = "relative" ;
//var svg = document.getElementById('draw_svg_'+parseInt( NodeID ) );
//var svgCode = window.btoa(svg.outerHTML);
//maskEditorDiv.style.background = "url(data:image/svg+xml;base64," + svgCode + ")";
@ -1991,48 +2064,24 @@ function showMaskEditor( fromDevTool, DevType, NodeID ){
items : [ {
xtype : 'panel' ,
width : cMapCanvasWidth ,
html : '<div id=\'popomas\' style="display: block; width: ' + cMapCanvasWidth + 'px; height: ' + cMapCanvasHeight + 'px; background: orange; background-position-x: ' + deviceMapLeftShift + 'px; background-position-y: ' + deviceMapTopShift + 'px; background-size: ' + cMapImageWidth + 'px ' + cMapImageHeight + 'px; background-image: url(\'/lib/controller/getDeviceDraw.php?MAP=1&NID=' + NodeID + '\'); background-repeat: no-repeat;"><canvas id="mask_canvas" width="' + cMapCanvasWidth + 'px" height="' + cMapCanvasHeight + 'px"></canvas></dvi>' ,
//html: '<div id=\'popomas\' style="display: block; width: '+cMapCanvasWidth+'px; height: '+cMapCanvasHeight+ 'px; background: orange; background-position-x: '+deviceMapLeftShift+'px; background-position-y: '+deviceMapTopShift+'px; background-size: '+cMapImageWidth+'px '+cMapImageHeight+'px; background-image: url(\'/lib/controller/getDeviceDraw.php?MAP=1&NID='+NodeID+'\'); background-repeat: no-repeat; z-index:10;"><canvas id="mask_canvas" width="'+cMapCanvasWidth+'px" height="'+cMapCanvasHeight+'px"></canvas></dvi>',
html : '<div id="popomas" style="display: block; width: ' + cMapCanvasWidth + 'px; height: ' + cMapCanvasHeight + 'px; position: relative; top:0; left:0; z-index: 1000;"><canvas id="mask_canvas" width="' + cMapCanvasWidth + 'px" height="' + cMapCanvasHeight + 'px"></canvas></div><div id="baka" style="background:orange;display:block;width: ' + cMapCanvasWidth + 'px; height: ' + cMapCanvasHeight + 'px; position:absolute;top:0; left:0; z-index:0;"><svg id="draw_svg_me" opacity="1.0" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="' + cMapImageWidth + '" height="' + cMapImageHeight + '" version="1.1" style="position: relative; top:' + deviceMapTopShift + '; left:' + deviceMapLeftShift + '; z-index:0; shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd;" viewBox="0 0 574 574" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><clipPath id="me_mask"><circle cx="287" cy="287" r="284"/></clipPath></defs><circle fill="#00A859" stroke="#373435" stroke-width="5.92139" cx="287" cy="287" r="284"/><line fill="none" stroke="#FFF212" stroke-width="1" x1="287" y1="3" x2="287" y2="571"/><line fill="none" stroke="#FFF212" stroke-width="1" x1="3" y1="287" x2="571" y2="287"/><circle fill="none" stroke="#373435" stroke-width="1" cx="287" cy="287" r="284"/></svg></div>' ,
listeners : {
afterrender : function ( ) {
//Doing a custom svg here for background!
var chicha = document . getElementById ( 'popomas' ) ;
var svg = document . getElementById ( 'draw_svg_' + parseInt ( NodeID ) ) ;
var svgCode = window . btoa ( svg . outerHTML ) ;
chicha . style . backgroundImage = "url(data:image/svg+xml;base64," + svgCode + ")" ;
var cSensor = getSensorByNodeId ( NodeID ) ;
if ( cSensor != null ) {
ME_max_range = cSensor . max_range ;
} else {
ME_max_range = 100 ;
} ;
//var svg = document.getElementById('draw_svg_'+parseInt( NodeID ) );
//var svgCode = window.btoa(svg.outerHTML);
//chicha.style.backgroundImage = "url(data:image/svg+xml;base64," + svgCode + ")";
//chicha.style.backgroundImage = "url('style/wicons/011.png')";
//alert( NodeID );
/ *
var svg = document . querySelector ( '#svg' ) ;
var svgCode = encodeURI ( svg . outerHTML ) ;
element . style . backgroundImage = "url(data:image/svg+xml;utf8," + svgCode + ")" ;
function set_gridSize ( num ) {
num = Number ( num ) ;
var xml = '<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><defs><pattern id="smallGrid" width="10" height="10" patternUnits="userSpaceOnUse"><path d="M 10 0 L 0 0 0 10" fill="none" stroke="gray" stroke-width="0.5"/> </pattern><pattern id="grid" width="100" height="100" patternUnits="userSpaceOnUse"><rect width="100" height="100" fill="url(#smallGrid)"/><path d="M 100 0 L 0 0 0 100" fill="none" stroke="gray" stroke-width="1"/></pattern></defs><rect width="100%" height="100%" fill="url(#grid)" /></svg>' ;
var data = $ ( $ . parseXML ( xml ) ) ;
var defs = data . children ( "svg" ) . children ( "defs" ) ;
defs . children ( "#smallGrid" ) . attr ( { height : num , width : num } ) ;
var path = defs . children ( "#smallGrid" ) . children ( ) . attr ( "d" ) ;
var arr = path . split ( " " ) ;
arr [ 1 ] = num ;
arr [ arr . length - 1 ] = num ;
path = arr . join ( " " ) ;
defs . children ( "#smallGrid" ) . children ( "path" ) . attr ( "d" , path )
defs . children ( "#grid" ) . attr ( { height : num * 10 , width : num * 10 } ) ;
defs . children ( "#grid" ) . children ( "rect" ) . attr ( { height : num * 10 , width : num * 10 } ) ;
var path = defs . children ( "#grid" ) . children ( "path" ) . attr ( "d" ) ;
var arr = path . split ( " " ) ;
arr [ 1 ] = num * 10 ;
arr [ arr . length - 1 ] = num * 10 ;
path = arr . join ( " " ) ;
defs . children ( "#grid" ) . children ( "path" ) . attr ( "d" , path ) ;
return "url(data:image/svg+xml;base64," + Base64 . encode ( new XMLSerializer ( ) . serializeToString ( defs . parent ( ) [ 0 ] ) ) + ")" ;
} ; * /
$ ( "#mask_canvas" ) . mousemove ( onMouseMove ) ;
loadMaskDraw ( NodeID ) ;
}
}
} ] ,
@ -2136,6 +2185,14 @@ function showMaskEditor( fromDevTool, DevType, NodeID ){
cMaskID = 4 ;
loadDeviceMask ( NodeID , cMaskID ) ;
}
} , '->' , {
xtype : 'panel' ,
frame : 'false' ,
id : 'me_coords_panel' ,
border : true ,
width : 230 ,
height : 30 ,
html : '<p style="color: white;">kook</p>'
} ] ,
buttons : [ {
text : 'Cancel' ,
@ -2159,11 +2216,13 @@ function showMaskEditor( fromDevTool, DevType, NodeID ){
MIW : cMapImageWidth ,
//MSF: deviceMapScaling,
MSHX : deviceMapLeftShift ,
MSHY : deviceMapTopShift
MSHY : deviceMapTopShift ,
DSTD : 0
} ,
success : function ( response , opts ) {
var data = Ext . decode ( response . responseText ) ;
hideMaskEditor ( ) ;
load2DMasks ( NodeID ) ;
} ,
failure : failureAJAXFunction
} ) ;
@ -2199,6 +2258,73 @@ function showMaskEditor( fromDevTool, DevType, NodeID ){
} ;
} ;
function loadMaskDraw ( a ) {
Ext . Ajax . request ( {
url : '/lib/controller/getDeviceDraw.php' ,
params : {
UID : < ? = $UserID ; ? > ,
SID : '<?=$Session;?>' ,
NID : a
} ,
success : function ( response , opts ) {
var data = Ext . decode ( response . responseText ) ;
if ( data . count > 0 ) {
//draws_2d[a] = data.data;
var csvg = document . getElementById ( 'draw_svg_me' ) ;
if ( csvg != undefined ) {
var draw = csvg . getElementById ( "draw" ) ;
if ( draw != null ) csvg . removeChild ( draw ) ;
var p2 = 2.0 * Math . PI ;
var so = - 10 * p2 / 360.0 ;
var bBox = csvg . getBBox ( ) ;
var newpath = document . createElementNS ( 'http://www.w3.org/2000/svg' , "polygon" ) ;
var ak = 2.0 * Math . PI / draws_2d [ a ] . length ;
var cpx = bBox . width / 2.0 ;
var cpy = bBox . height / 2.0 ;
var max = 1024 ;
//switch( drawZoomLevels[a] ){
// case 50: max = 512; break;
// case 25: max = 256; break;
// case 12: max = 128; break;
//};
var rk = bBox . width / ( max * 2 ) ;
var pp = '' ;
var jj = '' ;
for ( i = 0 ; i < data . data . length ; i ++ ) {
var cc = Math . cos ( p2 - ak * i - so ) ;
var cs = Math . sin ( p2 - ak * i - so ) ;
za = cpx + cpx * cc ;
zb = cpy + cpx * cs ;
if ( data . data [ i ] . M == 0 ) {
x = za ; y = zb ;
} else {
if ( data . data [ i ] . M < max ) {
x = cpx + data . data [ i ] . M * rk * cc ;
y = cpy + data . data [ i ] . M * rk * cs ;
} else {
x = za ; y = zb ;
} ;
} ;
pp += ' ' + za + ',' + zb ;
jj += ' ' + x + ',' + y ;
} ;
pp += jj ;
newpath . setAttributeNS ( null , "points" , pp ) ;
newpath . setAttributeNS ( null , "fill" , "#044B94" ) ;
newpath . setAttributeNS ( null , "fill-opacity" , "0.4" ) ;
newpath . setAttributeNS ( null , "id" , "draw" ) ;
csvg . appendChild ( newpath ) ;
} ;
} ;
} ,
failure : failureAJAXFunction
} ) ;
} ;
function setMaskEditorMode ( nM ) {
switch ( nM ) {
case 0 : {
@ -2278,7 +2404,7 @@ function loadDeviceMask( NodeID, LayerID = 0, LrfID = 0 ){
path . fillColor = data [ i ] . colour ;
path . closed = true ;
path . opacity = 0.5 ;
//path.onMouseMove = onMouseMove;
//path.onMouseMove = onPath MouseMove;
path . onMouseDown = onMouseDown ;
path . onMouseDrag = onMouseDrag ;
//path.onMouseUp = function( event ){
@ -2326,7 +2452,7 @@ function onMaskMouseDown( evt ){
path . fillColor = '#ff8020' ;
path . onMouseDown = onMouseDown ;
path . onMouseDrag = onMouseDrag ;
//path.onMouseMove = onMouseMove;
//path.onMouseMove = onPath MouseMove;
path . fullySelected = true ;
path . closed = true ;
path . opacity = 0.5 ;
@ -2354,6 +2480,7 @@ function onMaskMouseUp( evt ){
path . fullySelected = true ;
path . onMouseDown = onMouseDown ;
path . onMouseDrag = onMouseDrag ;
//path.onMouseMove = onPathMouseMove;
paper . view . draw ( ) ;
//poligones.push( path );
setMaskEditorMode ( 1 ) ;