Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ public ReactionDepiction(RendererModel model,
yOffsetSide = new double[sideGrid.width + 1],
xOffsetSide = new double[sideGrid.height + 1]);

// Retro synthetic swaps the order or reactants/products
if (direction == IReaction.Direction.RETRO_SYNTHETIC) {
List<Bounds> tmp = reactants;
reactants = products;
products = tmp;
}

// build the main components, we add a 'plus' between each molecule
for (Bounds reactant : reactants) {
this.mainComp.add(reactant);
Expand Down Expand Up @@ -305,7 +312,7 @@ public BufferedImage toImg() {

// SIDE COMPONENTS DRAW
xBase += arrowIdx * padding + rescale * xOffsets[arrowIdx];
yBase -= mainCompOffset;
yBase -= mainCompOffset + 2*margin;
for (int i = 0; i < sideComps.size(); i++) {
final int row = i / nSideCol;
final int col = i % nSideCol;
Expand Down Expand Up @@ -460,7 +467,7 @@ String toVecStr(String fmt, String units) {

// SIDE COMPONENTS DRAW
xBase += arrowIdx * padding + rescale * xOffsets[arrowIdx];
yBase -= mainCompOffset;
yBase -= mainCompOffset + 2*margin;
for (int i = 0; i < sideComps.size(); i++) {
final int row = i / nSideCol;
final int col = i % nSideCol;
Expand Down Expand Up @@ -584,9 +591,10 @@ private Bounds createArrow(double minWidth, double minHeight) {
final double headThickness = minHeight / 3;
final double inset = 0.8;
final double headLength = minHeight;
double strokeWidth = minHeight / 14;
switch (direction) {
case FORWARD:
arrow.add(new LineElement(0, 0, minWidth - 0.5 * headLength, 0, minHeight / 14, fgcol));
arrow.add(new LineElement(0, 0, minWidth - 0.5 * headLength, 0, strokeWidth, fgcol));
path.moveTo(minWidth, 0);
path.lineTo(minWidth - headLength, +headThickness);
path.lineTo(minWidth - inset * headLength, 0);
Expand All @@ -595,7 +603,7 @@ private Bounds createArrow(double minWidth, double minHeight) {
arrow.add(GeneralPath.shapeOf(path, fgcol));
break;
case BACKWARD:
arrow.add(new LineElement(0.5 * headLength, 0, minWidth, 0, minHeight / 14, fgcol));
arrow.add(new LineElement(0.5 * headLength, 0, minWidth, 0, strokeWidth, fgcol));
path.moveTo(0, 0);
path.lineTo(minHeight, +headThickness);
path.lineTo(minHeight - (1 - inset) * minHeight, 0);
Expand All @@ -604,13 +612,55 @@ private Bounds createArrow(double minWidth, double minHeight) {
arrow.add(GeneralPath.shapeOf(path, fgcol));
break;
case BIDIRECTIONAL: // equilibrium?
path.moveTo(0, 0.5 * +headThickness);
path.lineTo(minWidth + minHeight + minHeight, 0.5 * +headThickness);
path.lineTo(minWidth + minHeight, 1.5 * +headThickness);
path.moveTo(minWidth + minHeight + minHeight, 0.5 * -headThickness);
path.lineTo(0, 0.5 * -headThickness);
path.lineTo(minHeight, 1.5 * -headThickness);
arrow.add(GeneralPath.outlineOf(path, minHeight / 14, fgcol));

arrow.add(new LineElement(0, +0.5*headThickness, minWidth - 0.5 * headLength, +0.5*headThickness, strokeWidth, fgcol));
path.moveTo(minWidth, 0.5*headThickness-0.5*strokeWidth);
path.lineTo(minWidth - headLength, 1.5*headThickness);
path.lineTo(minWidth - inset * headLength, 0.5*headThickness-0.5*strokeWidth);
path.closePath();

arrow.add(new LineElement(0.5 * headLength, -0.5*headThickness, minWidth, -0.5*headThickness, strokeWidth, fgcol));
path.moveTo(0, -0.5*headThickness+0.5*strokeWidth);
path.lineTo(+headLength, -1.5*headThickness);
path.lineTo(inset * headLength, -0.5*headThickness+0.5*strokeWidth);
path.closePath();
arrow.add(GeneralPath.shapeOf(path, fgcol));
break;
case NO_GO: // crossed arrow
arrow.add(new LineElement(0, 0, minWidth - 0.5 * headLength, 0, strokeWidth, fgcol));
path.moveTo(minWidth, 0);
path.lineTo(minWidth - headLength, +headThickness);
path.lineTo(minWidth - inset * headLength, 0);
path.lineTo(minWidth - headLength, -headThickness);
path.closePath();
arrow.add(GeneralPath.shapeOf(path, fgcol));
double cx = minWidth/2;
arrow.add(new LineElement(cx-headThickness, -headThickness, cx+headThickness, +headThickness,
strokeWidth, fgcol));
arrow.add(new LineElement(cx-headThickness, +headThickness, cx+headThickness, -headThickness,
strokeWidth, fgcol));
break;
case RETRO_SYNTHETIC: // open arrow
arrow.add(new LineElement(0, -headThickness, minWidth - 0.5 * headLength, -headThickness, strokeWidth, fgcol));
arrow.add(new LineElement(0, +headThickness, minWidth - 0.5 * headLength, +headThickness, strokeWidth, fgcol));
path.moveTo(minWidth-headLength, -2*headThickness);
path.lineTo(minWidth, 0);
path.lineTo(minWidth-headLength, +2*headThickness);
arrow.add(GeneralPath.outlineOf(path, strokeWidth, fgcol));
break;
case RESONANCE:
arrow.add(new LineElement(0, 0, minWidth - 0.5 * headLength, 0, strokeWidth, fgcol));
path.moveTo(minWidth, 0);
path.lineTo(minWidth - headLength, +headThickness);
path.lineTo(minWidth - inset * headLength, 0);
path.lineTo(minWidth - headLength, -headThickness);
path.closePath();
path.moveTo(0, 0);
path.lineTo(minHeight, +headThickness);
path.lineTo(minHeight - (1 - inset) * minHeight, 0);
path.lineTo(minHeight, -headThickness);
path.closePath();
arrow.add(GeneralPath.shapeOf(path, fgcol));
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,24 @@ public interface IReaction extends IChemObject {
* Permissible reaction directions.
*/
enum Direction {
/** Reaction equilibrium which is (almost) fully on the product side. Often denoted with a forward arrow. */
/** Reaction equilibrium which is (almost) fully on the product side.
* Often denoted with a forward arrow. */
FORWARD,
/** Reaction equilibrium which is (almost) fully on the reactant side. Often denoted with a backward arrow. */
/** Reaction equilibrium which is (almost) fully on the reactant side.
* Often denoted with a backward arrow. */
BACKWARD,
/** Reaction equilibrium state. Often denoted by a double arrow. */
BIDIRECTIONAL
/** Reaction equilibrium state. Often denoted by a stacked arrows, one
* forwards, one backwards. */
BIDIRECTIONAL,
/** Reaction is a no-go, Often denoted by a cross or hash arrow. */
NO_GO,
/** Indicate the precursors for a given molecule,
* note this will make swap where reactant/products appear.
* Usually denoted with an open arrow. */
RETRO_SYNTHETIC,
/** Reaction shows interconversion between resonance forms. Usually
* denoted by a double-headed arrow. */
RESONANCE
}

/**
Expand Down