Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug - annotations were not added for single bonds. Add a test to … #819

Merged
merged 1 commit into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ else if (forceDelocalised && bond.isInRing())
* @return bond rendering element
*/
private IRenderingElement generateSingleBond(IBond bond, IAtom from, IAtom to) {

// add annotation label
String label = StandardGenerator.getAnnotationLabel(bond);
if (label != null) addAnnotation(from, to, label);

IBond.Display display = bond.getDisplay();
if (display == null || display == IBond.Display.Solid)
return generatePlainSingleBond(from, to);
Expand All @@ -291,10 +296,6 @@ private IRenderingElement generateSingleBond(IBond bond, IAtom from, IAtom to) {
fromBonds.remove(bond);
toBonds.remove(bond);

// add annotation label
String label = StandardGenerator.getAnnotationLabel(bond);
if (label != null) addAnnotation(from, to, label);

switch (display) {
case WedgedHashBegin:
return generateHashedWedgeBond(from, to, toBonds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@

package org.openscience.cdk.renderer.generators.standard;

import org.junit.Assert;
import org.junit.Test;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.layout.StructureDiagramGenerator;
import org.openscience.cdk.renderer.RendererModel;
import org.openscience.cdk.renderer.elements.ElementGroup;
import org.openscience.cdk.renderer.elements.IRenderingElement;
import org.openscience.cdk.renderer.generators.BasicSceneGenerator;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.templates.TestMoleculeFactory;

import javax.vecmath.Point2d;
import java.awt.*;
import java.util.Map;

import static org.hamcrest.CoreMatchers.is;
Expand Down Expand Up @@ -211,4 +219,35 @@ public void furaneComparedToThiophene() {
assertThat(new RingBondOffsetComparator().compare(thiophene, furane), is(+1));
}

@Test
public void ensureAnnotationsAreGenerator() throws CDKException {
IAtomContainer furane = TestMoleculeFactory.makePyrrole();
for (IBond bond : furane.bonds()) {
bond.setProperty(StandardGenerator.ANNOTATION_LABEL,
1+bond.getIndex());
}
new StructureDiagramGenerator().generateCoordinates(furane);
ElementGroup annotations = new ElementGroup();
Font font = new Font("Arial", Font.PLAIN, 16);
RendererModel model = new RendererModel();
model.registerParameters(new BasicSceneGenerator());
model.registerParameters(new StandardGenerator(font));
int count = 0;
for (IRenderingElement child : annotations)
++count;
Assert.assertEquals(0, count);
StandardBondGenerator.generateBonds(
furane,
new AtomSymbol[furane.getAtomCount()],
model,
1,
font,
annotations,
new StandardDonutGenerator(furane, font, model, 1));
count = 0;
for (IRenderingElement child : annotations)
++count;
Assert.assertEquals(5, count);
}

}