use of com.willwinder.ugs.nbp.designer.io.svg.SvgReader in project Universal-G-Code-Sender by winder.
the class DesignerMain method loadExample.
private void loadExample(Controller controller) {
SvgReader svgReader = new SvgReader();
svgReader.read(DesignerMain.class.getResourceAsStream("/com/willwinder/ugs/nbp/designer/platform/example.svg")).ifPresent(design -> design.getEntities().forEach(controller.getDrawing()::insertEntity));
}
use of com.willwinder.ugs.nbp.designer.io.svg.SvgReader in project Universal-G-Code-Sender by winder.
the class OpenAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
UndoManager undoManager = CentralLookup.getDefault().lookup(UndoManager.class);
undoManager.clear();
SelectionManager selectionManager = CentralLookup.getDefault().lookup(SelectionManager.class);
selectionManager.clearSelection();
Controller controller = CentralLookup.getDefault().lookup(Controller.class);
fileChooser.showOpenDialog(null);
ThreadHelper.invokeLater(() -> {
DesignReader designReader = new UgsDesignReader();
if (fileChooser.getFileFilter() == SVG_FILE_FILTER) {
designReader = new SvgReader();
} else if (fileChooser.getFileFilter() == C2D_FILE_FILTER) {
designReader = new C2dReader();
}
File selectedFile = fileChooser.getSelectedFile();
Optional<Design> optional = designReader.read(selectedFile);
if (optional.isPresent()) {
controller.setDesign(optional.get());
} else {
throw new RuntimeException("Could not open svg: " + selectedFile.getName());
}
});
}
use of com.willwinder.ugs.nbp.designer.io.svg.SvgReader in project Universal-G-Code-Sender by winder.
the class ToolImportAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileDialog = new JFileChooser();
fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileDialog.addChoosableFileFilter(new FileNameExtensionFilter("Scalable Vector Graphics (.svg)", "svg"));
fileDialog.addChoosableFileFilter(new FileNameExtensionFilter("Autodesk CAD (.dxf)", "dxf"));
fileDialog.addChoosableFileFilter(new FileNameExtensionFilter("Carbide Create (.c2d)", "c2d"));
fileDialog.showOpenDialog(null);
ThreadHelper.invokeLater(() -> {
File f = fileDialog.getSelectedFile();
if (f != null) {
Optional<Design> optionalDesign = Optional.empty();
if (StringUtils.endsWithIgnoreCase(f.getName(), ".svg")) {
SvgReader svgReader = new SvgReader();
optionalDesign = svgReader.read(f);
} else if (StringUtils.endsWithIgnoreCase(f.getName(), ".dxf")) {
DxfReader reader = new DxfReader();
optionalDesign = reader.read(f);
} else if (StringUtils.endsWithIgnoreCase(f.getName(), ".c2d")) {
C2dReader reader = new C2dReader();
optionalDesign = reader.read(f);
}
if (optionalDesign.isPresent()) {
Design design = optionalDesign.get();
controller.addEntities(design.getEntities());
controller.getSelectionManager().addSelection(design.getEntities());
controller.getDrawing().repaint();
controller.setTool(Tool.SELECT);
} else {
throw new RuntimeException("Could not open: " + f.getName());
}
}
});
}
use of com.willwinder.ugs.nbp.designer.io.svg.SvgReader in project Universal-G-Code-Sender by winder.
the class ImageTracerDialog method generateEntities.
private void generateEntities() {
SvgReader svgReader = new SvgReader();
Optional<Design> designOptional = svgReader.read(new ByteArrayInputStream(generatedSvgData.getBytes(Charset.defaultCharset())));
designOptional.ifPresent(design -> {
Map<String, List<Entity>> entityLayersMap = new HashMap<>();
((Group) design.getEntities().get(0)).getAllChildren().forEach(entity -> {
String layerId = StringUtils.substringBetween(entity.getDescription(), "l ", " ");
List<Entity> layerEntities = entityLayersMap.getOrDefault(layerId, new ArrayList<>());
layerEntities.add(entity);
entityLayersMap.put(layerId, layerEntities);
});
List<String> layerIds = new ArrayList<>(entityLayersMap.keySet());
Collections.reverse(layerIds);
entities = new ArrayList<>();
layerIds.forEach(layerId -> {
Group layerGroup = new Group();
layerGroup.setName(layerId);
layerGroup.addAll(entityLayersMap.get(layerId));
entities.add(layerGroup);
});
dispose();
});
}
Aggregations