Skip to content

Commit

Permalink
Merge pull request #278 from WesGilster/master
Browse files Browse the repository at this point in the history
Fix for printing files without customizers
  • Loading branch information
WesGilster authored Oct 27, 2016
2 parents cef98cc + febb402 commit e17435a
Show file tree
Hide file tree
Showing 21 changed files with 291 additions and 160 deletions.
7 changes: 6 additions & 1 deletion host/conf/log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ appender.rolling.policies.size.size=20MB
appender.rolling.strategy.type=DefaultRolloverStrategy
appender.rolling.strategy.max=5

loggers=hex,serial,printer,media
loggers=hex,serial,printer,media,usb

#We need to define each of the loggers that we listed in the previous line
logger.media.name=org.area515.resinprinter.services.MediaService
Expand All @@ -49,6 +49,11 @@ logger.printer.level=debug
logger.printer.additivity=false
logger.printer.appenderRefs=rolling
logger.printer.appenderRef.rolling.ref=RollingFile
logger.usb.name=org.area515.resinprinter.usbimport.USBUploader
logger.usb.level=debug
logger.usb.additivity=false
logger.usb.appenderRefs=rolling
logger.usb.appenderRef.rolling.ref=RollingFile

#Default logger
rootLogger.level=info
Expand Down
2 changes: 1 addition & 1 deletion host/resourcesnew/2dProperties.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h4>Scale to fit print area</h4>
</div>
<div class="list-group-item">
<i class="fa fa-2x fa-edit pull-left"></i>
<h4>Platform Calculator</h4>
<h4>Base Platform Calculator</h4>
<div class="input-group"
cwh-testscript
placeholder="(no return value required yet)"
Expand Down
57 changes: 55 additions & 2 deletions host/resourcesnew/cwh/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,67 @@
return new Date(1970, 0, 1).setMilliseconds(milliseconds);
};
}]);
cwhApp.factory('cacheControl', function() {

cwhApp.factory('photonicUtils', ['$http', '$rootScope', function($http, $rootScope) {
return {
previewExternalStateId:firstCacheId,

testScript: function(controller, scriptName, returnType, script, successFunction) {
var printerNameEn = encodeURIComponent(controller.currentPrinter.configuration.name);
var scriptNameEn = encodeURIComponent(scriptName);
var returnTypeEn = encodeURIComponent(returnType);

$http.post('/services/printers/testScript/' + printerNameEn + "/" + scriptNameEn + "/" + returnTypeEn, script).success(function (data) {
controller.graph = data.result;
if (data.error) {
$rootScope.$emit("MachineResponse", {machineResponse: {command:scriptName, message:data.errorDescription}, successFunction:null, afterErrorFunction:null});
return;
} else if (returnType.indexOf("[") > -1){
$('#graphScript').modal();
} else {
$rootScope.$emit("MachineResponse", {machineResponse: {command:scriptName, message:"Successful execution. Script returned:" + JSON.stringify(data.result), response:true}, successFunction:null, afterErrorFunction:null});
}
if (successFunction != null) {
successFunction();
}
}).error(function (data, status, headers, config, statusText) {
$rootScope.$emit("HTTPError", {status:status, statusText:data});
})
},

getPrintFileProcessorIconClass: function getPrintFileProcessorIconClass(processorContainer) {
if (processorContainer == null || processorContainer.printFileProcessor == null) {
return "Unknown";
}
if (processorContainer.printFileProcessor.friendlyName === 'Image') {
return "fa-photo";
}
if (processorContainer.printFileProcessor.friendlyName === 'Maze Cube') {
return "fa-cube";
}
if (processorContainer.printFileProcessor.friendlyName === 'STL 3D Model') {
return "fa-object-ungroup";
}
if (processorContainer.printFileProcessor.friendlyName === 'Creation Workshop Scene') {
return "fa-diamond";
}
if (processorContainer.printFileProcessor.friendlyName === 'Zip of Slice Images') {
return "fa-stack-overflow";
}
if (processorContainer.printFileProcessor.friendlyName === 'Simple Text') {
return "fa-bold";
}
if (processorContainer.printFileProcessor.friendlyName === 'Scalable Vector Graphics') {
return "fa-puzzle-piece";
}
return "fa-question-circle";
},

clearPreviewExternalState: function() {
this.previewExternalStateId = Math.random();
}
};
});
}]);

cwhApp.config(['$routeProvider', '$locationProvider', '$httpProvider', function($routeProvider, $locationProvider, $httpProvider) {
if (!$httpProvider.defaults.headers.get) {
Expand Down
28 changes: 2 additions & 26 deletions host/resourcesnew/cwh/js/printJobs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
var cwhApp = angular.module('cwhApp');
cwhApp.controller("PrintJobsController", ['$scope', '$http', '$location', '$anchorScroll', 'Upload', 'cwhWebSocket', function ($scope, $http, $location, $anchorScroll, Upload, cwhWebSocket) {
cwhApp.controller("PrintJobsController", ['$scope', '$http', '$location', '$anchorScroll', 'Upload', 'cwhWebSocket', 'photonicUtils', function ($scope, $http, $location, $anchorScroll, Upload, cwhWebSocket, photonicUtils) {
controller = this;

this.urlToUpload = null;
Expand Down Expand Up @@ -151,31 +151,7 @@
}

this.getPrintJobIconClass = function getPrintJobIconClass(printable) {
if (printable == null || printable.printFileProcessor == null) {
return "Unknown";
}
if (printable.printFileProcessor.friendlyName === 'Image') {
return "fa-photo";
}
if (printable.printFileProcessor.friendlyName === 'Maze Cube') {
return "fa-cube";
}
if (printable.printFileProcessor.friendlyName === 'STL 3D Model') {
return "fa-object-ungroup";
}
if (printable.printFileProcessor.friendlyName === 'Creation Workshop Scene') {
return "fa-diamond";
}
if (printable.printFileProcessor.friendlyName === 'Zip of Slice Images') {
return "fa-stack-overflow";
}
if (printable.printFileProcessor.friendlyName === 'Simple Text') {
return "fa-bold";
}
if (printable.printFileProcessor.friendlyName === 'Scalable Vector Graphics') {
return "fa-puzzle-piece";
}
return "fa-question-circle";
return photonicUtils.getPrintFileProcessorIconClass(printable);
}

this.refreshPrintJobs();
Expand Down
84 changes: 55 additions & 29 deletions host/resourcesnew/cwh/js/printables.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
var cwhApp = angular.module('cwhApp');
cwhApp.controller("PrintablesController", ['$scope', '$http', '$location', '$uibModal', '$anchorScroll', 'cwhWebSocket', 'cacheControl', function ($scope, $http, $location, $uibModal, $anchorScroll, cwhWebSocket, cacheControl) {
cwhApp.controller("PrintablesController", ['$scope', '$http', '$location', '$uibModal', '$anchorScroll', 'cwhWebSocket', 'photonicUtils', function ($scope, $http, $location, $uibModal, $anchorScroll, cwhWebSocket, photonicUtils) {
controller = this;

this.currentPrintable = null;
Expand All @@ -25,7 +25,7 @@

this.saveCustomizer = function saveCustomizer() {
if (controller.currentPrintable != null && controller.currentCustomizer != null) {
controller.currentCustomizer.externalImageAffectingState = cacheControl.previewExternalStateId;
controller.currentCustomizer.externalImageAffectingState = photonicUtils.previewExternalStateId;
$http.post("/services/customizers/upsert", controller.currentCustomizer).success(function (data) {
controller.currentPreviewImg = "/services/customizers/renderPreviewImage/" + controller.currentCustomizer.name + "?_=" + data.cacheId;
}).error(function (data, status, headers, config, statusText) {
Expand All @@ -49,7 +49,7 @@
return;
}

$http.get("services/customizers/get/" + newCustomizerName + "?externalState=" + cacheControl.previewExternalStateId).success(
$http.get("services/customizers/get/" + newCustomizerName + "?externalState=" + photonicUtils.previewExternalStateId).success(
function (data) {
if (data == "") {
controller.currentCustomizer = {
Expand All @@ -58,7 +58,7 @@
printableName: newPrintable.name,
printableExtension: newPrintable.extension,
supportsAffineTransformSettings: true,
externalImageAffectingState:cacheControl.previewExternalStateId,
externalImageAffectingState:photonicUtils.previewExternalStateId,
zscale: 1,
nextSlice: 0,
nextStep: "PerformHeader",
Expand All @@ -78,7 +78,7 @@
};
} else {
controller.currentCustomizer = data;
controller.currentCustomizer.externalImageAffectingState = cacheControl.previewExternalStateId;
controller.currentCustomizer.externalImageAffectingState = photonicUtils.previewExternalStateId;
}

//We probably don't need to save the customizer here but we do it in case the externalState changed
Expand Down Expand Up @@ -250,34 +250,60 @@
};

this.clearExternalCacheAndSaveCustomizer = function clearExternalCacheAndSaveCustomizer() {
cacheControl.clearPreviewExternalState();
photonicUtils.clearPreviewExternalState();
controller.saveCustomizer();
}

this.testScript = function testScript(scriptName, returnType, script) {
photonicUtils.testScript(controller, scriptName, returnType, script, controller.clearExternalCacheAndSaveCustomizer);
};

this.writeDrainHoldCode = function writeDrainHoldCode() {
controller.currentCustomizer.imageManipulationCalculator =
"var drainHoleInMM = { centerX:centerX, centerY:centerY, widthX:5, widthY:5, depth:5};\n\n" +
"if (($CURSLICE * $LayerThickness) <= drainHoleInMM.depth) {\n" +
" buildPlatformGraphics.setColor(java.awt.Color.BLACK);\n" +
" buildPlatformGraphics.fillOval(\n" +
" (drainHoleInMM.centerX - (drainHoleInMM.widthX/2 * pixelsPerMMX)),\n" +
" (drainHoleInMM.centerY - (drainHoleInMM.widthY/2 * pixelsPerMMY)),\n" +
" drainHoleInMM.widthX * pixelsPerMMX,\n" +
" drainHoleInMM.widthY * pixelsPerMMY);\n" +
"}\n";

controller.clearExternalCacheAndSaveCustomizer();
};

this.writeDuplicationGridCode = function writeDuplicationGridCode() {
controller.currentCustomizer.imageManipulationCalculator =
"var gridDataInMM = {distanceBetweenImagesX: 1, distanceBetweenImagesY: 1, numberOfRows:3, numberOfColumns:3 };\n\n" +
"for (var x = 0; x < gridDataInMM.numberOfColumns; x++) {\n" +
" for (var y = 0; y < gridDataInMM.numberOfRows; y++) {\n" +
" if (x > 0 || y > 0) {\n" +
" var currentTransform = new java.awt.geom.AffineTransform(affineTransform);\n" +
" currentTransform.translate(\n" +
" (x * gridDataInMM.distanceBetweenImagesX * pixelsPerMMX) + (x * printImage.getWidth()),\n" +
" (y * gridDataInMM.distanceBetweenImagesY * pixelsPerMMY) + (y * printImage.getHeight()));\n" +
" buildPlatformGraphics.drawImage(printImage, currentTransform, null);\n" +
" }\n" +
" }\n" +
"}\n";

controller.clearExternalCacheAndSaveCustomizer();
};

this.write3dTwistCode = function write3dTwistCode() {
controller.currentCustomizer.affineTransformSettings.affineTransformScriptCalculator =
"var currentTransform = new java.awt.geom.AffineTransform();\n" +
"currentTransform.rotate(java.lang.Math.toRadians($CURSLICE));\n" +
"currentTransform.translate(\n" +
" centerX-printImage.getWidth()/2,\n" +
" centerY-printImage.getHeight()/2);\n" +
"currentTransform";
}

this.getPrintableIconClass = function getPrintableIconClass(printable) {
if (printable.printFileProcessor.friendlyName === 'Image') {
return "fa-photo";
}
if (printable.printFileProcessor.friendlyName === 'Maze Cube') {
return "fa-cube";
}
if (printable.printFileProcessor.friendlyName === 'STL 3D Model') {
return "fa-object-ungroup";
}
if (printable.printFileProcessor.friendlyName === 'Creation Workshop Scene') {
return "fa-diamond";
}
if (printable.printFileProcessor.friendlyName === 'Zip of Slice Images') {
return "fa-stack-overflow";
}
if (printable.printFileProcessor.friendlyName === 'Simple Text') {
return "fa-bold";
}
if (printable.printFileProcessor.friendlyName === 'Scalable Vector Graphics') {
return "fa-puzzle-piece";
}
return "fa-question-circle";
};//*/
return photonicUtils.getPrintFileProcessorIconClass(printable);
};

this.refreshPrintables();
this.refreshCurrentPrinter();
Expand Down
4 changes: 2 additions & 2 deletions host/resourcesnew/cwh/js/printerControls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
var cwhApp = angular.module('cwhApp');
cwhApp.controller("PrinterControlsController", ['$scope', '$http', '$location', '$routeParams', 'cwhWebSocket', 'cacheControl', function ($scope, $http, $location, $routeParams, cwhWebSocket, cacheControl) {
cwhApp.controller("PrinterControlsController", ['$scope', '$http', '$location', '$routeParams', 'cwhWebSocket', 'photonicUtils', function ($scope, $http, $location, $routeParams, cwhWebSocket, photonicUtils) {
controller = this;
this.currentPrintJob = null;
this.gcodeProcessing = "";
Expand Down Expand Up @@ -94,7 +94,7 @@
$http.get("services/printers/calibrate/" + printerName + "/" + (controller.calibration.xPixels/controller.calibration.xMM) + "/" + (controller.calibration.yPixels/controller.calibration.yMM)).
then(function(data) {
gCodeSuccess(data);
cacheControl.clearPreviewExternalState();
photonicUtils.clearPreviewExternalState();
loadPrinter();
}, errorFunction);
controller.showBlankScreen();
Expand Down
29 changes: 7 additions & 22 deletions host/resourcesnew/cwh/js/printers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
var cwhApp = angular.module('cwhApp');
cwhApp.controller("PrintersController", ['$scope', '$http', '$location', '$anchorScroll', '$uibModal', 'cacheControl', function ($scope, $http, $location, $anchorScroll, $uibModal, cacheControl) {
cwhApp.controller("PrintersController", ['$scope', '$http', '$location', '$anchorScroll', '$uibModal', 'photonicUtils', function ($scope, $http, $location, $anchorScroll, $uibModal, photonicUtils) {
controller = this;
var PRINTERS_DIRECTORY = "printers";
var BRANCH = "master";
Expand Down Expand Up @@ -94,7 +94,7 @@
executeActionAndRefreshPrinters("Save Printer", "No printer selected to save.", '/services/printers/save', printer, true);
controller.editPrinter = null;
controller.openType = null;
cacheControl.clearPreviewExternalState();
photonicUtils.clearPreviewExternalState();
}

function openSavePrinterDialog(editTitle, isNewPrinter) {
Expand Down Expand Up @@ -184,25 +184,6 @@
this.gotoPrinterControls = function gotoPrinterControls() {
$location.path('/printerControlsPage').search({printerName: controller.currentPrinter.configuration.name})
};

this.testScript = function testScript(scriptName, returnType, script) {
var printerNameEn = encodeURIComponent(controller.currentPrinter.configuration.name);
var scriptNameEn = encodeURIComponent(scriptName);
var returnTypeEn = encodeURIComponent(returnType);

$http.post('/services/printers/testScript/' + printerNameEn + "/" + scriptNameEn + "/" + returnTypeEn, script).success(function (data) {
controller.graph = data.result;
if (data.error) {
$scope.$emit("MachineResponse", {machineResponse: {command:scriptName, message:data.errorDescription}, successFunction:null, afterErrorFunction:null});
} else if (returnType.indexOf("[") > -1){
$('#graphScript').modal();
} else {
$scope.$emit("MachineResponse", {machineResponse: {command:scriptName, message:"Successful execution. Script returned:" + JSON.stringify(data.result), response:true}, successFunction:null, afterErrorFunction:null});
}
}).error(function (data, status, headers, config, statusText) {
$scope.$emit("HTTPError", {status:status, statusText:data});
})
}

this.testTemplate = function testTemplate(scriptName, script) {
var printerNameEn = encodeURIComponent(controller.currentPrinter.configuration.name);
Expand Down Expand Up @@ -250,13 +231,17 @@
controller.machineConfigurations = data;
controller.loadingMachineConfigMessage = "Select a machine configuration...";
});
//https://raw.githubusercontent.com/WesGilster/Creation-Workshop-Host/master/host/printers/mUVe%201.json

$http.get("https://api.github.com/repos/" + $scope.repo + "/contents/host/" + PRINTERS_DIRECTORY + "?ref=" + BRANCH).success(
function (data) {
$scope.communityPrinters = data;
}
);

this.testScript = function testScript(scriptName, returnType, script) {
photonicUtils.testScript(controller, scriptName, returnType, script);
};

controller.inkDetectors = [{name:"Visual Ink Detector", className:"org.area515.resinprinter.inkdetection.visual.VisualPrintMaterialDetector"}];
refreshPrinters();
}])
Expand Down
2 changes: 1 addition & 1 deletion host/resourcesnew/cwh/js/users.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
var cwhApp = angular.module('cwhApp');
cwhApp.controller("UsersController", ['$scope', '$http', '$location', '$anchorScroll', '$uibModal', 'cacheControl', function ($scope, $http, $location, $anchorScroll, $uibModal, cacheControl) {
cwhApp.controller("UsersController", ['$scope', '$http', '$location', '$anchorScroll', '$uibModal', 'photonicUtils', function ($scope, $http, $location, $anchorScroll, $uibModal, photonicUtils) {
$scope.refreshUsers = function refreshUsers() {
$http.get('/services/users/list').success(function(data) {
$scope.users = data;
Expand Down
Loading

0 comments on commit e17435a

Please sign in to comment.