Skip to content

Commit

Permalink
Added the ability to add more gui skins
Browse files Browse the repository at this point in the history
Added the ability to correct images by the printer's aspect ratio
Fixed NPE
Added ability to restart Photonic3D from the Rest API so that new
settings can take place
Allow the ability to get skins from the Rest API
  • Loading branch information
WesGilster committed Aug 5, 2017
1 parent cd68bef commit e39aadd
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 81 deletions.
12 changes: 7 additions & 5 deletions host/conf/config.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
fakeserial=true
removeJobOnCompletion=false
printerHostPort=9091
#hostGUI=resources
#hostGUI=gui-prototypes/material-resin/app
#hostGUI=../../CWH-Reify3D/Customer/resources
hostGUI=resourcesnew
visibleCards=printers,printJobs,printables,settings
performedOneTimeInstall=false
limitLiveStreamToOneCPU=false
scriptEngineLanguage=js
forceCalibrationOnFirstUse=false

#hostGUI is no longer used, the "skins" key should be used instead
#hostGUI=resources
#hostGUI=gui-prototypes/material-resin/app
#hostGUI=../../CWH-Reify3D/Customer/resources
skins=[{"name":"Main skin", "welcomeFiles":["index.html"], "resourceBase": "resourcesnew", "active": true}]

feature.org.area515.resinprinter.discover.UPNPAdvertiser=true
feature.org.area515.resinprinter.usbimport.USBUploader=true
#feature.org.area515.resinprinter.util.cron.CronFeature=true
Expand Down Expand Up @@ -101,7 +103,7 @@ userKeystorePassword=usersKeystorePassword

#The following is an optional parameter.
#You only need to specify this parameter if you have a certificate signed by a CA.
#This certificate must be imported into into the keystore specified in the keystoreFilename above.
#This certificate must be imported into into the keystore specified in the "keystoreFilename" key in this property file.
#The certificate must be imported into the keystore using the alias specified below.
#This MUST also be the hostname that the certificate was issued to.
#*****************************************
Expand Down
24 changes: 24 additions & 0 deletions host/resourcesnew/cwh/js/printables.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,30 @@
"currentTransform";
}

this.correctAspectRatio = function correctAspectRatio() {
controller.currentCustomizer.affineTransformSettings.affineTransformScriptCalculator =
"var currentTransform = new java.awt.geom.AffineTransform();\n" +
"var scaleXDimension = false;\n" +
"var ppmmx = pixelsPerMMX;\n" +
"var ppmmy = pixelsPerMMY;\n" +
"function reduce(numerator,denominator){\n" +
" var gcd = function gcd(a,b){\n" +
" return b ? gcd(b, a%b) : a;\n" +
" };\n" +
" gcd = gcd(numerator,denominator);\n" +
" return [numerator/gcd, denominator/gcd];\n" +
"}\n" +
"var reduced = reduce(ppmmx, ppmmy);" +
"ppmmx = reduced[0];\n" +
"ppmmy = reduced[1];\n" +
"if (scaleXDimension) {\n" +
" currentTransform.scale(ppmmx / ppmmy, 1);\n" +
"} else {\n" +
" currentTransform.scale(1, ppmmy / ppmmx);\n" +
"}\n" +
"currentTransform";
}

this.getPrintableIconClass = function getPrintableIconClass(printable) {
return photonicUtils.getPrintFileProcessorIconClass(printable);
};
Expand Down
3 changes: 3 additions & 0 deletions host/resourcesnew/cwh/js/printers.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@
}

this.gotoPrinterControls = function gotoPrinterControls() {
if (controller.currentPrinter == null) {
return;
}
$location.path('/printerControlsPage').search({printerName: controller.currentPrinter.configuration.name})
};

Expand Down
12 changes: 8 additions & 4 deletions host/resourcesnew/printables.html
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,15 @@ <h4>Duplication grid</h4>
</div>

<div class="list-group-item">
<i class="fa fa-2x fa-retweet pull-left"></i>
<h4>3D spiral</h4>
<i class="fa fa-2x fa-puzzle-piece pull-left"></i>
<h4>Misc</h4>
<button class="btn btn-primary btn-sm" ng-click="printablesController.write3dTwistCode()">
<b class="fa fa-thumbs-o-up"></b>
<span>Create</span>
<b class="fa fa-retweet"></b>
<span>3d Spiral</span>
</button>
<button class="btn btn-primary btn-sm" ng-click="printablesController.correctAspectRatio()">
<b class="fa fa-chain"></b>
<span>Correct Aspect Ratio</span>
</button>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.area515.resinprinter.plugin.Feature;
import org.area515.resinprinter.server.HostInformation;
import org.area515.resinprinter.server.HostProperties;
import org.fourthline.cling.DefaultUpnpServiceConfiguration;
import org.fourthline.cling.UpnpServiceImpl;
import org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder;
import org.fourthline.cling.controlpoint.ControlPoint;
Expand Down Expand Up @@ -90,7 +89,7 @@ public void start(URI webPresentationURI, String settings) {
null);

