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;
......
This diff is collapsed.
......@@ -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