Skip to content
Snippets Groups Projects
Commit e5bcb7f4 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

copying adds information about comaprtments properly

parent d67bd59c
No related branches found
No related tags found
1 merge request!30Fixes on showing semantic in compartments
......@@ -176,6 +176,7 @@ public class CopyCommand extends NewModelCommand {
if (alias instanceof Compartment) {
Compartment copy = ((Compartment) alias).copy();
copy.getElements().clear();
copy.setCompartment(null);
result.addElement(copy);
}
......@@ -184,21 +185,25 @@ public class CopyCommand extends NewModelCommand {
for (Element alias : model.getElements()) {
if (alias instanceof Species) {
Species copy = ((Species) alias).copy();
Compartment ca = copy.getCompartment();
copy.setCompartment(null);
// the trick is that in addAlias also some connections are added, so
// lets clear info about parents
result.addElement(copy);
if (ca != null) {
ca = result.getElementByElementId(ca.getElementId());
copy.setCompartment(ca);
Compartment parentCompartment = alias.getCompartment();
if (parentCompartment != null) {
parentCompartment = result.getElementByElementId(parentCompartment.getElementId());
copy.setCompartment(parentCompartment);
}
} else if (alias instanceof Compartment) {
// we already added compartment alias
continue;
Compartment parentCompartment = alias.getCompartment();
if (parentCompartment != null) {
Compartment copy = result.getElementByElementId(alias.getElementId());
parentCompartment = result.getElementByElementId(parentCompartment.getElementId());
copy.setCompartment(parentCompartment);
}
} else {
throw new InvalidClassException("Don't know what to do with: " + alias.getClass());
}
......
package lcsb.mapviewer.commands;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.awt.geom.Point2D;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
......@@ -14,8 +18,11 @@ import org.junit.Test;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.OverviewImage;
import lcsb.mapviewer.model.map.OverviewModelLink;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.compartment.SquareCompartment;
import lcsb.mapviewer.model.map.layout.graphics.Layer;
import lcsb.mapviewer.model.map.model.ElementSubmodelConnection;
import lcsb.mapviewer.model.map.model.Model;
......@@ -23,9 +30,12 @@ import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.model.ModelSubmodelConnection;
import lcsb.mapviewer.model.map.model.SubmodelType;
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.Element;
import lcsb.mapviewer.model.map.reaction.type.StateTransitionReaction;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.GenericProtein;
public class CopyCommandTest extends CommandTestFunctions {
......@@ -311,4 +321,57 @@ public class CopyCommandTest extends CommandTestFunctions {
}
}
@Test
public void testCopyModelReaction() throws Exception {
try {
Model model = new ModelFullIndexed(null);
Compartment c1 = new SquareCompartment("c1");
Compartment c2 = new SquareCompartment("c2");
c1.setSemanticZoomLevelVisibility("2");
c2.setSemanticZoomLevelVisibility("3");
model.addElement(c1);
model.addElement(c2);
GenericProtein s1 = new GenericProtein("s1");
s1.setCompartment(c1);
model.addElement(s1);
GenericProtein s2 = new GenericProtein("s2");
s2.setCompartment(c2);
model.addElement(s2);
StateTransitionReaction reaction = new StateTransitionReaction();
Reactant reactant = new Reactant(s1);
reactant.setLine(new PolylineData(new Point2D.Double(0, 0), new Point2D.Double(10, 10)));
reaction.addReactant(reactant);
Product product = new Product(s2);
product.setLine(new PolylineData(new Point2D.Double(10, 0), new Point2D.Double(120, 10)));
reaction.addProduct(product);
reaction.setSemanticZoomLevelVisibility("4");
model.addReaction(reaction);
assertTrue(s1.equals(reaction.getReactants().get(0).getElement()));
assertTrue(s2.equals(reaction.getProducts().get(0).getElement()));
Model model2 = new CopyCommand(model).execute();
Reaction reaction2 = model2.getReactions().iterator().next();
assertTrue(s1.equals(reaction.getReactants().get(0).getElement()));
assertTrue(s2.equals(reaction.getProducts().get(0).getElement()));
assertFalse(s1.equals(reaction2.getReactants().get(0).getElement()));
assertFalse(s2.equals(reaction2.getProducts().get(0).getElement()));
assertNotNull(reaction2.getReactants().get(0).getElement().getCompartment());
assertNotNull(reaction2.getProducts().get(0).getElement().getCompartment());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment