Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #795 #798

Merged
merged 4 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ public static List<FileNameExtensionFilter> getSaveExtensions() {
public static void save(Turtle turtle,String filename, PlotterSettings settings) throws Exception {
if(filename == null || filename.trim().isEmpty()) throw new InvalidParameterException("filename cannot be empty");

String extension = filename.substring(filename.lastIndexOf("."));
if(extension.isEmpty()) throw new InvalidParameterException("filename must have an extension");

for (TurtleSaver saver : savers) {
if(isValidExtension(filename,saver.getFileNameFilter())) {
try (FileOutputStream out = new FileOutputStream(filename)) {
saver.save(out, turtle,settings);
return;
}
return;
}
}
String extension = filename.substring(filename.lastIndexOf("."));

throw new Exception("TurtleFactory could not save '"+filename+"' : invalid file format '" + extension + "'");
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package com.marginallyclever.makelangelo.donatelloimpl;

import com.marginallyclever.makelangelo.donatelloimpl.nodes.turtle.LoadTurtle;
import com.marginallyclever.makelangelo.donatelloimpl.nodes.turtle.SaveTurtle;
import com.marginallyclever.makelangelo.donatelloimpl.nodes.turtle.TurtleDAO4JSON;
import com.marginallyclever.makelangelo.turtle.Turtle;
import com.marginallyclever.nodegraphcore.Connection;
import com.marginallyclever.nodegraphcore.DAO4JSONFactory;
import com.marginallyclever.nodegraphcore.port.*;
import com.marginallyclever.nodegraphcore.Graph;
import com.marginallyclever.nodegraphcore.NodeFactory;
import com.marginallyclever.nodegraphcore.port.Input;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

import static org.junit.jupiter.api.Assertions.*;

/**
Expand All @@ -22,7 +28,7 @@
public class TestNodeGraphMakelangelo {
private static final Logger logger = LoggerFactory.getLogger(TestNodeGraphMakelangelo.class);

private static Graph model = new Graph();
private static final Graph model = new Graph();

@BeforeAll
public static void beforeAll() throws Exception {
Expand Down Expand Up @@ -81,4 +87,38 @@ public void testTurtleDAO() {
Turtle r2=dao.fromJSON(dao.toJSON(r1));
assertEquals(r1,r2);
}

/**
* Create a donatello panel;
* connect a LoadTurtle node and a SaveTurtle node;
* load a test file;
* save the test file;
* confirm the test file was saved.
*/
@Test
public void testLoadAndSaveTurtle() throws IOException {
Graph graph = new Graph();

// Create and connect LoadTurtle and SaveTurtle nodes
LoadTurtle loadNode = new LoadTurtle();
SaveTurtle saveNode = new SaveTurtle();
graph.add(loadNode);
graph.add(saveNode);
graph.add(new Connection(loadNode,1, saveNode,1));

// get a filename for a non-existent temporary file
File tempFile = File.createTempFile("testTurtle", ".dxf");
tempFile.deleteOnExit();
String tempFilename = tempFile.getAbsolutePath();

// Load a test file
loadNode.getPort("filename").setValue("src/test/resources/dxf/circle.dxf");
saveNode.getPort("filename").setValue(tempFilename);
loadNode.update();
saveNode.update();

// confirm the file saved.
assertTrue(tempFile.exists());
assert(tempFile.length()>0);
}
}