From e34439f2beae4221af3dc6e7de7683423be47324 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Wed, 28 Jun 2017 18:09:49 +0200
Subject: [PATCH] either pathways and compartments or custom semantic zoom view
 isi accessible when generating project

---
 .../lcsb/mapviewer/run/LegendGenerator.java   |  2 +-
 .../graphics/AbstractImageGenerator.java      | 23 ++-------------
 .../converter/graphics/ConverterParams.java   | 25 +++++++---------
 .../converter/graphics/MapGenerator.java      | 21 +-------------
 .../bioEntity/BioEntityConverter.java         |  2 +-
 .../bioEntity/BioEntityConverterImplTest.java |  4 +--
 .../reaction/ReactionConverterTest.java       | 16 +++++-----
 .../services/impl/ProjectService.java         | 29 +++++++++----------
 .../services/utils/data/BuildInLayout.java    |  4 +--
 9 files changed, 42 insertions(+), 84 deletions(-)

diff --git a/console/src/main/java/lcsb/mapviewer/run/LegendGenerator.java b/console/src/main/java/lcsb/mapviewer/run/LegendGenerator.java
index 9df1420f0e..df75ffdad6 100644
--- a/console/src/main/java/lcsb/mapviewer/run/LegendGenerator.java
+++ b/console/src/main/java/lcsb/mapviewer/run/LegendGenerator.java
@@ -160,7 +160,7 @@ public class LegendGenerator {
 
 		Model copy = new CopyCommand(model).execute();
 		PngImageGenerator generator = new PngImageGenerator(new Params()
-				.scale(ZOOM_FACTOR).x(lo.startX).y(lo.startY).width(lo.width).height(lo.height).model(copy).level(2).semanticZoom(true));
+				.scale(ZOOM_FACTOR).x(lo.startX).y(lo.startY).width(lo.width).height(lo.height).model(copy).level(1).nested(true));
 		generator.saveToFile(fileName);
 		Desktop.getDesktop().open(new File(fileName));
 	}
diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/AbstractImageGenerator.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/AbstractImageGenerator.java
index 19fe2746b3..3d4e0aefa3 100644
--- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/AbstractImageGenerator.java
+++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/AbstractImageGenerator.java
@@ -175,11 +175,6 @@ public abstract class AbstractImageGenerator {
 		 */
 		private boolean												 nested					= false;
 
-		/**
-		 * Should the visualization include semantic zoom view or not.
-		 */
-		private boolean												 semanticZoom		= false;
-
 		/**
 		 * Should sbgn standard be used.
 		 */
@@ -215,17 +210,6 @@ public abstract class AbstractImageGenerator {
 			return this;
 		}
 
-		/**
-		 * @param semanticZoom
-		 *          semanticZoom to set
-		 * @return object with all parameters
-		 * @see #semanticZoom
-		 */
-		public Params semanticZoom(boolean semanticZoom) {
-			this.semanticZoom = semanticZoom;
-			return this;
-		}
-
 		/**
 		 * @param scale
 		 *          scale to set
@@ -754,7 +738,7 @@ public abstract class AbstractImageGenerator {
 
 		// get a converter for this compartment
 		BioEntityConverterImpl converter = new BioEntityConverterImpl(compartment, colorExtractor);
-		ConverterParams compartmentParams = new ConverterParams().textCentered(fill).level(level).semanticZoomingOn(params.semanticZoom);
+		ConverterParams compartmentParams = new ConverterParams().textCentered(fill).level(level).nested(params.nested);
 
 		if (params.nested) {
 			compartmentParams.fill(fill).scale(Math.max(scale, 1));
@@ -855,8 +839,7 @@ public abstract class AbstractImageGenerator {
 		}
 		try {
 			converter.draw(
-					species, graphics,
-					new ConverterParams().scale(customScale).textCentered(rescale).level(level).sbgnFormat(sbgnFormat).semanticZoomingOn(params.semanticZoom),
+					species, graphics, new ConverterParams().scale(customScale).textCentered(rescale).level(level).sbgnFormat(sbgnFormat).nested(params.nested),
 					visibleLayouts);
 		} catch (Exception e) {
 			throw new DrawingException(eu.getElementTag(species) + "Problem with drawing element.", e);
@@ -894,7 +877,7 @@ public abstract class AbstractImageGenerator {
 			return;
 		}
 		BioEntityConverterImpl converter = new BioEntityConverterImpl(reaction, sbgnFormat, colorExtractor);
-		converter.draw(reaction, graphics, new ConverterParams().sbgnFormat(sbgnFormat).semanticZoomingOn(params.semanticZoom).level(level), visibleLayouts);
+		converter.draw(reaction, graphics, new ConverterParams().sbgnFormat(sbgnFormat).nested(params.nested).level(level), visibleLayouts);
 	}
 
 	/**
diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ConverterParams.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ConverterParams.java
index 59577a9350..7efaa3e51b 100644
--- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ConverterParams.java
+++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ConverterParams.java
@@ -34,10 +34,7 @@ public class ConverterParams {
 	 */
 	private boolean	sbgnFormat				= false;
 
-	/**
-	 * Is the semantic zooming filtered.
-	 */
-	private boolean	semanticZoomingOn	= false;
+	private boolean	nested	= false;
 
 	/**
 	 * @param fill
@@ -62,13 +59,13 @@ public class ConverterParams {
 	}
 
 	/**
-	 * @param semanticZoomingOn
-	 *          the semanticZoomingOn to set
+	 * @param nested
+	 *          the nested to set
 	 * @return object with all parameters
-	 * @see #semanticZoomingOn
+	 * @see #nested
 	 */
-	public ConverterParams semanticZoomingOn(final boolean semanticZoomingOn) {
-		this.semanticZoomingOn = semanticZoomingOn;
+	public ConverterParams nested(final boolean nested) {
+		this.nested = nested;
 		return this;
 	}
 
@@ -146,11 +143,11 @@ public class ConverterParams {
 	}
 
 	/**
-	 * @return the semanticZoomingOn
-	 * @see #semanticZoomingOn
+	 * @return the nested
+	 * @see #nested
 	 */
-	public boolean isSemanticZoomingOn() {
-		return semanticZoomingOn;
+	public boolean isNested() {
+		return nested;
 	}
 
 	@Override
@@ -160,7 +157,7 @@ public class ConverterParams {
 				"level:" + level + "," + //
 				"scale:" + scale + "," + //
 				"textCentered:" + textCentered + "," + //
-				"semanticZoomingOn:" + semanticZoomingOn + "," + //
+				"nested:" + nested + "," + //
 				"sbgnFormat:" + sbgnFormat;
 		return result;
 	}
diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/MapGenerator.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/MapGenerator.java
index 5e44baf425..697177d051 100644
--- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/MapGenerator.java
+++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/MapGenerator.java
@@ -58,10 +58,6 @@ public class MapGenerator {
 		 * 
 		 */
 		private boolean					 nested				= false;
-		/**
-		 * Do we want to generate images with semantic zoom view or not.
-		 */
-		private boolean					 semanticZoom	= false;
 		/**
 		 * Should we remove empty elements in nested view.
 		 * 
@@ -139,17 +135,6 @@ public class MapGenerator {
 			return this;
 		}
 
-		/**
-		 * @param semanticZoom
-		 *          the semanticZoom to set
-		 * @see #nested
-		 * @return full {@link MapGeneratorParams} object
-		 */
-		public MapGeneratorParams semanticZoom(boolean semanticZoom) {
-			this.semanticZoom = semanticZoom;
-			return this;
-		}
-
 		/**
 		 * @return the removeEmpty
 		 * @see #removeEmpty
@@ -342,11 +327,7 @@ public class MapGenerator {
 						imgParams.model(params.model);
 						imgParams.sbgn(params.sbgn);
 						imgParams.level(i);
-						imgParams.semanticZoom(params.semanticZoom);
-
-						if (params.nested) {
-							imgParams.level(i).nested(params.nested);
-						}
+						imgParams.nested(params.nested);
 						PngImageGenerator generator = new PngImageGenerator(imgParams);
 						for (int cx = 0; cx < TILES_CACHE_NUM; cx++) {
 							for (int cy = 0; cy < TILES_CACHE_NUM; cy++) {
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 fc23fb911c..30a411a810 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
@@ -156,7 +156,7 @@ public abstract class BioEntityConverter<T extends BioEntity> {
 	 * @return true if object is visible
 	 */
 	protected boolean isVisible(BioEntity bioEntity, ConverterParams params) {
-		if (params.isSemanticZoomingOn()) {
+		if (params.isNested()) {
 			boolean result = semanticZoomLevelMatcher.isVisible(params.getLevel(), bioEntity.getVisibilityLevel());
 			if (bioEntity instanceof Element) {
 				Compartment compartment = ((Element) bioEntity).getCompartment();
diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImplTest.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImplTest.java
index 9141204ccf..206b3f332f 100644
--- a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImplTest.java
+++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImplTest.java
@@ -49,7 +49,7 @@ public class BioEntityConverterImplTest {
 			reaction.getReactants().get(0).getElement().setVisibilityLevel("11");
 
 			BioEntityConverterImpl rc = new BioEntityConverterImpl(reaction, false, colorExtractor);
-			rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10));
+			rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10));
 
 			verify(graphics, times(0)).draw(any(GeneralPath.class));
 
@@ -67,7 +67,7 @@ public class BioEntityConverterImplTest {
 			reaction.getProducts().get(0).getElement().setVisibilityLevel("11");
 
 			BioEntityConverterImpl rc = new BioEntityConverterImpl(reaction, false, colorExtractor);
-			rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10));
+			rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10));
 
 			verify(graphics, times(0)).draw(any(GeneralPath.class));
 
diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverterTest.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverterTest.java
index 8d17b603ca..2606bb7c83 100644
--- a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverterTest.java
+++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverterTest.java
@@ -264,7 +264,7 @@ public class ReactionConverterTest {
 			ReactionConverter rc = new ReactionConverter(colorExtractor);
 
 			Reaction reaction = createReaction(1.0);
-			rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10));
+			rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10));
 
 			verify(graphics, times(4)).draw(any(GeneralPath.class));
 
