diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverter.java index eaa090e2966932c54e93380b2f1844dd52f5217c..83ea40c73472ad4b2659099afbe4484ef0b19abe 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverter.java @@ -38,13 +38,15 @@ public abstract class BioEntityConverter<T extends BioEntity> { * Default class logger. */ @SuppressWarnings("unused") - private final Logger logger = Logger.getLogger(BioEntityConverter.class); + private final Logger logger = Logger.getLogger(BioEntityConverter.class); + + private SemanticZoomLevelMatcher semanticZoomLevelMatcher = new SemanticZoomLevelMatcher(); /** * Alpha value (0..255) used for visualizing overlay data that are normally * visualized in javascript. */ - public static final int LAYOUT_ALPHA = 200; + public static final int LAYOUT_ALPHA = 200; /** * This function draw representation of the alias on the graphics object. @@ -144,8 +146,8 @@ public abstract class BioEntityConverter<T extends BioEntity> { } /** - * Checks if {@link BioEntity} is visible according to visualization - * given in params. + * Checks if {@link BioEntity} is visible according to visualization given in + * params. * * @param bioEntity * visibility of this object will be checked @@ -155,7 +157,7 @@ public abstract class BioEntityConverter<T extends BioEntity> { */ protected boolean isVisible(BioEntity bioEntity, ConverterParams params) { if (params.isSemanticZoomingOn()) { - boolean result = matchLevel(params.getLevel(), bioEntity.getSemanticZoomLevelVisibility()); + boolean result = semanticZoomLevelMatcher.matchLevel(params.getLevel(), bioEntity.getSemanticZoomLevelVisibility()); if (bioEntity instanceof Element) { Compartment compartment = ((Element) bioEntity).getCompartment(); if (compartment != null) { @@ -219,33 +221,4 @@ public abstract class BioEntityConverter<T extends BioEntity> { return result; } - /** - * Checks if level belongs to the range defined in - * semanticZoomLevelVisibility. - * - * @param level - * level to ve checked - * @param semanticZoomLevelVisibility - * range of levels to be checked - * @return true if level is in the range - */ - protected boolean matchLevel(int level, String semanticZoomLevelVisibility) { - if (semanticZoomLevelVisibility == null || semanticZoomLevelVisibility.isEmpty()) { - return true; - } - if (semanticZoomLevelVisibility.contains("{")) { - String strLevels = semanticZoomLevelVisibility.replace("{", "").replace("}", ""); - String[] ranges = strLevels.split(","); - for (String string : ranges) { - if (Integer.valueOf(string).equals(level)) { - return true; - } - } - } - if (Integer.valueOf(semanticZoomLevelVisibility) <= level) { - return true; - } - return false; - } - } diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/SemanticZoomLevelMatcher.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/SemanticZoomLevelMatcher.java new file mode 100644 index 0000000000000000000000000000000000000000..195b6e4916344c1838861a851220c82bb323c6f6 --- /dev/null +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/SemanticZoomLevelMatcher.java @@ -0,0 +1,34 @@ +package lcsb.mapviewer.converter.graphics.bioEntity; + +public class SemanticZoomLevelMatcher { + + /** + * Checks if level belongs to the range defined in + * semanticZoomLevelVisibility. + * + * @param level + * level to ve checked + * @param semanticZoomLevelVisibility + * range of levels to be checked + * @return true if level is in the range + */ + public boolean matchLevel(int level, String semanticZoomLevelVisibility) { + if (semanticZoomLevelVisibility == null || semanticZoomLevelVisibility.isEmpty()) { + return true; + } + if (semanticZoomLevelVisibility.contains("{")) { + String strLevels = semanticZoomLevelVisibility.replace("{", "").replace("}", ""); + String[] ranges = strLevels.split(","); + for (String string : ranges) { + if (Integer.valueOf(string).equals(level)) { + return true; + } + } + } + if (Integer.valueOf(semanticZoomLevelVisibility) <= level) { + return true; + } + return false; + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/ProjectService.java b/service/src/main/java/lcsb/mapviewer/services/impl/ProjectService.java index 272848fa2a2ec240be53102dc03b3324ae30c15b..0b95943a44f02eea6dfb63cf89cb3b317a73aeed 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/ProjectService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/ProjectService.java @@ -52,6 +52,7 @@ import lcsb.mapviewer.converter.InvalidInputDataExecption; import lcsb.mapviewer.converter.graphics.DrawingException; import lcsb.mapviewer.converter.graphics.MapGenerator; import lcsb.mapviewer.converter.graphics.MapGenerator.MapGeneratorParams; +import lcsb.mapviewer.converter.graphics.bioEntity.SemanticZoomLevelMatcher; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; import lcsb.mapviewer.converter.model.sbgnml.SbgnmlXmlConverter; import lcsb.mapviewer.converter.zip.ZipEntryFile; @@ -612,40 +613,64 @@ public class ProjectService implements IProjectService { int counter = 0; for (final Model model : models) { for (int i = 0; i < model.getLayouts().size(); i++) { - String directory = model.getLayouts().get(i).getDirectory(); Layout layout = model.getLayouts().get(i); if (layout.getInputData() == null) { - - Model output = model; - if (layout.isHierarchicalView()) { - output = new CopyCommand(model).execute(); - } - if (layout.getTitle().equals(BuildInLayout.CLEAN.getTitle())) { - output = new CopyCommand(model).execute(); - new ClearColorModelCommand(output).execute(); - } - final double imgCounter = counter; final double finalSize = size; - MapGeneratorParams imgParams = generator.new MapGeneratorParams() - .model(output).directory(directory).sbgn(params.isSbgnFormat()).nested(layout.isHierarchicalView()).updater(new IProgressUpdater() { - @Override - public void setProgress(double progress) { - updateProjectStatus( - originalModel.getProject(), ProjectStatus.GENERATING_IMAGES, - IProgressUpdater.MAX_PROGRESS * imgCounter / finalSize + progress / finalSize, params); - } - }); - if (layout.getTitle().contains(BuildInLayout.SEMANTIC.getTitle())) { - imgParams.semanticZoom(params.isSemanticZoom()); - } - generator.generateMapImages(imgParams); + IProgressUpdater updater = new IProgressUpdater() { + @Override + public void setProgress(double progress) { + updateProjectStatus( + originalModel.getProject(), ProjectStatus.GENERATING_IMAGES, IProgressUpdater.MAX_PROGRESS * imgCounter / finalSize + progress / finalSize, + params); + } + }; + + generateImagesForBuiltInOverlay(params, model, layout, updater); } counter++; } } } + private void generateImagesForBuiltInOverlay(final CreateProjectParams params, final Model model, Layout layout, IProgressUpdater updater) + throws CommandExecutionException, IOException, DrawingException { + String directory = layout.getDirectory(); + Model output = model; + if (layout.isHierarchicalView()) { + output = new CopyCommand(model).execute(); + } + if (layout.getTitle().equals(BuildInLayout.CLEAN.getTitle())) { + output = new CopyCommand(model).execute(); + new ClearColorModelCommand(output).execute(); + } + + MapGeneratorParams imgParams = generator.new MapGeneratorParams() + .directory(directory).sbgn(params.isSbgnFormat()).nested(layout.isHierarchicalView()).updater(updater); + if (layout.getTitle().contains(BuildInLayout.SEMANTIC.getTitle())) { + imgParams.semanticZoom(params.isSemanticZoom()); + if (Character.isDigit(layout.getTitle().charAt(layout.getTitle().length() - 1))) { + output = prepareSemanticZoomModel(model, layout.getTitle().replaceAll("[^0-9.]", "")); + } + } + imgParams.model(output); + generator.generateMapImages(imgParams); + } + + private Model prepareSemanticZoomModel(final Model model, String levelStr) { + SemanticZoomLevelMatcher matcher = new SemanticZoomLevelMatcher(); + int level = Integer.valueOf(levelStr); + Model output = new CopyCommand(model).execute(); + for (BioEntity bioEntity : output.getAnnotatedObjects()) { + if (matcher.matchLevel(level, bioEntity.getSemanticZoomLevelVisibility())) { + bioEntity.setSemanticZoomLevelVisibility(null); + } else { + bioEntity.setSemanticZoomLevelVisibility(Integer.MAX_VALUE + ""); + } + } + return output; + } + /** * Creates project. Loads model from the input and run PostLoadModification. * @@ -702,7 +727,6 @@ public class ProjectService implements IProjectService { model.setZoomLevels(generator.computeZoomLevels(model)); model.setTileSize(MapGenerator.TILE_SIZE); - Map<BuildInLayout, Layout> topLayoutsByType = new HashMap<>(); List<BuildInLayout> buildInLayouts = new ArrayList<>(); if (params.isNetworkLayoutAsDefault()) { buildInLayouts.add(BuildInLayout.NORMAL); @@ -728,29 +752,26 @@ public class ProjectService implements IProjectService { Collections.reverse(buildInLayouts); for (BuildInLayout buildInLayout : buildInLayouts) { - Layout layout = new Layout(buildInLayout.getTitle(), params.getProjectDir() + "/" + buildInLayout.getDirectorySuffix() + model.getId() + "/", true); - layout.setStatus(LayoutStatus.NA); - layout.setProgress(0.0); - layout.setHierarchicalView(buildInLayout.isNested()); - model.addLayout(0, layout); - topLayoutsByType.put(buildInLayout, layout); - } - - int submodelId = 1; - for (ModelSubmodelConnection connection : model.getSubmodelConnections()) { - for (BuildInLayout buildInLayout : buildInLayouts) { + Layout topLayout = new Layout(buildInLayout.getTitle(), params.getProjectDir() + "/" + buildInLayout.getDirectorySuffix() + model.getId() + "/", true); + topLayout.setStatus(LayoutStatus.NA); + topLayout.setProgress(0.0); + topLayout.setHierarchicalView(buildInLayout.isNested()); + model.addLayout(0, topLayout); + int submodelId = 1; + for (ModelSubmodelConnection connection : model.getSubmodelConnections()) { Layout layout = new Layout(buildInLayout.getTitle(), params.getProjectDir() + "/" + buildInLayout.getDirectorySuffix() + submodelId + "/", true); layout.setStatus(LayoutStatus.NA); layout.setProgress(0.0); layout.setHierarchicalView(buildInLayout.isNested()); - layout.setParentLayout(topLayoutsByType.get(buildInLayout)); + layout.setParentLayout(topLayout); connection.getSubmodel().addLayout(0, layout); - } - submodelId++; + submodelId++; - connection.getSubmodel().setZoomLevels(generator.computeZoomLevels(connection.getSubmodel().getModel())); - connection.getSubmodel().setTileSize(MapGenerator.TILE_SIZE); + connection.getSubmodel().setZoomLevels(generator.computeZoomLevels(connection.getSubmodel().getModel())); + connection.getSubmodel().setTileSize(MapGenerator.TILE_SIZE); + } } + if (params.isUpdateAnnotations()) { Map<Class<?>, List<ElementAnnotator>> annotators = null; if (params.getAnnotatorsMap() != null) {