X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FCommands.java;fp=src%2Fjalview%2Fbin%2FCommands.java;h=592ac85cc6679990cb785b0dead5c16e5417330d;hb=82fb94d50a9add200efe5e89214051ce59b42f6c;hp=737c9eb94a9903d46e8f65c4713de5d56b166f67;hpb=d79e3747b8ce78b1ac7aa83402e31b7e5dccfe1b;p=jalview.git diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index 737c9eb..592ac85 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -1,7 +1,9 @@ package jalview.bin; +import java.awt.Color; import java.io.File; import java.io.IOException; +import java.lang.reflect.Field; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; @@ -23,6 +25,8 @@ import jalview.bin.argparser.SubVals; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; import jalview.datamodel.annotations.AlphaFoldAnnotationRowBuilder; +import jalview.ext.jmol.JalviewJmolBinding; +import jalview.ext.jmol.JmolCommands; import jalview.gui.AlignFrame; import jalview.gui.AlignmentPanel; import jalview.gui.AppJmol; @@ -46,6 +50,8 @@ import jalview.io.NewickFile; import jalview.io.exceptions.ImageOutputException; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; +import jalview.structure.StructureCommandI; +import jalview.structure.StructureCommandsI; import jalview.structure.StructureImportSettings.TFType; import jalview.structure.StructureSelectionManager; import jalview.util.FileUtils; @@ -438,6 +444,7 @@ public class Commands commandArgsProvided = true; for (ArgValue av : avm.getArgValueList(Arg.STRUCTURE)) { + argParser.setStructureFilename(null); String val = av.getValue(); SubVals subVals = av.getSubVals(); int argIndex = av.getArgIndex(); @@ -679,33 +686,67 @@ public class Commands .getColourScheme(af); this.colourAlignFrame(af, imageColour); - List extraCommands = new ArrayList<>(); - // these don't actually do anything to the output image since we - // renderScreenImage - // extraCommands.add("set antialiasImages on"); - // extraCommands.add("set antialiasTranslucent on"); + List extraCommands = new ArrayList<>(); + StructureCommandsI sc; + switch (viewerType) + { + case JMOL: + sc = new JmolCommands(); + break; + default: + addWarn("Cannot export image for structure viewer " + + viewerType.name() + " yet"); + continue; + } - String bgcolour = avm.getValueFromSubValOrArg( + String bgcolourstring = avm.getValueFromSubValOrArg( structureImageArgValue, Arg.BGCOLOUR, structureImageSubVals); - if (bgcolour != null && bgcolour.length() > 0) + Color bgcolour = null; + if (bgcolourstring != null && bgcolourstring.length() > 0) { - if (bgcolour.charAt(0) == '#') + try { - bgcolour = "[x" + bgcolour.substring(1) + "]"; + if (bgcolourstring.charAt(0) == '#') + { + bgcolour = Color.decode(bgcolourstring); + } + else + { + Field field = Color.class.getField(bgcolourstring); + bgcolour = (Color) field.get(null); + } + } catch (IllegalArgumentException | NoSuchFieldException + | SecurityException | IllegalAccessException nfe) + { + Console.warn( + "Background colour string '" + bgcolourstring + + "' not recognised -- using black."); + bgcolour = Color.black; } - extraCommands.add("background " + bgcolour); + extraCommands.add(sc.setBackgroundColour(bgcolour)); } // TODO MAKE THIS VIEWER INDEPENDENT!! - switch (StructureViewer.getViewerType()) + switch (viewerType) { case JMOL: JalviewStructureDisplayI sview = structureViewer .getJalviewStructureDisplay(); + JmolCommands jc = (JmolCommands) sc; if (sview instanceof AppJmol) { AppJmol jmol = (AppJmol) sview; + JalviewJmolBinding jmb = (JalviewJmolBinding) jmol + .getBinding(); + String state = new StringBuilder() + .append("JalviewCommandsStructureState_") + .append(viewerType.name()).toString(); + jmb.executeCommand(jc.saveState(state), false); + for (StructureCommandI scmd : extraCommands) + { + jmb.executeCommand(scmd, false); + } try { boolean success = this.checksBeforeWritingToFile(avm, @@ -719,7 +760,7 @@ public class Commands Console.debug( "Rendering image to " + structureImageFile); jmol.makePDBImage(structureImageFile, imageType, - renderer, userBis, extraCommands); + renderer, userBis); Console.debug("Finished Rendering image to " + structureImageFile); @@ -729,19 +770,24 @@ public class Commands + structureImageFile, ioexc); isError = true; continue; + } finally + { + jmb.executeCommand(jc.restoreState(state), false); } } break; default: + // this shouldn't happen! addWarn("Cannot export image for structure viewer " - + structureViewer.getViewerType() + " yet"); + + viewerType.name() + " yet"); continue; } this.colourAlignFrame(af, originalColourScheme); } } } + argParser.setStructureFilename(null); } } }