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 25fbd300a7cc51d34d57a923dc724d6735c3adc8..0f3fbea1f767125d5922bbed62ae53ee300e4999 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 @@ -15,6 +15,9 @@ import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.layout.ColorSchema; import lcsb.mapviewer.model.map.reaction.AbstractNode; import lcsb.mapviewer.model.map.reaction.NodeOperator; +import lcsb.mapviewer.model.map.reaction.Product; +import lcsb.mapviewer.model.map.reaction.Reactant; +import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.ReactionNode; import lcsb.mapviewer.model.map.species.Complex; import lcsb.mapviewer.model.map.species.Element; @@ -164,12 +167,60 @@ public abstract class BioEntityConverter<T extends AnnotatedObject> { result &= isVisible(complex, params); } } + } else if (bioEntity instanceof Reaction) { + if (!isAnyProductVisible(((Reaction) bioEntity).getProducts(), params)) { + result = false; + } else if (!isAnyReactantVisible(((Reaction) bioEntity).getReactants(), params)) { + result = false; + } + + } else { + throw new InvalidArgumentException("Unknown class type: " + bioEntity.getClass()); } + return result; } return true; } + /** + * Checks if at least one reactant is visible. + * + * @param reactants + * list of reactants + * @param params + * params against which check is run + * @return true if at least one reactant is visible + */ + private boolean isAnyReactantVisible(List<Reactant> reactants, ConverterParams params) { + boolean result = false; + for (Reactant reactant : reactants) { + if (isVisible(reactant, params)) { + result = true; + } + } + return result; + } + + /** + * Checks if at least one product is visible. + * + * @param products + * list of products + * @param params + * params against which check is run + * @return true if at least one product is visible + */ + private boolean isAnyProductVisible(List<Product> products, ConverterParams params) { + boolean result = false; + for (Product product : products) { + if (isVisible(product, params)) { + result = true; + } + } + return result; + } + /** * Checks if level belongs to the range defined in * semanticZoomLevelVisibility. diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/AllGraphicsTests.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/AllGraphicsTests.java index 940785356395983a48c340979d981a2d65ffd175..712c9d780cc68a7801c4536f6d38d703ec5d54e6 100644 --- a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/AllGraphicsTests.java +++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/AllGraphicsTests.java @@ -1,19 +1,18 @@ package lcsb.mapviewer.converter.graphics; -import lcsb.mapviewer.converter.graphics.bioEntity.element.species.AllSpeciesConverterTests; -import lcsb.mapviewer.converter.graphics.bioEntity.reaction.AllReactionTests; -import lcsb.mapviewer.converter.graphics.geometry.AllGeometryTests; -import lcsb.mapviewer.converter.graphics.placefinder.AllPlaceFinderTest; - import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; +import lcsb.mapviewer.converter.graphics.bioEntity.AllBioEntityTests; +import lcsb.mapviewer.converter.graphics.geometry.AllGeometryTests; +import lcsb.mapviewer.converter.graphics.placefinder.AllPlaceFinderTest; + @RunWith(Suite.class) -@SuiteClasses({ AllGeometryTests.class, // +@SuiteClasses({ // + AllBioEntityTests.class, // + AllGeometryTests.class, // AllPlaceFinderTest.class, // - AllReactionTests.class, // - AllSpeciesConverterTests.class, // ConverterTest.class, // ImageGeneratorsTest.class, // MapGeneratorTest.class, // diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/AllBioEntityTests.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/AllBioEntityTests.java new file mode 100644 index 0000000000000000000000000000000000000000..4feec5c7d2f55a7a9f1e0888bc0ac822acb149ef --- /dev/null +++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/AllBioEntityTests.java @@ -0,0 +1,18 @@ +package lcsb.mapviewer.converter.graphics.bioEntity; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.AllSpeciesConverterTests; +import lcsb.mapviewer.converter.graphics.bioEntity.reaction.AllReactionTests; + +@RunWith(Suite.class) +@SuiteClasses({ // + AllSpeciesConverterTests.class, // + AllReactionTests.class, // + BioEntityConverterImplTest.class// +}) +public class AllBioEntityTests { + +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..8ba25ceb5b694c44954955c85a691d880e1aa439 --- /dev/null +++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImplTest.java @@ -0,0 +1,98 @@ +package lcsb.mapviewer.converter.graphics.bioEntity; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import lcsb.mapviewer.commands.ColorExtractor; +import lcsb.mapviewer.converter.graphics.ConverterParams; +import lcsb.mapviewer.model.graphics.PolylineData; +import lcsb.mapviewer.model.map.modifier.Catalysis; +import lcsb.mapviewer.model.map.reaction.Modifier; +import lcsb.mapviewer.model.map.reaction.Product; +import lcsb.mapviewer.model.map.reaction.Reactant; +import lcsb.mapviewer.model.map.reaction.Reaction; +import lcsb.mapviewer.model.map.species.GenericProtein; + +public class BioEntityConverterImplTest { + + ColorExtractor colorExtractor = new ColorExtractor(Color.RED, Color.GREEN); + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testDrawReactionWithSemanticZoomingAndReactantOff() throws Exception { + try { + Graphics2D graphics = Mockito.mock(Graphics2D.class); + Reaction reaction = createReaction(1.0); + reaction.getReactants().get(0).getElement().setSemanticZoomLevelVisibility("11"); + + BioEntityConverterImpl rc = new BioEntityConverterImpl(reaction, false, colorExtractor); + rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10)); + + verify(graphics, times(0)).draw(any(GeneralPath.class)); + + } catch (Exception e) { + throw e; + } + } + + @Test + public void testDrawReactionWithSemanticZoomingAndProductOff() throws Exception { + try { + Graphics2D graphics = Mockito.mock(Graphics2D.class); + + Reaction reaction = createReaction(1.0); + reaction.getProducts().get(0).getElement().setSemanticZoomLevelVisibility("11"); + + BioEntityConverterImpl rc = new BioEntityConverterImpl(reaction, false, colorExtractor); + rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10)); + + verify(graphics, times(0)).draw(any(GeneralPath.class)); + + } catch (Exception e) { + throw e; + } + } + + private Reaction createReaction(double lineWidth) { + Reaction result = new Reaction(); + + Modifier modifier = new Catalysis(new GenericProtein("s1")); + modifier.setLine(new PolylineData(new Point2D.Double(100, 20), new Point2D.Double(100, 80))); + modifier.getLine().setWidth(lineWidth); + + Reactant reactant = new Reactant(new GenericProtein("s2")); + reactant.setLine(new PolylineData(new Point2D.Double(90, 90), new Point2D.Double(10, 90))); + reactant.getLine().setWidth(lineWidth); + Product product = new Product(new GenericProtein("s3")); + product.setLine(new PolylineData(new Point2D.Double(200, 90), new Point2D.Double(110, 90))); + product.getLine().setWidth(lineWidth); + result.addModifier(modifier); + result.addProduct(product); + result.addReactant(reactant); + return result; + } + +}