mirror of
https://github.com/Doodle3D/doodle3d-client.git
synced 2024-11-14 06:47:55 +01:00
7 lines
32 KiB
Diff
7 lines
32 KiB
Diff
3c3
|
|
< break;case verticalShapes.SINUS:b=.25*Math.cos(a*Math.PI*4)+.75}return b}function doOnResize(){canvas.width=$canvas.width(),canvas.height=$canvas.height(),preview.width=$preview.width(),preview.height=$drawAreaContainer.height(),canvasWidth=canvas.width,canvasHeight=canvas.height,calcPreviewCanvasProperties(),drawCanvasTopLeftCoords[0]=drawCanvas.offset().left,drawCanvasTopLeftCoords[1]=drawCanvas.offset().top,redrawDoodle(),redrawPreview()}function initLayouting(){$drawAreaContainer=$("#drawareacontainer"),canvas.width=$canvas.width(),canvas.height=$canvas.height(),preview.width=$preview.width(),preview.height=$drawAreaContainer.height(),canvasWidth=canvas.width,canvasHeight=canvas.height,$drawAreaContainer.show(),setTimeout(_startOrientationAndChangeEventListening,1e3)}function _startOrientationAndChangeEventListening(){$(window).on("resize",doOnResize),doOnResize()}function initPreviewRendering(){$preview=$("#preview"),preview=$preview[0],previewCtx=preview.getContext("2d");var a=preview.width/canvas.width;preview_tmp=document.getElementById("preview_tmp"),preview_tmp.width=preview.width,preview_tmp.height=canvas.height*a,$("#preview_tmp").css("top",-preview_tmp.height),previewCtx_tmp=preview_tmp.getContext("2d"),calcPreviewCanvasProperties(),redrawPreview()}function calcPreviewCanvasProperties(){globalScale=preview.width/canvasWidth,layerCX=canvasWidth/2*globalScale,layerCY=canvasHeight/2*globalScale,layerOffsetY=preview.height*(1-previewVerticalPadding.bottom),yStep=(preview.height-preview.height*(previewVerticalPadding.top+previewVerticalPadding.bottom))/maxNumLayers}function redrawPreview(a){if(void 0==a&&(a=!1),_points.length<2)return void previewCtx.clearRect(0,0,preview.width,preview.height);a||(debug_redrawSimplification=_points.length<100?6:_points.length<250?7:_points.length<400?8:_points.length<550?9:_points.length<700?10:11);var b=0,c=0;previewCtx.clearRect(0,0,preview.width,preview.height),previewCtx.lineWidth=strokeWidth,previewCtx.strokeStyle="#f00";for(var d=0;numLayers>d;d++){var e=scaleFunction(d/maxNumLayers);if(previewCtx.globalAlpha=0==d||d==Math.floor(numLayers/2)||d==numLayers-1?1:globalAlpha,a&&d%debug_redrawSimplification!=0&&0!=d&&d!=Math.floor(numLayers/2)&&d!=numLayers-1)b-=yStep,c+=rStep;else{previewCtx.save(),previewCtx.translate(layerCX,layerOffsetY+b),previewCtx.scale(viewerScale*e,scaleY*viewerScale*e),previewCtx.rotate(c),previewCtx.translate(-doodleTransform[0]*globalScale*doodleTransform[2],-doodleTransform[1]*globalScale*doodleTransform[3]);var f=centeredAndScaledDoodlePoint(_points[0]);previewCtx.beginPath(),previewCtx.moveTo(f.x,f.y);for(var g=1;g<_points.length;g++)f=centeredAndScaledDoodlePoint(_points[g]),a&&g%debug_redrawSimplification!=0||previewCtx.lineTo(f.x,f.y);previewCtx.stroke(),b-=yStep,c+=rStep,previewCtx.restore()}}previewCtx.globalAlpha=globalAlpha}function renderToImageDataPreview(){if(!(_points.length<2)){previewCtx_tmp.clearRect(0,0,preview.width,preview.height),previewCtx_tmp.lineWidth=strokeWidth,previewCtx_tmp.strokeStyle="#f00",previewCtx_tmp.save(),previewCtx_tmp.translate(layerCX,layerCY),previewCtx_tmp.scale(viewerScale,viewerScale),previewCtx_tmp.translate(-doodleTransform[0]*globalScale*doodleTransform[2],-doodleTransform[1]*globalScale*doodleTransform[3]);var a=centeredAndScaledDoodlePoint(_points[0]);previewCtx_tmp.beginPath(),previewCtx_tmp.moveTo(a.x,a.y);for(var b=1;b<_points.length;b++)a=centeredAndScaledDoodlePoint(_points[b]),previewDefaults.showTravelLines||1!=_points[b][2]?previewCtx_tmp.lineTo(a.x,a.y):previewCtx_tmp.moveTo(a.x,a.y);previewCtx_tmp.stroke(),previewCtx_tmp.closePath(),previewCtx_tmp.restore();var c=preview_tmp.toDataURL();doodleImageCapture=new Image,doodleImageCapture.onload=function(){previewCtx.clearRect(0,0,preview.width,preview.height),previewCtx.lineWidth=strokeWidth,previewCtx.strokeStyle="#f00";for(var a=0,b=0,c=0;numLayers>c;c++){var d=scaleFunction(c/maxNumLayers);previewCtx.globalAlpha=0==c||c==Math.floor(numLayers/2)||c==numLayers-1?1:globalAlpha,previewCtx.save(),previewCtx.translate(layerCX,layerOffsetY+a),previewCtx.scale(d,scaleY*d),previewCtx.rotate(b),previewCtx.translate(-layerCX,-layerCY),previewCtx.drawImage(doodleImageCapture,0,0),a-=yStep,b+=rStep,previewCtx.restore()}},doodleImageCapture.src=c,previewCtx.globalAlpha=globalAlpha}}function redrawRenderedPreview(a){void 0==a&&(a=!1),previewCtx.clearRect(0,0,preview.width,preview.height),previewCtx.lineWidth=strokeWidth,previewCtx.strokeStyle="#f00";var b=0,c=0;if(doodleImageCapture.src&&""!=doodleImageCapture.src)for(var d=0;numLayers>d;d++){var e=scaleFunction(d/maxNumLayers);previewCtx.globalAlpha=0==d||d==Math.floor(numLayers/2)||d==numLayers-1?1:globalAlpha,a&&d%2!=0&&0!=d&&d!=Math.floor(numLayers/2)&&d!=numLayers-1?(b-=yStep,c+=rStep):(previewCtx.save(),previewCtx.translate(layerCX,layerOffsetY+b),previewCtx.scale(e,scaleY*e),previewCtx.rotate(c),previewCtx.translate(-layerCX,-layerCY),previewCtx.drawImage(doodleImageCapture,0,0),b-=yStep,c+=rStep,previewCtx.restore())}}function centeredAndScaledDoodlePoint(a){var b={x:0,y:0};return b.x=(a[0]-(doodleBounds[2]-doodleBounds[0])/2)*globalScale*doodleTransform[2],b.y=(a[1]-(doodleBounds[3]-doodleBounds[1])/2)*globalScale*doodleTransform[3],b}function updatePreview(a,b,c){if(void 0==c&&(c=!1),c=!1,!(_points.length<2)){if(-1==updatePrevX||-1==updatePrevY)return updatePrevX=a,void(updatePrevY=b);var d=0,e=0;previewCtx.lineWidth=strokeWidth,previewCtx.strokeStyle="#f00";for(var f=0;numLayers>f;f++)if(previewCtx.globalAlpha=0==f||f==Math.floor(numLayers/2)||f==numLayers-1?1:globalAlpha,c&&f%debug_redrawSimplification!=0&&0!=f&&f!=Math.floor(numLayers/2)&&f!=numLayers-1)d-=yStep,e+=rStep;else{previewCtx.save(),previewCtx.translate(layerCX,layerOffsetY+d),previewCtx.scale(viewerScale,scaleY*viewerScale),previewCtx.rotate(e),previewCtx.translate(-doodleTransform[0]*globalScale*doodleTransform[2],-doodleTransform[1]*globalScale*doodleTransform[3]),previewCtx.beginPath();var g=centeredAndScaledDoodlePoint([updatePrevX,updatePrevY]);previewCtx.moveTo(g.x,g.y);var h=centeredAndScaledDoodlePoint([a,b]);previewCtx.lineTo(h.x,h.y),previewCtx.stroke(),d-=yStep,e+=rStep,previewCtx.restore()}previewCtx.globalAlpha=globalAlpha,updatePrevX=a,updatePrevY=b}}function initSidebars(){console.log("f:initSidebars()"),sidebarLeft=new SideBar,sidebarLeft.init("#leftpanel","hideleft",function(){$("#leftpanel").show()}),sidebarRight=new SideBar,sidebarRight.init("#rightpanel","hideright",function(){$("#rightpanel").show()})}function SideBar(){this.initted=!1,this.$contentTarg=void 0,this.$sideBtn=void 0,this.contentHidden=!1,this.hideClass="",this.init=function(a,b,c){console.log("SideBar >> f:init >> targ: ",$(a),", hideClass: "+b),this.$contentTarg=$(a),this.hideClass=b,this.$contentTarg.addClass(this.hideClass),this.contentHidden=!0,this.$contentTarg.append("<div class='sidebutton'></div>"),this.$sideBtn=$(a+" .sidebutton");var d=this;this.$sideBtn.on("click",function(){console.log("sidebutton"),d.toggleShowHide()}),this.initted=!0,c()},this.toggleShowHide=function(){this.contentHidden?(this.contentHidden=!1,this.$contentTarg.removeClass(this.hideClass),this.$sideBtn.addClass("sidebuttonin")):(this.contentHidden=!0,this.$contentTarg.addClass(this.hideClass),this.$sideBtn.removeClass("sidebuttonin"))}}function previousSketch(){loadSketch(curSketch-1)}function nextSketch(){loadSketch(curSketch+1)}function newSketch(){clearDoodle(),curSketch=sketches.length,updateSketchButtonStates()}function listSketches(){console.log("listSketches"),$.get(wifiboxURL+"/sketch/list",function(a){"success"==a.status&&(sketches=a.data.list,curSketch=sketches.length-1,setSketchModified(!1),updateSketchButtonStates())})}function setSketchModified(a){isModified=a,updateSketchButtonStates()}function updateSketchButtonStates(){console.log("sketch: isModified",isModified,"curSketch",curSketch,"sketches.length",sketches.length),isModified?btnSave.enable():btnSave.disable(),curSketch<sketches.length-1?btnNext.enable():btnNext.disable(),curSketch>0?btnPrevious.enable():btnPrevious.disable()}function loadSketch(a){curSketch=a,0>curSketch&&(curSketch=0),curSketch>sketches.length-1&&(curSketch=sketches.length-1);var b=sketches[curSketch];console.log("sketch: loadSketch curSketch",curSketch,"id",b),$.get(wifiboxURL+"/sketch",{id:b},function(a){if("success"==a.status){console.log("sketch: loaded",a);var b=a.data.data;loadFromSvg(b),setSketchModified(!1),sketchLoaded=!0}else console.log("error loading sketch: ",a),listSketches()})}function saveSketch(){console.log("sketch: saveSketch");var a=saveToSvg();$.post(wifiboxURL+"/sketch",{data:a},function(a){console.log("sketch: saveSketch: response",a),listSketches()})}function getURLParameter(a){return decodeURI((new RegExp("[&?]"+a+"=(.+?)(&|$)").exec(location.search)||[,null])[1])}function isMobileDevice(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Windows Mobile/i.test(navigator.userAgent)}function isSmartphone(){var a=!1;if(/Android/i.test(navigator.userAgent)&&window.devicePixelRatio>1){var b=$(window).width()/window.devicePixelRatio;console.log("Android device >> ratio'd width: "+b),480>b&&(a=!0)}else a=/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini|Windows Mobile/i.test(navigator.userAgent);return a}function distance(a,b,c,d){return Math.sqrt((c-a)*(c-a)+(d-b)*(d-b))}function setVerticalShape(a){VERTICALSHAPE=a,redrawRenderedPreview()}function initVerticalShapes(){resetVerticalShapes()}function resetVerticalShapes(){setVerticalShape(verticalShapes.NONE)}function disableDragging(){$(document).bind("dragstart",function(a){console.log("dragstart"),a.preventDefault()})}function showOrHideThermo(){console.log("f:showOrHideThermo()"),showOrHide?(thermometer.hide(),progressbar.hide()):(thermometer.show(),progressbar.show()),showOrHide=!showOrHide}function settingsLoaded(){console.log("settingsLoaded"),firstTimeSettingsLoaded&&(console.log(" preheat: ",settings["printer.heatup.enabled"]),console.log(" state: ",state),state==Printer.IDLE_STATE&&settings["printer.heatup.enabled"]&&printer.preheat(),console.log("doodle3d.tour.enabled: ",settings["doodle3d.tour.enabled"]),settings["doodle3d.tour.enabled"]&&!clientInfo.isSmartphone&&(console.log("show tour"),initHelp()),firstTimeSettingsLoaded=!1)}function setDebugText(a){$("#debug_display").text(a)}var settings={},settingsPopup,objectHeight=20,layerHeight=.2,enableTraveling=!0,minScale=.3,maxScale=1,shape="%",twists=0,loglevel=2,serverport=8888,autoLoadImage="hand.txt",loadOffset=[0,0],showWarmUp=!0,loopAlways=!1,firstLayerSlow=!0,useSubpathColors=!1,autoWarmUp=!0,maxScaleDifference=.1,frameRate=60,quitOnEscape=!0,screenToMillimeterScale=.3,sideis3D=!0,sidevisible=!0,sidebounds=[900,210,131,390],sideborder=[880,169,2,471],windowbounds=[0,0,800,500],windowcenter=!0,windowfullscreen=!1,autoWarmUpCommand="M104 S230",autoWarmUpDelay=3,shapePopup;$("#fileScan").change(function(){readURL(this)});var shapeResolution=3,shapePopup;Button.prototype=new jQuery,$.fn.Button=function(){return $(this).each(function(){new Button(this)})};var grandTour,infoReminderTour,helpTours,keyboardShortcutsEnabled=!0,keyboardEscapeEnterEnabled=!1,wordBuffer="",wordFuncs={idbeholdl:function(){alert("Light!")},idspispopd:function(){drawTextOnCanvas("Im in ur kanvas drawin' ur stuffz.")},dia:function(){var a=canvasWidth/2,b=canvasHeight/2;drawCircle(a,b,50,4),shapeMoveTo(a-20,b),shapeLineTo(a+20,b),shapeMoveTo(a,b-20),shapeLineTo(a,b+20)},stats:function(){var a="Shape statistics:\nNumber of points: "+_points.length;alert(a)},pdump:function(){console.log("points array: "+_points)}},$displayThermometer=$("#thermometerContainer"),wordArtPopup,twistIncrement=Math.PI/1800,btnNew,btnPrevious,btnNext,btnOops,btnStop,btnInfo,btnSettings,btnWordArt,btnToggleEdit,buttonGroupEdit,btnZoom,btnMove,btnRotate,btnToggleVerticalShapes,btnHeight,btnTwist,btnShape,btnConv,btnStraight,btnSine,btnDiv,buttonGroupAdd,popupWordArt,btnScan,popupScan,state,prevState,hasControl,gcodeGenerateDelayer,gcodeGenerateDelay=50,preheatDelay,preheatDelayTime=15e3,connectingHintDelay=null,connectingHintDelayTime=2e4,preview,previewCtx,svgPathRegExp=/[LM]\d* \d*/gi,svgPathParamsRegExp=/([LM])(\d*) (\d*)/,dragging=!1,$canvas,canvas,ctx,canvasWidth,canvasHeight,drawCanvas,drawCanvasTopLeftCoords=[0,0],doodleBounds=[-1,-1,-1,-1],doodleTransform=[0,0,1,1],_points=[],prevCountingTime=0,movementCounter=0,drawVariableLineWeight=!1,lineweight=2,isModified=!1,showTravelLines=!1,prevPoint={x:-1,y:-1};prevUpdateFullPreview=0,prevUpdateFullPreviewInterval=25;var MAX_POINTS_TO_PRINT=2e5,gcode=[];pointsTranslate=function(a,b,c){for(var d=0;d<a.length;d++)a[d][0]+=b,a[d][1]+=c},pointsScale=function(a,b,c){for(var d=0;d<a.length;d++)a[d][0]*=b,a[d][1]*=c},pointsRotate=function(a,b){for(var c,d,e=0;e<a.length;e++)d=Math.sqrt(a[e][0]*a[e][0]+a[e][1]*a[e][1]),c=Math.atan2(a[e][1],a[e][0]),a[e][0]=Math.cos(c+b)*d,a[e][1]=Math.sin(c+b)*d},lineLength=function(a,b,c,d){return Math.sqrt((a-=c)*a+(b-=d)*b)};var Point=function(){};Point.prototype={x:0,y:0,set:function(a,b){this.x=a,this.y=b},distance:function(a){var b=-1;return a instanceof Point&&(b=Math.sqrt((a.x-this.x)*(a.x-this.x)+(a.y-this.y)*(a.y-this.y))),b},toString:function(){console.log("x:"+this.x+", y:"+this.y)}};var drawAreaContainerMinHeight=300,drawAreaContainerMaxHeight=450,$preview,preview,previewCtx,preview_tmp,previewCtx_tmp,previewDefaults={rotation:0,numLayers:5,showTravelLines:!1},svgPathRegExp=/[LM]\d* \d*/gi,svgPathParamsRegExp=/([LM])(\d*) (\d*)/,prevRedrawTime=(new Date).getTime(),redrawInterval=1e3/30,previewRotationLimit=Math.PI/30,numLayers=previewDefaults.numLayers,maxNumLayers=100,minNumLayers=2,globalScale=.3,globalAlpha=.2,scaleY=.4,viewerScale=.65,previewVerticalPadding={top:.15,bottom:.12},strokeWidth=2,rStep=previewDefaults.rotation,yStep,layerCX,layerCY,layerOffsetY,prevX=0,prevY=0,highlight=!0,linesRaw="",debug_redrawSimplification=6,updatePrevX=-1,updatePrevY=-1,sidebarLeft,sidebarRight,curSketch=0,sketches=[],sketchLoaded=!1,VERTICALSHAPE,verticalShapes={NONE:"none",DIVERGING:"diverging",CONVERGING:"converging",SINUS:"sinus"},debugMode=!1,sendPrintCommands=!0,communicateWithWifibox=!0,wifiboxIsRemote=!1,autoUpdate=!0,printer=new Printer,progressbar=new Progressbar,thermometer=new Thermometer,settingsWindow=new SettingsWindow,message=new Message,firstTimeSettingsLoaded=!0,wifiboxURL,wifiboxCGIBinURL,$drawAreaContainer,$doodleCanvas,doodleCanvas,doodleCanvasContext,$previewContainer,showhideInterval,showOrHide=!1,limitedFeatures=!1,clientInfo={},POPUP_SHOW_DURATION=175,BUTTON_GROUP_SHOW_DURATION=80;$(function(){console.log("ready"),"null"!=getURLParameter("d")&&(debugMode="1"==getURLParameter("d")),"null"!=getURLParameter("p")&&(sendPrintCommands="1"==getURLParameter("p")),"null"!=getURLParameter("c")&&(communicateWithWifibox="1"==getURLParameter("c")),"null"!=getURLParameter("r")&&(wifiboxIsRemote="1"==getURLParameter("r")),"null"!=getURLParameter("u")&&(autoUpdate="1"==getURLParameter("u")),"null"!=getURLParameter("l")&&(limitedFeatures="1"==getURLParameter("l"));var a;wifiboxIsRemote&&(a="http://192.168.5.1"),"null"!=getURLParameter("wifiboxURL")&&(a=getURLParameter("wifiboxURL")),a||(a="http://"+window.location.host),wifiboxURL=a+"/d3dapi",wifiboxCGIBinURL=a+"/cgi-bin/d3dapi",communicateWithWifibox||(sendPrintCommands=!1),console.log("debugMode: "+debugMode),console.log("sendPrintCommands: "+sendPrintCommands),console.log("communicateWithWifibox: "+communicateWithWifibox),console.log("wifiboxIsRemote: "+wifiboxIsRemote),console.log("wifibox URL: "+wifiboxURL),clientInfo.isMobileDevice=isMobileDevice(),clientInfo.isSmartphone=isSmartphone(),initDoodleDrawing(),initPreviewRendering(),initLayouting(),initButtonBehavior(),initKeyboard(),initWordArt(),initShapeDialog(),initScanDialog(),disableDragging(),clientInfo.isSmartphone||initHelp(),thermometer.init($("#thermometerCanvas"),$("#thermometerContainer")),progressbar.init($("#progressbarCanvas"),$("#progressbarCanvasContainer")),message.init($("#message")),printer.init(),$(document).on(Printer.UPDATE,update),settingsWindow.init(wifiboxURL,wifiboxCGIBinURL),$(document).on(SettingsWindow.SETTINGS_LOADED,settingsLoaded),debugMode&&(console.log("debug mode is true"),$("body").css("overflow","auto"),$("#debug_textArea").css("display","block"),$("#debug_display").css("display","block")),limitedFeatures&&initLimitedInterface()});
|
|
\ No newline at end of file
|
|
---
|
|
> break;case verticalShapes.SINUS:b=.25*Math.cos(a*Math.PI*4)+.75}return b}function doOnResize(){canvas.width=$canvas.width(),canvas.height=$canvas.height(),preview.width=$preview.width(),preview.height=$drawAreaContainer.height(),canvasWidth=canvas.width,canvasHeight=canvas.height,calcPreviewCanvasProperties(),drawCanvasTopLeftCoords[0]=drawCanvas.offset().left,drawCanvasTopLeftCoords[1]=drawCanvas.offset().top,redrawDoodle(),redrawPreview()}function initLayouting(){$drawAreaContainer=$("#drawareacontainer"),canvas.width=$canvas.width(),canvas.height=$canvas.height(),preview.width=$preview.width(),preview.height=$drawAreaContainer.height(),canvasWidth=canvas.width,canvasHeight=canvas.height,$drawAreaContainer.show(),setTimeout(_startOrientationAndChangeEventListening,1e3)}function _startOrientationAndChangeEventListening(){$(window).on("resize",doOnResize),doOnResize()}function initPreviewRendering(){$preview=$("#preview"),preview=$preview[0],previewCtx=preview.getContext("2d");var a=preview.width/canvas.width;preview_tmp=document.getElementById("preview_tmp"),preview_tmp.width=preview.width,preview_tmp.height=canvas.height*a,$("#preview_tmp").css("top",-preview_tmp.height),previewCtx_tmp=preview_tmp.getContext("2d"),calcPreviewCanvasProperties(),redrawPreview()}function calcPreviewCanvasProperties(){globalScale=preview.width/canvasWidth,layerCX=canvasWidth/2*globalScale,layerCY=canvasHeight/2*globalScale,layerOffsetY=preview.height*(1-previewVerticalPadding.bottom),yStep=(preview.height-preview.height*(previewVerticalPadding.top+previewVerticalPadding.bottom))/maxNumLayers}function redrawPreview(a){if(void 0==a&&(a=!1),_points.length<2)return void previewCtx.clearRect(0,0,preview.width,preview.height);a||(debug_redrawSimplification=_points.length<100?6:_points.length<250?7:_points.length<400?8:_points.length<550?9:_points.length<700?10:11);var b=0,c=0;previewCtx.clearRect(0,0,preview.width,preview.height),previewCtx.lineWidth=strokeWidth,previewCtx.strokeStyle="#f00";for(var d=0;numLayers>d;d++){var e=scaleFunction(d/maxNumLayers);if(previewCtx.globalAlpha=0==d||d==Math.floor(numLayers/2)||d==numLayers-1?1:globalAlpha,a&&d%debug_redrawSimplification!=0&&0!=d&&d!=Math.floor(numLayers/2)&&d!=numLayers-1)b-=yStep,c+=rStep;else{previewCtx.save(),previewCtx.translate(layerCX,layerOffsetY+b),previewCtx.scale(viewerScale*e,scaleY*viewerScale*e),previewCtx.rotate(c),previewCtx.translate(-doodleTransform[0]*globalScale*doodleTransform[2],-doodleTransform[1]*globalScale*doodleTransform[3]);var f=centeredAndScaledDoodlePoint(_points[0]);previewCtx.beginPath(),previewCtx.moveTo(f.x,f.y);for(var g=1;g<_points.length;g++)f=centeredAndScaledDoodlePoint(_points[g]),a&&g%debug_redrawSimplification!=0||previewCtx.lineTo(f.x,f.y);previewCtx.stroke(),b-=yStep,c+=rStep,previewCtx.restore()}}previewCtx.globalAlpha=globalAlpha}function renderToImageDataPreview(){if(!(_points.length<2)){previewCtx_tmp.clearRect(0,0,preview.width,preview.height),previewCtx_tmp.lineWidth=strokeWidth,previewCtx_tmp.strokeStyle="#f00",previewCtx_tmp.save(),previewCtx_tmp.translate(layerCX,layerCY),previewCtx_tmp.scale(viewerScale,viewerScale),previewCtx_tmp.translate(-doodleTransform[0]*globalScale*doodleTransform[2],-doodleTransform[1]*globalScale*doodleTransform[3]);var a=centeredAndScaledDoodlePoint(_points[0]);previewCtx_tmp.beginPath(),previewCtx_tmp.moveTo(a.x,a.y);for(var b=1;b<_points.length;b++)a=centeredAndScaledDoodlePoint(_points[b]),previewDefaults.showTravelLines||1!=_points[b][2]?previewCtx_tmp.lineTo(a.x,a.y):previewCtx_tmp.moveTo(a.x,a.y);previewCtx_tmp.stroke(),previewCtx_tmp.closePath(),previewCtx_tmp.restore();var c=preview_tmp.toDataURL();doodleImageCapture=new Image,doodleImageCapture.onload=function(){previewCtx.clearRect(0,0,preview.width,preview.height),previewCtx.lineWidth=strokeWidth,previewCtx.strokeStyle="#f00";for(var a=0,b=0,c=0;numLayers>c;c++){var d=scaleFunction(c/maxNumLayers);previewCtx.globalAlpha=0==c||c==Math.floor(numLayers/2)||c==numLayers-1?1:globalAlpha,previewCtx.save(),previewCtx.translate(layerCX,layerOffsetY+a),previewCtx.scale(d,scaleY*d),previewCtx.rotate(b),previewCtx.translate(-layerCX,-layerCY),previewCtx.drawImage(doodleImageCapture,0,0),a-=yStep,b+=rStep,previewCtx.restore()}},doodleImageCapture.src=c,previewCtx.globalAlpha=globalAlpha}}function redrawRenderedPreview(a){void 0==a&&(a=!1),previewCtx.clearRect(0,0,preview.width,preview.height),previewCtx.lineWidth=strokeWidth,previewCtx.strokeStyle="#f00";var b=0,c=0;if(doodleImageCapture.src&&""!=doodleImageCapture.src)for(var d=0;numLayers>d;d++){var e=scaleFunction(d/maxNumLayers);previewCtx.globalAlpha=0==d||d==Math.floor(numLayers/2)||d==numLayers-1?1:globalAlpha,a&&d%2!=0&&0!=d&&d!=Math.floor(numLayers/2)&&d!=numLayers-1?(b-=yStep,c+=rStep):(previewCtx.save(),previewCtx.translate(layerCX,layerOffsetY+b),previewCtx.scale(e,scaleY*e),previewCtx.rotate(c),previewCtx.translate(-layerCX,-layerCY),previewCtx.drawImage(doodleImageCapture,0,0),b-=yStep,c+=rStep,previewCtx.restore())}}function centeredAndScaledDoodlePoint(a){var b={x:0,y:0};return b.x=(a[0]-(doodleBounds[2]-doodleBounds[0])/2)*globalScale*doodleTransform[2],b.y=(a[1]-(doodleBounds[3]-doodleBounds[1])/2)*globalScale*doodleTransform[3],b}function updatePreview(a,b,c){if(void 0==c&&(c=!1),c=!1,!(_points.length<2)){if(-1==updatePrevX||-1==updatePrevY)return updatePrevX=a,void(updatePrevY=b);var d=0,e=0;previewCtx.lineWidth=strokeWidth,previewCtx.strokeStyle="#f00";for(var f=0;numLayers>f;f++)if(previewCtx.globalAlpha=0==f||f==Math.floor(numLayers/2)||f==numLayers-1?1:globalAlpha,c&&f%debug_redrawSimplification!=0&&0!=f&&f!=Math.floor(numLayers/2)&&f!=numLayers-1)d-=yStep,e+=rStep;else{previewCtx.save(),previewCtx.translate(layerCX,layerOffsetY+d),previewCtx.scale(viewerScale,scaleY*viewerScale),previewCtx.rotate(e),previewCtx.translate(-doodleTransform[0]*globalScale*doodleTransform[2],-doodleTransform[1]*globalScale*doodleTransform[3]),previewCtx.beginPath();var g=centeredAndScaledDoodlePoint([updatePrevX,updatePrevY]);previewCtx.moveTo(g.x,g.y);var h=centeredAndScaledDoodlePoint([a,b]);previewCtx.lineTo(h.x,h.y),previewCtx.stroke(),d-=yStep,e+=rStep,previewCtx.restore()}previewCtx.globalAlpha=globalAlpha,updatePrevX=a,updatePrevY=b}}function initSidebars(){console.log("f:initSidebars()"),sidebarLeft=new SideBar,sidebarLeft.init("#leftpanel","hideleft",function(){$("#leftpanel").show()}),sidebarRight=new SideBar,sidebarRight.init("#rightpanel","hideright",function(){$("#rightpanel").show()})}function SideBar(){this.initted=!1,this.$contentTarg=void 0,this.$sideBtn=void 0,this.contentHidden=!1,this.hideClass="",this.init=function(a,b,c){console.log("SideBar >> f:init >> targ: ",$(a),", hideClass: "+b),this.$contentTarg=$(a),this.hideClass=b,this.$contentTarg.addClass(this.hideClass),this.contentHidden=!0,this.$contentTarg.append("<div class='sidebutton'></div>"),this.$sideBtn=$(a+" .sidebutton");var d=this;this.$sideBtn.on("click",function(){console.log("sidebutton"),d.toggleShowHide()}),this.initted=!0,c()},this.toggleShowHide=function(){this.contentHidden?(this.contentHidden=!1,this.$contentTarg.removeClass(this.hideClass),this.$sideBtn.addClass("sidebuttonin")):(this.contentHidden=!0,this.$contentTarg.addClass(this.hideClass),this.$sideBtn.removeClass("sidebuttonin"))}}function previousSketch(){loadSketch(curSketch-1)}function nextSketch(){loadSketch(curSketch+1)}function newSketch(){clearDoodle(),curSketch=sketches.length,updateSketchButtonStates()}function listSketches(){console.log("listSketches"),$.get(wifiboxURL+"/sketch/list",function(a){"success"==a.status&&(sketches=a.data.list,curSketch=sketches.length-1,setSketchModified(!1),updateSketchButtonStates())})}function setSketchModified(a){isModified=a,updateSketchButtonStates()}function updateSketchButtonStates(){console.log("sketch: isModified",isModified,"curSketch",curSketch,"sketches.length",sketches.length),isModified?btnSave.enable():btnSave.disable(),curSketch<sketches.length-1?btnNext.enable():btnNext.disable(),curSketch>0?btnPrevious.enable():btnPrevious.disable()}function loadSketch(a){curSketch=a,0>curSketch&&(curSketch=0),curSketch>sketches.length-1&&(curSketch=sketches.length-1);var b=sketches[curSketch];console.log("sketch: loadSketch curSketch",curSketch,"id",b),$.get(wifiboxURL+"/sketch",{id:b},function(a){if("success"==a.status){console.log("sketch: loaded",a);var b=a.data.data;loadFromSvg(b),setSketchModified(!1),sketchLoaded=!0}else console.log("error loading sketch: ",a),listSketches()})}function saveSketch(){console.log("sketch: saveSketch");var a=saveToSvg();$.post(wifiboxURL+"/sketch",{data:a},function(a){console.log("sketch: saveSketch: response",a),listSketches()})}function getURLParameter(a){return decodeURI((new RegExp("[&?]"+a+"=(.+?)(&|$)").exec(location.search)||[,null])[1])}function isMobileDevice(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Windows Mobile/i.test(navigator.userAgent)}function isSmartphone(){var a=!1;if(/Android/i.test(navigator.userAgent)&&window.devicePixelRatio>1){var b=$(window).width()/window.devicePixelRatio;console.log("Android device >> ratio'd width: "+b),480>b&&(a=!0)}else a=/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini|Windows Mobile/i.test(navigator.userAgent);return a}function distance(a,b,c,d){return Math.sqrt((c-a)*(c-a)+(d-b)*(d-b))}function setVerticalShape(a){VERTICALSHAPE=a,redrawRenderedPreview()}function initVerticalShapes(){resetVerticalShapes()}function resetVerticalShapes(){setVerticalShape(verticalShapes.NONE)}function disableDragging(){$(document).bind("dragstart",function(a){console.log("dragstart"),a.preventDefault()})}function showOrHideThermo(){console.log("f:showOrHideThermo()"),showOrHide?(thermometer.hide(),progressbar.hide()):(thermometer.show(),progressbar.show()),showOrHide=!showOrHide}function settingsLoaded(){console.log("settingsLoaded"),firstTimeSettingsLoaded&&(console.log(" preheat: ",settings["printer.heatup.enabled"]),console.log(" state: ",state),state==Printer.IDLE_STATE&&settings["printer.heatup.enabled"]&&printer.preheat(),console.log("doodle3d.tour.enabled: ",settings["doodle3d.tour.enabled"]),settings["doodle3d.tour.enabled"]&&!clientInfo.isSmartphone&&(console.log("show tour"),initHelp()),firstTimeSettingsLoaded=!1)}function setDebugText(a){$("#debug_display").text(a)}var settings={},settingsPopup,objectHeight=20,layerHeight=.2,enableTraveling=!0,minScale=.3,maxScale=1,shape="%",twists=0,loglevel=2,serverport=8888,autoLoadImage="hand.txt",loadOffset=[0,0],showWarmUp=!0,loopAlways=!1,firstLayerSlow=!0,useSubpathColors=!1,autoWarmUp=!0,maxScaleDifference=.1,frameRate=60,quitOnEscape=!0,screenToMillimeterScale=.3,sideis3D=!0,sidevisible=!0,sidebounds=[900,210,131,390],sideborder=[880,169,2,471],windowbounds=[0,0,800,500],windowcenter=!0,windowfullscreen=!1,autoWarmUpCommand="M104 S230",autoWarmUpDelay=3,shapePopup;$("#fileScan").change(function(){readURL(this)});var shapeResolution=3,shapePopup;Button.prototype=new jQuery,$.fn.Button=function(){return $(this).each(function(){new Button(this)})};var grandTour,infoReminderTour,helpTours,keyboardShortcutsEnabled=!0,keyboardEscapeEnterEnabled=!1,wordBuffer="",wordFuncs={idbeholdl:function(){alert("Light!")},idspispopd:function(){drawTextOnCanvas("Im in ur kanvas drawin' ur stuffz.")},dia:function(){var a=canvasWidth/2,b=canvasHeight/2;drawCircle(a,b,50,4),shapeMoveTo(a-20,b),shapeLineTo(a+20,b),shapeMoveTo(a,b-20),shapeLineTo(a,b+20)},stats:function(){var a="Shape statistics:\nNumber of points: "+_points.length;alert(a)},pdump:function(){console.log("points array: "+_points)}},$displayThermometer=$("#thermometerContainer"),wordArtPopup,twistIncrement=Math.PI/1800,btnNew,btnPrevious,btnNext,btnOops,btnStop,btnInfo,btnSettings,btnWordArt,btnToggleEdit,buttonGroupEdit,btnZoom,btnMove,btnRotate,btnToggleVerticalShapes,btnHeight,btnTwist,btnShape,btnConv,btnStraight,btnSine,btnDiv,buttonGroupAdd,popupWordArt,btnScan,popupScan,state,prevState,hasControl,gcodeGenerateDelayer,gcodeGenerateDelay=50,preheatDelay,preheatDelayTime=15e3,connectingHintDelay=null,connectingHintDelayTime=2e4,preview,previewCtx,svgPathRegExp=/[LM]\d* \d*/gi,svgPathParamsRegExp=/([LM])(\d*) (\d*)/,dragging=!1,$canvas,canvas,ctx,canvasWidth,canvasHeight,drawCanvas,drawCanvasTopLeftCoords=[0,0],doodleBounds=[-1,-1,-1,-1],doodleTransform=[0,0,1,1],_points=[],prevCountingTime=0,movementCounter=0,drawVariableLineWeight=!1,lineweight=2,isModified=!1,showTravelLines=!1,prevPoint={x:-1,y:-1};prevUpdateFullPreview=0,prevUpdateFullPreviewInterval=25;var MAX_POINTS_TO_PRINT=2e5,gcode=[];pointsTranslate=function(a,b,c){for(var d=0;d<a.length;d++)a[d][0]+=b,a[d][1]+=c},pointsScale=function(a,b,c){for(var d=0;d<a.length;d++)a[d][0]*=b,a[d][1]*=c},pointsRotate=function(a,b){for(var c,d,e=0;e<a.length;e++)d=Math.sqrt(a[e][0]*a[e][0]+a[e][1]*a[e][1]),c=Math.atan2(a[e][1],a[e][0]),a[e][0]=Math.cos(c+b)*d,a[e][1]=Math.sin(c+b)*d},lineLength=function(a,b,c,d){return Math.sqrt((a-=c)*a+(b-=d)*b)};var Point=function(){};Point.prototype={x:0,y:0,set:function(a,b){this.x=a,this.y=b},distance:function(a){var b=-1;return a instanceof Point&&(b=Math.sqrt((a.x-this.x)*(a.x-this.x)+(a.y-this.y)*(a.y-this.y))),b},toString:function(){console.log("x:"+this.x+", y:"+this.y)}};var drawAreaContainerMinHeight=300,drawAreaContainerMaxHeight=450,$preview,preview,previewCtx,preview_tmp,previewCtx_tmp,previewDefaults={rotation:0,numLayers:2,showTravelLines:!1},svgPathRegExp=/[LM]\d* \d*/gi,svgPathParamsRegExp=/([LM])(\d*) (\d*)/,prevRedrawTime=(new Date).getTime(),redrawInterval=1e3/30,previewRotationLimit=Math.PI/30,numLayers=previewDefaults.numLayers,maxNumLayers=100,minNumLayers=2,globalScale=.3,globalAlpha=.2,scaleY=.4,viewerScale=.65,previewVerticalPadding={top:.15,bottom:.12},strokeWidth=2,rStep=previewDefaults.rotation,yStep,layerCX,layerCY,layerOffsetY,prevX=0,prevY=0,highlight=!0,linesRaw="",debug_redrawSimplification=6,updatePrevX=-1,updatePrevY=-1,sidebarLeft,sidebarRight,curSketch=0,sketches=[],sketchLoaded=!1,VERTICALSHAPE,verticalShapes={NONE:"none",DIVERGING:"diverging",CONVERGING:"converging",SINUS:"sinus"},debugMode=!1,sendPrintCommands=!0,communicateWithWifibox=!0,wifiboxIsRemote=!1,autoUpdate=!0,printer=new Printer,progressbar=new Progressbar,thermometer=new Thermometer,settingsWindow=new SettingsWindow,message=new Message,firstTimeSettingsLoaded=!0,wifiboxURL,wifiboxCGIBinURL,$drawAreaContainer,$doodleCanvas,doodleCanvas,doodleCanvasContext,$previewContainer,showhideInterval,showOrHide=!1,limitedFeatures=!1,clientInfo={},POPUP_SHOW_DURATION=175,BUTTON_GROUP_SHOW_DURATION=80;$(function(){console.log("ready"),"null"!=getURLParameter("d")&&(debugMode="1"==getURLParameter("d")),"null"!=getURLParameter("p")&&(sendPrintCommands="1"==getURLParameter("p")),"null"!=getURLParameter("c")&&(communicateWithWifibox="1"==getURLParameter("c")),"null"!=getURLParameter("r")&&(wifiboxIsRemote="1"==getURLParameter("r")),"null"!=getURLParameter("u")&&(autoUpdate="1"==getURLParameter("u")),"null"!=getURLParameter("l")&&(limitedFeatures="1"==getURLParameter("l"));var a;wifiboxIsRemote&&(a="http://192.168.5.1"),"null"!=getURLParameter("wifiboxURL")&&(a=getURLParameter("wifiboxURL")),a||(a="http://"+window.location.host),wifiboxURL=a+"/d3dapi",wifiboxCGIBinURL=a+"/cgi-bin/d3dapi",communicateWithWifibox||(sendPrintCommands=!1),console.log("debugMode: "+debugMode),console.log("sendPrintCommands: "+sendPrintCommands),console.log("communicateWithWifibox: "+communicateWithWifibox),console.log("wifiboxIsRemote: "+wifiboxIsRemote),console.log("wifibox URL: "+wifiboxURL),clientInfo.isMobileDevice=isMobileDevice(),clientInfo.isSmartphone=isSmartphone(),initDoodleDrawing(),initPreviewRendering(),initLayouting(),initButtonBehavior(),initKeyboard(),initWordArt(),initShapeDialog(),initScanDialog(),disableDragging(),clientInfo.isSmartphone||initHelp(),thermometer.init($("#thermometerCanvas"),$("#thermometerContainer")),progressbar.init($("#progressbarCanvas"),$("#progressbarCanvasContainer")),message.init($("#message")),printer.init(),$(document).on(Printer.UPDATE,update),settingsWindow.init(wifiboxURL,wifiboxCGIBinURL),$(document).on(SettingsWindow.SETTINGS_LOADED,settingsLoaded),debugMode&&(console.log("debug mode is true"),$("body").css("overflow","auto"),$("#debug_textArea").css("display","block"),$("#debug_display").css("display","block")),limitedFeatures&&initLimitedInterface()});
|
|
\ No newline at end of file
|