Commit 8afa6513 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

StructuralStateConverter implemented

parent a9127d71
......@@ -18,6 +18,8 @@ import lcsb.mapviewer.commands.SemanticZoomLevelMatcher;
import lcsb.mapviewer.common.MimeType;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.converter.graphics.bioentity.BioEntityConverterImpl;
import lcsb.mapviewer.converter.graphics.bioentity.element.species.StructuralStateConverter;
import lcsb.mapviewer.converter.graphics.bioentity.element.species.StructuralStateSbgnConverter;
import lcsb.mapviewer.converter.graphics.layer.LayerLineConverter;
import lcsb.mapviewer.converter.graphics.layer.LayerOvalConverter;
import lcsb.mapviewer.converter.graphics.layer.LayerRectConverter;
......@@ -27,7 +29,6 @@ import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.Drawable;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.compartment.PathwayCompartment;
import lcsb.mapviewer.model.map.layout.graphics.Layer;
import lcsb.mapviewer.model.map.layout.graphics.LayerOval;
import lcsb.mapviewer.model.map.layout.graphics.LayerRect;
import lcsb.mapviewer.model.map.layout.graphics.LayerText;
......@@ -36,6 +37,7 @@ import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.StructuralState;
import lcsb.mapviewer.model.overlay.DataOverlayEntry;
/**
......@@ -210,17 +212,11 @@ public abstract class AbstractImageGenerator {
// Get the SBGN display format option from the model
this.sbgnFormat = params.isSbgn();
List<Drawable> bioEntities = new ArrayList<>();
bioEntities.addAll(params.getModel().getBioEntities());
for (final Layer layer : params.getModel().getLayers()) {
if (layer.isVisible()) {
bioEntities.addAll(layer.getDrawables());
}
}
bioEntities.sort(BioEntity.Z_INDEX_COMPARATOR);
List<Drawable> drawables = new ArrayList<>(params.getModel().getDrawables());
drawables.sort(BioEntity.Z_INDEX_COMPARATOR);
// draw all elements
for (final Drawable element : bioEntities) {
for (final Drawable element : drawables) {
if (element instanceof Species) {
drawSpecies((Species) element);
} else if (element instanceof Reaction) {
......@@ -235,6 +231,8 @@ public abstract class AbstractImageGenerator {
drawRect((LayerRect) element);
} else if (element instanceof PolylineData) {
drawLine((PolylineData) element);
} else if (element instanceof StructuralState) {
drawStructuralState((StructuralState) element);
} else {
throw new DrawingException("Unknown class type: " + element);
}
......@@ -259,6 +257,14 @@ public abstract class AbstractImageGenerator {
new LayerLineConverter().draw(element, graphics);
}
private void drawStructuralState(final StructuralState structuralState) {
if (this.sbgnFormat) {
new StructuralStateSbgnConverter().draw(structuralState, graphics);
} else {
new StructuralStateConverter().draw(structuralState, graphics);
}
}
/**
* Method called after drawing. It should close drawing canvas properly.
*/
......
......@@ -103,8 +103,6 @@ public class ComplexConverter extends SpeciesConverter<Complex> {
complex.setWidth(complex.getWidth() + SpeciesConverter.HOMODIMER_OFFSET * (complex.getHomodimer() - 1));
complex.setHeight(complex.getHeight() + SpeciesConverter.HOMODIMER_OFFSET * (complex.getHomodimer() - 1));
drawStructuralState(complex.getStructuralState(), graphics);
drawText(complex, graphics, params);
graphics.setColor(oldColor);
}
......
......@@ -2,8 +2,6 @@ package lcsb.mapviewer.converter.graphics.bioentity.element.species;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import java.util.ArrayList;
import org.apache.logging.log4j.LogManager;
......@@ -13,7 +11,6 @@ import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.StructuralState;
import lcsb.mapviewer.model.overlay.DataOverlayEntry;
/**
......@@ -71,11 +68,4 @@ public class ComplexSbgnConverter extends ComplexConverter {
graphics.setColor(oldColor);
}
@Override
Shape getStructuralStateShape(final StructuralState state) {
double arcSize = Math.min(state.getWidth(), state.getHeight());
return new RoundRectangle2D.Double(state.getPosition().getX(), state.getPosition().getY(), state.getWidth(),
state.getHeight(), arcSize, arcSize);
}
}
......@@ -118,7 +118,6 @@ public class ProteinConverter extends SpeciesConverter<Protein> {
drawModification(mr, graphics, params.isSbgnFormat());
}
drawStructuralState(protein.getStructuralState(), graphics);
if (!params.isSbgnFormat()) {
drawUnitOfInformation(unitOfInformationText, protein, graphics);
}
......
......@@ -2,7 +2,6 @@ package lcsb.mapviewer.converter.graphics.bioentity.element.species;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import java.util.List;
import org.apache.logging.log4j.LogManager;
......@@ -13,7 +12,6 @@ import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.model.map.species.IonChannelProtein;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.StructuralState;
/**
* This class defines methods used for drawing {@link Protein} on the
......@@ -31,8 +29,8 @@ public class ProteinSbgnConverter extends ProteinConverter {
* Default constructor.
*
* @param colorExtractor
* Object that helps to convert {@link ColorSchema} values into colors
* when drawing {@link Species}
* Object that helps to convert {@link ColorSchema} values into
* colors when drawing {@link Species}
*/
public ProteinSbgnConverter(final ColorExtractor colorExtractor) {
super(colorExtractor);
......@@ -85,12 +83,4 @@ public class ProteinSbgnConverter extends ProteinConverter {
@Override
void drawActivityShape(final Protein protein, final Graphics2D graphics) {
}
@Override
Shape getStructuralStateShape(final StructuralState state) {
double arcSize = Math.min(state.getWidth(), state.getHeight());
return new RoundRectangle2D.Double(state.getPosition().getX(), state.getPosition().getY(), state.getWidth(),
state.getHeight(), arcSize, arcSize);
}
}
......@@ -39,7 +39,6 @@ import lcsb.mapviewer.model.map.species.field.ModificationState;
import lcsb.mapviewer.model.map.species.field.ProteinBindingDomain;
import lcsb.mapviewer.model.map.species.field.RegulatoryRegion;
import lcsb.mapviewer.model.map.species.field.Residue;
import lcsb.mapviewer.model.map.species.field.StructuralState;
import lcsb.mapviewer.model.map.species.field.TranscriptionSite;
import lcsb.mapviewer.model.overlay.DataOverlayEntry;
......@@ -355,53 +354,6 @@ public abstract class SpeciesConverter<T extends Species> extends ElementConvert
this.unitOfInformationFont = unitOfInformationFont;
}
/**
* Draws structural state description of the alias (ellipse in the top part of
* the alias).
*
* @param state
* state description text
* @param species
* state description should be drawn on this {@link Species}
* @param graphics
* where the drawing should be performed
*/
protected void drawStructuralState(final StructuralState state, final Graphics2D graphics) {
if (state == null) {
return;
}
double width = state.getWidth();
double height = state.getHeight();
Shape ellipse = getStructuralStateShape(state);
Color c = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fill(ellipse);
graphics.setColor(c);
graphics.draw(ellipse);
if (!state.getValue().equals("")) {
Font tmpFont = graphics.getFont();
Font font = new Font(Font.SANS_SERIF, 0, state.getFontSize().intValue());
graphics.setFont(font);
width = graphics.getFontMetrics().stringWidth(state.getValue());
height = graphics.getFontMetrics().getAscent() - graphics.getFontMetrics().getDescent();
double x = state.getPosition().getX() + (state.getWidth() - width) / 2;
double y = state.getPosition().getY() + (state.getHeight() + height) / 2;
graphics.drawString(state.getValue(), (int) x, (int) y);
graphics.setFont(tmpFont);
}
}
Shape getStructuralStateShape(final StructuralState state) {
return new Ellipse2D.Double(state.getPosition().getX(), state.getPosition().getY(), state.getWidth(),
state.getHeight());
}
/**
* Draws unit of information for the {@link Species} (rectangle in the top
* part of the alias).
......
package lcsb.mapviewer.converter.graphics.bioentity.element.species;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import lcsb.mapviewer.model.map.species.field.StructuralState;
public class StructuralStateConverter {
public void draw(final StructuralState state, final Graphics2D graphics) {
if (state == null) {
return;
}
double width = state.getWidth();
double height = state.getHeight();
Shape ellipse = getStructuralStateShape(state);
Color c = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fill(ellipse);
graphics.setColor(c);
graphics.draw(ellipse);
if (!state.getValue().equals("")) {
Font tmpFont = graphics.getFont();
Font font = new Font(Font.SANS_SERIF, 0, state.getFontSize().intValue());
graphics.setFont(font);
width = graphics.getFontMetrics().stringWidth(state.getValue());
height = graphics.getFontMetrics().getAscent() - graphics.getFontMetrics().getDescent();
double x = state.getPosition().getX() + (state.getWidth() - width) / 2;
double y = state.getPosition().getY() + (state.getHeight() + height) / 2;
graphics.drawString(state.getValue(), (int) x, (int) y);
graphics.setFont(tmpFont);
}
}
Shape getStructuralStateShape(final StructuralState state) {
return new Ellipse2D.Double(
state.getPosition().getX(),
state.getPosition().getY(),
state.getWidth(),
state.getHeight());
}
}
package lcsb.mapviewer.converter.graphics.bioentity.element.species;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import lcsb.mapviewer.model.map.species.field.StructuralState;
public class StructuralStateSbgnConverter extends StructuralStateConverter {
@Override
Shape getStructuralStateShape(final StructuralState state) {
double arcSize = Math.min(state.getWidth(), state.getHeight());
return new RoundRectangle2D.Double(
state.getPosition().getX(),
state.getPosition().getY(),
state.getWidth(),
state.getHeight(),
arcSize,
arcSize);
}
}
This diff is collapsed.
......@@ -702,6 +702,11 @@ public class ModelFullIndexed implements Model {
public Set<Drawable> getDrawables() {
Set<Drawable> result = new HashSet<>();
result.addAll(getBioEntities());
for (Species species : getSpeciesList()) {
if (species.getStructuralState() != null) {
result.add(species.getStructuralState());
}
}
for (final Layer layer : getLayers()) {
result.addAll(layer.getDrawables());
}
......
......@@ -34,6 +34,7 @@ import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.StructuralState;
public class ModelFullIndexedTest extends ModelTestFunctions {
......@@ -525,4 +526,20 @@ public class ModelFullIndexedTest extends ModelTestFunctions {
assertEquals(2, obj.size());
}
@Test
public void testGetDrawables() {
ModelFullIndexed model = new ModelFullIndexed(null);
Reaction reaction = new Reaction("re");
reaction.setIdReaction("id_r");
model.addReaction(reaction);
Species protein = new GenericProtein("2");
StructuralState state = new StructuralState();
protein.setStructuralState(state);
model.addElement(protein);
assertTrue(model.getDrawables().contains(reaction));
assertTrue(model.getDrawables().contains(protein));
assertTrue(model.getDrawables().contains(state));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment