//=================================================================== // arc.txt // Author: Clif Collins Date Jan 2010 //------------------------------------------------------------------ // Main routines to control the arc generation process //=================================================================== var mode = 1; var iarc; var ipnt; var idir; var ibul; var ipdf; var ilin; var darc; //==================================================================== // draw (graphics to server) //==================================================================== function draw() { var f,idata; idata = document.getElementById('data'); idata.value = '' + darc.data + ''; f = document.getElementById('form'); f.submit(); } //==================================================================== // drawPoint //==================================================================== function drawPoint(x,y,label) { var text,cos,sin,tx,ty,angle,r; var dx,dy,h,w,width,dir; x = ( (x - darc.xorg) / darc.scale ) + darc.cx; y = ( (y - darc.yorg) / darc.scale ) + darc.cy; darc.data += 'symbol ' + v(x,1) + ',' + v(y,1) + ',12,0,Z154;'; if (label != '') { angle = lineAngle(darc.cx,darc.cy,x,y); angle = angle / 180 * Math.PI; cos = Math.cos(angle); sin = Math.sin(angle); h = 10; w = 7; label = "" + label; width = w * label.length; r = darc.radius + 10 + (width / 2); tx = (cos * r) + darc.cx; ty = (sin * r) + darc.cy; dx = width / 2; dy = h / 2; tx = tx - dx; ty = ty - dy; darc.data += 'text ' + tx + ',' + ty + ',0,' + label + ',,10,black;'; } } //==================================================================== // drawLine //==================================================================== function drawLine(lin) { var text,i,x,y; var p1,p2,c,p,points; text = ''; text += 'line black,1,,,'; points = ''; for (i=0; i < lin.length; ++i) { if (i > 0) text += ','; x = lin[i].x; y = lin[i].y; x = ( (x - darc.xorg) / darc.scale ) + darc.cx; y = ( (y - darc.yorg) / darc.scale ) + darc.cy; if (i == 0) p1 = v(x,100) + ':' + v(y,100); if (i == (lin.length-1)) p2 = v(x,100) + ':' + v(y,100); text += v(x,10) + ':' + v(y,10); points += 'symbol ' + v(x,10) + ',' + v(y,10) + ',6,0,Z152,blue;'; } c = v(darc.cx,1) + ':' + v(darc.cy,1); text += ';'; text += 'line silver,1,dash,,' + c + ',' + p1 + ';'; text += 'line silver,1,dash,,' + c + ',' + p2 + ';'; darc.data += text + points; } //==================================================================== // drawArc //==================================================================== function drawArc(arc) { var ticSize,radius,x1,y1,x2,y2,text,f; var angle,dir,tx,ty,a,x,label; ticSize = 20; radius = 150; darc = new Object; darc.cx = ticSize + radius; darc.cy = ticSize + radius; darc.radius = radius; darc.start = arc.start; darc.sweep = sweep; darc.yorg = arc.cy; darc.xorg = arc.cx; darc.scale = arc.radius / radius; text = ''; x1 = 0; y1 = ticSize + radius; x2 = 2 * (ticSize + radius); y2 = y1; text += 'line black,1,,,' + x1 + ':' + y1 + ',' + x2 + ':' + y2 + ';'; tx = x1 - 30; ty = y1 - 4; text += 'text ' + tx + ',' + ty + ',0,180|deg|,,12;'; tx = x2 + 10; text += 'text ' + tx + ',' + ty + ',0,0|deg|,,12;'; x1 = ticSize + radius; x2 = x1; y1 = 0; y2 = 2 * (ticSize + radius); text += 'line black,1,,,' + x1 + ':' + y1 + ',' + x2 + ':' + y2 + ';'; tx = x1 - 10; ty = y1 - 14; text += 'text ' + tx + ',' + ty + ',0,270|deg|,,12;'; tx = x1 - 7; ty = y2 + 4; text += 'text ' + tx + ',' + ty + ',0,90|deg|,,12;'; if (mode != 6) { text += 'cone red,1,dash,,' + darc.cx + ',' + darc.cy + ',' + radius + ',' + arc.start + ',' + arc.sweep + ';'; text += 'arc black,4,solid,,' + darc.cx + ',' + darc.cy + ',' + radius + ',' + arc.start + ',' + arc.sweep + ';'; } //------------- Start ------------- if (Math.abs(arc.start) > 25) { text += 'arc silver,1,,,' + darc.cx + ',' + darc.cy + ',' + 40 + ',' + 0 + ',' + arc.start + ';'; angle = arc.start - 4; angle = angle / 180 * Math.PI; x = 40 a = arc.start; tx = Math.cos(angle) * x + darc.cx; ty = Math.sin(angle) * x + darc.cy; text += 'symbol ' + v(tx,1) + ',' + v(ty,1) + ',12,' + a + ',Z163,silver;'; x = 45 label = 'start = ' + v(arc.start,10) + '|deg|'; dir = 0; angle = arc.start / 2; angle = angle / 180 * Math.PI; tx = Math.cos(angle) * x + darc.cx; ty = Math.sin(angle) * x + darc.cy; text += 'text ' + v(tx,1) + ',' + v(ty,1) + ',' + dir + ',' + label + ',,10;'; } //------------ Sweep -------------- if (Math.abs(arc.sweep) > 15) { text += 'arc silver,1,,,' + darc.cx + ',' + darc.cy + ',' + 60 + ',' + arc.start + ',' + arc.sweep + ';'; dir = arc.start + arc.sweep; dir = (dir + 360) % 360; angle = (dir - 4) / 180 * Math.PI; x = 60 a = dir; tx = Math.cos(angle) * x + darc.cx; ty = Math.sin(angle) * x + darc.cy; text += 'symbol ' + v(tx,1) + ',' + v(ty,1) + ',12,' + a + ',Z163,silver;'; x = 65 label = 'sweep = ' + v(arc.sweep,10) + '|deg|'; dir = 0; angle = (arc.sweep / 2) + arc.start; angle = angle / 180 * Math.PI; tx = Math.cos(angle) * x + darc.cx; ty = Math.sin(angle) * x + darc.cy; text += 'text ' + v(tx,1) + ',' + v(ty,1) + ',' + dir + ',' + label + ',,10;'; } darc.data = text; } //==================================================================== // execute //==================================================================== function execute() { var arc,pnt,dir,bul,pdf,lin; darc.data = ''; switch (mode) { case 1: arc = getArc(); pnt = arcToPoint(arc); dir = arcToDirection(arc); bul = arcToBulge(arc); break; case 2: pnt = getPoint(); arc = pointToArc(pnt); dir = arcToDirection(arc); bul = arcToBulge(arc); break; case 3: dir = getDirection(); arc = directionToArc(dir); pnt = arcToPoint(arc); bul = arcToBulge(arc); break; case 4: bul = getBulge(); if (bul == null) return; arc = bulgeToArc(bul); pnt = arcToPoint(arc); dir = arcToDirection(arc); break; case 6: arc = getArc(); pnt = arcToPoint(arc); dir = arcToDirection(arc); bul = arcToBulge(arc); break; } pdf = arcToPdf(arc); lin = arcToLine(arc); if (mode != 1) putArc(arc); if (mode != 2) putPoint(pnt); if (mode != 3) putDirection(dir); if (mode != 4) putBulge(bul); putPdf(pdf); putLine(lin); drawArc(arc); if (mode == 2) { drawPoint(pnt[0].x,pnt[0].y,'1'); drawPoint(pnt[1].x,pnt[1].y,'2'); drawPoint(pnt[2].x,pnt[2].y,'3'); } if (mode == 3) { drawPoint(dir.x1,dir.y1,'1'); drawPoint(dir.x2,dir.y2,'2'); } if (mode == 4) { drawPoint(bul.x1,bul.y1,'1'); drawPoint(bul.x2,bul.y2,'2'); } if (mode == 6) { drawLine(lin); } draw(); } //==================================================================== // r8 //==================================================================== function r8(value) { if (typeof(value) == 'undefined') return 0; value = parseFloat(value); if (isNaN(value)) return 0; return value; } //==================================================================== // v //==================================================================== function v(value,prec) { value = Math.round(value * prec) / prec; return value; } //==================================================================== // getArc //==================================================================== function getArc() { var arc,text,list; arc = new Object(); arc.cx = 50; arc.cy = 50; arc.radius = 50; arc.start = 0; arc.sweep = 45; arc.rev = false; text = iarc.value; list = text.split(','); if (list.length > 0) arc.cx = r8(list[0]); if (list.length > 1) arc.cy = r8(list[1]); if (list.length > 2) arc.radius = r8(list[2]); if (list.length > 3) arc.start = r8(list[3]); if (list.length > 4) arc.sweep = r8(list[4]); return arc; } //==================================================================== // putArc //==================================================================== function putArc(arc) { var text; text = v(arc.cx,1); text += ',' + v(arc.cy,1); text += ',' + v(arc.radius,10); text += ',' + v(arc.start,10); text += ',' + v(arc.sweep,10); iarc.value = text; } //==================================================================== // getTextarea //==================================================================== function getTextarea(ele) { if (typeof(ele.textContent) != 'undefined') return ele.textContent; return ele.innerText; } //==================================================================== // putTextarea //==================================================================== function putTextarea(ele,value) { if (typeof(ele.textContent) != 'undefined') ele.textContent = value; else ele.innerText = value; } //==================================================================== // getPoint //==================================================================== function getPoint() { var pnt,i,a,j,pnt; pnt = new Array(); for (i=0; i < 3; ++i) { p = new Object(); p.x = 0; p.y = 0; pnt[i] = p; } text = getTextarea(ipnt); list = text.split('\r\n'); j = 0; for (i=0; i < list.length; ++i) { a = list[i].split(','); if (a.length != 2) continue; pnt[j].x = r8(a[0]); pnt[j].y = r8(a[1]); j = j + 1; if (j == 3) break; } return pnt; } //==================================================================== // putPoint //==================================================================== function putPoint(pnt) { var text,i; text = ''; if (pnt != null) { text += v(pnt[0].x,100) + ',' + v(pnt[0].y,100) + '\r\n'; text += v(pnt[1].x,100) + ',' + v(pnt[1].y,100) + '\r\n'; text += v(pnt[2].x,100) + ',' + v(pnt[2].y,100) + '\r\n'; } putTextarea(ipnt,text); } //==================================================================== // getDirection //==================================================================== function getDirection() { var i,a,j,p,dir,list,text,c; dir = new Object(); dir.cx = 0; dir.cy = 0; dir.x1 = 0; dir.y1 = 0; dir.x2 = 0; dir.y2 = 0; dir.clockwise = false; text = idir.value; list = text.split(','); if (list.length > 0) dir.cx = r8(list[0]); if (list.length > 1) dir.cy = r8(list[1]); if (list.length > 2) dir.x1 = r8(list[2]); if (list.length > 3) dir.y1 = r8(list[3]); if (list.length > 4) dir.x2 = r8(list[4]); if (list.length > 5) dir.y2 = r8(list[5]); c = ''; if (list.length > 6) c = list[6]; c = c.toLowerCase(); if (c == 'true') dir.clockwise = true; return dir; } //==================================================================== // putDirection //==================================================================== function putDirection(dir) { var text; text = ''; if (dir != null) { text += v(dir.cx,100); text += ',' + v(dir.cy,100); text += ',' + v(dir.x1,100); text += ',' + v(dir.y1,100); text += ',' + v(dir.x2,100); text += ',' + v(dir.y2,100); text += ',' + dir.clockwise; } idir.value = text; } //==================================================================== // getBulge //==================================================================== function getBulge() { var i,a,j,p,bul,list,text; bul = new Object(); bul.x1 = 0; bul.y1 = 0; bul.x2 = 0; bul.y2 = 0; bul.bulge = 0; text = ibul.value; list = text.split(','); if (list.length > 0) bul.x1 = r8(list[0]); if (list.length > 1) bul.y1 = r8(list[1]); if (list.length > 2) bul.x2 = r8(list[2]); if (list.length > 3) bul.y2 = r8(list[3]); if (list.length > 4) bul.bulge = r8(list[4]); return bul; } //==================================================================== // putBulge //==================================================================== function putBulge(bul) { var text; text = ''; if (bul != null) { text += v(bul.x1,10); text += ',' + v(bul.y1,10); text += ',' + v(bul.x2,10); text += ',' + v(bul.y2,10); text += ',' + v(bul.bulge,1000000); } ibul.value = text; } //========================================================================================== // putLine //========================================================================================== function putLine(points) { var text,line,x,y,i; text = ''; for (i=0; i < points.length; ++i) { p = points[i]; x = Math.round(p.x * 10) / 10; y = Math.round(p.y * 10) / 10; text += i + ') ' + x + ', ' + y + '\r\n'; } putTextarea(ilin,text); } //========================================================================================== // putPdf //========================================================================================== function putPdf(text) { ipdf.value = text; } //==================================================================== // setExecute //==================================================================== function setExecute(status,imode) { var e; mode = imode; e = document.getElementById('executeButton') e.disabled = ! status e = document.getElementById('sourceButton') e.disabled = false; iarc.readonly = true; iarc.style.backgroundColor = '#cfcfcf'; ipnt.readonly = true; ipnt.style.backgroundColor = '#cfcfcf'; idir.readonly = true; idir.style.backgroundColor = '#cfcfcf'; ibul.readonly = true; ibul.style.backgroundColor = '#cfcfcf'; ilin.readonly = true; ilin.style.backgroundColor = '#cfcfcf'; ipdf.readonly = true; ipdf.style.backgroundColor = '#cfcfcf'; switch (mode) { case 1: iarc.readonly = false; iarc.style.backgroundColor = ''; break; case 2: ipnt.readonly = false; ipnt.style.backgroundColor = ''; break; case 3: idir.readonly = false; idir.style.backgroundColor = ''; break; case 4: ibul.readonly = false; ibul.style.backgroundColor = ''; break; case 6: iarc.readonly = false; iarc.style.backgroundColor = ''; break; } } //==================================================================== // sourceCode //==================================================================== function sourceCode() { switch (mode) { case 1: window.open("ARC.txt"); break; case 2: window.open("ARC_POINT.txt"); break; case 3: window.open("ARC_DIRECTION.txt"); break; case 4: window.open("ARC_BULGE.txt"); break; case 5: window.open("ARC_PDF.txt"); break; case 6: window.open("ARC_LINE.txt"); break; } } //==================================================================== // init //==================================================================== function init() { iarc = document.getElementById('input_arc'); ipnt = document.getElementById('input_point'); idir = document.getElementById('input_dir'); ibul = document.getElementById('input_bulge'); ipdf = document.getElementById('input_pdf'); ilin = document.getElementById('input_line'); darc = new Object; setExecute(true,1); execute(); }