From: <ha...@us...> - 2012-08-22 22:07:33
|
Revision: 17466 http://jmol.svn.sourceforge.net/jmol/?rev=17466&view=rev Author: hansonr Date: 2012-08-22 22:07:26 +0000 (Wed, 22 Aug 2012) Log Message: ----------- ___version=13.0.2_dev bug fix: pngj storage of Spartan zip files cannot be read. Modified Paths: -------------- trunk/Jmol/src/org/jmol/export/_IdtfExporter.java trunk/Jmol/src/org/jmol/export/_PovrayExporter.java trunk/Jmol/src/org/jmol/export/image/ImageCreator.java trunk/Jmol/src/org/jmol/viewer/FileManager.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/export/_IdtfExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_IdtfExporter.java 2012-08-22 21:56:52 UTC (rev 17465) +++ trunk/Jmol/src/org/jmol/export/_IdtfExporter.java 2012-08-22 22:07:26 UTC (rev 17466) @@ -342,7 +342,7 @@ + "\n\\end{center}" + "\n\\end{document}" +"\n\\begin{comment}" - + viewer.getWrappedState(null, true, false, 0, 0) + + viewer.getWrappedState(null, null, true, false, 0, 0) +"\n\\end{comment}"; } Modified: trunk/Jmol/src/org/jmol/export/_PovrayExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_PovrayExporter.java 2012-08-22 21:56:52 UTC (rev 17465) +++ trunk/Jmol/src/org/jmol/export/_PovrayExporter.java 2012-08-22 22:07:26 UTC (rev 17466) @@ -67,7 +67,7 @@ output("// This script was generated on " + getExportDate() + "\n"); output("// ******************************************************\n"); try { - output((String) viewer.getWrappedState(null, true, false, 0, 0)); + output((String) viewer.getWrappedState(null, null, true, false, 0, 0)); } catch (Exception e) { // tough luck } Modified: trunk/Jmol/src/org/jmol/export/image/ImageCreator.java =================================================================== --- trunk/Jmol/src/org/jmol/export/image/ImageCreator.java 2012-08-22 21:56:52 UTC (rev 17465) +++ trunk/Jmol/src/org/jmol/export/image/ImageCreator.java 2012-08-22 22:07:26 UTC (rev 17466) @@ -183,7 +183,7 @@ boolean includeState = (asBytes && type.equals("PNGJ") || !asBytes && appendText == null); if (type.equals("PNGJ") && includeState) - ret = viewer.getWrappedState(scripts, true, true, image.getWidth(null), image + ret = viewer.getWrappedState(fileName, scripts, true, true, image.getWidth(null), image .getHeight(null)); if (isOsTemp) os = new FileOutputStream(fileName); @@ -194,8 +194,8 @@ bytes = JpegEncoder.getBytes(viewer.getApiPlatform(), image, quality, Viewer.getJmolVersion()); } else { - String caption = (includeState ? (String) viewer.getWrappedState(null, true, false, image - .getWidth(null), image.getHeight(null)) : Viewer.getJmolVersion()); + String caption = (includeState ? (String) viewer.getWrappedState(null, null, true, false, image + .getWidth(null), image.getHeight(null)) : Viewer.getJmolVersion()); JpegEncoder.write(viewer.getApiPlatform(), image, quality, os, caption); } @@ -222,8 +222,8 @@ int nPNG = bytes.length; b = bytes; if (ret == null) - ret = viewer.getWrappedState(scripts, true, false, image.getWidth(null), - image.getHeight(null)); + ret = viewer.getWrappedState(null, scripts, true, false, + image.getWidth(null), image.getHeight(null)); bytes = (ret instanceof byte[] ? (byte[]) ret : ((String) ret) .getBytes()); int nState = bytes.length; Modified: trunk/Jmol/src/org/jmol/viewer/FileManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/FileManager.java 2012-08-22 21:56:52 UTC (rev 17465) +++ trunk/Jmol/src/org/jmol/viewer/FileManager.java 2012-08-22 22:07:26 UTC (rev 17466) @@ -80,6 +80,7 @@ void clear() { fullPathName = fileName = nameAsGiven = viewer.getZapName(); + spardirCache = null; } private void setLoadState(Map<String, Object> htParams) { @@ -530,6 +531,7 @@ String[] subFileList = null; String[] info = (doSpecialLoad ? viewer.getModelAdapter().specialLoad(name, "filesNeeded?") : null); + String name00 = name; if (info != null) { if (isTypeCheckOnly) return info; @@ -554,14 +556,19 @@ StringBuffer sb = new StringBuffer(); if (fileData.get("OUTPUT") != null) sb.append(fileData.get(fileData.get("OUTPUT"))); + String s; for (int i = 2; i < info.length; i++) { name = info[i]; name = getObjectAsSections(name, header, fileData); Logger.info("reading " + name); - String s = fileData.get(name); + s = fileData.get(name); sb.append(s); } - return getBufferedReaderForString(sb.toString()); + s = sb.toString(); + if (spardirCache == null) + spardirCache = new Hashtable<String, byte[]>(); + spardirCache.put(name00.replace('\\','/'), s.getBytes()); + return getBufferedReaderForString(s); } // continuing... // here, for example, for an SPT file load that is not just a type check @@ -1284,13 +1291,15 @@ newName = (name.indexOf("?") > 0 && name.indexOf("|") < 0 ? TextFormat.replaceAllCharacters(name, "/:?\"'=&", "_") : stripPath(name)); newName = TextFormat.replaceAllCharacters(newName, "[]", "_"); - if (isLocal && name.indexOf("|") < 0) { + boolean isSparDir = (spardirCache != null && spardirCache.containsKey(name)); + if (isLocal && name.indexOf("|") < 0 + && !isSparDir) { v.add(name); v.add(newName); v.add(null); // data will be gotten from disk } else { // all remote files, and any file that was opened from a ZIP collection - Object ret = getFileAsBytes(name, null); + Object ret = (isSparDir ? spardirCache.get(name) : getFileAsBytes(name, null)); if (!(ret instanceof byte[])) return ret; CRC32 crc = new CRC32(); @@ -1301,6 +1310,8 @@ // let newName point to the already added data newName = crcMap.get(crcValue); }else{ + if (isSparDir) + newName = newName.replace('.', '_'); if (crcMap.containsKey(newName)) { // now we have a conflict. To different files with the same name // append "[iFile]" to the new file name to ensure it's unique @@ -1919,11 +1930,14 @@ } private Map<String, byte[]> pngjCache; + private Map<String, byte[]> spardirCache; - void clearPngjCache() { - pngjCache = null; + void clearPngjCache(String fileName) { + if (fileName == null || pngjCache != null && pngjCache.containsKey(getCanonicalName(getZipRoot(fileName)))) + pngjCache = null; } - + + private byte[] getCachedPngjBytes(String pathName) { if (pathName.indexOf(".png") < 0) return null; Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2012-08-22 21:56:52 UTC (rev 17465) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2012-08-22 22:07:26 UTC (rev 17466) @@ -3417,13 +3417,18 @@ return modelSet.getAllPolymerInfo(getAtomBitSet(atomExpression)); } - public Object getWrappedState(String[] scripts, boolean isImage, boolean asJmolZip, int width, - int height) { + public Object getWrappedState(String fileName, String[] scripts, boolean isImage, boolean asJmolZip, + int width, int height) { if (isImage && !global.imageState && !asJmolZip || !global.preserveState) return ""; String s = getStateInfo(null, width, height); - if (asJmolZip) + if (asJmolZip) { + if (fileName != null) + fileManager.clearPngjCache(fileName); + // when writing a file, we need to make sure + // the pngj cache for that file is cleared return fileManager.createZipSet(null, s, scripts, true); + } // we remove local file references in the embedded states for images try { s = JmolConstants.embedScript(FileManager.setScriptFileReferences(s, ".", @@ -10509,7 +10514,7 @@ public void cacheClear() { statusManager.cacheClear(); - fileManager.clearPngjCache(); + fileManager.clearPngjCache(null); } public void setCurrentModelID(String id) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |