2010-12-13 15:07:20 +01:00
|
|
|
/*
|
2011-07-27 13:25:10 +02:00
|
|
|
* Copyright [2011] [wisemapping]
|
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2010-12-22 23:34:24 +01:00
|
|
|
*/
|
2010-12-13 15:07:20 +01:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
mindplot.ConnectionLine = new Class({
|
|
|
|
initialize:function(sourceNode, targetNode, lineType) {
|
2011-07-27 19:33:02 +02:00
|
|
|
$assert(targetNode, 'parentNode node can not be null');
|
|
|
|
$assert(sourceNode, 'childNode node can not be null');
|
|
|
|
$assert(sourceNode != targetNode, 'Cilcular connection');
|
2011-07-27 13:25:10 +02:00
|
|
|
|
|
|
|
this._targetTopic = targetNode;
|
|
|
|
this._sourceTopic = sourceNode;
|
|
|
|
|
|
|
|
var line;
|
2011-10-09 23:38:41 +02:00
|
|
|
var ctrlPoints = this._getCtrlPoints(sourceNode, targetNode);
|
2011-09-08 15:03:42 +02:00
|
|
|
if (targetNode.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
|
2011-07-27 13:25:10 +02:00
|
|
|
line = this._createLine(lineType, mindplot.ConnectionLine.CURVED);
|
|
|
|
if (line.getType() == "CurvedLine") {
|
|
|
|
line.setSrcControlPoint(ctrlPoints[0]);
|
|
|
|
line.setDestControlPoint(ctrlPoints[1]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
line = this._createLine(lineType, mindplot.ConnectionLine.SIMPLE_CURVED);
|
|
|
|
if (line.getType() == "CurvedLine") {
|
|
|
|
line.setSrcControlPoint(ctrlPoints[0]);
|
|
|
|
line.setDestControlPoint(ctrlPoints[1]);
|
|
|
|
}
|
2011-02-06 14:10:12 +01:00
|
|
|
}
|
2012-01-21 19:47:21 +01:00
|
|
|
// Set line styles ...
|
|
|
|
var strokeColor = mindplot.ConnectionLine.getStrokeColor();
|
|
|
|
line.setStroke(1, 'solid', strokeColor, 1);
|
|
|
|
line.setFill(strokeColor, 1);
|
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
this._line2d = line;
|
|
|
|
},
|
2011-02-06 14:10:12 +01:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
_getCtrlPoints : function(sourceNode, targetNode) {
|
|
|
|
var srcPos = sourceNode.workoutOutgoingConnectionPoint(targetNode.getPosition());
|
|
|
|
var destPos = targetNode.workoutIncomingConnectionPoint(sourceNode.getPosition());
|
|
|
|
var deltaX = (srcPos.x - destPos.x) / 3;
|
|
|
|
return [new core.Point(deltaX, 0), new core.Point(-deltaX, 0)];
|
|
|
|
},
|
2010-12-13 15:07:20 +01:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
_createLine : function(lineType, defaultStyle) {
|
2011-07-27 18:44:09 +02:00
|
|
|
if (!$defined(lineType)) {
|
2011-07-27 13:25:10 +02:00
|
|
|
lineType = defaultStyle;
|
|
|
|
}
|
|
|
|
lineType = parseInt(lineType);
|
|
|
|
this._lineType = lineType;
|
|
|
|
var line = null;
|
|
|
|
switch (lineType) {
|
|
|
|
case mindplot.ConnectionLine.POLYLINE:
|
|
|
|
line = new web2d.PolyLine();
|
|
|
|
break;
|
|
|
|
case mindplot.ConnectionLine.CURVED:
|
|
|
|
line = new web2d.CurvedLine();
|
|
|
|
break;
|
|
|
|
case mindplot.ConnectionLine.SIMPLE_CURVED:
|
|
|
|
line = new web2d.CurvedLine();
|
|
|
|
line.setStyle(web2d.CurvedLine.SIMPLE_LINE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
line = new web2d.Line();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return line;
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
setVisibility : function(value) {
|
|
|
|
this._line2d.setVisibility(value);
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
isVisible : function() {
|
|
|
|
return this._line2d.isVisible();
|
|
|
|
},
|
2011-02-09 15:29:09 +01:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
setOpacity : function(opacity) {
|
|
|
|
this._line2d.setOpacity(opacity);
|
|
|
|
},
|
2011-02-09 15:29:09 +01:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
redraw : function() {
|
|
|
|
var line2d = this._line2d;
|
|
|
|
var sourceTopic = this._sourceTopic;
|
|
|
|
var sourcePosition = sourceTopic.getPosition();
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
var targetTopic = this._targetTopic;
|
|
|
|
var targetPosition = targetTopic.getPosition();
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
var sPos,tPos;
|
2012-01-21 19:30:39 +01:00
|
|
|
sPos = sourceTopic.workoutOutgoingConnectionPoint(targetPosition);
|
|
|
|
tPos = targetTopic.workoutIncomingConnectionPoint(sourcePosition);
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
line2d.setFrom(tPos.x, tPos.y);
|
|
|
|
line2d.setTo(sPos.x, sPos.y);
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
if (line2d.getType() == "CurvedLine") {
|
|
|
|
var ctrlPoints = this._getCtrlPoints(this._sourceTopic, this._targetTopic);
|
|
|
|
line2d.setSrcControlPoint(ctrlPoints[0]);
|
|
|
|
line2d.setDestControlPoint(ctrlPoints[1]);
|
|
|
|
}
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
// Add connector ...
|
|
|
|
this._positionateConnector(targetTopic);
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
_positionateConnector : function(targetTopic) {
|
|
|
|
var targetPosition = targetTopic.getPosition();
|
|
|
|
var offset = mindplot.Topic.CONNECTOR_WIDTH / 2;
|
|
|
|
var targetTopicSize = targetTopic.getSize();
|
|
|
|
var y;
|
2012-02-28 02:47:10 +01:00
|
|
|
if (targetTopic.getShapeType() == mindplot.model.TopicShape.LINE) {
|
2011-07-27 13:25:10 +02:00
|
|
|
y = targetTopicSize.height;
|
|
|
|
} else {
|
|
|
|
y = targetTopicSize.height / 2;
|
|
|
|
}
|
|
|
|
y = y - offset;
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
var connector = targetTopic.getShrinkConnector();
|
|
|
|
if (Math.sign(targetPosition.x) > 0) {
|
|
|
|
var x = targetTopicSize.width;
|
|
|
|
connector.setPosition(x, y);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var x = -mindplot.Topic.CONNECTOR_WIDTH;
|
|
|
|
connector.setPosition(x, y);
|
|
|
|
}
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
setStroke : function(color, style, opacity) {
|
|
|
|
this._line2d.setStroke(null, null, color, opacity);
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
addToWorkspace : function(workspace) {
|
|
|
|
workspace.appendChild(this._line2d);
|
|
|
|
this._line2d.moveToBack();
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
removeFromWorkspace : function(workspace) {
|
|
|
|
workspace.removeChild(this._line2d);
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
getTargetTopic : function() {
|
|
|
|
return this._targetTopic;
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
getSourceTopic : function() {
|
|
|
|
return this._sourceTopic;
|
|
|
|
},
|
2010-12-13 15:07:20 +01:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
getLineType : function() {
|
|
|
|
return this._lineType;
|
|
|
|
},
|
2010-12-13 15:07:20 +01:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
getLine : function() {
|
|
|
|
return this._line2d;
|
|
|
|
},
|
2010-12-13 15:07:20 +01:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
getModel : function() {
|
|
|
|
return this._model;
|
|
|
|
},
|
2010-12-13 15:07:20 +01:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
setModel : function(model) {
|
|
|
|
this._model = model;
|
|
|
|
},
|
2010-12-13 15:07:20 +01:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
getType : function() {
|
|
|
|
return "ConnectionLine";
|
|
|
|
},
|
2010-12-13 15:07:20 +01:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
getId : function() {
|
|
|
|
return this._model.getId();
|
|
|
|
},
|
2010-12-13 15:07:20 +01:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
moveToBack : function() {
|
|
|
|
this._line2d.moveToBack();
|
|
|
|
},
|
2010-12-13 15:07:20 +01:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
moveToFront : function() {
|
|
|
|
this._line2d.moveToFront();
|
|
|
|
}
|
|
|
|
});
|
2011-04-12 14:59:03 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
mindplot.ConnectionLine.getStrokeColor = function() {
|
|
|
|
return '#495879';
|
2011-04-12 14:59:03 +02:00
|
|
|
};
|
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
mindplot.ConnectionLine.SIMPLE = 0;
|
|
|
|
mindplot.ConnectionLine.POLYLINE = 1;
|
|
|
|
mindplot.ConnectionLine.CURVED = 2;
|
|
|
|
mindplot.ConnectionLine.SIMPLE_CURVED = 3;
|