@@ -281,7 +281,7 @@ public class ReactionConverterTest {
 
 			Reaction reaction = createReaction(1.0);
 			reaction.getModifiers().get(0).getElement().setVisibilityLevel("11");
-			rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10));
+			rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10));
 
 			verify(graphics, times(3)).draw(any(GeneralPath.class));
 
@@ -298,7 +298,7 @@ public class ReactionConverterTest {
 
 			Reaction reaction = createReaction(1.0);
 			reaction.getReactants().get(0).getElement().setVisibilityLevel("11");
-			rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10));
+			rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10));
 
 			verify(graphics, times(3)).draw(any(GeneralPath.class));
 
@@ -315,7 +315,7 @@ public class ReactionConverterTest {
 
 			Reaction reaction = createReaction(1.0);
 			reaction.getProducts().get(0).getElement().setVisibilityLevel("11");
-			rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10));
+			rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10));
 
 			verify(graphics, times(3)).draw(any(GeneralPath.class));
 
@@ -332,7 +332,7 @@ public class ReactionConverterTest {
 
 			Reaction reaction = createComplexReaction(1.0);
 			reaction.getModifiers().get(0).getElement().setVisibilityLevel("11");
-			rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10));
+			rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10));
 
 			verify(graphics, times(12)).draw(any(GeneralPath.class));
 
@@ -350,7 +350,7 @@ public class ReactionConverterTest {
 			Reaction reaction = createComplexReaction(1.0);
 			reaction.getModifiers().get(0).getElement().setVisibilityLevel("11");
 			reaction.getModifiers().get(1).getElement().setVisibilityLevel("11");
-			rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10));
+			rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10));
 
 			verify(graphics, times(9)).draw(any(GeneralPath.class));
 
@@ -375,7 +375,7 @@ public class ReactionConverterTest {
 
 			Reaction reaction = createComplexReaction(1.0);
 			reaction.getReactants().get(0).getElement().setVisibilityLevel("11");
-			rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10));
+			rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10));
 
 			verify(graphics, times(12)).draw(any(GeneralPath.class));
 
