Commit 43530f71 authored by SergeyLuzyanin's avatar SergeyLuzyanin

connectors

parent ffc22f45
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
this.dir = AscFormat.CARD_DIRECTION_E; this.dir = AscFormat.CARD_DIRECTION_E;
this.x = 0; this.x = 0;
this.y = 0; this.y = 0;
this.idx = 0;
} }
ConnectionParams.prototype.copy = function(){ ConnectionParams.prototype.copy = function(){
var _c = new ConnectionParams(); var _c = new ConnectionParams();
...@@ -21,6 +22,7 @@ ...@@ -21,6 +22,7 @@
_c.dir = this.dir; _c.dir = this.dir;
_c.x = this.x; _c.x = this.x;
_c.y = this.y; _c.y = this.y;
_c.idx = this.idx;
return _c; return _c;
}; };
ConnectionParams.prototype.transform = function(oTransform){ ConnectionParams.prototype.transform = function(oTransform){
...@@ -118,7 +120,7 @@ ...@@ -118,7 +120,7 @@
} }
var oTransform = new AscCommon.CMatrix(); var oTransform = new AscCommon.CMatrix();
oTransform.Rotate(fAngle, AscCommon.MATRIX_ORDER_APPEND); AscCommon.global_MatrixTransformer.RotateRadAppend(oTransform, -fAngle);
_begin.transform(oTransform); _begin.transform(oTransform);
_end.transform(oTransform); _end.transform(oTransform);
...@@ -266,18 +268,27 @@ ...@@ -266,18 +268,27 @@
else{ else{
if(_end.x < _begin.x){ if(_end.x < _begin.x){
sPreset = "bentConnector4"; if(_end.y > _begin.y){
rot = Math.PI / 2.0; sPreset = "bentConnector4";
tmp = extX; rot = Math.PI / 2.0;
extX = extY; tmp = extX;
extY = tmp; extX = extY;
posX = (_end.x + _begin.x)/2.0 - extX/2.0; extY = tmp;
posY = (_end.y + _begin.y)/2.0 - extY/2.0; posX = (_end.x + _begin.x)/2.0 - extX/2.0;
flipH = true; posY = (_end.y + _begin.y)/2.0 - extY/2.0;
flipV = true; flipH = true;
flipV = true;
oMapAdj["adj1"] = -((100000*(Math.max(_begin.bounds.b, _end.bounds.b) + CONNECTOR_MARGIN - _end.y)/extX + 0.5) >> 0); 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; oMapAdj["adj2"] = 100000 + (100000*(Math.max(CONNECTOR_MARGIN, _end.bounds.r + CONNECTOR_MARGIN - _begin.x)/extY) + 0.5) >> 0;
}
else{
sPreset = "bentConnector4";
flipH = true;
flipV = true;
oMapAdj["adj1"] = -((100000*(Math.max(_begin.bounds.r, _end.bounds.r) + CONNECTOR_MARGIN - begin.x)/extX + 0.5) >> 0);
oMapAdj["adj2"] = - (100000*((Math.max(_end.bounds.b, _begin.bounds.b) - _begin.y + CONNECTOR_MARGIN)/extY) + 0.5) >> 0;
}
} }
else{ else{
sPreset = "bentConnector4"; sPreset = "bentConnector4";
...@@ -290,7 +301,7 @@ ...@@ -290,7 +301,7 @@
flipH = true; flipH = true;
oMapAdj["adj1"] = -((100000*(Math.max(_begin.bounds.b, _end.bounds.b) + CONNECTOR_MARGIN - _end.y)/extX + 0.5) >> 0); 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; oMapAdj["adj2"] = -(100000*((Math.max(_begin.bounds.r, _end.bounds.r) + CONNECTOR_MARGIN - Math.max(_begin.x, _end.x))/extY) + 0.5) >> 0;
} }
} }
} }
...@@ -315,7 +326,7 @@ ...@@ -315,7 +326,7 @@
oMapAdj["adj2"] = (100000*(((_begin.bounds.t + _end.bounds.b)/2 - posY)/extY) + 0.5) >> 0; oMapAdj["adj2"] = (100000*(((_begin.bounds.t + _end.bounds.b)/2 - posY)/extY) + 0.5) >> 0;
} }
else{ else{
oMapAdj["adj2"] = (100000*(((_end.bounds.t + _begin.bounds.b)/2 - posY)/extY) + 0.5) >> 0; oMapAdj["adj2"] = 100000 - (100000*(((_end.bounds.t + _begin.bounds.b)/2 - posY)/extY) + 0.5) >> 0;
} }
} }
else{ else{
...@@ -332,18 +343,78 @@ ...@@ -332,18 +343,78 @@
} }
case AscFormat.CARD_DIRECTION_E:{ case AscFormat.CARD_DIRECTION_E:{
if(_end.bounds.l > _begin.bounds.r){ if(_end.bounds.l > _begin.bounds.r){
if(_end.bounds.b < _begin.y){ if(_end.bounds.b < _begin.y ){
sPreset = "bentConnector3"; sPreset = "bentConnector3";
flipH = true; flipH = true;
oMapAdj["adj1"] = -(100000*(CONNECTOR_MARGIN/extX) + 0.5) >> 0 oMapAdj["adj1"] = -(100000*(CONNECTOR_MARGIN/extX) + 0.5) >> 0;
}
else if(_end.bounds.t > _begin.y){
sPreset = "bentConnector5";
flipV = true;
oMapAdj["adj1"] = (100000*((_end.bounds.l + _begin.bounds.r)/2 - _begin.x)/extX + 0.5) >> 0;
oMapAdj["adj2"] = (100000 + (_end.y - (_end.bounds.t - CONNECTOR_MARGIN))/extY + 0.5) >> 0;
oMapAdj["adj3"] = 100000 + (100000*(CONNECTOR_MARGIN/extX) + 0.5) >> 0;
} }
else{ else{
if(_end.y < _begin.y){ if(_end.y < _begin.y){
sPreset = "bentConnector5";
flipV = true;
oMapAdj["adj1"] = (100000*((_end.bounds.l + _begin.bounds.r)/2 - _begin.x)/extX + 0.5) >> 0;
oMapAdj["adj2"] = (100000 + 100000*(_end.y - (_end.bounds.t - CONNECTOR_MARGIN))/extY + 0.5) >> 0;
oMapAdj["adj3"] = 100000 + (100000*(_end.bounds.r + CONNECTOR_MARGIN - _end.x)/extX + 0.5) >> 0;
}
else{
sPreset = "bentConnector5";
oMapAdj["adj1"] = (100000*((_end.bounds.l + _begin.bounds.r)/2 - _begin.x)/extX + 0.5) >> 0;
oMapAdj["adj2"] = -(100000*(begin.y - (_end.bounds.t - CONNECTOR_MARGIN))/extY + 0.5) >> 0;
oMapAdj["adj3"] = 100000 + (100000*(_end.bounds.r + CONNECTOR_MARGIN - _end.x)/extX + 0.5) >> 0;
}
}
}
else{
if(_end.x >= _begin.bounds.l || _end.y > _begin.bounds.b || _end.y < _begin.bounds.t){
if(_end.y < _begin.y){
if(_end.x < _begin.x){
flipH = true;
flipV = true;
sPreset = "bentConnector3";
oMapAdj["adj1"] = -(100000*(Math.max(_end.bounds.r, _begin.bounds.r) + CONNECTOR_MARGIN - _begin.x)/extX + 0.5) >> 0;
}
else {
flipV = true;
sPreset = "bentConnector3";
oMapAdj["adj1"] = 100000 + (100000*(Math.max(_end.bounds.r, _begin.bounds.r) + CONNECTOR_MARGIN - _end.x)/extX + 0.5) >> 0;
}
}
else{
if(_end.x < _begin.x){
flipH = true;
sPreset = "bentConnector3";
oMapAdj["adj1"] = -(100000*(Math.max(_end.bounds.r, _begin.bounds.r) + CONNECTOR_MARGIN - _begin.x)/extX + 0.5) >> 0;
}
else {
sPreset = "bentConnector3";
oMapAdj["adj1"] = 100000 + (100000*(Math.max(_end.bounds.r, _begin.bounds.r) + CONNECTOR_MARGIN - _end.x)/extX + 0.5) >> 0;
}
}
}
else{
if(_end.y >= _begin.y){
sPreset = "bentConnector5"; sPreset = "bentConnector5";
flipH = true; flipH = true;
oMapAdj["adj1"] = -(100000*(CONNECTOR_MARGIN/extX) + 0.5) >> 0; oMapAdj["adj1"] = -((100000*(CONNECTOR_MARGIN/extX) + 0.5) >> 0);
oMapAdj["adj2"] = -(100000*(CONNECTOR_MARGIN/extX) + 0.5) >> 0; oMapAdj["adj2"] = (100000 + 100000*(_begin.bounds.b + CONNECTOR_MARGIN - _end.y)/extY + 0.5) >> 0;
oMapAdj["adj3"] = (100000 - (100000*(CONNECTOR_MARGIN/extX) + 0.5)) >> 0; oMapAdj["adj3"] = (100000*(_begin.x - (_end.bounds.r + _begin.bounds.l)/2.0)/extX + 0.5) >> 0;
}
else{
sPreset = "bentConnector5";
flipH = true;
flipV = true;
oMapAdj["adj1"] = -((100000*(CONNECTOR_MARGIN/extX) + 0.5) >> 0);
oMapAdj["adj2"] = -(100000*(_begin.bounds.b + CONNECTOR_MARGIN - _begin.y)/extY + 0.5) >> 0;
oMapAdj["adj3"] = (100000*(_begin.x - (_end.bounds.r + _begin.bounds.l)/2.0)/extX + 0.5) >> 0;
} }
} }
} }
...@@ -352,6 +423,10 @@ ...@@ -352,6 +423,10 @@
} }
} }
var _posX = (end.x + begin.x)/2.0 - extX/2.0;
var _posY = (end.y + begin.y)/2.0 - extY/2.0;
var _fAng = AscFormat.normalizeRotate(rot - fAngle);
var oGeometry = AscFormat.CreateGeometry(sPreset); var oGeometry = AscFormat.CreateGeometry(sPreset);
for(var key in oMapAdj){ for(var key in oMapAdj){
if(oMapAdj.hasOwnProperty(key)){ if(oMapAdj.hasOwnProperty(key)){
...@@ -360,11 +435,11 @@ ...@@ -360,11 +435,11 @@
} }
oSpPr.setGeometry(oGeometry); oSpPr.setGeometry(oGeometry);
oGeometry.setParent(oSpPr); oGeometry.setParent(oSpPr);
oXfrm.setOffX(posX); oXfrm.setOffX(_posX);
oXfrm.setOffY(posY); oXfrm.setOffY(_posY);
oXfrm.setExtX(extX); oXfrm.setExtX(extX);
oXfrm.setExtY(extY); oXfrm.setExtY(extY);
oXfrm.setRot(rot); oXfrm.setRot(_fAng);
oXfrm.setFlipH(flipH); oXfrm.setFlipH(flipH);
oXfrm.setFlipV(flipV); oXfrm.setFlipV(flipV);
return oSpPr; return oSpPr;
...@@ -415,4 +490,5 @@ ...@@ -415,4 +490,5 @@
window['AscFormat'].fCalculateSpPr = fCalculateSpPr; window['AscFormat'].fCalculateSpPr = fCalculateSpPr;
window['AscFormat'].fCalculateConnectionInfo = fCalculateConnectionInfo; window['AscFormat'].fCalculateConnectionInfo = fCalculateConnectionInfo;
window['AscFormat'].ConnectionParams = ConnectionParams; window['AscFormat'].ConnectionParams = ConnectionParams;
window['AscFormat'].CConnectionShape = CConnectionShape;
})(); })();
\ No newline at end of file
...@@ -1087,7 +1087,7 @@ Geometry.prototype= ...@@ -1087,7 +1087,7 @@ Geometry.prototype=
if(Math.sqrt(dx*dx+dy*dy) < distanse) 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 {idx: i, ang: this.cnxLst[i].ang, x: this.cnxLst[i].x, y: this.cnxLst[i].y};
} }
} }
return null; return null;
......
...@@ -5390,6 +5390,7 @@ CShape.prototype.getColumnNumber = function(){ ...@@ -5390,6 +5390,7 @@ CShape.prototype.getColumnNumber = function(){
_ret.x = oTransform.TransformPointX(oConnectorInfo.x, oConnectorInfo.y); _ret.x = oTransform.TransformPointX(oConnectorInfo.x, oConnectorInfo.y);
_ret.y = oTransform.TransformPointY(oConnectorInfo.x, oConnectorInfo.y); _ret.y = oTransform.TransformPointY(oConnectorInfo.x, oConnectorInfo.y);
_ret.bounds.fromOther(this.bounds); _ret.bounds.fromOther(this.bounds);
_ret.idx = oConnectorInfo.idx;
return _ret; return _ret;
}; };
......
...@@ -131,6 +131,10 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide, ...@@ -131,6 +131,10 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide,
this.oShapeDrawConnectors = null; this.oShapeDrawConnectors = null;
this.lastSpPr = null; this.lastSpPr = null;
this.startShape = null;
this.endShape = null;
this.endConnectionInfo = null;
AscFormat.ExecuteNoHistory(function(){ AscFormat.ExecuteNoHistory(function(){
if(slide){ if(slide){
...@@ -144,6 +148,7 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide, ...@@ -144,6 +148,7 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide,
this.startConnectionInfo = oConnector; this.startConnectionInfo = oConnector;
this.startX = oConnector.x; this.startX = oConnector.x;
this.startY = oConnector.y; this.startY = oConnector.y;
this.startShape = aSpTree[i];
break; break;
} }
} }
...@@ -268,6 +273,9 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide, ...@@ -268,6 +273,9 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide,
this.oShapeDrawConnectors = null; this.oShapeDrawConnectors = null;
this.lastSpPr = null; this.lastSpPr = null;
this.endShape = null;
this.endConnectionInfo = null;
if(this.bConnector){ if(this.bConnector){
var aSpTree = slide.cSld.spTree; var aSpTree = slide.cSld.spTree;
var oConnector = null; var oConnector = null;
...@@ -277,6 +285,8 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide, ...@@ -277,6 +285,8 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide,
if(oConnector){ if(oConnector){
oEndConnectionInfo = oConnector; oEndConnectionInfo = oConnector;
this.oShapeDrawConnectors = aSpTree[i]; this.oShapeDrawConnectors = aSpTree[i];
this.endShape = aSpTree[i];
this.endConnectionInfo = oEndConnectionInfo;
break; break;
} }
} }
...@@ -548,22 +558,47 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide, ...@@ -548,22 +558,47 @@ function NewShapeTrack(presetGeom, startX, startY, theme, master, layout, slide,
this.getShape = function(bFromWord, DrawingDocument, drawingObjects) this.getShape = function(bFromWord, DrawingDocument, drawingObjects)
{ {
var shape = new AscFormat.CShape();
if(drawingObjects)
{
shape.setDrawingObjects(drawingObjects);
}
var _sp_pr; var _sp_pr;
if(this.lastSpPr){ if(this.lastSpPr){
var shape = new AscFormat.CConnectionShape();
if(drawingObjects)
{
shape.setDrawingObjects(drawingObjects);
}
_sp_pr = this.lastSpPr.createDuplicate(); _sp_pr = this.lastSpPr.createDuplicate();
shape.setSpPr(_sp_pr); shape.setSpPr(_sp_pr);
_sp_pr.setParent(shape); _sp_pr.setParent(shape);
var nv_sp_pr = new AscFormat.UniNvPr();
nv_sp_pr.cNvPr.setId(++slide.maxId);
shape.setNvSpPr(nv_sp_pr);
var nvUniSpPr = new AscFormat.CNvUniSpPr();
if(this.startShape && this.startConnectionInfo)
{
nvUniSpPr.stCnxIdx = this.startConnectionInfo.idx;
nvUniSpPr.stCnxId = this.startShape.nvSpPr.cNvPr.id;
}
if(this.endShape && this.endConnectionInfo)
{
nvUniSpPr.endCnxIdx = this.endConnectionInfo.idx;
nvUniSpPr.endCnxId = this.endShape.nvSpPr.cNvPr.id;
}
shape.nvSpPr.setUniSpPr(nvUniSpPr);
} }
else{ else{
var shape = new AscFormat.CShape();
if(drawingObjects)
{
shape.setDrawingObjects(drawingObjects);
}
shape.setSpPr(new AscFormat.CSpPr()); shape.setSpPr(new AscFormat.CSpPr());
shape.spPr.setParent(shape); shape.spPr.setParent(shape);
if(bFromWord) if(bFromWord)
......
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