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

custom semantic zoom can control transparency levels

parent 6835036b
No related branches found
No related tags found
2 merge requests!412changes from 12.1.0~beta.1 into master,!402Resolve "Custom semantic zoom - set transparency level"
Pipeline #6413 passed
......@@ -123,7 +123,13 @@ public enum NoteField {
/**
* {@link Element#getSemanticZoomLevelVisibility()}.
*/
SEMANTIC_ZOOM_LEVEL_VISIBILITY("SemanticZoomLevelVisibility", BioEntity.class, null); //
SEMANTIC_ZOOM_LEVEL_VISIBILITY("SemanticZoomLevelVisibility", BioEntity.class, null),
/**
* {@link Element#getSemanticZoomLevelVisibility()}.
*/
TRANSPARENCY_ZOOM_LEVEL_VISIBILITY("TransparencyZoomLevelVisibility", Element.class, null),
; //
/**
* Name used in the notes to distinguish fields.
......
......@@ -628,27 +628,41 @@ public class RestAnnotationParser extends XmlParser {
}
}
/**
* Assigns semanticZoomingLevel to the element from notes string.
*
* @param element
* element to which data should be put to
* @param annotationString
* notes string
*/
private void setSemanticZoomLevelVisibility(BioEntity element, String annotationString) {
String zoomLevelVisibility = getParamByPrefix(annotationString, NoteField.SEMANTIC_ZOOM_LEVEL_VISIBILITY.getCommonName() + ":");
if (zoomLevelVisibility == null) {
return;
}
if (element.getVisibilityLevel() == null || element.getVisibilityLevel().isEmpty()) {
element.setVisibilityLevel(zoomLevelVisibility);
} else if (!element.getVisibilityLevel().equals(zoomLevelVisibility)) {
logger.warn(
elementUtils.getElementTag(element) + " New " + NoteField.SEMANTIC_ZOOM_LEVEL_VISIBILITY.getCommonName() + " different than default ["
+ zoomLevelVisibility + "][" + element.getVisibilityLevel() + "]. Ignoring.");
}
}
/**
* Assigns semanticZoomingLevel to the element from notes string.
*
* @param element
* element to which data should be put to
* @param annotationString
* notes string
*/
private void setSemanticZoomLevelVisibility(BioEntity element, String annotationString) {
String zoomLevelVisibility = getParamByPrefix(annotationString, NoteField.SEMANTIC_ZOOM_LEVEL_VISIBILITY.getCommonName() + ":");
if (zoomLevelVisibility == null) {
return;
}
if (element.getVisibilityLevel() == null || element.getVisibilityLevel().isEmpty()) {
element.setVisibilityLevel(zoomLevelVisibility);
} else if (!element.getVisibilityLevel().equals(zoomLevelVisibility)) {
logger.warn(
elementUtils.getElementTag(element) + " New " + NoteField.SEMANTIC_ZOOM_LEVEL_VISIBILITY.getCommonName() + " different than default ["
+ zoomLevelVisibility + "][" + element.getVisibilityLevel() + "]. Ignoring.");
}
}
private void setTransparencyZoomLevelVisibility(Element element, String annotationString) {
String transparencyZoomLevelVisibility = getParamByPrefix(annotationString, NoteField.TRANSPARENCY_ZOOM_LEVEL_VISIBILITY.getCommonName() + ":");
if (transparencyZoomLevelVisibility == null) {
return;
}
if (element.getTransparencyLevel() == null || element.getTransparencyLevel().isEmpty()) {
element.setTransparencyLevel(transparencyZoomLevelVisibility);
} else if (!element.getTransparencyLevel().equals(transparencyZoomLevelVisibility)) {
logger.warn(
elementUtils.getElementTag(element) + " New " + NoteField.TRANSPARENCY_ZOOM_LEVEL_VISIBILITY.getCommonName() + " different than default ["
+ transparencyZoomLevelVisibility + "][" + element.getVisibilityLevel() + "]. Ignoring.");
}
}
/**
* Assigns notes to the element from notes string. This might look strange.
......@@ -719,6 +733,7 @@ public class RestAnnotationParser extends XmlParser {
setSubsystemToReaction(reaction, ann);
setGeneProteinReactionToReaction(reaction, ann);
} else if (object instanceof Element) {
setTransparencyZoomLevelVisibility((Element)object, ann);
setFullNameToSpecies((Element) object, ann);
setFormerSymbolsToSpecies((Element) object, ann);
if (object instanceof Species) {
......
......@@ -87,6 +87,18 @@ public class CellDesignerXmlParserTest extends CellDesignerTestFunctions {
}
}
@Test
public void testParseTransparency() throws Exception {
try {
CellDesignerXmlParser parser = new CellDesignerXmlParser();
Model model = parser.createModel(new ConverterParams().filename("testFiles/model_with_transparency.xml"));
assertFalse(model.getCompartments().get(0).getTransparencyLevel().isEmpty());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testOpenFromInvalidFile() throws Exception {
try {
......
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level2/version4" xmlns:celldesigner="http://www.sbml.org/2001/ns/celldesigner" level="2" version="4">
<model metaid="untitled" id="untitled">
<annotation>
<celldesigner:extension>
<celldesigner:modelVersion>4.0</celldesigner:modelVersion>
<celldesigner:modelDisplay sizeX="600" sizeY="400"/>
<celldesigner:listOfCompartmentAliases>
<celldesigner:compartmentAlias id="ca1" compartment="c1">
<celldesigner:class>SQUARE</celldesigner:class>
<celldesigner:bounds x="15.0" y="73.0" w="137.0" h="153.0"/>
<celldesigner:namePoint x="75.0" y="190.5"/>
<celldesigner:doubleLine thickness="12.0" outerWidth="2.0" innerWidth="1.0"/>
<celldesigner:paint color="ffcccc00" scheme="Color"/>
<celldesigner:info state="empty" angle="-1.5707963267948966"/>
</celldesigner:compartmentAlias>
<celldesigner:compartmentAlias id="ca3" compartment="c3">
<celldesigner:class>SQUARE</celldesigner:class>
<celldesigner:bounds x="176.0" y="30.0" w="203.0" h="129.0"/>
<celldesigner:namePoint x="269.0" y="123.5"/>
<celldesigner:doubleLine thickness="12.0" outerWidth="2.0" innerWidth="1.0"/>
<celldesigner:paint color="ffcccc00" scheme="Color"/>
<celldesigner:info state="empty" angle="-1.5707963267948966"/>
</celldesigner:compartmentAlias>
<celldesigner:compartmentAlias id="ca4" compartment="c4">
<celldesigner:class>SQUARE</celldesigner:class>
<celldesigner:bounds x="443.0" y="69.0" w="149.0" h="178.0"/>
<celldesigner:namePoint x="509.0" y="211.5"/>
<celldesigner:doubleLine thickness="12.0" outerWidth="2.0" innerWidth="1.0"/>
<celldesigner:paint color="ffcccc00" scheme="Color"/>
<celldesigner:info state="empty" angle="-1.5707963267948966"/>
</celldesigner:compartmentAlias>
<celldesigner:compartmentAlias id="ca5" compartment="c5">
<celldesigner:class>SQUARE</celldesigner:class>
<celldesigner:bounds x="197.0" y="219.0" w="186.0" h="129.0"/>
<celldesigner:namePoint x="281.5" y="312.5"/>
<celldesigner:doubleLine thickness="12.0" outerWidth="2.0" innerWidth="1.0"/>
<celldesigner:paint color="ffcccc00" scheme="Color"/>
<celldesigner:info state="empty" angle="-1.5707963267948966"/>
</celldesigner:compartmentAlias>
</celldesigner:listOfCompartmentAliases>
<celldesigner:listOfComplexSpeciesAliases/>
<celldesigner:listOfSpeciesAliases>
<celldesigner:speciesAlias id="sa1" species="s1" compartmentAlias="ca1">
<celldesigner:activity>inactive</celldesigner:activity>
<celldesigner:bounds x="34.0" y="121.0" w="80.0" h="40.0"/>
<celldesigner:font size="12"/>
<celldesigner:view state="usual"/>
<celldesigner:usualView>
<celldesigner:innerPosition x="19.0" y="48.0"/>
<celldesigner:boxSize width="80.0" height="40.0"/>
<celldesigner:singleLine width="1.0"/>
<celldesigner:paint color="ffccffcc" scheme="Color"/>
</celldesigner:usualView>
<celldesigner:briefView>
<celldesigner:innerPosition x="0.0" y="0.0"/>
<celldesigner:boxSize width="80.0" height="60.0"/>
<celldesigner:singleLine width="0.0"/>
<celldesigner:paint color="3fff0000" scheme="Color"/>
</celldesigner:briefView>
<celldesigner:info state="empty" angle="-1.5707963267948966"/>
</celldesigner:speciesAlias>
<celldesigner:speciesAlias id="sa2" species="s2" compartmentAlias="ca3">
<celldesigner:activity>inactive</celldesigner:activity>
<celldesigner:bounds x="233.0" y="57.0" w="80.0" h="40.0"/>
<celldesigner:font size="12"/>
<celldesigner:view state="usual"/>
<celldesigner:usualView>
<celldesigner:innerPosition x="57.0" y="27.0"/>
<celldesigner:boxSize width="80.0" height="40.0"/>
<celldesigner:singleLine width="1.0"/>
<celldesigner:paint color="ffccffcc" scheme="Color"/>
</celldesigner:usualView>
<celldesigner:briefView>
<celldesigner:innerPosition x="0.0" y="0.0"/>
<celldesigner:boxSize width="80.0" height="60.0"/>
<celldesigner:singleLine width="0.0"/>
<celldesigner:paint color="3fff0000" scheme="Color"/>
</celldesigner:briefView>
<celldesigner:info state="empty" angle="-1.5707963267948966"/>
</celldesigner:speciesAlias>
<celldesigner:speciesAlias id="sa3" species="s3" compartmentAlias="ca4">
<celldesigner:activity>inactive</celldesigner:activity>
<celldesigner:bounds x="473.0" y="137.0" w="80.0" h="40.0"/>
<celldesigner:font size="12"/>
<celldesigner:view state="usual"/>
<celldesigner:usualView>
<celldesigner:innerPosition x="30.0" y="68.0"/>
<celldesigner:boxSize width="80.0" height="40.0"/>
<celldesigner:singleLine width="1.0"/>
<celldesigner:paint color="ffccffcc" scheme="Color"/>
</celldesigner:usualView>
<celldesigner:briefView>
<celldesigner:innerPosition x="0.0" y="0.0"/>
<celldesigner:boxSize width="80.0" height="60.0"/>
<celldesigner:singleLine width="0.0"/>
<celldesigner:paint color="3fff0000" scheme="Color"/>
</celldesigner:briefView>
<celldesigner:info state="empty" angle="-1.5707963267948966"/>
</celldesigner:speciesAlias>
<celldesigner:speciesAlias id="sa4" species="s4" compartmentAlias="ca5">
<celldesigner:activity>inactive</celldesigner:activity>
<celldesigner:bounds x="277.0" y="263.0" w="80.0" h="40.0"/>
<celldesigner:font size="12"/>
<celldesigner:view state="usual"/>
<celldesigner:usualView>
<celldesigner:innerPosition x="80.0" y="44.0"/>
<celldesigner:boxSize width="80.0" height="40.0"/>
<celldesigner:singleLine width="1.0"/>
<celldesigner:paint color="ffccffcc" scheme="Color"/>
</celldesigner:usualView>
<celldesigner:briefView>
<celldesigner:innerPosition x="0.0" y="0.0"/>
<celldesigner:boxSize width="80.0" height="60.0"/>
<celldesigner:singleLine width="0.0"/>
<celldesigner:paint color="3fff0000" scheme="Color"/>
</celldesigner:briefView>
<celldesigner:info state="empty" angle="-1.5707963267948966"/>
</celldesigner:speciesAlias>
</celldesigner:listOfSpeciesAliases>
<celldesigner:listOfGroups/>
<celldesigner:listOfProteins>
<celldesigner:protein id="pr1" name="s1" type="GENERIC"/>
</celldesigner:listOfProteins>
<celldesigner:listOfGenes/>
<celldesigner:listOfRNAs/>
<celldesigner:listOfAntisenseRNAs/>
<celldesigner:listOfLayers/>
<celldesigner:listOfBlockDiagrams/>
</celldesigner:extension>
</annotation>
<listOfUnitDefinitions>
<unitDefinition metaid="substance" id="substance" name="substance">
<listOfUnits>
<unit metaid="CDMT00001" kind="mole"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="volume" id="volume" name="volume">
<listOfUnits>
<unit metaid="CDMT00002" kind="litre"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="area" id="area" name="area">
<listOfUnits>
<unit metaid="CDMT00003" kind="metre" exponent="2"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="length" id="length" name="length">
<listOfUnits>
<unit metaid="CDMT00004" kind="metre"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="time" id="time" name="time">
<listOfUnits>
<unit metaid="CDMT00005" kind="second"/>
</listOfUnits>
</unitDefinition>
</listOfUnitDefinitions>
<listOfCompartments>
<compartment metaid="default" id="default" size="1" units="volume"/>
<compartment metaid="c1" id="c1" name="c1" size="1" units="volume" outside="default">
<notes>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title/>
</head>
<body>TransparencyZoomLevelVisibility:0
</body>
</html>
</notes>
<annotation>
<celldesigner:extension>
<celldesigner:name>c1</celldesigner:name>
</celldesigner:extension>
</annotation>
</compartment>
<compartment metaid="c3" id="c3" name="c3" size="1" units="volume" outside="default">
<notes>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title/>
</head>
<body>TransparencyZoomLevelVisibility:1
</body>
</html>
</notes>
<annotation>
<celldesigner:extension>
<celldesigner:name>c3</celldesigner:name>
</celldesigner:extension>
</annotation>
</compartment>
<compartment metaid="c4" id="c4" name="c4" size="1" units="volume" outside="default">
<notes>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title/>
</head>
<body>TransparencyZoomLevelVisibility:2
</body>
</html>
</notes>
<annotation>
<celldesigner:extension>
<celldesigner:name>c4</celldesigner:name>
</celldesigner:extension>
</annotation>
</compartment>
<compartment metaid="c5" id="c5" name="c5" size="1" units="volume" outside="default">
<notes>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title/>
</head>
<body>TransparencyZoomLevelVisibility:3
</body>
</html>
</notes>
<annotation>
<celldesigner:extension>
<celldesigner:name>c5</celldesigner:name>
</celldesigner:extension>
</annotation>
</compartment>
</listOfCompartments>
<listOfSpecies>
<species metaid="s1" id="s1" name="s1" compartment="c1" initialAmount="0">
<annotation>
<celldesigner:extension>
<celldesigner:positionToCompartment>inside</celldesigner:positionToCompartment>
<celldesigner:speciesIdentity>
<celldesigner:class>PROTEIN</celldesigner:class>
<celldesigner:proteinReference>pr1</celldesigner:proteinReference>
</celldesigner:speciesIdentity>
</celldesigner:extension>
</annotation>
</species>
<species metaid="s2" id="s2" name="s1" compartment="c3" initialAmount="0">
<annotation>
<celldesigner:extension>
<celldesigner:positionToCompartment>inside</celldesigner:positionToCompartment>
<celldesigner:speciesIdentity>
<celldesigner:class>PROTEIN</celldesigner:class>
<celldesigner:proteinReference>pr1</celldesigner:proteinReference>
</celldesigner:speciesIdentity>
</celldesigner:extension>
</annotation>
</species>
<species metaid="s3" id="s3" name="s1" compartment="c4" initialAmount="0">
<annotation>
<celldesigner:extension>
<celldesigner:positionToCompartment>inside</celldesigner:positionToCompartment>
<celldesigner:speciesIdentity>
<celldesigner:class>PROTEIN</celldesigner:class>
<celldesigner:proteinReference>pr1</celldesigner:proteinReference>
</celldesigner:speciesIdentity>
</celldesigner:extension>
</annotation>
</species>
<species metaid="s4" id="s4" name="s1" compartment="c5" initialAmount="0">
<annotation>
<celldesigner:extension>
<celldesigner:positionToCompartment>inside</celldesigner:positionToCompartment>
<celldesigner:speciesIdentity>
<celldesigner:class>PROTEIN</celldesigner:class>
<celldesigner:proteinReference>pr1</celldesigner:proteinReference>
</celldesigner:speciesIdentity>
</celldesigner:extension>
</annotation>
</species>
</listOfSpecies>
</model>
</sbml>
package lcsb.mapviewer.commands;
import java.util.HashSet;
import java.util.Set;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.species.Element;
/**
* This {@link ModelCommand command} class allows to transform model into
......@@ -16,46 +20,59 @@ import lcsb.mapviewer.model.map.model.Model;
*
*/
public class SetFixedHierarchyLevelCommand extends ModelCommand {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(SetFixedHierarchyLevelCommand.class);
private Integer level;
public SetFixedHierarchyLevelCommand(Model model, Integer level) {
super(model);
this.level = level;
}
@Override
protected void undoImplementation() {
throw new NotImplementedException();
}
@Override
protected void executeImplementation() {
if (!ModelCommandStatus.CREATED.equals(getStatus()) && !ModelCommandStatus.UNDONE.equals(getStatus())) {
throw new InvalidStateException("To execute command, the command must be in CREATED or UNDONE state. " + getStatus() + " found.");
}
if (level != null) {
SemanticZoomLevelMatcher matcher = new SemanticZoomLevelMatcher();
Model output = getModel();
for (BioEntity bioEntity : output.getBioEntities()) {
if (matcher.isVisible(level, bioEntity.getVisibilityLevel())) {
bioEntity.setVisibilityLevel("0");
} else {
bioEntity.setVisibilityLevel(Integer.MAX_VALUE + "");
}
}
}
setStatus(ModelCommandStatus.EXECUTED);
}
@Override
protected void redoImplementation() {
throw new NotImplementedException();
}
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(SetFixedHierarchyLevelCommand.class);
private Integer level;
public SetFixedHierarchyLevelCommand(Model model, Integer level) {
super(model);
this.level = level;
}
@Override
protected void undoImplementation() {
throw new NotImplementedException();
}
@Override
protected void executeImplementation() {
if (!ModelCommandStatus.CREATED.equals(getStatus()) && !ModelCommandStatus.UNDONE.equals(getStatus())) {
throw new InvalidStateException(
"To execute command, the command must be in CREATED or UNDONE state. " + getStatus() + " found.");
}
if (level != null) {
SemanticZoomLevelMatcher matcher = new SemanticZoomLevelMatcher();
Set<Model> models = new HashSet<>();
Model output = getModel();
models.add(output);
models.addAll(output.getSubmodels());
for (Model model : models) {
for (BioEntity bioEntity : model.getBioEntities()) {
if (matcher.isVisible(level, bioEntity.getVisibilityLevel())) {
bioEntity.setVisibilityLevel("0");
} else {
bioEntity.setVisibilityLevel(Integer.MAX_VALUE + "");
}
}
for (Element element : model.getElements()) {
if (matcher.isVisible(level, element.getTransparencyLevel())) {
element.setTransparencyLevel("0");
} else {
element.setTransparencyLevel(Integer.MAX_VALUE + "");
}
}
}
}
setStatus(ModelCommandStatus.EXECUTED);
}
@Override
protected void redoImplementation() {
throw new NotImplementedException();
}
}
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