2424
2525package org .openscience .cdk .renderer .generators .standard ;
2626
27+ import org .openscience .cdk .CDKConstants ;
28+ import org .openscience .cdk .geometry .GeometryUtil ;
2729import org .openscience .cdk .interfaces .IAtom ;
2830import org .openscience .cdk .interfaces .IAtomContainer ;
2931import org .openscience .cdk .interfaces .IBond ;
4547import org .openscience .cdk .renderer .generators .IGenerator ;
4648import org .openscience .cdk .renderer .generators .IGeneratorParameter ;
4749import org .openscience .cdk .renderer .generators .parameter .AbstractGeneratorParameter ;
50+ import org .openscience .cdk .sgroup .Sgroup ;
51+ import org .openscience .cdk .sgroup .SgroupType ;
4852
4953import javax .vecmath .Point2d ;
5054import javax .vecmath .Vector2d ;
@@ -504,12 +508,12 @@ private AtomSymbol[] generateAtomSymbols(IAtomContainer container,
504508 new ArrayList <Vector2d >());
505509
506510 final TextOutline outline = generateAnnotation (atom .getPoint2d (),
507- Integer .toString (attachNum ),
508- vector ,
509- 1.75 * annDist + strokeAdjust ,
510- annScale ,
511- font .deriveFont (Font .BOLD ),
512- null );
511+ Integer .toString (attachNum ),
512+ vector ,
513+ 1.75 * annDist + strokeAdjust ,
514+ annScale ,
515+ font .deriveFont (Font .BOLD ),
516+ null );
513517
514518 attachNumOutlines .add (outline );
515519
@@ -522,7 +526,7 @@ private AtomSymbol[] generateAtomSymbols(IAtomContainer container,
522526
523527 for (TextOutline outline : attachNumOutlines ) {
524528 ElementGroup group = new ElementGroup ();
525- double radius = 2 *stroke + maxRadius ;
529+ double radius = 1. 2 *stroke + maxRadius ;
526530 Shape shape = new Ellipse2D .Double (outline .getCenter ().getX () - radius ,
527531 outline .getCenter ().getY () - radius ,
528532 2 *radius ,
@@ -532,7 +536,55 @@ private AtomSymbol[] generateAtomSymbols(IAtomContainer container,
532536 group .add (GeneralPath .shapeOf (area1 , foreground ));
533537 annotations .add (group );
534538 }
539+ }
540+
541+ // ligand/attachment ordering annotations on bonds
542+ List <Sgroup > sgroups = container .getProperty (CDKConstants .CTAB_SGROUPS );
543+ if (sgroups != null ) {
544+
545+ List <TextOutline > attachNumOutlines = new ArrayList <>();
546+ double maxRadius = 0 ;
547+
548+ for (Sgroup sgroup : sgroups ) {
549+ if (sgroup .getType () == SgroupType .ExtAttachOrdering ) {
550+ int number = 1 ;
551+ for (IBond bond : sgroup .getBonds ()) {
552+ Point2d beg = bond .getBegin ().getPoint2d ();
553+ Point2d end = bond .getEnd ().getPoint2d ();
554+ Point2d mid = VecmathUtil .midpoint (beg , end );
555+
556+ final TextOutline outline = generateAnnotation (mid ,
557+ Integer .toString (number ++),
558+ new Vector2d (0 ,0 ),
559+ 0 ,
560+ annScale ,
561+ font .deriveFont (Font .BOLD ),
562+ null );
563+
564+ attachNumOutlines .add (outline );
565+
566+ double w = outline .getBounds ().getWidth ();
567+ double h = outline .getBounds ().getHeight ();
568+ double r = Math .sqrt (w * w + h * h )/2 ;
569+ if (r > maxRadius )
570+ maxRadius = r ;
571+ }
572+ }
573+ }
535574
575+ for (TextOutline outline : attachNumOutlines ) {
576+ ElementGroup group = new ElementGroup ();
577+ double radius = 1.2 *stroke + maxRadius ;
578+ Shape shape = new Ellipse2D .Double (outline .getCenter ().getX () - radius ,
579+ outline .getCenter ().getY () - radius ,
580+ 2 *radius ,
581+ 2 *radius );
582+ Area area1 = new Area (shape );
583+ group .add (GeneralPath .shapeOf (shape , Color .white ));
584+ group .add (GeneralPath .outlineOf (shape , 0.2 *stroke , foreground ));
585+ group .add (GeneralPath .shapeOf (outline .getOutline (), foreground ));
586+ annotations .add (group );
587+ }
536588 }
537589
538590 return symbols ;
0 commit comments