mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Detect when a file is created with a newer version of DIYLC and show a
warning Force correct prefix for transistors in spice
This commit is contained in:
@@ -300,8 +300,9 @@ public class Presenter implements IPlugInPort {
|
|||||||
@Override
|
@Override
|
||||||
public void loadProjectFromFile(String fileName) {
|
public void loadProjectFromFile(String fileName) {
|
||||||
LOG.info(String.format("loadProjectFromFile(%s)", fileName));
|
LOG.info(String.format("loadProjectFromFile(%s)", fileName));
|
||||||
|
List<String> warnings = null;
|
||||||
try {
|
try {
|
||||||
List<String> warnings = new ArrayList<String>();
|
warnings = new ArrayList<String>();
|
||||||
Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName, warnings);
|
Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName, warnings);
|
||||||
loadProject(project, true);
|
loadProject(project, true);
|
||||||
projectFileManager.fireFileStatusChanged();
|
projectFileManager.fireFileStatusChanged();
|
||||||
@@ -317,7 +318,15 @@ public class Presenter implements IPlugInPort {
|
|||||||
addToRecentFiles(fileName);
|
addToRecentFiles(fileName);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("Could not load file", ex);
|
LOG.error("Could not load file", ex);
|
||||||
view.showMessage("Could not open file " + fileName + ". Check the log for details.", "Error", IView.ERROR_MESSAGE);
|
String errorMessage = "Could not open file " + fileName + ". Check the log for details.";
|
||||||
|
if (warnings != null && !warnings.isEmpty()) {
|
||||||
|
errorMessage += " Possible reasons are:\n\n";
|
||||||
|
for (String warn : warnings) {
|
||||||
|
errorMessage += warn;
|
||||||
|
errorMessage += "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
view.showMessage(errorMessage, "Error", IView.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,10 +44,13 @@ import javax.xml.parsers.ParserConfigurationException;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.diylc.appframework.miscutils.Utils;
|
import org.diylc.appframework.miscutils.Utils;
|
||||||
import org.diylc.appframework.simplemq.MessageDispatcher;
|
import org.diylc.appframework.simplemq.MessageDispatcher;
|
||||||
|
import org.diylc.appframework.update.VersionNumber;
|
||||||
import org.diylc.common.EventType;
|
import org.diylc.common.EventType;
|
||||||
import org.diylc.core.Project;
|
import org.diylc.core.Project;
|
||||||
import org.diylc.parsing.IOldFileParser;
|
import org.diylc.parsing.IOldFileParser;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
@@ -209,7 +212,15 @@ public class ProjectFileManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Project parseV3File(String fileName, List<String> warnings) throws IOException {
|
private Project parseV3File(String fileName, List<String> warnings) throws IOException {
|
||||||
Project project;
|
Project project;
|
||||||
|
VersionNumber fileVersion;
|
||||||
|
try {
|
||||||
|
fileVersion = readV3Version(fileName);
|
||||||
|
if (fileVersion.compareTo(Presenter.CURRENT_VERSION) > 0)
|
||||||
|
warnings.add("The file is created with a newer version of DIYLC and may contain features that are not supported by your version of DIYLC. Please update.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
warnings.add("Could not read file version number, the file may be corrupted.");
|
||||||
|
}
|
||||||
FileInputStream fis = new FileInputStream(fileName);
|
FileInputStream fis = new FileInputStream(fileName);
|
||||||
missingFields.clear();
|
missingFields.clear();
|
||||||
try {
|
try {
|
||||||
@@ -226,5 +237,32 @@ public class ProjectFileManager {
|
|||||||
}
|
}
|
||||||
fis.close();
|
fis.close();
|
||||||
return project;
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
private VersionNumber readV3Version(String fileName) throws Exception {
|
||||||
|
File fXmlFile = new File(fileName);
|
||||||
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||||
|
Document doc = dBuilder.parse(fXmlFile);
|
||||||
|
|
||||||
|
doc.getDocumentElement().normalize();
|
||||||
|
|
||||||
|
NodeList nList = doc.getElementsByTagName("fileVersion");
|
||||||
|
|
||||||
|
int items = nList.getLength();
|
||||||
|
|
||||||
|
if (items != 1)
|
||||||
|
throw new Exception("File version information could not be read from the XML.");
|
||||||
|
|
||||||
|
Node versionNode = nList.item(0);
|
||||||
|
Node n = versionNode.getFirstChild().getNextSibling();
|
||||||
|
int major = Integer.parseInt(n.getFirstChild().getNodeValue());
|
||||||
|
n = n.getNextSibling().getNextSibling();
|
||||||
|
int minor = Integer.parseInt(n.getFirstChild().getNodeValue());
|
||||||
|
n = n.getNextSibling().getNextSibling();
|
||||||
|
int build = Integer.parseInt(n.getFirstChild().getNodeValue());
|
||||||
|
|
||||||
|
return new VersionNumber(major, minor, build);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
+8
-1
@@ -89,7 +89,14 @@ public abstract class AbstractTransistorPackage extends AbstractTransparentCompo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getComment() {
|
public String getComment() {
|
||||||
return getPinout() == null ? null : (getPinout().toString() + " pinout");
|
return getPinout() == null ? "Pinout not configured, validate this line" : (getPinout().toString() + " pinout");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrefix() {
|
||||||
|
if (getPinout() == null)
|
||||||
|
return null;
|
||||||
|
return getPinout().name().substring(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty
|
@EditableProperty
|
||||||
|
|||||||
@@ -31,4 +31,6 @@ public interface ISpiceMapper {
|
|||||||
int mapToSpiceNode(int pontIndex);
|
int mapToSpiceNode(int pontIndex);
|
||||||
|
|
||||||
String getComment();
|
String getComment();
|
||||||
|
|
||||||
|
String getPrefix();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,8 +80,16 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
|
|||||||
maxLen = c.getName().length();
|
maxLen = c.getName().length();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (IDIYComponent<?> c : allComponents) {
|
for (IDIYComponent<?> c : allComponents) {
|
||||||
sb.append(fill(c.getName(), (int) (Math.ceil(maxLen / 5.0) * 5)));
|
// change the prefix to match spice convention if needed
|
||||||
|
String name = c.getName();
|
||||||
|
String prefix = null;
|
||||||
|
if (c instanceof ISpiceMapper)
|
||||||
|
prefix = ((ISpiceMapper)c).getPrefix();
|
||||||
|
if (prefix != null && !name.toLowerCase().startsWith(prefix.toLowerCase()))
|
||||||
|
name = prefix + name;
|
||||||
|
|
||||||
|
sb.append(fill(name, (int) (Math.ceil(maxLen / 5.0) * 5)));
|
||||||
sb.append(" ");
|
sb.append(" ");
|
||||||
int[] nodeIndices = new int[c.getControlPointCount()];
|
int[] nodeIndices = new int[c.getControlPointCount()];
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -2598,6 +2598,10 @@
|
|||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Cleaner and more compact XML format for .DIY files resulting in files about half the size of originals. Backward compatible with older files, but might introduce issues when opening files from the new version using an old version!</description>
|
<description>Cleaner and more compact XML format for .DIY files resulting in files about half the size of originals. Backward compatible with older files, but might introduce issues when opening files from the new version using an old version!</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Detect when a file is created with a newer version of DIYLC and show a warning</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>BUG_FIX</changeType>
|
<changeType>BUG_FIX</changeType>
|
||||||
<description>"Highlight Connected Areas" doesn't follow multiple chained wires and jumpers</description>
|
<description>"Highlight Connected Areas" doesn't follow multiple chained wires and jumpers</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user