import jalview.structure.StructureCommandsI;
import jalview.structure.StructureImportSettings.TFType;
import jalview.structure.StructureSelectionManager;
+import jalview.util.ColorUtils;
import jalview.util.FileUtils;
import jalview.util.HttpUtils;
import jalview.util.ImageMaker;
BitmapImageSizing userBis = ImageMaker
.parseScaleWidthHeightStrings(scale, width, height);
+ /////
+ // DON'T TRY TO EXPORT IF VIEWER IS UNSUPPORTED
+ if (viewerType!=ViewerType.JMOL) {
+ addWarn("Cannot export image for structure viewer "
+ + viewerType.name() + " yet");
+ continue;
+ }
+
+ /////
+ // Apply the temporary colourscheme to the linked alignment
+ // TODO: enhance for multiple linked alignments.
+
String imageColour = avm.getValueFromSubValOrArg(
structureImageArgValue, Arg.IMAGECOLOUR,
structureImageSubVals);
.getColourScheme(af);
this.colourAlignFrame(af, imageColour);
- List<StructureCommandI> 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;
- }
+ /////
+ // custom image background colour
String bgcolourstring = avm.getValueFromSubValOrArg(
structureImageArgValue, Arg.BGCOLOUR,
{
try
{
+ //
+ // FIXME: Why not use ColorUtils.parseColourString(bgcolourstring) - this is consistent and backwards compatible
+ //
if (bgcolourstring.charAt(0) == '#')
{
bgcolour = Color.decode(bgcolourstring);
{
Console.warn(
"Background colour string '" + bgcolourstring
- + "' not recognised -- using black.");
- bgcolour = Color.black;
+ + "' not recognised -- using default");
+ //bgcolour = Color.black;
}
- extraCommands.add(sc.setBackgroundColour(bgcolour));
}
- // TODO MAKE THIS VIEWER INDEPENDENT!!
- switch (viewerType)
+ JalviewStructureDisplayI sview = structureViewer
+ .getJalviewStructureDisplay();
+
+ File sessionToRestore = null;
+
+ List<StructureCommandI> extraCommands=new ArrayList<>();
+
+ if (extraCommands.size() > 0 || bgcolour!=null)
{
- case JMOL:
- JalviewStructureDisplayI sview = structureViewer
- .getJalviewStructureDisplay();
- JmolCommands jc = (JmolCommands) sc;
- if (sview instanceof AppJmol)
+ try {
+ sessionToRestore = sview.saveSession();
+ } catch (Throwable t)
{
- 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,
- subVals, false, structureImageFilename,
- "structure image", isError);
- if (!success)
- {
- continue;
- }
-
- Console.debug(
- "Rendering image to " + structureImageFile);
- jmol.makePDBImage(structureImageFile, imageType,
+ Console.warn("Unable to save temporary session file before custom structure view export operation.");
+ }
+ }
+
+ ////
+ // Do temporary ops
+
+ sview.getBinding().setBackgroundColour(bgcolour);
+
+ sview.getBinding().executeCommands(extraCommands, false, "Executing Custom Commands");
+
+ // and export the view as an image
+ boolean success = this.checksBeforeWritingToFile(avm,
+ subVals, false, structureImageFilename,
+ "structure image", isError);
+
+ if (!success)
+ {
+ continue;
+ }
+ Console.debug(
+ "Rendering image to " + structureImageFile);
+ //
+ // TODO - extend StructureViewer / Binding with makePDBImage so we can do this with every viewer
+ //
+
+ try {
+ // We don't expect class cast exception
+ AppJmol jmol = (AppJmol) sview;
+ jmol.makePDBImage(structureImageFile, imageType,
renderer, userBis);
- Console.debug("Finished Rendering image to "
- + structureImageFile);
-
- } catch (ImageOutputException ioexc)
- {
- addError("Unexpected error whilst exporting image to "
- + structureImageFile, ioexc);
- isError = true;
- continue;
- } finally
- {
- jmb.executeCommand(jc.restoreState(state), false);
- }
-
+ Console.debug("Finished Rendering image to "
+ + structureImageFile);
+
+ // RESTORE SESSION AFTER EXPORT IF NEED BE
+ if (sessionToRestore != null)
+ {
+ sview.getBinding().openSession(sessionToRestore.getCanonicalPath());
}
- break;
- default:
- // this shouldn't happen!
- addWarn("Cannot export image for structure viewer "
- + viewerType.name() + " yet");
+ } catch (ImageOutputException ioexc)
+ {
+ addError("Unexpected error whilst exporting image to "
+ + structureImageFile, ioexc);
+ isError = true;
+ continue;
+ }
+ catch (IOException ioexec)
+ {
+ addError("Unexpected error when restoring structure viewer session after custom view operations.");
+ isError = true;
continue;
}
- this.colourAlignFrame(af, originalColourScheme);
+ finally
+ {
+ this.colourAlignFrame(af, originalColourScheme);
+ }
}
}
}