Commit 1a32370f authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander.Trofimov

изменения в DependencyGraph для сдвигов и move

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@53681 954022d7-b5bf-4e40-9824-e11837661b57
parent 6f96bc5c
...@@ -2778,9 +2778,17 @@ parserFormula.prototype = { ...@@ -2778,9 +2778,17 @@ parserFormula.prototype = {
setRefError : function(wsId, cellId){ setRefError : function(wsId, cellId){
for ( var i = 0; i < this.outStack.length; i++ ) { for ( var i = 0; i < this.outStack.length; i++ ) {
var node = this.outStack[i]; var node = this.outStack[i];
if ( node instanceof cRef || node instanceof cArea || node instanceof cRef3D || node instanceof cArea3D ) if ( node instanceof cRef || node instanceof cArea || node instanceof cRef3D)
{
if( wsId == node.ws.getId() && cellId == node._cells)
this.outStack[i] = new cError( cErrorType.bad_reference ); this.outStack[i] = new cError( cErrorType.bad_reference );
} }
else if(node instanceof cArea3D)
{
if( node.wsFrom == node.wsTo && wsId == node.wsFrom.getId() && cellId == node._cells)
this.outStack[i] = new cError( cErrorType.bad_reference );
}
}
}, },
/* /*
Для изменения ссылок на конкретную ячейку. Для изменения ссылок на конкретную ячейку.
......
...@@ -2979,12 +2979,11 @@ UndoRedoWoorksheet.prototype = { ...@@ -2979,12 +2979,11 @@ UndoRedoWoorksheet.prototype = {
{ {
var sFormula = Data.sFormula var sFormula = Data.sFormula
var cell = ws._getCell(nRow, nCol); var cell = ws._getCell(nRow, nCol);
ws.workbook.dependencyFormulas.deleteMasterNodes(ws.getId(), cell.getName());
cell.setFormula(sFormula); cell.setFormula(sFormula);
cell.formulaParsed.setFormula(sFormula);
addToArrRecalc(ws.workbook, ws.getId(), cell.getName()); addToArrRecalc(ws.workbook, ws.getId(), cell.getName());
ws.workbook.needRecalc[ getVertexId(ws.getId(),cell.getName()) ] = [ ws.getId(),cell.getName() ]; ws.workbook.needRecalc2.nodes[ getVertexId(ws.getId(),cell.getName()) ] = [ ws.getId(),cell.getName() ];
if( ws.workbook.needRecalc.length < 0) ws.workbook.needRecalc.length = 0; ws.workbook.needRecalc2.nodesLength++;
ws.workbook.needRecalc.length++;
} }
} }
else if(historyitem_Worksheet_ColProp == Type) else if(historyitem_Worksheet_ColProp == Type)
......
...@@ -44,6 +44,7 @@ function DependencyGraph(wb) { ...@@ -44,6 +44,7 @@ function DependencyGraph(wb) {
this.nodesCell = null; this.nodesCell = null;
this.nodesArea = null; this.nodesArea = null;
this.nodeslength = null; this.nodeslength = null;
this.bSetRefError = false;
this.clear(); this.clear();
} }
DependencyGraph.prototype = { DependencyGraph.prototype = {
...@@ -52,6 +53,7 @@ DependencyGraph.prototype = { ...@@ -52,6 +53,7 @@ DependencyGraph.prototype = {
this.nodesCell = {}; this.nodesCell = {};
this.nodesArea = {}; this.nodesArea = {};
this.nodeslength = 0; this.nodeslength = 0;
this.bSetRefError = false;
}, },
nodeExist : function(node){ nodeExist : function(node){
return this.nodeExist2(node.sheetId, node.cellId); return this.nodeExist2(node.sheetId, node.cellId);
...@@ -82,6 +84,7 @@ DependencyGraph.prototype = { ...@@ -82,6 +84,7 @@ DependencyGraph.prototype = {
return this.addNode(node.sheetId, node.cellId); return this.addNode(node.sheetId, node.cellId);
}, },
addNode : function(sheetId, cellId){ addNode : function(sheetId, cellId){
var _this = this;
var nodeId = getVertexId(sheetId, cellId) var nodeId = getVertexId(sheetId, cellId)
var oRes = this.nodesId[nodeId]; var oRes = this.nodesId[nodeId];
if(null == oRes) if(null == oRes)
...@@ -93,7 +96,7 @@ DependencyGraph.prototype = { ...@@ -93,7 +96,7 @@ DependencyGraph.prototype = {
var nodesSheetArea = this.nodesArea[node.sheetId]; var nodesSheetArea = this.nodesArea[node.sheetId];
if(null == nodesSheetArea) if(null == nodesSheetArea)
{ {
nodesSheetArea = new RangeDataManager(null); nodesSheetArea = new RangeDataManager(function(data, from, to){_this._changeNode(data, from, to);});
this.nodesArea[node.sheetId] = nodesSheetArea; this.nodesArea[node.sheetId] = nodesSheetArea;
} }
nodesSheetArea.add(oBBoxNode, node); nodesSheetArea.add(oBBoxNode, node);
...@@ -103,13 +106,11 @@ DependencyGraph.prototype = { ...@@ -103,13 +106,11 @@ DependencyGraph.prototype = {
var nodesSheetCell = this.nodesCell[node.sheetId]; var nodesSheetCell = this.nodesCell[node.sheetId];
if(null == nodesSheetCell) if(null == nodesSheetCell)
{ {
nodesSheetCell = new CellArea(null); nodesSheetCell = new CellArea(function(data, from, to){_this._changeNode(data, from, to);});
this.nodesCell[node.sheetId] = nodesSheetCell; this.nodesCell[node.sheetId] = nodesSheetCell;
} }
nodesSheetCell.add(oBBoxNode.r1, oBBoxNode.c1, node); nodesSheetCell.add(oBBoxNode.r1, oBBoxNode.c1, node);
} }
this.nodesId[node.nodeId] = node;
this.nodeslength++;
oRes = node; oRes = node;
} }
return oRes; return oRes;
...@@ -145,23 +146,7 @@ DependencyGraph.prototype = { ...@@ -145,23 +146,7 @@ DependencyGraph.prototype = {
} }
return arr; return arr;
}, },
deleteNode : function(n, bSetRefError){ deleteNode : function(node){
var node = this.nodesId[n.nodeId];
if( node )
{
var oSlaves = node.deleteAllSlaveEdges();
if(bSetRefError)
{
//выставляем #REF!
for(var i in oSlaves)
{
var slave = oSlaves[i];
slave.setRefError();
this.wb.needRecalc[slave.nodeId] = [slave.sheetId, slave.cellId ];
this.wb.needRecalc.length++;
}
}
this.deleteMasterNodes(node.sheetId, node.cellId);
if(node.isArea) if(node.isArea)
{ {
var nodesSheetArea = this.nodesArea[node.sheetId]; var nodesSheetArea = this.nodesArea[node.sheetId];
...@@ -174,9 +159,26 @@ DependencyGraph.prototype = { ...@@ -174,9 +159,26 @@ DependencyGraph.prototype = {
if(nodesSheetCell) if(nodesSheetCell)
nodesSheetCell.removeElement(new RangeDataManagerElem(node.getBBox(), node)); nodesSheetCell.removeElement(new RangeDataManagerElem(node.getBBox(), node));
} }
delete this.nodesId[node.nodeId]; },
this.nodeslength--; deleteNodes : function(sheetId, bbox){
var bSetRefErrorOld = this.bSetRefError;
this.bSetRefError = true;
var nodesSheetArea = this.nodesArea[sheetId];
var oGetRes;
if(nodesSheetArea)
{
oGetRes = nodesSheetArea.get(bbox);
for(var i = 0, length = oGetRes.inner.length; i < length; ++i)
nodesSheetArea.removeElement(oGetRes.inner[i]);
}
var nodesSheetCell = this.nodesCell[sheetId];
if(nodesSheetCell)
{
oGetRes = nodesSheetCell.get(bbox);
for(var i = 0, length = oGetRes.length; i < length; ++i)
nodesSheetCell.removeElement(oGetRes[i]);
} }
this.bSetRefError = bSetRefErrorOld;
}, },
deleteMasterNodes : function(sheetId, cellId){ deleteMasterNodes : function(sheetId, cellId){
var node = this.getNode(sheetId, cellId); var node = this.getNode(sheetId, cellId);
...@@ -191,6 +193,12 @@ DependencyGraph.prototype = { ...@@ -191,6 +193,12 @@ DependencyGraph.prototype = {
} }
return node; return node;
}, },
deleteMasterNodes2 : function(sheetId, cellId){
var node = this.deleteMasterNodes(sheetId, cellId);
if(node && node.refCount <= 0)
this.deleteNode(node);
return node;
},
getSlaveNodes : function(sheetId, cellId){ getSlaveNodes : function(sheetId, cellId){
//todo //todo
return null; return null;
...@@ -206,60 +214,68 @@ DependencyGraph.prototype = { ...@@ -206,60 +214,68 @@ DependencyGraph.prototype = {
var _this = this; var _this = this;
var bHor = 0 != offset.offsetCol; var bHor = 0 != offset.offsetCol;
var toDelete = offset.offsetCol < 0 || offset.offsetRow < 0; var toDelete = offset.offsetCol < 0 || offset.offsetRow < 0;
var bSetRefErrorOld = this.bSetRefError;
this.bSetRefError = true;
var oShiftGetBBox = shiftGetBBox(BBox, bHor);
var sShiftGetBBoxName = oShiftGetBBox.getName();
this.wb.needRecalc.nodes[getVertexId(wsId, sShiftGetBBoxName)] = [wsId, sShiftGetBBoxName];
this.wb.needRecalc.length++;
var nodesSheetArea = this.nodesArea[wsId]; var nodesSheetArea = this.nodesArea[wsId];
if(nodesSheetArea) if(nodesSheetArea)
{ nodesSheetArea.shift(BBox, !toDelete, bHor);
var oShiftGet = nodesSheetArea.shiftGet(BBox, bHor);
if(oShiftGet && oShiftGet.elems && oShiftGet.elems.outer)
{
for(var i = 0, length = oShiftGet.elems.outer.length; i < length; i++)
{
var elem = oShiftGet.elems.outer[i];
var node = elem.data;
this.wb.needRecalc[node.nodeId] = [node.sheetId, node.cellId ];
this.wb.needRecalc.length++;
}
}
//временно выставляем fChange
nodesSheetArea.fChange = function(node, from, to){_this._moveNode(node, from, to, BBox, offset, wsId);};
nodesSheetArea.shift(BBox, !toDelete, bHor, oShiftGet);
nodesSheetArea.fChange = null;
}
var nodesSheetCell = this.nodesCell[wsId]; var nodesSheetCell = this.nodesCell[wsId];
if(nodesSheetCell) if(nodesSheetCell)
{
nodesSheetCell.fChange = function(node, from, to){_this._moveNode(node, from, to, BBox, offset, wsId);};
nodesSheetCell.shift(BBox, !toDelete, bHor); nodesSheetCell.shift(BBox, !toDelete, bHor);
nodesSheetCell.fChange = null; this.bSetRefError = bSetRefErrorOld;
}
}, },
_moveNode : function(node, from, to, BBox, offset, wsId) _changeNode : function(node, from, to)
{ {
var toDelete = null == to; var toDelete = null == to;
if(toDelete) var toAdd = null == from;
this.deleteNode(node, true); var wsId = node.sheetId;
if(toAdd)
{
this.nodesId[node.nodeId] = node;
this.nodeslength++;
}
else if(toDelete)
{
var oSlaves = node.deleteAllSlaveEdges();
if(this.bSetRefError)
{
//выставляем #REF!
for(var i in oSlaves)
{
var slave = oSlaves[i];
slave.setRefError(wsId, node.cellId);
}
}
this.deleteMasterNodes(node.sheetId, node.cellId);
delete this.nodesId[node.nodeId];
this.nodeslength--;
}
else else
{ {
var sOldnodeId = node.nodeId; var sOldnodeId = node.nodeId;
var sOldCellId = node.cellId; var sOldCellId = node.cellId;
if((from.r1 == to.r1 && from.c1 == to.c1) || (from.r2 == to.r2 && from.c2 == to.c2)) if((from.r1 == to.r1 && from.c1 == to.c1) || (from.r2 == to.r2 && from.c2 == to.c2))
{
node.moveStretch(to); node.moveStretch(to);
this.wb.needRecalc[node.nodeId] = [node.sheetId, node.cellId ];
this.wb.needRecalc.length++;
}
else else
node.move(offset, BBox, wsId, toDelete); node.move({offsetCol: to.c1 - from.c1, offsetRow: to.r1 - from.r1}, wsId, toDelete);
delete this.nodesId[sOldnodeId]; delete this.nodesId[sOldnodeId];
this.nodesId[node.nodeId] = node; this.nodesId[node.nodeId] = node;
}
//важно что ячейки уже сдвинулись, поэтому до вызова returnCell нужно сделать node.move //важно что ячейки уже сдвинулись, поэтому до вызова returnCell нужно сделать node.move
if(!node.isArea)
{
var cwf = this.wb.cwf[wsId]; var cwf = this.wb.cwf[wsId];
if(cwf && !node.isArea) if(cwf)
{ {
var cell = node.returnCell(); var cell = node.returnCell();
if( cell && cell.formulaParsed ) if( cell && cell.formulaParsed )
{ {
if(!toAdd)
delete cwf.cells[sOldCellId]; delete cwf.cells[sOldCellId];
if(!toDelete) if(!toDelete)
cwf.cells[node.cellId] = node.cellId; cwf.cells[node.cellId] = node.cellId;
...@@ -267,53 +283,43 @@ DependencyGraph.prototype = { ...@@ -267,53 +283,43 @@ DependencyGraph.prototype = {
} }
} }
}, },
helper : function(BBoxFrom, oBBoxTo, wsId){ getCellInRange : function(sheetId, bbox){
var oGetRes, node, nodesSheetCell = this.nodesCell[wsId], nodesSheetArea = this.nodesArea[wsId]; var res = [], oGetRes, nodesSheetCell = this.nodesCell[sheetId];
var offset = {offsetCol: oBBoxTo.c1 - BBoxFrom.c1, offsetRow: oBBoxTo.r1 - BBoxFrom.r1};
var elem, bbox;
if(nodesSheetCell) if(nodesSheetCell)
{ {
oGetRes = nodesSheetCell.get(BBoxFrom); oGetRes = nodesSheetCell.get(bbox);
for(var i = 0, length = oGetRes.length; i < length; i++) for(var i = 0, length = oGetRes.length; i < length; i++)
{ {
elem = oGetRes[i]; elem = oGetRes[i];
bbox = elem.bbox; res.push(elem.data);
node = elem.data;
nodesSheetCell.removeElement(elem);
this._moveNode(node, bbox, new Asc.Range(bbox.c1 + offset.offsetCol, bbox.r1 + offset.offsetRow, bbox.c2 + offset.offsetCol, bbox.r2 + offset.offsetRow), BBoxFrom, offset, wsId);
nodesSheetCell.add(bbox.r1 + offset.offsetRow, bbox.c1 + offset.offsetCol, elem.data);
this.wb.needRecalc[node.nodeId] = [node.sheetId, node.cellId ];
this.wb.needRecalc.length++;
} }
} }
return res;
},
getAreaInRange : function(sheetId, bbox){
var res = [], oGetRes, nodesSheetArea = this.nodesArea[sheetId];
if(nodesSheetArea) if(nodesSheetArea)
{ {
oGetRes = nodesSheetArea.get(BBoxFrom); oGetRes = nodesSheetArea.get(bbox);
for(var i = 0, length = oGetRes.inner.length; i < length; i++) for(var i = 0, length = oGetRes.all.length; i < length; i++)
{ {
elem = oGetRes.inner[i]; elem = oGetRes.all[i];
bbox = elem.bbox; res.push(elem.data);
node = elem.data;
nodesSheetArea.removeElement(elem);
this._moveNode(node, bbox, new Asc.Range(bbox.c1 + offset.offsetCol, bbox.r1 + offset.offsetRow, bbox.c2 + offset.offsetCol, bbox.r2 + offset.offsetRow), BBoxFrom, offset, wsId);
nodesSheetArea.add(node.getBBox(), elem.data);
this.wb.needRecalc[node.nodeId] = [node.sheetId, node.cellId ];
this.wb.needRecalc.length++;
}
for(var i = 0, length = oGetRes.outer.length; i < length; i++)
{
node = oGetRes.outer[i].data;
this.wb.needRecalc[node.nodeId] = [node.sheetId, node.cellId ];
this.wb.needRecalc.length++;
}
oGetRes = nodesSheetArea.get(oBBoxTo);
for(var i = 0, length = oGetRes.outer.length; i < length; i++)
{
node = oGetRes.outer[i].data;
this.wb.needRecalc[node.nodeId] = [node.sheetId, node.cellId ];
this.wb.needRecalc.length++;
} }
} }
return res;
},
getInRange : function(sheetId, bbox){
return this.getCellInRange(sheetId, bbox).concat(this.getAreaInRange(sheetId, bbox));
},
helper : function(BBoxFrom, oBBoxTo, wsId){
var oGetRes, node, nodesSheetCell = this.nodesCell[wsId], nodesSheetArea = this.nodesArea[wsId];
var offset = {offsetCol: oBBoxTo.c1 - BBoxFrom.c1, offsetRow: oBBoxTo.r1 - BBoxFrom.r1};
var elem, bbox;
if(nodesSheetCell)
oGetRes = nodesSheetCell.move(BBoxFrom, oBBoxTo);
if(nodesSheetArea)
oGetRes = nodesSheetArea.move(BBoxFrom, oBBoxTo);
}, },
drawDep : function(cellId,se){ drawDep : function(cellId,se){
// ToDo неиспользуемая функция, реализовать после выпуска // ToDo неиспользуемая функция, реализовать после выпуска
...@@ -480,8 +486,8 @@ DependencyGraph.prototype = { ...@@ -480,8 +486,8 @@ DependencyGraph.prototype = {
}, },
removeNodeBySheetId : function(sheetId){ removeNodeBySheetId : function(sheetId){
var arr = false; var arr = false;
this.wb.needRecalc = []; // this.wb.needRecalc = [];
this.wb.needRecalc.length = 0; // this.wb.needRecalc.length = 0;
var nodesSheet = nodes[sheetId]; var nodesSheet = nodes[sheetId];
if(nodesSheet){ if(nodesSheet){
var aNodes = nodesSheet.getAll(); var aNodes = nodesSheet.getAll();
...@@ -492,8 +498,8 @@ DependencyGraph.prototype = { ...@@ -492,8 +498,8 @@ DependencyGraph.prototype = {
for(var id2 in se){ for(var id2 in se){
if(se[id2].sheetId != sheetId){ if(se[id2].sheetId != sheetId){
if(!arr) arr = true; if(!arr) arr = true;
this.wb.needRecalc[id2] = [se[id2].sheetId,se[id2].cellId]; // this.wb.needRecalc[id2] = [se[id2].sheetId,se[id2].cellId];
this.wb.needRecalc.length++; // this.wb.needRecalc.length++;
// arr.push(se[id2]); // arr.push(se[id2]);
} }
} }
...@@ -520,9 +526,11 @@ DependencyGraph.prototype = { ...@@ -520,9 +526,11 @@ DependencyGraph.prototype = {
for(var i in aElems) for(var i in aElems)
{ {
elem = aElems[i]; elem = aElems[i];
var sheetId = elem[0];
var cellId = elem[1];
//нужно обавлять в oSheetRanges даже несушествующие node, чтобы поддержать именении ячеек в SUM(A1:B2) //нужно обавлять в oSheetRanges даже несушествующие node, чтобы поддержать именении ячеек в SUM(A1:B2)
this._getNodeDependenceNodeToRange(elem.sheetId, Asc.g_oRangeCache.getAscRange(elem.cellId), oSheetRanges); this._getNodeDependenceNodeToRange(sheetId, Asc.g_oRangeCache.getAscRange(cellId), oSheetRanges);
node = this.getNode(elem.sheetId, elem.cellId); node = this.getNode(sheetId, cellId);
if(node && null == oRes.oWeightMap[node.nodeId]) if(node && null == oRes.oWeightMap[node.nodeId])
{ {
//все node из aElems записываем в master //все node из aElems записываем в master
...@@ -579,7 +587,7 @@ DependencyGraph.prototype = { ...@@ -579,7 +587,7 @@ DependencyGraph.prototype = {
for(var j in aAllOuter) for(var j in aAllOuter)
{ {
var node = aAllOuter[j].data; var node = aAllOuter[j].data;
aElems[node.nodeId] = {sheetId: node.sheetId, cellId: node.cellId}; aElems[node.nodeId] = [node.sheetId, node.cellId];
} }
} }
} }
...@@ -619,7 +627,11 @@ DependencyGraph.prototype = { ...@@ -619,7 +627,11 @@ DependencyGraph.prototype = {
else else
{ {
if(oWeightMapElem.master && oWeightMapElem.max > 1) if(oWeightMapElem.master && oWeightMapElem.max > 1)
oWeightMapElem.master = false;//если повторно пришли в master node, то не считаем ее master {
//если повторно пришли в master node, то не считаем ее master
oWeightMapElem.master = false;
oWeightMapElem.max--;
}
} }
} }
if(1 == oWeightMapElem.max) if(1 == oWeightMapElem.max)
...@@ -702,46 +714,70 @@ Vertex.prototype = { ...@@ -702,46 +714,70 @@ Vertex.prototype = {
{ {
return this.bbox; return this.bbox;
}, },
setRefError : function() setRefError : function(wsId, cellId)
{ {
var cell = this.returnCell(); var cell = this.returnCell();
if( cell && cell.formulaParsed ) if( cell && cell.formulaParsed )
{ {
cell.formulaParsed.setRefError(this.sheetId, this.cellId); this.wb.dependencyFormulas.deleteMasterNodes2( wsId, cellId );
cell.formulaParsed.setRefError(wsId, cellId);
cell.setFormula(cell.formulaParsed.assemble(), true); cell.setFormula(cell.formulaParsed.assemble(), true);
addToArrRecalc(this.wb, wsId, cellId);
this.wb.needRecalc.nodes[this.nodeId] = [this.sheetId, this.cellId ];
this.wb.needRecalc.length++;
} }
}, },
move : function(offset, oBBox, wsId, toDelete) move : function(offset, wsId, toDelete)
{ {
var oNewBBox = new Asc.Range(this.bbox.c1 + offset.offsetCol, this.bbox.r1 + offset.offsetRow, this.bbox.c2 + offset.offsetCol, this.bbox.r2 + offset.offsetRow);
var sNewBBoxName = oNewBBox.getName();
var _sn = this.getSlaveEdges(); var _sn = this.getSlaveEdges();
var cell = this.returnCell();
if( cell && cell.formulaParsed )
{
this.wb.dependencyFormulas.deleteMasterNodes2(wsId, this.bbox.getName());
addToArrRecalc(this.wb, wsId, sNewBBoxName);
}
for( var _id in _sn ){ for( var _id in _sn ){
var cell = _sn[_id].returnCell(), cellName; var slave = _sn[_id]
cell = slave.returnCell();
if( cell && cell.formulaParsed ) if( cell && cell.formulaParsed )
{ {
cellName = cell.getName(); this.wb.dependencyFormulas.deleteMasterNodes2( slave.sheetId, slave.cellId );
cell.formulaParsed.shiftCells( offset, oBBox, this, wsId, toDelete); cell.formulaParsed.shiftCells( offset, null, this, slave.sheetId, toDelete);
cell.setFormula(cell.formulaParsed.assemble(), true); cell.setFormula(cell.formulaParsed.assemble(), true);
addToArrRecalc(this.wb, slave.sheetId, slave.cellId);
this.wb.needRecalc.nodes[slave.nodeId] = [slave.sheetId, slave.cellId ];
this.wb.needRecalc.length++;
} }
} }
this.bbox = new Asc.Range(this.bbox.c1 + offset.offsetCol, this.bbox.r1 + offset.offsetRow, this.bbox.c2 + offset.offsetCol, this.bbox.r2 + offset.offsetRow); this.bbox = oNewBBox;
this.cellId = this.bbox.getName(); this.cellId = sNewBBoxName;
this.nodeId = getVertexId(this.sheetId, this.cellId); this.nodeId = getVertexId(this.sheetId, this.cellId);
this.wb.needRecalc.nodes[this.nodeId] = [this.sheetId, this.cellId ];
this.wb.needRecalc.length++;
}, },
moveStretch : function(bboxTo) moveStretch : function(bboxTo)
{ {
var sNewName = bboxTo.getName(); var sNewName = bboxTo.getName();
var _sn = this.getSlaveEdges(); var _sn = this.getSlaveEdges();
for( var _id in _sn ){ for( var _id in _sn ){
var cell = _sn[_id].returnCell(), cellName; var slave = _sn[_id];
var cell = slave.returnCell();
if( cell && cell.formulaParsed ){ if( cell && cell.formulaParsed ){
cellName = cell.getName(); this.wb.dependencyFormulas.deleteMasterNodes2( slave.sheetId, slave.cellId );
cell.formulaParsed.stretchArea( this, sNewName ); cell.formulaParsed.stretchArea( this, sNewName );
cell.setFormula(cell.formulaParsed.assemble(), true); cell.setFormula(cell.formulaParsed.assemble(), true);
addToArrRecalc(this.wb, slave.sheetId, slave.cellId);
this.wb.needRecalc.nodes[slave.nodeId] = [slave.sheetId, slave.cellId ];
this.wb.needRecalc.length++;
} }
} }
this.bbox = bboxTo this.bbox = bboxTo
this.cellId = sNewName; this.cellId = sNewName;
this.nodeId = getVertexId(this.sheetId, this.cellId); this.nodeId = getVertexId(this.sheetId, this.cellId);
this.wb.needRecalc.nodes[this.nodeId] = [this.sheetId, this.cellId ];
this.wb.needRecalc.length++;
}, },
//добавляем ведущую ячейку. //добавляем ведущую ячейку.
addMasterEdge : function(node){ addMasterEdge : function(node){
...@@ -855,8 +891,6 @@ function unLockDraw(wb){ ...@@ -855,8 +891,6 @@ function unLockDraw(wb){
} }
} }
function addToArrRecalc(wb, sheetId, cellId){ function addToArrRecalc(wb, sheetId, cellId){
if(!wb.isNeedCacheClean)
{
var temp = arrRecalc[sheetId]; var temp = arrRecalc[sheetId];
if( !temp ) if( !temp )
{ {
...@@ -864,7 +898,6 @@ function addToArrRecalc(wb, sheetId, cellId){ ...@@ -864,7 +898,6 @@ function addToArrRecalc(wb, sheetId, cellId){
arrRecalc[sheetId] = temp; arrRecalc[sheetId] = temp;
} }
temp[cellId] = cellId; temp[cellId] = cellId;
}
} }
function buildRecalc(_wb,notrec){ function buildRecalc(_wb,notrec){
var ws; var ws;
...@@ -950,22 +983,15 @@ function helpRecalc(dep1, nR, calculatedCells, wb){ ...@@ -950,22 +983,15 @@ function helpRecalc(dep1, nR, calculatedCells, wb){
} }
function sortDependency(wb){ function sortDependency(wb){
if ( wb.isNeedCacheClean ){
buildRecalc(wb, true);
arrRecalc = {};
}
var nR = wb.needRecalc; var nR = wb.needRecalc;
var elem = null; if(nR && (nR.length > 0))
var ar2 = {};
var sr = {};
if(nR && nR.length > 0)
{
for(var i in nR)
{
if("length" != i)
{ {
elem = nR[i];
ar2[elem[0] + elem[1]] = {sheetId: elem[0], cellId: elem[1]};
}
}
var oCleanCellCacheArea = {}; var oCleanCellCacheArea = {};
var oNodeDependence = wb.dependencyFormulas.getNodeDependence(ar2); var oNodeDependence = wb.dependencyFormulas.getNodeDependence(nR.nodes);
for(var i in oNodeDependence.oMasterNodes) for(var i in oNodeDependence.oMasterNodes)
{ {
var node = oNodeDependence.oMasterNodes[i]; var node = oNodeDependence.oMasterNodes[i];
...@@ -986,7 +1012,7 @@ function sortDependency(wb){ ...@@ -986,7 +1012,7 @@ function sortDependency(wb){
} }
} }
} }
wb.needRecalc = {length: 0}; wb.needRecalc = {nodes: {}, length:0};
} }
function _sortDependency(wb, node, oWeightMap, bBad, oCleanCellCacheArea){ function _sortDependency(wb, node, oWeightMap, bBad, oCleanCellCacheArea){
if(node) if(node)
...@@ -1104,7 +1130,7 @@ function Workbook(sUrlPath, eventsHandlers, oApi){ ...@@ -1104,7 +1130,7 @@ function Workbook(sUrlPath, eventsHandlers, oApi){
this.oApi = oApi; this.oApi = oApi;
this.sUrlPath = sUrlPath; this.sUrlPath = sUrlPath;
this.handlers = eventsHandlers; this.handlers = eventsHandlers;
this.needRecalc = {length:0}; this.needRecalc = {nodes: {}, length:0};
this.dependencyFormulas = new DependencyGraph(this); this.dependencyFormulas = new DependencyGraph(this);
this.nActive = 0; this.nActive = 0;
...@@ -1352,17 +1378,17 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){ ...@@ -1352,17 +1378,17 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){
_c.setFormula(_c.formulaParsed.moveSheet(tempW).assemble());//Перестраиваем трехмерные ссылки в формуле. _c.setFormula(_c.formulaParsed.moveSheet(tempW).assemble());//Перестраиваем трехмерные ссылки в формуле.
this.dependencyFormulas.deleteMasterNodes(_ws.Id, cID); this.dependencyFormulas.deleteMasterNodes(_ws.Id, cID);
addToArrRecalc(this, _ws.getId(), cID); addToArrRecalc(this, _ws.getId(), cID);
this.needRecalc[ getVertexId(_ws.getId(),cID) ] = [ _ws.getId(),cID ]; // this.needRecalc[ getVertexId(_ws.getId(),cID) ] = [ _ws.getId(),cID ];
if( this.needRecalc.length < 0) this.needRecalc.length = 0; // if( this.needRecalc.length < 0) this.needRecalc.length = 0;
this.needRecalc.length++; // this.needRecalc.length++;
} }
else if( f.indexOf(_ws.getName()) < 0 ){ else if( f.indexOf(_ws.getName()) < 0 ){
this.dependencyFormulas.deleteMasterNodes(_ws.Id, cID); this.dependencyFormulas.deleteMasterNodes(_ws.Id, cID);
_ws._BuildDependencies({id:cID}); _ws._BuildDependencies({id:cID});
addToArrRecalc(this, _ws.getId(), cID); addToArrRecalc(this, _ws.getId(), cID);
this.needRecalc[ getVertexId(_ws.getId(),cID) ] = [ _ws.getId(),cID ]; // this.needRecalc[ getVertexId(_ws.getId(),cID) ] = [ _ws.getId(),cID ];
if( this.needRecalc.length < 0) this.needRecalc.length = 0; // if( this.needRecalc.length < 0) this.needRecalc.length = 0;
this.needRecalc.length++; // this.needRecalc.length++;
} }
} }
} }
...@@ -1414,9 +1440,9 @@ Workbook.prototype.removeWorksheet=function(nIndex, outputParams){ ...@@ -1414,9 +1440,9 @@ Workbook.prototype.removeWorksheet=function(nIndex, outputParams){
if( se[id].sheetId != removedSheet[0].getId() ){ if( se[id].sheetId != removedSheet[0].getId() ){
var _ws = this.getWorksheetById(se[id].sheetId), f = _ws.getCell2(se[id].cellId).getCells()[0].sFormula, cID = se[id].cellId; var _ws = this.getWorksheetById(se[id].sheetId), f = _ws.getCell2(se[id].cellId).getCells()[0].sFormula, cID = se[id].cellId;
addToArrRecalc(this, _ws.getId(), cID); addToArrRecalc(this, _ws.getId(), cID);
this.needRecalc[ getVertexId(_ws.getId(),cID) ] = [ _ws.getId(),cID ]; // this.needRecalc[ getVertexId(_ws.getId(),cID) ] = [ _ws.getId(),cID ];
if( this.needRecalc.length < 0) this.needRecalc.length = 0; // if( this.needRecalc.length < 0) this.needRecalc.length = 0;
this.needRecalc.length++; // this.needRecalc.length++;
} }
} }
} }
...@@ -2072,7 +2098,7 @@ Woorksheet.prototype.init=function(){ ...@@ -2072,7 +2098,7 @@ Woorksheet.prototype.init=function(){
Строится список ячеек, которые необходимо пересчитать при открытии. Это ячейки имеющие атрибут f.ca или значение в которых неопределено. Строится список ячеек, которые необходимо пересчитать при открытии. Это ячейки имеющие атрибут f.ca или значение в которых неопределено.
*/ */
if(oCell.sFormula && (oCell.oFormulaExt.ca || !oCell.oValue.getValueWithoutFormat()) ){ if(oCell.sFormula && (oCell.oFormulaExt.ca || !oCell.oValue.getValueWithoutFormat()) ){
this.workbook.needRecalc[ getVertexId( this.Id, sCellId ) ] = [this.Id, sCellId]; this.workbook.needRecalc.nodes[ getVertexId( this.Id, sCellId ) ] = [this.Id, sCellId];
this.workbook.needRecalc.length++; this.workbook.needRecalc.length++;
} }
//в редакторе не работаем с расширенными формулами //в редакторе не работаем с расширенными формулами
...@@ -2890,15 +2916,17 @@ Woorksheet.prototype._removeCell=function(nRow, nCol, cell){ ...@@ -2890,15 +2916,17 @@ Woorksheet.prototype._removeCell=function(nRow, nCol, cell){
oUndoRedoData_CellData.style = cell.xfs.clone(); oUndoRedoData_CellData.style = cell.xfs.clone();
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_RemoveCell, this.getId(), new Asc.Range(0, nRow, gc_nMaxCol0, nRow), new UndoRedoData_CellSimpleData(nRow, nCol, oUndoRedoData_CellData, null)); History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_RemoveCell, this.getId(), new Asc.Range(0, nRow, gc_nMaxCol0, nRow), new UndoRedoData_CellSimpleData(nRow, nCol, oUndoRedoData_CellData, null));
} }
if(cell.formulaParsed)
this.wb.dependencyFormulas.deleteMasterNodes2( this.getId(), cell.getName() );
this.helperRebuildFormulas(cell,cell.getName(),cell.getName()); // this.helperRebuildFormulas(cell,cell.getName(),cell.getName());
addToArrRecalc(this.workbook, this.getId(), cell.getName()); // addToArrRecalc(this.workbook, this.getId(), cell.getName());
if( this.workbook.dependencyFormulas.getNode(this.getId(),this.getName()) && !this.workbook.needRecalc[ getVertexId(this.getId(),cell.getName()) ] ){ // if( this.workbook.dependencyFormulas.getNode(this.getId(),this.getName()) && !this.workbook.needRecalc[ getVertexId(this.getId(),cell.getName()) ] ){
this.workbook.needRecalc[ getVertexId(this.getId(),cell.getName()) ] = [ this.getId(),cell.getName() ]; // this.workbook.needRecalc[ getVertexId(this.getId(),cell.getName()) ] = [ this.getId(),cell.getName() ];
if( this.workbook.needRecalc.length < 0) this.workbook.needRecalc.length = 0; // if( this.workbook.needRecalc.length < 0) this.workbook.needRecalc.length = 0;
this.workbook.needRecalc.length++; // this.workbook.needRecalc.length++;
} // }
delete row.c[nCol]; delete row.c[nCol];
if(row.isEmpty()) if(row.isEmpty())
...@@ -3098,11 +3126,6 @@ Woorksheet.prototype._prepareMoveRange=function(oBBoxFrom, oBBoxTo){ ...@@ -3098,11 +3126,6 @@ Woorksheet.prototype._prepareMoveRange=function(oBBoxFrom, oBBoxTo){
} }
return res; return res;
} }
Woorksheet.prototype._moveRecalcGraph=function(oBBoxFrom, oBBoxTo, offset){
var rec = this.workbook.dependencyFormulas.helper(oBBoxFrom, oBBoxTo,this.Id);
return rec;
}
Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
if(oBBoxFrom.isEqual(oBBoxTo)) if(oBBoxFrom.isEqual(oBBoxTo))
return; return;
...@@ -3159,11 +3182,14 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){ ...@@ -3159,11 +3182,14 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
var aRangesToCheck = this._prepareMoveRangeGetCleanRanges(oBBoxFrom, oBBoxTo); var aRangesToCheck = this._prepareMoveRangeGetCleanRanges(oBBoxFrom, oBBoxTo);
for(var i = 0, length = aRangesToCheck.length; i < length; i++) for(var i = 0, length = aRangesToCheck.length; i < length; i++)
aRangesToCheck[i].cleanAll(); aRangesToCheck[i].cleanAll();
//выставляем для slave refError
if(!copyRange)
this.workbook.dependencyFormulas.deleteNodes(this.getId(), oBBoxTo);
//перемещаем без истории //перемещаем без истории
History.TurnOff(); History.TurnOff();
//удаляем from без истории, потому что эти данные не терются а перемещаются //удаляем from без истории, потому что эти данные не терются а перемещаются
var oRangeFrom = this.getRange3(oBBoxFrom.r1, oBBoxFrom.c1, oBBoxFrom.r2, oBBoxFrom.c2 ), rec = {length:0};
if(!copyRange || (copyRange && this.workbook.bUndoChanges)){ if(!copyRange || (copyRange && this.workbook.bUndoChanges)){
var oRangeFrom = this.getRange3(oBBoxFrom.r1, oBBoxFrom.c1, oBBoxFrom.r2, oBBoxFrom.c2 )
oRangeFrom._setPropertyNoEmpty(null, null, function(cell, nRow0, nCol0, nRowStart, nColStart){ oRangeFrom._setPropertyNoEmpty(null, null, function(cell, nRow0, nCol0, nRowStart, nColStart){
var row = oThis._getRowNoEmpty(nRow0); var row = oThis._getRowNoEmpty(nRow0);
if(null != row) if(null != row)
...@@ -3171,7 +3197,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){ ...@@ -3171,7 +3197,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
}); });
} }
if(!copyRange){ if(!copyRange){
this._moveRecalcGraph(oBBoxFrom, oBBoxTo, offset); this.workbook.dependencyFormulas.helper(oBBoxFrom, oBBoxTo,this.Id);
} }
for ( var i in aTempObj.cells ) { for ( var i in aTempObj.cells ) {
...@@ -3186,13 +3212,13 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){ ...@@ -3186,13 +3212,13 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
if ( oTempCell.sFormula ) { if ( oTempCell.sFormula ) {
this.workbook.cwf[this.Id].cells[oTempCell.getName()] = oTempCell.getName(); this.workbook.cwf[this.Id].cells[oTempCell.getName()] = oTempCell.getName();
rec[ oTempCell.getName() ] = [ this.Id, oTempCell.getName() ];
rec.length++;
if(copyRange){ if(copyRange){
oTempCell.formulaParsed = new parserFormula( oTempCell.sFormula, oTempCell.oId.getID(), this ); oTempCell.formulaParsed = new parserFormula( oTempCell.sFormula, oTempCell.oId.getID(), this );
oTempCell.formulaParsed.parse(); oTempCell.formulaParsed.parse();
oTempCell.formulaParsed = oTempCell.formulaParsed.changeOffset(offset); oTempCell.formulaParsed = oTempCell.formulaParsed.changeOffset(offset);
oTempCell.sFormula = oTempCell.formulaParsed.assemble(); oTempCell.sFormula = oTempCell.formulaParsed.assemble();
addToArrRecalc(this.workbook, this.getId(), oTempCell.getName());
} }
} }
} }
...@@ -3231,10 +3257,20 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){ ...@@ -3231,10 +3257,20 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
if(oBBoxTo.c2 > this.nColsCount) if(oBBoxTo.c2 > this.nColsCount)
this.nColsCount = oBBoxTo.c2 + 1; this.nColsCount = oBBoxTo.c2 + 1;
if(!copyRange){
// this.workbook.buildDependency(); var sBBoxFromName = oBBoxFrom.getName();
//this.workbook.needRecalc = rec; this.workbook.needRecalc.nodes[getVertexId(this.getId(), sBBoxFromName)] = [this.getId(), sBBoxFromName];
this.workbook.needRecalc.length++;
}
var sBBoxToName = oBBoxTo.getName();
this.workbook.needRecalc.nodes[getVertexId(this.getId(), sBBoxToName)] = [this.getId(), sBBoxToName];
this.workbook.needRecalc.length++;
if ( this.workbook.isNeedCacheClean ){
/*
Если необходим пересчет, то по списку пересчитываемых ячеек сортируем граф зависимостей и пересчиываем в получившемся порядке. Плохим ячейкам с цикличискими ссылками выставляем ошибку "#REF!".
*/
sortDependency(this.workbook); sortDependency(this.workbook);
}
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_MoveRange, History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_MoveRange,
this.getId(), new Asc.Range(0, 0, gc_nMaxCol0, gc_nMaxRow0), this.getId(), new Asc.Range(0, 0, gc_nMaxCol0, gc_nMaxRow0),
new UndoRedoData_FromTo(new UndoRedoData_BBox(oBBoxFrom), new UndoRedoData_BBox(oBBoxTo), copyRange)); new UndoRedoData_FromTo(new UndoRedoData_BBox(oBBoxFrom), new UndoRedoData_BBox(oBBoxTo), copyRange));
...@@ -3752,41 +3788,25 @@ Cell.prototype.setValue=function(val,callback){ ...@@ -3752,41 +3788,25 @@ Cell.prototype.setValue=function(val,callback){
} }
//удаляем старые значения //удаляем старые значения
this.oValue.clean(); this.oValue.clean();
var needRecalc = false;
var ar = {};
var sheetId = this.ws.getId(); var sheetId = this.ws.getId();
if (this.sFormula) if (this.sFormula)
{ {
var node = wb.dependencyFormulas.deleteMasterNodes( ws.Id, this.oId.getID() ); wb.dependencyFormulas.deleteMasterNodes2( ws.Id, this.oId.getID() );
if(node && node.refCount <= 0)
wb.dependencyFormulas.deleteNode(node);
} }
if( null != val && val[0] != "=" || true == numFormat.isTextFormat()){ if( null != val && val[0] != "=" || true == numFormat.isTextFormat()){
if (this.sFormula){ if (this.sFormula){
if ( this.oId.getID() in wb.cwf[ws.Id].cells){ if ( this.oId.getID() in wb.cwf[ws.Id].cells){
delete wb.cwf[ws.Id].cells[this.oId.getID()]; delete wb.cwf[ws.Id].cells[this.oId.getID()];
} }
needRecalc = true;
}
else{
if( wb.dependencyFormulas.nodeExistWithArea( ws.Id, this.oId.getID() ) ){
needRecalc = true;
}
} }
} }
else{ else{
wb.cwf[ws.Id].cells[this.oId.getID()] = this.oId.getID(); wb.cwf[ws.Id].cells[this.oId.getID()] = this.oId.getID();
if(this.ws.workbook.isNeedCacheClean)
ar[this.oId.getID()] = this.oId.getID();
else
addToArrRecalc(this.ws.workbook, this.ws.getId(), this.oId.getID()); addToArrRecalc(this.ws.workbook, this.ws.getId(), this.oId.getID());
needRecalc = true;
} }
if(needRecalc) wb.needRecalc.nodes[getVertexId(sheetId,this.oId.getID())] = [sheetId, this.oId.getID()];
{
wb.needRecalc[getVertexId(sheetId,this.oId.getID())] = [sheetId, this.oId.getID()];
wb.needRecalc.length++; wb.needRecalc.length++;
}
this.sFormula = null; this.sFormula = null;
this.setFormulaCA(false); this.setFormulaCA(false);
if(val){ if(val){
...@@ -3797,20 +3817,12 @@ Cell.prototype.setValue=function(val,callback){ ...@@ -3797,20 +3817,12 @@ Cell.prototype.setValue=function(val,callback){
this.oValue.setValue(val); this.oValue.setValue(val);
} }
} }
if ( needRecalc && this.ws.workbook.isNeedCacheClean ){ if ( this.ws.workbook.isNeedCacheClean ){
/* /*
Если необходим пересчет, то по списку пересчитываемых ячеек сортируем граф зависимостей и пересчиываем в получившемся порядке. Плохим ячейкам с цикличискими ссылками выставляем ошибку "#REF!". Если необходим пересчет, то по списку пересчитываемых ячеек сортируем граф зависимостей и пересчиываем в получившемся порядке. Плохим ячейкам с цикличискими ссылками выставляем ошибку "#REF!".
*/ */
ws._BuildDependencies(ar);
sortDependency(this.ws.workbook); sortDependency(this.ws.workbook);
} }
// else if( this.ws.workbook.isNeedCacheClean == false ){
// if( ws.workbook.dependencyFormulas.nodeExistWithArea(this.ws.getId(),this.getName()) ){
// addToArrRecalc(this.ws.workbook, this.ws.getId(), this.oId.getID());
// wb.needRecalc[ getVertexId(this.ws.getId(),this.oId.getID()) ] = [ this.ws.getId(),this.oId.getID() ];
// wb.needRecalc.length++;
// }
// }
var DataNew = null; var DataNew = null;
if(History.Is_On()) if(History.Is_On())
DataNew = this.getValueData(); DataNew = this.getValueData();
...@@ -3833,34 +3845,20 @@ Cell.prototype.setValue2=function(array){ ...@@ -3833,34 +3845,20 @@ Cell.prototype.setValue2=function(array){
//удаляем сторое значение //удаляем сторое значение
var ws = this.ws; var ws = this.ws;
var wb = this.ws.workbook; var wb = this.ws.workbook;
var needRecalc = false;
var sheetId = this.ws.getId(); var sheetId = this.ws.getId();
if (this.sFormula){ if (this.sFormula){
var node = wb.dependencyFormulas.deleteMasterNodes( ws.Id, this.oId.getID(), true ); var node = wb.dependencyFormulas.deleteMasterNodes2( ws.Id, this.oId.getID(), true );
if(node && node.refCount <= 0)
wb.dependencyFormulas.deleteNode(node);
if ( this.oId.getID() in wb.cwf[ws.Id].cells) if ( this.oId.getID() in wb.cwf[ws.Id].cells)
delete wb.cwf[ws.Id].cells[this.oId.getID()]; delete wb.cwf[ws.Id].cells[this.oId.getID()];
needRecalc = true;
}
else{
if( wb.dependencyFormulas.nodeExistWithArea( ws.Id, this.oId.getID() ) ){
needRecalc = true;
}
} }
this.sFormula = null; this.sFormula = null;
this.oValue.clean(); this.oValue.clean();
this.setFormulaCA(false); this.setFormulaCA(false);
this.oValue.setValue2(array); this.oValue.setValue2(array);
if (needRecalc){
wb.needRecalc[getVertexId(sheetId,this.oId.getID())] = [sheetId, this.oId.getID()]; wb.needRecalc.nodes[getVertexId(sheetId,this.oId.getID())] = [sheetId, this.oId.getID()];
wb.needRecalc.length++; wb.needRecalc.length++;
/*
Если необходим пересчет, то по списку пересчитываемых ячеек сортируем граф зависимостей и пересчиываем в получившемся порядке. Плохим ячейкам с цикличискими ссылками выставляем ошибку "#REF!".
*/
//this.ws._BuildDependencies(ar);
sortDependency(this.ws.workbook); sortDependency(this.ws.workbook);
}
var DataNew = null; var DataNew = null;
if(History.Is_On()) if(History.Is_On())
DataNew = this.getValueData(); DataNew = this.getValueData();
...@@ -4617,7 +4615,7 @@ Range.prototype.setValue2=function(array){ ...@@ -4617,7 +4615,7 @@ Range.prototype.setValue2=function(array){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox; var oBBox = this.bbox;
History.StartTransaction(); History.StartTransaction();
var wb = this.worksheet.workbook, ws = this.worksheet, needRecalc = false, ar =[]; var wb = this.worksheet.workbook, ws = this.worksheet, ar =[];
//[{"text":"qwe","format":{"b":true, "i":false, "u":"none", "s":false, "fn":"Arial", "fs": 12, "c": 0xff00ff, "va": "subscript" }},{}...] //[{"text":"qwe","format":{"b":true, "i":false, "u":"none", "s":false, "fn":"Arial", "fs": 12, "c": 0xff00ff, "va": "subscript" }},{}...]
var oThis = this; var oThis = this;
/* /*
...@@ -6797,7 +6795,7 @@ Range.prototype.sort=function(nOption, nStartCol){ ...@@ -6797,7 +6795,7 @@ Range.prototype.sort=function(nOption, nStartCol){
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_Sort, this.worksheet.getId(), new Asc.Range(0, nRowFirst0, gc_nMaxCol0, nLastRow0), oRes); History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_Sort, this.worksheet.getId(), new Asc.Range(0, nRowFirst0, gc_nMaxCol0, nLastRow0), oRes);
this._sortByArray(oUndoRedoBBox, aSortData); this._sortByArray(oUndoRedoBBox, aSortData);
} }
buildRecalc(this.worksheet.workbook,true); buildRecalc(this.worksheet.workbook);
unLockDraw(this.worksheet.workbook); unLockDraw(this.worksheet.workbook);
return oRes; return oRes;
} }
...@@ -6868,20 +6866,14 @@ Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){ ...@@ -6868,20 +6866,14 @@ Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){
var lastName = oCurCell.getName(); var lastName = oCurCell.getName();
oCurCell.moveVer(shift); oCurCell.moveVer(shift);
rowTo.c[i] = oCurCell; rowTo.c[i] = oCurCell;
var sNewName = oCurCell.getName();
if(oCurCell.sFormula) if(oCurCell.sFormula)
{ {
var sNewName = oCurCell.getName();
oCurCell.setFormula(oCurCell.formulaParsed.changeOffset({offsetCol:0, offsetRow:shift}).assemble());//получаем новую формулу, путем сдвига входящих в нее ссылок на ячейки на offsetCol и offsetRow. не путать с shiftCells - меняет одну конкретную ячейку в формуле, changeOffset - меняет оффсет для всех входящих в формулу ячеек. oCurCell.setFormula(oCurCell.formulaParsed.changeOffset({offsetCol:0, offsetRow:shift}).assemble());//получаем новую формулу, путем сдвига входящих в нее ссылок на ячейки на offsetCol и offsetRow. не путать с shiftCells - меняет одну конкретную ячейку в формуле, changeOffset - меняет оффсет для всех входящих в формулу ячеек.
this.worksheet.workbook.dependencyFormulas.deleteMasterNodes( this.worksheet.Id, lastName );//разрываем ссылки между старой ячейкой и ведущими ячейками для нее. this.worksheet.workbook.dependencyFormulas.deleteMasterNodes2( this.worksheet.Id, lastName );//разрываем ссылки между старой ячейкой и ведущими ячейками для нее.
delete this.worksheet.workbook.cwf[this.worksheet.Id].cells[lastName];
addToArrRecalc(this.worksheet.workbook, this.worksheet.getId(), sNewName); addToArrRecalc(this.worksheet.workbook, this.worksheet.getId(), sNewName);
/*this.worksheet.workbook.needRecalc[ getVertexId(this.worksheet.getId(),sNewName) ] = [ this.worksheet.getId(),sNewName ]; this.worksheet.workbook.needRecalc.nodes[ getVertexId(this.worksheet.getId(),sNewName) ] = [ this.worksheet.getId(),sNewName ];
if( this.worksheet.workbook.needRecalc.length < 0) this.worksheet.workbook.needRecalc.length = 0; this.worksheet.workbook.needRecalc.length++;
this.worksheet.workbook.needRecalc.length++;*/
}
else{
// sortDependency(this.worksheet, {sNewName:sNewName});
} }
} }
else else
...@@ -6890,20 +6882,13 @@ Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){ ...@@ -6890,20 +6882,13 @@ Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){
{ {
//здесь достаточно простого delete, потому что на самом деле в функции ячейки только меняются местами, удаления не происходит //здесь достаточно простого delete, потому что на самом деле в функции ячейки только меняются местами, удаления не происходит
delete rowTo.c[i]; delete rowTo.c[i];
var sNewName = (new CellAddress(nIndexTo, i, 0)).getID();
addToArrRecalc(this.worksheet.workbook, this.worksheet.getId(), sNewName);
/*this.worksheet.workbook.needRecalc[ getVertexId(this.worksheet.getId(),sNewName) ] = [ this.worksheet.getId(),sNewName ];
if( this.worksheet.workbook.needRecalc.length < 0) this.worksheet.workbook.needRecalc.length = 0;
this.worksheet.workbook.needRecalc.length++;*/
// sortDependency(this.worksheet, {sNewName:sNewName});
} }
} }
} }
} }
// this.worksheet.workbook.buildDependency();
// this.worksheet.workbook.needRecalc = rec;
// sortDependency(this.worksheet.workbook); if (this.worksheet.workbook.isNeedCacheClean)
sortDependency(this.worksheet.workbook);
if(false == this.worksheet.workbook.bUndoChanges && false == this.worksheet.workbook.bRedoChanges) if(false == this.worksheet.workbook.bUndoChanges && false == this.worksheet.workbook.bRedoChanges)
{ {
//восстанавливаем удаленые гиперссылки //восстанавливаем удаленые гиперссылки
...@@ -7282,7 +7267,7 @@ Range.prototype.promote=function(bCtrl, bVertical, nIndex){ ...@@ -7282,7 +7267,7 @@ Range.prototype.promote=function(bCtrl, bVertical, nIndex){
else if(null != oFromCell) else if(null != oFromCell)
{ {
//копируем полностью //копируем полностью
if(!oFromCell.sFormula){ if(!oFromCell.formulaParsed){
var DataOld = oCopyCell.getValueData(); var DataOld = oCopyCell.getValueData();
oCopyCell.oValue = oFromCell.oValue.clone(oCopyCell); oCopyCell.oValue = oFromCell.oValue.clone(oCopyCell);
var DataNew = oCopyCell.getValueData(); var DataNew = oCopyCell.getValueData();
...@@ -7291,26 +7276,22 @@ Range.prototype.promote=function(bCtrl, bVertical, nIndex){ ...@@ -7291,26 +7276,22 @@ Range.prototype.promote=function(bCtrl, bVertical, nIndex){
//todo //todo
// if(oCopyCell.isEmptyTextString()) // if(oCopyCell.isEmptyTextString())
// this.worksheet._getHyperlink().remove({r1: oCopyCell.oId.getRow0(), c1: oCopyCell.oId.getCol0(), r2: oCopyCell.oId.getRow0(), c2: oCopyCell.oId.getCol0()}); // this.worksheet._getHyperlink().remove({r1: oCopyCell.oId.getRow0(), c1: oCopyCell.oId.getCol0(), r2: oCopyCell.oId.getRow0(), c2: oCopyCell.oId.getCol0()});
addToArrRecalc(this.worksheet.workbook, this.worksheet.getId(), oCopyCell.getName());
this.worksheet.workbook.needRecalc[ getVertexId(this.worksheet.getId(),oCopyCell.getName()) ] = [ this.worksheet.getId(),oCopyCell.getName() ];
if( this.worksheet.workbook.needRecalc.length < 0) this.worksheet.workbook.needRecalc.length = 0;
this.worksheet.workbook.needRecalc.length++;
} }
else{ else{
var assemb; var assemb;
var _p_ = new parserFormula(oFromCell.sFormula,oCopyCell.getName(),this.worksheet); var _p_ = new parserFormula(oFromCell.sFormula,oCopyCell.getName(),this.worksheet);
if( _p_.parse() ){ if( _p_.parse() ){
assemb = _p_.changeOffset(oCopyCell.getOffset2(oFromCell.getName())).assemble(); assemb = _p_.changeOffset(oCopyCell.getOffset2(oFromCell.getName())).assemble();
oCopyCell.setValue("="+assemb); var sCopyCellName = oCopyCell.getName();
oCopyCell.setFormula(assemb);
} addToArrRecalc(this.worksheet.workbook, this.worksheet.getId(), sCopyCellName);
this.worksheet.workbook.needRecalc[ getVertexId(this.worksheet.getId(),oCopyCell.getName()) ] = [ this.worksheet.getId(),oCopyCell.getName() ]; this.worksheet.workbook.needRecalc.nodes[ getVertexId(this.worksheet.getId(),sCopyCellName) ] = [ this.worksheet.getId(),sCopyCellName ];
if( this.worksheet.workbook.needRecalc.length < 0) this.worksheet.workbook.needRecalc.length = 0;
this.worksheet.workbook.needRecalc.length++; this.worksheet.workbook.needRecalc.length++;
} }
} }
} }
} }
}
} }
//добавляем замерженые области //добавляем замерженые области
var nShiftHorizontal = 0; var nShiftHorizontal = 0;
......
...@@ -3986,11 +3986,14 @@ RangeDataManager.prototype = { ...@@ -3986,11 +3986,14 @@ RangeDataManager.prototype = {
else else
aToChange.sort(function(a, b){return _this.shiftSort(a, b, true, true);}); aToChange.sort(function(a, b){return _this.shiftSort(a, b, true, true);});
} }
if(null != this.fChange)
{
for(var i = 0, length = aToChange.length; i < length; ++i) for(var i = 0, length = aToChange.length; i < length; ++i)
{ {
var item = aToChange[i]; var item = aToChange[i];
this.fChange.call(this, item.elem.data, item.elem.bbox, item.to); this.fChange.call(this, item.elem.data, item.elem.bbox, item.to);
} }
}
//убираем fChange, чтобы потом послать его только на одну операцию, а не 2 //убираем fChange, чтобы потом послать его только на одну операцию, а не 2
var fOldChange = this.fChange; var fOldChange = this.fChange;
this.fChange = null; this.fChange = null;
...@@ -4008,6 +4011,25 @@ RangeDataManager.prototype = { ...@@ -4008,6 +4011,25 @@ RangeDataManager.prototype = {
if(null != item.to) if(null != item.to)
this.add(item.to, item.elem.data); this.add(item.to, item.elem.data);
} }
},
move : function(from, to)
{
//убираем fChange, чтобы потом послать его только на одну операцию, а не 2
var fOldChange = this.fChange;
this.fChange = null;
var nOffsetRow = to.r1 - from.r1;
var nOffsetCol = to.c1 - from.c1;
var oGetRes = this.get(from);
for(var i = 0, length = oGetRes.inner.length; i < length; i++)
{
var elem = oGetRes.inner[i];
var oNewBBox = new Asc.Range(elem.bbox.c1 + nOffsetCol, elem.bbox.r1 + nOffsetRow, elem.bbox.c2 + nOffsetCol, elem.bbox.r2 + nOffsetRow);
if(null != fOldChange)
fOldChange.call(this, elem.data, elem.bbox, oNewBBox);
this.removeElement(elem);
this.add(oNewBBox, elem.data);
}
this.fChange = fOldChange; this.fChange = fOldChange;
}, },
getAll : function() getAll : function()
...@@ -4055,7 +4077,10 @@ CellArea.prototype = { ...@@ -4055,7 +4077,10 @@ CellArea.prototype = {
var oNewRow = oStoredNode.storedValue; var oNewRow = oStoredNode.storedValue;
var oNewColNode = new TreeRBNode(col, null); var oNewColNode = new TreeRBNode(col, null);
var oStoredColNode = oNewRow.insertOrGet(oNewColNode); var oStoredColNode = oNewRow.insertOrGet(oNewColNode);
oNewColNode.storedValue = new RangeDataManagerElem(new Asc.Range(col, row, col, row), value); var storedValue = new RangeDataManagerElem(new Asc.Range(col, row, col, row), value);
oNewColNode.storedValue = storedValue;
if(null != this.fChange)
this.fChange.call(this, storedValue.data, null, storedValue.bbox);
}, },
get : function(bbox) get : function(bbox)
{ {
...@@ -4078,7 +4103,11 @@ CellArea.prototype = { ...@@ -4078,7 +4103,11 @@ CellArea.prototype = {
var row = rowElem.storedValue; var row = rowElem.storedValue;
var cellElem = row.getElem(elem.bbox.c1); var cellElem = row.getElem(elem.bbox.c1);
if(cellElem) if(cellElem)
{
row.deleteNode(cellElem); row.deleteNode(cellElem);
if(null != this.fChange)
this.fChange.call(this, cellElem.storedValue.data, cellElem.storedValue.bbox, null);
}
} }
}, },
shiftGet : function(bbox, bHor) shiftGet : function(bbox, bHor)
...@@ -4151,11 +4180,14 @@ CellArea.prototype = { ...@@ -4151,11 +4180,14 @@ CellArea.prototype = {
else else
aToChange.sort(function(a, b){return a.to.r1 - b.to.r1;}); aToChange.sort(function(a, b){return a.to.r1 - b.to.r1;});
} }
if(null != this.fChange)
{
for(var i = 0, length = aToChange.length; i < length; ++i) for(var i = 0, length = aToChange.length; i < length; ++i)
{ {
var item = aToChange[i]; var item = aToChange[i];
this.fChange.call(this, item.elem.data, item.elem.bbox, item.to); this.fChange.call(this, item.elem.data, item.elem.bbox, item.to);
} }
}
//убираем fChange, чтобы потом послать его только на одну операцию, а не 2 //убираем fChange, чтобы потом послать его только на одну операцию, а не 2
var fOldChange = this.fChange; var fOldChange = this.fChange;
this.fChange = null; this.fChange = null;
...@@ -4175,6 +4207,25 @@ CellArea.prototype = { ...@@ -4175,6 +4207,25 @@ CellArea.prototype = {
} }
this.fChange = fOldChange; this.fChange = fOldChange;
}, },
move : function(from, to)
{
//убираем fChange, чтобы потом послать его только на одну операцию, а не 2
var fOldChange = this.fChange;
this.fChange = null;
var nOffsetRow = to.r1 - from.r1;
var nOffsetCol = to.c1 - from.c1;
var oGetRes = this.get(from);
for(var i = 0, length = oGetRes.length; i < length; i++)
{
var elem = oGetRes[i];
var oNewBBox = new Asc.Range(elem.bbox.c1 + nOffsetCol, elem.bbox.r1 + nOffsetRow, elem.bbox.c2 + nOffsetCol, elem.bbox.r2 + nOffsetRow);
if(null != fOldChange)
fOldChange.call(this, elem.data, elem.bbox, oNewBBox);
this.removeElement(elem);
this.add(oNewBBox.r1, oNewBBox.c1, elem.data);
}
this.fChange = fOldChange;
},
getAll : function(){ getAll : function(){
var aRes = []; var aRes = [];
var oRows = this.rows.getNodeAll(); var oRows = this.rows.getNodeAll();
......
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