JAL-4265 Added --bgcolour for --structureimage output. Saves and restores Jmol state...
authorBen Soares <b.soares@dundee.ac.uk>
Sat, 16 Sep 2023 12:28:53 +0000 (13:28 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Sat, 16 Sep 2023 12:28:53 +0000 (13:28 +0100)
src/jalview/bin/Commands.java
src/jalview/bin/argparser/Arg.java
src/jalview/gui/AppJmol.java

index 3173b35..0565111 100644 (file)
@@ -678,6 +678,20 @@ public class Commands
                         .getColourScheme(af);
                 this.colourAlignFrame(af, imageColour);
 
+                List<String> 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);
 
index 51a2d16..9bb5f38 100644 (file)
@@ -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"
index cfbac04..5b935b7 100644 (file)
@@ -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<String> 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")