@@ -392,7 +392,7 @@ public class ReactionConverterTest {
 
 			Reaction reaction = createComplexReaction(1.0);
 			reaction.getProducts().get(0).getElement().setVisibilityLevel("11");
-			rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10));
+			rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10));
 
 			verify(graphics, times(12)).draw(any(GeneralPath.class));
 
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 c502dcc853..ed54015542 100644
--- a/service/src/main/java/lcsb/mapviewer/services/impl/ProjectService.java
+++ b/service/src/main/java/lcsb/mapviewer/services/impl/ProjectService.java
@@ -648,7 +648,6 @@ public class ProjectService implements IProjectService {
 		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.]", ""));
 			}
@@ -728,24 +727,20 @@ public class ProjectService implements IProjectService {
 		model.setTileSize(MapGenerator.TILE_SIZE);
 
 		List<BuildInLayout> buildInLayouts = new ArrayList<>();
+		BuildInLayout nested = null;
+		if (params.isSemanticZoom()) {
+			nested = BuildInLayout.SEMANTIC;
+		} else {
+			nested = BuildInLayout.NESTED;
+		}
 		if (params.isNetworkLayoutAsDefault()) {
 			buildInLayouts.add(BuildInLayout.NORMAL);
-			for (BuildInLayout buildInLayout : BuildInLayout.values()) {
-				if (!buildInLayout.equals(BuildInLayout.NORMAL) && !buildInLayout.equals(BuildInLayout.SEMANTIC)) {
-					buildInLayouts.add(buildInLayout);
-				}
-			}
+			buildInLayouts.add(nested);
 		} else {
-			buildInLayouts.add(BuildInLayout.NESTED);
-			for (BuildInLayout buildInLayout : BuildInLayout.values()) {
-				if (!buildInLayout.equals(BuildInLayout.NESTED) && !buildInLayout.equals(BuildInLayout.SEMANTIC)) {
-					buildInLayouts.add(buildInLayout);
-				}
-			}
-		}
-		if (params.isSemanticZoom()) {
-			buildInLayouts.add(BuildInLayout.SEMANTIC);
+			buildInLayouts.add(nested);
+			buildInLayouts.add(BuildInLayout.NORMAL);
 		}
+		buildInLayouts.add(BuildInLayout.CLEAN);
 
 		// reverse the order of build in layouts, so we can insert them at the
 		// beginning of list of layouts (the order will be the same)
@@ -972,7 +967,9 @@ public class ProjectService implements IProjectService {
 					}
 
 					Model originalModel = createModel(params, project);
-					new CreateHierarchyCommand(originalModel, generator.computeZoomLevels(originalModel), generator.computeZoomFactor(originalModel)).execute();
+					if (!params.isSemanticZoom()) {
+						new CreateHierarchyCommand(originalModel, generator.computeZoomLevels(originalModel), generator.computeZoomFactor(originalModel)).execute();
+					}
 
 					addUsers(project, params);
 					createImages(originalModel, params);
diff --git a/service/src/main/java/lcsb/mapviewer/services/utils/data/BuildInLayout.java b/service/src/main/java/lcsb/mapviewer/services/utils/data/BuildInLayout.java
index 3bdf5704f7..c0edc377be 100644
--- a/service/src/main/java/lcsb/mapviewer/services/utils/data/BuildInLayout.java
+++ b/service/src/main/java/lcsb/mapviewer/services/utils/data/BuildInLayout.java
@@ -31,8 +31,8 @@ public enum BuildInLayout { //
 	/**
 	 * Standard visualization with hierarchical view.
 	 */
-	NESTED("Pathways and compartments", "_nested", null, true),
-	SEMANTIC("Semantic zoom", "_semantic", null, false),
+	NESTED("Pathways and compartments", "_nested", null, true), //
+	SEMANTIC("Semantic zoom", "_semantic", null, true),
 	/**
 	 * Clean visualization (with colors reset to black and white).
 	 */
-- 
GitLab