From: <gil...@us...> - 2008-11-27 22:58:44
|
Revision: 13358 http://cdk.svn.sourceforge.net/cdk/?rev=13358&view=rev Author: gilleain Date: 2008-11-27 22:58:39 +0000 (Thu, 27 Nov 2008) Log Message: ----------- Filled wedge bonds now render. Modified Paths: -------------- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/IntermediateRenderer.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/generators/BasicBondGenerator.java Added Paths: ----------- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/AlterBondStereoModule.java Added: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/AlterBondStereoModule.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/AlterBondStereoModule.java (rev 0) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/AlterBondStereoModule.java 2008-11-27 22:58:39 UTC (rev 13358) @@ -0,0 +1,70 @@ +/* $Revision$ $Author$ $Date$ + * + * Copyright (C) 2008 Gilleain Torrance <gil...@gm...> + * + * Contact: cdk...@li... + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * All I ask is that proper credit is given for my work, which includes + * - but is not limited to - adding the above copyright notice to the beginning + * of your source code files, and to any copyright notice that you may distribute + * with programs based on this work. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk.controller; + +import javax.vecmath.Point2d; + +import org.openscience.cdk.CDKConstants; +import org.openscience.cdk.interfaces.IBond; + + +/** + * Alters the chirality of a bond, setting it to be into or outof the plane. + * + * @author Gilleain Torrance + * @cdk.svnrev $Revision$ + * @cdk.module control + */ +public class AlterBondStereoModule extends ControllerModuleAdapter { + + public enum Direction { UP, DOWN }; + private Direction direction; + + public AlterBondStereoModule(IChemModelRelay chemModelRelay, Direction direction) { + super(chemModelRelay); + this.direction = direction; + } + + public void mouseClickedDown(Point2d worldCoord) { + IBond bond = this.chemModelRelay.getClosestBond(worldCoord); + if (bond != null) { + if (this.direction == Direction.UP) { + bond.setStereo(CDKConstants.STEREO_BOND_UP); + } else { + bond.setStereo(CDKConstants.STEREO_BOND_DOWN); + } + } + chemModelRelay.updateView(); + } + + public void setChemModelRelay(IChemModelRelay relay) { + this.chemModelRelay = relay; + } + + public String getDrawModeString() { + return IControllerModel.DrawMode.ADDATOMORCHANGEELEMENT.getName(); + } + +} Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/IntermediateRenderer.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/IntermediateRenderer.java 2008-11-27 21:36:40 UTC (rev 13357) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/IntermediateRenderer.java 2008-11-27 22:58:39 UTC (rev 13358) @@ -25,12 +25,14 @@ import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Point; +import java.awt.Polygon; import java.awt.Stroke; import java.awt.geom.AffineTransform; import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Rectangle2D; import javax.vecmath.Point2d; +import javax.vecmath.Vector2d; import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IAtomContainer; @@ -82,6 +84,7 @@ } public void paintChemModel(IChemModel chemModel, Graphics2D g, Rectangle2D bounds) { + if (chemModel.getMoleculeSet() == null) return; // calculate the total bounding box Rectangle2D totalBounds = new Rectangle2D.Double(); @@ -275,13 +278,70 @@ this.g.setColor(textElement.color); this.g.drawString(textElement.text, p.x, p.y); } + + public void visit(WedgeLineElement wedge) { - public void visit(WedgeLineElement wedge) { - // TODO : FIXME - int[] a = this.transformPoint(wedge.x1, wedge.y1); - int[] b = this.transformPoint(wedge.x2, wedge.y2); - this.g.drawLine(a[0], a[1], b[0], b[1]); + Vector2d normal = new Vector2d(wedge.y1 - wedge.y2, wedge.x2 - wedge.x1); + normal.normalize(); + normal.scale(0.15); + + Point2d c; + Point2d d; + Point2d e; + // if (wedge.direction == WedgeLineElement.Direction.toSecond) { + c = new Point2d(wedge.x1, wedge.y1); + d = new Point2d(c); + e = new Point2d(wedge.x2, wedge.y2); + // } else { + // c = new Point2d(b[0], b[1]); + // d = new Point2d(b[0], b[1]); + // e = new Point2d(a[0], a[1]); + // } + c.add(normal); + normal.negate(); + d.add(normal); + +// int[] xp = new int[] { (int)e.x, (int)c.x, (int)d.x }; +// int[] yp = new int[] { (int)e.y, (int)c.y, (int)d.y }; + int[] pc = this.transformPoint(c.x, c.y); + int[] pd = this.transformPoint(d.x, d.y); + int[] pe = this.transformPoint(e.x, e.y); + + this.g.setColor(wedge.color); + this.g.fillPolygon(new int[] {pc[0], pd[0], pe[0]}, new int[] {pc[1], pd[1], pe[1]}, 3); } + + +// public void visit(WedgeLineElement wedge) { +// int[] a = this.transformPoint(wedge.x1, wedge.y1); +// int[] b = this.transformPoint(wedge.x2, wedge.y2); +// +// Vector2d normal = new Vector2d(b[1] - a[1], a[0] - b[0]); +// normal.normalize(); +// normal.scale(wedge.width * 2); +// +// Point2d c; +// Point2d d; +// Point2d e; +//// if (wedge.direction == WedgeLineElement.Direction.toSecond) { +// c = new Point2d(a[0], a[1]); +// d = new Point2d(a[0], a[1]); +// e = new Point2d(b[0], b[1]); +//// } else { +//// c = new Point2d(b[0], b[1]); +//// d = new Point2d(b[0], b[1]); +//// e = new Point2d(a[0], a[1]); +//// } +// c.add(normal); +// normal.negate(); +// d.add(normal); +// +// int[] xp = new int[] { (int)e.x, (int)c.x, (int)d.x }; +// int[] yp = new int[] { (int)e.y, (int)c.y, (int)d.y }; +// +// this.g.setColor(wedge.color); +// this.g.fillPolygon(xp, yp, 3); +// } public void visit(AtomSymbolElement atomSymbol) { this.g.setFont(this.fontManager.getFont()); @@ -331,6 +391,8 @@ public void visit(IRenderingElement element) { if (element instanceof ElementGroup) visit((ElementGroup) element); + else if (element instanceof WedgeLineElement) + visit((WedgeLineElement) element); else if (element instanceof LineElement) visit((LineElement) element); else if (element instanceof OvalElement) @@ -339,8 +401,6 @@ visit((AtomSymbolElement) element); else if (element instanceof TextElement) visit((TextElement) element); - else if (element instanceof WedgeLineElement) - visit((WedgeLineElement) element); else if (element instanceof RectangleElement) visit((RectangleElement) element); else Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/generators/BasicBondGenerator.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/generators/BasicBondGenerator.java 2008-11-27 21:36:40 UTC (rev 13357) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/generators/BasicBondGenerator.java 2008-11-27 22:58:39 UTC (rev 13358) @@ -238,7 +238,6 @@ dir = Direction.toFirst; IRenderingElement base = generateBondElement(bond, IBond.Order.SINGLE); - // XXX return new WedgeLineElement((LineElement)base, dashed, dir, this.getColorForBond(bond)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |