Skip to content

Commit

Permalink
Allow the fancy rendering of wedges to be turned disabled.
Browse files Browse the repository at this point in the history
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Sep 2, 2014
1 parent edf308e commit 968cb50
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 24 deletions.
Expand Up @@ -106,6 +106,7 @@ final class StandardBondGenerator {
private final double wedgeWidth;
private final int hatchSections;
private final Color foreground;
private final boolean fancyBoldWedges, fancyHashedWedges;


/**
Expand Down Expand Up @@ -134,6 +135,8 @@ private StandardBondGenerator(IAtomContainer container, AtomSymbol[] symbols, Re
this.backOff = parameters.get(StandardGenerator.SymbolMarginRatio.class) * stroke;
this.wedgeWidth = parameters.get(StandardGenerator.WedgeRatio.class) * stroke;
this.hatchSections = parameters.get(StandardGenerator.HatchSections.class);
this.fancyBoldWedges = parameters.get(StandardGenerator.FancyBoldWedges.class);
this.fancyHashedWedges = parameters.get(StandardGenerator.FancyHashedWedges.class);

// foreground is based on the carbon color
this.foreground = parameters.get(StandardGenerator.AtomColor.class)
Expand Down Expand Up @@ -279,7 +282,7 @@ IRenderingElement generateBoldWedgeBond(IAtom from, IAtom to, List<IBond> toBond

// if the symbol at the wide end of the wedge is not displayed, we can improve
// the aesthetics by adjusting the endpoints based on connected bond angles.
if (!hasDisplayedSymbol(to)) {
if (fancyBoldWedges && !hasDisplayedSymbol(to)) {

// slanted wedge
if (toBonds.size() == 1) {
Expand Down Expand Up @@ -381,23 +384,25 @@ IRenderingElement generateHashedWedgeBond(IAtom from, IAtom to, List<IBond> toBo
Vector2d hatchAngle = perpendicular;

// fancy hashed wedges with slanted hatch sections aligned with neighboring bonds
if (!hasDisplayedSymbol(to) && toBonds.size() == 1) {
final IBond toBondNeighbor = toBonds.get(0);
final IAtom toNeighbor = toBondNeighbor.getConnectedAtom(to);
if (fancyHashedWedges && !hasDisplayedSymbol(to)) {
if (toBonds.size() == 1) {
final IBond toBondNeighbor = toBonds.get(0);
final IAtom toNeighbor = toBondNeighbor.getConnectedAtom(to);

Vector2d refVector = newUnitVector(toPoint, toNeighbor.getPoint2d());
Vector2d refVector = newUnitVector(toPoint, toNeighbor.getPoint2d());

// special case when wedge bonds are in a bridged ring, wide-to-wide end we
// don't want to slant as normal but rather butt up against each wind end
if (atWideEndOfWedge(to, toBondNeighbor)) {
refVector = sum(refVector, negate(unit));
refVector.normalize();
}
// special case when wedge bonds are in a bridged ring, wide-to-wide end we
// don't want to slant as normal but rather butt up against each wind end
if (atWideEndOfWedge(to, toBondNeighbor)) {
refVector = sum(refVector, negate(unit));
refVector.normalize();
}

// only slant if the angle isn't shallow
if (refVector.angle(unit) > threshold) {
hatchAngle = refVector;
}
// only slant if the angle isn't shallow
if (refVector.angle(unit) > threshold) {
hatchAngle = refVector;
}
}
}

for (int i = 0; i < hatchSections; i++) {
Expand Down
Expand Up @@ -74,7 +74,9 @@ public final class StandardGenerator implements IGenerator<IAtomContainer> {
marginRatio = new SymbolMarginRatio(),
hatchSections = new HatchSections(),
dashSections = new DashSection(),
waveSections = new WaveSections();
waveSections = new WaveSections(),
fancyBoldWedges = new FancyBoldWedges(),
fancyHashedWedges = new FancyHashedWedges();

/**
* Create a new standard generator that utilises the specified font to display atom symbols.
Expand Down Expand Up @@ -196,14 +198,17 @@ private AtomSymbol[] generateAtomSymbols(IAtomContainer container, SymbolVisibil
* @inheritDoc
*/
@Override public List<IGeneratorParameter<?>> getParameters() {
return Arrays.<IGeneratorParameter<?>>asList(atomColor,
visibility,
strokeRatio,
separationRatio,
wedgeRatio,
marginRatio,
hatchSections,
dashSections, waveSections);
return Arrays.asList(atomColor,
visibility,
strokeRatio,
separationRatio,
wedgeRatio,
marginRatio,
hatchSections,
dashSections,
waveSections,
fancyBoldWedges,
fancyHashedWedges);
}

/**
Expand Down Expand Up @@ -379,4 +384,24 @@ public static final class DashSection extends AbstractGeneratorParameter<Integer
}
}

/**
* Modify bold wedges to be flush with adjacent bonds, default = true.
*/
public static final class FancyBoldWedges extends AbstractGeneratorParameter<Boolean> {
/** @inheritDoc */
@Override public Boolean getDefault() {
return true;
}
}

/**
* Modify hashed wedges to be flush when there is a single adjacent bond, default = true.
*/
public static final class FancyHashedWedges extends AbstractGeneratorParameter<Boolean> {
/** @inheritDoc */
@Override public Boolean getDefault() {
return true;
}
}

}

0 comments on commit 968cb50

Please sign in to comment.