From 14488926488f05f802480c508da1cc4ed53c5b1a Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Sat, 16 Sep 2023 13:28:53 +0100 Subject: [PATCH] JAL-4265 Added --bgcolour for --structureimage output. Saves and restores Jmol state before and after colour changes and export. Added 'set antialiasdisplay on' by default for all Jmol viewers. --- src/jalview/bin/Commands.java | 16 +++++++++++++++- src/jalview/bin/argparser/Arg.java | 3 +++ src/jalview/gui/AppJmol.java | 24 +++++++++++++++++++++--- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index 3173b35..0565111 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -678,6 +678,20 @@ public class Commands .getColourScheme(af); this.colourAlignFrame(af, imageColour); + List extraCommands = new ArrayList<>(); + + String bgcolour = avm.getValueFromSubValOrArg( + structureImageArgValue, Arg.BGCOLOUR, + structureImageSubVals); + if (bgcolour != null && bgcolour.length() > 0) + { + if (bgcolour.charAt(0) == '#') + { + bgcolour = "[x" + bgcolour.substring(1) + "]"; + } + extraCommands.add("background " + bgcolour); + } + // TODO MAKE THIS VIEWER INDEPENDENT!! switch (StructureViewer.getViewerType()) { @@ -700,7 +714,7 @@ public class Commands Console.debug( "Rendering image to " + structureImageFile); jmol.makePDBImage(structureImageFile, imageType, - renderer, userBis); + renderer, userBis, extraCommands); Console.debug("Finished Rendering image to " + structureImageFile); diff --git a/src/jalview/bin/argparser/Arg.java b/src/jalview/bin/argparser/Arg.java index 51a2d16..9bb5f38 100644 --- a/src/jalview/bin/argparser/Arg.java +++ b/src/jalview/bin/argparser/Arg.java @@ -188,6 +188,9 @@ public enum Arg + " (or none) will apply. Valid values are the same as " + Arg.COLOUR.argString() + ".", Opt.STRING, Opt.LINKED, Opt.MULTIVALUE, Opt.ALLOWMULTIID), + BGCOLOUR(Type.IMAGE, "bgcolor", // being a bit soft on the Americans! + "Applies a background colour to the structure image. Valid values are named colours or #RRGGBB.", + Opt.STRING, Opt.LINKED, Opt.MULTIVALUE, Opt.ALLOWMULTIID), /* STRUCTUREIMAGETYPE(Type.IMAGE, "Set the structure image format for the preceding --structureimage. Valid values are:\n" diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index cfbac04..5b935b7 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -264,6 +264,8 @@ public class AppJmol extends StructureViewerBase } jmb.executeCommand(new StructureCommand(command), false); jmb.executeCommand(new StructureCommand("set hoverDelay=0.1"), false); + jmb.executeCommand(new StructureCommand("set antialiasdisplay on"), + false); jmb.setFinishedInit(true); } @@ -432,7 +434,7 @@ public class AppJmol extends StructureViewerBase try { makePDBImage(null, type, null, - BitmapImageSizing.defaultBitmapImageSizing()); + BitmapImageSizing.defaultBitmapImageSizing(), null); } catch (ImageOutputException ioex) { Console.error("Unexpected error whilst writing " + type.toString(), @@ -441,7 +443,8 @@ public class AppJmol extends StructureViewerBase } public void makePDBImage(File file, ImageMaker.TYPE type, String renderer, - BitmapImageSizing userBis) throws ImageOutputException + BitmapImageSizing userBis, List extraCommands) + throws ImageOutputException { int width = getWidth(); int height = getHeight(); @@ -470,9 +473,24 @@ public class AppJmol extends StructureViewerBase } } - jmb.jmolViewer.antialiased = true; + String saveStateNameTemp = "JalviewSaveStateTemp"; + jmb.executeCommand( + new StructureCommand("save STATE " + saveStateNameTemp), + false); + + if (extraCommands != null) + { + for (String cmd : extraCommands) + { + jmb.executeCommand(new StructureCommand(cmd), false); + } + } + jmb.jmolViewer.requestRepaintAndWait("image export"); jmb.jmolViewer.renderScreenImage(ig2, usewidth, useheight); + jmb.executeCommand( + new StructureCommand("restore STATE " + saveStateNameTemp), + false); } }; String view = MessageManager.getString("action.view") -- 1.7.10.2