List<Icon> icons = new ArrayList<Icon>();
File iconFiles[] = new File(HostProperties.Instance().getHostGUIDir(), "favicon").listFiles(new FilenameFilter() {
File iconFiles[] = new File(HostProperties.Instance().getFirstActiveSkin().getResourceBase(), "favicon").listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
name = name.toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void setCacheId(String cacheId) {
}

public String toString() {
return getCacheId();
return name + " " + getCacheId();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public static boolean isCertificateAndPrivateKeyAvailable(File keyFile, String p
}
}

public static void secureContext(String ipAddress, ServletContextHandler context, Server jettyServer) throws Exception {
public static void secureContext(String ipAddress, ServletContextHandler context, Server jettyServer) throws InvalidNameException, IOException, GeneralSecurityException {
if (HostProperties.Instance().getExternallyAccessableName() != null) {
ipAddress = HostProperties.Instance().getExternallyAccessableName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public class HostProperties {
private static HostProperties INSTANCE = null;
private File uploadDir;
private File printDir;
private String hostGUI;
private boolean fakeSerial = false;
private boolean removeJobOnCompletion = true;
private boolean forceCalibrationOnFirstUse = false;
Expand All @@ -91,10 +90,10 @@ public class HostProperties {
private Class<SerialCommunicationsPort> serialPortClass;
private Class<NetworkManager> networkManagerClass;

private int versionNumber;
private String releaseTagName;
private List<String> visibleCards;
private String hexCodeBasedProjectorsJson;
private String skinsStringJson;
private String forwardHeader;
private CountDownLatch hostReady = new CountDownLatch(1);
private String scriptEngineLanguage = null;
Expand Down Expand Up @@ -193,8 +192,8 @@ private HostProperties() {
uploadDirString = configurationProperties.getProperty("uploaddir");

fakeSerial = new Boolean(configurationProperties.getProperty("fakeserial", "false"));
hostGUI = configurationProperties.getProperty("hostGUI", "resources");
visibleCards = Arrays.asList(configurationProperties.getProperty("visibleCards", "printers,printJobs,printables,users,settings").split(","));
skinsStringJson = configurationProperties.getProperty("skins", "[{\"name\":\"Main skin\", \"welcomeFiles\":[\"index.htm\"], \"resourceBase\": \"resourcesnew\", \"active\": true}]");

//This loads features
for (Entry<Object, Object> currentProperty : configurationProperties.entrySet()) {
Expand Down Expand Up @@ -334,7 +333,7 @@ private HostProperties() {
Properties newProperties = new Properties();
try {
newProperties.load(new FileInputStream(versionFile));
versionNumber = Integer.valueOf((String)newProperties.get("build.number")) - 1;
//versionNumber = Integer.valueOf((String)newProperties.get("build.number")) - 1;
releaseTagName = (String)newProperties.get("repo.version");
} catch (IOException e) {
logger.error("Version file is missing:{}", versionFile);
Expand All @@ -360,6 +359,16 @@ private HostProperties() {
this.sharedScriptEngine = this.buildScriptEngine();
}

public Skin getFirstActiveSkin() {
for (Skin skin : getSkins()) {
if (skin.isActive()) {
return skin;
}
}

return null;
}

private Properties getClasspathProperties() {
InputStream stream = HostProperties.class.getClassLoader().getResourceAsStream("config.properties");
if (stream == null) {
Expand Down Expand Up @@ -469,10 +478,6 @@ public String getPrinterProfileRepo() {
public int getPrinterHostPort() {
return printerHostPort;
}

public String getHostGUIDir() {
return hostGUI;
}

public File getUploadDir(){
return uploadDir;
Expand Down Expand Up @@ -671,6 +676,18 @@ public List<ProjectorModel> getAutodetectProjectors() {
}
}

public List<Skin> getSkins() {
ObjectMapper mapper = new ObjectMapper(new JsonFactory());
List<Skin> projectors;
try {
projectors = mapper.readValue(skinsStringJson, new TypeReference<List<Skin>>(){});
return projectors;
} catch (IOException e) {
logger.error("Problem loading skins json.", e);
return new ArrayList<Skin>();
}
}

public <T extends Named> List<T> getConfigurations(File searchDirectory, String extension, Class<T> clazz) {
List<T> configurations = new ArrayList<T>();

Expand Down
Loading

0 comments on commit e39aadd

Please sign in to comment.