2010-12-13 15:07:20 +01:00
|
|
|
/*
|
2011-01-24 00:34:05 +01:00
|
|
|
* Copyright [2011] [wisemapping]
|
|
|
|
*
|
2011-01-24 01:03:12 +01:00
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
2011-01-24 00:34:05 +01:00
|
|
|
* "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
|
|
|
|
|
|
|
mindplot.ConnectionLine = function(sourceNode, targetNode, lineType)
|
2009-06-07 20:59:43 +02:00
|
|
|
{
|
|
|
|
core.assert(targetNode, 'parentNode node can not be null');
|
|
|
|
core.assert(sourceNode, 'childNode node can not be null');
|
|
|
|
core.assert(sourceNode != targetNode, 'Cilcular connection');
|
|
|
|
|
|
|
|
this._targetTopic = targetNode;
|
|
|
|
this._sourceTopic = sourceNode;
|
|
|
|
|
|
|
|
var strokeColor = mindplot.ConnectionLine.getStrokeColor();
|
|
|
|
var line;
|
|
|
|
if (targetNode.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE)
|
|
|
|
{
|
2011-04-20 10:30:45 +02:00
|
|
|
line = this._createLine(lineType,mindplot.ConnectionLine.CURVED);
|
2010-12-22 23:34:24 +01:00
|
|
|
// line = new web2d.Line();
|
2011-02-06 14:10:12 +01:00
|
|
|
if(line.getType()=="CurvedLine"){
|
|
|
|
var ctrlPoints = this._getCtrlPoints(sourceNode, targetNode);
|
|
|
|
line.setSrcControlPoint(ctrlPoints[0]);
|
|
|
|
line.setDestControlPoint(ctrlPoints[1]);
|
|
|
|
}
|
2009-06-07 20:59:43 +02:00
|
|
|
line.setStroke(1, 'solid', strokeColor);
|
|
|
|
} else
|
|
|
|
{
|
2011-04-15 17:18:59 +02:00
|
|
|
line = this._createLine(lineType,mindplot.ConnectionLine.SIMPLE_CURVED);
|
|
|
|
if(line.getType()=="CurvedLine"){
|
|
|
|
var ctrlPoints = this._getCtrlPoints(sourceNode, targetNode);
|
|
|
|
line.setSrcControlPoint(ctrlPoints[0]);
|
|
|
|
line.setDestControlPoint(ctrlPoints[1]);
|
|
|
|
}
|
2010-12-22 23:34:24 +01:00
|
|
|
// line = new web2d.PolyLine();
|
2009-06-07 20:59:43 +02:00
|
|
|
line.setStroke(1, 'solid', strokeColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._line2d = line;
|
|
|
|
};
|
|
|
|
|
2011-02-06 14:10:12 +01:00
|
|
|
mindplot.ConnectionLine.prototype._getCtrlPoints = function(sourceNode, targetNode){
|
2011-04-15 17:18:59 +02:00
|
|
|
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)];
|
2011-02-06 14:10:12 +01:00
|
|
|
};
|
|
|
|
|
2010-12-13 15:07:20 +01:00
|
|
|
mindplot.ConnectionLine.prototype._createLine = function(lineType, defaultStyle){
|
|
|
|
if(!core.Utils.isDefined(lineType)){
|
|
|
|
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;
|
2011-01-24 17:18:14 +01:00
|
|
|
};
|
2010-12-13 15:07:20 +01:00
|
|
|
|
2009-06-07 20:59:43 +02:00
|
|
|
mindplot.ConnectionLine.getStrokeColor = function()
|
|
|
|
{
|
2011-04-20 10:43:04 +02:00
|
|
|
return '#495879';
|
2009-06-07 20:59:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
mindplot.ConnectionLine.prototype.setVisibility = function(value)
|
|
|
|
{
|
2011-01-23 23:54:40 +01:00
|
|
|
this._line2d.setVisibility(value);
|
2009-06-07 20:59:43 +02:00
|
|
|
};
|
|
|
|
|
2011-02-09 15:29:09 +01:00
|
|
|
mindplot.ConnectionLine.prototype.isVisible = function()
|
|
|
|
{
|
|
|
|
return this._line2d.isVisible();
|
|
|
|
};
|
|
|
|
|
|
|
|
mindplot.ConnectionLine.prototype.setOpacity = function(opacity){
|
|
|
|
this._line2d.setOpacity(opacity);
|
|
|
|
};
|
|
|
|
|
2009-06-07 20:59:43 +02:00
|
|
|
mindplot.ConnectionLine.prototype.redraw = function()
|
|
|
|
{
|
|
|
|
var line2d = this._line2d;
|
|
|
|
var sourceTopic = this._sourceTopic;
|
|
|
|
var sourcePosition = sourceTopic.getPosition();
|
|
|
|
|
|
|
|
var targetTopic = this._targetTopic;
|
|
|
|
var targetPosition = targetTopic.getPosition();
|
|
|
|
|
2010-12-13 15:07:20 +01:00
|
|
|
var sPos,tPos;
|
2010-12-22 23:34:24 +01:00
|
|
|
sPos = sourceTopic.workoutOutgoingConnectionPoint(targetPosition, false);
|
|
|
|
tPos = targetTopic.workoutIncomingConnectionPoint(sourcePosition, false);
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2010-12-31 19:11:32 +01:00
|
|
|
line2d.setFrom(tPos.x, tPos.y);
|
|
|
|
line2d.setTo(sPos.x, sPos.y);
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-04-15 17:18:59 +02:00
|
|
|
if(line2d.getType()=="CurvedLine"){
|
|
|
|
var ctrlPoints = this._getCtrlPoints(this._sourceTopic, this._targetTopic);
|
|
|
|
line2d.setSrcControlPoint(ctrlPoints[0]);
|
|
|
|
line2d.setDestControlPoint(ctrlPoints[1]);
|
|
|
|
}
|
2011-05-06 16:29:25 +02:00
|
|
|
// line2d.moveToBack();
|
2009-06-07 20:59:43 +02:00
|
|
|
|
|
|
|
// Add connector ...
|
|
|
|
this._positionateConnector(targetTopic);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
mindplot.ConnectionLine.prototype._positionateConnector = function(targetTopic)
|
|
|
|
{
|
|
|
|
var targetPosition = targetTopic.getPosition();
|
|
|
|
var offset = mindplot.Topic.CONNECTOR_WIDTH / 2;
|
|
|
|
var targetTopicSize = targetTopic.getSize();
|
|
|
|
var y;
|
|
|
|
if (targetTopic.getShapeType() == mindplot.NodeModel.SHAPE_TYPE_LINE)
|
|
|
|
{
|
|
|
|
y = targetTopicSize.height;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
y = targetTopicSize.height / 2;
|
|
|
|
}
|
|
|
|
y = y - offset;
|
|
|
|
|
|
|
|
var connector = targetTopic.getShrinkConnector();
|
2011-04-08 16:31:40 +02:00
|
|
|
if (Math.sign(targetPosition.x) > 0)
|
2009-06-07 20:59:43 +02:00
|
|
|
{
|
|
|
|
var x = targetTopicSize.width;
|
|
|
|
connector.setPosition(x, y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var x = -mindplot.Topic.CONNECTOR_WIDTH;
|
|
|
|
connector.setPosition(x, y);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
mindplot.ConnectionLine.prototype.setStroke = function(color, style, opacity)
|
|
|
|
{
|
|
|
|
var line2d = this._line2d;
|
|
|
|
this._line2d.setStroke(null, null, color, opacity);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
mindplot.ConnectionLine.prototype.addToWorkspace = function(workspace)
|
|
|
|
{
|
|
|
|
workspace.appendChild(this._line2d);
|
2011-05-06 16:29:25 +02:00
|
|
|
this._line2d.moveToBack();
|
2009-06-07 20:59:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
mindplot.ConnectionLine.prototype.removeFromWorkspace = function(workspace)
|
|
|
|
{
|
|
|
|
workspace.removeChild(this._line2d);
|
|
|
|
};
|
|
|
|
|
|
|
|
mindplot.ConnectionLine.prototype.getTargetTopic = function()
|
|
|
|
{
|
|
|
|
return this._targetTopic;
|
2010-12-13 15:07:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
mindplot.ConnectionLine.prototype.getSourceTopic = function()
|
|
|
|
{
|
|
|
|
return this._sourceTopic;
|
|
|
|
};
|
|
|
|
|
|
|
|
mindplot.ConnectionLine.prototype.getLineType = function(){
|
|
|
|
return this._lineType;
|
|
|
|
};
|
|
|
|
|
|
|
|
mindplot.ConnectionLine.prototype.getLine = function(){
|
|
|
|
return this._line2d;
|
|
|
|
};
|
|
|
|
|
|
|
|
mindplot.ConnectionLine.prototype.getModel = function(){
|
|
|
|
return this._model;
|
|
|
|
};
|
|
|
|
|
|
|
|
mindplot.ConnectionLine.prototype.setModel = function(model){
|
|
|
|
this._model = model;
|
|
|
|
};
|
|
|
|
|
2010-12-22 23:34:24 +01:00
|
|
|
mindplot.ConnectionLine.prototype.getType = function(){
|
|
|
|
return "ConnectionLine";
|
2010-12-13 15:07:20 +01:00
|
|
|
};
|
|
|
|
|
2010-12-22 23:34:24 +01:00
|
|
|
mindplot.ConnectionLine.prototype.getId = function(){
|
|
|
|
return this._model.getId();
|
2010-12-13 15:07:20 +01:00
|
|
|
};
|
|
|
|
|
2011-04-12 14:59:03 +02:00
|
|
|
mindplot.ConnectionLine.prototype.moveToBack = function(){
|
|
|
|
this._line2d.moveToBack();
|
|
|
|
};
|
|
|
|
|
|
|
|
mindplot.ConnectionLine.prototype.moveToFront = function(){
|
|
|
|
this._line2d.moveToFront();
|
|
|
|
};
|
|
|
|
|
2010-12-13 15:07:20 +01:00
|
|
|
mindplot.ConnectionLine.SIMPLE=0;
|
|
|
|
mindplot.ConnectionLine.POLYLINE=1;
|
|
|
|
mindplot.ConnectionLine.CURVED=2;
|
|
|
|
mindplot.ConnectionLine.SIMPLE_CURVED=3;
|