9393 */
9494final class StandardBondGenerator {
9595
96- private final IAtomContainer container ;
97- private final AtomSymbol [] symbols ;
98- private final RendererModel parameters ;
96+ private final IAtomContainer container ;
97+ private final AtomSymbol [] symbols ;
98+ private final RendererModel parameters ;
99+ private final StandardDonutGenerator donutGenerator ;
99100
100101 // logging
101102 private final ILoggingTool logger = LoggingToolFactory .createLoggingTool (getClass ());
102103
103104 // indexes of atoms and rings
104105 private final Map <IAtom , Integer > atomIndexMap = new HashMap <IAtom , Integer >();
105106 private final Map <IBond , IAtomContainer > ringMap ;
106- private final Set <IBond > donuts = new HashSet <>();
107107
108108 // parameters
109109 private final double scale ;
@@ -116,7 +116,6 @@ final class StandardBondGenerator {
116116 private final Color foreground , annotationColor ;
117117 private final boolean fancyBoldWedges , fancyHashedWedges ;
118118 private final double annotationDistance , annotationScale ;
119- private final boolean delocalisedDonuts ;
120119 private final Font font ;
121120 private final ElementGroup annotations ;
122121 private final boolean forceDelocalised ;
@@ -131,12 +130,18 @@ final class StandardBondGenerator {
131130 * @param parameters rendering options
132131 * @param stroke scaled stroke width
133132 */
134- private StandardBondGenerator (IAtomContainer container , AtomSymbol [] symbols , RendererModel parameters ,
135- ElementGroup annotations , Font font , double stroke ) {
133+ private StandardBondGenerator (IAtomContainer container ,
134+ AtomSymbol [] symbols ,
135+ RendererModel parameters ,
136+ ElementGroup annotations ,
137+ Font font ,
138+ double stroke ,
139+ StandardDonutGenerator donutGen ) {
136140 this .container = container ;
137141 this .symbols = symbols ;
138142 this .parameters = parameters ;
139143 this .annotations = annotations ;
144+ this .donutGenerator = donutGen ;
140145
141146 // index atoms and rings
142147 for (int i = 0 ; i < container .getAtomCount (); i ++)
@@ -159,7 +164,6 @@ private StandardBondGenerator(IAtomContainer container, AtomSymbol[] symbols, Re
159164 this .annotationScale = (1 / scale ) * parameters .get (StandardGenerator .AnnotationFontScale .class );
160165 this .annotationColor = parameters .get (StandardGenerator .AnnotationColor .class );
161166 this .forceDelocalised = parameters .get (StandardGenerator .ForceDelocalisedBondDisplay .class );
162- this .delocalisedDonuts = parameters .get (StandardGenerator .DelocalisedDonutsBondDisplay .class );
163167 this .font = font ;
164168
165169 // foreground is based on the carbon color
@@ -177,20 +181,18 @@ private StandardBondGenerator(IAtomContainer container, AtomSymbol[] symbols, Re
177181 * @param parameters rendering options
178182 * @param stroke scaled stroke width
179183 */
180- static IRenderingElement [] generateBonds (IAtomContainer container , AtomSymbol [] symbols , RendererModel parameters ,
181- double stroke , Font font , ElementGroup annotations ) {
182- StandardBondGenerator bondGenerator = new StandardBondGenerator (container , symbols , parameters , annotations ,
183- font , stroke );
184- IRenderingElement [] elements ;
185-
186- IRenderingElement donuts = bondGenerator .generateDonuts ();
187- if (donuts != null ) {
188- elements = new IRenderingElement [container .getBondCount ()+1 ];
189- elements [elements .length -1 ] = donuts ;
190- } else {
191- elements = new IRenderingElement [container .getBondCount ()];
192- }
193-
184+ static IRenderingElement [] generateBonds (IAtomContainer container ,
185+ AtomSymbol [] symbols ,
186+ RendererModel parameters ,
187+ double stroke ,
188+ Font font ,
189+ ElementGroup annotations ,
190+ StandardDonutGenerator donutGen ) {
191+ StandardBondGenerator bondGenerator ;
192+ bondGenerator = new StandardBondGenerator (container , symbols ,
193+ parameters , annotations ,
194+ font , stroke , donutGen );
195+ IRenderingElement [] elements = new IRenderingElement [container .getBondCount ()];
194196 for (int i = 0 ; i < container .getBondCount (); i ++) {
195197 final IBond bond = container .getBond (i );
196198 if (!StandardGenerator .isHidden (bond )) {
@@ -200,40 +202,6 @@ static IRenderingElement[] generateBonds(IAtomContainer container, AtomSymbol[]
200202 return elements ;
201203 }
202204
203- boolean canDelocalise (final IAtomContainer ring ) {
204- boolean okay = ring .getBondCount () <= 8 ;
205- if (!okay )
206- return false ;
207- for (IBond bond : ring .bonds ()) {
208- if (!bond .isAromatic ())
209- okay = false ;
210- if ((bond .getOrder () != null &&
211- bond .getOrder () != UNSET ) &&
212- !forceDelocalised )
213- okay = false ;
214- }
215- return okay ;
216- }
217-
218- IRenderingElement generateDonuts () {
219- if (!delocalisedDonuts )
220- return null ;
221- ElementGroup group = new ElementGroup ();
222- Set <IAtomContainer > rings = new HashSet <>(ringMap .values ());
223- for (IAtomContainer ring : rings ) {
224- if (!canDelocalise (ring ))
225- continue ;
226- for (IBond bond : ring .bonds ())
227- donuts .add (bond );
228- Point2d p2 = GeometryUtil .get2DCenter (ring );
229- double s = GeometryUtil .getBondLengthMedian (ring );
230- double n = ring .getBondCount ();
231- double r = s / (2 *Math .tan (Math .PI /n ));
232- group .add (new OvalElement (p2 .x , p2 .y , r -separation , false , foreground ));
233- }
234- return group ;
235- }
236-
237205 /**
238206 * Generate a rendering element for a given bond.
239207 *
@@ -254,7 +222,7 @@ IRenderingElement generate(IBond bond) {
254222 case SINGLE :
255223 // TODO check small ring!
256224 if (bond .isAromatic ()) {
257- if (donuts . contains (bond ))
225+ if (donutGenerator . isDelocalised (bond ))
258226 elem = generateSingleBond (bond , atom1 , atom2 );
259227 else if (forceDelocalised )
260228 elem = generateDoubleBond (bond , forceDelocalised );
@@ -265,7 +233,7 @@ else if (forceDelocalised)
265233 break ;
266234 case DOUBLE :
267235 if (bond .isAromatic ()) {
268- if (donuts . contains (bond ))
236+ if (donutGenerator . isDelocalised (bond ))
269237 elem = generateSingleBond (bond , atom1 , atom2 );
270238 else
271239 elem = generateDoubleBond (bond , forceDelocalised );
@@ -277,7 +245,7 @@ else if (forceDelocalised)
277245 break ;
278246 default :
279247 if (bond .isAromatic () && order == UNSET ) {
280- if (donuts . contains (bond ))
248+ if (donutGenerator . isDelocalised (bond ))
281249 elem = generateSingleBond (bond , atom1 , atom2 );
282250 else
283251 elem = generateDoubleBond (bond , true );
0 commit comments