From ec7dad53adfa7c4f10afb5d16942db71f1023aba Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Fri, 7 Jun 2019 16:24:45 +0200 Subject: [PATCH] pathways can be drawn using glyphs --- CHANGELOG | 1 + .../mapviewer/converter/ProjectFactory.java | 20 ++++++++ .../converter/ProjectFactoryTest.java | 49 +++++++++++++++++++ .../commands/CreateHierarchyCommand.java | 5 +- .../model/map/layout/graphics/LayerText.java | 19 +++++++ .../V13.1.0.20190607__text_contains_glyph.sql | 5 ++ 6 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 persist/src/main/resources/db/migration/13.1.0~beta.1/V13.1.0.20190607__text_contains_glyph.sql diff --git a/CHANGELOG b/CHANGELOG index 484adae3d3..d91c26390c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -28,6 +28,7 @@ minerva (12.3.1~beta.1) unstable; urgency=low close button twice (#818) * Bug fix: empty type for data overlay is allowed (#827) * Bug fix: genetic variants data overlay was ignoring color parameter (#827) + * Bug fix: pathways can be drawn using glyphs (#825) minerva (13.1.0~beta.0) unstable; urgency=low * Feature: annotators are more flexible - you can define set of input and diff --git a/converter/src/main/java/lcsb/mapviewer/converter/ProjectFactory.java b/converter/src/main/java/lcsb/mapviewer/converter/ProjectFactory.java index dd5c55cbb8..3b576a5fb2 100644 --- a/converter/src/main/java/lcsb/mapviewer/converter/ProjectFactory.java +++ b/converter/src/main/java/lcsb/mapviewer/converter/ProjectFactory.java @@ -18,8 +18,11 @@ import lcsb.mapviewer.converter.zip.LayoutZipEntryFile; import lcsb.mapviewer.converter.zip.ZipEntryFile; import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.layout.graphics.Glyph; +import lcsb.mapviewer.model.map.layout.graphics.Layer; +import lcsb.mapviewer.model.map.layout.graphics.LayerText; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelData; +import lcsb.mapviewer.model.map.model.ModelSubmodelConnection; import lcsb.mapviewer.model.map.species.Element; public class ProjectFactory { @@ -90,7 +93,15 @@ public class ProjectFactory { } private void assignGlyphsToElements(Project project) throws InvalidGlyphFile { + Set<ModelData> models = new HashSet<>(); + models.addAll(project.getModels()); + for (ModelData model : project.getModels()) { + for (ModelSubmodelConnection connection : model.getSubmodels()) { + models.add(connection.getSubmodel()); + } + } + for (ModelData model : models) { for (Element element : model.getElements()) { Glyph glyph = extractGlyph(project, element.getNotes()); if (glyph != null) { @@ -98,6 +109,15 @@ public class ProjectFactory { element.setGlyph(glyph); } } + for (Layer layer : model.getLayers()) { + for (LayerText text : layer.getTexts()) { + Glyph glyph = extractGlyph(project, text.getNotes()); + if (glyph != null) { + text.setNotes(removeGlyph(text.getNotes())); + text.setGlyph(glyph); + } + } + } } } diff --git a/converter/src/test/java/lcsb/mapviewer/converter/ProjectFactoryTest.java b/converter/src/test/java/lcsb/mapviewer/converter/ProjectFactoryTest.java index ad6b5dc397..b882d44aa6 100644 --- a/converter/src/test/java/lcsb/mapviewer/converter/ProjectFactoryTest.java +++ b/converter/src/test/java/lcsb/mapviewer/converter/ProjectFactoryTest.java @@ -23,6 +23,8 @@ import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.OverviewImage; import lcsb.mapviewer.model.map.OverviewLink; import lcsb.mapviewer.model.map.OverviewModelLink; +import lcsb.mapviewer.model.map.layout.graphics.Layer; +import lcsb.mapviewer.model.map.layout.graphics.LayerText; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelData; import lcsb.mapviewer.model.map.model.ModelFullIndexed; @@ -211,6 +213,53 @@ public class ProjectFactoryTest extends ConverterTestFunctions { } + @Test + public void testParseGlyphsAndPutThemAsTextGlyphs() throws Exception { + try { + Model model = new ModelFullIndexed(null); + Layer layer = new Layer(); + + LayerText text = new LayerText(); + text.setNotes("Glyph: glyphs/g1.png"); + layer.addLayerText(text); + model.addLayer(layer); + + MockConverter.modelToBeReturned = model; + + ComplexZipConverter converter = new ComplexZipConverter(MockConverter.class); + ProjectFactory projectFactory = new ProjectFactory(converter); + + ComplexZipConverterParams params = new ComplexZipConverterParams(); + params.zipFile(new ZipFile("testFiles/complex_with_glyphs.zip")); + params.entry(new ModelZipEntryFile("main.xml", "main", true, false, null)); + + ZipFile zipFile = new ZipFile("testFiles/complex_with_glyphs.zip"); + + ZipEntryFileFactory factory = new ZipEntryFileFactory(); + Enumeration<? extends ZipEntry> entries = zipFile.entries(); + while (entries.hasMoreElements()) { + ZipEntry entry = entries.nextElement(); + if (!entry.isDirectory()) { + params.entry(factory.createZipEntryFile(entry, zipFile)); + } + } + + Project project = projectFactory.create(params); + assertNotNull(project); + model = project.getModels().iterator().next().getModel(); + + LayerText fetchedProtein = model.getLayers().iterator().next().getTexts().get(0); + + assertFalse("Glyph field should be removed from notes", fetchedProtein.getNotes().contains("Glyph")); + assertNotNull("Glyph in the protein is not defined but should", fetchedProtein.getGlyph()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + private GenericProtein createProtein() { GenericProtein result = new GenericProtein("s" + elementCounter++); return result; diff --git a/model-command/src/main/java/lcsb/mapviewer/commands/CreateHierarchyCommand.java b/model-command/src/main/java/lcsb/mapviewer/commands/CreateHierarchyCommand.java index adb5061425..294b1fb29c 100644 --- a/model-command/src/main/java/lcsb/mapviewer/commands/CreateHierarchyCommand.java +++ b/model-command/src/main/java/lcsb/mapviewer/commands/CreateHierarchyCommand.java @@ -43,11 +43,11 @@ public class CreateHierarchyCommand extends ModelCommand { private static final double LOG_4 = Math.log(4); /** - * Top left corner x coordinate of the text associated with compratment. + * Top left corner x coordinate of the text associated with compartment. */ private static final double DEFAULT_TITLE_X_COORD_IN_ARTIFITIAL_COMPARTMENT = 10; /** - * Top left corner y coordinate of the text associated with compratment. + * Top left corner y coordinate of the text associated with compartment. */ private static final double DEFAULT_TITLE_Y_COORD_IN_ARTIFITIAL_COMPARTMENT = 10; @@ -180,6 +180,7 @@ public class CreateHierarchyCommand extends ModelCommand { compartment.setName(extractNameFromText(text.getNotes())); compartment.setNotes(extractNotesFromText(text.getNotes())); compartment.setZ(text.getZ()); + compartment.setGlyph(text.getGlyph()); rap.processNotes(compartment); compartment.setNamePoint(new Point2D.Double(text.getX() + DEFAULT_TITLE_X_COORD_IN_ARTIFITIAL_COMPARTMENT, diff --git a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerText.java b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerText.java index d866c3e6e1..ecd49c6f8b 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerText.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerText.java @@ -5,9 +5,11 @@ import java.awt.geom.Rectangle2D; import java.io.Serializable; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.ManyToOne; import org.apache.log4j.Logger; @@ -92,6 +94,12 @@ public class LayerText implements Serializable, Drawable { */ private Double fontSize = DEFAULT_LAYER_FONT_SIZE; + /** + * Glyph used for drawing (instead of text). + */ + @ManyToOne(fetch = FetchType.LAZY) + private Glyph glyph = null; + /** * Default constructor. */ @@ -130,6 +138,9 @@ public class LayerText implements Serializable, Drawable { height = layerText.getHeight(); notes = layerText.getNotes(); fontSize = layerText.getFontSize(); + if (layerText.getGlyph() != null) { + setGlyph(new Glyph(layerText.getGlyph())); + } } /** @@ -377,4 +388,12 @@ public class LayerText implements Serializable, Drawable { return "x=" + x + ";y=" + y + "; w=" + width + ", h=" + height; } + public Glyph getGlyph() { + return glyph; + } + + public void setGlyph(Glyph glyph) { + this.glyph = glyph; + } + } diff --git a/persist/src/main/resources/db/migration/13.1.0~beta.1/V13.1.0.20190607__text_contains_glyph.sql b/persist/src/main/resources/db/migration/13.1.0~beta.1/V13.1.0.20190607__text_contains_glyph.sql new file mode 100644 index 0000000000..8c1f1ac837 --- /dev/null +++ b/persist/src/main/resources/db/migration/13.1.0~beta.1/V13.1.0.20190607__text_contains_glyph.sql @@ -0,0 +1,5 @@ +alter table layer_text_table add column glyph_id integer; +alter table layer_text_table add constraint layer_text_table_glyph_fk FOREIGN KEY (glyph_id) + REFERENCES glyph_table (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION; + -- GitLab