//**************************************************************** // icMap.js (_ic306.txt) // // Copyright (c) 2006 Clifford L. Collins // All rights are Reserved // // Collins Software // 7710 Janak Drive, Houston Texas // //---------------------------------------------------------------- // No distribution/publication/use of this code is permitted //**************************************************************** var clBlack = 0; var clTransparent = parseInt('0xf2f2f2'); var G; var SELECT_COLOR = '#FF8000'; var SELECT_WIDTH = '4'; var HANDLE_CENTER = -99; var HANDLE_ROTATE = -98; var HANDLE_RADIUS = -97; var RANGE_ID = -102; var Zgraphic = 150; var blinkLayer = null; var blinkSet = false; var blinkStatus = false; var blinkOn = true; //=================================================== // degree$ //=================================================== function degree$(angle) { var degree; var a,b; degree = (angle * 180.0) / Math.PI; return degree; } //======================================================================== // ic$userMap (Constructor) //======================================================================== function ic$userMap(name,view,height,width) { G = this; G.gid = 0; // Unique Graphic ID G.mode = 'select'; this.isSelect = false; this.isEdit = false; this.activeNode = null; G.modified = false; this.name = name; this.topFeature = null; this.freeGraphic = null; this.infoLink = ''; this.infoTag = ''; this.infoId = ''; this.modified = false; this.dbname = ''; // no Database Name Opened this.view = view; // mapping screen to real world this.height = height; this.width = width; this.cut = MAP$cut; this.copy = MAP$copy; this.selectAll = MAP$selectAll; this.paste = MAP$paste; this.drawSelected = MAP$drawSelected; this.startEdit = MAP$startEdit; this.undraw = MAP$undraw; this.isTable = false; this.clearLayer = MAP$clearLayer; this.curfea = null; this.promptSave = MAP$promptSave; this.hasAll = MAP$hasAll; this.hasSelected = MAP$hasSelected; this.previousRecord = MAP$previousRecord; this.nextRecord = MAP$nextRecord; this.firstRecord = MAP$firstRecord; this.lastRecord = MAP$lastRecord; this.autoRefresh = MAP$autoRefresh; this.autoToolbar = MAP$autoToolbar; this.autoCenter = MAP$autoCenter; this.toolbar = MAP$toolbar; this.refresh = MAP$refresh; this.centerSelected = MAP$centerSelected; this.previousFeature = MAP$previousFeature; this.nextFeature = MAP$nextFeature; this.addFeature = MAP$addFeature; this.newFeature = MAP$newFeature; this.clear = MAP$clear; this.deleteAll = MAP$deleteAll; this.del = MAP$del; this.setSize = MAP$setSize; this.setFixed = MAP$setFixed; this.selectFeature = MAP$selectFeature; this.htmlFeatures = MAP$htmlFeatures; this.findFeature = MAP$findFeature; this.findAddFeature = MAP$findAddFeature; this.activeFeature = MAP$activeFeature; this.listFeature = MAP$listFeature; this.setFeatureVisible = MAP$setFeatureVisible; this.setFeatureSnap = MAP$setFeatureSnap; this.featureExists = MAP$featureExists; this.clearSelected = MAP$clearSelected; this.deleteSelected = MAP$deleteSelected; this.deleteSelectedGraphics = MAP$deleteSelectedGraphics; this.renameTool = MAP$renameTool; // selected Feature this.deleteTool = MAP$deleteTool; // selected Feature this.addTool = MAP$addTool; // selected Feature this.renameFeature = MAP$renameFeature; // selected Feature this.deleteFeature = MAP$deleteFeature; // selected Feature this.eraseFeature = MAP$eraseFeature; // selected Feature this.moveFeatureUp = MAP$moveFeatureUp; // selected Feature this.moveFeatureDown = MAP$moveFeatureDown; // selected Feature this.eraseSelected = MAP$eraseSelected; // erase all selected features this.addGraphic = MAP$addGraphic; this.draw = MAP$draw; this.snap = MAP$snap; this.redraw = MAP$redraw; this.saveToFile = MAP$saveToFile; this.loadFromFile = MAP$loadFromFile; this.data = MAP$data; this.dataPaste = MAP$dataPaste; this.fdPaste = MAP$fdPaste; this.dataSelected = MAP$dataSelected; this.dataLayer = MAP$dataLayer; this.write = MAP$write; this.toObject = MAP$toObject; this.fromObject = MAP$fromObject; this.hotspot = MAP$hotspot; this.hotspot_csv = MAP$hotspot_csv; this.select = MAP$select; this.setZ = MAP$setZ; this.setBlink = MAP$setBlink; this.checkKeyEnter = MAP$checkKeyEnter; this.setNavigationButtons = MAP$setNavigationButtons; this.findById = MAP$findById; this.deleteById = MAP$deleteById; //------------------- Graphic Constructors ------------------ this.ic_Shape = ic$Shape; this.ic_Symbol = ic$Symbol; this.ic_Polygon = ic$Polygon; this.ic_Line = ic$Line; this.ic_Pline = ic$Pline; this.ic_Circle = ic$Circle; this.ic_Arc = ic$Arc; this.ic_Rectangle = ic$Rectangle; this.ic_Text = ic$Text; this.ic_Textbox = ic$Textbox; this.ic_Sketch = ic$Sketch; this.ic_Image = ic$Image; //-------------- Active Edit Feature (1 graphic element) -------- this.E = new ic$feature('activeEdit',this); this.E.isEdit = true; this.E.layer.style.zIndex = ZSelectPlane+1; //-------------- Delete Graphics (max 2000 units) -------- this.D = new ic$feature('DeletedElements',this); this.D.isDELETE = true; this.D.max = 2000; this.D.addDeleted = FEATURE$addDeleted; this.D.undelete = FEATURE$undelete; this.D.did = 0; this.undelete = MAP$undelete; //----------------- Selected Graphics List ----------------------- this.L = new ic$feature('selectList',this); this.L.isSelect = true; //----------------------------------------------------------- this.addFeature('Notes'); this.selectFeature('Notes'); this.editSetFeature = MAP$editSetFeature; this.forSelectedGraphics = MAP$forSelectedGraphics; this.edit = new ic$edit(this); blinkSet = false; blinkLayer = this.selectFeature('Notes'); } //======================================================================== // MAP$setZ //======================================================================== function MAP$setZ(layer,z) { var fea; fea = this.findAddFeature(layer); fea.layer.style.zIndex = parseInt(z); } //======================================================================== // MAP$setBlink //======================================================================== function MAP$setBlink(checked) { blinkOn = checked; } //======================================================================== // MAP$undelete //======================================================================== function MAP$undelete() { var xgra; xgra = this.D.botGraphicNode; if (!xgra) return; did = xgra.did; gra = this.D.undelete(did); while (gra) { fea = this.findFeature(gra.feature.name); if (! fea) fea = new ic$feature(gra.feature.name); fea.appendGraphic(gra); fea.drawGraphic(gra); gra = this.D.undelete(did); } this.selectFeature(xgra.feature.name); } //======================================================================== // MAP$startEdit //======================================================================== function MAP$startEdit() { this.isSelect = false; this.fromObject(this.activeNode); } //======================================================================== // MAP$checkKeyEnter //======================================================================== function MAP$checkKeyEnter(evt) { if (window.event.keyCode != 13) return; this.refresh(); } //======================================================================== // MAP$setFixed //======================================================================== function MAP$setFixed(checked) { this.forSelectedGraphics('gra.dc.fixed = ' + checked); } //======================================================================== // MAP$forSelectedGraphics //======================================================================== function MAP$forSelectedGraphics(cmd) { var gra; var gnode; if (this.L.graphicCount == 0) { gnode = this.activeNode; if (! gnode) return; gra = gnode.gra; eval(cmd); return; } gnode = this.L.topGraphicNode; while (gnode) { gra = gnode.gra; eval(cmd); gnode = gnode.next; } } //======================================================================== // MAP$undraw //======================================================================== function MAP$undraw(gra) { var obj; obj = getObject('$g$' + gra.gid); if (!obj) return; obj.innerHTML = ''; } //======================================================================== // MAP$eraseSelected //======================================================================== function MAP$eraseSelected() { var gnode; var nnode; var fea; this.D.did = this.D.did + 1; gnode = this.L.topGraphicNode; this.L.topGraphicNode = null; this.L.botGraphicNode = null; this.L.curnode = null; if (!gnode) { gnode = this.activeNode; if (!gnode) return; fea = gnode.gra.feature; this.undraw(gnode.gra); fea.deleteGraphic(gnode.gra); gnode = null; } while (gnode) { fea = gnode.gra.feature; this.undraw(gnode.gra); fea.deleteGraphic(gnode.gra); nnode = gnode.next; gnode.gra = null; gnode = nnode; } this.clearSelected() this.draw(); this.setNavigationButtons(); } //======================================================================== // MAP$promptSave //======================================================================== function MAP$promptSave() { if (!this.modified) return true; this.modified = false; fileSaveAs(); } //======================================================================== // MAP$copy //======================================================================== function MAP$copy(layer) { var data; data = this.dataLayer(layer); toClipboard(data); } //======================================================================== // MAP$cut //======================================================================== function MAP$cut(layer) { var data; data = this.dataLayer(layer); toClipboard(data); this.clearLayer(layer); } //======================================================================== // MAP$slelectAll //======================================================================== function MAP$selectAll() { var gnode; var fea; this.clearSelected(); fea = this.topFeature; while (fea) { gnode = fea.topGraphicNode; while (gnode) { this.L.addGraphic(gnode.gra); gnode = gnode.next; } fea = fea.next; } this.drawSelected(); return; } //======================================================================== // MAP$paste //======================================================================== function MAP$paste(layer) { var data; var fd; var test; data = clipboard(); this.dataPaste(layer,data); } //======================================================================== // MAP$dataPaste //======================================================================== function MAP$dataPaste(layer,data) { var data; var fd; var test; if (! data) return; if (data == '') return; test = data.substr(0,40).toLowerCase(); if (test.indexOf('*cg2') < 0) return; fd = new ic$memoryFile(data); this.fdPaste(fd,layer); } //======================================================================== // MAP$autoCenter //======================================================================== function MAP$autoCenter(gra) { var cx,cy,obj; setToolbarByName(gra.type); obj = getObject('autoCenter'); if (!obj) return; if (!obj.checked) return; cx = (gra.xmin + gra.xmax) / 2; cy = (gra.ymin + gra.ymax) / 2; goXY(cx,cy); draw(); } //======================================================================== // MAP$centerSelected //======================================================================== function MAP$centerSelected() { var cx,cy,obj; var gra; if (this.L.graphicCount > 0) gra = this.L.rng else { if (! this.activeNode) return; gra = this.activeNode.gra; } if (!gra) return; cx = (gra.xmin + gra.xmax) / 2; cy = (gra.ymin + gra.ymax) / 2; try { goXY(cx,cy); draw(); } catch (e) {return; } } //======================================================================== // MAP$hotspot //======================================================================== function MAP$hotspot(gra,text) { var lnk; var a; if (text == '') return text; if (this.isSelect) return text; if (this.isEdit) return text; try { lnk = gra.link; } catch (e) {lnk = '' } if (lnk == '') return text; a = ''; return (a + text + ''); } //======================================================================== // MAP$hotspot_csv //======================================================================== function MAP$hotspot_csv(gra,text) { var hint,href,target; var obj,z,a; try { if (text == '') return text; if (this.isSelect) return text; if (this.isEdit) return text; href = gra.href; //------------------- Set Z-Index --------- if (href == '') return text; href = editHref(href); a = ''; return (a + text + ''); } catch (e) { return text } } //======================================================================== // MAP$autoToolbar //======================================================================== function MAP$autoToolbar() { if (! autoToolbar.checked) return; this.toolbar(); } //======================================================================== // MAP$toolbar //======================================================================== function MAP$toolbar() { setEditTool(editMode); } //======================================================================== // MAP$autoRefresh //======================================================================== function MAP$autoRefresh() { if (! autoRefresh.checked) return; this.refresh(); } //======================================================================== // MAP$refresh //======================================================================== function MAP$refresh() { var gra; if (! this.activeNode) return; gra = this.activeNode.gra; editGetDC(gra.dc,gra.type); this.redraw(gra); } //======================================================================== // MAP$listFeature //======================================================================== function MAP$listFeature() { if (this.L.curnode) return this.L; else return this.curfea; } //======================================================================== // MAP$activeFeature //======================================================================== function MAP$activeFeature() { if (this.L.curnode) return this.L.curnode.gra.feature; else return this.curfea; } //======================================================================== // MAP$editSetFeature //======================================================================== function MAP$editSetFeature() { upTool.style.display = ''; // Feature Up/Down off downTool.style.display = ''; } //======================================================================== // MAP$findById //======================================================================== function MAP$findById(id) { var fea; var gra; fea = this.topFeature; while (fea) { gra = fea.findById(id); if (gra) return gra; fea = fea.next; } return null; } //======================================================================== // MAP$deleteById //======================================================================== function MAP$deleteById(layer,ID) { var fea; fea = this.findAddFeature(layer); if (fea.deleteById(ID)) return true; return false; } //======================================================================== // MAP$clearLayer //======================================================================== function MAP$clearLayer(layer) { var fea; fea = this.findAddFeature(layer); fea.clear(); } //======================================================================== // MAP$select //======================================================================== function MAP$select(x1,y1,x2,y2) { var dx,dy; var fea; var tx1,ty1; var rng; tol = 8; tx1 = this.view.screenToX(0); tx2 = this.view.screenToX(tol); stol = Math.abs(tx2 - tx1); if (this.L.graphicCount > 0) { this.toObject(); if (this.curfea) this.fromObject(this.curfea.curnode); else this.fromObject(null); } this.L.clear(); this.E.clear(); fea = this.topFeature; while (fea) { fea.select(x1,y1,x2,y2); fea = fea.next; } this.drawSelected(); } //======================================================================== // MAP$drawSelected //======================================================================== function MAP$drawSelected() { var fea; if (this.L.graphicCount == 1) // set 1 element as the active graphic { fea = this.L.topGraphicNode.gra.feature; fea.selectGraphic(this.L.topGraphicNode.gra); this.selectFeature(fea.name); this.L.clear(); } if (this.L.graphicCount == 0) { fea = this.activeFeature(); if (!fea) return; this.selectFeature(fea.name); return; // none selected; // reset to active; } this.L.rng = this.L.range(); this.draw(); this.E.drawGraphic(this.L.rng); } //======================================================================== // MAP$previousFeature //======================================================================== function MAP$previousFeature() { } //======================================================================== // MAP$nextFeature //======================================================================== function MAP$nextFeature() { } //======================================================================== // MAP$redraw //======================================================================== function MAP$redraw(gra) { var obj; obj = getObject('$g$' + gra.gid); // if (obj) obj.innerHTML = gra.vml(); // else gra.feature.drawGraphic(gra); gra.feature.drawGraphic(gra); if (!this.activeNode) return; if (gra != this.activeNode.gra) return; this.E.layer.innerHTML = ''; this.E.drawGraphic(gra); } //======================================================================== // MAP$clearSelected //======================================================================== function MAP$clearSelected() { try { this.E.clear(); this.L.clear(); } catch (e) { }; } //======================================================================== // ic$edit //======================================================================== function ic$edit(parent) { this.parent = parent; this.isDone = false; this.down = EDIT$down; this.move = EDIT$move; this.up = EDIT$up; this.moveEvent = EDIT$moveEvent; this.gra = null; } //======================================================================== // getPointRange //======================================================================== function getPointRange(gra,n) { var p; if (n >= 0) return null; if (n < -4) return null; p = null if (n == -1) { p = new Array(2); p[0] = gra.xmin; p[1] = gra.ymin; return p; } if (n == -2) { p = new Array(2); p[0] = gra.xmin; p[1] = gra.ymax; return p; } if (n == -3) { p = new Array(2); p[0] = gra.xmax; p[1] = gra.ymax; return p; } if (n == -4) { p = new Array(2); p[0] = gra.xmax; p[1] = gra.ymin; return p; } return null; } //======================================================================== // getPointLine //======================================================================== function getPointLine(gra,n) { var p; if (n < 0) return getPointRange(gra,n); if (n >= gra.x.length) return null; p = new Array(2); p[0] = gra.x[n]; p[1] = gra.y[n]; return p; } //======================================================================== // getPointArc //======================================================================== function getPointArc(gra,n) { var p; return null; if (n == HANDLE_CENTER) { p = new Array(2); p[0] = gra.cx; p[1] = gra.cy; return p; } switch (n) { case 1: // first p = new Array(2); p[0] = G.view.screenToX(this.ax1); p[1] = G.view.screenToX(this.ay1); break; case 2: // center p = new Array(2); p[0] = G.view.screenToX(this.ax2); p[1] = G.view.screenToX(this.ay2); break; case 3: // last p = new Array(2); p[0] = G.view.screenToX(this.ax3); p[1] = G.view.screenToX(this.ay3); break; } } //======================================================================== // getPointCircle //======================================================================== function getPointCircle(gra,n) { var p; if (n == HANDLE_CENTER) { p = new Array(2); p[0] = gra.cx; p[1] = gra.cy; return p; } if (n == HANDLE_RADIUS) { p = new Array(2); p[0] = gra.cx + gra.radius; p[1] = gra.cy; return p; } return null; } //======================================================================== // getPointSymbol //======================================================================== function getPointSymbol(gra,n) { var p; if (n < 0) return getPointRange(gra,n); if (n != 0) return null; p = new Array(2); p[0] = gra.x; p[1] = gra.y; return p; } //======================================================================== // getPointText //======================================================================== function getPointText(gra,n) { var p; if (n < 0) return getPointRange(gra,n); if (n != 0) return null; p = new Array(2); p[0] = gra.x; p[1] = gra.y; return p; } //======================================================================== // getPointTextbox //======================================================================== function getPointTextbox(gra,n) { var p; if (n < 0) return getPointRange(gra,n); if (n != 0) return null; p = new Array(2); p[0] = gra.x; p[1] = gra.y; return p; } //======================================================================== // getPointShape //======================================================================== function getPointShape(gra,n) { var p; if (n < 0) return getPointRange(gra,n); if (n != 0) return null; p = new Array(2); p[0] = gra.x; p[1] = gra.y; return p; } //======================================================================== // getPointImage //======================================================================== function getPointImage(gra,n) { var p; if (n < 0) return getPointRange(gra,n); if (n != 0) return null; p = new Array(2); p[0] = gra.x; p[1] = gra.y; return p; } //======================================================================== // EDIT$moveEvent //======================================================================== function EDIT$moveEvent(gid,n) { var gra; G.snapPoint = false; if (gid == RANGE_ID) return false; // ?? fea = this.parent.activeFeature(); if (! fea) return true; if (! fea.curnode) return true; if (fea.curnode.gra.gid != gid) return true; gra = fea.curnode.gra; p = null; if (gra.type == 'line') p = getPointLine(gra,n); if (gra.type == 'polygon') p = getPointLine(gra,n); if (gra.type == 'rectangle') p = getPointLine(gra,n); if (gra.type == 'arc') p = getPointArc(gra,n); if (gra.type == 'circle') p = getPointCircle(gra,n); if (gra.type == 'symbol') p = getPointSymbol(gra,n); if (gra.type == 'text') p = getPointText(gra,n); if (gra.type == 'textbox') p = getPointTextbox(gra,n); if (gra.type == 'shape') p = getPointShape(gra,n); if (gra.type == 'image') p = getPointImage(gra,n); if (!p) return; x = G.view.xToScreen(p[0]); y = G.view.yToScreen(p[1]); G.snapPoint = true; G.snapX = x; G.snapY = y; } //======================================================================== // EDIT$down //======================================================================== function EDIT$down(x,y,gid,n) { var fea; this.isDown = false; if (gid == RANGE_ID) { this.gra = this.parent.L.rng; } else { fea = this.parent.activeFeature(); if (! fea) return; if (! fea.curnode) return; if (fea.curnode.gra.gid != gid) return; this.gra = fea.curnode.gra; } this.parent.mode = 'edit'; this.x1 = x; this.y1 = y; this.x2 = x; this.y2 = y; this.x = x; // should be set by "findGra" this.y = y; this.n = n; this.edit = EDIT$fail; if (this.gra.type == 'line') this.edit = EDIT$line; if (this.gra.type == 'pline') this.edit = EDIT$line; if (this.gra.type == 'arc') this.edit = EDIT$arc; if (this.gra.type == 'circle') this.edit = EDIT$circle; if (this.gra.type == 'polygon') this.edit = EDIT$polygon; if (this.gra.type == 'rectangle') this.edit = EDIT$polygon; if (this.gra.type == 'symbol') this.edit = EDIT$symbol; if (this.gra.type == 'text') this.edit = EDIT$text; if (this.gra.type == 'textbox') this.edit = EDIT$textbox; if (this.gra.type == 'shape') this.edit = EDIT$shape; if (this.gra.type == 'image') this.edit = EDIT$image; if (this.gra.type == 'range') this.edit = EDIT$range; if (this.gra.type == 'arc') graToArc(this.gra,this); obj = getObject('$g$' + this.gra.gid); if (obj) obj.innerHTML = ''; this.isDown = true; this.move(x,y); } //======================================================================== // EDIT$fail //======================================================================== function EDIT$fail(gra) { } //======================================================================== // EDIT$move //======================================================================== function EDIT$move(x,y) { var dx,dy; var rx,ry; if (! this.isDown) return; rx = this.parent.view.screenToX(x-3); ry = this.parent.view.screenToY(y-3); this.x2 = x; this.y2 = y; this.edit(this.gra,rx,ry,this.n); this.parent.E.layer.innerHTML = ''; this.parent.E.drawGraphic(this.gra); } //======================================================================== // EDIT$up //======================================================================== function EDIT$up(x,y) { this.isDown = false; this.parent.mode = 'build'; if (! this.gra) return; obj = getObject('$g$' + this.gra.gid); if (this.gra.type == 'range') { this.parent.L.transform(this.gra); this.parent.draw(); this.parent.E.drawGraphic(this.parent.L.rng); } else if (obj) obj.innerHTML = this.gra.vml(); this.gra = null; } //======================================================================== // fit$line //======================================================================== function fit$line(gra) { var i; if (gra.x.length == 0) { gra.xmin = 0; gra.ymin = 0; gra.xmax = 0; gra.ymax = 0; return; } gra.xmin = gra.x[0]; gra.ymin = gra.y[0]; gra.xmax = gra.x[0]; gra.ymax = gra.y[0]; for (i = 1; i < gra.x.length; ++i) { gra.xmin = Math.min(gra.xmin,gra.x[i]); gra.ymin = Math.min(gra.ymin,gra.y[i]); gra.xmax = Math.max(gra.xmax,gra.x[i]); gra.ymax = Math.max(gra.ymax,gra.y[i]); } } //======================================================================== // EDIT$line //======================================================================== function EDIT$line(gra,x,y,n) { var cx,cy,dx,dy,i; if (n == HANDLE_CENTER) { cx = (gra.xmax + gra.xmin) / 2; cy = (gra.ymax + gra.ymin) / 2; dx = x - cx; dy = y - cy; for (i = 0; i < gra.x.length; ++i) { gra.x[i] = gra.x[i] + dx; gra.y[i] = gra.y[i] + dy; } gra.xmin = gra.xmin + dx; gra.ymin = gra.ymin + dy; gra.xmax = gra.xmax + dx; gra.ymax = gra.ymax + dy; return; } if (n < 0) return; gra.x[n] = x; gra.y[n] = y; fit$line(gra) G.setSize(gra); } //======================================================================== // EDIT$polygon //======================================================================== function EDIT$polygon(gra,x,y,n) { var i; var cx,cy; var dx,dy; if (n == HANDLE_CENTER) { cx = (gra.xmax + gra.xmin) / 2; cy = (gra.ymax + gra.ymin) / 2; dx = x - cx; dy = y - cy; for (i = 0; i < gra.x.length; ++i) { gra.x[i] = gra.x[i] + dx; gra.y[i] = gra.y[i] + dy; } gra.xmin = gra.xmin + dx; gra.ymin = gra.ymin + dy; gra.xmax = gra.xmax + dx; gra.ymax = gra.ymax + dy; return; } if (n < 0) return; if ((n == 0) || (n == (gra.x.length-1))) { i = gra.x.length-1; gra.x[0] = x; gra.y[0] = y; gra.x[i] = x; gra.y[i] = y; } else { gra.x[n] = x; gra.y[n] = y; } fit$line(gra); G.setSize(gra); } //======================================================================== // EDIT$rectangle //======================================================================== function EDIT$rectangle(gra,x,y,n) { var i; var cx,cy; var dx,dy; if (n == HANDLE_CENTER) { cx = (gra.xmax + gra.xmin) / 2; cy = (gra.ymax + gra.ymin) / 2; dx = x - cx; dy = y - cy; for (i = 0; i < gra.x.length; ++i) { gra.x[i] = gra.x[i] + dx; gra.y[i] = gra.y[i] + dy; } gra.xmin = gra.xmin + dx; gra.ymin = gra.ymin + dy; gra.xmax = gra.xmax + dx; gra.ymax = gra.ymax + dy; return; } if (n < 0) return; if ((n == 0) || (n == (gra.x.length-1))) { i = gra.x.length-1; gra.x[0] = x; gra.y[0] = y; gra.x[i] = x; gra.y[i] = y; } else { gra.x[n] = x; gra.y[n] = y; } fit$line(gra); G.setSize(gra); } //======================================================================== // EDIT$symbol //======================================================================== function EDIT$symbol(gra,x,y,n) { if (n == 0) { gra.x = x; gra.y = y; return; } if (n == HANDLE_ROTATE) { gra.angle = angle$(gra.x,gra.y,x,y); } } //======================================================================== // EDIT$text //======================================================================== function EDIT$text(gra,x,y,n) { if (n < 0) return; gra.x = x; gra.y = y; } //======================================================================== // EDIT$textbox //======================================================================== function EDIT$textbox(gra,x,y,n) { var dx,dy; var xmin,ymin,xmax,ymax; xmin = gra.xmin; ymin = gra.ymin; xmax = gra.xmax; ymax = gra.ymax; switch (n) { case -1: xmin = x; ymin = y; break; case -2: xmin = x; ymax = y; break; case -3: xmax = x; ymax = y; break; case -4: xmax = x; ymin = y; break; case HANDLE_CENTER: // (move) dx = (xmax - xmin) / 2; dy = (ymax - ymin) / 2; xmin = x - dx; ymin = y - dy; xmax = x + dx; ymax = y + dy; break; } gra.xmin = Math.min(xmin,xmax); gra.ymin = Math.min(ymin,ymax); gra.xmax = Math.max(xmin,xmax); gra.ymax = Math.max(ymin,ymax); G.setSize(gra); } //======================================================================== // EDIT$shape //======================================================================== function EDIT$shape(gra,x,y,n) { var dx,dy; var xmin,ymin,xmax,ymax; xmin = gra.xmin; ymin = gra.ymin; xmax = gra.xmax; ymax = gra.ymax; switch (n) { case -1: xmin = x; ymin = y; break; case -2: xmin = x; ymax = y; break; case -3: xmax = x; ymax = y; break; case -4: xmax = x; ymin = y; break; case HANDLE_CENTER: // (move) dx = (xmax - xmin) / 2; dy = (ymax - ymin) / 2; xmin = x - dx; ymin = y - dy; xmax = x + dx; ymax = y + dy; break; } gra.xmin = Math.min(xmin,xmax); gra.ymin = Math.min(ymin,ymax); gra.xmax = Math.max(xmin,xmax); gra.ymax = Math.max(ymin,ymax); G.setSize(gra); } //======================================================================== // EDIT$image //======================================================================== function EDIT$image(gra,x,y,n) { var dx,dy; var xmin,ymin,xmax,ymax; xmin = gra.xmin; ymin = gra.ymin; xmax = gra.xmax; ymax = gra.ymax; switch (n) { case -1: xmin = x; ymin = y; break; case -2: xmin = x; ymax = y; break; case -3: xmax = x; ymax = y; break; case -4: xmax = x; ymin = y; break; case HANDLE_CENTER: // (move) dx = (xmax - xmin) / 2; dy = (ymax - ymin) / 2; xmin = x - dx; ymin = y - dy; xmax = x + dx; ymax = y + dy; break; } gra.xmin = Math.min(xmin,xmax); gra.ymin = Math.min(ymin,ymax); gra.xmax = Math.max(xmin,xmax); gra.ymax = Math.max(ymin,ymax); G.setSize(gra); } //======================================================================== // fit$range //======================================================================== function fit$range(gra) { var xmin,ymin,xmax,ymax; xmin = gra.xmin; ymin = gra.xmin; xmax = gra.xmax; ymax = gra.xmax; gra.xmin = Math.min(xmin,xmax); gra.ymin = Math.min(ymin,ymax); gra.xmax = Math.max(xmin,xmax); gra.ymax = Math.max(ymin,ymax); G.setSize(gra); return; } //======================================================================== // EDIT$range //======================================================================== function EDIT$range(gra,x,y,n) { var dx,dy; var xmin,ymin,xmax,ymax; xmin = gra.xmin; ymin = gra.ymin; xmax = gra.xmax; ymax = gra.ymax; switch (n) { case -1: xmin = x; ymin = y; break; case -2: xmin = x; ymax = y; break; case -3: xmax = x; ymax = y; break; case -4: xmax = x; ymin = y; break; case HANDLE_CENTER: // (move) dx = (xmax - xmin) / 2; dy = (ymax - ymin) / 2; xmin = x - dx; ymin = y - dy; xmax = x + dx; ymax = y + dy; break; } gra.xmin = Math.min(xmin,xmax); gra.ymin = Math.min(ymin,ymax); gra.xmax = Math.max(xmin,xmax); gra.ymax = Math.max(ymin,ymax); G.setSize(gra); return; } //======================================================================== // EDIT$arc //======================================================================== function EDIT$arc(gra,x,y,n) { var sx,sy,arc; if (n == HANDLE_CENTER) { gra.cx = x; gra.cy = y; return; } if (n < 0) return; sx = G.view.xToScreen(x); sy = G.view.yToScreen(y); switch (n) { case 1: // first this.ax1 = sx; this.ay1 = sy; break; case 2: // center this.ax2 = sx; this.ay2 = sy; break; case 3: // last this.ax3 = sx; this.ay3 = sy; break; case HANDLE_CENTER: arc = makeArc$(this.ax1,this.ay1,this.ax2,this.ay2,this.ax3,this.ay3); dx = arc.cx - sx; dy = arc.cy - sy; this.ax1 = this.ax1 + dx; this.ay1 = this.ay1 + dy; this.ax2 = this.ax2 + dx; this.ay2 = this.ay2 + dy; this.ax3 = this.ax3 + dx; this.ay3 = this.ay3 + dy; break; } arc = makeArc$(this.ax1,this.ay1,this.ax2,this.ay2,this.ax3,this.ay3); if (arc.np = 0) return; gra.cx = G.view.screenToX(arc.cx); gra.cy = G.view.screenToY(arc.cy); gra.radius = Math.abs(G.view.screenToX(0) - G.view.screenToX(arc.radius)); gra.start = arc.start; // inverted Y axis gra.sweep = arc.sweep; fit$arc(gra); G.setSize(gra); return; } //======================================================================== // EDIT$circle //======================================================================== function EDIT$circle(gra,x,y,n) { switch (n) { case HANDLE_CENTER: // center gra.cx = x; gra.cy = y; break; case HANDLE_RADIUS: // radius gra.radius = length$(gra.cx,gra.cy,x,y); break; } fit$circle(gra); G.setSize(gra); } //======================================================================== // MAP$deleteSelected //======================================================================== function MAP$deleteSelected() { var gra; var gnode; var fea; this.D.did = this.D.did + 1; if (this.L.graphicCount > 0) { if (! confirm('delete ' + this.L.graphicCount + ' element' + S(this.L.graphicCount))) return; this.eraseSelected() return; } gnode = this.activeNode; if (! gnode) return; fea = gnode.gra.feature; this.undraw(gnode.gra); fea.deleteGraphic(gnode.gra); } //======================================================================== // MAP$deleteSelectedGraphics //======================================================================== function MAP$deleteSelectedGraphics() { var gnode; this.D.did = this.D.did + 1; gnode = this.L.topGraphicNode; while (gnode) { this.undraw(gnode.gra); gnode.gra.feature.deleteGraphic(gnode.gra); gnode = gnode.next; } this.L.clear(); } //======================================================================== // MAP$fromObject //======================================================================== function MAP$fromObject(node) { var gra; this.activeNode = node; if (! this.activeNode) { this.setNavigationButtons(); return; } fea = this.activeNode.gra.feature; gra = this.activeNode.gra; this.autoCenter(gra); try { activeName.innerText = fea.name + ' (' + gra.gid + ')'; } catch (e) {} editPutDC(gra.dc,gra.type); this.redraw(gra); this.setNavigationButtons(); } //======================================================================== // MAP$toObject //======================================================================== function MAP$toObject() { var gra; if (!this.activeNode) return; gra = this.activeNode.gra; try { editGetDC(gra.dc,gra.type); } catch (e) { alert('error toObject') }; } //======================================================================== // MAP$firstRecord //======================================================================== function MAP$firstRecord() { var fea; this.toObject(); fea = this.listFeature(); if (! fea) return; if (! fea.topGraphicNode) return; fea.selectNode(fea.topGraphicNode); } //======================================================================== // MAP$lastRecord //======================================================================== function MAP$lastRecord() { var fea; this.toObject(); fea = this.listFeature(); if (!fea) return; if (! fea.botGraphicNode) return; fea.selectNode(fea.botGraphicNode); } //======================================================================== // MAP$previousRecord //======================================================================== function MAP$previousRecord() { var fea; var list; fea = this.listFeature(); if (! fea) return; if (! fea.curnode) return; if (fea.curnode.prev) fea.selectNode(fea.curnode.prev); } //======================================================================== // MAP$nextRecord //======================================================================== function MAP$nextRecord() { var fea; fea = this.listFeature(); if (! fea) return; if (! fea.curnode) return; if (fea.curnode.next) fea.selectNode(fea.curnode.next); } //======================================================================== // MAP$write //======================================================================== function MAP$write(fd,has) { var names; var R; var fea; fd.write('*cg2;'); fd.write('*style,icMap;'); fd.writeCommentLine('!'); R = ',Range:(xmin:R8+ymin:R8+xmax:R8+ymax:R8)' + ',Fixed:(isSet:A5+PixelHeight:I4+PixelWidth:I4)'; if (has.line) { names = DCNames('line'); fd.write('*define:line, lin, ' + names + R + ',xy_list(32000):(x:R8+y:R8);'); } if (has.pline) { names = DCNames('pline'); fd.write('*define:pline, pln, ' + names + R + ',xy_list(32000):(x:R8+y:R8);'); } if (has.polygon) { names = DCNames('polygon'); fd.write('*define:polygon, pol, ' + names + R + ',xy_list(32000):(x:R8+y:R8);'); } if (has.rectangle) { names = DCNames('rectangle'); fd.write('*define:rectangle, rec, ' + names + R + ',xy_list(5):(x:R8+y:R8);'); } if (has.circle) { names = DCNames('circle'); fd.write('*define:circle, cir, ' + names + R + ',XY:(x:R8+y:R8),radius:R8;'); } if (has.arc) { names = DCNames('arc'); fd.write('*define:arc, arc, ' + names + R + ',XY:(x:R8+y:R8),radius:R8,start:R8,sweep:R8;'); } if (has.symbol) { names = DCNames('symbol'); fd.write('*define:symbol, sym, ' + names + R + ',XY:(x:R8+y:R8),angle:I4;'); } if (has.text) { names = DCNames('text'); fd.write('*define:text, txt, ' + names + R + ',XY:(X:r8:Y:R8),angle:I4;'); } if (has.textbox) { names = DCNames('textbox'); fd.write('*define:textbox, tbo, ' + names + R + ',XY:(X:R8+Y:R8);'); } if (has.shape) { names = DCNames('shape'); fd.write('*define:shape, shp, ' + names + R + ',style:i4,XY:(X:R8+Y:R8);'); } if (has.image) { names = DCNames('image'); fd.write('*define:image, img, ' + names + R + ',style:i4,XY:(X:R8+Y:R8);'); } } //======================================================================== // ic$has (constructor) //======================================================================== function ic$has() { this.line = false; this.pline = false; this.polyon = false; this.symbol = false; this.arc = false; this.circle = false; this.text = false; this.textbox = false; this.shape = false; this.image = false; this.lineCount = 0; this.plineCount = 0; this.polgonCount = 0; this.arcCount = 0; this.circleCount = 0; this.symbolCount = 0; this.textCount = 0; this.textboxCount = 0; this.shapeCount = 0; this.imageCount = 0; } //======================================================================== // MAP$hasAll //======================================================================== function MAP$hasAll() { has = new ic$has(); f = this.topFeature; while (f) { f.has(has); f = f.next; } return has; } //======================================================================== // MAP$hasSelected //======================================================================== function MAP$hasSelected() { has = new ic$has(); if (this.L.graphicCount > 0) this.L.has(has) else if (this.activeNode) this.activeNode.has(has); return has; } //======================================================================== // MAP$saveToFile //======================================================================== function MAP$saveToFile(filename) { var f,fd; var has; this.dbname = filename; fd = new ic$file(); if (! fd.create(filename)) return; has = this.hasAll(); this.write(fd,has); has = null; f = this.topFeature; while (f) { f.write(fd); f = f.next; } fd.write('!-------- End-of-File--------------;'); fd.close(); this.modified = false; } //======================================================================== // MAP$data //======================================================================== function MAP$data(fd,paste) { var f,fd; var xin; var has; var p; xin = false; if (MAP$data.arguments.length > 0) xin = true; //----------- read ------------ if (xin) { this.clearSelected(); p = new ic$parser(fd); while (p.nextSection()) { if (paste) fea = this.curfea; else fea = this.findCreateFeature(p.sectionName,p.findTable(p.sectionName)); gra = p.readGraphic(); while (gra) { gra.feature = fea; fea.appendGraphic(gra); // fea.drawGraphic(gra); if (paste) this.L.addGraphic(gra); gra = p.readGraphic(); } } this.clearSelected(); this.draw(); return; } //----------- write ------------- fd = new ic$memoryFile(); has = this.hasAll(); this.write(fd,has); f = this.topFeature; while (f) { f.write(fd); f = f.next; } fd.write('!-------- End-of-File--------------;'); return fd.close(); } //======================================================================== // MAP$fdPaste //======================================================================== function MAP$fdPaste(fd,layer) { var f,fd; var xin; var has; var p; var fea; fea = this.findAddFeature(layer); p = new ic$parser(fd); while (p.nextSection()) { gra = p.readGraphic(); while (gra) { gra.feature = fea; fea.appendGraphic(gra); gra = p.readGraphic(); } } this.draw(); } //======================================================================== // MAP$dataSelected //======================================================================== function MAP$dataSelected(data) { var f,fd; var xin; var fea,gra; var has; xin = false; if (MAP$dataSelected.arguments.length > 0) xin = true; //----------- Write ------------ if (xin) { // TODO return false; } //----------- Read ------------- fd = new ic$memoryFile(); has = this.hasSelected(); this.write(fd,has); has = null; if (this.L.graphicCount > 0) this.L.write(fd); // selected graphics else if (this.activeNode) // activeNode { gra = this.activeNode.gra; fea = gra.feature; fd.writeCommentLine('!'); fd.write('*section,' + fea.name + ';'); fd.write(fea.name + ', ' + gra.csv + ';'); gra.write(fd); } fd.write('!-------- End-of-File--------------;'); return fd.close(); } //======================================================================== // MAP$dataLayer //======================================================================== function MAP$dataLayer(layer) { var fd; var fea var has; fea = this.findFeature(layer); if (! fea) return ""; fd = new ic$memoryFile(); has = new ic$has(); fea.has(has); this.write(fd,has); has = null; fea.write(fd); fd.write('!-------- End-of-File--------------;'); return fd.close(); } //======================================================================== // MAP$loadFromFile //======================================================================== function MAP$loadFromFile(filename) { var f,fd; this.dbname = filename; fd = new ic$file(); if (! fd.openRead(filename)) return; this.data(fd,false); fd.close(); // this.centerSelected(); // this.draw; } //======================================================================== // MAP$draw //======================================================================== function MAP$draw() { var f; f = this.topFeature; while (f) { f.draw(); f = f.next; } // this.L.draw(); // selected // this.E.draw(); // active edit } //======================================================================== // MAP$snap //======================================================================== function MAP$snap(p,tol) { var f; var x1,x2,xtol; x1 = this.view.screenToX(0); x2 = this.view.screenToX(tol); xtol = Math.abs(x2 - x1); f = this.topFeature; while (f) { if (f.snap(p,xtol)) return true; f = f.next; } return false; } //======================================================================== // MAP$addGraphic //======================================================================== function MAP$addGraphic(layer,gra,isDraw) { var fea; this.modified = true; G.activeNode = null; fea = this.findAddFeature(layer); fea.addGraphic(gra,isDraw); // this.setNavigationButtons(); // this.curfea.draw(); } //======================================================================== // MAP$newFeature //======================================================================== function MAP$newFeature() { var name; name = ''; while (true) { name = window.prompt('New Feature name',name); if (! name) return; name = editName(name); if (! this.featureExists(name)) break; alert('feature /' + name + '/ already exists'); } this.addFeature(name); this.selectFeature(name); } //======================================================================== // MAP$moveFeatureUp (selected) //======================================================================== function MAP$moveFeatureUp() { var name; var f,prev,parent; prev = null; parent = null; f = this.topFeature; while (f) { if (f == this.curfea) { if (! prev) return; // already at top; if (parent) { parent.next = f; prev.next = f.next; f.next = prev; break; } else { this.topFeature = f; prev.next = f.next; f.next = prev; break; } } parent = prev; prev = f; f = f.next; } if (!f) return; this.selectFeature(f.name); } //======================================================================== // MAP$moveFeatureDown (selected) //======================================================================== function MAP$moveFeatureDown() { var name; var f,prev,n1,n2; if (! this.curfea) return; if (! this.curfea.next) return; // already at bottom; prev = null; f = this.topFeature; while (f) { if (f == this.curfea) { if (prev) { prev.next = f.next; } else { this.topFeature = f.next; } n1 = f.next; n2 = f.next.next; n1.next = f; f.next = n2; break; } prev = f; f = f.next; } if (!f) return; this.selectFeature(f.name); } //======================================================================== // MAP$del //======================================================================== function MAP$del(name) { var name; var f,prev,next; f = this.findFeature(name); if (!f) return; prev = null; next = null; this.curfea = null; f = this.topFeature; while (f != null) { next = f.next; if (name.toLowerCase() == f.name.toLowerCase()) if (prev == null) { this.topFeature = f.next; f.clear; f = null; break; } else { prev.next = f.next; f.clear; f = null; break; } prev = f; f = f.next; } if (prev) this.curfea = prev; if (next) this.curfea = next; } //======================================================================== // specialName //======================================================================== function specialName(name) { nam = name.toLowerCase(); if (nam == '[selected]') { alert('operation not allowed on feature /' + name + '/'); return true; } return false; } //======================================================================== // MAP$deleteFeature (selected) //======================================================================== function MAP$deleteFeature() { var name; if (! this.curfea) return; name = this.curfea.name; if (specialName(name)) return; if (! window.confirm('Delete Feature /' + name + '/')) return; this.del(name); name = ''; if (this.curfea) name = this.curfea.name; this.selectFeature(name); } //======================================================================== // MAP$addTool (selected) //======================================================================== function MAP$addTool() { if (icFeatureEdit.checked) this.newFeature(); } //======================================================================== // MAP$renameTool (selected) //======================================================================== function MAP$renameTool() { if (icFeatureEdit.checked) this.renameFeature(); } //======================================================================== // MAP$deleteTool (selected) //======================================================================== function MAP$deleteTool() { if (icFeatureEdit.checked) this.deleteFeature(); } //======================================================================== // MAP$eraseFeature (selected) //======================================================================== function MAP$eraseFeature() { var name; var cnt; if (! this.curfea) return; name = this.curfea.name; cnt = this.curfea.graphicCount; if (! window.confirm('delete ' + cnt + ' graphic element' + S(cnt) + ' from /' + name + '/')) return; this.clearSelected(); this.curfea.clear(); this.curfea.draw(); } //======================================================================== // MAP$renameFeature (selected) //======================================================================== function MAP$renameFeature() { var name; if (! this.curfea) return; name = this.curfea.name; if (specialName(name)) return; while (true) { name = window.prompt('Rename Feature',name); if (!name) return; name = editName(name); if ((name != '') && (! this.findFeature(name,true))) break; alert('duplicate feature /' + name + '/'); } this.curfea.name = name; this.selectFeature(name); } //======================================================================== // MAP$setFeatureVisible //======================================================================== function MAP$setFeatureVisible(checked) { var name; var f f = this.curfea; if (!f) return; f.visible = checked; f.draw(); if (!this.activeNode) return; if (f != this.activeNode.gra.feature) return; this.E.innerHTML = ''; if (!checked) return; this.E.drawGraphic(this.activeNode.gra); } //======================================================================== // MAP$setFeatureSnap //======================================================================== function MAP$setFeatureSnap(checked) { if (this.curfea) this.curfea.isSnap = checked; } //======================================================================== // MAP$clear //======================================================================== function MAP$clear() { var f,n; f = this.topFeature; this.topFeature = null; this.curfea = null; while (f) { n = f.next; f.clear; f = null; f = n; } f = this.freeGraphic this.freeGraphic = null; while (f) { n = f.next; f.clear; f = null; f = n; } } //======================================================================== // MAP$deleteAll //======================================================================== function MAP$deleteAll() { var f,n; this.L.clear(); this.E.clear(); this.D.clear(); f = this.topFeature; while (f) { n = f.next; f.clear(); f = n; } f = this.freeGraphic this.freeGraphic = null; while (f) { n = f.next; f.clear(); f = null; f = n; } } //======================================================================== // MAP$findAddFeature //======================================================================== function MAP$findAddFeature(name) { var fea; fea = this.findFeature(name); if (fea) return fea; fea = this.addFeature(name); return fea; } //======================================================================== // MAP$findFeature //======================================================================== function MAP$findFeature(name,excludeActive) { var f; f = this.topFeature; exclude = false; if (excludeActive != undefined) exclude = true; while (f != null) { if ((! exclude) || (f != this.curfea)) { if (name.toLowerCase() == f.name.toLowerCase()) return f; } f = f.next; } return null; } //======================================================================== // MAP$featureExists //======================================================================== function MAP$featureExists(name) { if (this.findFeature(name)) return true; return false; } //======================================================================== // MAP$addFeature //======================================================================== function MAP$addFeature(name) { var fea; this.curfea = new ic$feature(name,this); if (this.topFeature == null) { this.topFeature = this.curfea; } else { bot = this.topFeature; while (bot.next != null) bot = bot.next; bot.next = this.curfea; } this.selectFeature(name); return this.curfea; } //======================================================================== // MAP$selectFeature //======================================================================== function MAP$selectFeature(name) { this.toObject(); this.curfea = this.findFeature(name); try { icFeatureList.innerHTML = this.htmlFeatures(name); } catch (e) {}; if (! this.curfea) return; this.curfea.selectNode(this.curfea.curnode); return (this.curfea); } //======================================================================== // MAP$htmlFeatures //======================================================================== function MAP$htmlFeatures(name) { var text; var f; var rows, a; rows = 0; f = this.topFeature; while (f != null) { rows = rows + 1; f = f.next; } if (rows > 6) rows = 6; text = ''; return text; } //======================================================================== // ic$feature (Constructor) //======================================================================== function ic$feature(name,parent) { this.name = name; this.visible = true; this.isSnap = true; this.parent = parent; this.isEdit = false; this.isSelect = false; this.dcTable = null; this.next = null; this.graphicCount = 0; this.graphicID = 0; // Unique ID (do not reuse) this.topGraphicNode = null; this.botGraphicNode = null; this.selectGraphic = FEATURE$selectGraphic; this.selectNode = FEATURE$selectNode; this.draw = FEATURE$draw; this.drawGraphic = FEATURE$drawGraphic; this.snap = FEATURE$snap; this.write = FEATURE$write; this.select = FEATURE$select; this.deleteColumn = FEATURE$deleteColumn; this.has = FEATURE$has; this.range = FEATURE$range; this.transform = FEATURE$transform; this.findById = FEATURE$findById; this.deleteById = FEATURE$deleteById; this.addGraphic = FEATURE$addGraphic; this.appendGraphic = FEATURE$appendGraphic; this.deleteGraphic = FEATURE$deleteGraphic; this.deleteGraphicNode = FEATURE$deleteGraphicNode; this.clear = FEATURE$clear; this.next = null; this.layer = document.createElement('
'); this.layer.style.zIndex = Zgraphic; this.layer.style.borderWidth = 0; this.layer.style.border = ""; this.layer.style.position = "absolute"; this.layer.style.posTop = 0; this.layer.style.posLeft = 0; this.layer.style.pixelHeight = this.parent.height; this.layer.style.pixelWidth = this.parent.width; this.layer.oncontextmenu = null; document.body.appendChild(this.layer); } //======================================================================== // FEATURE$has //======================================================================== function FEATURE$has(has) { gnode = this.topGraphicNode; while (gnode) { gnode.has(has); gnode = gnode.next; } } //======================================================================== // FEATURE$undelete //======================================================================== function FEATURE$undelete(did) { var gra; gra = this.botGraphicNode; if (!gra) return null; if (gra.did != did) return null; this.graphicCount = this.graphicCount-1; if (!gra.prev) { this.topGraphicNode = null; this.botGraphicNode = null; gra.prev = null; gra.next = null; return gra; } this.botGraphicNode = gra.prev; gra.prev = null; gra.next = null; return gra; } //======================================================================== // FEATURE$addDeleted //======================================================================== function FEATURE$addDeleted(gra) { var xgra; gra.did = this.did; if (this.graphicCount >= this.max) { xgra = this.topGraphicNode; this.topGraphicNode = xgra.next; this.graphicCount = this.graphicCount-1; xgra = null; } this.graphicCount = this.graphicCount+1; if (this.topGraphicNode) { this.botGraphicNode.next = gra; gra.next = null; gra.prev = this.botGraphicNode; this.botGraphicNode = gra; return; } else { this.topGraphicNode = gra; this.botGraphicNode = gra; gra.next = null; gra.prev = null; } } //======================================================================== // FEATURE$selectNode //======================================================================== function FEATURE$selectNode(node) { G.toObject(); // update active node; this.curnode = node; G.fromObject(this.curnode); } //======================================================================== // FEATURE$findById //======================================================================== function FEATURE$findById(id) { var gnode; gnode = this.topGraphicNode; while (gnode) { if (gnode.gra.id == id) return gnode.gra; gnode = gnode.next; } return null; } //======================================================================== // FEATURE$deleteById //======================================================================== function FEATURE$deleteById(id) { var gnode; var pnode; var obj; gnode = this.topGraphicNode; pnode = null; while (gnode) { if (gnode.gra.id == id) { if (pnode == null) { this.topGraphicNode = gnode.next} else { pnode.next = gnode.next; } if (this.botGraphicNode == gnode) this.botGraphicNode = pnode; this.graphicCount = this.graphicCount - 1; obj = getObject('$g$' + gnode.gra.gid); if (obj) obj.innerHTML = ''; gnode.gra= null; gnode = null; return true; } pnode = gnode; gnode = gnode.next; } return false; } //======================================================================== // FEATURE$selectGraphic //======================================================================== function FEATURE$selectGraphic(gra) { var gnode; gnode = this.topGraphicNode; while (gnode) { if (gnode.gra == gra) { this.selectNode(gnode); // change active node; return; } gnode = gnode.next; } this.curnode = this.topGraphicNode; this.selectNode(this.topGraphicNode); } //======================================================================== // FEATURE$transform //======================================================================== function FEATURE$transform(gra) { var dx,dy; var w1,h1; var w2,h2; var xscl,yscl; var cx1,cy1,cx2,cy2; if (!gra) return; if (gra.type != 'range') return; if (!this.topGraphicNode) return; w1 = gra.xmax_old - gra.xmin_old; h1 = gra.ymax_old - gra.ymin_old; if (w1 < 0.0001) return; if (h1 < 0.0002) return; w2 = gra.xmax - gra.xmin; h2 = gra.ymax - gra.ymin; xscl = w2 / w1; yscl = h2 / h1; cx1 = (gra.xmax_old + gra.xmin_old) / 2; cy1 = (gra.ymax_old + gra.ymin_old) / 2; cx2 = (gra.xmax + gra.xmin) / 2; cy2 = (gra.ymax + gra.ymin) / 2; gnode = this.topGraphicNode; while (gnode) { gra$move(gnode.gra,-cx1,-cy1); gra$scale(gnode.gra,xscl,yscl); gra$move(gnode.gra,cx2,cy2); gra$fit(gnode.gra); gnode = gnode.next; } gra.xmin_old = gra.xmin; gra.ymin_old = gra.ymin; gra.xmax_old = gra.xmax; gra.ymax_old = gra.ymax; } //======================================================================== // gra$fit //======================================================================== function gra$fit(gra) { var i; if ((gra.type == 'line') || (gra.type == 'range') || (gra.type == 'polygon') || (gra.type == 'rectangle')) { fit$line(gra); return; } if (gra.type == 'symbol') fit$symobl(gra); if (gra.type == 'text') fit$text(gra); if (gra.type == 'textbox') fit$textbox(gra); if (gra.type == 'shape') fit$shape(gra); if (gra.type == 'circle') fit$circle(gra); if (gra.type == 'arc') fit$arc(gra); } //======================================================================== // gra$move //======================================================================== function gra$move(gra,xorg,yorg) { var i; if ((gra.type == 'line') || (gra.type == 'range') || (gra.type == 'polygon') || (gra.type == 'rectangle')) { for (i = 0; i < gra.x.length; ++i) { gra.x[i] = gra.x[i] + xorg; gra.y[i] = gra.y[i] + yorg; } return; } if ((gra.type == 'symbol') || (gra.type == 'text') || (gra.type == 'textbox') || (gra.type == 'shape')) { gra.x = gra.x + xorg; gra.y = gra.y + yorg; return; } if ((gra.type == 'circle') || (gra.type == 'arc')) { gra.cx = gra.cx + xorg; gra.cy = gra.cy + yorg; return; } } //======================================================================== // gra$scale //======================================================================== function gra$scale(gra,xscl,yscl) { var i; if ((Math.abs(xscl-1.0) < 0.0000001) && (Math.abs(yscl-1.0) < 0.0000001)) return; if ((gra.type == 'line') || (gra.type == 'range') || (gra.type == 'polygon') || (gra.type == 'rectangle')) { for (i = 0; i < gra.x.length; ++i) { gra.x[i] = gra.x[i] * xscl; gra.y[i] = gra.y[i] * yscl; } return; } if ((gra.type == 'symbol') || (gra.type == 'text') || (gra.type == 'textbox') || (gra.type == 'shape')) { gra.x = gra.x * xscl; gra.y = gra.y * yscl; return; } if ((gra.type == 'circle') || (gra.type == 'arc')) { gra.radius = gra.radius * xscl; return; } } //======================================================================== // FEATURE$range //======================================================================== function FEATURE$range() { var gnode; var gra; var xmin,ymin,xmax,ymax; xmin = 1.0e126; ymin = 1.0e126; xmax = -1.0e126; ymax = -1.0e126; gnode = this.topGraphicNode; if (!gnode) return; while (gnode) { xmin = Math.min(xmin,gnode.gra.xmin); ymin = Math.min(ymin,gnode.gra.ymin); xmax = Math.max(xmax,gnode.gra.xmax); ymax = Math.max(ymax,gnode.gra.ymax); gnode = gnode.next; } gra = new ic$Range(xmin,ymin,xmax,ymax); gra.gid = RANGE_ID; gra.feature = this; return gra; } //======================================================================== // RangeTouchesRange (A touches B) //======================================================================== function RangeTouchesRange(axmin,aymin,axmax,aymax,bxmin,bymin,bxmax,bymax) { if ((bxmin > axmax) && (bymin > aymax) && (axmin > bxmax) && (aymin > bymax)) return false; return true; } //======================================================================== // RangeInsideRange (A inside B) //======================================================================== function RangeInsideRange(axmin,aymin,axmax,aymax,bxmin,bymin,bxmax,bymax) { if (bxmin > axmax) return false; if (bymin > aymax) return false; if (axmin > bxmax) return false; if (aymin > bymax) return false; return true; } //======================================================================== // FEATURE$select //======================================================================== function FEATURE$select(x1,y1,x2,y2) { var gnode; gnode = this.topGraphicNode; while (gnode) { if (RangeInsideRange(gnode.gra.xmin,gnode.gra.ymin, gnode.gra.xmax,gnode.gra.ymax, x1,y1,x2,y2)) G.L.addGraphic(gnode.gra); gnode = gnode.next; } } //======================================================================== // ic$graphicNode (constructor) //======================================================================== function ic$graphicNode() { this.gra = null; this.next = null; this.prev = null; this.has = GRAPHICNODE$has; } //======================================================================== // GRAPHICNODE$has //======================================================================== function GRAPHICNODE$has(has) { switch (this.gra.type) { case 'line': has.line = true; has.lineCount = has.lineCount + 1; break; case 'pline': has.line = true; has.plineCount = has.plineCount + 1; break; case 'polygon': has.polygon = true; has.polygonCount = has.polygonCount + 1; break; case 'rectangle': has.rectangle = true; has.rectangleCount = has.rectangleCount + 1; break; case 'arc': has.arc = true; has.arcCount = has.arcCount + 1; break; case 'circle': has.circle = true; has.circleCount = has.circleCount + 1; break; case 'symbol': has.symbol = true; has.symbolCount = has.symbolCount + 1; break; case 'text': has.text = true; has.textCount = has.textCount + 1; break; case 'textbox': has.textbox = true; has.textboxCount = has.textboxCount + 1; break; case 'shape': has.shape = true; has.shapeCount = has.shapeCount + 1; break; case 'image': has.image = true; has.imageCount = has.imageCount + 1; break; } } //======================================================================== // FEATURE$write //======================================================================== function FEATURE$write(fd) { var text; fd.writeCommentLine('!'); fd.write('*section,' + this.name + ';'); gnode = this.topGraphicNode while (gnode) { gnode.gra.write(fd); gnode = gnode.next; } } //======================================================================== // FEATURE$draw //======================================================================== function FEATURE$draw() { var text; this.layer.innerHTML = ''; if (! this.visible) return; gnode = this.topGraphicNode; while (gnode) { this.drawGraphic(gnode.gra); gnode = gnode.next; } } //======================================================================== // FEATURE$deleteColumn //======================================================================== function FEATURE$deleteColumn(col) { var csv; var text; csv = new ic$csv(); gnode = this.topGraphicNode; while (gnode) { csv.data = gnode.gra.csv; csv.deleteColumn(col); gnode.gra.csv = csv.data; gnode = gnode.next; } csv = null; } //======================================================================== // FEATURE$snap //======================================================================== function FEATURE$snap(p,tol) { var text; if (! this.visible) return false; if (! this.isSnap) return false; gnode = this.topGraphicNode; while (gnode) { if (gnode.gra.snap(p,tol)) return true; gnode = gnode.next; } return false; } //======================================================================== // SymbolLibrary //======================================================================== function SymbolLibrary() { return "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""; } //======================================================================== // FEATURE$drawGraphic //======================================================================== function FEATURE$drawGraphic(gra) { var text,obj; if (!gra.feature.visible) return; G.isSelect = this.isSelect; G.isEdit = this.isEdit; text = gra.vml(); // if (icFeatureRange.checked) // { // gra.vrng = GRAPHIC$vmlRange; // text = text + gra.vrng(); // } G.isSelect = false; G.isEdit = false; if (this.layer.innerHTML == '') { obj = document.createElement(''); obj.innerHTML = SymbolLibrary(); this.layer.appendChild(obj); } //-------------- Add Graphic ------------------- obj = document.createElement(''); if (this.isEdit) { text = vmlHandle(gra) + text; } // toClipboard(text); obj.innerHTML = '' + text; obj.id = '$g$' + gra.gid; this.layer.appendChild(obj); } //======================================================================== // MAP$setNavigationButtons //======================================================================== function MAP$setNavigationButtons() { var fea; try { icGraphicFirst.disabled = true; icGraphicPrevious.disabled = true; icGraphicNext.disabled = true; icGraphicLast.disabled = true; icGraphicCount.innerText = ''; this.E.layer.innerHTML = ''; if (!this.activeNode) return; this.E.drawGraphic(this.activeNode.gra); fea = this.listFeature(); if (fea) icGraphicCount.innerText = fea.graphicCount; fea = this.activeNode.gra.feature; if (activeName) activeName.innerText = fea.name; if (! fea.curnode) return; if (fea.curnode.prev) { icGraphicFirst.disabled = false; icGraphicPrevious.disabled = false; } if (fea.curnode.next) { icGraphicNext.disabled = false; icGraphicLast.disabled = false; } } catch (e) {}; } //======================================================================== // FEATURE$clear //======================================================================== function FEATURE$clear() { var gnode; var n; this.layer.innerHTML == '' gnode = this.topGraphicNode; this.topGraphicNode = null; this.botGraphicNode = null; this.curnode = null; this.graphicCount = 0; this.graphicID = 0; while (gnode) { n = gnode.next; gnode.gra = null; gnode = null; gnode = n; } this.draw(); } //======================================================================== // FEATURE$appendGraphic //======================================================================== function FEATURE$appendGraphic(gra) { var gnode; var first; gnode = new ic$graphicNode(); gnode.gra = gra; gnode.prev = null; gnode.next = null; if (! this.topGraphicNode) { this.graphicCount = 1; this.topGraphicNode = gnode; this.botGraphicNode = gnode; } else { this.graphicCount = this.graphicCount + 1; gnode.prev = this.botGraphicNode; this.botGraphicNode.next = gnode; this.botGraphicNode = gnode; } this.curnode = gnode; G.toObject(); // save changes to current object; this.curnode = null; return gnode; } //======================================================================== // FEATURE$addGraphic //======================================================================== function FEATURE$addGraphic(gra,isDraw) { var gnode; var first; gnode = this.appendGraphic(gra); if (this.isEdit) return; if (this.isSelect) return; gra.feature = this; G.activeNode = gnode; // do NOT update current node G.toObject(); // set new graphics as active G.activeNode = null; if (isDraw) this.draw(gnode); } //======================================================================== // FEATURE$deleteGraphic //======================================================================== function FEATURE$deleteGraphic(gra) { var gnode; gnode = this.topGraphicNode; while (gnode) { if (gnode.gra == gra) { this.deleteGraphicNode(gnode); return; } gnode = gnode.next; } } //======================================================================== // FEATURE$deleteGraphicNode //======================================================================== function FEATURE$deleteGraphicNode(gnode) { this.graphicCount = this.graphicCount-1; if (this.curnode == gnode) { this.curnode = gnode.next; if (!this.curnode) this.curnode = gnode.prev; } if (this.botGraphicNode == gnode) this.botGraphicNode = gnode.prev; if (gnode.next) gnode.next.prev = gnode.prev; if (! gnode.prev) { if (gnode.next) gnode.next.prev = null; this.topGraphicNode = gnode.next; } else { gnode.prev.next = gnode.next; } if (G.activeNode == gnode) { G.fromObject(this.curnode); } G.D.addDeleted(gnode.gra); gnode = null; } //======================================================================== // ic$dc (Constructor) //======================================================================== function ic$dc(type) { this.setType = DC$setType; this.setType(type); try { editGetDC(this,type); } catch (e) { alert(e.message); }; } //======================================================================== // ic$dc (Constructor) //======================================================================== function DC$setType(type) { this.style = DC$lineStyle; if (type == 'text') this.style = DC$textStyle; if (type == 'textbox') this.style = DC$textStyle; if (type == 'shape') this.style = DC$shapeStyle; if (type == 'symbol') this.style = DC$symbolStyle; if (type == 'line') this.style = DC$lineStyle; if (type == 'pline') this.style = DC$lineStyle; if (type == 'arc') this.style = DC$lineStyle; if (type == 'sketch') this.style = DC$lineStyle; if (type == 'circle') this.style = DC$polygonStyle; if (type == 'polygon') this.style = DC$polygonStyle; if (type == 'rectangle') this.style = DC$polygonStyle; if (type == 'area') this.style = DC$areaStyle; if (type == 'measure') this.style = DC$measureStyle; if (type == 'range') this.style = DC$rangeStyle; } //======================================================================== // defineGraphic (build common for graphics) //======================================================================== function defineGraphic(gra,type) { gra.type = type; gra.dc = new ic$dc(type); G.gid = G.gid + 1; gra.gid = G.gid; gra.id = ''; gra.link = ''; gra.tag = ''; gra.blink = false; gra.id = G.infoId; gra.link = G.infoLink; gra.tag = G.infoTag; gra.projection = null; gra.snap = GRAPHIC$snapFail; if (type == 'line') gra.snap = GRAPHIC$snapLine; if (type == 'pline') gra.snap = GRAPHIC$snapLine; if (type == 'polygon') gra.snap = GRAPHIC$snapLine; if (type == 'rectangle') gra.snap = GRAPHIC$snapLine; if (type == 'circle') gra.snap = GRAPHIC$snapCircle; if (type == 'arc') gra.snap = GRAPHIC$snapArc; if (type == 'symbol') gra.snap = GRAPHIC$snapSymbol; if (type == 'text') gra.snap = GRAPHIC$snapText; if (type == 'textbox') gra.snap = GRAPHIC$snapTextbox; if (type == 'shape') gra.snap = GRAPHIC$snapShape; if (type == 'image') gra.snap = GRAPHIC$snapImage; if (type == 'line') gra.write = GRAPHIC$writeLine; if (type == 'pline') gra.write = GRAPHIC$writePline; if (type == 'polygon') gra.write = GRAPHIC$writePolygon; if (type == 'rectangle') gra.write = GRAPHIC$writeRectangle; if (type == 'circle') gra.write = GRAPHIC$writeCircle; if (type == 'arc') gra.write = GRAPHIC$writeArc; if (type == 'symbol') gra.write = GRAPHIC$writeSymbol; if (type == 'text') gra.write = GRAPHIC$writeText; if (type == 'textbox') gra.write = GRAPHIC$writeTextbox; if (type == 'shape') gra.write = GRAPHIC$writeShape; if (type == 'image') gra.write = GRAPHIC$writeImage; if (type == 'line') gra.csv = GRAPHIC$csvLine; if (type == 'pline') gra.csv = GRAPHIC$csvPline; if (type == 'polygon') gra.csv = GRAPHIC$csvPolygon; if (type == 'rectangle') gra.csv = GRAPHIC$csvRectangle; if (type == 'circle') gra.csv = GRAPHIC$csvCircle; if (type == 'arc') gra.csv = GRAPHIC$csvArc; if (type == 'symbol') gra.csv = GRAPHIC$csvSymbol; if (type == 'text') gra.csv = GRAPHIC$csvText; if (type == 'textbox') gra.csv = GRAPHIC$csvTextbox; if (type == 'shape') gra.csv = GRAPHIC$csvShape; if (type == 'image') gra.csv = GRAPHIC$csvImage; } //======================================================================== // defineGraphicPoints //======================================================================== function defineGraphicPoints(g,np,px,py,closed) { var i; var n; n = np; if (closed) { dx = px[0] - px[np-1]; dy = py[0] - py[np-1]; if (Math.sqrt(dx*dx + dy*dy) < 0.0001) { px[np-1] = px[0]; py[np-1] = py[0]; } else { n = np + 1 }; } g.x = new Array(n); g.y = new Array(n); g.xmin = 1.0e64; g.ymin = 1.0e64; g.xmax = -1.0e64; g.ymax = -1.0e64; for (i = 0; i < np; ++i) { g.x[i] = px[i]; g.y[i] = py[i]; g.xmin = Math.min(g.xmin,px[i]); g.ymin = Math.min(g.ymin,py[i]); g.xmax = Math.max(g.xmax,px[i]); g.ymax = Math.max(g.ymax,py[i]); } if (n == np) return; // force closed g.x[np] = g.x[0]; g.y[np] = g.y[0]; } //======================================================================== // MAP$setSize //======================================================================== function MAP$setSize(gra) { var x1,y1,x2,y2; x1 = this.view.xToScreen(gra.xmin); y1 = this.view.yToScreen(gra.ymin); x2 = this.view.xToScreen(gra.xmax); y2 = this.view.yToScreen(gra.ymax); gra.height = Math.round(Math.abs(y2 - y1)); gra.width = Math.round(Math.abs(x2 - x1)); } //======================================================================== // ic$Range (Constructor) //======================================================================== function ic$Range(xmin,ymin,xmax,ymax) { defineGraphic(this,'range'); this.xmin = Math.min(xmin,xmax); this.ymin = Math.min(ymin,ymax); this.xmax = Math.max(xmin,xmax); this.ymax = Math.max(ymin,ymax); this.xmin_old = this.xmin; this.ymin_old = this.ymin; this.xmax_old = this.xmax; this.ymax_old = this.ymax; this.dc.fixed = false; this.x = new Array(5); this.y = new Array(5); this.x[0] = this.xmin; this.y[0] = this.ymin; this.x[1] = this.xmin; this.y[1] = this.ymax; this.x[2] = this.xmax; this.y[2] = this.ymax; this.x[3] = this.xmax; this.y[3] = this.ymin; this.x[4] = this.xmin; this.y[4] = this.ymin; this.vml = GRAPHIC$vmlRange; G.setSize(this); } //======================================================================== // ic$Line (Constructor) //======================================================================== function ic$Line(x1,y1,x2,y2) { defineGraphic(this,'line'); this.xmin = Math.min(x1,x2); this.ymin = Math.min(y1,y2); this.xmax = Math.max(x1,x2); this.ymax = Math.max(y1,y2); this.x = new Array(2); this.y = new Array(2); this.x[0] = x1; this.y[0] = y1; this.x[1] = x2; this.y[1] = y2; this.vml = GRAPHIC$vmlLine; G.setSize(this); } //======================================================================== // ic$Pline (Constructor) //======================================================================== function ic$Pline(np,px,py) { defineGraphic(this,'line'); defineGraphicPoints(this,np,px,py,false); this.vml = GRAPHIC$vmlLine; G.setSize(this); } //======================================================================== // ic$Sketch (Constructor) //======================================================================== function ic$Sketch(np,px,py) { defineGraphic(this,'line'); defineGraphicPoints(this,np,px,py,false); this.vml = GRAPHIC$vmlLine; G.setSize(this); } //======================================================================== // ic$Polygon (Constructor) //======================================================================== function ic$Polygon(np,px,py) { defineGraphic(this,'polygon'); defineGraphicPoints(this,np,px,py,true); this.vml = GRAPHIC$vmlLine; G.setSize(this); } //======================================================================== // ic$Rectangle (Constructor) //======================================================================== function ic$Rectangle(xmin,ymin,xmax,ymax) { var np,px,py; defineGraphic(this,'rectangle'); this.vml = GRAPHIC$vmlLine; np = 5; px = new Array(5); py = new Array(5); px[0] = xmin; py[0] = ymin; px[1] = xmin; py[1] = ymax; px[2] = xmax; py[2] = ymax; px[3] = xmax; py[3] = ymin; px[4] = xmin; py[4] = ymin; defineGraphicPoints(this,np,px,py,true); G.setSize(this); } //======================================================================== // ic$Arc (Constructor) //======================================================================== function ic$Arc(cx,cy,radius,start,sweep) { defineGraphic(this,'arc'); this.cx = cx; this.cy = cy; this.radius = radius; this.start = start; this.sweep = sweep; this.vml = GRAPHIC$vmlArc; fit$arc(this); G.setSize(this); } //======================================================================== // getArcRange //======================================================================== function getArcRange(gra) { var xlen,nseg; var i; var da; var x,y; var sx,sy,sx2; var tx,ty; var rad; nseg = 30; da = gra.sweep / nseg; ang = 0.0; for (i = 0; i <= nseg; ++i) { x = Math.cos(ang + gra.start) * gra.radius; x = x + gra.cx; y = Math.sin(ang + gra.start) * gra.radius; y = y + gra.cy; if (i == 0) { gra.xmin = x; gra.ymin = y; gra.xmax = x; gra.ymax = y; } else { gra.xmin = Math.min(gra.xmin,x); gra.ymin = Math.min(gra.ymin,y); gra.xmax = Math.max(gra.xmax,x); gra.ymax = Math.max(gra.ymax,y); } ang = ang + da; } } //======================================================================== // fit$arc //======================================================================== function fit$arc(gra) { var xlen,nseg; var i; var da; var x,y; var sx,sy,sx2; var tx,ty; var rad; if (! G) return; sx = G.view.xToScreen(gra.cx); sy = G.view.yToScreen(gra.cy); sx2 = G.view.xToScreen(gra.cx + gra.radius); rad = Math.abs(sx - sx2); nseg = 20; da = gra.sweep / 20; ang = 0.0; //------ calculate in screen units -------- for (i = 0; i <= nseg; ++i) { tx = Math.cos(ang + gra.start) * rad; tx = tx + sx; ty = Math.sin(ang + gra.start) * rad; ty = ty + sy; x = G.view.screenToX(tx); y = G.view.screenToY(ty); if (i == 0) { gra.xmin = x; gra.ymin = y; gra.xmax = x; gra.ymax = y; } else { gra.xmin = Math.min(gra.xmin,x); gra.ymin = Math.min(gra.ymin,y); gra.xmax = Math.max(gra.xmax,x); gra.ymax = Math.max(gra.ymax,y); } ang = ang + da; } } //======================================================================== // ic$Circle (Constructor) //======================================================================== function ic$Circle(cx,cy,radius) { defineGraphic(this,'circle'); this.cx = parseFloat(cx); this.cy = parseFloat(cy); this.radius = parseFloat(radius); this.xmin = cx - radius; this.ymin = cy - radius; this.xmax = cx + radius; this.ymax = cy + radius; G.setSize(this); this.vml = GRAPHIC$vmlCircle; } //======================================================================== // fit$circle //======================================================================== function fit$circle(gra) { gra.xmin = gra.cx - gra.radius; gra.ymin = gra.cy - gra.radius; gra.xmax = gra.cx + gra.radius; gra.ymax = gra.cy + gra.radius; } //======================================================================== // ic$Symbol (Constructor) //======================================================================== function ic$Symbol(cx,cy,angle) { var dx,x1,x2; defineGraphic(this,'symbol'); this.x = parseFloat(cx); this.y = parseFloat(cy); this.angle = angle; this.vml = GRAPHIC$vmlSymbol; this.dc.symbolName = 'box'; this.dc.symbolSize = 20; this.dc.symbolFill = true; this.dc.symbolFillColor = 'red'; fit$symbol(this); G.setSize(this); } //======================================================================== // ic$Symbol (Constructor) //======================================================================== function fit$symbol(gra) { var x1,y1,x2; x1 = G.view.screenToX(0); x2 = G.view.screenToX(gra.dc.symbolSize); dx = Math.abs(x2 - x1) / 2; gra.xmin = gra.x - dx; gra.ymin = gra.y - dx; gra.xmax = gra.x + dx; gra.ymax = gra.y + dx; } //======================================================================== // ic$Text (Constructor) //======================================================================== function ic$Text(cx,cy,angle) { var x1,y1,dx,w; defineGraphic(this,'text'); this.x = parseFloat(cx); this.y = parseFloat(cy); this.angle = parseFloat(angle); this.vml = GRAPHIC$vmlText; fit$text(this); G.setSize(this); } //======================================================================== // fit$text //======================================================================== function fit$text(gra) { var x1,y1,nt; var dx,w; x1 = G.view.screenToX(0); x2 = G.view.screenToX(gra.dc.textSize); dx = Math.abs(x2 - x1); nt = gra.dc.textText.length; if (nt == 0) nt = 1; w = 0 if (nt > 0) w = dx + ((nt-1) * (dx * 0.66)); gra.xmin = gra.x; gra.ymin = gra.y - (dx / 2); gra.xmax = gra.xmin + w; gra.ymax = gra.y + (dx / 2); } //======================================================================== // ic$Textbox (Constructor) //======================================================================== function ic$Textbox(xmin,ymin,xmax,ymax,height,width) { defineGraphic(this,'textbox'); this.xmin = parseFloat(xmin); this.ymin = parseFloat(ymin); this.xmax = parseFloat(xmax); this.ymax = parseFloat(ymax); this.height = parseInt(height); // screen units this.width = parseInt(width); this.angle = 0; this.vml = GRAPHIC$vmlTextbox; } //======================================================================== // ic$Image (Constructor) //======================================================================== function ic$Image(xmin,ymin,xmax,ymax,height,width) { defineGraphic(this,'image'); this.xmin = parseFloat(xmin); this.ymin = parseFloat(ymin); this.xmax = parseFloat(xmax); this.ymax = parseFloat(ymax); this.height = parseInt(height); // screen units this.width = parseInt(width); this.angle = 0; this.vml = GRAPHIC$vmlImage; } //======================================================================== // ic$Shape (Constructor) //======================================================================== function ic$Shape(xmin,ymin,xmax,ymax,height,width) { defineGraphic(this,'shape'); this.xmin = parseFloat(xmin); this.ymin = parseFloat(ymin); this.xmax = parseFloat(xmax); this.ymax = parseFloat(ymax); this.height = parseInt(height); // screen units this.width = parseInt(width); this.angle = 0; this.vml = GRAPHIC$vmlShape; } //======================================================================== // editName //======================================================================== function editName(iname) { name = iname; if (name == '[selected]') return name; name = name.replace(/\s/g,'_'); // Space name = name.replace(/\t/g,''); // Tab name = name.replace(/\;/g,''); name = name.replace(/\=/g,''); name = name.replace(/\-/g,''); name = name.replace(/\*/g,''); name = name.replace(/\+/g,''); name = name.replace(/\/g,''); name = name.replace(/\%/g,''); name = name.replace(/\@/g,''); name = name.replace(/\(/g,''); name = name.replace(/\(/g,''); name = name.replace(/\)/g,''); name = name.replace(/\\/g,''); name = name.replace(/\$/g,''); name = name.replace(/\#/g,''); name = name.replace(/\&/g,''); name = name.replace(/\//g,''); return name; } //========================================================================= // DC$lineStyle //========================================================================= function DC$lineStyle() { var value; var text; var color,width; color = this.lineColor; width = this.lineWidth; if (G.isSelect) { color = SELECT_COLOR; width = SELECT_WIDTH; } text = ''; value = 'black'; if (color != '') value = color; text = text + ' strokecolor="' + value + '" '; text = text + ' filled="false"'; text = text + ' strokeweight="' + width + 'px"'; text = text + '>' + "\r\n" text = text + ""; return text; } //========================================================================= // DC$measureStyle //========================================================================= function DC$measureStyle() { var value; text = 'strokecolor="gray" '; text = text + ' strokeweight="2px"'; text = text + '>' + "\r\n" text = text + ""; return text; } //========================================================================= // DC$areaStyle //========================================================================= function DC$areaStyle() { var value; text = 'strokecolor="blue" '; text = text + ' strokeweight="2px"'; text = text + '>' + "\r\n" text = text + '"; text = text + ""; return text; } //========================================================================= // DC$rangeStyle //========================================================================= function DC$rangeStyle() { var value; text = 'strokecolor="green" '; text = text + ' strokeweight="1px"'; text = text + '>' + "\r\n" text = text + '"; text = text + ""; return text; } //========================================================================= // DC$rangeStyle //========================================================================= function DC$rangeStyle() { var value; text = 'strokecolor="blue" '; text = text + ' strokeweight="1px"'; text = text + '>' + "\r\n" text = text + '"; return text; } //========================================================================= // DC$symbolStyle //========================================================================= function DC$symbolStyle() { var text,color,width; var value; text = ''; if (G.isSelect) { text = 'strokecolor="' + SELECT_COLOR + '" '; text = text + ' strokeweight="' + SELECT_WIDTH + 'px"'; } else { if (this.symbolColor != '') text = 'strokecolor="' + this.symbolColor + '" '; if (this.symbolLine != '') text = text + ' strokewidth="' + this.symbolLine + '" '; } text = text + ' type="#' + this.symbolName + '" '; value = this.symbolFillcolor; if (! this.symbolFill) value = ''; if (value != '') text = text + ' fillcolor="' + this.symbolFillcolor + '"'; text = text + '>'; value = this.symbolFillTransparent; if (value == undefined) value = ''; if (value != '') text = text + ''; return text; } //========================================================================= // DC$textStyle //========================================================================= function DC$textStyle() { var text,color,width; text = ''; color = 'black'; width = this.textLineWidth; if (G.isSelect) { color = SELECT_COLOR; width = SELECT_WIDTH; } if (width != '0') text = text + " border='solid " + color + " " + width + "';"; if ((this.textBgcolor != '') && this.textFill) text = text + ' background-color:' + this.textBgcolor + ";"; return text; } //========================================================================= // DC$shapeStyle //========================================================================= function DC$shapeStyle() { var text,color,width; text = ''; color = 'black'; width = this.textLineWidth; if (G.isSelect) { color = SELECT_COLOR; width = SELECT_WIDTH; } return text; } //========================================================================= // DC$polygonStyle //========================================================================= function DC$polygonStyle() { var value; var text; color = this.lineColor; width = this.lineWidth; if (G.isSelect) { color = SELECT_COLOR; width = SELECT_WIDTH; } text = ''; if (color != '') text = ' strokecolor="' + color + '" '; text = text + ' strokeweight="' + width + 'px"'; text = text + '>' + "\r\n" value = this.lineFillcolor; if (value != '') { text = text + '"; } text = text + ""; if (this.lineShadow) text = text + ''; if (this.blink) text = blinkTag(text); return text; } //======================================================================== // GRAPHIC$vmlRange //======================================================================== function GRAPHIC$vmlRange() { var xmin,ymin,xmax,ymax,text; var coord,i,first,filled,xhref; var cmd; var np; this.dc.xstyle = DC$rangeStyle; x1 = Math.round(G.view.xToScreen(this.xmin)); y1 = Math.round(G.view.yToScreen(this.ymin)); x2 = Math.round(G.view.xToScreen(this.xmax)); y2 = Math.round(G.view.yToScreen(this.ymax)); coord = x1 + ',' + y1 + ',' + x1 + ',' + y2 + ',' + x2 + ',' + y2 + ',' + x2 + ',' + y1 + ',' + x1 + ',' + y1; text = ""; if (this.blink) text = blinkTag(text); return text; } //======================================================================== // GRAPHIC$vmlLine //======================================================================== function GRAPHIC$vmlLine() { var xmin,ymin,xmax,ymax,text; var coord,i,first,filled,xhref; var cmd,z; var np,a; np = this.x.length; if (np < 2) return ""; for (i = 0; i < np; ++i) { x = Math.round(G.view.xToScreen(this.x[i])); y = Math.round(G.view.yToScreen(this.y[i])); if (i == 0) { coord = x + "," + y; } else { coord = coord + ", " + x + "," + y; } } a = ''; z = parseInt(this.dc.z); a = 'z-index:' + z + ';'; text = ""; if (this.blink) text = blinkTag(text); return G.hotspot(this,text); } //======================================================================== // GRAPHIC$vmlArc //======================================================================== function GRAPHIC$vmlArc() { var xlen,nseg var da,ang; var i,a,z; var sx,sy,radius,sx2; sx = Math.round(G.view.xToScreen(this.cx)); sy = Math.round(G.view.yToScreen(this.cy)); sx2 = Math.round(G.view.xToScreen(this.cx + this.radius)); radius = Math.abs(sx2 - sx); xlen = Math.abs(radius * this.sweep) // ARC LENGTH nseg = Math.ceil(xlen / 2); // Pixels if (nseg < 22) nseg = 22; if (nseg > 40) nseg = 40; da = this.sweep / nseg; ang = 0; for (i = 0; i <= nseg; ++i) { x = Math.round((Math.cos(ang + this.start) * radius) + sx); y = Math.round((Math.sin(ang + this.start) * radius) + sy); if (i == 0) { coord = x + "," + y; } else { coord = coord + ", " + x + "," + y; } ang = ang + da; } a = ''; if (this.dc.z == undefined) this.dc.z = 0; z = parseInt(this.dc.z); a = 'z-index:' + z + ';'; text = ""; if (this.blink) text = blinkTag(text); return text; } //======================================================================== // GRAPHIC$vmlSymbol //======================================================================== function GRAPHIC$vmlSymbol() { var text; var size,z; var np,rot,deg; var x,y,dx,a; x1 = Math.round(G.view.xToScreen(this.x)); y1 = Math.round(G.view.yToScreen(this.y)); size = this.dc.symbolSize; if (size == undefined) size = 6; dx = Math.round(size / 2); x = x1 - dx; y = y1 - dx; rot = ''; deg = Math.abs(degree$(this.angle)); deg = Math.round(360 - deg); if ((deg != 360) || (deg == 0)) rot = ' Rotation=' + deg + ';'; a = ''; if (this.dc.z == undefined) this.dc.z = 0; z = parseInt(this.dc.z); // a = 'z-index:' + z + ';'; text = ""; if (this.blink) text = blinkTag(text); return G.hotspot(this,text); } //========================================================================== // GRAPHIC$vmlText //========================================================================== function GRAPHIC$vmlText() { var txt,angle,text; var color1,color2; this.angle = 0; x = Math.round(G.view.xToScreen(this.x)); y = Math.round(G.view.yToScreen(this.y)); text = this.dc.textText; if (text == '') text = ' '; size = parseInt(this.dc.textSize); if (size <= 0) size = 1; y = y - size; //------------ Simple Text ------- txt = ''; if (this.dc.textBold) text = '' + text + ''; if (this.dc.textItalic) text = '' + text + ''; if (this.dc.textUnderline) text = '' + text + ''; txt = txt + text + ''; if (this.blink) text = blinkTag(text); return G.hotspot(this,txt); } //========================================================================== // GRAPHIC$vmlTextbox //========================================================================== function GRAPHIC$vmlTextbox(isEdit) { var txt,angle,text; var x1,y1,x2,y2; var xmin,ymin,xmax,ymax; var h,w,a; x1 = Math.round(G.view.xToScreen(this.xmin)); y1 = Math.round(G.view.yToScreen(this.ymin)); x2 = Math.round(G.view.xToScreen(this.xmax)); y2 = Math.round(G.view.yToScreen(this.ymax)); xmin = Math.min(x1,x2); ymin = Math.min(y1,y2); xmax = Math.max(x1,x2); ymax = Math.max(y1,y2); w = xmax - xmin; h = ymax - ymin; if (this.dc.fixed) { w = this.width; h = this.height; } text = this.dc.textText; if (text == '') text = ' '; size = parseInt(this.dc.textSize); if (size <= 0) size = 1; if (this.dc.textBold) text = '' + text + ''; if (this.dc.textItalic) text = '' + text + ''; if (this.dc.textUnderline) text = '' + text + ''; //----------- Text Box ------------ s = this.dc.style(); txt = ""; a = ''; if (this.dc.z != 0) a = 'z-index:' + parseInt(this.dc.z) + ';'; txt = txt + ""; // if (! isEdit) { txt = txt + ''; txt = txt + ''; txt = txt + text + ''; txt = txt + ''; } txt = txt + ""; if (this.blink) text = blinkTag(text); return G.hotspot(this,txt); } //========================================================================== // GRAPHIC$vmlImage //========================================================================== function GRAPHIC$vmlImage(isEdit) { var txt,angle,text; var x1,y1,x2,y2; var xmin,ymin,xmax,ymax; var h,w,a; x1 = Math.round(G.view.xToScreen(this.xmin)); y1 = Math.round(G.view.yToScreen(this.ymin)); x2 = Math.round(G.view.xToScreen(this.xmax)); y2 = Math.round(G.view.yToScreen(this.ymax)); xmin = Math.min(x1,x2); ymin = Math.min(y1,y2); xmax = Math.max(x1,x2); ymax = Math.max(y1,y2); w = xmax - xmin; h = ymax - ymin; if (this.dc.fixed) { w = this.width; h = this.height; } //----------- Text Box ------------ txt = ""; a = ''; if (this.dc.z != 0) a = 'z-index:' + parseInt(this.dc.z) + ';'; txt = txt + ""; txt = txt + ""; txt = txt + ""; if (this.blink) text = blinkTag(text); return G.hotspot(this,txt); } //========================================================================== // GRAPHIC$vmlShape //========================================================================== function GRAPHIC$vmlShape(isEdit) { var txt,angle,text; var x1,y1,x2,y2; var xmin,ymin,xmax,ymax; var h,w,a,b,c; var s,ss; x1 = Math.round(G.view.xToScreen(this.xmin)); y1 = Math.round(G.view.yToScreen(this.ymin)); x2 = Math.round(G.view.xToScreen(this.xmax)); y2 = Math.round(G.view.yToScreen(this.ymax)); xmin = Math.min(x1,x2); ymin = Math.min(y1,y2); xmax = Math.max(x1,x2); ymax = Math.max(y1,y2); w = xmax - xmin; h = ymax - ymin; if (this.dc.fixed) { w = this.width; h = this.height; } text = this.dc.textText; size = parseInt(this.dc.textSize); if (size <= 0) size = 1; if (this.dc.textBold) text = '' + text + ''; if (this.dc.textItalic) text = '' + text + ''; if (this.dc.textUnderline) text = '' + text + ''; //----------- Text Box ------------ s = this.dc.style(); ss = parseInt(this.dc.shapeStyle); if (isNaN(ss)) ss = 63; if (ss < 0) ss = 63; b = ''; if ((this.dc.textBgcolor != '') && this.dc.textFill) b = b + ' fillcolor=' + this.dc.textBgcolor; a = ''; if (this.dc.z != 0) a = 'z-index:' + parseInt(this.dc.z) + ';'; txt = ""; txt = txt + ""; c = parseInt(this.dc.shapeLineWidth); if (c > 0) { txt = txt + ""; } if (text != '') { txt = txt + ''; txt = txt + ''; txt = txt + text + ''; txt = txt + ''; } txt = txt + ""; if (this.blink) text = blinkTag(text); return G.hotspot(this,txt); } //========================================================================== // GRAPHIC$vmlTextbox //========================================================================== function GRAPHIC$vmlTextboxold() { var txt,angle,text; var color1,color2; this.angle = 0; x = Math.round(G.view.xToScreen(this.x)); y = Math.round(G.view.yToScreen(this.y)); text = this.dc.textText; if (text == '') text = ' '; size = parseInt(this.dc.textSize); if (size <= 0) size = 1; rot = ''; if (this.angle != 0) rot = ' Rotation=' + Math.round(degree$(this.angle)) + ';'; color1 = textColor.value; color2 = "black"; //----------- Word Art ------------ h = 40; w = text.length * h * 1.2; txt = ""; txt = txt + ""; txt = txt + ""; txt = txt + ""; txt = txt + ""; txt = txt + ""; txt = txt + ""; if (this.blink) txt = blinkTag(txt); return txt; } //======================================================================== // GRAPHIC$vmlCircle //======================================================================== function GRAPHIC$vmlCircle() { var xmin,ymin,text; var radius; var diameter; var cx,cy; var x2,a; cx = Math.round(G.view.xToScreen(this.cx)); cy = Math.round(G.view.yToScreen(this.cy)); x2 = Math.round(G.view.xToScreen(this.cx + this.radius)); radius = Math.abs(x2 - cx); xmin = cx - radius; ymin = cy - radius; diameter = radius * 2; a = ''; if (this.dc.z != 0) a = 'z-index:' + parseInt(this.dc.z) + ';'; text = ""; if (this.blink) text = blinkTag(text); return G.hotspot(this,text); } //======================================================================== // snapNearRange //======================================================================== function snapNearRange(g,p,tol) { var i; if ((p[0] + tol) < g.xmin) return false; if ((p[1] + tol) < g.ymin) return false; if ((p[0] - tol) > g.xmax) return false; if ((p[1] - tol) > g.ymax) return false; return true; } //======================================================================== // snapNear //======================================================================== function snapNear(x1,y1,x2,y2,tol) { var d; d = length$(x1,y1,x2,y2); if (d > tol) return false; return true; } //======================================================================== // snapSegment //======================================================================== function snapSegment(p,x1,y1,x2,y2,tol) { var d; var x,y; var xp; var ang; ang = angle$(x1,y1,x2,y2); d = length$(x1,y1,x2,y2); x = p[0] - x1; y = p[1] - y1; xp = rotate$(x,y,-ang); x = xp[0]; y = xp[1]; if (Math.abs(y) > tol) return false; if ((x+tol) < 0) return false; if ((x-tol) > d) return false; if (x < 0) x = 0; if (x > d) x = d; y = 0; xp = rotate$(x,y,ang); p[0] = xp[0] + x1; p[1] = xp[1] + y1; return true; } //======================================================================== // GRAPHIC$snapLine //======================================================================== function GRAPHIC$snapLine(p,tol) { var i; if (! snapNearRange(this,p,tol)) return false; for (i = 0; i < this.x.length; ++i) { if (snapNear(p[0],p[1],this.x[i],this.y[i],tol)) { p[0] = this.x[i]; p[1] = this.y[i]; return true; } if (optionSnapEdge.checked && (i < this.x.length-1)) if (snapSegment(p,this.x[i],this.y[i],this.x[i+1],this.y[i+1],tol)) return true; } return false; } //======================================================================== // GRAPHIC$snapCircle //======================================================================== function GRAPHIC$snapCircle(p,tol) { var d; d = length$(p[0],p[1],this.cx,this.cy); d = Math.abs(d - this.radius); if (d > tol) return false; return false; } //======================================================================== // GRAPHIC$snapArc //======================================================================== function GRAPHIC$snapArc(p,tol) { var d; d = length$(p[0],p[1],this.cx,this.cy); d = Math.abs(d - this.radius); if (d > tol) return false; return false; } //======================================================================== // GRAPHIC$snapSymbol //======================================================================== function GRAPHIC$snapSymbol(p,tol) { var d; if (! snapNearRange(this,p,tol)) return false; p[0] = this.x; p[1] = this.y; return true; } //======================================================================== // GRAPHIC$snapText //======================================================================== function GRAPHIC$snapText(p,tol) { // if (! snapNearRange(this,p,tol)) return false; // p[0] = this.x; // p[1] = this.y; return false; } //======================================================================== // GRAPHIC$snapTextbox //======================================================================== function GRAPHIC$snapTextbox(p,tol) { // if (! snapNearRange(this,p,tol)) return false; return false; } //======================================================================== // GRAPHIC$snapShape //======================================================================== function GRAPHIC$snapShape(p,tol) { // if (! snapNearRange(this,p,tol)) return false; return false; } //======================================================================== // GRAPHIC$snapFail //======================================================================== function GRAPHIC$snapFail(p,tol) { return false; } //======================================================================== // csvShape //======================================================================== function csvLine(gra) { var text; var n; var x,y; n = gra.x.length; text = n; for (i = 0; i < n; ++i) { x = gra.x[i]; y = gra.y[i]; if (gra.projection) { x = gra.projection.x(x); y = gra.projection.y(y); } text = text + ',' + x + ':' + y; } return text; } //======================================================================== // csvRange //======================================================================== function csvRange(gra) { var text; var xmin,ymin,xmax,ymax; var h,w; if (gra.projection) { xmin = gra.projection.x(gra.xmin); ymin = gra.projection.y(gra.ymin); xmax = gra.projection.x(gra.xmax); ymax = gra.projection.y(gra.ymax); h = Math.abs(xmax - xmin); w = Math.abs(ymax - ymin); text = xmin + ':' + ymin + ':' + xmax + ':' + ymax; text = text + ',' + gra.dc.fixed + ':' + h + ':' + w; } else { text = gra.xmin + ':' + gra.ymin + ':' + gra.xmax + ':' + gra.ymax; text = text + ',' + gra.dc.fixed + ':' + gra.height + ':' + gra.width; } return text; } //======================================================================== // GRAPHIC$writeLine //======================================================================== function GRAPHIC$writeLine(fd) { var text; text = 'lin, ' + DCValues(this) + ',' + csvRange(this) + ',' + csvLine(this) + ';'; fd.write(text); } //======================================================================== // GRAPHIC$writePline //======================================================================== function GRAPHIC$writePline(fd) { var text; text = 'pln, ' + DCValues(this) + ',' + csvRange(this) + ',' + csvLine(this) + ';'; fd.write(text); } //======================================================================== // GRAPHIC$writePolygon //======================================================================== function GRAPHIC$writePolygon(fd) { var text; text = 'pol, ' + DCValues(this) + ',' + csvRange(this) + ',' + csvLine(this) + ';'; fd.write(text); } //======================================================================== // GRAPHIC$writeRectangle //======================================================================== function GRAPHIC$writeRectangle(fd) { var text; text = 'rec, ' + DCValues(this) + ',' + csvRange(this) + ',' + csvLine(this) + ';'; fd.write(text); } //======================================================================== // GRAPHIC$writeCircle //======================================================================== function GRAPHIC$writeCircle(fd) { var text; text = 'cir, ' + DCValues(this) + ',' + csvRange(this) + ',' + this.cx + ':' + this.cy + ',' + this.radius + ';'; fd.write(text); } //======================================================================== // GRAPHIC$writeArc //======================================================================== function GRAPHIC$writeArc(fd) { var text; text = 'arc, ' + DCValues(this) + ',' + csvRange(this) + ',' + this.cx + ':' + this.cy + ',' + this.radius + ',' + degree$(this.start) + ',' + degree$(this.sweep) + ';'; fd.write(text); } //======================================================================== // GRAPHIC$writeSymbol //======================================================================== function GRAPHIC$writeSymbol(fd) { var text; text = 'sym, ' + DCValues(this) + ',' + csvRange(this) + ',' + this.x + ':' + this.y + ',' + degree$(this.angle) + ';'; fd.write(text); } //======================================================================== // GRAPHIC$writeText //======================================================================== function GRAPHIC$writeText(fd) { var text; text = 'txt, ' + DCValues(this) + ',' + csvRange(this) + ',' + this.x + ':' + this.y + ',' + degree$(this.angle) + ';'; fd.write(text); } //======================================================================== // GRAPHIC$writeTextbox //======================================================================== function GRAPHIC$writeTextbox(fd) { var text; var x,y; x = this.xmin; y = this.ymin; text = 'tbo, ' + DCValues(this) + ',' + csvRange(this) + ',' + x + ':' + y + ';'; fd.write(text); } //======================================================================== // GRAPHIC$writeShape //======================================================================== function GRAPHIC$writeShape(fd) { var text; var x,y; var style; x = this.xmin; y = th