Commit affb89d3 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when providing automatic layout set center line properly

parent 595af049
......@@ -240,16 +240,21 @@ public class ApplySimpleLayoutModelCommand extends ApplyLayoutModelCommand {
Element productElement = reaction.getProducts().get(0).getElement();
Element reactantElement = reaction.getReactants().get(0).getElement();
Point2D middle = getMiddlePoint(productElement.getCenter(), reactantElement.getCenter());
Point2D centerLineStart = getMiddlePoint(reactantElement.getCenter(), productElement.getCenter(), 0.4);
Point2D centerLineEnd = getMiddlePoint(reactantElement.getCenter(), productElement.getCenter(), 0.6);
Point2D middle = getMiddlePoint(reactantElement.getCenter(), productElement.getCenter(), 0.5);
// for self reactions
if (productElement.equals(reactantElement)) {
middle.setLocation(middle.getX(), middle.getY() + 50);
centerLineStart.setLocation(centerLineStart.getX(), centerLineStart.getY() + 50);
centerLineEnd.setLocation(centerLineStart.getX(), centerLineEnd.getY() + 50);
}
modifyProducts(reaction, middle);
modifyReactants(reaction, middle);
modifyReactants(reaction, centerLineStart);
modifyProducts(reaction, centerLineEnd);
modifyModifiers(reaction, middle);
reaction.setLine(new PolylineData(centerLineStart, centerLineEnd));
if (super.isAddReactionPrefixes()) {
super.getModel().removeReaction(reaction);
......@@ -258,7 +263,7 @@ public class ApplySimpleLayoutModelCommand extends ApplyLayoutModelCommand {
}
}
private Point2D.Double getMiddlePoint(Point2D middle, Point2D productPoint) {
private Point2D.Double getMiddlePoint(Point2D middle, Point2D productPoint, double coef) {
return new Point2D.Double((productPoint.getX() + middle.getX()) / 2, (productPoint.getY() + middle.getY()) / 2);
}
......@@ -271,7 +276,7 @@ public class ApplySimpleLayoutModelCommand extends ApplyLayoutModelCommand {
operator = new AndOperator();
}
Point2D productPoint = reaction.getReactants().get(0).getElement().getCenter();
Point2D operatorPoint = getMiddlePoint(middle, productPoint);
Point2D operatorPoint = getMiddlePoint(middle, productPoint, 0.5);
operator.setLine(new PolylineData(operatorPoint, middle));
reaction.addNode(operator);
middle = operatorPoint;
......@@ -310,7 +315,7 @@ public class ApplySimpleLayoutModelCommand extends ApplyLayoutModelCommand {
operator = new SplitOperator();
}
Point2D productPoint = reaction.getProducts().get(0).getElement().getCenter();
Point2D operatorPoint = getMiddlePoint(middle, productPoint);
Point2D operatorPoint = getMiddlePoint(middle, productPoint, 0.5);
operator.setLine(new PolylineData(operatorPoint, middle));
reaction.addNode(operator);
middle = operatorPoint;
......
......@@ -16,6 +16,7 @@ import java.util.Set;
import org.junit.Test;
import lcsb.mapviewer.commands.CommandExecutionException;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.geometry.DoubleDimension;
import lcsb.mapviewer.model.map.BioEntity;
......@@ -23,6 +24,10 @@ import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.compartment.SquareCompartment;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
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.type.TransportReaction;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.GenericProtein;
......@@ -375,4 +380,35 @@ public class ApplySimpleLayoutModelCommandTest {
Math.abs(rect.getMaxX() - resultPoint.getX()) < Configuration.EPSILON);
}
@Test
public void testApplyLayoutForReaction() throws CommandExecutionException {
try {
Model model = new ModelFullIndexed(null);
Protein protein = createProtein();
model.addElement(protein);
Protein protein2 = createProtein();
model.addElement(protein2);
Reaction reaction = createReaction(protein, protein2);
model.addReaction(reaction);
ApplySimpleLayoutModelCommand layoutModelCommand = new ApplySimpleLayoutModelCommand(model);
layoutModelCommand.execute();
assertNotNull("Reactant doesn't have line", reaction.getReactants().get(0).getLine());
assertNotNull("Product doesn't have line", reaction.getProducts().get(0).getLine());
assertNotNull("Reaction doesn't have line", reaction.getLine());
} catch (CommandExecutionException e) {
e.printStackTrace();
throw e;
}
}
private Reaction createReaction(Protein protein, Protein protein2) {
Reaction reaction = new TransportReaction();
reaction.addReactant(new Reactant(protein));
reaction.addProduct(new Product(protein2));
return reaction;
}
}
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