├── .gitignore ├── Adding a printer to Spark PrintManager.pdf ├── Autodesk_Spark Contrib Agreement.pdf ├── Connection of Print Studio to Print Manager.pdf ├── LICENSE ├── Print Manager Documentation.pdf ├── README.md ├── spark-print-data ├── .gitignore ├── README.md ├── data │ ├── DreamMaker_OverLord.zip │ ├── DreamMaker_OverLord_100x100.png │ ├── DreamMaker_OverLord_16x16.png │ ├── DreamMaker_OverLord_200x60.png │ ├── DreamMaker_OverLord_32x32.png │ ├── DreamMaker_OverLord_400x120.png │ ├── DreamMaker_OverLord_50x50.png │ ├── DremelPackager.lua │ ├── DremelPrintableIcon.bmp │ ├── EmberPackager.lua │ ├── OCFarm1.zip │ ├── OCFarm1_100x100.png │ ├── OCFarm1_16x16.png │ ├── OCFarm1_32x32.png │ ├── OCFarm1_50x50.png │ ├── RepRapPrusaMendel.zip │ ├── TypeA.zip │ ├── dremel.zip │ ├── dremel_100x100.png │ ├── dremel_16x16.png │ ├── dremel_200x60.png │ ├── dremel_32x32.png │ ├── dremel_400x120.png │ ├── dremel_50x50.png │ ├── ember.zip │ ├── ember_100x100.png │ ├── ember_16x16.png │ ├── ember_200x60.png │ ├── ember_32x32.png │ ├── ember_400x120.png │ ├── ember_50x50.png │ ├── printrbotplay.zip │ ├── printrbotplay_100x100.png │ ├── printrbotplay_16x16.png │ ├── printrbotplay_32x32.png │ ├── printrbotplay_50x50.png │ ├── printrbotplus.zip │ ├── printrbotplus_100x100.png │ ├── printrbotplus_16x16.png │ ├── printrbotplus_32x32.png │ ├── printrbotplus_50x50.png │ ├── printrbotsimple.zip │ ├── printrbotsimple_100x100.png │ ├── printrbotsimple_16x16.png │ ├── printrbotsimple_32x32.png │ ├── printrbotsimple_50x50.png │ ├── replicator2.zip │ ├── replicator2_100x100.png │ ├── replicator2_16x16.png │ ├── replicator2_32x32.png │ ├── replicator2_50x50.png │ ├── replicator2x.zip │ ├── typeA_100x100.png │ ├── typeA_16x16.png │ ├── typeA_32x32.png │ ├── typeA_50x50.png │ ├── ultimaker2.zip │ ├── ultimaker2_100x100.png │ ├── ultimaker2_16x16.png │ ├── ultimaker2_32x32.png │ └── ultimaker2_50x50.png ├── materials.json ├── materials_generator │ ├── Spark Matrix Ammended V10_Mike.xls │ ├── export_rgb.js │ ├── materials.json │ └── materials_to_json.js ├── printertypes.json ├── profiles.json └── version.json └── spark-print-mgr ├── .gitignore ├── LocalFileUploader.js ├── README.md ├── app.js ├── appSettings.js ├── bin ├── macos │ └── node └── win │ ├── node.exe │ ├── nssm.exe │ └── nssm64.exe ├── build.py ├── config.js ├── config.json ├── console ├── README.md ├── css │ └── console.css ├── icons │ ├── Add.png │ ├── Back.png │ ├── Delete.png │ ├── DreamMaker_OverLord.png │ ├── Edit.png │ ├── Options.png │ ├── Refresh.png │ ├── dremel.png │ ├── ember.png │ ├── printrbotplay.png │ ├── printrbotplus.png │ ├── printrbotsimple.png │ ├── replicator2.png │ ├── typeA.png │ └── ultimaker2.png ├── index.html ├── js │ ├── app.js │ ├── controllers.js │ └── services.js ├── partials │ ├── printJobDetails.html │ ├── printerAdd.html │ ├── printerDetails.html │ ├── printerList.html │ ├── printersEdit.html │ └── settings.html └── vendor │ ├── css │ └── bootstrap.min.css │ └── js │ ├── angular-resource.min.js │ ├── angular-resource.min.js.map │ ├── angular-route.min.js │ ├── angular-route.min.js.map │ ├── angular.min.js │ └── angular.min.js.map ├── error ├── APIError.js ├── ErrorFactory.js └── Errors.js ├── fileMetadata.js ├── files.js ├── install_os_dependencies.js ├── jobs.js ├── logging ├── Logger.js └── PrintManagerLogger.js ├── materials.js ├── meshes.js ├── package.json ├── package_mac.json ├── package_win.json ├── printableTranslation ├── DLPPrintable.proto ├── DLPReader.js ├── DLPTranslator.js ├── FDMPrintable.proto ├── FDMReader.js ├── FDMTranslator.js ├── FDMTranslatorDelta.js ├── FDMTranslatorMakerbot.js ├── FDMTranslatorMarlin.js ├── FDMTranslatorPrintrbot.js ├── PrintableReader.js ├── README.md ├── Translator.js ├── TranslatorFactory.js └── translators │ ├── Autodesk-Ember.js │ ├── DreamMaker_OverLord.js │ ├── Dremel.js │ ├── Ocean-Farm1.js │ ├── Printrbot-Play.js │ ├── Printrbot-Plus.js │ ├── Printrbot-Simple.js │ ├── Replicator2.js │ ├── TypeA.js │ └── Ultimaker.js ├── printers ├── bonjourDiscovery.js ├── command.js ├── connectionFactory.js ├── conveyorDiscovery.js ├── deviceData.js ├── deviceMonitor.js ├── discoveryFactory.js ├── driver.js ├── driverResponse.js ├── drivers │ ├── commandQueue.js │ ├── conveyor.js │ ├── dremel.js │ ├── driverApi.js │ ├── driverBase.js │ ├── driverConfig.json │ ├── ember.js │ ├── gcodeClient.js │ ├── marlin.js │ ├── octoprint.js │ ├── overlord.js │ ├── printrbot.js │ ├── serial.js │ ├── serialCommandExecutor.js │ ├── serialConnection.js │ ├── ultimaker.js │ └── virtualPrinter.js ├── emberDiscovery.js ├── exportPrinter.js ├── jobStatus.js ├── printer.js ├── printerManager.js ├── printerUtil.js ├── rpc.js ├── sandbox │ └── test.js ├── serialDiscovery.js ├── status.js └── usbDiscovery.js ├── printertypes.js ├── profiles.js ├── resource.js ├── roopa.js ├── roopaScripts ├── analyzeMesh.lua ├── createTray.lua ├── exportMesh.lua ├── exportSupports.lua ├── generatePrintable.lua ├── generateVisual.lua ├── getVersion.lua ├── hello.lua ├── importMesh.lua ├── prepareTray.lua ├── renameMesh.lua ├── repairMesh.lua └── transformMesh.lua ├── server.js ├── tasks.js ├── test ├── AppSettingsSpec.js ├── DLPReaderSpec.js ├── DLPTranslatorSpec.js ├── DateUtilsSpec.js ├── FDMPrintableSpec.js ├── FileSpec.js ├── JobsSpec.js ├── LocalFileUploaderSpec.js ├── MeshSpec.js ├── README.md ├── ResourceSpec.js ├── TasksSpec.js ├── TranslatorFactorySpec.js ├── TraySpec.js ├── config │ ├── default.json │ └── initializer.js ├── data │ ├── comparables │ │ ├── FDMComparableDremel.g3drem │ │ ├── FDMComparableRep2.gcode │ │ ├── FDMComparableRep2Verbose.gcode │ │ ├── FDMComparableRep2VerboseRaft.gcode │ │ ├── FDMComparableRep2VerboseSupports.gcode │ │ ├── FDMComparableTypeA.gcode │ │ ├── FDMComparableTypeAVerbose.gcode │ │ ├── FDMComparableTypeAVerboseRaft.gcode │ │ ├── FDMComparableTypeAVerboseSupports.gcode │ │ ├── FDMComparableUltimaker.gcode │ │ ├── FDMComparableUltimakerVerbose.gcode │ │ ├── FDMComparableUltimakerVerboseRaft.gcode │ │ └── FDMComparableUltimakerVerboseSupports.gcode │ ├── models │ │ ├── Chimney.stl │ │ ├── HudTest.obj │ │ └── torus.obj │ ├── printables │ │ ├── DLPPrintable.pb │ │ ├── FDMPrintable.mic │ │ ├── FDMPrintableDremel.mic │ │ ├── FDMPrintableRep2.mic │ │ ├── FDMPrintableRep2Verbose.mic │ │ ├── FDMPrintableRep2VerboseRaft.mic │ │ ├── FDMPrintableRep2VerboseSupports.mic │ │ ├── FDMPrintableTypeA.mic │ │ ├── FDMPrintableTypeAVerbose.mic │ │ ├── FDMPrintableTypeAVerboseRaft.mic │ │ ├── FDMPrintableTypeAVerboseSupports.mic │ │ ├── FDMPrintableUltimaker.mic │ │ ├── FDMPrintableUltimakerVerbose.mic │ │ ├── FDMPrintableUltimakerVerboseRaft.mic │ │ └── FDMPrintableUltimakerVerboseSupports.mic │ └── translators │ │ └── DLPToJSONTranslator.js ├── helpers │ └── TestHelper.js └── printers │ ├── drivers │ └── CommandQueueSpec.js │ ├── firmwares │ ├── FDMTranslatorMakerbotSpec.js │ └── FDMTranslatorMarlinSpec.js │ └── translators │ ├── DremelTranslatorSpec.js │ ├── EmberTranslatorSpec.js │ ├── Replicator2Spec.js │ ├── TypeATranslatorSpec.js │ └── UltimakerTranslatorSpec.js ├── trays.js ├── utils ├── dateUtils.js ├── formats.js └── validator.js └── version.js /.gitignore: -------------------------------------------------------------------------------- 1 | logs 2 | node_modules/ 3 | .DS_Store 4 | .idea/ 5 | *.log 6 | -------------------------------------------------------------------------------- /Adding a printer to Spark PrintManager.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/Adding a printer to Spark PrintManager.pdf -------------------------------------------------------------------------------- /Autodesk_Spark Contrib Agreement.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/Autodesk_Spark Contrib Agreement.pdf -------------------------------------------------------------------------------- /Connection of Print Studio to Print Manager.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/Connection of Print Studio to Print Manager.pdf -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Spark3dp/print-manager 3 | 4 | Copyright 2015 Autodesk, Inc. 5 | 6 | Licensed under the Apache License, Version 2.0 (the “License”. 7 | You may not use this file except in compliance with the License, 8 | a copy of which can be obtained at: 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an “AS IS” BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 15 | including, without limitation, any warranties or conditions of TITLE, 16 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.. 17 | See the License for the specific language governing permissions and 18 | limitations under the License. 19 | 20 | 21 | === 22 | 23 | All files located in the node_modules and external directories are 24 | externally maintained libraries used by this software which have their 25 | own licenses; we recommend you read them, as their terms may differ from 26 | the terms above. -------------------------------------------------------------------------------- /Print Manager Documentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/Print Manager Documentation.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | print-manager 2 | =========== 3 | 4 | ## This project is no longer being maintained or updated. 5 | 6 | Print Manager is a desktop utility which identifies and connects 3D printers and converts files for delivery to a particular model of 3D printer. The utility is used by Print Studio. 7 | 8 | On supported 3D printers, Print Manager converts a set of native 3D printer commands into a format recognized by the supported printer models, allowing a "printable" file to be sent to a specific printer model. 9 | 10 | To download print studio, please see installer attached to [Print Manager Releases](https://github.com/spark3dp/print-manager/releases) 11 | 12 | If you are a printer manufacturer interested in integrating your printer with Print Manager then read the PDF "Adding a printer to Spark PrintManager" 13 | 14 | For Print Manager to start you must download the RoopaServer that is attached to the releases see [Print Manager Releases](https://github.com/spark3dp/print-manager/releases) 15 | 16 | When unzipped please edit the localConfig.json file to use this. 17 | 18 | 19 | ## Quick Start 20 | 1. Install node version 0.11.16 (not the latest) found here: 21 | https://nodejs.org/download/release/v0.11.16/ 22 | NOTE: C++ platform tools are required to build some of the modules. 23 | 2. CD spark-print-mgr 24 | 3. Add localConfig.json to the spark-print-mgr directory with the following content (it contains the location to the prep server) 25 | 26 | { 27 | "roopaServerPath" : "/Users/bob/Documents/RoopaServer.app/Contents/MacOS/RoopaServer" 28 | } 29 | 30 | The above will work for Mac OS*. 31 | 32 | 4. npm install 33 | 5. node Server.js (will start server on localhost:9998) 34 | 6. Go to: http://localhost:9998/printdb/printertypes to see normal execution 35 | 36 | You can fork this project. If you want to submit contributions, please complete the contributers agreement. 37 | 38 | If you see any issues please use the github issue mechanism. 39 | 40 | If you are building on Windows, install Bonjour SDK from the Apple Store and make sure the variable BONJOUR_SDK_HOME is set to the location. 41 | 42 | *Here is an example of localConfig.json for Windows. 43 | 44 | { 45 | "roopaServerPath" : "C:\\\Users\\\joe\\\Release\\\runTime\\\bin\\\RoopaServer.exe", 46 | } 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /spark-print-data/.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | -------------------------------------------------------------------------------- /spark-print-data/README.md: -------------------------------------------------------------------------------- 1 | Spark Print Data 2 | ================ 3 | 4 | These files represent the contents of the print definition database. 5 | Until such a time that the schema is finalized and the web service is 6 | reliably hosting the databe, the data will be kept here. 7 | 8 | If you modify the data in a compatible way, increment the parameter 9 | "print_definition_revision" in version.json. If you modify the 10 | database schema (ie. you add or remove fields) in an incompatible way 11 | with the rest of the system, increment the parameter 12 | "print_definition_schema", and reset "print_definition_revision" to 1. 13 | -------------------------------------------------------------------------------- /spark-print-data/data/DreamMaker_OverLord.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/DreamMaker_OverLord.zip -------------------------------------------------------------------------------- /spark-print-data/data/DreamMaker_OverLord_100x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/DreamMaker_OverLord_100x100.png -------------------------------------------------------------------------------- /spark-print-data/data/DreamMaker_OverLord_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/DreamMaker_OverLord_16x16.png -------------------------------------------------------------------------------- /spark-print-data/data/DreamMaker_OverLord_200x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/DreamMaker_OverLord_200x60.png -------------------------------------------------------------------------------- /spark-print-data/data/DreamMaker_OverLord_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/DreamMaker_OverLord_32x32.png -------------------------------------------------------------------------------- /spark-print-data/data/DreamMaker_OverLord_400x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/DreamMaker_OverLord_400x120.png -------------------------------------------------------------------------------- /spark-print-data/data/DreamMaker_OverLord_50x50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/DreamMaker_OverLord_50x50.png -------------------------------------------------------------------------------- /spark-print-data/data/DremelPackager.lua: -------------------------------------------------------------------------------- 1 | -- This version just copies the input file to the output file 2 | local packager = function( params ) 3 | -- print("DREMEL in: " .. params.inputFiles[1]); 4 | -- print("DREMEL out: " .. params.outputFile); 5 | local out = io.open( params.outputFile, "wb" ) 6 | if out == nil then 7 | return false 8 | end 9 | 10 | -- copy the gcode 11 | local gcode = io.open( params.inputFiles[1], "r" ) 12 | local count = 0 13 | while true do 14 | local data = gcode:read( 4096 ) 15 | if data == nil then 16 | break 17 | end 18 | count = count + #data 19 | out:write( data ) 20 | end 21 | gcode:close() 22 | 23 | out:close() 24 | -- print("DREMEL: write " .. tostring(count)) 25 | end 26 | 27 | --[[ This version may be used in the future 28 | -- 29 | function fsize (file) 30 | local current = file:seek() -- get current position 31 | local size = file:seek("end") -- get file size 32 | file:seek("set", current) -- restore position 33 | return size 34 | end 35 | 36 | local packager = function( params ) 37 | local out = io.open( params.outputFile, "wb" ) 38 | if out == nil then 39 | return false 40 | end 41 | 42 | -- load the icon data 43 | local icon = io.open( params.printerType.printable.packager_data.icon_file_id, "rb" ) 44 | local iconData = icon:read( "*a" ) 45 | 46 | -- magic string 47 | out:write( "g3drem 1.0 " ) 48 | 49 | -- image start offset? 50 | out:write( ak.writeUInt32(58) ) 51 | 52 | -- unused 53 | out:write( ak.writeUInt32(0) ) 54 | 55 | -- gcode start offset? 56 | out:write( ak.writeUInt32(58 + fsize(icon) ) ) 57 | 58 | -- estimated build time (seconds) 59 | out:write( ak.writeUInt32(6403) ) 60 | 61 | -- right/left extruder material used (mm) 62 | out:write( ak.writeUInt32(9401) ) 63 | out:write( ak.writeUInt32(0) ) 64 | 65 | -- flags? 66 | out:write( ak.writeUInt16(1) ) 67 | 68 | -- layer height (micrometers) 69 | out:write( ak.writeUInt16(200) ) 70 | 71 | -- infill thickness percentage 72 | out:write( ak.writeUInt16(25) ) 73 | 74 | -- shell count 75 | out:write( ak.writeUInt16(3) ) 76 | 77 | -- build speed? 78 | out:write( ak.writeUInt16(100) ) 79 | 80 | -- platform temperature? 81 | out:write( ak.writeUInt16(0) ) 82 | 83 | -- right/left extruder temperature 84 | out:write( ak.writeUInt16(220) ) 85 | out:write( ak.writeUInt16(0) ) 86 | 87 | -- right/left material types 88 | out:write( ak.writeUInt8(1) ) 89 | out:write( ak.writeUInt8(255) ) 90 | 91 | -- copy the icon 92 | out:write( iconData ) 93 | icon:close() 94 | 95 | -- copy the gcode 96 | local gcode = io.open( params.inputFiles[1], "r" ) 97 | while true do 98 | local data = gcode:read( 4096 ) 99 | if data == nil then 100 | break 101 | end 102 | out:write( data ) 103 | end 104 | gcode:close() 105 | 106 | out:close() 107 | 108 | return true 109 | end 110 | --]] 111 | 112 | return packager 113 | -------------------------------------------------------------------------------- /spark-print-data/data/DremelPrintableIcon.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/DremelPrintableIcon.bmp -------------------------------------------------------------------------------- /spark-print-data/data/OCFarm1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/OCFarm1.zip -------------------------------------------------------------------------------- /spark-print-data/data/OCFarm1_100x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/OCFarm1_100x100.png -------------------------------------------------------------------------------- /spark-print-data/data/OCFarm1_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/OCFarm1_16x16.png -------------------------------------------------------------------------------- /spark-print-data/data/OCFarm1_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/OCFarm1_32x32.png -------------------------------------------------------------------------------- /spark-print-data/data/OCFarm1_50x50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/OCFarm1_50x50.png -------------------------------------------------------------------------------- /spark-print-data/data/RepRapPrusaMendel.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/RepRapPrusaMendel.zip -------------------------------------------------------------------------------- /spark-print-data/data/TypeA.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/TypeA.zip -------------------------------------------------------------------------------- /spark-print-data/data/dremel.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/dremel.zip -------------------------------------------------------------------------------- /spark-print-data/data/dremel_100x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/dremel_100x100.png -------------------------------------------------------------------------------- /spark-print-data/data/dremel_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/dremel_16x16.png -------------------------------------------------------------------------------- /spark-print-data/data/dremel_200x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/dremel_200x60.png -------------------------------------------------------------------------------- /spark-print-data/data/dremel_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/dremel_32x32.png -------------------------------------------------------------------------------- /spark-print-data/data/dremel_400x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/dremel_400x120.png -------------------------------------------------------------------------------- /spark-print-data/data/dremel_50x50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/dremel_50x50.png -------------------------------------------------------------------------------- /spark-print-data/data/ember.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/ember.zip -------------------------------------------------------------------------------- /spark-print-data/data/ember_100x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/ember_100x100.png -------------------------------------------------------------------------------- /spark-print-data/data/ember_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/ember_16x16.png -------------------------------------------------------------------------------- /spark-print-data/data/ember_200x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/ember_200x60.png -------------------------------------------------------------------------------- /spark-print-data/data/ember_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/ember_32x32.png -------------------------------------------------------------------------------- /spark-print-data/data/ember_400x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/ember_400x120.png -------------------------------------------------------------------------------- /spark-print-data/data/ember_50x50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/ember_50x50.png -------------------------------------------------------------------------------- /spark-print-data/data/printrbotplay.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotplay.zip -------------------------------------------------------------------------------- /spark-print-data/data/printrbotplay_100x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotplay_100x100.png -------------------------------------------------------------------------------- /spark-print-data/data/printrbotplay_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotplay_16x16.png -------------------------------------------------------------------------------- /spark-print-data/data/printrbotplay_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotplay_32x32.png -------------------------------------------------------------------------------- /spark-print-data/data/printrbotplay_50x50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotplay_50x50.png -------------------------------------------------------------------------------- /spark-print-data/data/printrbotplus.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotplus.zip -------------------------------------------------------------------------------- /spark-print-data/data/printrbotplus_100x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotplus_100x100.png -------------------------------------------------------------------------------- /spark-print-data/data/printrbotplus_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotplus_16x16.png -------------------------------------------------------------------------------- /spark-print-data/data/printrbotplus_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotplus_32x32.png -------------------------------------------------------------------------------- /spark-print-data/data/printrbotplus_50x50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotplus_50x50.png -------------------------------------------------------------------------------- /spark-print-data/data/printrbotsimple.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotsimple.zip -------------------------------------------------------------------------------- /spark-print-data/data/printrbotsimple_100x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotsimple_100x100.png -------------------------------------------------------------------------------- /spark-print-data/data/printrbotsimple_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotsimple_16x16.png -------------------------------------------------------------------------------- /spark-print-data/data/printrbotsimple_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotsimple_32x32.png -------------------------------------------------------------------------------- /spark-print-data/data/printrbotsimple_50x50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/printrbotsimple_50x50.png -------------------------------------------------------------------------------- /spark-print-data/data/replicator2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/replicator2.zip -------------------------------------------------------------------------------- /spark-print-data/data/replicator2_100x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/replicator2_100x100.png -------------------------------------------------------------------------------- /spark-print-data/data/replicator2_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/replicator2_16x16.png -------------------------------------------------------------------------------- /spark-print-data/data/replicator2_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/replicator2_32x32.png -------------------------------------------------------------------------------- /spark-print-data/data/replicator2_50x50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/replicator2_50x50.png -------------------------------------------------------------------------------- /spark-print-data/data/replicator2x.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/replicator2x.zip -------------------------------------------------------------------------------- /spark-print-data/data/typeA_100x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/typeA_100x100.png -------------------------------------------------------------------------------- /spark-print-data/data/typeA_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/typeA_16x16.png -------------------------------------------------------------------------------- /spark-print-data/data/typeA_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/typeA_32x32.png -------------------------------------------------------------------------------- /spark-print-data/data/typeA_50x50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/typeA_50x50.png -------------------------------------------------------------------------------- /spark-print-data/data/ultimaker2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/ultimaker2.zip -------------------------------------------------------------------------------- /spark-print-data/data/ultimaker2_100x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/ultimaker2_100x100.png -------------------------------------------------------------------------------- /spark-print-data/data/ultimaker2_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/ultimaker2_16x16.png -------------------------------------------------------------------------------- /spark-print-data/data/ultimaker2_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/ultimaker2_32x32.png -------------------------------------------------------------------------------- /spark-print-data/data/ultimaker2_50x50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/data/ultimaker2_50x50.png -------------------------------------------------------------------------------- /spark-print-data/materials_generator/Spark Matrix Ammended V10_Mike.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-data/materials_generator/Spark Matrix Ammended V10_Mike.xls -------------------------------------------------------------------------------- /spark-print-data/materials_generator/export_rgb.js: -------------------------------------------------------------------------------- 1 | var fs = require("fs") 2 | , split = require("split") //imports the split module 3 | , input_file = "Spark Matrix Ammended V9_Mike_mod_for_Roberto_text_in.txt" 4 | , output_file = "Spark Matrix Ammended V9_Mike_mod_for_Roberto_text_out.txt" 5 | , html_values = []; 6 | 7 | fs.readFile(input_file, "utf8", function(err,values) { 8 | if (err) { 9 | return console.log(err) 10 | } 11 | else { 12 | html_values = values.split("\r\n"); 13 | 14 | var rgb_values = html_values.map(function(num) { 15 | return "[" + hexToRgb(num).r + ", " + hexToRgb(num).g + ", " + hexToRgb(num).b + "]"; 16 | }); 17 | 18 | console.log("html_values are: \n" + html_values); 19 | //console.log("rgb_values are: \n" + rgb_values); 20 | 21 | rgb_values_parsed = "[" + rgb_values.r + "," + rgb_values.g + "," + rgb_values.b + "]"; 22 | 23 | fs.writeFile(output_file,rgb_values.join("\r\n"), function(err) { 24 | if(err) { 25 | console.log(err); 26 | } 27 | else { 28 | console.log("the file was saved!"); 29 | } 30 | }); 31 | } 32 | }); 33 | 34 | 35 | 36 | function componentToHex(c) { 37 | var hex = c.toString(16); 38 | return hex.length == 1 ? "0" + hex : hex; 39 | } 40 | 41 | 42 | function rgbToHex(r, g, b) { 43 | return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); 44 | } 45 | 46 | 47 | function hexToRgb(hex) { 48 | // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") 49 | var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; 50 | hex = hex.replace(shorthandRegex, function(m, r, g, b) { 51 | return r + r + g + g + b + b; 52 | }); 53 | 54 | var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); 55 | return result ? { 56 | r: parseInt(result[1], 16), 57 | g: parseInt(result[2], 16), 58 | b: parseInt(result[3], 16) 59 | } : null; 60 | } -------------------------------------------------------------------------------- /spark-print-data/version.json: -------------------------------------------------------------------------------- 1 | { 2 | "print_definition_schema" : 4, 3 | "print_definition_revision" : 9 4 | } 5 | -------------------------------------------------------------------------------- /spark-print-mgr/.gitignore: -------------------------------------------------------------------------------- 1 | localConfig.json 2 | files/ 3 | .DS_Store 4 | db/ 5 | print_manager.jx 6 | print_manager.jxp 7 | *.log 8 | -------------------------------------------------------------------------------- /spark-print-mgr/LocalFileUploader.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'), 2 | path = require('path'), 3 | files = require( './files'), 4 | logger = require('./logging/PrintManagerLogger'); 5 | 6 | 7 | var fileIds = {}; // filename -> id 8 | 9 | 10 | /** 11 | * Returns the value of a property of the root object. 12 | * 13 | * @param {Object} root 14 | * @param {string[]} propNames - Array of property names 15 | * @returns {*} 16 | */ 17 | function getProperty(root, propNames) { 18 | var prop = root; 19 | propNames.forEach(function (propName) { 20 | prop = prop[propName]; 21 | }); 22 | return prop; 23 | } 24 | 25 | /** 26 | * Uploads one local file referenced in the json. 27 | * See uploadFiles(). 28 | * 29 | * @param {string} dir - Directory containing the files 30 | * @param {Object} json 31 | * @param {string} concatPropName - dot-concatenated property name (e.g., "foo.bar.baz") 32 | */ 33 | function uploadFile(dir, json, concatPropName) { 34 | var propNames = concatPropName.split('.'), 35 | value = getProperty(json, propNames), 36 | id = fileIds[value]; 37 | 38 | if (id === undefined) { 39 | 40 | var src = path.join(__dirname, dir, value); 41 | if (fs.existsSync(src)) { 42 | 43 | // Haven't seen this file before. Symlink and remember it. 44 | // 45 | var f = new files.File(null, value); 46 | fs.symlinkSync(src, f.path); 47 | 48 | id = f.id; 49 | fileIds[value] = id; 50 | 51 | } else { 52 | logger.error('Upload file ' + concatPropName + '="' + src + '" not found'); 53 | } 54 | } 55 | 56 | // Replace filename with file id. 57 | // 58 | if (id !== undefined) { 59 | var lastPropName = propNames.pop(); 60 | value = getProperty(json, propNames); 61 | value[lastPropName] = id; 62 | } 63 | } 64 | 65 | /** 66 | * Uploads local files referenced in the json. 67 | * 68 | * If the json contains a "_files" property, then that property is an array of strings 69 | * each of which is a dot-concatenated property name (e.g., "foo.bar.baz") which points 70 | * to a property in the json that contains a filename. 71 | * 72 | * This function "uploads" (actually symlinks) the files into an internal files directory 73 | * where actually-uploaded files are also saved and replaces the filename in the json 74 | * with the file id. 75 | * 76 | * @param {string} dir - Directory containing the files 77 | * @param {Object} json 78 | */ 79 | function uploadFiles(dir, json) { 80 | var concatPropNames = json._files; 81 | if (concatPropNames && 0 < concatPropNames.length) { 82 | concatPropNames.forEach(function (concatPropName) { 83 | uploadFile(dir, json, concatPropName); 84 | }); 85 | } 86 | } 87 | 88 | function reset() { 89 | fileIds = {}; 90 | } 91 | 92 | module.exports = { 93 | uploadFiles: uploadFiles, 94 | reset: reset 95 | }; 96 | -------------------------------------------------------------------------------- /spark-print-mgr/README.md: -------------------------------------------------------------------------------- 1 | Spark Print Manager 2 | =================== 3 | 4 | #How to Run 5 | Run: "npm install" to install node modules 6 | Create localConfig.json containing: { "roopaServerPath" : "" } 7 | Start server with "node server.js" 8 | 9 | -------------------------------------------------------------------------------- /spark-print-mgr/bin/macos/node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/bin/macos/node -------------------------------------------------------------------------------- /spark-print-mgr/bin/win/node.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/bin/win/node.exe -------------------------------------------------------------------------------- /spark-print-mgr/bin/win/nssm.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/bin/win/nssm.exe -------------------------------------------------------------------------------- /spark-print-mgr/bin/win/nssm64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/bin/win/nssm64.exe -------------------------------------------------------------------------------- /spark-print-mgr/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "PORT" : 9998, 3 | "logger_options" : { 4 | "log_file_name" : "print-manager.log", 5 | "log_file_location" : "", 6 | "write_to_console" : true 7 | }, 8 | "memory_cleanup_options" : { 9 | "delete_jobs_older_than" : 5, 10 | "delete_tasks_older_than" : 5 11 | }, 12 | "data_files_location" : "", 13 | "printer_data_files" : "../spark-print-data/", 14 | "localhost_only" : true, 15 | "EMBER" : "127.0.0.1", 16 | "commit_id" : "0000000000000000000000000000000000000000", 17 | "roopa_server_commit" : "07659fc7a275b09d4bfd278d77e831a5c6060bb9", 18 | "roopa_server_timeout" : 120, 19 | "device_discovery_services" : ["bonjour", "usb", "serial", "ember", "conveyor"] 20 | } 21 | -------------------------------------------------------------------------------- /spark-print-mgr/console/README.md: -------------------------------------------------------------------------------- 1 | Adding a printer to the console. 2 | =========== 3 | 4 | The console application is a simple web application that displays enabled printers and offers simple control and monitoring. 5 | 6 | For your printer to show up in the console there are a number of steps to take. 7 | 8 | Most importantly is https://github.com/spark3dp/print-manager/blob/sandbox/spark-print-mgr/console/js/controllers.js 9 | 10 | You add your print by adding it to the list. 11 | 12 | eg 13 | 14 | '8301C8D0-7A59-4F4B-A918-D5D38888790F' : { 15 | cssClass: 'printrbotplus', 16 | nickname: 'Printrbot Plus' 17 | } 18 | 19 | 20 | Where the UUID is the printertype and the cssClass is a reference to 21 | 22 | https://github.com/spark3dp/print-manager/blob/sandbox/spark-print-mgr/console/css/console.css 23 | 24 | '.printrbotplus { 25 | background-image: url("../icons/printrbotplus.png"); 26 | } 27 | 28 | You also need to add a png representing your printer as shown above. 29 | 30 | Your printer will then show up in the console. 31 | 32 | -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/Add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/Add.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/Back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/Back.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/Delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/Delete.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/DreamMaker_OverLord.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/DreamMaker_OverLord.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/Edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/Edit.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/Options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/Options.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/Refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/Refresh.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/dremel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/dremel.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/ember.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/ember.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/printrbotplay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/printrbotplay.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/printrbotplus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/printrbotplus.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/printrbotsimple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/printrbotsimple.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/replicator2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/replicator2.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/typeA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/typeA.png -------------------------------------------------------------------------------- /spark-print-mgr/console/icons/ultimaker2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/console/icons/ultimaker2.png -------------------------------------------------------------------------------- /spark-print-mgr/console/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 |
19 |
20 |
21 | 22 | -------------------------------------------------------------------------------- /spark-print-mgr/console/js/app.js: -------------------------------------------------------------------------------- 1 | var PrintManagerConsole = angular.module('PrintManagerConsole', [ 2 | 'ngRoute', 3 | 'PrintManagerControllers', 4 | 'PrintManagerServices' 5 | ]); 6 | 7 | PrintManagerConsole.config(['$httpProvider', function($httpProvider) { 8 | if (!$httpProvider.defaults.headers.get) { 9 | $httpProvider.defaults.headers.get = {}; 10 | } 11 | //disable IE ajax request caching 12 | $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT'; 13 | // extra 14 | $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; 15 | $httpProvider.defaults.headers.get['Pragma'] = 'no-cache'; 16 | }]); 17 | 18 | PrintManagerConsole.config(['$routeProvider', 19 | function($routeProvider) { 20 | $routeProvider 21 | .when('/printers', { 22 | templateUrl: 'partials/printerList.html', 23 | controller: 'PrinterListController' 24 | }) 25 | .when('/printers/edit', { 26 | templateUrl: 'partials/printersEdit.html', 27 | controller: 'PrintersEditController' 28 | }) 29 | .when('/printers/add', { 30 | templateUrl: 'partials/printerAdd.html', 31 | controller: 'PrinterAddController' 32 | }) 33 | .when('/printers/:printerId', { 34 | templateUrl: 'partials/printerDetails.html', 35 | controller: 'PrinterDetailsController' 36 | }) 37 | .when('/settings', { 38 | templateUrl: 'partials/settings.html', 39 | controller: 'ConsoleSettingsController' 40 | }) 41 | .when('/printers/status/:printerId', { 42 | templateUrl: 'partials/printJobDetails.html', 43 | controller: 'PrintJobDetailsController' 44 | }) 45 | .otherwise({ 46 | redirectTo: '/printers' 47 | }); 48 | }]); 49 | -------------------------------------------------------------------------------- /spark-print-mgr/console/js/services.js: -------------------------------------------------------------------------------- 1 | var PrintManagerServices = angular.module('PrintManagerServices', ['ngResource']); 2 | 3 | PrintManagerServices.factory('Printers', ['$resource', 4 | function($resource){ 5 | return $resource('/print/printers/:printerId', null, { 6 | update: { 7 | method: 'PUT', 8 | url: '/print/printers/:printerId/local', 9 | params: { 10 | printerId: '@printerId' // Apparently this line is needed for all methods except GET 11 | } 12 | }, 13 | list: { 14 | method: 'GET', 15 | params: { 16 | printerId: '' 17 | } 18 | }, 19 | add: { 20 | method: 'POST', 21 | url: '/print/printers/local' 22 | }, 23 | status: { 24 | method: 'GET', 25 | url: '/print/printers/status/:printerId' 26 | }, 27 | command: { 28 | method: 'POST', 29 | url: '/print/printers/:printerId/command', 30 | params: { 31 | printerId: '@printerId' 32 | } 33 | } 34 | }); 35 | }]); 36 | 37 | PrintManagerServices.factory('PrinterTypes', ['$resource', 38 | function($resource){ 39 | return $resource('/printdb/printertypes/:printerTypeId', {}, { 40 | list: { 41 | method: 'GET', 42 | params: { 43 | printerTypeId: '' 44 | } 45 | } 46 | }); 47 | }]); 48 | 49 | PrintManagerServices.factory('Settings', ['$resource', 50 | function($resource){ 51 | return $resource('/config'); 52 | }]); -------------------------------------------------------------------------------- /spark-print-mgr/console/partials/printJobDetails.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 | 7 |
8 |

{{(printer.name)}}

9 |
{{(printer.type_id)?(getDefaultsForType(printer.type_id)['nickname']) : ''}}
10 |
11 |
12 | 13 |
14 |
15 |
16 |
Printer Status:
17 |
18 |
19 |
{{printer.status.state.charAt(0).toUpperCase() + printer.status.state.slice(1)}}
20 |
21 |
22 |
23 |
24 |
25 |
30 | 31 |
{{(percent)? (percent | number: 0) : 0}}%
32 |
33 |
34 |
35 |
36 | 55 |
56 |
57 | {{jobCompletionMessage}} 58 |
59 |
60 |
61 | 63 |
64 | 65 | -------------------------------------------------------------------------------- /spark-print-mgr/console/partials/printerAdd.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
5 | 8 |
Add Printer
9 |
10 | 11 |
12 | 13 |
14 |
15 |
16 | 17 |
18 | 22 |
23 |
24 |
25 | 26 |
27 | 28 |

30 | A name is required 31 |

32 |
33 |
34 |
35 | 36 |
37 | 39 |

41 | An IP Address is required 42 |

43 |
44 |

Find your printer's IP address in the Settings tab of your printer's LCD screen.

45 |
46 |
47 |
48 | 49 | 60 | 61 |
62 | 63 |
64 | 65 |
66 | -------------------------------------------------------------------------------- /spark-print-mgr/console/partials/printerDetails.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 6 |
Edit Printer
7 |
8 | 9 |
10 | 11 |
12 |
13 | 14 |
15 | 16 |
17 | 18 |
19 |
20 |
21 | 22 |
23 | 24 |

26 | A name is required 27 |

28 |
29 |
30 | 31 | 32 |
35 | 36 |
37 | 38 |
39 |
40 | 41 |
42 |
43 |

Connected via USB.

44 |
45 |
46 | 47 |
48 | 49 | 60 |
61 |
62 |
-------------------------------------------------------------------------------- /spark-print-mgr/console/partials/printerList.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 6 |
Status
7 |
8 | 11 |
12 | 13 |
14 | 15 | 16 | 28 | 29 |
17 |
18 |
19 |
{{printer.name}}
20 |
21 | 27 |
30 |
31 | 32 | 35 |
36 | -------------------------------------------------------------------------------- /spark-print-mgr/console/partials/printersEdit.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 6 |
Manage Printers
7 | 10 |
11 | 12 |
13 | 14 | 15 | 24 | 25 |
16 |
17 |
{{printer.name}}
18 |
19 | 20 | 21 | 22 |
23 |
26 |
27 | 28 | 31 |
-------------------------------------------------------------------------------- /spark-print-mgr/console/vendor/js/angular-resource.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | AngularJS v1.3.13 3 | (c) 2010-2014 Google, Inc. http://angularjs.org 4 | License: MIT 5 | */ 6 | (function(I,d,B){'use strict';function D(f,q){q=q||{};d.forEach(q,function(d,h){delete q[h]});for(var h in f)!f.hasOwnProperty(h)||"$"===h.charAt(0)&&"$"===h.charAt(1)||(q[h]=f[h]);return q}var w=d.$$minErr("$resource"),C=/^(\.[a-zA-Z_$][0-9a-zA-Z_$]*)+$/;d.module("ngResource",["ng"]).provider("$resource",function(){var f=this;this.defaults={stripTrailingSlashes:!0,actions:{get:{method:"GET"},save:{method:"POST"},query:{method:"GET",isArray:!0},remove:{method:"DELETE"},"delete":{method:"DELETE"}}}; 7 | this.$get=["$http","$q",function(q,h){function t(d,g){this.template=d;this.defaults=s({},f.defaults,g);this.urlParams={}}function v(x,g,l,m){function c(b,k){var c={};k=s({},g,k);r(k,function(a,k){u(a)&&(a=a());var d;if(a&&a.charAt&&"@"==a.charAt(0)){d=b;var e=a.substr(1);if(null==e||""===e||"hasOwnProperty"===e||!C.test("."+e))throw w("badmember",e);for(var e=e.split("."),n=0,g=e.length;n 0) { 68 | line += command.custom + "\n"; 69 | } 70 | if (this.initialBedTemp > 0) { 71 | line += "M190 S" + this.initialBedTemp + "\n"; 72 | } 73 | line += "M109 S" + this.initialTemp; 74 | 75 | return this.postProcessLine(command, line); 76 | }; 77 | 78 | /** 79 | * Create a G1 command and then check for feed rate changes 80 | * If Feed Rate has changed since last command, append 81 | * F to the G1 command 82 | * 83 | * @param {Object} command 84 | * @returns {string} line 85 | */ 86 | FDMTranslatorPrintrbot.prototype.convertMove = function(command) { 87 | if (this.firstMoveProcessed) { 88 | var line = this.processAxesArray(command); 89 | return line; 90 | } else { 91 | this.firstMoveProcessed = true; 92 | return ""; 93 | } 94 | }; 95 | 96 | module.exports = FDMTranslatorPrintrbot; 97 | -------------------------------------------------------------------------------- /spark-print-mgr/printableTranslation/Translator.js: -------------------------------------------------------------------------------- 1 | var events = require('events'), 2 | Promise = require('promise'), 3 | util = require('util'); 4 | 5 | /** 6 | * Translator is the base class for translators. 7 | * 8 | * @param {Object} printerType - an Object representing the printer type 9 | * @param {Object} printerProfile - an Object representing the printer profile 10 | * @param {Object} material - an Object representing the material 11 | * @param {String} jobName - name of the job 12 | * @constructor 13 | */ 14 | function Translator(printerType, printerProfile, material, jobName) { 15 | events.EventEmitter.call(this); 16 | this.printerType = printerType; 17 | this.printerProfile = printerProfile; 18 | this.material = material; 19 | this.jobName = jobName; 20 | this.progress = 0; 21 | } 22 | util.inherits(Translator, events.EventEmitter); 23 | 24 | Translator.prototype.getPrinterType = function() { 25 | return this.printerType; 26 | }; 27 | 28 | Translator.prototype.getPrinterProfile = function() { 29 | return this.printerProfile; 30 | }; 31 | 32 | Translator.prototype.getMaterial = function() { 33 | return this.material; 34 | }; 35 | 36 | Translator.prototype.getJobName = function() { 37 | return this.jobName; 38 | }; 39 | 40 | /** 41 | * Override this to return true if this class handles the translation for the given 42 | * combination of printer type, printer profile, and material. 43 | * 44 | * @param {Object} printerType 45 | * @param {Object} printerMaterial 46 | * @param {Object} material 47 | * @returns {boolean} 48 | */ 49 | Translator.canTranslate = function (printerType, printerProfile, material) { 50 | return false; 51 | }; 52 | 53 | /** 54 | * Override this to start the translation of the given input file. It should return 55 | * a promise that is fulfilled when the translation is done, and rejected when there 56 | * is an error. 57 | * 58 | * @param {String} inputPath 59 | * @returns {Promise} 60 | */ 61 | Translator.prototype.startTranslation = function (inputPath, outputPath) { 62 | return null; 63 | }; 64 | 65 | /** 66 | * Translates the given file represented by inputPath, and output the translation 67 | * to outputPath. 68 | * 69 | * @param {string} inputPath - the path to the input file. 70 | * @param {string} outputPath - the path to which the translated file will be written. 71 | * @param {Object} [options] - an optional dictionary of options used by your translator. 72 | * This can include translation options, temporary directories, 73 | * output formats, etc. 74 | * @returns {Promise} - this is fulfilled if the translation completes successfully, 75 | * and rejected if the read fails. 76 | */ 77 | Translator.prototype.translate = function (inputPath, outputPath, options) { 78 | var self = this; 79 | return new Promise(function (resolve, reject) { 80 | try { 81 | return self.startTranslation(inputPath, outputPath) 82 | .then(function () { 83 | return self.endTranslation(outputPath); 84 | }).then(function (data) { 85 | resolve(data); 86 | }).catch(function (err) { 87 | reject(err); 88 | }); 89 | } 90 | catch (e) { 91 | reject(e); 92 | } 93 | }); 94 | }; 95 | 96 | /** 97 | * Override this to end the translation. Typically this is outputting the file to the given 98 | * output path. If this method is performing an asynchronous operation, return a promise and 99 | * resolve it when the operation is complete. 100 | * 101 | * @param {String} outputPath 102 | */ 103 | Translator.prototype.endTranslation = function (outputPath) { 104 | }; 105 | 106 | /** 107 | * Sets the progress for the translation. 108 | * 109 | * @param {number} progress - a number between 0 and 1, inclusive. 110 | */ 111 | Translator.prototype.setProgress = function (progress) { 112 | this.progress = progress; 113 | this.emit('progress', progress); 114 | }; 115 | 116 | /** 117 | * Returns the current progress of the translation. 118 | * 119 | * @returns {number} 120 | */ 121 | Translator.prototype.getProgress = function () { 122 | return this.progress; 123 | }; 124 | 125 | module.exports = Translator; -------------------------------------------------------------------------------- /spark-print-mgr/printableTranslation/TranslatorFactory.js: -------------------------------------------------------------------------------- 1 | var walk = require('fs-walk'), 2 | path = require('path'), 3 | fs = require('fs'), 4 | logger = require('../logging/PrintManagerLogger'), 5 | Translator = require('./Translator'); 6 | 7 | function TranslatorFactory() { 8 | this.translators = []; 9 | } 10 | 11 | TranslatorFactory.prototype.registerTranslator = function (translatorClass) { 12 | if (translatorClass.prototype instanceof Translator) { 13 | this.translators.push(translatorClass); 14 | return true; 15 | } 16 | return false; 17 | }; 18 | 19 | TranslatorFactory.prototype.getTranslator = function (printerType, printerProfile, material, jobName) { 20 | for (var i = 0; i < this.translators.length; ++i) { 21 | var translatorClass = this.translators[i]; 22 | try { 23 | if (translatorClass.canTranslate(printerType, printerProfile, material)) { 24 | return new translatorClass(printerType, printerProfile, material, jobName); 25 | } 26 | } catch (e) { 27 | } 28 | } 29 | return null; 30 | }; 31 | 32 | TranslatorFactory.prototype.registerTranslators = function (directory) { 33 | var self = this; 34 | 35 | if (!directory) { 36 | directory = path.join(__dirname, 'translators'); 37 | } 38 | 39 | if (!fs.existsSync(directory)) { 40 | return false; 41 | } 42 | 43 | var found = false; 44 | walk.filesSync(directory, function (basedir, filename, stat, next) { 45 | try { 46 | var translatorClass = require(path.join(basedir, filename)); 47 | found = self.registerTranslator(translatorClass) || found; 48 | } catch (e) { 49 | logger.error(e); 50 | } 51 | }, function (err) { 52 | if (err) logger.error(err); 53 | }); 54 | 55 | return found; 56 | }; 57 | 58 | TranslatorFactory.prototype.getTranslatorCount = function () { 59 | return this.translators.length; 60 | }; 61 | 62 | TranslatorFactory.prototype.clearTranslators = function () { 63 | this.translators = []; 64 | }; 65 | 66 | var theTranslatorFactory = new TranslatorFactory(); 67 | module.exports = theTranslatorFactory; -------------------------------------------------------------------------------- /spark-print-mgr/printableTranslation/translators/DreamMaker_OverLord.js: -------------------------------------------------------------------------------- 1 | var FDMTranslatorDelta = require('../FDMTranslatorDelta'), 2 | util = require('util'), 3 | 4 | DreamMaker_OverLordTranslator = function(printerType, printerProfile, material, config) { 5 | FDMTranslatorDelta.call(this, printerType, printerProfile, material, config); 6 | this.jobName = "Spark"; 7 | }; 8 | 9 | util.inherits(DreamMaker_OverLordTranslator, FDMTranslatorDelta); 10 | 11 | DreamMaker_OverLordTranslator.canTranslate = function (printerType, profile, material) { 12 | return printerType.id === "4A0F7523-071B-4F1E-A527-9DA49AECB807"; 13 | }; 14 | 15 | module.exports = DreamMaker_OverLordTranslator; 16 | -------------------------------------------------------------------------------- /spark-print-mgr/printableTranslation/translators/Ocean-Farm1.js: -------------------------------------------------------------------------------- 1 | var FDMTranslatorDelta = require('../FDMTranslatorDelta'), 2 | util = require('util'), 3 | 4 | OceanFarm1Translator = function(printerType, printerProfile, material, config) { 5 | FDMTranslatorDelta.call(this, printerType, printerProfile, material, config); 6 | this.jobName = "Spark"; 7 | }; 8 | 9 | util.inherits(OceanFarm1Translator, FDMTranslatorDelta); 10 | 11 | OceanFarm1Translator.canTranslate = function (printerType, profile, material) { 12 | return printerType.id === "FA1118E1-7A59-FF4B-B938-D4D37788792F"; 13 | }; 14 | 15 | module.exports = OceanFarm1Translator; 16 | -------------------------------------------------------------------------------- /spark-print-mgr/printableTranslation/translators/Printrbot-Play.js: -------------------------------------------------------------------------------- 1 | var FDMTranslatorPrintrbot = require('../FDMTranslatorPrintrbot'), 2 | util = require('util'), 3 | 4 | PrintrbotSimpleTranslator = function(printerType, printerProfile, material, config) { 5 | FDMTranslatorPrintrbot.call(this, printerType, printerProfile, material, config); 6 | this.jobName = "Spark"; 7 | }; 8 | 9 | util.inherits(PrintrbotSimpleTranslator, FDMTranslatorPrintrbot); 10 | 11 | PrintrbotSimpleTranslator.canTranslate = function (printerType, profile, material) { 12 | return printerType.id === "8D586473-C1A9-451B-A129-2425357C6428"; 13 | }; 14 | 15 | module.exports = PrintrbotSimpleTranslator; 16 | -------------------------------------------------------------------------------- /spark-print-mgr/printableTranslation/translators/Printrbot-Plus.js: -------------------------------------------------------------------------------- 1 | var FDMTranslatorPrintrbot = require('../FDMTranslatorPrintrbot'), 2 | util = require('util'), 3 | 4 | PrintrbotSimpleTranslator = function(printerType, printerProfile, material, config) { 5 | FDMTranslatorPrintrbot.call(this, printerType, printerProfile, material, config); 6 | this.jobName = "Spark"; 7 | }; 8 | 9 | util.inherits(PrintrbotSimpleTranslator, FDMTranslatorPrintrbot); 10 | 11 | PrintrbotSimpleTranslator.canTranslate = function (printerType, profile, material) { 12 | return printerType.id === "8301C8D0-7A59-4F4B-A918-D5D38888790F"; 13 | }; 14 | 15 | module.exports = PrintrbotSimpleTranslator; 16 | -------------------------------------------------------------------------------- /spark-print-mgr/printableTranslation/translators/Printrbot-Simple.js: -------------------------------------------------------------------------------- 1 | var FDMTranslatorPrintrbot = require('../FDMTranslatorPrintrbot'), 2 | util = require('util'), 3 | 4 | PrintrbotSimpleTranslator = function(printerType, printerProfile, material, config) { 5 | FDMTranslatorPrintrbot.call(this, printerType, printerProfile, material, config); 6 | this.jobName = "Spark"; 7 | }; 8 | 9 | util.inherits(PrintrbotSimpleTranslator, FDMTranslatorPrintrbot); 10 | 11 | PrintrbotSimpleTranslator.canTranslate = function (printerType, profile, material) { 12 | return printerType.id === "152A72A1-45C7-11E5-B970-0800200C9A66"; 13 | }; 14 | 15 | module.exports = PrintrbotSimpleTranslator; 16 | -------------------------------------------------------------------------------- /spark-print-mgr/printableTranslation/translators/Replicator2.js: -------------------------------------------------------------------------------- 1 | var FDMTranslatorMakerbot = require('../FDMTranslatorMakerbot'), 2 | util = require('util'), 3 | 4 | Replicator2Translator = function(printerType, printerProfile, material, config) { 5 | FDMTranslatorMakerbot.call(this, printerType, printerProfile, material, config); 6 | this.jobName = "Spark"; 7 | }; 8 | 9 | util.inherits(Replicator2Translator, FDMTranslatorMakerbot); 10 | 11 | Replicator2Translator.canTranslate = function (printerType, profile, material) { 12 | return printerType.id === "F2F4B9B6-1D54-4A16-883E-B0385F27380D"; 13 | }; 14 | 15 | module.exports = Replicator2Translator; 16 | -------------------------------------------------------------------------------- /spark-print-mgr/printableTranslation/translators/TypeA.js: -------------------------------------------------------------------------------- 1 | var FDMTranslatorMarlin = require('../FDMTranslatorMarlin'), 2 | util = require('util'), 3 | 4 | TypeATranslator = function(printerType, printerProfile, material, config) { 5 | FDMTranslatorMarlin.call(this, printerType, printerProfile, material, config); 6 | this.jobName = "Spark"; 7 | }; 8 | 9 | util.inherits(TypeATranslator, FDMTranslatorMarlin); 10 | 11 | TypeATranslator.canTranslate = function (printerType, profile, material) { 12 | return printerType.id === "F2F4B9B6-1D54-4A16-883E-B0385F27380C"; 13 | }; 14 | 15 | module.exports = TypeATranslator; 16 | -------------------------------------------------------------------------------- /spark-print-mgr/printableTranslation/translators/Ultimaker.js: -------------------------------------------------------------------------------- 1 | var FDMTranslatorMarlin = require('../FDMTranslatorMarlin'), 2 | util = require('util'), 3 | 4 | UltimakerTranslator = function(printerType, printerProfile, material, config) { 5 | FDMTranslatorMarlin.call(this, printerType, printerProfile, material, config); 6 | this.jobName = "Spark"; 7 | }; 8 | 9 | util.inherits(UltimakerTranslator, FDMTranslatorMarlin); 10 | 11 | UltimakerTranslator.canTranslate = function (printerType, profile, material) { 12 | return printerType.id === "8D39294C-FA7A-40F4-AB79-19F506C64097"; 13 | }; 14 | 15 | module.exports = UltimakerTranslator; 16 | -------------------------------------------------------------------------------- /spark-print-mgr/printers/command.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * command.js 3 | * 4 | * This is the enum of commands common to all printers. Printer specific 5 | * commands are strings just like these. 6 | ******************************************************************************/ 7 | 8 | Command = { 9 | CONNECT : 'connect', 10 | DISCONNECT : 'disconnect', 11 | START : 'start', // This is in Ember. Is it different from 'print'? 12 | PRINT : 'print', 13 | CANCEL : 'cancel', 14 | PAUSE : 'pause', 15 | RESUME : 'resume', 16 | STATUS : 'status', // We should have only 'status','getStatus' or 'state' 17 | GET_STATUS : 'getStatus', // not all three. Deprecate 'getStatus' if we can 18 | EXIT : 'exit', 19 | RESET : 'reset', 20 | COMMAND : 'command' 21 | }; 22 | 23 | module.exports = Command; 24 | -------------------------------------------------------------------------------- /spark-print-mgr/printers/conveyorDiscovery.js: -------------------------------------------------------------------------------- 1 | var util = require('util'), 2 | EventEmitter = require('events').EventEmitter 3 | _ = require('underscore'), 4 | net = require('net'), 5 | RPC = require('./rpc'), 6 | os = require('os'), 7 | DeviceData = require('./deviceData'), 8 | logger = require('../logging/PrintManagerLogger') 9 | 10 | var SocketWrapper = function (socket){ 11 | EventEmitter.call(this); 12 | this.socket = socket; 13 | var that = this; 14 | socket.on('data', function (data) { 15 | that.emit('message', data); 16 | }); 17 | socket.on('close', function (){ 18 | logger.debug('wrapper received close'); 19 | this.emit('exit'); 20 | }); 21 | }; 22 | 23 | util.inherits(SocketWrapper, EventEmitter); 24 | 25 | SocketWrapper.prototype.send = function(data) { 26 | this.socket.write(data); 27 | } 28 | 29 | var ConveyorDiscovery = function () { 30 | EventEmitter.call(this); 31 | 32 | this.devices = {}; 33 | }; 34 | 35 | util.inherits(ConveyorDiscovery, EventEmitter); 36 | 37 | 38 | //handler function to RPC 39 | ConveyorDiscovery.prototype.onNotification = function (notification, params) { 40 | if (params) { 41 | if(notification === 'port_attached'){ 42 | var deviceData = new DeviceData(params.machine_type, params.machine_name, 'conveyor'); 43 | deviceData.model = params.machine_type; 44 | this.devices[deviceData.identifier.iserial] = deviceData; 45 | 46 | this.emit('deviceUp', deviceData); 47 | 48 | 49 | } else if(notification === 'port_detached') { 50 | var identifier = params.machine_name && params.machine_name.iserial; 51 | if (identifier) { 52 | var deviceData = this.devices[identifier]; 53 | 54 | if (deviceData) { 55 | this.emit('deviceDown', deviceData); 56 | } 57 | } 58 | } 59 | } 60 | }; 61 | 62 | ConveyorDiscovery.prototype.init = function (){ 63 | var that = this; 64 | 65 | this.client = new SocketWrapper(this.socket); 66 | this.rpc = new RPC.Client(this.client, 'conveyor'); 67 | this.rpc.on('notify', _.bind(this.onNotification, this)); 68 | 69 | logger.debug('initiating handshake; invoking hello on conveyor... waiting'); 70 | 71 | this.rpc.invoke('hello', { username : 'ram'}) 72 | .then(function (reply) { 73 | logger.debug('in CoveyorDiscovery. reply from conveyor for method hello "', reply); 74 | if (reply ==='world') { 75 | logger.info('conveyor discovery service started'); 76 | that.ready = true; 77 | 78 | that.rpc.invoke('getports') 79 | .then(function (reply) { 80 | logger.debug('in ConveyorDiscovery. reply from conveyor for method getports "', reply); 81 | for (var i = 0; i < reply.length; ++i) { 82 | var printer = reply[i]; 83 | 84 | logger.debug('Found connected printer: ' + printer.display_name); 85 | var deviceData = new DeviceData(printer.machine_type, printer.machine_name, 'conveyor'); 86 | deviceData.model = printer.machine_type; 87 | that.devices[deviceData.identifier.iserial] = deviceData; 88 | 89 | that.emit('deviceUp', deviceData); 90 | } 91 | }); 92 | } 93 | }); 94 | }; 95 | 96 | ConveyorDiscovery.prototype.start = function () { 97 | logger.info('starting conveyor discovery'); 98 | var socket = new net.Socket(); 99 | socket.setEncoding('utf8'); 100 | socket.on('close', function () { 101 | logger.debug('could not connect to conveyor, connection closed'); 102 | }); 103 | socket.on('error', function (e) { 104 | logger.debug('could not connect to conveyor, error =', e); 105 | }); 106 | 107 | try { 108 | var platform = os.platform(); 109 | var address; 110 | if ( platform == "darwin" || platform == "linux") { 111 | address = '/var/tmp/conveyord.socket'; 112 | } else { 113 | address = 9999; 114 | } 115 | socket.connect(address, _.bind(this.init, this)); 116 | this.socket = socket; 117 | } catch (e) { 118 | logger.debug('could not connect to conveyor, error =', e); 119 | } 120 | 121 | }; 122 | 123 | module.exports = new ConveyorDiscovery(); -------------------------------------------------------------------------------- /spark-print-mgr/printers/deviceData.js: -------------------------------------------------------------------------------- 1 | var _ = require('underscore') 2 | 3 | function DeviceData(name, identifier, deviceType, data) { 4 | this.serviceName = name; 5 | this.identifier = identifier; 6 | this.type = deviceType; 7 | 8 | // Conventions 9 | // this.VID = 10 | // this.PID = 11 | 12 | //add all other data properties in self 13 | if(data){ 14 | _.extend(this, data); 15 | } 16 | } 17 | 18 | module.exports = DeviceData; -------------------------------------------------------------------------------- /spark-print-mgr/printers/deviceMonitor.js: -------------------------------------------------------------------------------- 1 | var util = require('util'), 2 | events = require('events'), 3 | _ = require('underscore'), 4 | config = require('../config').config, 5 | DiscoveryFactory = require('./discoveryFactory'), 6 | logger = require('../logging/PrintManagerLogger'); 7 | 8 | var DeviceMonitor = function(list) { 9 | this.discovery = {}; 10 | }; 11 | 12 | util.inherits(DeviceMonitor, events.EventEmitter); 13 | 14 | DeviceMonitor.prototype.addDiscovery = function(discovery) { 15 | logger.debug('adding discovery to DeviceMonitor: ', discovery); 16 | if(!this.discovery[discovery]){ 17 | var d = DiscoveryFactory.create(discovery); 18 | if(d){ 19 | d.on('deviceUp', _.bind(this.onDeviceUp, this)); 20 | d.on('deviceDown', _.bind(this.onDeviceDown, this)); 21 | this.discovery[discovery] = d; 22 | } 23 | } 24 | }; 25 | 26 | DeviceMonitor.prototype.onDeviceUp = function(deviceData) { 27 | logger.debug('devicemonitor got deviceUp event:', deviceData); 28 | this.emit('deviceUp', deviceData); 29 | }; 30 | 31 | DeviceMonitor.prototype.onDeviceDown = function(deviceData) { 32 | logger.debug('devicemonitor got deviceDown event:', deviceData); 33 | this.emit('deviceDown', deviceData); 34 | }; 35 | 36 | DeviceMonitor.prototype.init = function(list) { 37 | logger.info('initialized device monitor'); 38 | this.services = list || config.device_discovery_services; 39 | _.each(this.services, this.addDiscovery, this); 40 | }; 41 | 42 | DeviceMonitor.prototype.start = function() { 43 | var that = this; 44 | _.each(this.discovery, function(value, key, list) { value.start(that)}); 45 | }; 46 | 47 | module.exports = new DeviceMonitor(); 48 | 49 | // Need to stop monitoring when exiting or the process refuses to die. 50 | 51 | 52 | -------------------------------------------------------------------------------- /spark-print-mgr/printers/discoveryFactory.js: -------------------------------------------------------------------------------- 1 | var DiscoveryFactory = function(){ 2 | this.discovery = {}; 3 | }; 4 | 5 | DiscoveryFactory.prototype.create = function (discovery){ 6 | this.discovery[discovery] = this.discovery[discovery] || require('./' + discovery + 'Discovery.js'); 7 | return this.discovery[discovery]; 8 | } 9 | 10 | module.exports = new DiscoveryFactory(); -------------------------------------------------------------------------------- /spark-print-mgr/printers/driver.js: -------------------------------------------------------------------------------- 1 | var extend = require('util')._extend, 2 | logger = require('../logging/PrintManagerLogger'), 3 | vm = require('vm'), 4 | fs = require('fs'), 5 | jrs = require('jsonrpc-serializer'), 6 | _ = require('underscore'), 7 | RPC = require('./rpc'), 8 | when = require('node-promise').when; 9 | 10 | var MAX_ID = 0; 11 | 12 | var args = process.argv.slice(2); 13 | var path = args && args[0]; 14 | var data = args && args.slice(1); 15 | 16 | // Allow one second for cleanup before killing the child process 17 | process.on('SIGINT', function (){ 18 | setTimeout(function (){ 19 | process.exit(); 20 | }, 1000); 21 | logger.debug('SIGINT called in driver process'); 22 | }); 23 | 24 | var Wrapper = function (path, dataString){ 25 | logger.debug('in Wrapper, path=', path, ', dataString=', dataString); 26 | if(path) { 27 | try { 28 | var Driver = this.safe_require(path, []); 29 | this.driver = Driver(JSON.parse(dataString)); 30 | if(this.driver){ 31 | logger.debug('created driver: ', this.driver && this.driver.name); 32 | this._init_driver(this.driver); 33 | } else { 34 | throw new Exception("could not load the driver"); 35 | } 36 | } catch (e) { 37 | logger.error('rogue driver. instantiation prohibited. ', e.stack); 38 | } 39 | } else { 40 | this.rpc.notify( "information", { message : 'failed to install driver' }); 41 | } 42 | }; 43 | 44 | Wrapper.prototype._init_driver = function(driver){ 45 | if(driver){ 46 | logger.debug('initializing rpc with the driver'); 47 | this.rpc = new RPC.Server(process, driver, 'child'); 48 | logger.debug('rpc=', this.rpc.name); 49 | 50 | //dont need to emit ready as the driver constructor is doing the same. 51 | // when(this.driver.status(), function (result){ 52 | // if(result.status){ 53 | // this.driver.emit('event', Status.State.READY); 54 | // } 55 | // }, function (){}); 56 | } 57 | }; 58 | 59 | Wrapper.prototype.safe_require = function(mod, modules) { 60 | var code = fs.readFileSync(require.resolve(mod)); 61 | var sandbox = { 62 | console : console, 63 | module : {}, 64 | require : function(mod) { 65 | logger.debug('driver script requires ', arguments[0]); 66 | return require.apply(this, arguments); 67 | } 68 | }; 69 | 70 | vm.runInNewContext(code, sandbox, __filename); 71 | return sandbox.module.exports; 72 | }; 73 | 74 | var wrapper = new Wrapper(path, data); 75 | -------------------------------------------------------------------------------- /spark-print-mgr/printers/driverResponse.js: -------------------------------------------------------------------------------- 1 | /** 2 | * driverresponse.js 3 | * 4 | * DriverResponse is a class to capture responses from the DriverApi interface methods 5 | * 6 | * All responses are successful or unsuccessful (don't leave 'success' undefined) 7 | * Any response may have warnings (array of strings) 8 | * Unsuccessful responses may have errors (array of strings) 9 | * All responses contain the state of the driver at the time of the response 10 | * 11 | * DriverResponses may be annoted with additional data, for example the DriverApi.status() 12 | * will return a DriverResponse with {'status' : Status } 13 | * Note that DriverResponse.state and DriverResponse.status.state will be redundant here 14 | * but that is OK, not all responses have status. 15 | */ 16 | var Status = require('./status'); 17 | 18 | var DriverResponse = function () { 19 | this.success = true; // true/false 20 | this.warnings = undefined; // array of warning strings 21 | this.errors = undefined; // array of error strings 22 | this.state = undefined; // printer state at the time of warning / error 23 | }; 24 | 25 | DriverResponse.Success = function(inState, inWarnings) { 26 | var response = new DriverResponse; 27 | 28 | response.success = true; 29 | response.warnings = inWarnings; 30 | response.state = inState; 31 | 32 | return response; 33 | }; 34 | 35 | DriverResponse.Failure = function(inState, inErrors, inWarnings) { 36 | var response = new DriverResponse; 37 | 38 | response.success = false; 39 | response.errors = inErrors; 40 | response.state = inState; 41 | response.warnings = inWarnings; 42 | 43 | return response; 44 | }; 45 | 46 | DriverResponse.Errors = { 47 | UNKNOWN_ERROR : 'An unknown error occured', 48 | UNKNOWN_COMMAND : 'The command is not recognized', 49 | COMMAND_FAILED : 'The command failed to execute', 50 | BAD_STATE : 'The printer cannot execute command from existing state', 51 | MODEL_NOT_LOADED : 'Cannot print if no model has been loaded', 52 | BAD_ASSET : 'An asset was corrupt or of the wrong type', 53 | CONNECTION_ERROR : 'There was a problem connecting' 54 | }; 55 | 56 | module.exports = DriverResponse; 57 | -------------------------------------------------------------------------------- /spark-print-mgr/printers/drivers/driverApi.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * driverApi.js 3 | * 4 | * Defines the API through which the print manager will call virtual print 5 | * drivers 6 | * 7 | * Drivers will generally not want to inherit directly from this (although they 8 | * may) but instead inherit from DriverBase, a subclass of our DriverApi that 9 | * adds in regular progress events during a print. 10 | * 11 | * Note that default DriverResponses from these API prototypes should not be 12 | * used and are for documentation value. The API has no idea what state an 13 | * abstract driver might find itself in. 14 | ******************************************************************************/ 15 | 16 | var util = require('util'), 17 | events = require('events'), 18 | Status = require('../status'), 19 | DriverResponse = require('../driverResponse'); 20 | 21 | /** 22 | * Constructor, inherits from EventEmitter 23 | */ 24 | var DriverApi = function () { 25 | events.EventEmitter.call(this); // superclass construtor 26 | }; 27 | 28 | // Inherit from EventEmitter to allow registration of event handlers for drivers 29 | util.inherits(DriverApi, events.EventEmitter); 30 | 31 | 32 | /** 33 | * getWorkingDir() 34 | * 35 | * Get the working directory where a virtual driver can place temporary 36 | * files during a print 37 | * 38 | * Args: N/A 39 | * Return: path to a directory 40 | */ 41 | DriverApi.prototype.getWorkingDir = function() { 42 | /**** NOT A GOOD SOLUTION ****/ 43 | /**** Needs discussion ****/ 44 | return '/tmp'; 45 | }; 46 | 47 | /** 48 | * loadmodel() 49 | * 50 | * Load a model asset so that it is prepared for printing 51 | * 52 | * Args: inAsset - asset descriptor: 53 | * { type : 'file', path : '/foo/bar' } 54 | * { type : 'url' , url : 'https://foo/bar' } 55 | * Return: DriverResponse 56 | */ 57 | DriverApi.prototype.loadmodel = function(inAsset) { 58 | return DriverResponse.Success(Status.State.DISCONNECTED); 59 | }; 60 | 61 | /** 62 | * print() 63 | * Start printing the previously uploaded model 64 | * 65 | * Args: N/A 66 | * Return: DriverResponse 67 | */ 68 | DriverApi.prototype.print = function() { 69 | return DriverResponse.Success(Status.State.DISCONNECTED); 70 | }; 71 | 72 | /** 73 | * cancel() 74 | * 75 | * Stop the currently printing job 76 | * 77 | * Args: N/A 78 | * Return: DriverResponse 79 | */ 80 | DriverApi.prototype.cancel = function() { 81 | return DriverResponse.Success(Status.State.DISCONNECTED); 82 | }; 83 | 84 | /** 85 | * pause() 86 | * 87 | * Pause the currently printing job 88 | * 89 | * Args: N/A 90 | * Return: DriverResponse 91 | */ 92 | DriverApi.prototype.pause = function() { 93 | return DriverResponse.Success(Status.State.DISCONNECTED); 94 | }; 95 | 96 | /** 97 | * resume() 98 | * 99 | * Resume printing a paused job 100 | * 101 | * Args: N/A 102 | * Return: DriverResponse 103 | */ 104 | DriverApi.prototype.resume = function() { 105 | return DriverResponse.Success(Status.State.DISCONNECTED); 106 | }; 107 | 108 | /** 109 | * getStatus() 110 | * 111 | * Return the current status of the printer 112 | * 113 | * Args: N/A 114 | * Return: DriverResponse with "status = " 115 | */ 116 | DriverApi.prototype.getStatus = function() { 117 | var response = DriverResponse.Success(Status.State.DISCONNECTED); 118 | 119 | response.status = new Status(response.state); 120 | 121 | return response; 122 | }; 123 | 124 | /** 125 | * cleanup() 126 | * 127 | * Cleanup any state before this driver is shut down. 128 | * 129 | * Args: N/A 130 | * Return: DriverResponse 131 | */ 132 | DriverApi.prototype.cleanup = function() { 133 | return DriverResponse.Success(Status.State.DISCONNECTED); 134 | }; 135 | 136 | /** 137 | * command() 138 | * 139 | * Send a device specific command to the printer 140 | * 141 | * Args: inParams: Flexible object with at least { command : } 142 | * Return: DriverResponse 143 | */ 144 | DriverApi.prototype.command = function(inParams) { 145 | return DriverResponse.Success(Status.State.DISCONNECTED); 146 | }; 147 | 148 | module.exports = DriverApi; 149 | -------------------------------------------------------------------------------- /spark-print-mgr/printers/drivers/driverConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "devices" : [ 3 | { 4 | "type" : "usb", 5 | "blackBox" : false, 6 | "description" : "Dremel Idea Builder", 7 | "VID" : 10889, 8 | "PID" : 34953, 9 | "driverPath" : "./drivers/dremel", 10 | "printerType" : "3F64F6EC-A1DF-44AB-A22E-58C036F2F474" 11 | }, 12 | { 13 | "type" : "serial", 14 | "blackBox" : false, 15 | "description" : "Ultimaker 2", 16 | "VID" : 9025, 17 | "PID" : 16, 18 | "driverPath" : "./drivers/ultimaker", 19 | "printerType" : "8D39294C-FA7A-40F4-AB79-19F506C64097" 20 | }, 21 | { 22 | "type" : "serial", 23 | "blackBox" : true, 24 | "blackBoxTypes" : [ 25 | { 26 | "description" : "Printrbot Play", 27 | "dimensions" : [110, 110, 141], 28 | "printerType" : "8D586473-C1A9-451B-A129-2425357C6428" 29 | }, 30 | { 31 | "description" : "Printrbot Simple", 32 | "dimensions" : [160, 160, 160], 33 | "printerType" : "152A72A1-45C7-11E5-B970-0800200C9A66" 34 | }, 35 | { 36 | "description" : "Printrbot Plus", 37 | "dimensions" : [260, 260, 275], 38 | "printerType" : "8301C8D0-7A59-4F4B-A918-D5D38888790F" 39 | } 40 | ], 41 | "description" : "Printrbot", 42 | "VID" : 5824, 43 | "PID" : -1, 44 | "driverPath" : "./drivers/printrbot", 45 | "printerType" : "152A72A1-45C7-11E5-B970-0800200C9A66" 46 | }, 47 | { 48 | "type" : "serial", 49 | "blackBox" : true, 50 | "blackBoxTypes" : [ 51 | { 52 | "description" : "Printrbot Play", 53 | "dimensions" : [110, 110, 141], 54 | "printerType" : "8D586473-C1A9-451B-A129-2425357C6428" 55 | }, 56 | { 57 | "description" : "Printrbot Simple", 58 | "dimensions" : [160, 160, 160], 59 | "printerType" : "152A72A1-45C7-11E5-B970-0800200C9A66" 60 | }, 61 | { 62 | "description" : "Printrbot Plus", 63 | "dimensions" : [260, 260, 275], 64 | "printerType" : "8301C8D0-7A59-4F4B-A918-D5D38888790F" 65 | } 66 | ], 67 | "description" : "Printrbot", 68 | "VID" : 10612, 69 | "PID" : -1, 70 | "driverPath" : "./drivers/printrbot", 71 | "printerType" : "152A72A1-45C7-11E5-B970-0800200C9A66" 72 | }, 73 | { 74 | "type" : "serial", 75 | "blackBox" : false, 76 | "description" : "DreamMaker Overlord", 77 | "VID" : 403, 78 | "PID" : 6001, 79 | "driverPath" : "./drivers/overlord", 80 | "printerType" : "4A0F7523-071B-4F1E-A527-9DA49AECB807" 81 | } 82 | ] 83 | } -------------------------------------------------------------------------------- /spark-print-mgr/printers/drivers/serialCommandExecutor.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * SerialCommandExecutor() 3 | * 4 | * Constructor for the SerialCommandExecutor. The command queue requests to 5 | * open and close the connection, and while open sends command strings to be 6 | * executed. 7 | * 8 | * This class uses SerialConnection() to establish and maintain our connection 9 | * open. 10 | * 11 | * Args: inComName - com port to which to connect 12 | * inBaud - baud rate at which to connect 13 | * inOpenPrimeStr - function a string of commands to send to prime the conn 14 | */ 15 | 16 | var SerialConnection = require('./serialConnection'), 17 | logger = require('../../logging/PrintManagerLogger'); 18 | 19 | var SerialCommandExecutor = function (inComName, inBaud, inOpenPrimeStr) { 20 | this.mComName = inComName; 21 | this.mBaud = inBaud; 22 | this.mOpenPrimeStr = inOpenPrimeStr; 23 | this.mConnection = undefined; 24 | this.mCommandsProcessed = undefined; 25 | }; 26 | 27 | /** 28 | * getCommandsProcessed() 29 | * 30 | * Accessor 31 | */ 32 | SerialCommandExecutor.prototype.getCommandsProcessed = function () { 33 | return this.mCommandsProcessed; 34 | }; 35 | 36 | /** 37 | * open() 38 | * 39 | * The executor's open uses a SerialConnection object to establish a 40 | * stable connection. 41 | * 42 | * Args: inDoneFunc - called when we complete our connection 43 | * Return: N/A 44 | */ 45 | SerialCommandExecutor.prototype.open = function (inDoneFunc) { 46 | var that = this; 47 | that.mConnection = new SerialConnection( 48 | that.mComName, 49 | that.mBaud, 50 | that.mOpenPrimeStr, 51 | function (inData) { 52 | logger.debug("Initial serial connection response\n", inData); 53 | }, 54 | function () { inDoneFunc(true); } 55 | ); 56 | // ****** WHAT TO DO IF OPEN FAILS???? ********// 57 | that.mCommandsProcessed = 0; 58 | }; 59 | 60 | /** 61 | * close() 62 | * 63 | * The executor simply closes any open port. 64 | * 65 | * Args: inDoneFunc - called when we close our connection 66 | * Return: N/A 67 | */ 68 | SerialCommandExecutor.prototype.close = function (inDoneFunc) { 69 | var that = this; 70 | that.mConnection.close(); 71 | inDoneFunc(true); 72 | that.mCommandsProcessed = undefined; 73 | }; 74 | 75 | 76 | /** 77 | * execute() 78 | * 79 | * Send the requested command to the device, passing any response 80 | * data back for processing. 81 | * 82 | * Args: inRawCode - command to send 83 | * inDataFunc - function to call with response data 84 | * inDoneFunc - function to call if the command will have no response 85 | */ 86 | SerialCommandExecutor.prototype.execute = function ( 87 | inRawCode, 88 | inDataFunc, 89 | inDoneFunc 90 | ) { 91 | var that = this; 92 | 93 | that.mConnection.setDataFunc(inDataFunc); 94 | that.mConnection.send(inRawCode); 95 | that.mCommandsProcessed++; 96 | }; 97 | 98 | module.exports = SerialCommandExecutor; -------------------------------------------------------------------------------- /spark-print-mgr/printers/emberDiscovery.js: -------------------------------------------------------------------------------- 1 | var util = require('util') 2 | , events = require('events') 3 | , _ = require('underscore') 4 | , logger = require('../logging/PrintManagerLogger') 5 | , deviceMonitor = require('./deviceMonitor') 6 | , DeviceData = require('./deviceData'); 7 | var devices = {}; 8 | var EVENT_DELAY = 4000; 9 | 10 | // Made an array in case we want to support future 11 | // Embers with a different vid pid pair 12 | var EMBER_VID_PIDS = [ 13 | { VID : 10883, PID : 2305 } 14 | ]; 15 | 16 | function EmberDiscovery () { 17 | events.EventEmitter.call(this); 18 | } 19 | 20 | util.inherits(EmberDiscovery, events.EventEmitter); 21 | 22 | EmberDiscovery.prototype.start = function() { 23 | var that = this; 24 | logger.info('started EmberDiscovery'); 25 | if (!deviceMonitor.discovery['usb']) { 26 | deviceMonitor.addDiscovery('usb'); 27 | usb.start(); 28 | } 29 | var usb = deviceMonitor.discovery['usb']; 30 | 31 | if (usb) { 32 | usb.on('deviceUp', function (inDeviceData) { 33 | logger.debug('Ember discovery got deviceUp: ', inDeviceData); 34 | if (isEmber(inDeviceData)) { 35 | logger.debug('looks like it is a USB attached ember printer'); 36 | 37 | var newDeviceData = new DeviceData("Ember", 38 | inDeviceData.identifier, 'ember', { address : "http://192.168.7.2"}); 39 | devices[newDeviceData.identifier] = newDeviceData; 40 | 41 | //looks like EVENT_DELAY is enough time for the Ember printer to get ready 42 | //anything less, and the status query fails. 43 | 44 | setTimeout(function () { 45 | that.emit('deviceUp', newDeviceData); 46 | }, EVENT_DELAY); 47 | 48 | } 49 | }); 50 | 51 | usb.on('deviceDown', function (inDeviceData) { 52 | logger.debug('Ember discovery got deviceDown: ', inDeviceData); 53 | if(isEmber(inDeviceData)) { 54 | logger.debug('looks like it is a USB attached ember printer'); 55 | if(devices[inDeviceData.identifier]) { 56 | //be symmetric to deviceUp for the delay 57 | setTimeout(function (){ 58 | that.emit('deviceDown', devices[inDeviceData.identifier]); 59 | }, EVENT_DELAY); 60 | } 61 | } 62 | }); 63 | } 64 | 65 | }; 66 | 67 | /** 68 | * Returns true if deviceData matches ember's vid pid 69 | * @param {json object} inDeviceData - object with VID and PID parameters 70 | * @return {boolean} 71 | */ 72 | function isEmber(inDeviceData) { 73 | var vidPid = _.find(EMBER_VID_PIDS, function(inVidPid) { 74 | return inVidPid.VID === inDeviceData.VID && inVidPid.PID === inDeviceData.PID; 75 | }); 76 | return vidPid !== undefined ? true : false; 77 | } 78 | 79 | function createDiscovery() { 80 | return new EmberDiscovery(); 81 | } 82 | 83 | module.exports = createDiscovery(); -------------------------------------------------------------------------------- /spark-print-mgr/printers/exportPrinter.js: -------------------------------------------------------------------------------- 1 | var usb = require('usb'); // import modules (some may be extra) 2 | var fs = require("fs"); 3 | -------------------------------------------------------------------------------- /spark-print-mgr/printers/jobStatus.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * jobStatus.js 3 | * 4 | * The JobStatus object encapsulates a job state and other job specific details 5 | ******************************************************************************/ 6 | 7 | JobStatus = function (inState) { 8 | this.state = inState || JobStatus.State.CREATED; 9 | this.progress = undefined; 10 | this.error = undefined; 11 | }; 12 | 13 | JobStatus.State = { 14 | CREATED : 'created', 15 | READY : 'ready', 16 | SENT : 'sent', 17 | RECEIVED : 'received', 18 | LOADING_MODEL : 'loadingmodel', 19 | MODEL_LOADED : 'modelloaded', 20 | PRINTING : 'printing', 21 | PAUSED : 'paused', 22 | CANCELED : 'canceled', 23 | COMPLETED : 'completed', 24 | ERROR : 'error' //todo: set to Failed to align with cloud APIs? 25 | }; 26 | 27 | module.exports = JobStatus; 28 | -------------------------------------------------------------------------------- /spark-print-mgr/printers/printer.js: -------------------------------------------------------------------------------- 1 | var util = require('util'), 2 | _ = require('underscore'), 3 | logger = require('../logging/PrintManagerLogger'), 4 | resource = require('../resource'), 5 | printerTypes = require('../printertypes'); 6 | 7 | 8 | function Printer(name, type_id, connection, id, data) { 9 | _.extend(this, data); 10 | resource.Resource.call(this); // This is what sets our id 11 | this.name = name; 12 | this.type_id = type_id; 13 | this.__connection = connection; 14 | this.id = id || this.id; 15 | this.default_material_id = ""; 16 | this.default_profile_id = ""; 17 | 18 | // Get default material and profile from the printer type 19 | var printerType = printerTypes.find(type_id); 20 | var defaultMaterialId; 21 | var defaultProfileId; 22 | 23 | if (printerType) { 24 | defaultMaterialId = printerType.getDefaultMaterialId(); 25 | defaultProfileId = printerType.getDefaultProfileId(); 26 | 27 | if (!defaultMaterialId) { 28 | logger.warn('Failed to get default_material_id from printer type: ' + type_id); 29 | } else { 30 | this.default_material_id = defaultMaterialId; 31 | } 32 | 33 | if (!defaultProfileId) { 34 | logger.warn('Failed to get default_profile_id from printer type: ' + type_id); 35 | } else { 36 | this.default_profile_id = defaultProfileId; 37 | } 38 | 39 | } else { 40 | logger.warn('Failed to get printer from type_id: ' + type_id); 41 | } 42 | } 43 | 44 | util.inherits(Printer, resource.Resource); 45 | 46 | module.exports = exports = Printer; -------------------------------------------------------------------------------- /spark-print-mgr/printers/printerUtil.js: -------------------------------------------------------------------------------- 1 | var _ = require('underscore'), 2 | driverConfig = require('./drivers/driverConfig'), 3 | logger = require('../logging/PrintManagerLogger'), 4 | printerTypes = require('../printertypes'); 5 | 6 | function getDriverInfo(deviceData) { 7 | // locate and return driver 8 | if (!deviceData) 9 | return; 10 | 11 | switch (deviceData.type) { 12 | case 'octoprint': 13 | return { driverPath : './drivers/octoprint'}; 14 | case 'ember': 15 | return { driverPath : './drivers/ember'}; 16 | case 'virtual': 17 | return { driverPath : './drivers/virtualPrinter' }; 18 | 19 | // USB and Serial get their device data from deviceConfig.json 20 | // If the device has an arbitrary PID, set it to -1 in driverConfig 21 | case 'usb': 22 | case 'serial': 23 | var driver = _.find( 24 | driverConfig.devices, 25 | function(device) { 26 | return ( 27 | deviceData.VID === device.VID && 28 | (deviceData.PID === device.PID || deviceData.PID === -1) 29 | ); 30 | }); 31 | if (driver && driver.driverPath) { 32 | return { driverPath : driver.driverPath }; 33 | } else { 34 | break; 35 | } 36 | case 'conveyor': 37 | return { driverPath : './drivers/conveyor'}; 38 | default: 39 | break; 40 | } 41 | } 42 | 43 | function getPrinterType(deviceData) { 44 | // magically figure out which printertype is to be picked up. 45 | // may be we can keep a map somewhere 46 | var typeId; 47 | switch (deviceData.type) { 48 | case 'octoprint': 49 | if (deviceData.serviceName.toLowerCase().indexOf('series') !== -1) { 50 | typeId = 'F2F4B9B6-1D54-4A16-883E-B0385F27380C'; 51 | } 52 | /* 53 | else if (deviceData.serviceName.toLowerCase().indexOf('printrbot') !== -1) { 54 | typeId = 'F2F4B9B6-1D54-4A16-883E-B0385F27380C'; //using reprap as printrbot is not defined 55 | } else { 56 | typeId = 'F2F4B9B6-1D54-4A16-883E-B0385F27380C'; 57 | } 58 | */ 59 | break; 60 | 61 | // USB and Serial look up the printerType value in the driverConfig.json 62 | case 'usb': 63 | case 'serial': 64 | var device = _.find(driverConfig.devices, function(device) { 65 | return ((deviceData.type === device.type) && 66 | (deviceData.VID === device.VID) && 67 | (deviceData.PID === device.PID)); 68 | }); 69 | if (device) { 70 | typeId = device.printerType; 71 | } 72 | break; 73 | case 'ember': 74 | typeId = '7FAF097F-DB2E-45DC-9395-A30210E789AA'; 75 | break; 76 | 77 | case 'conveyor': 78 | if (deviceData.serviceName.toLowerCase().indexOf('replicator 2x') !== -1) { 79 | typeId = '367012CF-2533-44C7-AD11-9FCD1ED9F2FC'; 80 | } else if (deviceData.serviceName.toLowerCase().indexOf('replicator 2') !== -1) { 81 | typeId = 'F2F4B9B6-1D54-4A16-883E-B0385F27380D'; 82 | } 83 | break; 84 | 85 | default: 86 | logger.warn('Unknown printer:', deviceData); 87 | } 88 | 89 | return (typeId && printerTypes.find(typeId)); 90 | } 91 | 92 | module.exports.getDriverInfo = getDriverInfo;module.exports.getPrinterType = getPrinterType; -------------------------------------------------------------------------------- /spark-print-mgr/printers/status.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * status.js 3 | * 4 | * The Status object encapsulates a state and printer specific details 5 | ******************************************************************************/ 6 | 7 | var Status = function (inState) { 8 | this.state = inState || Status.State.ERROR; 9 | this.errors = undefined; // array of error strings 10 | this.warnings = undefined; // array of warning strings 11 | 12 | this.job = {}; 13 | 14 | this.percentComplete = undefined; 15 | 16 | this.tools = {}; 17 | this.sensors = {}; 18 | this.materials = {}; 19 | }; 20 | 21 | Status.State = { 22 | ERROR : 'error', 23 | CONNECTING : 'connecting', 24 | CONNECTED : 'connected', 25 | DISCONNECTING : 'disconnecting', 26 | DISCONNECTED : 'disconnected', 27 | READY : 'ready', 28 | PRINTING : 'printing', 29 | PAUSED : 'paused', 30 | MAINTENANCE : 'maintenance', 31 | BUSY : 'busy', 32 | LOADING_MODEL : 'loadingmodel', 33 | MODEL_LOADED : 'modelloaded' 34 | }; 35 | 36 | module.exports = Status; 37 | -------------------------------------------------------------------------------- /spark-print-mgr/profiles.js: -------------------------------------------------------------------------------- 1 | var express = require('express'), 2 | path = require('path'), 3 | resources = require('./resource'), 4 | util = require('util'), 5 | _ = require('underscore'), 6 | logger = require('./logging/PrintManagerLogger'), 7 | config = require('./config').config, 8 | LocalFileUploader = require('./LocalFileUploader'); 9 | 10 | var router = null; 11 | var profiles = {}; 12 | 13 | function sendError( res, code, msg ) 14 | { 15 | // TODO: Switch to using spark-common/ErrorHandler 16 | logger.error( msg ); 17 | res.status( code ); 18 | res.send( msg ); 19 | } 20 | 21 | 22 | function Profile( data ) 23 | { 24 | // call the base class 25 | resources.Resource.call( this ); 26 | 27 | _.extend(this, data); 28 | 29 | // install in our collection 30 | profiles[this.getID()] = this; 31 | } 32 | 33 | util.inherits( Profile, resources.Resource ); 34 | 35 | 36 | function initialize() { 37 | var dir = config.printer_data_files, 38 | data = require(path.join(dir, 'profiles.json')); 39 | 40 | data.profiles.forEach(function (profile) { 41 | LocalFileUploader.uploadFiles(dir, profile); 42 | var result = addProfile(profile); 43 | if (!result.success) { 44 | logger.error(result.msg); 45 | } 46 | }); 47 | } 48 | 49 | 50 | function getAllProfiles( req, res ) 51 | { 52 | var data = []; 53 | 54 | for( var id in profiles ) 55 | { 56 | if( profiles.hasOwnProperty(id) ) { 57 | var profile = profiles[id]; 58 | data.push(profile.asJSON()); 59 | } 60 | } 61 | 62 | res.send( { "profiles" : data } ); 63 | } 64 | 65 | 66 | function addProfile(data) { 67 | var id = data.id, 68 | result = {}; 69 | 70 | if( !id ) 71 | { 72 | result.success = false; 73 | result.code = 400; 74 | result.msg = 'No ID specified for Profile'; 75 | } 76 | else if( findProfile(id) ) 77 | { 78 | result.success = false; 79 | result.code = 400; 80 | result.msg = 'Profile already exists: ' + id; 81 | } 82 | else 83 | { 84 | var profile = new Profile( data ); 85 | 86 | result.success = true; 87 | result.code = 204; 88 | } 89 | 90 | return result; 91 | } 92 | 93 | 94 | function postProfile( req, res ) 95 | { 96 | var result = addProfile(req.body); 97 | if (result.success) { 98 | res.status(result.code); 99 | res.send(); 100 | } else { 101 | sendError(res, result.code, result.msg); 102 | } 103 | } 104 | 105 | 106 | function getProfile( req, res ) 107 | { 108 | var id = req.params.id; 109 | var type = findProfile(req.params.id); 110 | 111 | if( type ) 112 | { 113 | res.send( type.asJSON() ); 114 | } 115 | else 116 | { 117 | res.status( 404 ); 118 | var msg = 'Profile not found: ' + id; 119 | logger.error( msg ); 120 | res.send( msg ); 121 | } 122 | } 123 | 124 | 125 | function findProfile( id ) 126 | { 127 | if (!(typeof(id) === 'string' || id instanceof String)) { 128 | return undefined; 129 | } 130 | 131 | return profiles.hasOwnProperty(id) ? profiles[id] : undefined; 132 | } 133 | 134 | 135 | function getRouter() 136 | { 137 | if( router ) 138 | return router; 139 | 140 | router = express.Router(); 141 | 142 | router.get( '/', getAllProfiles ); 143 | //router.post( '/', postProfile ); 144 | router.get('/:id', getProfile ); 145 | 146 | return router; 147 | } 148 | 149 | module.exports = exports = { 150 | 'initialize': initialize, 151 | 'Router' : getRouter, 152 | 'find' : findProfile 153 | }; 154 | -------------------------------------------------------------------------------- /spark-print-mgr/resource.js: -------------------------------------------------------------------------------- 1 | var uuid = require('node-uuid'), 2 | logger = require('./logging/PrintManagerLogger'); 3 | 4 | function Resource() 5 | { 6 | this.id = uuid.v4(); 7 | this.__refCount = 0; 8 | this.__timeStamp = new Date(); 9 | this.__children = {}; 10 | } 11 | 12 | 13 | Resource.prototype.getID = function() 14 | { 15 | return this.id; 16 | }; 17 | 18 | 19 | Resource.prototype.getRefCount = function() 20 | { 21 | return this.__refCount; 22 | }; 23 | 24 | 25 | Resource.prototype.getTimeStamp = function() 26 | { 27 | return this.__timeStamp; 28 | }; 29 | 30 | 31 | Resource.prototype.addChild = function( child ) 32 | { 33 | if (this.__children[child.getID()] === undefined ) 34 | { 35 | child.__refCount = child.__refCount + 1; 36 | this.__children[child.getID()] = child; 37 | logger.debug('adding child ' + child); 38 | } 39 | }; 40 | 41 | 42 | Resource.prototype.removeChild = function( child ) 43 | { 44 | if (this.__children[child.getID()] !== undefined ) 45 | { 46 | child.__refCount = child.__refCount - 1; 47 | delete this.__children[child.getID()]; 48 | } 49 | }; 50 | 51 | 52 | Resource.prototype.removeAllChildren = function() 53 | { 54 | for (var childId in this.__children) 55 | { 56 | var childToRemove = this.__children[childId]; 57 | this.removeChild(childToRemove); 58 | } 59 | } 60 | 61 | // Not the best solution but Javascript types are rather screwy: 62 | function simpleClone(obj) 63 | { 64 | // Assumes that obj will not contain another resource type. 65 | if( obj instanceof Array || ( obj instanceof Object && !(obj instanceof Function) ) ) 66 | return JSON.parse( JSON.stringify( obj ) ); 67 | 68 | return obj; 69 | } 70 | 71 | 72 | Resource.prototype.asJSON = function() 73 | { 74 | // This method returns the JSON form of the resource. Any keys 75 | // that aren't strings are skipped, and any string keys that don't 76 | // start with a double underscore are skipped. So, if you are 77 | // storing data in your resource that you don't want sent as the 78 | // JSON form of the resource, keep it in key names that start with 79 | // a double underscore. 80 | 81 | var data = {}; 82 | 83 | for( var key in this ) 84 | { 85 | if( typeof key != 'string' ) 86 | continue; 87 | 88 | if( key.substring(0,2) == '__' ) 89 | continue; 90 | 91 | var val = this[key]; 92 | 93 | if( !(val instanceof Function) ) 94 | data[key] = (val && val.asJSON) ? val.asJSON() : simpleClone(val); 95 | } 96 | 97 | return data; 98 | }; 99 | 100 | 101 | module.exports = exports = { 102 | 'Resource' : Resource 103 | }; 104 | -------------------------------------------------------------------------------- /spark-print-mgr/roopaScripts/analyzeMesh.lua: -------------------------------------------------------------------------------- 1 | local args = readStdin() 2 | print( encodeJSON( Meshes.analyze( args ) ) ) 3 | -------------------------------------------------------------------------------- /spark-print-mgr/roopaScripts/createTray.lua: -------------------------------------------------------------------------------- 1 | local args = readStdin() 2 | print( encodeJSON( Trays.create( args ) ) ) 3 | -------------------------------------------------------------------------------- /spark-print-mgr/roopaScripts/exportMesh.lua: -------------------------------------------------------------------------------- 1 | local args = readStdin() 2 | print( encodeJSON( Meshes.export( args ) ) ) 3 | -------------------------------------------------------------------------------- /spark-print-mgr/roopaScripts/exportSupports.lua: -------------------------------------------------------------------------------- 1 | local args = readStdin() 2 | print( encodeJSON( Trays.exportSupports( args ) ) ) 3 | -------------------------------------------------------------------------------- /spark-print-mgr/roopaScripts/generatePrintable.lua: -------------------------------------------------------------------------------- 1 | local args = readStdin() 2 | print( encodeJSON( Trays.generatePrintable( args ) ) ) 3 | -------------------------------------------------------------------------------- /spark-print-mgr/roopaScripts/generateVisual.lua: -------------------------------------------------------------------------------- 1 | local args = readStdin() 2 | print( encodeJSON( Meshes.exportBolt( args ) ) ) 3 | -------------------------------------------------------------------------------- /spark-print-mgr/roopaScripts/getVersion.lua: -------------------------------------------------------------------------------- 1 | print( encodeJSON( getVersion() ) ) 2 | -------------------------------------------------------------------------------- /spark-print-mgr/roopaScripts/hello.lua: -------------------------------------------------------------------------------- 1 | print( '{' ) 2 | print( ' "greeting" : [' ) 3 | for i = 1, 100 do 4 | print( ' "hello",' ); 5 | end 6 | print( ' "hello"' ) 7 | print( ' ]' ) 8 | print( '}' ) 9 | -------------------------------------------------------------------------------- /spark-print-mgr/roopaScripts/importMesh.lua: -------------------------------------------------------------------------------- 1 | newFile() 2 | local args = readStdin() 3 | print( encodeJSON( Meshes.import( args ) ) ) 4 | -------------------------------------------------------------------------------- /spark-print-mgr/roopaScripts/prepareTray.lua: -------------------------------------------------------------------------------- 1 | local args = readStdin() 2 | print( encodeJSON( Trays.prepare( args ) ) ) 3 | -------------------------------------------------------------------------------- /spark-print-mgr/roopaScripts/renameMesh.lua: -------------------------------------------------------------------------------- 1 | local args = readStdin() 2 | print( encodeJSON( Meshes.rename( args ) ) ) 3 | -------------------------------------------------------------------------------- /spark-print-mgr/roopaScripts/repairMesh.lua: -------------------------------------------------------------------------------- 1 | local args = readStdin() 2 | print( encodeJSON( Meshes.repair( args ) ) ) 3 | -------------------------------------------------------------------------------- /spark-print-mgr/roopaScripts/transformMesh.lua: -------------------------------------------------------------------------------- 1 | local args = readStdin() 2 | print( encodeJSON( Meshes.transform( args ) ) ) 3 | -------------------------------------------------------------------------------- /spark-print-mgr/server.js: -------------------------------------------------------------------------------- 1 | var app = require('./app'), 2 | config = require('./config').config; 3 | 4 | 5 | if (config.localhost_only) { 6 | // Allow only requests from the local host. 7 | app.listen(config.PORT, '127.0.0.1'); 8 | } 9 | else { 10 | // Open the server to all other computers. 11 | app.listen(config.PORT, '0.0.0.0'); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /spark-print-mgr/tasks.js: -------------------------------------------------------------------------------- 1 | var express = require('express'), 2 | resource = require('./resource'), 3 | logger = require('./logging/PrintManagerLogger'), 4 | Errors = require('./error/Errors'), 5 | validator = require('./utils/validator'), 6 | APIError = require('./error/APIError.js'), 7 | util = require('util'); 8 | 9 | var router = null; 10 | var tasks = {}; 11 | 12 | function Task() 13 | { 14 | // call the base class 15 | resource.Resource.call( this ); 16 | 17 | // initialize members 18 | this.status = 'running'; 19 | this.progress = 0; 20 | 21 | // install in our collection 22 | tasks[this.getID()] = this; 23 | } 24 | 25 | util.inherits( Task, resource.Resource ); 26 | 27 | Task.prototype.setResult = function( result ) 28 | { 29 | this.status = 'done'; 30 | this.progress = 1; 31 | this.result = result; 32 | }; 33 | 34 | Task.prototype.setError = function (error) 35 | { 36 | this.status = 'error'; 37 | this.progress = 1; 38 | if (error instanceof APIError) { 39 | this.error = { 40 | error_id: error.errorId, 41 | code: error.code, 42 | message: error.message 43 | } 44 | } else { 45 | this.error = { 'message': error } 46 | } 47 | }; 48 | 49 | Task.prototype.asJSON = function() 50 | { 51 | var js = {}; 52 | 53 | js.id = this.id; 54 | js.status = this.status; 55 | js.progress = this.progress; 56 | 57 | if( this.result ) 58 | js.result = this.result; 59 | 60 | if( this.error ) 61 | js.error = this.error; 62 | 63 | return js; 64 | }; 65 | 66 | function getTask( req, res, next ) 67 | { 68 | var id = req.params.id; 69 | 70 | if (!validator.isUUID(id)) { 71 | return next(new Errors.Request.NotFoundError('id should be a UUID', 122000)); 72 | } 73 | 74 | var task = findTask(id); 75 | 76 | if( task instanceof Task ) 77 | { 78 | res.send( task.asJSON() ); 79 | } 80 | else 81 | { 82 | return next(new Errors.Request.NotFoundError('Task ' + id + ' cannot be found', 122001)); 83 | } 84 | } 85 | 86 | 87 | function findTask( id ) 88 | { 89 | if (!(typeof(id) === 'string' || id instanceof String)) { 90 | return undefined; 91 | } 92 | 93 | return tasks.hasOwnProperty(id) ? tasks[id] : undefined; 94 | } 95 | 96 | 97 | function getRouter() 98 | { 99 | if( router ) 100 | return router; 101 | 102 | // configure the router 103 | router = express.Router(); 104 | router.get('/:id', getTask ); 105 | 106 | return router; 107 | } 108 | 109 | 110 | function prune( pruneOlderThan ) 111 | { 112 | if (pruneOlderThan === undefined ) { 113 | pruneOlderThan = 5; 114 | } 115 | 116 | var dateUtils = require('./utils/dateUtils'); 117 | 118 | logger.info('Pruning tasks older than: ' + pruneOlderThan + ' days'); 119 | 120 | var nowDate = new Date(); 121 | 122 | // Prune any task that has zero references. 123 | for (var taskId in tasks) 124 | { 125 | var task = tasks[taskId]; 126 | if (dateUtils.daysBetween(task.__timeStamp, nowDate) >= pruneOlderThan ) 127 | { 128 | // Unref the children 129 | task.removeAllChildren(); 130 | delete tasks[taskId]; 131 | 132 | logger.info( ' - deleted task:' + taskId ); 133 | } 134 | } 135 | } 136 | 137 | 138 | module.exports = exports = { 139 | 'Router' : getRouter, 140 | 'Task' : Task, 141 | 'find' : findTask, 142 | 'prune': prune 143 | }; 144 | -------------------------------------------------------------------------------- /spark-print-mgr/test/AppSettingsSpec.js: -------------------------------------------------------------------------------- 1 | var should = require('should'), 2 | fs = require('fs'); 3 | appSettings = require('../config').appSettings, 4 | files = require('../files.js'), 5 | config = require('../config').config, 6 | LocalFileUploader = require('../LocalFileUploader'), 7 | TestHelper = require('./helpers/TestHelper'); 8 | 9 | 10 | describe('appSettings', function () { 11 | 12 | it('should initialize and create PrintManager temp date direcotry.', function (done) { 13 | should.exist(appSettings.APP_DATA_FOLDER); 14 | fs.stat(appSettings.APP_DATA_FOLDER, function (er, s) { 15 | should.not.exist(er); 16 | s.isDirectory().should.be.true; 17 | }); 18 | done(); 19 | }); 20 | 21 | it('should initialize and create PrintManager/files temp date direcotry.', function (done) { 22 | should.exist(appSettings.APP_FILES_FOLDER); 23 | fs.stat(appSettings.APP_FILES_FOLDER, function (er, s) { 24 | should.not.exist(er); 25 | s.isDirectory().should.be.true; 26 | }); 27 | done(); 28 | }); 29 | 30 | it('should initialize and create PrintManager/db temp date direcotry.', function (done) { 31 | should.exist(appSettings.APP_DB_FOLDER); 32 | fs.stat(appSettings.APP_DB_FOLDER, function (er, s) { 33 | should.not.exist(er); 34 | s.isDirectory().should.be.true; 35 | }); 36 | done(); 37 | }); 38 | 39 | it('should set the log file name to a string with a valid file name', function (done) { 40 | var loggerOptions = config.logger_options; 41 | should.exist(loggerOptions); 42 | should.exist(loggerOptions['log_file_name']); 43 | done(); 44 | }); 45 | 46 | it('should set the log file location to PrintManager temp directory', function (done) { 47 | var loggerOptions = config.logger_options; 48 | should.exist(loggerOptions); 49 | should.exist(loggerOptions['log_file_location']); 50 | fs.stat(loggerOptions['log_file_location'], function (er, s) { 51 | should.not.exist(er); 52 | s.isDirectory().should.be.true; 53 | }); 54 | done(); 55 | }); 56 | 57 | it('should deleteAppDataFiles() from the PrintManager/files directory.', function (done) { 58 | 59 | // Upload some files - it will create temp files in PrintManager app date dir: appSettings.APP_FILES_FOLDER 60 | var json = { 61 | id_1: 'data/models/Chimney.stl', 62 | id_2: 'data/models/torus.obj', 63 | 64 | _files: ['id_1', 'id_2'] 65 | }; 66 | 67 | LocalFileUploader.uploadFiles('./test/', json); 68 | 69 | // Test files that do exists 70 | json._files.forEach(function (id) { 71 | var file = files.find(json[id]); 72 | should.exist(file); 73 | TestHelper.fileExists(file.path).should.be.true; 74 | }); 75 | 76 | appSettings.deleteAppDataFiles(); 77 | 78 | // All the temp files on disk should be gone. 79 | json._files.forEach(function (id) { 80 | var file = files.find(json[id]); 81 | should.exist(file); 82 | TestHelper.fileExists(file.path).should.be.false; 83 | }); 84 | done(); 85 | }); 86 | 87 | }); 88 | -------------------------------------------------------------------------------- /spark-print-mgr/test/DateUtilsSpec.js: -------------------------------------------------------------------------------- 1 | var should = require('should'), 2 | utils = require('../utils/dateUtils'); 3 | 4 | describe('DateUtils: daysBetween', function () { 5 | 6 | it('should return zero for the same date', function (done) { 7 | 8 | // Current date and time. 9 | var date1 = new Date(); 10 | var days = utils.daysBetween( date1, date1 ); 11 | days.should.equal(0); 12 | 13 | // Current date 2 hours later. 14 | var date2 = new Date(); 15 | date2.setHours(date2.getHours()+2); 16 | 17 | var days = utils.daysBetween( date1, date1 ); 18 | days.should.equal(0); 19 | 20 | done(); 21 | }); 22 | 23 | it('should return number of days for dates apart by days', function (done) { 24 | 25 | var one_day = 24; // one day in hours 26 | 27 | // Current date and time. 28 | var date1 = new Date(); 29 | 30 | // Set the date2 to one day and one hour later. 31 | var date2 = new Date(); 32 | date2.setHours( date2.getHours() + one_day + 1 ); 33 | var days = utils.daysBetween( date1, date2 ); 34 | days.should.equal(1); 35 | 36 | // Set the date3 to 5 days and one hour later. 37 | var date3 = new Date(); 38 | date3.setHours(date3.getHours() + 5*one_day + 1); 39 | days = utils.daysBetween( date1, date3 ); 40 | days.should.equal(5); 41 | 42 | done(); 43 | }); 44 | 45 | it('should return negative number of days for dates apart by days', function (done) { 46 | var one_day = 24; // one day in hours 47 | 48 | // Current date and time. 49 | var date1 = new Date(); 50 | 51 | // Set the date2 to one day and one hour later. 52 | var date2 = new Date(); 53 | date2.setHours( date2.getHours() + one_day + 1 ); 54 | var days = utils.daysBetween( date2, date1 ); 55 | days.should.equal(-1); 56 | 57 | // Set the date3 to 5 days and one hour later. 58 | var date3 = new Date(); 59 | date3.setHours(date3.getHours() + 5*one_day + 1); 60 | days = utils.daysBetween( date3, date1 ); 61 | days.should.equal(-5); 62 | 63 | done(); 64 | }); 65 | 66 | }); 67 | 68 | describe('DateUtils: dateToYYYYMMDDhhmmss ', function () { 69 | 70 | it('should return properly formated (yyyymmddhhmmss) string for a given date', function (done) { 71 | 72 | // Note: months are counted from zero. 73 | 74 | // Check Dec 31, 1999 23:59:59 75 | date = new Date( 1999, 11, 31, 23, 59, 59 ); 76 | dateToString = utils.dateToYYYYMMDDhhmmss(date); 77 | dateToString.should.equal("19991231235959"); 78 | 79 | // Check Jan 1, 2000 00:00:00 80 | date = new Date( 2000, 0, 1, 0, 0, 0 ); 81 | dateToString = utils.dateToYYYYMMDDhhmmss(date); 82 | dateToString.should.equal("20000101000000"); 83 | 84 | // Check Feb 29, 2016 6:53:12 85 | var date = new Date( 2016, 1, 29, 6, 53, 12 ); 86 | var dateToString = utils.dateToYYYYMMDDhhmmss(date); 87 | dateToString.should.equal("20160229065312"); 88 | 89 | done(); 90 | }); 91 | }); -------------------------------------------------------------------------------- /spark-print-mgr/test/FileSpec.js: -------------------------------------------------------------------------------- 1 | var should = require('should'), 2 | files = require('../files'), 3 | LocalFileUploader = require('../LocalFileUploader'), 4 | TestHelper = require('./helpers/TestHelper'); 5 | 6 | describe('Files', function () { 7 | 8 | it('should fail to find nonexistent files.', function (done) { 9 | // Test finding a file that does not exists. 10 | var file = files.find("TestIdDoesNotExist"); 11 | should.not.exist(file); 12 | 13 | done(); 14 | }); 15 | 16 | it('should find newly uploaded files together with the corresponding temp stored files on disk.', function (done) { 17 | 18 | var json = { 19 | id_1: 'data/models/Chimney.stl', 20 | id_2: 'data/models/torus.obj', 21 | 22 | _files: ['id_1', 'id_2'] 23 | }; 24 | 25 | LocalFileUploader.uploadFiles('./test/', json); 26 | 27 | // Test files that do exists 28 | json._files.forEach(function (id) { 29 | var file = files.find(json[id]); 30 | should.exist(file); 31 | TestHelper.fileExists(file.path).should.be.true; 32 | }); 33 | 34 | done(); 35 | }); 36 | 37 | it('should remove newly uploaded files and their corresponding temp files stored on disk.', function (done) { 38 | 39 | var json = { 40 | id_1: 'data/models/Chimney.stl', 41 | id_2: 'data/models/torus.obj', 42 | 43 | _files: ['id_1', 'id_2'] 44 | }; 45 | 46 | LocalFileUploader.uploadFiles('./test/', json); 47 | 48 | // Test files that do exists 49 | json._files.forEach(function (id) { 50 | var file = files.find(json[id]); 51 | should.exist(file); 52 | TestHelper.fileExists(file.path).should.be.true; 53 | 54 | file.remove(); 55 | 56 | // File should have been deleted from disk. 57 | TestHelper.fileExists(file.path).should.be.false; 58 | 59 | // Try getting it again (it should not exisit) 60 | file = files.find(json[id]); 61 | should.not.exist(file); 62 | }); 63 | 64 | done(); 65 | }); 66 | 67 | it('should prune all the files and their correspoding temp files stored on disk.', function (done) { 68 | 69 | var json = { 70 | id_1: 'data/models/Chimney.stl', 71 | id_2: 'data/models/torus.obj', 72 | 73 | _files: ['id_1', 'id_2'] 74 | }; 75 | 76 | LocalFileUploader.uploadFiles('./test/', json); 77 | 78 | // Test files that do exists 79 | paths = {}; 80 | json._files.forEach(function (id) { 81 | var file = files.find(json[id]); 82 | should.exist(file); 83 | TestHelper.fileExists(file.path).should.be.true; 84 | 85 | // Save the path. 86 | paths[json[id]] = file.path; 87 | }); 88 | 89 | files.prune(); 90 | 91 | json._files.forEach(function (id) { 92 | var file = files.find(json[id]); 93 | should.not.exist(file); 94 | TestHelper.fileExists( paths[json[id]]).should.be.false; 95 | }); 96 | 97 | done(); 98 | }); 99 | 100 | afterEach(function (done) { 101 | LocalFileUploader.reset(); 102 | files.prune(); 103 | done(); 104 | }); 105 | }); -------------------------------------------------------------------------------- /spark-print-mgr/test/JobsSpec.js: -------------------------------------------------------------------------------- 1 | var should = require('should'), 2 | trays = require('../trays'), 3 | jobs = require('../jobs'); 4 | 5 | 6 | describe('Jobs', function () { 7 | 8 | function createJobs() 9 | { 10 | // Create trays. 11 | var testTrays = {}; 12 | 13 | var tray = new trays.Tray( {} ); 14 | testTrays[tray.getID()] = tray; 15 | tray = new trays.Tray( {} ); 16 | testTrays[tray.getID()] = tray; 17 | tray = new trays.Tray( {} ); 18 | testTrays[tray.getID()] = tray; 19 | 20 | var testJobs = {}; 21 | for (var trayId in testTrays) 22 | { 23 | var job = new jobs.Job("", trayId, "", ""); 24 | job.addChild( testTrays[trayId]); 25 | 26 | testJobs[job.getID()] = job; 27 | } 28 | 29 | return { 'trays' : testTrays, 'jobs' : testJobs }; 30 | } 31 | 32 | it('should fail to find nonexistent job.', function (done) { 33 | // Test finding a job that does not exists. 34 | var job = jobs.find("OO131"); 35 | should.not.exist(job); 36 | 37 | done(); 38 | }); 39 | 40 | it('should find newly created jobs.', function (done) { 41 | 42 | var result = createJobs(); 43 | 44 | var testTrays = result['trays']; 45 | var testJobs = result['jobs']; 46 | 47 | for (var jobId in testJobs) 48 | { 49 | var job = jobs.find( jobId ); 50 | should.exist(job); 51 | job.getID().should.be.equal( jobId ); 52 | job.getRefCount().should.be.eql(0); 53 | 54 | var createdJob = testJobs[jobId]; 55 | job.should.equal( createdJob ); 56 | } 57 | 58 | done(); 59 | }); 60 | 61 | it('should prune all jobs', function (done) { 62 | 63 | var result = createJobs(); 64 | 65 | var testTrays = result['trays']; 66 | var testJobs = result['jobs']; 67 | 68 | for (var jobId in testJobs) 69 | { 70 | var job = jobs.find( jobId ); 71 | should.exist(job); 72 | } 73 | 74 | for (var trayId in testTrays) 75 | { 76 | var tray = trays.find( trayId ); 77 | tray.getRefCount().should.equal(1); 78 | } 79 | 80 | // Prune all the jobs that are older than 0 days. 81 | jobs.prune(0); 82 | 83 | for (var jobId in testJobs) 84 | { 85 | var job = jobs.find( jobId ); 86 | should.not.exist(job); 87 | } 88 | 89 | for (var trayId in testTrays) 90 | { 91 | var tray = trays.find( trayId ); 92 | tray.getRefCount().should.equal(0); 93 | } 94 | done(); 95 | }); 96 | 97 | afterEach(function (done) { 98 | jobs.prune(0); 99 | trays.prune(); 100 | done(); 101 | }); 102 | }); 103 | -------------------------------------------------------------------------------- /spark-print-mgr/test/LocalFileUploaderSpec.js: -------------------------------------------------------------------------------- 1 | var path = require('path'), 2 | should = require('should'), 3 | files = require('../files'), 4 | LocalFileUploader = require('../LocalFileUploader'), 5 | TestHelper = require('./helpers/TestHelper'); 6 | 7 | describe('LocalFileUploader', function () { 8 | it('should handle basic upload', function (done) { 9 | var json = { 10 | id_1: 'data/models/Chimney.stl', 11 | id_2: 'data/models/torus.obj', 12 | 13 | _files: ['id_1', 'id_2'] 14 | }, 15 | originalJSON = JSON.parse(JSON.stringify(json)); 16 | 17 | LocalFileUploader.uploadFiles('./test/', json); 18 | 19 | json._files.forEach(function (id) { 20 | json[id].should.not.equal(originalJSON[id]); 21 | var f = files.find(json[id]); 22 | should.exist(f); 23 | TestHelper.filesSameSize(path.join(__dirname, originalJSON[id]), f.path).should.be.true; 24 | f.remove(); 25 | }); 26 | 27 | done(); 28 | }); 29 | 30 | it('should handle nested property names', function (done) { 31 | var json = { 32 | p1: {p2: {p3: {id: 'data/models/Chimney.stl'}}}, 33 | _files: ['p1.p2.p3.id'] 34 | }, 35 | originalJSON = JSON.parse(JSON.stringify(json)); 36 | 37 | LocalFileUploader.uploadFiles('./test/', json); 38 | 39 | json.p1.p2.p3.id.should.not.equal(originalJSON.p1.p2.p3.id); 40 | var f = files.find(json.p1.p2.p3.id); 41 | should.exist(f); 42 | TestHelper.filesSameSize(path.join(__dirname, originalJSON.p1.p2.p3.id), f.path).should.be.true; 43 | f.remove(); 44 | 45 | done(); 46 | }); 47 | 48 | it('should handle duplicates', function (done) { 49 | var json = { 50 | p1: {p2: {id_1: 'data/models/Chimney.stl'}}, 51 | id_2: 'data/models/Chimney.stl', 52 | _files: ['p1.p2.id_1', 'id_2'] 53 | }, 54 | originalJSON = JSON.parse(JSON.stringify(json)); 55 | 56 | LocalFileUploader.uploadFiles('./test/', json); 57 | 58 | json.p1.p2.id_1.should.not.equal(originalJSON.p1.p2.id_1); 59 | json.id_2.should.not.equal(originalJSON.id_2); 60 | json.p1.p2.id_1.should.equal(json.id_2); 61 | 62 | var f = files.find(json.id_2); 63 | should.exist(f); 64 | TestHelper.filesSameSize(path.join(__dirname, originalJSON.id_2), f.path).should.be.true; 65 | f.remove(); 66 | 67 | done(); 68 | }); 69 | 70 | it('should do nothing when source file not found', function (done) { 71 | var json = { 72 | id: 'data/file_not_found.stl', 73 | _files: ['id'] 74 | }, 75 | originalJSON = JSON.parse(JSON.stringify(json)); 76 | 77 | LocalFileUploader.uploadFiles('./test/', json); 78 | 79 | json.id.should.equal(originalJSON.id); 80 | var f = files.find(json.id); 81 | should.not.exist(f); 82 | 83 | done(); 84 | }); 85 | 86 | it('should do nothing for properties not listed in _files', function (done) { 87 | var json = { 88 | id: 'data/models/torus.stl', 89 | _files: ['id'] 90 | }, 91 | originalJSON = JSON.parse(JSON.stringify(json)); 92 | 93 | LocalFileUploader.uploadFiles('./test/', json); 94 | 95 | json.id.should.equal(originalJSON.id); 96 | var f = files.find(json.id); 97 | should.not.exist(f); 98 | 99 | done(); 100 | }); 101 | 102 | afterEach(function (done) { 103 | LocalFileUploader.reset(); 104 | done(); 105 | }); 106 | }); 107 | -------------------------------------------------------------------------------- /spark-print-mgr/test/MeshSpec.js: -------------------------------------------------------------------------------- 1 | var should = require('should'), 2 | meshes = require('../meshes'), 3 | files = require('../files'), 4 | LocalFileUploader = require('../LocalFileUploader'); 5 | 6 | describe('Meshes', function () { 7 | 8 | function createMeshes() 9 | { 10 | var json = { 11 | id_1: 'data/models/Chimney.stl', 12 | id_2: 'data/models/torus.obj', 13 | 14 | _files: ['id_1', 'id_2'] 15 | }; 16 | 17 | LocalFileUploader.uploadFiles('./test/', json); 18 | 19 | // Create meshes. 20 | var testMeshes = {}; 21 | json._files.forEach(function (id) { 22 | var file = files.find(json[id]); 23 | 24 | // Create a mesh. 25 | var mesh = new meshes.Mesh( file, {} ); 26 | testMeshes[mesh.getID()] = mesh; 27 | }); 28 | 29 | return { 'json' : json, 'meshes' : testMeshes }; 30 | } 31 | 32 | it('should create meshes with reference count equal to zero.', function (done) { 33 | 34 | var result = createMeshes(); 35 | 36 | var json = result['json']; 37 | var testMeshes = result['meshes']; 38 | 39 | // Test files. 40 | json._files.forEach(function (id) { 41 | var file = files.find(json[id]); 42 | should.exist(file); 43 | file.getRefCount().should.be.eql(1); 44 | }); 45 | 46 | for (var meshId in testMeshes) 47 | { 48 | var mesh = testMeshes[meshId]; 49 | mesh.getID().should.be.equal( meshId ); 50 | mesh.getRefCount().should.be.eql(0); 51 | } 52 | 53 | done(); 54 | }); 55 | 56 | it('should fail to find nonexistent mesh.', function (done) { 57 | 58 | // Test finding a mesh that does not exists. 59 | var mesh = meshes.find("TestIdDoesNotExist"); 60 | should.not.exist(mesh); 61 | 62 | done(); 63 | }); 64 | 65 | it ('should find newly created meshes.', function (done) { 66 | 67 | var result = createMeshes(); 68 | 69 | var json = result['json']; 70 | var testMeshes = result['meshes']; 71 | 72 | for (var meshId in testMeshes) 73 | { 74 | if (testMeshes.hasOwnProperty(meshId)) { 75 | var mesh = meshes.find(meshId); 76 | should.exist(mesh); 77 | mesh.getID().should.be.equal(meshId); 78 | mesh.getRefCount().should.be.eql(0); 79 | } 80 | } 81 | 82 | done(); 83 | }); 84 | 85 | it ('should prune newly created meshes.', function (done) { 86 | 87 | var result = createMeshes(); 88 | 89 | var json = result['json']; 90 | var testMeshes = result['meshes']; 91 | 92 | for (var meshId in testMeshes) 93 | { 94 | var mesh = meshes.find(meshId); 95 | should.exist(mesh); 96 | } 97 | 98 | // Before prune, files should have ref count equal to 1. 99 | json._files.forEach(function (id) { 100 | var file = files.find(json[id]); 101 | file.getRefCount().should.be.eql(1); 102 | }); 103 | 104 | // Now, prune the meshes. 105 | meshes.prune(); 106 | 107 | for (var meshId in testMeshes) 108 | { 109 | var mesh = meshes.find(meshId); 110 | should.not.exist(mesh); 111 | } 112 | 113 | // After prune, files should have ref count equal to 0. 114 | json._files.forEach(function (id) { 115 | var file = files.find(json[id]); 116 | file.getRefCount().should.be.eql(0); 117 | }); 118 | 119 | done(); 120 | }); 121 | 122 | afterEach(function (done) { 123 | LocalFileUploader.reset(); 124 | 125 | meshes.prune(); 126 | files.prune(); 127 | 128 | done(); 129 | }); 130 | }); -------------------------------------------------------------------------------- /spark-print-mgr/test/README.md: -------------------------------------------------------------------------------- 1 | Unit Testing for Print Manager 2 | ============== 3 | 4 | ## How to Run 5 | cd to the spark-print-mgr directory, then type: 6 | ``` 7 | npm test 8 | ``` 9 | 10 | Or install mocha globally: 11 | ``` 12 | sudo npm install -g mocha 13 | ``` 14 | 15 | then type: 16 | ``` 17 | mocha 18 | ``` 19 | 20 | ## How to add a test 21 | 1. Create the appropriate helper methods in test/helper/TestServer.js if necessary. 22 | * See the class documentation in helpers/TestServer.js on how to add new helper methods. 23 | * Here you’ll be using the supertest APIs, which provide APIs for making different REST calls to an express app (ie. PrintManager) with the appropriate headers, query parameters, data, etc. This is based on the superagent library. 24 | * **supertest** API documentation found here: http://visionmedia.github.io/superagent/ 25 | 26 | 2. Create the test cases in the appropriate \*Spec.js file, if not already existent. There should be one JS file for the particular related group of endpoints you are testing. Please refer to existing Api\*Spec.js tests for examples. 27 | 28 | 3. The test cases will use the helper methods found in TestServer.js. You can use the helper methods together so that you can for example, upload a file, import the mesh, and then generate the visual. For these test cases you will use the mocha and should libraries. 29 | 30 | ###Mocha 31 | This describes the suite and the different test cases. The important methods are: 32 | * `describe`, to signal the start of the suite, and `it` to signal the start of a test case. 33 | * `done` - this signals the end of the test. Because the REST calls are asynchronous, you should call this somewhere in * the callback you pass into the helper methods of TestServer. 34 | * If you need to do some setup before and/or after each suite (ie. the code within `describe`), you can call `before` and/or `after` 35 | * If you need to do some setup before and/or after each test (ie. the code within `it`), you can call `beforeEach` and/or `afterEach`. For the existing tests, `afterEach` was used to do some cleanup of files that were created during the test. 36 | * If you want to run only a specific suite or test, you can append `only` - ie. `describe.only(…)`, `it.only(…)`. This is useful if you’re debugging a specific set of functionality. 37 | * If you want to skip particular suites or tests, you can append `skip`, -ie. `describe.skip(…)`, `it.skip(…)`. This is useful if you want to omit specific tests. 38 | * More API documentation found here: http://mochajs.org/ 39 | 40 | ###Should 41 | This is used for asserting correctness. These will read like plain English. Basic methods are: 42 | ``` 43 | .should.equal() 44 | .should.not.equal() 45 | should.not.exist() 46 | .should.have.property() 47 | ``` 48 | More API documentation found here: http://shouldjs.github.io/ 49 | -------------------------------------------------------------------------------- /spark-print-mgr/test/TasksSpec.js: -------------------------------------------------------------------------------- 1 | var should = require('should'), 2 | tasks = require('../tasks'); 3 | 4 | describe('Tasks', function () { 5 | 6 | function createTasks() 7 | { 8 | var testTasks = []; 9 | 10 | testTasks.push(new tasks.Task()); 11 | testTasks.push(new tasks.Task()); 12 | testTasks.push(new tasks.Task()); 13 | 14 | return testTasks; 15 | } 16 | 17 | it('should fail to find nonexistent task.', function (done) { 18 | // Test finding a task that does not exists. 19 | var task = tasks.find("OO131"); 20 | should.not.exist(task); 21 | 22 | done(); 23 | }); 24 | 25 | it('should find newly created tasks.', function (done) { 26 | 27 | var testTasks = createTasks(); 28 | 29 | testTasks.forEach(function(task) { 30 | var returnedTask = tasks.find( task.getID() ); 31 | should.exist(returnedTask); 32 | 33 | returnedTask.getRefCount().should.be.eql(0); 34 | returnedTask.should.equal( task ); 35 | }); 36 | 37 | done(); 38 | }); 39 | 40 | it('should prune tasks.', function (done) { 41 | 42 | var testTasks = createTasks(); 43 | 44 | testTasks.forEach(function(task) { 45 | var returnedTask = tasks.find( task.getID() ); 46 | should.exist(returnedTask); 47 | }); 48 | 49 | tasks.prune( 0 ); 50 | 51 | testTasks.forEach(function(task) { 52 | var returnedTask = tasks.find( task.getID() ); 53 | should.not.exist(returnedTask); 54 | }); 55 | 56 | done(); 57 | }); 58 | 59 | it('should be case sensitive.', function (done) { 60 | var testTasks = createTasks(); 61 | 62 | testTasks.forEach(function(task) { 63 | var lowerCaseTask = tasks.find( task.getID().toLowerCase() ); 64 | var upperCaseTask = tasks.find( task.getID().toUpperCase() ); 65 | 66 | lowerCaseTask.should.not.eql(upperCaseTask); 67 | }); 68 | 69 | done(); 70 | }); 71 | 72 | afterEach(function (done) { 73 | tasks.prune(0); 74 | done(); 75 | }); 76 | 77 | }); -------------------------------------------------------------------------------- /spark-print-mgr/test/TraySpec.js: -------------------------------------------------------------------------------- 1 | var should = require('should'), 2 | files = require('../files'), 3 | meshes = require('../meshes'), 4 | trays = require('../trays'), 5 | LocalFileUploader = require('../LocalFileUploader'); 6 | 7 | describe('Trays', function () { 8 | 9 | 10 | function createTrays() 11 | { 12 | var json = { 13 | id_1: 'data/models/Chimney.stl', 14 | id_2: 'data/models/torus.obj', 15 | id_3: 'data/models/HudTest.obj', 16 | 17 | _files: ['id_1', 'id_2', 'id_3'] 18 | }; 19 | 20 | LocalFileUploader.uploadFiles('./test/', json); 21 | 22 | // Create meshes. 23 | var testMeshes = {}; 24 | json._files.forEach(function (id) { 25 | var file = files.find(json[id]); 26 | 27 | // Create a mesh. 28 | var mesh = new meshes.Mesh( file, {} ); 29 | testMeshes[mesh.getID()] = mesh; 30 | }); 31 | 32 | // Create trays. 33 | var testTrays = {}; 34 | for (var meshId in testMeshes) 35 | { 36 | var mesh = testMeshes[meshId]; 37 | var meshListJSON = [ mesh.asJSON()]; 38 | var data = { 39 | 'meshes' : meshListJSON 40 | } 41 | var tray = new trays.Tray( data ); 42 | tray.addChild(mesh); 43 | 44 | testTrays[tray.getID()] = tray; 45 | } 46 | 47 | return { 'meshes' : testMeshes, 'trays' : testTrays }; 48 | } 49 | 50 | it('should fail to find nonexistent tray.', function (done) { 51 | // Test finding a tray that does not exists. 52 | var tray = trays.find("OO131"); 53 | should.not.exist(tray); 54 | 55 | done(); 56 | }); 57 | 58 | it('should find newly created trays.', function (done) { 59 | 60 | var result = createTrays(); 61 | 62 | var testTrays = result['trays']; 63 | var testMeshes = result['meshes']; 64 | 65 | for (var trayId in testTrays) 66 | { 67 | var tray = trays.find( trayId ); 68 | should.exist(tray); 69 | tray.getID().should.be.equal( trayId ); 70 | tray.getRefCount().should.be.eql(0); 71 | 72 | var createdTray = testTrays[trayId]; 73 | tray.should.equal( createdTray ); 74 | } 75 | 76 | done(); 77 | }); 78 | 79 | it('should prune trays and release corresponding meshes.', function (done) { 80 | 81 | var result = createTrays(); 82 | 83 | var testTrays = result['trays']; 84 | var testMeshes = result['meshes']; 85 | 86 | // Confirm that before prune, each mesh referenced by a tray has refcount == 1 87 | for (var meshId in testMeshes) 88 | { 89 | var mesh = testMeshes[meshId]; 90 | mesh.getRefCount().should.equal(1); 91 | } 92 | 93 | // Confirm that all trays exist. 94 | for (var trayId in testTrays) 95 | { 96 | var tray = trays.find( trayId ); 97 | should.exist(tray); 98 | } 99 | 100 | // Prune 101 | trays.prune(); 102 | 103 | // Confirm that all trays are deleted. 104 | for (var trayId in testTrays) 105 | { 106 | var tray = trays.find( trayId ); 107 | should.not.exist(tray); 108 | } 109 | 110 | // Confirm that all meshes got released. 111 | for (var meshId in testMeshes) 112 | { 113 | var mesh = testMeshes[meshId]; 114 | mesh.getRefCount().should.equal(0); 115 | } 116 | 117 | done(); 118 | }); 119 | 120 | afterEach(function (done) { 121 | LocalFileUploader.reset(); 122 | trays.prune(); 123 | meshes.prune(); 124 | files.prune(); 125 | done(); 126 | }); 127 | }); -------------------------------------------------------------------------------- /spark-print-mgr/test/config/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "api_tests": { 3 | "description": "Runs the API tests on PrintManager directly. No need to start a server.", 4 | "services": [ 5 | { 6 | "name": "default", 7 | "target": "app", 8 | "app_module_path": "./app.js", 9 | "api_prefix": "", 10 | "end_points": ["*"] 11 | } 12 | ], 13 | "initializer_module_path": "./test/config/initializer.js" 14 | } 15 | } -------------------------------------------------------------------------------- /spark-print-mgr/test/config/initializer.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'), 2 | config = require('../../config').config, 3 | files = require('../../files'), 4 | os = require('os'), 5 | Promise = require('promise'), 6 | Logger = require('../../logging/Logger'); 7 | 8 | var theLogger = new Logger({ 9 | log_file_name: "print-manager-tests.log", 10 | write_to_console: false 11 | }); 12 | 13 | var theFilesToRemove = []; 14 | 15 | /** 16 | * Marks the given file for removal. The file is removed when removeFiles() or cleanUp() 17 | * is called. 18 | * 19 | * @param filePath - the absolute path to the file. 20 | * @returns {boolean} - true if the file was successfully marked for removal; false otherwise. 21 | */ 22 | function addFileToRemove(filePath) { 23 | if (theFilesToRemove.indexOf(filePath) === -1 && fs.existsSync(filePath)) { 24 | theFilesToRemove.push(filePath); 25 | return true; 26 | } 27 | return false; 28 | } 29 | 30 | /** 31 | * Removes the files marked for removal. 32 | */ 33 | function removeFiles() { 34 | for (var i = 0; i < theFilesToRemove.length; ++i) { 35 | theLogger.info('Removing: ' + theFilesToRemove[i]); 36 | fs.unlinkSync(theFilesToRemove[i]); 37 | } 38 | theFilesToRemove = []; 39 | } 40 | 41 | function initialize(testServer) { 42 | return new Promise(function (resolve, reject) { 43 | // Disable logging in PrintManager 44 | // 45 | var pmLogger = require('../../logging/PrintManagerLogger'); 46 | pmLogger.setEnabled(false); 47 | 48 | // Change the APP_DB_FOLDER to point to the temp directory. We need to do this 49 | // before app.js is read. We want the printers.db file to be placed in this 50 | // directory instead of using the real one. 51 | // 52 | var appSettings = require('../../config').appSettings; 53 | appSettings.APP_DB_FOLDER = os.tmpDir(); 54 | 55 | // Add event listeners to cleanup any files that were uploaded or created. 56 | // 57 | testServer.addListener('file_uploaded', function (event) { 58 | theLogger.info('Uploaded:' + event.fileId); 59 | var file = files.find(event.fileId); 60 | addFileToRemove(file.path); 61 | }); 62 | 63 | testServer.addListener('temp_file_created', function (event) { 64 | //console.log('Temp file created: ' + event.tempFilePath); 65 | addFileToRemove(event.tempFilePath); 66 | }); 67 | 68 | testServer.addListener('internal_file_created', function (event) { 69 | theLogger.info('Created: ' + event.internalFileId); 70 | var internalFilePath = files.find(event.internalFileId).path; 71 | addFileToRemove(internalFilePath); 72 | }); 73 | 74 | /** 75 | * Performs cleanup tasks. Currently this includes removing files marked for removal. 76 | * Typically this would be called in the afterEach() method of a test suite. 77 | */ 78 | var printerManager = require('../../printers/printerManager.js'); 79 | testServer.addListener('clean_up', function (event) { 80 | theLogger.info('Cleaning up'); 81 | removeFiles(); 82 | printerManager.clearSavedPrintersDb(); 83 | }); 84 | 85 | // Change the timeout for Roopa Server for PrintManager testing. 86 | // 87 | config.roopa_server_timeout = 30; 88 | 89 | theLogger.info('Initialized TestServer for PrintManager'); 90 | 91 | resolve(); 92 | }) 93 | } 94 | 95 | module.exports = initialize; -------------------------------------------------------------------------------- /spark-print-mgr/test/data/comparables/FDMComparableDremel.g3drem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/comparables/FDMComparableDremel.g3drem -------------------------------------------------------------------------------- /spark-print-mgr/test/data/models/HudTest.obj: -------------------------------------------------------------------------------- 1 | # Obj file \ 2 | # /Users/pittmab/Perforce/main/Kalpana/src/UI/Common/Resources/Materials/Hu \ 3 | # dTestMesh.obj generated by Autodesk OpenModel V2012 4 | # Fri Nov 19 10:57:04 2010 5 | # The units used in this file are Centimeters 6 | # fromNurbs#2 7 | # usemtl UNKNOWN 8 | g Obj_fromNurbs#2 9 | v -0.06932376 -0.01205582 0.07892155 10 | v 0.1161379 -0.01205582 0.07892155 11 | v 0.1161379 0.04830251 0.3347094 12 | v -0.06932376 0.04830251 0.3347094 13 | g 14 | vn 0 -0.9732702 0.2296629 15 | vn 0 -0.9732702 0.2296629 16 | vn 0 -0.9732702 0.2296629 17 | vn 0 -0.9732702 0.2296629 18 | vt 1 0 19 | vt 1 1 20 | vt 0 1 21 | vt 0 0 22 | s 1 23 | f 1/1/1 2/2/2 3/3/3 24 | f 3/3/3 4/4/4 1/1/1 25 | s off 26 | # End of Obj file \ 27 | # /Users/pittmab/Perforce/main/Kalpana/src/UI/Common/Resources/Materials/Hu \ 28 | # dTestMesh.obj 29 | -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/DLPPrintable.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/DLPPrintable.pb -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintable.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintable.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintableDremel.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintableDremel.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintableRep2.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintableRep2.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintableRep2Verbose.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintableRep2Verbose.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintableRep2VerboseRaft.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintableRep2VerboseRaft.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintableRep2VerboseSupports.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintableRep2VerboseSupports.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintableTypeA.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintableTypeA.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintableTypeAVerbose.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintableTypeAVerbose.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintableTypeAVerboseRaft.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintableTypeAVerboseRaft.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintableTypeAVerboseSupports.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintableTypeAVerboseSupports.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintableUltimaker.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintableUltimaker.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintableUltimakerVerbose.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintableUltimakerVerbose.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintableUltimakerVerboseRaft.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintableUltimakerVerboseRaft.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/printables/FDMPrintableUltimakerVerboseSupports.mic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spark3dp/print-manager/13d824d75ea2ccd054ef25578ad6c7205de738ae/spark-print-mgr/test/data/printables/FDMPrintableUltimakerVerboseSupports.mic -------------------------------------------------------------------------------- /spark-print-mgr/test/data/translators/DLPToJSONTranslator.js: -------------------------------------------------------------------------------- 1 | var DLPTranslator = require('../../../printableTranslation/DLPTranslator'), 2 | util = require('util'); 3 | 4 | function DLPToJSONTranslator(printerType, printerProfile, material) { 5 | DLPTranslator.call(this, printerType, printerProfile, material); 6 | this.sliceCount = 0; 7 | this.output = {}; 8 | } 9 | util.inherits(DLPToJSONTranslator, DLPTranslator); 10 | 11 | DLPToJSONTranslator.canTranslate = function (printerType, profile, material) { 12 | return printerType && printerType.technology && printerType.technology === 'DLP'; 13 | }; 14 | 15 | DLPToJSONTranslator.prototype.onHeader = function (header) { 16 | header.should.have.property('printer_type_id').and.be.String; 17 | header.should.have.property('image_height').and.be.Number; 18 | header.should.have.property('image_width').and.be.Number; 19 | header.should.have.property('num_slices').and.be.Number; 20 | 21 | this.sliceCount = header.num_slices; 22 | var jsonHeader = { 23 | 'printer_type_id': header.printer_type_id, 24 | 'image_height': header.image_height, 25 | 'image_width': header.image_width, 26 | 'num_slices': header.num_slices, 27 | }; 28 | 29 | this.output.header = jsonHeader; 30 | }; 31 | 32 | DLPToJSONTranslator.prototype.onSlice = function (index, slice) { 33 | if (!this.output.slices) { 34 | this.output.slices = []; 35 | } 36 | this.output.slices.push({index: index, size: slice.png_data.buffer.length}); 37 | 38 | var progress = (index + 1) / this.sliceCount; 39 | this.setProgress(progress); 40 | }; 41 | 42 | DLPToJSONTranslator.prototype.endTranslation = function (outputFile) { 43 | fs.writeFileSync(outputFile, JSON.stringify(this.output)); 44 | }; 45 | 46 | module.exports = DLPToJSONTranslator; -------------------------------------------------------------------------------- /spark-print-mgr/test/helpers/TestHelper.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | 3 | // Disable the logging in PrintManager. 4 | // 5 | var pmLogger = require('../../logging/PrintManagerLogger'); 6 | pmLogger.setEnabled(false); 7 | 8 | /** 9 | * Returns true if the file at the given path exists. 10 | * 11 | * @param {string} filePath 12 | * @returns {boolean} 13 | */ 14 | function fileExists(filePath) { 15 | return fs.existsSync(filePath); 16 | } 17 | 18 | /** 19 | * Returns true if the two files exist and have the same size. 20 | * 21 | * @param {string} aPath - path to a file 22 | * @param {string} bPath - path to another file 23 | * @returns {boolean} 24 | */ 25 | function filesSameSize(aPath, bPath) { 26 | if (fileExists(aPath) && fileExists(bPath)) { 27 | var aStat = fs.statSync(aPath), 28 | bStat = fs.statSync(bPath); 29 | return (aStat.size === bStat.size); 30 | } 31 | return false; 32 | } 33 | 34 | module.exports = { 35 | fileExists: fileExists, 36 | filesSameSize: filesSameSize 37 | }; 38 | -------------------------------------------------------------------------------- /spark-print-mgr/test/printers/translators/DremelTranslatorSpec.js: -------------------------------------------------------------------------------- 1 | var should = require('should'), 2 | os = require('os'), 3 | path = require('path'), 4 | checksum = require('checksum'), 5 | 6 | TestHelper = require('../../helpers/TestHelper'), 7 | DremelTranslator = require('../../../printableTranslation/translators/Dremel'), 8 | 9 | printerType = {id :"3F64F6EC-A1DF-44AB-A22E-58C036F2F474"}, 10 | comparableFile = path.join(__dirname, '../../data/comparables/FDMComparableDremel.g3drem'), 11 | inputFile = path.join(__dirname, '../../data/printables/FDMPrintableDremel.mic'), 12 | outputFile = path.join(os.tmpdir(), 'FDMPrintableDremel.g3drem'); 13 | 14 | describe('Dremel Translator', function () { 15 | it('should verify that it has the proper printerType ID', function (done) { 16 | DremelTranslator.canTranslate(printerType, undefined, undefined).should.equal(true); 17 | done(); 18 | }); 19 | 20 | it('should verify that the Dremel icon file exists', function (done) { 21 | var bitmapFilename = path.join(__dirname, '../../../../spark-print-data/data/DremelPrintableIcon.bmp'); 22 | TestHelper.fileExists(bitmapFilename).should.equal(true); 23 | done(); 24 | }); 25 | 26 | it('should translate a valid FDM file', function (done) { 27 | var config = { 28 | verbose : undefined, 29 | precision : undefined 30 | }; 31 | config.verbose = false; 32 | config.precision = { 33 | x: 3, 34 | y: 3, 35 | z: 3, 36 | e: 5, 37 | f: 0, 38 | p: 0, 39 | s: 0 40 | }; 41 | 42 | var translator = new DremelTranslator(printerType, undefined, undefined, config); 43 | 44 | var jobName = "Spark"; 45 | translator.getJobName().should.eql(jobName); 46 | 47 | 48 | translator.translate(inputFile, outputFile) 49 | .then(function () { 50 | TestHelper.fileExists(outputFile).should.equal(true); 51 | done(); 52 | }) 53 | .catch(function (err) { 54 | done(err); 55 | }); 56 | }); 57 | 58 | it('should match our expected file', function (done) { 59 | checksum.file(outputFile, function (err, sum) { 60 | checksum.file(comparableFile, function (err2, sum2) { 61 | sum.should.equal(sum2); 62 | done(); 63 | }); 64 | }); 65 | }); 66 | 67 | }); -------------------------------------------------------------------------------- /spark-print-mgr/test/printers/translators/EmberTranslatorSpec.js: -------------------------------------------------------------------------------- 1 | var should = require('should'), 2 | os = require('os'), 3 | path = require('path'), 4 | materials = require('../../../materials.js'), 5 | printerTypes = require('../../../printertypes.js'), 6 | profiles = require('../../../profiles.js'), 7 | EmberTranslator = require('../../../printableTranslation/translators/Autodesk-Ember.js'); 8 | 9 | describe('Ember Translator', function () { 10 | var printerType, printerProfile, material; 11 | 12 | before(function (done) { 13 | printerTypes.initialize(); 14 | printerType = printerTypes.find('7FAF097F-DB2E-45DC-9395-A30210E789AA'); 15 | should.exist(printerType); 16 | 17 | materials.initialize(); 18 | material = materials.find('426F14FE-E6AF-496F-BBC7-7D6C0E16861D'); 19 | should.exist(material); 20 | 21 | profiles.initialize(); 22 | printerProfile = profiles.find('0EE76E3C-41FB-ACA7-362A-F1A2818BC3F2'); 23 | should.exist(printerProfile); 24 | 25 | // TODO: These parameters are required by the translator. The profiles need to 26 | // be updated to include these and any missing ones in profiles.json. 27 | // 28 | printerProfile['burn-in_layer_angle_of_rotation'] = 10; 29 | printerProfile['first_layer_angle_of_rotation'] = 10; 30 | printerProfile['model_layer_angle_of_rotation'] = 10; 31 | 32 | done(); 33 | }); 34 | 35 | it('should translate a valid DLP file', function (done) { 36 | var jobName = "Test-Spark"; 37 | var translator = new EmberTranslator(printerType, printerProfile, material, jobName); 38 | translator.getPrinterType().should.eql(printerType); 39 | translator.getPrinterProfile().should.eql(printerProfile); 40 | translator.getMaterial().should.eql(material); 41 | translator.getJobName().should.eql(jobName); 42 | 43 | translator.on('progress', function (progress) { 44 | translator.progress.should.equal(progress); 45 | }); 46 | 47 | var inputFile = path.join(__dirname, '../../data/printables/DLPPrintable.pb'); 48 | var outputFile = path.join(os.tmpdir(), 'EmberPrintable.tar.gz'); 49 | translator.translate(inputFile, outputFile) 50 | .then(function () { 51 | TestHelper.fileExists(outputFile); 52 | 53 | // TODO: Read the output file to check correctness. 54 | // 55 | done(); 56 | }) 57 | .catch(function (err) { 58 | done(err); 59 | }); 60 | }); 61 | }); -------------------------------------------------------------------------------- /spark-print-mgr/utils/dateUtils.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Returns number of days between the two given dates. 4 | * 5 | * @param {Date} date1 - A date from which to count days. 6 | * @param {Date} date2 - A date to which to count days. 7 | * @returns {Int} - number of days between date1 and date2 8 | */ 9 | function daysBetween( date1, date2 ) 10 | { 11 | // Get 1 day in milliseconds 12 | var one_day=1000*60*60*24; 13 | 14 | // Convert both dates to milliseconds 15 | var date1_ms = date1.getTime(); 16 | var date2_ms = date2.getTime(); 17 | 18 | // Calculate the difference in milliseconds 19 | var difference_ms = date2_ms - date1_ms; 20 | 21 | // Convert back to days and return 22 | return Math.round(difference_ms/one_day); 23 | } 24 | 25 | 26 | /** 27 | * Returns a date as a string in the following format: yyyymmddhhmmss 28 | * 29 | * @param {Date} date - A date to format 30 | * @returns {String} - date formated as yyyymmddhhmmss 31 | */ 32 | function dateToYYYYMMDDhhmmss(date) { 33 | function pad(num) { 34 | num = num + ''; 35 | return num.length < 2 ? '0' + num : num; 36 | } 37 | 38 | return date.getFullYear() + 39 | pad(date.getMonth() + 1) + 40 | pad(date.getDate()) + 41 | pad(date.getHours()) + 42 | pad(date.getMinutes()) + 43 | pad(date.getSeconds()); 44 | } 45 | 46 | 47 | module.exports = { 48 | daysBetween: daysBetween, 49 | dateToYYYYMMDDhhmmss: dateToYYYYMMDDhhmmss 50 | }; -------------------------------------------------------------------------------- /spark-print-mgr/utils/formats.js: -------------------------------------------------------------------------------- 1 | // Formats for various resource types 2 | module.exports = { 3 | printerTypeCommon: { 4 | id: String, 5 | version: Number, 6 | manufacturer: String, 7 | name: String, 8 | technology: String, 9 | default_material_id: String, 10 | default_profile_id: String, 11 | supported_connections: Array, 12 | 13 | build_volume: { 14 | type: String, 15 | bed_size: Array, 16 | bed_file_id: String, 17 | park_position: Array, 18 | home_position: Array 19 | }, 20 | 21 | printable: { 22 | //packager_file_id: String // TODO: Not all printers have a packager yet so this has been commented out. 23 | //packager_data: Object // Optional 24 | }, 25 | _files: Array 26 | }, 27 | 28 | printerTypeFDM: { 29 | // Torpedo additions 30 | printer_capabilities: { 31 | num_extruders: Number, 32 | nozzle_diameter: Number, 33 | nozzle_temp_max: Number, 34 | bed_temp_max: Number, 35 | xy_speed_max: Number, 36 | z_speed_max: Number, 37 | e_speed_max: Number 38 | } 39 | }, 40 | 41 | supportedConnection: { 42 | type: String, 43 | protocol: String 44 | //info: Object // Optional 45 | }, 46 | 47 | printer: { 48 | id: String, 49 | name: String, 50 | type_id: String, 51 | /*firmware: {}, */ // Optional. Currently no way to get firmware version from a typea printer. 52 | default_material_id: String, 53 | default_profile_id: String 54 | }, 55 | 56 | firmware: { 57 | type: String, 58 | version: String 59 | }, 60 | 61 | materialCommon: { 62 | id: String, 63 | version: Number, 64 | manufacturer: String, 65 | name: String, 66 | technology: String, 67 | composition: String, 68 | printer_types: Array, 69 | cost: Number, 70 | website: String, 71 | color: String, 72 | opacity: Number, 73 | rating: Number, 74 | tags: Array, 75 | //pct_shrink: Number, // Can't be checked with format function since it can also be null. 76 | //prism_URN: Number, // Tentative 77 | is_user: Boolean 78 | }, 79 | 80 | materialFDM: { 81 | filament_diameter: Number, 82 | filament_extrusion_to_flow_multiplier: Number, 83 | temp_extrude_default: Number, 84 | temp_min_extrude: Number, 85 | temp_max_extrude: Number, 86 | temp_bed: Number, 87 | min_nozzle_diameter: Number, 88 | extruder_fan_speed: Number 89 | }, 90 | 91 | materialDLP: { 92 | FirstExposureSec: Number, 93 | BurnInLayers: Number, 94 | BurnInExposureSec: Number, 95 | ModelExposureSec: Number, 96 | density: Number 97 | }, 98 | 99 | profile: { 100 | id: String, 101 | version: Number, 102 | name: String, 103 | technology: String, 104 | printer_types: Array, 105 | layer_height: Number, 106 | support_angle_tol: Number, 107 | support_contact_tol: Number 108 | // TODO: Find out what the undocumented fields are and document them 109 | }, 110 | 111 | mesh: { 112 | id: String, 113 | name: String, 114 | internal_file_id: String, 115 | transform: Array, 116 | geom: { 117 | num_vertices: Number, 118 | num_triangles: Number, 119 | has_uvs: Boolean, 120 | bounding_box: { 121 | min: Array, 122 | max: Array 123 | } 124 | }, 125 | //visual_file_id: String, // Optional 126 | analyzed: Boolean 127 | //problems: Array // Optional, dependent on analyzed being true 128 | }, 129 | 130 | tray: { 131 | id: String, 132 | printer_type_id: String, 133 | profile_id: String, 134 | default_material_id: String, 135 | meshes: Array, 136 | // mesh_attrs: Object, // Not optional but can't be checked with a format 137 | state: String, 138 | ready: Boolean 139 | } 140 | }; 141 | -------------------------------------------------------------------------------- /spark-print-mgr/version.js: -------------------------------------------------------------------------------- 1 | var express = require( 'express'), 2 | roopa = require( './roopa'), 3 | config = require('./config').config, 4 | logger = require('./logging/PrintManagerLogger'); 5 | 6 | var router = null; 7 | var version = null; 8 | 9 | 10 | function initialize () { 11 | 12 | // Read print definition schema and revision values from 13 | // version.json config file. 14 | // 15 | var data = require(config.printer_data_files + 'version.json'); 16 | config.print_definition_schema = data.print_definition_schema; 17 | config.print_definition_revision = data.print_definition_revision; 18 | } 19 | 20 | function computeVersion(techData) { 21 | // api 22 | var api = {}; 23 | api.major = 1; 24 | api.minor = 0; 25 | api.commit_id = config.commit_id; 26 | api.short_commit_id = api.commit_id.substring( 0, 6 ); 27 | 28 | // print_definition 29 | var pd = {}; 30 | pd.schema = config.print_definition_schema; 31 | pd.revision = config.print_definition_revision; 32 | 33 | // assemble the final object ... 34 | var ver = {}; 35 | ver.api = api; 36 | ver.core_technology = techData; 37 | ver.print_definition = pd; 38 | 39 | // ... and set it 40 | version = ver; 41 | } 42 | 43 | function sendVersion(res) { 44 | res.status(200); 45 | res.send(version); 46 | } 47 | 48 | function getVersion(req, res, next) { 49 | if (version) { 50 | sendVersion(res); 51 | return; 52 | } 53 | 54 | // generate the version info 55 | var p = roopa.run( "getVersion.lua" ); 56 | p.then(function (data) { 57 | computeVersion( data ); 58 | sendVersion( res ); 59 | }, 60 | function (data) { 61 | logger.warn('getVersion failed!'); 62 | res.send('getVersion failed!'); 63 | res.status( 500 ); 64 | }); 65 | } 66 | 67 | function getRouter() { 68 | if (router) 69 | return router; 70 | 71 | // configure the router 72 | router = express.Router(); 73 | router.get('/', getVersion); 74 | 75 | return router; 76 | } 77 | 78 | 79 | module.exports = exports = { 80 | 'initialize' : initialize, 81 | 'Router' : getRouter 82 | }; 83 | --------------------------------------------------------------------------------