Commit 6c4898da authored by SergeyLuzyanin's avatar SergeyLuzyanin

connectors in presentation editor

parent 266b5e42
......@@ -55,6 +55,7 @@
"../common/Drawings/Format/Format.js",
"../common/Drawings/Format/GraphicObjectBase.js",
"../common/Drawings/Format/Shape.js",
"../common/Drawings/Format/CnxShape.js",
"../common/Drawings/Format/Path.js",
"../common/Drawings/Format/Image.js",
"../common/Drawings/Format/GroupShape.js",
......
......@@ -55,6 +55,7 @@
"../common/Drawings/Format/Format.js",
"../common/Drawings/Format/GraphicObjectBase.js",
"../common/Drawings/Format/Shape.js",
"../common/Drawings/Format/CnxShape.js",
"../slide/Editor/Format/ShapePrototype.js",
"../common/Drawings/Format/Path.js",
"../common/Drawings/Format/Image.js",
......
......@@ -57,6 +57,7 @@
"../common/Drawings/Format/Format.js",
"../common/Drawings/Format/GraphicObjectBase.js",
"../common/Drawings/Format/Shape.js",
"../common/Drawings/Format/CnxShape.js",
"../common/Drawings/Format/Path.js",
"../common/Drawings/Format/Image.js",
"../common/Drawings/Format/GroupShape.js",
......
......@@ -493,7 +493,7 @@ function CheckStockChart(oDrawingObjects, oApi)
function CheckLinePreset(preset)
{
return preset === "line";
return CheckLinePresetForParagraphAdd(preset);
}
function CheckLinePresetForParagraphAdd(preset)
......@@ -8150,7 +8150,7 @@ DrawingObjectsController.prototype =
if ( undefined != Props.DefaultTab )
{
//this.setDefa( Props.DefaultTab );
this.setDefaltTabSize( Props.DefaultTab );
}
......@@ -10629,6 +10629,15 @@ function ApplyPresetToChartSpace(oChartSpace, aPreset, bCreate){
window['AscFormat'].SCATTER_STYLE_SMOOTH = SCATTER_STYLE_SMOOTH;
window['AscFormat'].SCATTER_STYLE_SMOOTH_MARKER = SCATTER_STYLE_SMOOTH_MARKER;
window['AscFormat'].CARD_DIRECTION_N = CARD_DIRECTION_N;
window['AscFormat'].CARD_DIRECTION_NE = CARD_DIRECTION_NE;
window['AscFormat'].CARD_DIRECTION_E = CARD_DIRECTION_E;
window['AscFormat'].CARD_DIRECTION_SE = CARD_DIRECTION_SE;
window['AscFormat'].CARD_DIRECTION_S = CARD_DIRECTION_S;
window['AscFormat'].CARD_DIRECTION_SW = CARD_DIRECTION_SW;
window['AscFormat'].CARD_DIRECTION_W = CARD_DIRECTION_W;
window['AscFormat'].CARD_DIRECTION_NW = CARD_DIRECTION_NW;
window['AscFormat'].CURSOR_TYPES_BY_CARD_DIRECTION = CURSOR_TYPES_BY_CARD_DIRECTION;
window['AscFormat'].removeDPtsFromSeries = removeDPtsFromSeries;
window['AscFormat'].checkTxBodyDefFonts = checkTxBodyDefFonts;
......
......@@ -4,16 +4,402 @@
(function(undefined){
var CONNECTOR_MARGIN = 6.35;
function CBaseParams() {
this.aAdj = [];//{"@adjName": value};
this.posX = null;
this.posY = null;
this.extX = null;
this.extY = null;
this.flipH = null;
this.flipV = null;
this.rot = null;
/**
* @constructor
* */
function ConnectionParams(){
this.bounds = new AscFormat.CGraphicBounds(0, 0, 0, 0);
this.dir = AscFormat.CARD_DIRECTION_E;
this.x = 0;
this.y = 0;
}
ConnectionParams.prototype.copy = function(){
var _c = new ConnectionParams();
_c.bounds.fromOther(this.bounds);
_c.dir = this.dir;
_c.x = this.x;
_c.y = this.y;
return _c;
};
ConnectionParams.prototype.transform = function(oTransform){
this.bounds.transform(oTransform);
//this.dir = AscFormat.CARD_DIRECTION_E;
var _x = oTransform.TransformPointX(this.x, this.y);
var _y = oTransform.TransformPointY(this.x, this.y);
this.x = _x;
this.y = _y;
};
function fCalculateSpPr(begin, end, sPreset){
return AscFormat.ExecuteNoHistory(function(){
var oSpPr = new AscFormat.CSpPr();
var oXfrm = new AscFormat.CXfrm();
oSpPr.setXfrm(oXfrm);
oXfrm.setParent(oSpPr);
var _begin = begin.copy();
var _end = end.copy();
var fAngle = 0;
switch(begin.dir){
case AscFormat.CARD_DIRECTION_N:{
fAngle = Math.PI/2;
switch(_end.dir){
case AscFormat.CARD_DIRECTION_N:{
_end.dir = AscFormat.CARD_DIRECTION_E;
break;
}
case AscFormat.CARD_DIRECTION_S:{
_end.dir = AscFormat.CARD_DIRECTION_W;
break;
}
case AscFormat.CARD_DIRECTION_W:{
_end.dir = AscFormat.CARD_DIRECTION_N;
break;
}
case AscFormat.CARD_DIRECTION_E:{
_end.dir = AscFormat.CARD_DIRECTION_S;
break;
}
}
break;
}
case AscFormat.CARD_DIRECTION_S:{
fAngle = -Math.PI/2;
switch(_end.dir){
case AscFormat.CARD_DIRECTION_N:{
_end.dir = AscFormat.CARD_DIRECTION_W;
break;
}
case AscFormat.CARD_DIRECTION_S:{
_end.dir = AscFormat.CARD_DIRECTION_E;
break;
}
case AscFormat.CARD_DIRECTION_W:{
_end.dir = AscFormat.CARD_DIRECTION_S;
break;
}
case AscFormat.CARD_DIRECTION_E:{
_end.dir = AscFormat.CARD_DIRECTION_N;
break;
}
}
break;
}
case AscFormat.CARD_DIRECTION_W:{
fAngle = Math.PI;
switch(_end.dir){
case AscFormat.CARD_DIRECTION_N:{
_end.dir = AscFormat.CARD_DIRECTION_S;
break;
}
case AscFormat.CARD_DIRECTION_S:{
_end.dir = AscFormat.CARD_DIRECTION_N;
break;
}
case AscFormat.CARD_DIRECTION_W:{
_end.dir = AscFormat.CARD_DIRECTION_E;
break;
}
case AscFormat.CARD_DIRECTION_E:{
_end.dir = AscFormat.CARD_DIRECTION_W;
break;
}
}
break;
}
default:{
//East is default direction
fAngle = 0;
break;
}
}
var oTransform = new AscCommon.CMatrix();
oTransform.Rotate(fAngle, AscCommon.MATRIX_ORDER_APPEND);
_begin.transform(oTransform);
_end.transform(oTransform);
var posX = Math.min(_begin.x, _end.x);
var posY = Math.min(_begin.y, _end.y);
var extX = Math.abs(_end.x - _begin.x);
var extY = Math.abs(_end.y - _begin.y);
var flipV = false;
var flipH = false;
var rot = 0;
var oMapAdj = {};
var tmp;
var xc = posX + extX/2, yc = posY + extY/2;
if(sPreset === "line"){
}
else if(sPreset.indexOf("curvedConnector") > 0){
}
else{
//returns "bentConnector" by default
switch(_end.dir){
case AscFormat.CARD_DIRECTION_N:{
if(_end.bounds.l > _begin.bounds.r){
if(_end.y <= _begin.y){
sPreset = "bentConnector4";
rot = 3.0*Math.PI/2.0;
tmp = extX;
extX = extY;
extY = tmp;
posX = (_end.x + _begin.x)/2.0 - extX/2.0;
posY = (_end.y + _begin.y)/2.0 - extY/2.0;
flipH = true;
flipV = true;
oMapAdj["adj2"] = 100000 - (100000*(((_begin.bounds.r + _end.bounds.l)/2 - (xc - extY/2))/extY) + 0.5) >> 0;
oMapAdj["adj1"] = (-100000*(CONNECTOR_MARGIN/extX) + 0.5) >> 0;
}
else{
sPreset = "bentConnector2";
rot = 3.0*Math.PI/2.0;
tmp = extX;
extX = extY;
extY = tmp;
posX = (_end.x + _begin.x)/2.0 - extX/2.0;
posY = (_end.y + _begin.y)/2.0 - extY/2.0;
flipV = true;
}
}
else{
if(_end.y <= _begin.bounds.b){
if(_end.y <= _begin.y){
sPreset = "bentConnector4";
rot = 3.0*Math.PI/2.0;
tmp = extX;
extX = extY;
extY = tmp;
posX = (_end.x + _begin.x)/2.0 - extX/2.0;
posY = (_end.y + _begin.y)/2.0 - extY/2.0;
flipH = true;
oMapAdj["adj1"] = -((100000*((yc - extX/2 - (Math.min(_end.bounds.t, _begin.bounds.t) - CONNECTOR_MARGIN))/extX) + 0.5) >> 0);
oMapAdj["adj2"] = 100000 + (100000*(Math.max(CONNECTOR_MARGIN, _end.bounds.r + CONNECTOR_MARGIN - _begin.x)/extY) + 0.5) >> 0;
}
else{
sPreset = "bentConnector4";
rot = Math.PI/2.0;
tmp = extX;
extX = extY;
extY = tmp;
posX = (_end.x + _begin.x)/2.0 - extX/2.0;
posY = (_end.y + _begin.y)/2.0 - extY/2.0;
flipH = true;
flipV = true;
oMapAdj["adj1"] = 100000 + ((100000*((yc - extX/2 - (Math.min(_end.bounds.t, _begin.bounds.t) - CONNECTOR_MARGIN))/extX) + 0.5) >> 0);
oMapAdj["adj2"] = 100000 + (100000*(Math.max(CONNECTOR_MARGIN, _end.bounds.r + CONNECTOR_MARGIN - _begin.x)/extY) + 0.5) >> 0;
}
}
else{
sPreset = "bentConnector4";
rot = Math.PI/2.0;
tmp = extX;
extX = extY;
extY = tmp;
posX = (_end.x + _begin.x)/2.0 - extX/2.0;
posY = (_end.y + _begin.y)/2.0 - extY/2.0;
flipH = true;
flipV = true;
oMapAdj["adj1"] = ((100000*(_end.y - (_end.bounds.t + _begin.bounds.b)/2)/extX) + 0.5) >> 0;
oMapAdj["adj2"] = 100000 + (100000*(CONNECTOR_MARGIN/extY) + 0.5) >> 0;
}
}
break;
}
case AscFormat.CARD_DIRECTION_S:{
if(_end.bounds.l > _begin.bounds.r){
if(_end.bounds.b < _begin.y){
sPreset = "bentConnector2";
rot = Math.PI/2.0;
tmp = extX;
extX = extY;
extY = tmp;
posX = (_end.x + _begin.x)/2.0 - extX/2.0;
posY = (_end.y + _begin.y)/2.0 - extY/2.0;
}
else{
sPreset = "bentConnector4";
rot = Math.PI / 2.0;
tmp = extX;
extX = extY;
extY = tmp;
posX = (_end.x + _begin.x)/2.0 - extX/2.0;
posY = (_end.y + _begin.y)/2.0 - extY/2.0;
flipH = true;
oMapAdj["adj1"] = (-100000*(CONNECTOR_MARGIN/extX) + 0.5) >> 0;
oMapAdj["adj2"] = 100000 - (100000*(((_begin.bounds.r + _end.bounds.l)/2 - (xc - extY/2))/extY) + 0.5) >> 0;
}
}
else{
if(_end.bounds.b < _begin.bounds.t){
if(_end.x > _begin.bounds.r){
sPreset = "bentConnector2";
rot = Math.PI/2.0;
tmp = extX;
extX = extY;
extY = tmp;
posX = (_end.x + _begin.x)/2.0 - extX/2.0;
posY = (_end.y + _begin.y)/2.0 - extY/2.0;
}
else{
sPreset = "bentConnector4";
rot = 3.0 * Math.PI / 2.0;
tmp = extX;
extX = extY;
extY = tmp;
posX = (_end.x + _begin.x)/2.0 - extX/2.0;
posY = (_end.y + _begin.y)/2.0 - extY/2.0;
flipH = true;
oMapAdj["adj1"] = (100000*(((_begin.bounds.t + _end.bounds.b)/2 - (yc - extX/2))/extX) + 0.5) >> 0;
oMapAdj["adj2"] = 100000 + (100000*(Math.max(CONNECTOR_MARGIN, _end.bounds.r + CONNECTOR_MARGIN - _begin.x)/extY) + 0.5) >> 0;
}
}
else{
if(_end.x < _begin.x){
sPreset = "bentConnector4";
rot = Math.PI / 2.0;
tmp = extX;
extX = extY;
extY = tmp;
posX = (_end.x + _begin.x)/2.0 - extX/2.0;
posY = (_end.y + _begin.y)/2.0 - extY/2.0;
flipH = true;
flipV = true;
oMapAdj["adj1"] = -((100000*(Math.max(_begin.bounds.b, _end.bounds.b) + CONNECTOR_MARGIN - _end.y)/extX + 0.5) >> 0);
oMapAdj["adj2"] = 100000 + (100000*(Math.max(CONNECTOR_MARGIN, _end.bounds.r + CONNECTOR_MARGIN - _begin.x)/extY) + 0.5) >> 0;
}
else{
sPreset = "bentConnector4";
rot = Math.PI / 2.0;
tmp = extX;
extX = extY;
extY = tmp;
posX = (_end.x + _begin.x)/2.0 - extX/2.0;
posY = (_end.y + _begin.y)/2.0 - extY/2.0;
flipH = true;
oMapAdj["adj1"] = -((100000*(Math.max(_begin.bounds.b, _end.bounds.b) + CONNECTOR_MARGIN - _end.y)/extX + 0.5) >> 0);
oMapAdj["adj2"] = -(100000*(Math.max(CONNECTOR_MARGIN, _end.bounds.r + CONNECTOR_MARGIN - _begin.x)/extY) + 0.5) >> 0;
}
}
}
break;
}
case AscFormat.CARD_DIRECTION_W:{
if(_begin.x < _end.x){
sPreset = "bentConnector3";
flipV = _begin.y > _end.y;
}
else{
sPreset = "bentConnector5";
rot = Math.PI;
flipH = true;
oMapAdj["adj3"] = (100000 + 100000*(CONNECTOR_MARGIN/extX) + 0.5) >> 0;
var leftX =_end.x - Math.min(_begin.bounds.l, _end.bounds.l) + CONNECTOR_MARGIN;
oMapAdj["adj1"] = (-100000*(leftX/extX) + 0.5) >> 0;
if(_end.bounds.b < _begin.bounds.t || _end.bounds.t > _begin.bounds.b){
if(_end.bounds.b < _begin.bounds.t){
flipV = true;
oMapAdj["adj2"] = (100000*(((_begin.bounds.t + _end.bounds.b)/2 - posY)/extY) + 0.5) >> 0;
}
else{
oMapAdj["adj2"] = (100000*(((_end.bounds.t + _begin.bounds.b)/2 - posY)/extY) + 0.5) >> 0;
}
}
else{
if(_end.y < _begin.y){
flipV = true;
oMapAdj["adj2"] = (100000*((Math.max(_begin.bounds.b, _end.bounds.b) + CONNECTOR_MARGIN - posY)/extY) + 0.5) >> 0;
}
else{
oMapAdj["adj2"] = 100000 - (100000*((Math.min(_begin.bounds.t, _end.bounds.t) - CONNECTOR_MARGIN - posY)/extY) + 0.5) >> 0;
}
}
}
break;
}
case AscFormat.CARD_DIRECTION_E:{
if(_end.bounds.l > _begin.bounds.r){
if(_end.bounds.b < _begin.y){
sPreset = "bentConnector3";
flipH = true;
oMapAdj["adj1"] = -(100000*(CONNECTOR_MARGIN/extX) + 0.5) >> 0
}
else{
if(_end.y < _begin.y){
sPreset = "bentConnector5";
flipH = true;
oMapAdj["adj1"] = -(100000*(CONNECTOR_MARGIN/extX) + 0.5) >> 0;
oMapAdj["adj2"] = -(100000*(CONNECTOR_MARGIN/extX) + 0.5) >> 0;
oMapAdj["adj3"] = (100000 - (100000*(CONNECTOR_MARGIN/extX) + 0.5)) >> 0;
}
}
}
break;
}
}
}
var oGeometry = AscFormat.CreateGeometry(sPreset);
for(var key in oMapAdj){
if(oMapAdj.hasOwnProperty(key)){
oGeometry.setAdjValue(key, oMapAdj[key]);
}
}
oSpPr.setGeometry(oGeometry);
oGeometry.setParent(oSpPr);
oXfrm.setOffX(posX);
oXfrm.setOffY(posY);
oXfrm.setExtX(extX);
oXfrm.setExtY(extY);
oXfrm.setRot(rot);
oXfrm.setFlipH(flipH);
oXfrm.setFlipV(flipV);
return oSpPr;
}, this, []);
}
function fCalculateConnectionInfo(oConnInfo, x, y) {
var oConnecInfo2 = new ConnectionParams();
oConnecInfo2.x = x;
oConnecInfo2.y = y;
oConnecInfo2.bounds.fromOther(new AscFormat.CGraphicBounds(x, y, x, y));
var diffX = x - oConnInfo.x;
var diffY = y - oConnInfo.y;
if(Math.abs(diffX) > Math.abs(diffY)){
if(diffX < 0){
oConnecInfo2.dir = AscFormat.CARD_DIRECTION_E;
}
else{
oConnecInfo2.dir = AscFormat.CARD_DIRECTION_W;
}
}
else{
if(diffY < 0){
oConnecInfo2.dir = AscFormat.CARD_DIRECTION_S;
}
else{
oConnecInfo2.dir = AscFormat.CARD_DIRECTION_N;
}
}
return oConnecInfo2;
}
function CConnectionShape() {
......@@ -22,8 +408,11 @@
CConnectionShape.prototype = Object.create(AscFormat.CShape.prototype);
CConnectionShape.prototype.constructor = CConnectionShape;
CConnectionShape.prototype.calculateBaseParams = function(startPos, endPos){
}
CConnectionShape.prototype.calculateSpPr = function(begin, end){
};
window['AscFormat'] = window['AscFormat'] || {};
window['AscFormat'].fCalculateSpPr = fCalculateSpPr;
window['AscFormat'].fCalculateConnectionInfo = fCalculateConnectionInfo;
window['AscFormat'].ConnectionParams = ConnectionParams;
})();
\ No newline at end of file
......@@ -1078,6 +1078,41 @@ Geometry.prototype=
this.rectS.b = b;
},
findConnector: function(x, y, distanse){
var dx, dy;
for(var i = 0; i < this.cnxLst.length; i++)
{
dx=x-this.cnxLst[i].x;
dy=y-this.cnxLst[i].y;
if(Math.sqrt(dx*dx+dy*dy) < distanse)
{
return {ang: this.cnxLst[i].ang, x: this.cnxLst[i].x, y: this.cnxLst[i].y};
}
}
return null;
},
drawConnectors: function(overlay, transform){
var dOldAlpha;
var oGraphics = overlay.Graphics ? overlay.Graphics : overlay;
if(AscFormat.isRealNumber(oGraphics.globalAlpha) && oGraphics.put_GlobalAlpha){
dOldAlpha = oGraphics.globalAlpha;
oGraphics.put_GlobalAlpha(false, 1);
}
for(var i = 0; i < this.cnxLst.length; i++)
{
overlay.DrawEditWrapPointsPolygon([{x: this.cnxLst[i].x, y: this.cnxLst[i].y}], transform);
}
if(AscFormat.isRealNumber(dOldAlpha) && oGraphics.put_GlobalAlpha){
oGraphics.put_GlobalAlpha(true, dOldAlpha);
}
},
Recalculate: function(w, h, bResetPathsInfo)
{
this.gdLst["_3cd4"]= 16200000;
......
......@@ -249,6 +249,42 @@
this.w = r - l;
this.h = b - t;
}
CGraphicBounds.prototype.fromOther = function(oBounds){
this.l = oBounds.l;
this.t = oBounds.t;
this.r = oBounds.r;
this.b = oBounds.b;
this.x = oBounds.x;
this.y = oBounds.y;
this.w = oBounds.w;
this.h = oBounds.h;
};
CGraphicBounds.prototype.transform = function(oTransform){
var xlt = oTransform.TransformPointX(this.l, this.t);
var ylt = oTransform.TransformPointY(this.l, this.t);
var xrt = oTransform.TransformPointX(this.r, this.t);
var yrt = oTransform.TransformPointY(this.r, this.t);
var xlb = oTransform.TransformPointX(this.l, this.b);
var ylb = oTransform.TransformPointY(this.l, this.b);
var xrb = oTransform.TransformPointX(this.r, this.b);
var yrb = oTransform.TransformPointY(this.r, this.b);
this.l = Math.min(xlb, xlt, xrb, xrt);
this.t = Math.min(ylb, ylt, yrb, yrt);
this.r = Math.max(xlb, xlt, xrb, xrt);
this.b = Math.max(ylb, ylt, yrb, yrt);
this.x = this.l;
this.y = this.t;
this.w = this.r - this.l;
this.h = this.b - this.t;
};
/**
* Base class for all graphic objects
* @constructor
......@@ -778,6 +814,17 @@
CGraphicObjectBase.prototype.Restart_CheckSpelling = function()
{
};
CGraphicObjectBase.prototype.findConnector = function()
{
return null;
};
CGraphicObjectBase.prototype.findConnectionShape = function(x, y)
{
return null;
};
CGraphicObjectBase.prototype.drawConnectors = function(overlay)
{
};
CGraphicObjectBase.prototype.GetAllContentControls = function(arrContentControls)
{
......
......@@ -1829,6 +1829,26 @@ function CGroupShape()
}
};
CGroupShape.prototype.findConnector = function(x, y){
for(var i = this.spTree.length - 1; i > -1; --i ){
var oConInfo = this.spTree[i].findConnector(x, y);
if(oConInfo){
return oConInfo;
}
}
return null;
};
CGroupShape.prototype.findConnectionShape = function(x, y){
for(var i = this.spTree.length - 1; i > -1; --i){
var _ret = this.spTree[i].findConnectionShape(x, y);
if(_ret){
return _ret;
}
}
return null;
};
CGroupShape.prototype.GetAllContentControls = function(arrContentControls){
for(var i = 0; i < this.spTree.length; ++i)
{
......
......@@ -61,7 +61,7 @@ var c_oAscFill = Asc.c_oAscFill;
function CheckObjectLine(obj)
{
return (obj instanceof CShape && obj.spPr && obj.spPr.geometry && obj.spPr.geometry.preset === "line");
return (obj instanceof CShape && obj.spPr && obj.spPr.geometry && AscFormat.CheckLinePreset(obj.spPr.geometry.preset));
}
......@@ -5370,6 +5370,65 @@ CShape.prototype.getColumnNumber = function(){
}
};
CShape.prototype.convertToConnectionParams = function(rot, oTransform, oBounds, oConnectorInfo){
var _ret = new AscFormat.ConnectionParams();
var _rot = oConnectorInfo.ang*AscFormat.cToRad + rot;
var _normalized_rot = AscFormat.normalizeRotate(_rot);
_ret.dir = AscFormat.CARD_DIRECTION_E;
if(_normalized_rot >= 0 && _normalized_rot < Math.PI * 0.25 || _normalized_rot >= 7 * Math.PI * 0.25 && _normalized_rot < 2 * Math.PI){
_ret.dir = AscFormat.CARD_DIRECTION_E;
}
else if(_normalized_rot >= Math.PI * 0.25 && _normalized_rot < 3 * Math.PI * 0.25){
_ret.dir = AscFormat.CARD_DIRECTION_S;
}
else if(_normalized_rot >= 3 * Math.PI * 0.25 && _normalized_rot < 5 * Math.PI * 0.25){
_ret.dir = AscFormat.CARD_DIRECTION_W;
}
else if(_normalized_rot >= 5 * Math.PI * 0.25 && _normalized_rot < 7 * Math.PI * 0.25){
_ret.dir = AscFormat.CARD_DIRECTION_N;
}
_ret.x = oTransform.TransformPointX(oConnectorInfo.x, oConnectorInfo.y);
_ret.y = oTransform.TransformPointY(oConnectorInfo.x, oConnectorInfo.y);
_ret.bounds.fromOther(this.bounds);
return _ret;
};
CShape.prototype.findGeomConnector = function(x, y){
if(this.spPr && this.spPr.geometry){
var oInvertTransform = this.invertTransform;
var _x = oInvertTransform.TransformPointX(x, y);
var _y = oInvertTransform.TransformPointY(x, y);
return this.spPr.geometry.findConnector(_x, _y, this.convertPixToMM(global_mouseEvent.KoefPixToMM * AscCommon.TRACK_CIRCLE_RADIUS));
}
return null;
};
CShape.prototype.findConnector = function(x, y){
var oConnGeom = this.findGeomConnector(x, y);
if(oConnGeom){
return this.convertToConnectionParams(this.rot, this.transform, this.bounds, oConnGeom);
}
return null;
};
CShape.prototype.findConnectionShape = function(x, y){
if(this.spPr && this.spPr.geometry && this.spPr.geometry.cnxLst.length >0){
if(this.hit(x, y)){
return this;
}
}
return null;
};
CShape.prototype.drawConnectors = function(overlay)
{
if(this.spPr && this.spPr.geometry){
this.spPr.geometry.drawConnectors(overlay, this.transform);
}
};
function CreateBinaryReader(szSrc, offset, srcLen)
{
var nWritten = 0;
......
......@@ -119,12 +119,38 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide,
this.y = null;
this.extX = null;
this.extY = null;
this.rot = 0;
this.arrowsCount = 0;
this.transform = new AscCommon.CMatrix();
this.pageIndex = pageIndex;
this.theme = theme;
//for connectors
this.bConnector = false;
this.startConnectionInfo = null;
this.oShapeDrawConnectors = null;
this.lastSpPr = null;
AscFormat.ExecuteNoHistory(function(){
if(slide){
this.bConnector = presetGeom.toLowerCase().indexOf("connector") > -1;
if(this.bConnector){
var aSpTree = slide.cSld.spTree;
var oConnector = null;
for(var i = aSpTree.length - 1; i > -1; --i){
oConnector = aSpTree[i].findConnector(startX, startY);
if(oConnector){
this.startConnectionInfo = oConnector;
this.startX = oConnector.x;
this.startY = oConnector.y;
break;
}
}
}
}
var style;
if(presetGeom.indexOf("WithArrow") > -1)
......@@ -238,12 +264,65 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide,
this.track = function(e, x, y)
{
var bConnectorHandled = false;
this.oShapeDrawConnectors = null;
this.lastSpPr = null;
if(this.bConnector){
var aSpTree = slide.cSld.spTree;
var oConnector = null;
var oEndConnectionInfo = null;
for(var i = aSpTree.length - 1; i > -1; --i){
oConnector = aSpTree[i].findConnector(x, y);
if(oConnector){
oEndConnectionInfo = oConnector;
this.oShapeDrawConnectors = aSpTree[i];
break;
}
}
if(this.startConnectionInfo || oEndConnectionInfo){
var _startInfo = this.startConnectionInfo;
var _endInfo = oEndConnectionInfo;
if(!_startInfo){
_startInfo = AscFormat.fCalculateConnectionInfo(_endInfo, this.startX, this.startY);
}
else if(!_endInfo){
_endInfo = AscFormat.fCalculateConnectionInfo(_startInfo, x, y);
}
var oSpPr = AscFormat.fCalculateSpPr(_startInfo, _endInfo, this.presetGeom);
this.flipH = oSpPr.xfrm.flipH === true;
this.flipV = oSpPr.xfrm.flipV === true;
this.rot = AscFormat.isRealNumber(oSpPr.xfrm.rot) ? oSpPr.xfrm.rot : 0;
this.extX = oSpPr.xfrm.extX;
this.extY = oSpPr.xfrm.extY;
this.x = oSpPr.xfrm.offX;
this.y = oSpPr.xfrm.offY;
this.overlayObject = new AscFormat.OverlayObject(oSpPr.geometry, 5, 5, this.overlayObject.brush, this.overlayObject.pen, this.transform);
bConnectorHandled = true;
this.lastSpPr = oSpPr;
}
if(!this.oShapeDrawConnectors){
for(var i = aSpTree.length - 1; i > -1; --i){
var oCs = aSpTree[i].findConnectionShape(x, y);
if(oCs ){
oEndConnectionInfo = oConnector;
this.oShapeDrawConnectors = oCs;
break;
}
}
}
}
if(false === bConnectorHandled){
var real_dist_x = x - this.startX;
var abs_dist_x = Math.abs(real_dist_x);
var real_dist_y = y - this.startY;
var abs_dist_y = Math.abs(real_dist_y);
this.flipH = false;
this.flipV = false;
this.rot = 0;
if(this.isLine)
{
if(x < this.startX)
......@@ -439,6 +518,8 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide,
this.x = this.startX - this.extX*0.5;
this.y = this.startY - this.extY*0.5;
}
}
this.overlayObject.updateExtents(this.extX, this.extY);
this.transform.Reset();
var hc = this.extX * 0.5;
......@@ -448,6 +529,8 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide,
AscCommon.global_MatrixTransformer.ScaleAppend(this.transform, -1, 1);
if (this.flipV)
AscCommon.global_MatrixTransformer.ScaleAppend(this.transform, 1, -1);
AscCommon.global_MatrixTransformer.RotateRadAppend(this.transform, -this.rot);
AscCommon.global_MatrixTransformer.TranslateAppend(this.transform, this.x + hc, this.y + vc);
};
......@@ -457,6 +540,9 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide,
{
overlay.SetCurrentPage(this.pageIndex);
}
if(this.oShapeDrawConnectors){
this.oShapeDrawConnectors.drawConnectors(overlay);
}
this.overlayObject.draw(overlay);
};
......@@ -467,15 +553,23 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide,
{
shape.setDrawingObjects(drawingObjects);
}
var _sp_pr;
if(this.lastSpPr){
_sp_pr = this.lastSpPr.createDuplicate();
shape.setSpPr(_sp_pr);
_sp_pr.setParent(shape);
}
else{
shape.setSpPr(new AscFormat.CSpPr());
shape.spPr.setParent(shape);
shape.spPr.setXfrm(new AscFormat.CXfrm());
if(bFromWord)
{
shape.setWordShape(true);
}
var xfrm = shape.spPr.xfrm;
xfrm.setParent(shape.spPr);
var x, y;
if(bFromWord)
{
......@@ -487,12 +581,18 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide,
x = this.x;
y = this.y;
}
shape.spPr.setXfrm(new AscFormat.CXfrm());
var xfrm = shape.spPr.xfrm;
xfrm.setParent(shape.spPr);
xfrm.setOffX(x);
xfrm.setOffY(y);
xfrm.setExtX(this.extX);
xfrm.setExtY(this.extY);
xfrm.setFlipH(this.flipH);
xfrm.setFlipV(this.flipV);
}
shape.setBDeleted(false);
if(this.presetGeom === "textRect")
......@@ -548,7 +648,9 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide,
}
else
{
if(!shape.spPr.geometry){
shape.spPr.setGeometry(AscFormat.CreateGeometry(this.presetGeom));
}
shape.setStyle(AscFormat.CreateDefaultShapeStyle(this.presetGeom));
if(this.arrowsCount > 0)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment