Making curved line control point relative and Importing Freemind relationship lines curve control points

This commit is contained in:
Pablo Luna 2011-01-14 14:10:15 -03:00
parent 8db75a940d
commit 4777ccf6fb
13 changed files with 124 additions and 48 deletions

View File

@ -52,14 +52,14 @@ mindplot.ControlPoint.prototype.setLine= function(line) {
mindplot.ControlPoint.prototype._createControlPoint = function() {
this._controls= this._line.getLine().getControlPoints();
this._controlPointsController[0].setPosition(this._controls[mindplot.ControlPoint.FROM].x, this._controls[mindplot.ControlPoint.FROM].y-3);
this._controlPointsController[1].setPosition(this._controls[mindplot.ControlPoint.TO].x, this._controls[mindplot.ControlPoint.TO].y-3);
var pos = this._line.getLine().getFrom();
this._controlPointsController[0].setPosition(this._controls[mindplot.ControlPoint.FROM].x+pos.x, this._controls[mindplot.ControlPoint.FROM].y+pos.y-3);
this._controlLines[0].setFrom(pos.x, pos.y);
this._controlLines[0].setTo(this._controls[mindplot.ControlPoint.FROM].x+3, this._controls[mindplot.ControlPoint.FROM].y);
this._controlLines[0].setTo(this._controls[mindplot.ControlPoint.FROM].x+pos.x+3, this._controls[mindplot.ControlPoint.FROM].y+pos.y);
pos = this._line.getLine().getTo();
this._controlLines[1].setFrom(pos.x, pos.y);
this._controlLines[1].setTo(this._controls[mindplot.ControlPoint.TO].x+3, this._controls[mindplot.ControlPoint.TO].y);
this._controlLines[1].setTo(this._controls[mindplot.ControlPoint.TO].x+pos.x+3, this._controls[mindplot.ControlPoint.TO].y+pos.y);
this._controlPointsController[1].setPosition(this._controls[mindplot.ControlPoint.TO].x+pos.x, this._controls[mindplot.ControlPoint.TO].y+pos.y-3);
};
@ -91,8 +91,8 @@ mindplot.ControlPoint.prototype._mouseMove = function(event, point) {
var cords = core.Utils.calculateRelationShipPointCoordinates(this._line.getTargetTopic(),pos);
this._line.getLine().setTo(cords.x, cords.y);
}
this._controls[point].x=pos.x;
this._controls[point].y=pos.y;
this._controls[point].x=(pos.x - cords.x);
this._controls[point].y=(pos.y - cords.y);
this._controlPointsController[point].setPosition(pos.x-5,pos.y-3);
this._controlLines[point].setFrom(cords.x, cords.y);
this._controlLines[point].setTo(pos.x-2,pos.y);

View File

@ -30,14 +30,20 @@ mindplot.RelationshipLine.prototype.redraw = function()
this._line2d.setStroke(2);
var ctrlPoints = this._line2d.getControlPoints();
if(!core.Utils.isDefined(ctrlPoints[0].x) || !core.Utils.isDefined(ctrlPoints[1].x)){
var defaultPoints = core.Utils.calculateDefaultControlPoints(sourceTopic.getPosition(), targetTopic.getPosition());
ctrlPoints[0].x=defaultPoints[0].x;
ctrlPoints[0].y=defaultPoints[0].y;
ctrlPoints[1].x=defaultPoints[1].x;
ctrlPoints[1].y=defaultPoints[1].y;
var defaultPoints = core.Utils.calculateDefaultControlPoints(sourcePosition, targetPosition);
ctrlPoints[0].x=sourcePosition.x - defaultPoints[0].x;
ctrlPoints[0].y=sourcePosition.y - defaultPoints[0].y;
ctrlPoints[1].x=targetPosition.x - defaultPoints[1].x;
ctrlPoints[1].y=targetPosition.y - defaultPoints[1].y;
}
sPos = core.Utils.calculateRelationShipPointCoordinates(sourceTopic,ctrlPoints[0]);
tPos = core.Utils.calculateRelationShipPointCoordinates(targetTopic,ctrlPoints[1]);
var spoint = new core.Point();
spoint.x=parseInt(ctrlPoints[0].x)+parseInt(sourcePosition.x);
spoint.y=parseInt(ctrlPoints[0].y)+parseInt(sourcePosition.y);
var tpoint = new core.Point();
tpoint.x=parseInt(ctrlPoints[1].x)+parseInt(targetPosition.x);
tpoint.y=parseInt(ctrlPoints[1].y)+parseInt(targetPosition.y);
sPos = core.Utils.calculateRelationShipPointCoordinates(sourceTopic,spoint);
tPos = core.Utils.calculateRelationShipPointCoordinates(targetTopic,tpoint);
line2d.setFrom(sPos.x, sPos.y);
line2d.setTo(tPos.x, tPos.y);

View File

@ -10,6 +10,7 @@ mindplot.RelationshipModel = function(fromNode, toNode)
this._srcCtrlPoint=null;
this._destCtrlPoint=null;
this._endArrow=true;
this._ctrlPointRelative=false;
};

View File

@ -36,6 +36,8 @@ web2d.peer.svg.CurvedLinePeer.prototype.setSrcControlPoint = function(control){
this._customControlPoint_1 = true;
if(core.Utils.isDefined(control.x)){
this._control1 = control;
this._control1.x = parseInt(this._control1.x);
this._control1.y = parseInt(this._control1.y)
}
this._updatePath();
};
@ -44,6 +46,8 @@ web2d.peer.svg.CurvedLinePeer.prototype.setDestControlPoint = function(control){
this._customControlPoint_2 = true;
if(core.Utils.isDefined(control.x)){
this._control2 = control;
this._control2.x = parseInt(this._control2.x);
this._control2.y = parseInt(this._control2.y)
}
this._updatePath();
};
@ -72,23 +76,15 @@ web2d.peer.svg.CurvedLinePeer.prototype.getControlPoints = function(){
web2d.peer.svg.CurvedLinePeer.prototype.setFrom = function(x1, y1)
{
if(this._customControlPoint_1 && core.Utils.isDefined(this._x1)){
this._control1.x-=this._x1-x1;
this._control1.y-=this._y1-y1;
}
this._x1 = x1;
this._y1 = y1;
this._x1 = parseInt(x1);
this._y1 = parseInt(y1);
this._updatePath();
};
web2d.peer.svg.CurvedLinePeer.prototype.setTo = function(x2, y2)
{
if(this._customControlPoint_2 && core.Utils.isDefined(this._x2)){
this._control2.x-=this._x2-x2;
this._control2.y-=this._y2-y2;
}
this._x2 = x2;
this._y2 = y2;
this._x2 = parseInt(x2);
this._y2 = parseInt(y2);
this._updatePath();
};
@ -153,8 +149,8 @@ web2d.peer.svg.CurvedLinePeer.prototype._updatePath = function(avoidControlPoint
if(this._showArrow){
if(this._control2.y == 0)
this._control2.y=1;
var y0 = parseInt(this._control2.y) - this._y2;
var x0 = parseInt(this._control2.x) - this._x2;
var y0 = this._control2.y;
var x0 = this._control2.x;
var x2=x0+y0;
var y2 = y0-x0;
var x3 = x0-y0;
@ -171,13 +167,13 @@ web2d.peer.svg.CurvedLinePeer.prototype._updatePath = function(avoidControlPoint
yp = (x3==0?l*Math.sign(y3):mp*xp);
}
var path = "M"+this._x1+","+this._y1
+" C"+this._control1.x+","+this._control1.y+" "
+this._control2.x+","+this._control2.y+" "
+" C"+(this._control1.x+this._x1)+","+(this._control1.y+this._y1)+" "
+(this._control2.x+this._x2)+","+(this._control2.y+this._y2)+" "
+this._x2+","+this._y2+
(this._lineStyle?" "
+this._control2.x+","+(parseInt(this._control2.y)+3)+" "
+this._control1.x+","+(parseInt(this._control1.y)+3)+" "
+this._x1+","+(parseInt(this._y1)+3)+" Z"
+(this._control2.x+this._x2)+","+(this._control2.y+this._y2+3)+" "
+(this._control1.x+this._x1)+","+(this._control1.y+this._y1+3)+" "
+this._x1+","+(this._y1+3)+" Z"
:""
)+
(this._showArrow?" "

View File

@ -76,6 +76,7 @@ public class FreemindImporter
mindmapMap.setName(mapName);
nodesMap = new HashMap<String, TopicType>();
relationships = new ArrayList<RelationshipType>();
nodesMap.put(centralNode.getID(), centralTopic);
addTopicFromNode(centralNode,centralTopic);
fixCentralTopicChildOrder(centralTopic);
@ -103,13 +104,53 @@ public class FreemindImporter
List<RelationshipType> mapRelationships = mindmapMap.getRelationship();
for(RelationshipType relationship : relationships){
relationship.setId(String.valueOf(currentId++));
fixRelationshipControlPoints(relationship);
//Fix dest ID
String destId = relationship.getDestTopicId();
TopicType destTopic = nodesMap.get(destId);
relationship.setDestTopicId(destTopic.getId());
//Fix src ID
String srcId = relationship.getSrcTopicId();
TopicType srcTopic = nodesMap.get(srcId);
relationship.setSrcTopicId(srcTopic.getId());
mapRelationships.add(relationship);
}
}
private void fixRelationshipControlPoints(RelationshipType relationship) {
//Both relationship node's ids should be freemind ones at this point.
TopicType srcTopic = nodesMap.get(relationship.getSrcTopicId());
TopicType destTopicType = nodesMap.get(relationship.getDestTopicId());
//Fix x coord
if(isOnLeftSide(srcTopic)){
String[] srcCtrlPoint = relationship.getSrcCtrlPoint().split(",");
int x = Integer.valueOf(srcCtrlPoint[0]) * -1;
relationship.setSrcCtrlPoint(x+","+srcCtrlPoint[1]);
}
if(isOnLeftSide(destTopicType)){
String[] destCtrlPoint = relationship.getDestCtrlPoint().split(",");
int x = Integer.valueOf(destCtrlPoint[0]) * -1;
relationship.setDestCtrlPoint(x+","+destCtrlPoint[1]);
}
//Fix y coord
if(srcTopic.getOrder()%2!=0){ //Odd order.
String[] srcCtrlPoint = relationship.getSrcCtrlPoint().split(",");
int y = Integer.valueOf(srcCtrlPoint[1]) * -1;
relationship.setSrcCtrlPoint(srcCtrlPoint[0]+","+y);
}
if(destTopicType.getOrder()%2!=0){ //Odd order.
String[] destCtrlPoint = relationship.getDestCtrlPoint().split(",");
int y = Integer.valueOf(destCtrlPoint[1]) * -1;
relationship.setDestCtrlPoint(destCtrlPoint[0]+","+y);
}
}
private void fixCentralTopicChildOrder(TopicType centralTopic){
List<TopicType> topics = centralTopic.getTopic();
List<TopicType> leftTopics = new ArrayList<TopicType>();
@ -209,6 +250,9 @@ public class FreemindImporter
link.setUrl(url);
newTopic.setLink(link);
}
if(POSITION_LEFT.equals(mainNode.getPOSITION())){
node.setPOSITION(POSITION_LEFT);
}
setNodePropertiesToTopic(newTopic, node);
addTopicFromNode(node,newTopic);
if (!newTopic.equals(topic))
@ -272,12 +316,13 @@ public class FreemindImporter
final Arrowlink arrow = (Arrowlink) freemindNode;
RelationshipType relationship = mindmapObjectFactory.createRelationshipType();
String destId = arrow.getDESTINATION();
relationship.setSrcTopicId(currentTopic.getId());
relationship.setSrcTopicId(mainNode.getID());
relationship.setDestTopicId(destId);
/*String[] inclination = arrow.getENDINCLINATION().split(";");
String[] inclination = arrow.getENDINCLINATION().split(";");
relationship.setDestCtrlPoint(inclination[0]+","+inclination[1]);
inclination = arrow.getSTARTINCLINATION().split(";");
relationship.setSrcCtrlPoint(inclination[0]+","+inclination[1]);*/
relationship.setSrcCtrlPoint(inclination[0]+","+inclination[1]);
//relationship.setCtrlPointRelative(true);
relationship.setEndArrow(!arrow.getENDARROW().equals("None"));
relationship.setLineType("3");
relationships.add(relationship);

View File

@ -59,6 +59,7 @@
<xsd:attribute name="srcCtrlPoint" type="xsd:string"/>
<xsd:attribute name="destCtrlPoint" type="xsd:string"/>
<xsd:attribute name="endArrow" type="xsd:boolean"/>
<xsd:attribute name="ctrlPointRelative" type="xsd:boolean"/>
</xsd:complexType>
</xsd:schema>

View File

@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.01.11 at 02:17:09 PM ART
// Generated on: 2011.01.11 at 06:58:42 PM ART
//

View File

@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.01.11 at 02:17:09 PM ART
// Generated on: 2011.01.11 at 06:58:42 PM ART
//

View File

@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.01.11 at 02:17:09 PM ART
// Generated on: 2011.01.11 at 06:58:42 PM ART
//

View File

@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.01.11 at 02:17:09 PM ART
// Generated on: 2011.01.11 at 06:58:42 PM ART
//

View File

@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.01.11 at 02:17:09 PM ART
// Generated on: 2011.01.11 at 06:58:42 PM ART
//
@ -42,11 +42,11 @@ public class ObjectFactory {
}
/**
* Create an instance of {@link RelationshipType }
* Create an instance of {@link Note }
*
*/
public RelationshipType createRelationshipType() {
return new RelationshipType();
public Note createNote() {
return new Note();
}
/**
@ -74,11 +74,11 @@ public class ObjectFactory {
}
/**
* Create an instance of {@link Note }
* Create an instance of {@link RelationshipType }
*
*/
public Note createNote() {
return new Note();
public RelationshipType createRelationshipType() {
return new RelationshipType();
}
/**

View File

@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.01.11 at 02:17:09 PM ART
// Generated on: 2011.01.11 at 06:58:42 PM ART
//
@ -30,6 +30,7 @@ import javax.xml.bind.annotation.XmlType;
* &lt;attribute name="srcCtrlPoint" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;attribute name="destCtrlPoint" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;attribute name="endArrow" type="{http://www.w3.org/2001/XMLSchema}boolean" />
* &lt;attribute name="ctrlPointRelative" type="{http://www.w3.org/2001/XMLSchema}boolean" />
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
@ -55,6 +56,8 @@ public class RelationshipType {
protected String destCtrlPoint;
@XmlAttribute
protected Boolean endArrow;
@XmlAttribute
protected Boolean ctrlPointRelative;
/**
* Gets the value of the id property.
@ -224,4 +227,28 @@ public class RelationshipType {
this.endArrow = value;
}
/**
* Gets the value of the ctrlPointRelative property.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isCtrlPointRelative() {
return ctrlPointRelative;
}
/**
* Sets the value of the ctrlPointRelative property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setCtrlPointRelative(Boolean value) {
this.ctrlPointRelative = value;
}
}

View File

@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.01.11 at 02:17:09 PM ART
// Generated on: 2011.01.11 at 06:58:42 PM ART
//