From e20ba61f65a657b4850b7353cd1f6b23e5b6f95c Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Mon, 7 Aug 2017 09:38:53 -1000 Subject: [PATCH 1/2] Fixes to inch/mm detection --- widget.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/widget.js b/widget.js index 1a13975..1df4c82 100644 --- a/widget.js +++ b/widget.js @@ -2453,7 +2453,6 @@ cpdefine('inline:com-chilipeppr-widget-3dviewer', ['chilipeppr_ready', 'Three', this.lastArgs = {cmd: null}; this.lastFeedrate = null; - this.isUnitsMm = true; this.parseLine = function (text, info) { var origtext = text; @@ -3312,16 +3311,14 @@ cpdefine('inline:com-chilipeppr-widget-3dviewer', ['chilipeppr_ready', 'Three', // However, we need to set a global property so the trinket decorations // like toolhead, axes, grid, and extent labels are scaled correctly // later on when they are drawn after the gcode is rendered - console.log("SETTING UNITS TO INCHES!!!"); - cofg.isUnitsMm = false; // false means inches cuz default is mm + cofg.setUnits("inch"); }, G21: function () { // G21: Set Units to Millimeters // Example: G21 // Units from now on are in millimeters. (This is the RepRap default.) - console.log("SETTING UNITS TO MM!!!"); - cofg.isUnitsMm = true; // true means mm + cofg.setUnits("mm"); }, // A bunch of no-op modes that do not affect the viewer @@ -3418,10 +3415,6 @@ cpdefine('inline:com-chilipeppr-widget-3dviewer', ['chilipeppr_ready', 'Three', parser.parse(gcode); - // set what units we're using in the gcode - //console.log('setting units from parser to 3dviewer. parser:', parser, "this:", this); - this.isUnitsMm = parser.isUnitsMm; - console.log("inside creatGcodeFromObject. this:", this); console.log("Layer Count ", layers.length); From ae8942f031edc73c78089768df829da699330c7f Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Mon, 7 Aug 2017 19:57:06 +0000 Subject: [PATCH 2/2] Made some changes to ChiliPeppr widget using Cloud9 --- README.md | 12 ++++++------ auto-generated-widget.html | 19 ++++++------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 0a57e51..eaba2da 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,10 @@ not conflict with other ChiliPeppr widgets. | ID | com-chilipeppr-widget-3dviewer | | Name | Widget / 3D GCode Viewer | | Description | Visualize your GCode in 3D by simulating your GCode run or seeing where your run is at in 3D while your CNC operation is in action. | -| chilipeppr.load() URL | http://raw.githubusercontent.com/dchote/widget-3dviewer/master/auto-generated-widget.html | -| Edit URL | http://ide.c9.io/undefined/undefined | -| Github URL | http://github.com/dchote/widget-3dviewer | -| Test URL | https://preview.c9users.io/undefined/undefined/widget.html | +| chilipeppr.load() URL | http://raw.githubusercontent.com/MitchBradley/widget-3dviewer/master/auto-generated-widget.html | +| Edit URL | http://ide.c9.io/mitchbradley/widget-3dviewer-dchotepull | +| Github URL | http://github.com/MitchBradley/widget-3dviewer | +| Test URL | https://preview.c9users.io/mitchbradley/widget-3dviewer-dchotepull/widget.html | ## Example Code for chilipeppr.load() Statement @@ -33,7 +33,7 @@ $("body").append('<' + 'div id="myDivWidget3dviewer"><' + '/div>'); chilipeppr.load( "#myDivWidget3dviewer", - "http://raw.githubusercontent.com/dchote/widget-3dviewer/master/auto-generated-widget.html", + "http://raw.githubusercontent.com/MitchBradley/widget-3dviewer/master/auto-generated-widget.html", function() { // Callback after widget loaded into #myDivWidget3dviewer // Now use require.js to get reference to instantiated widget @@ -132,7 +132,7 @@ The table below shows, in order, the methods and properties inside the widget/el - idstring"com-chilipeppr-widget-3dviewer"namestring"Widget / 3D GCode Viewer"descstring"Visualize your GCode in 3D by simulating your GCode run or seeing where your run is at in 3D while your CNC operation is in action."urlstring"http://raw.githubusercontent.com/dchote/widget-3dviewer/master/auto-generated-widget.html"fiddleurlstring"http://ide.c9.io/undefined/undefined"githuburlstring"http://github.com/dchote/widget-3dviewer"testurlstring"http://undefined-undefined.c9users.io/widget.html"publishobjectPlease see docs above.subscribeobjectPlease see docs above.foreignSubscribeobjectPlease see docs above.foreignPublishobjectPlease see docs above.initOptionsobjectonSignalSceneReloadedFailAttemptsnumberdomElementobjectsceneobjectobjectobjectcameraobjectcontrolsobjecttoolheadobjectdecorateobjectshadowplaneobjectgridobjectaxesobjectelementobjectparsedLinesobjectlineObjectsobjectsceneCenterobjectsceneBoundariesobjectisUnitsMmbooleananimationLatencyTimerobjectanimationLatencyDelaynumberanimationLatencyDelayDefaultnumberinspectLatencyTimerobjectinspectLatencyDelaynumberjogLatencyTimerobjectjogLatencyDelaynumbermoveAnimatebooleangotoAnimatebooleantweenAnimatebooleaninspectAnimatebooleanfpsCalculationTimerobjectrenderFrameCountnumbertweenobjecttweenHighlightobjecttweenIndexobjecttweenSpeednumbertweenPausedbooleantweenIsPlayingbooleanzheighttestnumbertextFontbooleanisInspectSelectbooleaninspectArrowGrpobjectinspectCurPosobjectinspectLastObjobjectinspectLastDecorateGroupobjectinspectDlgElobjectisJogBtnAttachedbooleanisJogSelectbooleanarrowHelperobjectjogPlaneobjectisJogRaycasterbooleanjogArrowobjectjogArrowCylobjectjogArrowLineobjectjogArrowShadowobjectjogCurPosobjectcolorBackgroundnumbercolorG0numbercolorG1numbercolorG2numbercolorArcnumbercolorActivenumbercolorCompletednumbercolorGhostednumberlineWidthnumberdisableAnimationbooleandisableAAbooleanshowShadowbooleangridSizenumberisLookAtToolHeadModebooleaninitfunctionfunction (initOptions) setupScenePubSubfunctionfunction () onSignalSceneReloadedfunctionfunction () initInspectfunctionfunction () setupInspectfunctionfunction (evt) unsetupInspectfunctionfunction () toggleInspectfunctionfunction (evt) inspectKeyDownfunctionfunction (evt) inspectKeyUpfunctionfunction (evt) inspectMouseClickfunctionfunction (evt) onInspectGotofunctionfunction (evt) createInspectArrowfunctionfunction () inspectMouseMovefunctionfunction (evt) createGlowfunctionfunction (threeObj) createGlowCubeCapsfunctionfunction (threeObj) initJogfunctionfunction () setupJogfunctionfunction (evt) unsetupJogfunctionfunction () toggleJogfunctionfunction (evt) jogKeyDownfunctionfunction (evt) jogKeyUpfunctionfunction (evt) unsetupJogRaycasterfunctionfunction () setupJogRaycasterfunctionfunction () jogMouseClickfunctionfunction (evt) jogMouseMovefunctionfunction (evt) setupCogMenufunctionfunction () setCogMenuStatefunctionfunction () onToggleAAClickfunctionfunction (evt, param) onToggleShadowClickfunctionfunction (evt, param) onToggleAnimationClickfunctionfunction (evt, param) setupGridSizeMenufunctionfunction () onGridSizeClickfunctionfunction (evt, param) setUnitsfunctionfunction (units) requestUnitsfunctionfunction () onUnitsChangedfunctionfunction () request3dObjectfunctionfunction () sceneAddfunctionfunction (obj) sceneRemovefunctionfunction (obj) sceneClearfunctionfunction () btnSetupfunctionfunction () forkSetupfunctionfunction () onPubSubFileLoadedfunctionfunction (txt) errorfunctionfunction (msg) loadFilefunctionfunction (path, callback /* function(contents) */ ) setDetailsfunctionfunction (txt) speedUpfunctionfunction () openGCodeFromPathfunctionfunction (path) openGCodeFromTextfunctionfunction (gcode) lookAtCenterfunctionfunction () lookAtToolHeadfunctionfunction () toCameraCoordsfunctionfunction (position) scaleInViewfunctionfunction () viewExtentsfunctionfunction () stopSampleRunfunctionfunction (evt) pauseSampleRunfunctionfunction () gotoXyzfunctionfunction (data) gotoLinefunctionfunction (data) playNextTweenfunctionfunction (isGotoLine) playSampleRunfunctionfunction (evt) downloadFontfunctionfunction () makeTextfunctionfunction (vals) decorateExtentsfunctionfunction () convertMinsToPrettyDurationfunctionfunction (mins) makeSpritefunctionfunction (scene, rendererType, vals) getInchesFromMmfunctionfunction (mm) getUnitValfunctionfunction (val) drawAxesToolAndExtentsfunctionfunction () drawToolheadfunctionfunction () gridTurnOfffunctionfunction () gridTurnOnfunctionfunction () drawGridfunctionfunction () drawExtentsLabelsfunctionfunction () drawAxesfunctionfunction () createScenefunctionfunction (element) resizefunctionfunction () wakeAnimatefunctionfunction () animatefunctionfunction () GCodeParserfunctionfunction (handlers, modecmdhandlers)

Parses a string of gcode instructions, and invokes handlers for + idstring"com-chilipeppr-widget-3dviewer"namestring"Widget / 3D GCode Viewer"descstring"Visualize your GCode in 3D by simulating your GCode run or seeing where your run is at in 3D while your CNC operation is in action."urlstring"http://raw.githubusercontent.com/MitchBradley/widget-3dviewer/master/auto-generated-widget.html"fiddleurlstring"http://ide.c9.io/mitchbradley/widget-3dviewer-dchotepull"githuburlstring"http://github.com/MitchBradley/widget-3dviewer"testurlstring"http://widget-3dviewer-dchotepull-mitchbradley.c9users.io/widget.html"publishobjectPlease see docs above.subscribeobjectPlease see docs above.foreignSubscribeobjectPlease see docs above.foreignPublishobjectPlease see docs above.initOptionsobjectonSignalSceneReloadedFailAttemptsnumberdomElementobjectsceneobjectobjectobjectcameraobjectcontrolsobjecttoolheadobjectdecorateobjectshadowplaneobjectgridobjectaxesobjectelementobjectparsedLinesobjectlineObjectsobjectsceneCenterobjectsceneBoundariesobjectisUnitsMmbooleananimationLatencyTimerobjectanimationLatencyDelaynumberanimationLatencyDelayDefaultnumberinspectLatencyTimerobjectinspectLatencyDelaynumberjogLatencyTimerobjectjogLatencyDelaynumbermoveAnimatebooleangotoAnimatebooleantweenAnimatebooleaninspectAnimatebooleanfpsCalculationTimerobjectrenderFrameCountnumbertweenobjecttweenHighlightobjecttweenIndexobjecttweenSpeednumbertweenPausedbooleantweenIsPlayingbooleanzheighttestnumbertextFontbooleanisInspectSelectbooleaninspectArrowGrpobjectinspectCurPosobjectinspectLastObjobjectinspectLastDecorateGroupobjectinspectDlgElobjectisJogBtnAttachedbooleanisJogSelectbooleanarrowHelperobjectjogPlaneobjectisJogRaycasterbooleanjogArrowobjectjogArrowCylobjectjogArrowLineobjectjogArrowShadowobjectjogCurPosobjectcolorBackgroundnumbercolorG0numbercolorG1numbercolorG2numbercolorArcnumbercolorActivenumbercolorCompletednumbercolorGhostednumberlineWidthnumberdisableAnimationbooleandisableAAbooleanshowShadowbooleangridSizenumberisLookAtToolHeadModebooleaninitfunctionfunction (initOptions) setupScenePubSubfunctionfunction () onSignalSceneReloadedfunctionfunction () initInspectfunctionfunction () setupInspectfunctionfunction (evt) unsetupInspectfunctionfunction () toggleInspectfunctionfunction (evt) inspectKeyDownfunctionfunction (evt) inspectKeyUpfunctionfunction (evt) inspectMouseClickfunctionfunction (evt) onInspectGotofunctionfunction (evt) createInspectArrowfunctionfunction () inspectMouseMovefunctionfunction (evt) createGlowfunctionfunction (threeObj) createGlowCubeCapsfunctionfunction (threeObj) initJogfunctionfunction () setupJogfunctionfunction (evt) unsetupJogfunctionfunction () toggleJogfunctionfunction (evt) jogKeyDownfunctionfunction (evt) jogKeyUpfunctionfunction (evt) unsetupJogRaycasterfunctionfunction () setupJogRaycasterfunctionfunction () jogMouseClickfunctionfunction (evt) jogMouseMovefunctionfunction (evt) setupCogMenufunctionfunction () setCogMenuStatefunctionfunction () onToggleAAClickfunctionfunction (evt, param) onToggleShadowClickfunctionfunction (evt, param) onToggleAnimationClickfunctionfunction (evt, param) setupGridSizeMenufunctionfunction () onGridSizeClickfunctionfunction (evt, param) setUnitsfunctionfunction (units) requestUnitsfunctionfunction () onUnitsChangedfunctionfunction () request3dObjectfunctionfunction () sceneAddfunctionfunction (obj) sceneRemovefunctionfunction (obj) sceneClearfunctionfunction () btnSetupfunctionfunction () forkSetupfunctionfunction () onPubSubFileLoadedfunctionfunction (txt) errorfunctionfunction (msg) loadFilefunctionfunction (path, callback /* function(contents) */ ) setDetailsfunctionfunction (txt) speedUpfunctionfunction () openGCodeFromPathfunctionfunction (path) openGCodeFromTextfunctionfunction (gcode) lookAtCenterfunctionfunction () lookAtToolHeadfunctionfunction () toCameraCoordsfunctionfunction (position) scaleInViewfunctionfunction () viewExtentsfunctionfunction () stopSampleRunfunctionfunction (evt) pauseSampleRunfunctionfunction () gotoXyzfunctionfunction (data) gotoLinefunctionfunction (data) playNextTweenfunctionfunction (isGotoLine) playSampleRunfunctionfunction (evt) downloadFontfunctionfunction () makeTextfunctionfunction (vals) decorateExtentsfunctionfunction () convertMinsToPrettyDurationfunctionfunction (mins) makeSpritefunctionfunction (scene, rendererType, vals) getInchesFromMmfunctionfunction (mm) getUnitValfunctionfunction (val) drawAxesToolAndExtentsfunctionfunction () drawToolheadfunctionfunction () gridTurnOfffunctionfunction () gridTurnOnfunctionfunction () drawGridfunctionfunction () drawExtentsLabelsfunctionfunction () drawAxesfunctionfunction () createScenefunctionfunction (element) resizefunctionfunction () wakeAnimatefunctionfunction () animatefunctionfunction () GCodeParserfunctionfunction (handlers, modecmdhandlers)

Parses a string of gcode instructions, and invokes handlers for each type of command.

Special handler: 'default': Called if no other handler matches.createObjectFromGCodefunctionfunction (gcode, indxMax) convertLineGeometryToBufferGeometryfunctionfunction (lineGeometry, color) diff --git a/auto-generated-widget.html b/auto-generated-widget.html index f14b873..36b7fd4 100644 --- a/auto-generated-widget.html +++ b/auto-generated-widget.html @@ -246,10 +246,10 @@ id: 'com-chilipeppr-widget-3dviewer', name: "Widget / 3D GCode Viewer", desc: "Visualize your GCode in 3D by simulating your GCode run or seeing where your run is at in 3D while your CNC operation is in action.", - url: "http://raw.githubusercontent.com/dchote/widget-3dviewer/master/auto-generated-widget.html", // The final URL of the working widget as a single HTML file with CSS and Javascript inlined. You can let runme.js auto fill this if you are using Cloud9. - fiddleurl: "http://ide.c9.io/undefined/undefined", // The edit URL. This can be auto-filled by runme.js in Cloud9 if you'd like, or just define it on your own to help people know where they can edit/fork your widget - githuburl: "http://github.com/dchote/widget-3dviewer", // The backing github repo - testurl: "http://undefined-undefined.c9users.io/widget.html", // The standalone working widget so can view it working by itself + url: "http://raw.githubusercontent.com/MitchBradley/widget-3dviewer/master/auto-generated-widget.html", // The final URL of the working widget as a single HTML file with CSS and Javascript inlined. You can let runme.js auto fill this if you are using Cloud9. + fiddleurl: "http://ide.c9.io/mitchbradley/widget-3dviewer-dchotepull", // The edit URL. This can be auto-filled by runme.js in Cloud9 if you'd like, or just define it on your own to help people know where they can edit/fork your widget + githuburl: "http://github.com/MitchBradley/widget-3dviewer", // The backing github repo + testurl: "http://widget-3dviewer-dchotepull-mitchbradley.c9users.io/widget.html", // The standalone working widget so can view it working by itself publish: { '/recv3dObject' : "When you send a /request3dObject you will receive a signal back of /recv3dObject. This signal has a payload of the THREE.js user object being shown in the 3D viewer.", '/recvUnits' : 'When you send a /requestUnits you will receive back this signal with a payload of "mm" or "inch" as a string. Please also see /unitsChanged in case you want to know whenever units are changed from a file open event. You can request what units the Gcode are in from the 3D Viewer. Since the 3D Viewer parses Gcode, it can determine the units. The 3D Viewer is mostly unit agnostic, however to draw the toolhead, grid, and extents labels it does need to know the units to draw the decorations in a somewhat appropriate size.', @@ -2559,7 +2559,6 @@ this.lastArgs = {cmd: null}; this.lastFeedrate = null; - this.isUnitsMm = true; this.parseLine = function (text, info) { var origtext = text; @@ -3418,16 +3417,14 @@ // However, we need to set a global property so the trinket decorations // like toolhead, axes, grid, and extent labels are scaled correctly // later on when they are drawn after the gcode is rendered - console.log("SETTING UNITS TO INCHES!!!"); - cofg.isUnitsMm = false; // false means inches cuz default is mm + cofg.setUnits("inch"); }, G21: function () { // G21: Set Units to Millimeters // Example: G21 // Units from now on are in millimeters. (This is the RepRap default.) - console.log("SETTING UNITS TO MM!!!"); - cofg.isUnitsMm = true; // true means mm + cofg.setUnits("mm"); }, // A bunch of no-op modes that do not affect the viewer @@ -3524,10 +3521,6 @@ parser.parse(gcode); - // set what units we're using in the gcode - //console.log('setting units from parser to 3dviewer. parser:', parser, "this:", this); - this.isUnitsMm = parser.isUnitsMm; - console.log("inside creatGcodeFromObject. this:", this); console.log("Layer Count ", layers.length);