package fr.orsay.lri.varna.applications.templateEditor; import java.awt.Graphics2D; import java.awt.Polygon; import java.awt.Shape; import java.awt.geom.CubicCurve2D; import java.awt.geom.GeneralPath; import java.awt.geom.Point2D; import java.awt.geom.Point2D.Double; import java.util.ArrayList; import fr.orsay.lri.varna.applications.templateEditor.GraphicalTemplateElement.RelativePosition; import fr.orsay.lri.varna.exceptions.ExceptionEdgeEndpointAlreadyConnected; import fr.orsay.lri.varna.exceptions.ExceptionInvalidRNATemplate; import fr.orsay.lri.varna.models.geom.CubicBezierCurve; import fr.orsay.lri.varna.models.templates.RNATemplate; import fr.orsay.lri.varna.models.templates.RNATemplate.EdgeEndPointPosition; import fr.orsay.lri.varna.models.templates.RNATemplate.RNATemplateElement; import fr.orsay.lri.varna.models.templates.RNATemplate.RNATemplateHelix; import fr.orsay.lri.varna.models.templates.RNATemplate.RNATemplateUnpairedSequence; import fr.orsay.lri.varna.models.templates.RNATemplate.RNATemplateElement.EdgeEndPoint; public class UnpairedRegion extends GraphicalTemplateElement{ private RNATemplateUnpairedSequence _e; public static final double DEFAULT_VECTOR_LENGTH = 35; public static final double DEFAULT_VECTOR_DISTANCE = 35; private Point2D.Double[] sequenceBasesCoords = null; public UnpairedRegion(double x, double y, RNATemplate tmp) { _e = tmp.new RNATemplateUnpairedSequence(""); _e.setVertex5(new Point2D.Double(x,y)); _e.setVertex3(new Point2D.Double(x+DEFAULT_VECTOR_DISTANCE,y)); _e.setInTangentVectorLength(DEFAULT_VECTOR_LENGTH); _e.setInTangentVectorAngle(-Math.PI/2.0); _e.setOutTangentVectorLength(DEFAULT_VECTOR_LENGTH); _e.setOutTangentVectorAngle(-Math.PI/2.0); updateLength(); } /** * Build an UnpairedRegion object from a RNATemplateUnpairedSequence * object. The RNATemplateUnpairedSequence must be connected to * an helix on both sides. */ public UnpairedRegion(RNATemplateUnpairedSequence templateSequence) { _e = templateSequence; } public Point2D.Double getEdge5() { RelativePosition r = RelativePosition.RP_CONNECT_START5; Couple c = getAttachedElement(r); return (isAnchored5()? c.second.getEdgePosition(c.first): _e.getVertex5()); } public Point2D.Double getEdge3() { RelativePosition r = RelativePosition.RP_CONNECT_END3; Couple c = getAttachedElement(r); return (isAnchored3()? c.second.getEdgePosition(c.first): _e.getVertex3()); } public Point2D.Double getCenter() { Point2D.Double p1 = getEdge5(); Point2D.Double p2 = getEdge3(); return new Point2D.Double((p1.x+p2.x)/2.,(p1.y+p2.y)/2.); } public void setEdge5(Point2D.Double d) { _e.setVertex5(d); updateLength(); } public void setEdge3(Point2D.Double d) { _e.setVertex3(d); updateLength(); } public void setCenter(Point2D.Double d) { Point2D.Double p1 = getEdge5(); Point2D.Double p2 = getEdge3(); double dx = p1.x-p2.x; double dy = p1.y-p2.y; _e.setVertex3(new Point2D.Double(d.x-dx/2.,d.y-dy/2.)); _e.setVertex5(new Point2D.Double(d.x+dx/2.,d.y+dy/2.)); invalidateCoords(); } public boolean isAnchored5() { return (_e.getIn().getOtherElement()!=null); } public boolean isAnchored3() { return (_e.getOut().getOtherElement()!=null); } public static Shape bezToShape(CubicBezierCurve c) { GeneralPath p = new GeneralPath(); int nb = 9; double[] tab = new double[nb]; for (int i=0;i> v = new ArrayList>(); v.add(new Couple(p.distance(p5),RelativePosition.RP_CONNECT_START5)); v.add(new Couple(p.distance(p3),RelativePosition.RP_CONNECT_END3)); v.add(new Couple(p.distance(t5),RelativePosition.RP_EDIT_TANGENT_5)); v.add(new Couple(p.distance(t3),RelativePosition.RP_EDIT_TANGENT_3)); v.add(new Couple(p.distance(ct),RelativePosition.RP_INNER_MOVE)); double dist = java.lang.Double.MAX_VALUE; RelativePosition r = RelativePosition.RP_OUTER; for (Couple c : v) { if (c.first c = getAttachedElement(edge); getEndPoint(edge).disconnect(); } // Call the parent class detach function, which will also take care to disconnect this other endpoint of this edge super.detach(edge); } public void setEdgePosition(RelativePosition edge, Point2D.Double pos) { switch(edge) { case RP_CONNECT_START5: setEdge5(pos); break; case RP_INNER_MOVE: setCenter(pos); break; case RP_CONNECT_END3: setEdge3(pos); break; case RP_EDIT_TANGENT_5: updateControl5(pos); break; case RP_EDIT_TANGENT_3: updateControl3(pos); break; } } public ArrayList getConnectedEdges() { ArrayList result = new ArrayList(); result.add(RelativePosition.RP_CONNECT_START5); result.add(RelativePosition.RP_CONNECT_END3); return result; } public RNATemplateElement getTemplateElement() { return _e; } public RelativePosition relativePositionFromEdgeEndPointPosition( EdgeEndPointPosition pos) { switch (pos) { case IN1: return RelativePosition.RP_CONNECT_START5; case OUT1: return RelativePosition.RP_CONNECT_END3; default: return null; } } }