Skip to content

Commit

Permalink
Merge pull request #256 from WesGilster/master
Browse files Browse the repository at this point in the history
Added functionality to restore print from last status when using a customizer
  • Loading branch information
WesGilster authored Sep 25, 2016
2 parents 1537614 + 71a923f commit 6b0f88a
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 91 deletions.
18 changes: 14 additions & 4 deletions host/resourcesnew/cwh/js/cwhspinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ angular.module('cwh.spinner', []).directive('cwhSpinner', function() {
iElement.find('input')[0].value = ngModelController.$viewValue;
};
function incrementModel(inc) {
ngModelController.$setViewValue(ngModelController.$viewValue + inc);
ngModelController.$render();
if (ngModelController.$viewValue + inc <= max &&
ngModelController.$viewValue + inc >= min) {
ngModelController.$setViewValue(ngModelController.$viewValue + inc);
ngModelController.$render();
return true;
}

return false;
}
scope.setModel = function() {
var input = parseFloat(iElement.find('input')[0].value);
Expand All @@ -35,10 +41,14 @@ angular.module('cwh.spinner', []).directive('cwhSpinner', function() {
ngModelController.$setViewValue(input);
}
scope.increment = function() {
incrementModel(increment);
if (incrementModel(increment) && iAttrs.incclick != null) {
scope.$parent.$eval(iAttrs.incclick);
}
}
scope.decrement = function() {
incrementModel(-increment);
if (incrementModel(-increment) && iAttrs.decclick != null) {
scope.$parent.$eval(iAttrs.decclick);
}
}
scope.goClick = function() {
scope.$parent.$eval(iAttrs.goclick);
Expand Down
32 changes: 11 additions & 21 deletions host/resourcesnew/cwh/js/printables.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
supportsAffineTransformSettings: true,
externalImageAffectingState:cacheControl.previewExternalStateId,
zscale: 1,
nextSlice: 0,
nextStep: "PerformHeader",
affineTransformSettings: {
yflip: false,
xflip: false,
Expand Down Expand Up @@ -92,6 +94,9 @@
$http.get("services/printers/getFirstAvailablePrinter").success(
function (data) {
controller.currentPrinter = data;
}).error(
function (data) {
controller.errorMsg = data;
});
};

Expand All @@ -118,26 +123,6 @@
})
}

/*this.flipY = function flipY() {
var incrementor = controller.currentPrinter.configuration.machineConfig.MonitorDriverConfig.DLP_Y_Res;
if (controller.currentCustomizer.affineTransformSettings.yscale < 0) {
incrementor *= -1;
}
controller.currentCustomizer.affineTransformSettings.ytranslate += incrementor;
controller.currentCustomizer.affineTransformSettings.yscale = -controller.currentCustomizer.affineTransformSettings.yscale;
this.saveCustomizer();
}
this.flipX = function flipX() {
var incrementor = controller.currentPrinter.configuration.machineConfig.MonitorDriverConfig.DLP_X_Res;
if (controller.currentCustomizer.affineTransformSettings.xscale < 0) {
incrementor *= -1;
}
controller.currentCustomizer.affineTransformSettings.xtranslate += incrementor;
controller.currentCustomizer.affineTransformSettings.xscale = -controller.currentCustomizer.affineTransformSettings.xscale;
this.saveCustomizer();
}*/

this.changeScale = function changeScale(x, y, z) {
controller.currentCustomizer.affineTransformSettings.xscale += x;
controller.currentCustomizer.affineTransformSettings.yscale += y;
Expand Down Expand Up @@ -258,7 +243,12 @@

fileChosenModal.result.then(function (uploadedPrintable) {this.refreshPrintables()});
};


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

this.getPrintableIconClass = function getPrintableIconClass(printable) {
if (printable.printFileProcessor.friendlyName === 'Image') {
return "fa-photo";
Expand Down
17 changes: 16 additions & 1 deletion host/resourcesnew/printables.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ <h6>Translate image on Y axis: {{printablesController.currentCustomizer.affineTr
<a class="btn btn-sm btn-success fa fa-angle-up" ng-click="printablesController.changeTranslate(0, -1)"> 1</a>
<a class="btn btn-sm btn-success fa fa-angle-up" ng-click="printablesController.changeTranslate(0, -10)"> 10</a>
<a class="btn btn-sm btn-success fa fa-angle-double-up" ng-click="printablesController.changeTranslate(0, -100)"> 100</a>
</span>
</span>
<h6>Translate image on X axis: {{printablesController.currentCustomizer.affineTransformSettings.xtranslate}}</h6>
<span class="btn-group" >
<b class="btn btn-sm btn-danger fa fa-angle-double-left" ng-click="printablesController.changeTranslate(-100, 0)"> 100</b>
Expand All @@ -218,6 +218,21 @@ <h6>Translate image on X axis: {{printablesController.currentCustomizer.affineTr
<a class="btn btn-sm btn-success fa fa-angle-double-right" ng-click="printablesController.changeTranslate(100, 0)">100</a>
</span>
</div>
<div class="list-group-item">
<i class="fa fa-2x fa-list-ol pull-left"></i>
<h4>Starting slice #</h4>
<div class="input-group"
cwh-spinner
placeholder="Slice #"
min="0"
max="500000000000"
inc="1"
goClick="printablesController.clearExternalCacheAndSaveCustomizer()"
incClick="printablesController.clearExternalCacheAndSaveCustomizer()"
decClick="printablesController.clearExternalCacheAndSaveCustomizer()"
ng-model="printablesController.currentCustomizer.nextSlice">
</div>
</div>
</div>
<!-- End list group -->
<div class="panel-footer">
Expand Down
2 changes: 2 additions & 0 deletions host/resourcesnew/printerControls.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ <h4>Grid Screen (pixels)</h4>
max="500"
inc="1"
goClick="printerControlsController.showGridScreen()"
incClick="printerControlsController.showGridScreen()"
decClick="printerControlsController.showGridScreen()"
ng-model="printerControlsController.squarePixelSize">
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package org.area515.resinprinter.job;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.locks.ReentrantLock;

import javax.imageio.ImageIO;
import javax.script.ScriptEngine;
import javax.script.ScriptException;

Expand All @@ -37,6 +39,7 @@
import org.area515.resinprinter.slice.StlError;
import org.area515.util.Log4jTimer;
import org.area515.util.TemplateEngine;
import org.fourthline.cling.support.avtransport.callback.GetTransportInfo;

public abstract class AbstractPrintFileProcessor<G,E> implements PrintFileProcessor<G,E>{
private static final Logger logger = LogManager.getLogger();
Expand All @@ -59,7 +62,7 @@ public static class DataAid {
public long currentSliceTime;
public Paint maskPaint;
public boolean optimizeWithPreviewMode;
public AffineTransform affineTransform = new AffineTransform();
private AffineTransform affineTransform;
public RenderingCache cache = new RenderingCache();
public Customizer customizer;

Expand All @@ -77,9 +80,8 @@ public DataAid(PrintJob printJob) throws JobManagerException {
yResolution = slicingProfile.getyResolution();
optimizeWithPreviewMode = false;
customizer = printJob.getCustomizer();
if (customizer != null) {
this.affineTransform = customizer.createAffineTransform(xResolution, yResolution);
} else {

if (customizer == null) {
customizer = new Customizer();
customizer.setNextStep(PrinterStep.PerformHeader);
customizer.setNextSlice(0);
Expand All @@ -102,6 +104,20 @@ public DataAid(PrintJob printJob) throws JobManagerException {
//TODO: how do I integrate slicingProfile.getLiftDistance()
sliceHeight = inkConfiguration.getSliceHeight();
}

public AffineTransform getAffineTransform(BufferedImage img) {
if (this.affineTransform != null) {
return this.affineTransform;
}

if (customizer != null) {
this.affineTransform = customizer.createAffineTransform(xResolution, yResolution, img.getWidth(), img.getHeight());
} else {
this.affineTransform = new AffineTransform();
}

return this.affineTransform;
}
}

@Override
Expand Down Expand Up @@ -382,17 +398,39 @@ public BufferedImage applyImageTransforms(DataAid aid, BufferedImage img) throws
return img;
}

BufferedImage after = new BufferedImage(aid.xResolution, aid.yResolution, img.getType());
AffineTransformOp transOp = new AffineTransformOp(aid.affineTransform, AffineTransformOp.TYPE_BILINEAR);
after = transOp.filter(img, after);

/*try {
ImageIO.write(img, "png", new File("first.png"));
} catch (IOException e) {
}//*/

BufferedImage after = new BufferedImage(aid.xResolution, aid.yResolution, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g = (Graphics2D)after.getGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, aid.xResolution, aid.yResolution);

/*try {
ImageIO.write(after, "png", new File("afterfill.png"));
} catch (IOException e) {
}//*/

AffineTransform transform = aid.getAffineTransform(img);
g.drawImage(img, transform, null);
/*try {
ImageIO.write(after, "png", new File("afterapplication.png"));
} catch (IOException e) {
}//*/
applyBulbMask(aid, (Graphics2D)after.getGraphics(), aid.xResolution, aid.yResolution);
/*try {
ImageIO.write(after, "png", new File("afterbulb.png"));
} catch (IOException e) {
}//*/

return after;
}

protected BufferedImage convertTo3BGR(BufferedImage input) {
BufferedImage output = new BufferedImage(input.getWidth(), input.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
output.getGraphics().drawImage(input, 0, 0, null);
output.getGraphics().drawImage(input, 0, 0, Color.BLACK, null);
return output;
}

Expand Down Expand Up @@ -431,10 +469,10 @@ public BufferedImage buildPreviewSlice(Customizer customizer, File jobFile, Prev
dataAid.optimizeWithPreviewMode = true;
image = previewable.renderPreviewImage(dataAid);
dataAid.optimizeWithPreviewMode = false;
if (customizer.getAffineTransformSettings().isIdentity()) {
/*if (customizer.getAffineTransformSettings().isIdentity()) {
image = convertTo3BGR(image);
customizer.setOrigSliceCache(image);
}
}*/
}

image = applyImageTransforms(dataAid, image);
Expand Down
24 changes: 8 additions & 16 deletions host/src/main/java/org/area515/resinprinter/job/Customizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ public static class AffineTransformSettings {
private Boolean yFlip = false;
private String affineTransformScriptCalculator;//Ignore this for now

@JsonIgnore
public boolean isIdentity() {
if (xTranslate == 0.0 && yTranslate == 0.0
&& xScale == 1.0 && yScale == 1.0) {
return true;
} else {
return false;
}
}

public Double getXTranslate() {
return xTranslate;
}
Expand Down Expand Up @@ -125,19 +115,21 @@ public void setAffineTransformScriptCalculator(String affineTransformScriptCalcu
this.affineTransformScriptCalculator = affineTransformScriptCalculator;
}

public AffineTransform createAffineTransform(double width, double height) {
public AffineTransform createAffineTransform(double xResolution, double yResolution, double imageWidth, double imageHeight) {
AffineTransform firstTransform = null;
if (this.xFlip || this.yFlip) {
firstTransform = new AffineTransform();
firstTransform.translate(xFlip?width:0, yFlip?height:0);
firstTransform.translate((xFlip?imageWidth:0), (yFlip?imageHeight:0));
firstTransform.scale(xFlip?-1:1, yFlip?-1:1);
}

AffineTransform affineTransform = new AffineTransform();
affineTransform.translate(this.xTranslate, this.yTranslate);
affineTransform.translate(xResolution/2, yResolution/2);
affineTransform.shear(this.xShear, this.yShear);
affineTransform.rotate(Math.toRadians(this.rotation), width/2, height/2);
affineTransform.rotate(Math.toRadians(this.rotation));
affineTransform.scale(this.xScale, this.yScale);
affineTransform.translate(-imageWidth/2 + this.xTranslate, -imageHeight/2 + this.yTranslate);

if (firstTransform != null) {
affineTransform.concatenate(firstTransform);
}
Expand All @@ -160,8 +152,8 @@ public void setNextStep(PrinterStep nextStep) {
this.nextStep = nextStep;
}

public AffineTransform createAffineTransform(double width, double height) {
return this.affineTransformSettings.createAffineTransform(width, height);
public AffineTransform createAffineTransform(double width, double height, double imageWidth, double imageHeight) {
return this.affineTransformSettings.createAffineTransform(width, height, imageWidth, imageHeight);
}

public String getPrintableExtension() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.Future;

import javax.script.ScriptException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.area515.resinprinter.display.InappropriateDeviceException;
import org.area515.resinprinter.exception.SliceHandlingException;
import org.area515.resinprinter.job.render.RenderedData;
import org.area515.resinprinter.job.render.RenderingCache;
import org.area515.resinprinter.printer.BuildDirection;
import org.area515.resinprinter.server.Main;
import org.area515.resinprinter.slice.CloseOffMend;
Expand Down Expand Up @@ -72,15 +67,15 @@ public JobStatus processFile(PrintJob printJob) throws Exception {
printJob.setTotalSlices(slicer.getZMaxIndex() - slicer.getZMinIndex());

//Get the slicer queued up for the first image;
dataAid.slicer.setZIndex(slicer.getZMinIndex());
int startPoint = dataAid.slicingProfile.getDirection() == BuildDirection.Bottom_Up?(slicer.getZMinIndex() + 1 + customizer.getNextSlice()): (slicer.getZMaxIndex() + 1);
int endPoint = dataAid.slicingProfile.getDirection() == BuildDirection.Bottom_Up?(slicer.getZMaxIndex() + 1 - customizer.getNextSlice()): (slicer.getZMinIndex() + 1);
dataAid.slicer.setZIndex(startPoint);
Object nextRenderingPointer = dataAid.cache.getCurrentRenderingPointer();
Future<RenderedData> currentImage = Main.GLOBAL_EXECUTOR.submit(new STLImageRenderer(dataAid, this, nextRenderingPointer, false));

//Everything needs to be setup in the dataByPrintJob before we start the header
performHeader(dataAid);

int startPoint = dataAid.slicingProfile.getDirection() == BuildDirection.Bottom_Up?(slicer.getZMinIndex() + 1): (slicer.getZMaxIndex() + 1);
int endPoint = dataAid.slicingProfile.getDirection() == BuildDirection.Bottom_Up?(slicer.getZMaxIndex() + 1): (slicer.getZMinIndex() + 1);
for (int z = startPoint; z <= endPoint && dataAid.printer.isPrintActive(); z += dataAid.slicingProfile.getDirection().getVector()) {

//Performs all of the duties that are common to most print files
Expand Down Expand Up @@ -137,7 +132,7 @@ public BufferedImage renderPreviewImage(DataAid aid) throws SliceHandlingExcepti
dataAid.printJob.setTotalSlices(dataAid.slicer.getZMaxIndex() - dataAid.slicer.getZMinIndex());

//Get the slicer queued up for the first image;
dataAid.slicer.setZIndex(dataAid.slicer.getZMinIndex());
dataAid.slicer.setZIndex(dataAid.slicer.getZMinIndex() + dataAid.customizer.getNextSlice());
Object nextRenderingPointer = dataAid.cache.getCurrentRenderingPointer();
STLImageRenderer renderer = new STLImageRenderer(dataAid, this, nextRenderingPointer, true);
return renderer.call().getPrintableImage();
Expand Down
Loading

0 comments on commit 6b0f88a

Please sign in to comment.