2011-01-24 00:34:05 +01:00
|
|
|
/*
|
2011-07-30 23:55:32 +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.
|
|
|
|
*/
|
|
|
|
mindplot.commands.MoveControlPointCommand = new Class({
|
2011-07-26 20:07:53 +02:00
|
|
|
Extends:mindplot.Command,
|
2011-07-30 23:55:32 +02:00
|
|
|
initialize: function(ctrlPointController, point) {
|
2011-07-27 19:33:02 +02:00
|
|
|
$assert(ctrlPointController, 'line can not be null');
|
2011-08-03 22:52:39 +02:00
|
|
|
$assert(point, 'point can not be null');
|
|
|
|
|
2010-12-22 23:34:24 +01:00
|
|
|
this._ctrlPointControler = ctrlPointController;
|
|
|
|
this._line = ctrlPointController._line;
|
|
|
|
this._controlPoint = this._ctrlPointControler.getControlPoint(point).clone();
|
2011-07-30 23:55:32 +02:00
|
|
|
this._oldControlPoint = this._ctrlPointControler.getOriginalCtrlPoint(point).clone();
|
2010-12-22 23:34:24 +01:00
|
|
|
this._originalEndPoint = this._ctrlPointControler.getOriginalEndPoint(point).clone();
|
2011-07-30 23:55:32 +02:00
|
|
|
switch (point) {
|
2010-12-22 23:34:24 +01:00
|
|
|
case 0:
|
|
|
|
this._wasCustom = this._line.getLine().isSrcControlPointCustom();
|
|
|
|
this._endPoint = this._line.getLine().getFrom().clone();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
this._wasCustom = this._line.getLine().isDestControlPointCustom();
|
|
|
|
this._endPoint = this._line.getLine().getTo().clone();
|
|
|
|
break;
|
|
|
|
}
|
2010-12-13 15:07:20 +01:00
|
|
|
this._id = mindplot.Command._nextUUID();
|
|
|
|
this._point = point;
|
|
|
|
},
|
2011-07-30 23:55:32 +02:00
|
|
|
execute: function(commandContext) {
|
2010-12-22 23:34:24 +01:00
|
|
|
var model = this._line.getModel();
|
2011-07-30 23:55:32 +02:00
|
|
|
switch (this._point) {
|
2010-12-13 15:07:20 +01:00
|
|
|
case 0:
|
2010-12-22 23:34:24 +01:00
|
|
|
model.setSrcCtrlPoint(this._controlPoint.clone());
|
2011-01-24 14:55:06 +01:00
|
|
|
this._line.setFrom(this._endPoint.x, this._endPoint.y);
|
|
|
|
this._line.setIsSrcControlPointCustom(true);
|
|
|
|
this._line.setSrcControlPoint(this._controlPoint.clone());
|
2010-12-13 15:07:20 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2010-12-22 23:34:24 +01:00
|
|
|
model.setDestCtrlPoint(this._controlPoint.clone());
|
|
|
|
this._wasCustom = this._line.getLine().isDestControlPointCustom();
|
2011-01-24 14:55:06 +01:00
|
|
|
this._line.setTo(this._endPoint.x, this._endPoint.y);
|
|
|
|
this._line.setIsDestControlPointCustom(true);
|
|
|
|
this._line.setDestControlPoint(this._controlPoint.clone());
|
2010-12-13 15:07:20 +01:00
|
|
|
break;
|
|
|
|
}
|
2011-07-30 23:55:32 +02:00
|
|
|
if (this._line.isOnFocus()) {
|
2010-12-22 23:34:24 +01:00
|
|
|
this._line._refreshSelectedShape();
|
|
|
|
this._ctrlPointControler.setLine(this._line);
|
|
|
|
}
|
|
|
|
this._line.getLine().updateLine(this._point);
|
2010-12-13 15:07:20 +01:00
|
|
|
},
|
2011-07-30 23:55:32 +02:00
|
|
|
undoExecute: function(commandContext) {
|
2010-12-22 23:34:24 +01:00
|
|
|
var line = this._line;
|
2010-12-13 15:07:20 +01:00
|
|
|
var model = line.getModel();
|
2011-07-30 23:55:32 +02:00
|
|
|
switch (this._point) {
|
2010-12-13 15:07:20 +01:00
|
|
|
case 0:
|
2011-07-30 23:55:32 +02:00
|
|
|
if ($defined(this._oldControlPoint)) {
|
2011-01-24 14:55:06 +01:00
|
|
|
line.setFrom(this._originalEndPoint.x, this._originalEndPoint.y);
|
2010-12-22 23:34:24 +01:00
|
|
|
model.setSrcCtrlPoint(this._oldControlPoint.clone());
|
2011-01-24 14:55:06 +01:00
|
|
|
line.setSrcControlPoint(this._oldControlPoint.clone());
|
|
|
|
line.setIsSrcControlPointCustom(this._wasCustom);
|
2010-12-13 15:07:20 +01:00
|
|
|
}
|
2011-07-30 23:55:32 +02:00
|
|
|
break;
|
2010-12-13 15:07:20 +01:00
|
|
|
case 1:
|
2011-07-30 23:55:32 +02:00
|
|
|
if ($defined(this._oldControlPoint)) {
|
2011-01-24 14:55:06 +01:00
|
|
|
line.setTo(this._originalEndPoint.x, this._originalEndPoint.y);
|
2010-12-22 23:34:24 +01:00
|
|
|
model.setDestCtrlPoint(this._oldControlPoint.clone());
|
2011-01-24 14:55:06 +01:00
|
|
|
line.setDestControlPoint(this._oldControlPoint.clone());
|
|
|
|
line.setIsDestControlPointCustom(this._wasCustom);
|
2010-12-13 15:07:20 +01:00
|
|
|
}
|
2011-07-30 23:55:32 +02:00
|
|
|
break;
|
2010-12-13 15:07:20 +01:00
|
|
|
}
|
2010-12-22 23:34:24 +01:00
|
|
|
this._line.getLine().updateLine(this._point);
|
2011-07-30 23:55:32 +02:00
|
|
|
if (this._line.isOnFocus()) {
|
2010-12-22 23:34:24 +01:00
|
|
|
this._ctrlPointControler.setLine(line);
|
|
|
|
line._refreshSelectedShape();
|
|
|
|
}
|
2010-12-13 15:07:20 +01:00
|
|
|
}
|
|
|
|
});
|