1 /** 2 * Object that is used to undo actions when anything is moved, rotated or resized 3 * @this {MatrixCommand} 4 * @constructor 5 * @param property {Number} History.MATRIX 6 * @param previousValue {Matrix} the matrix to revert to 7 * @param currentValue {Matrix} the matrix we now have 8 */ 9 function MatrixCommand(objectId, typeOfObject, property, previousValue, currentValue){ 10 this.objectId = objectId; 11 this.typeOfObject = typeOfObject; 12 this.property = property; 13 this.previousValue = previousValue; 14 this.currentValue = currentValue; 15 this.oType = "Matrix Action"; 16 } 17 18 MatrixCommand.prototype = { 19 /**This method got called every time the Command must execute*/ 20 redo : function(){ 21 this._doAction(this.currentValue); 22 }, 23 24 25 /**This method should be called every time the Command should be undone*/ 26 undo : function(){ 27 this._doAction(this.previousValue); 28 }, 29 30 _doAction:function(value){ 31 var figure; 32 if(this.typeOfObject == History.OBJECT_FIGURE){ 33 figure = stack.figureGetById(this.objectId); 34 } 35 else if(this.typeOfObject == History.OBJECT_GROUP){ 36 figure = stack.groupGetById(this.objectId); 37 } 38 else if(this.typeOfObject == History.OBJECT_CONNECTION_POINT){ 39 figure = CONNECTOR_MANAGER.connectionPointGetById(this.objectId); 40 var con = CONNECTOR_MANAGER.connectorGetById(figure.parentId); 41 if(con.turningPoints[0].equals(this.property)){ 42 con.turningPoints[0] = this.property; 43 } 44 if(con.turningPoints[con.turningPoints.length - 1].equals(this.property)){ 45 con.turningPoints[con.turningPoints.length - 1] = this.property; 46 } 47 if(this.property != null && this.previousValue == value){//only for undoing 48 CONNECTOR_MANAGER.glueCreate(this.property[0], this.property[1]); 49 } 50 else if(this.property != null && this.currentValue == value){//only for redoing 51 CONNECTOR_MANAGER.glueRemoveByIds(this.property[0], this.property[1]); 52 } 53 } 54 55 for(var i = 0; i < value.length; i++){ 56 if(this.property instanceof Point){ 57 this.property.transform(value[i]); 58 } 59 figure.transform(value[i]); 60 } 61 62 if(this.typeOfObject == History.OBJECT_CONNECTION_POINT){ 63 //var connector = CONNECTOR_MANAGER.connectorGetByConnectionPointId(this.objectId); 64 //if(connector != null && connector.type == Connector.TYPE_JAGGED){ 65 CONNECTOR_MANAGER.connectorAdjustByConnectionPoint(this.objectId, value[0][0][2], value[0][1][2]) 66 //} 67 } 68 //figure.transform(Matrix.translationMatrix(value[0]-figure.getBounds()[0],value[1]-figure.getBounds()[1])); 69 } 70 } 71 72