Commit ba844cc0 authored by Romain Loth's avatar Romain Loth

CTRL+Z extended to changeLevel

parent eb8da4a4
......@@ -146,6 +146,7 @@ function SelectionEngine() {
* Main function for any selecting action
*
* @nodes: eg targeted array (only ids)
* @noState: bool flag to avoid registering new state (useful for CTRL+Z)
*
* external usage : clickHandler, search, changeType, filters, tag click...
*/
......@@ -154,12 +155,14 @@ function SelectionEngine() {
if (!args) args = {}
if (isUndef(args.nodes)) args.nodes = []
if (isUndef(args.noState)) args.noState = false
if (TW.conf.debug.logSelections) {
var tMS2_deb = performance.now()
console.log("IN SelectionEngine.MultipleSelection2:")
console.log("nodes", args.nodes)
console.log("noState", args.noState)
}
// deselects only the active ones (based on SystemState())
......@@ -314,8 +317,10 @@ function SelectionEngine() {
}
// it's a new SystemState
TW.pushState( { 'sels': theSelection,
'rels': activeRelations } )
if (! args.noState) {
TW.pushState( { 'sels': theSelection,
'rels': activeRelations } )
}
// we send our "gotNodeSet" event
// (signal for plugins that a search-selection was done or a new hand picked selection)
......@@ -330,7 +335,6 @@ function SelectionEngine() {
TW.partialGraph.render();
updateRelatedNodesPanel( theSelection , same, oppos )
if (TW.conf.debug.logSelections) {
......@@ -848,24 +852,33 @@ var TinaWebJS = function ( sigmacanvas ) {
}
var timeoutIdCTRLZ = window.setTimeout(function() {
// console.log("pop state")
let previousState = TW.states.pop()
if (TW.gui.selectionActive) {
deselectNodes(TW.SystemState())
TW.gui.selectionActive = false
}
console.log("pop state")
TW.states.pop()
deselectNodes(previousState)
let returningState = TW.SystemState()
// restoring selection
if (returningState.selectionNids.length) {
TW.instance.selNgn.MultipleSelection2({nodes:returningState.selectionNids})
TW.gui.selectionActive = true
// changes active/highlight and refresh
// POSS turn the nostate version into a select fun like deselect (ie no state, no refresh)
TW.instance.selNgn.MultipleSelection2({
nodes: returningState.selectionNids,
noState: true
})
}
else {
cancelSelection()
TW.gui.selectionActive = false
TW.partialGraph.refresh()
}
TW.partialGraph.refresh()
// restoring level
if (returningState.level != previousState.level) {
changeLevel(returningState)
}
}, 100)
......
......@@ -461,17 +461,29 @@ function changeType() {
// v
// local selection SysSt = {level: false, activetypes:XY}
//
function changeLevel() {
// optional args:
// @optionalTargetState: in rare cases we already have it (like CTRL+Z)
// (=> avoid redoing property computations and state push)
function changeLevel(optionalTargetState) {
console.log('got optionalTargetState', optionalTargetState)
// show waiting cursor
TW.gui.elHtml.classList.add('waiting');
// let the waiting cursor appear
setTimeout(function() {
var present = TW.SystemState(); // Last
var sels = present.selectionNids ;//[144, 384, 543]//TW.states[last].selectionNids;
var sels
deselectNodes()
if (optionalTargetState) {
sels = optionalTargetState.selectionNids
}
else {
var present = TW.SystemState(); // Last
sels = present.selectionNids
deselectNodes()
}
let selsChecker = {}
for (let i in sels) {
......@@ -484,7 +496,14 @@ function changeLevel() {
// types eg [true] <=> '1'
// [true, true] <=> '1|1'
var activetypes = present.activetypes;
var activetypes;
if (optionalTargetState) {
activetypes = optionalTargetState.activetypes
}
else {
activetypes = present.activetypes;
}
var activetypesKey = activetypes.map(Number).join("|")
TW.partialGraph.graph.clear();
......@@ -516,28 +535,33 @@ function changeLevel() {
}
}
var futurelevel = null
if(present.level) { // [Change to Local] when level=Global(1)
var futurelevel
if (optionalTargetState) {
futurelevel = optionalTargetState.level
}
else {
futurelevel = ! present.level
}
if(! futurelevel) { // [Change to Local] when level=Global(1)
for(var nid in nodesToAdd)
add1Elem(nid)
for(var eid in edgesToAdd)
add1Elem(eid)
// Adding intra-neighbors edges O(voisinage²)
voisinage = Object.keys(voisinage)
for(var i=0;i<voisinage.length;i++) {
for(var j=1;j<voisinage.length;j++) {
if( voisinage[i]!=voisinage[j] ) {
// console.log( "\t" + voisinage[i] + " vs " + voisinage[j] )
add1Elem( voisinage[i]+";"+voisinage[j] )
}
}
}
futurelevel = false;
// Selection is unchanged, no need to call MultipleSelection2
// Adding intra-neighbors edges O(voisinage²)
voisinage = Object.keys(voisinage)
for(var i=0;i<voisinage.length;i++) {
for(var j=1;j<voisinage.length;j++) {
if( voisinage[i]!=voisinage[j] ) {
// console.log( "\t" + voisinage[i] + " vs " + voisinage[j] )
add1Elem( voisinage[i]+";"+voisinage[j] )
}
}
}
} else { // [Change to Global] when level=Local(0)
......@@ -553,20 +577,19 @@ function changeLevel() {
}
// var t1 = performance.now()
futurelevel = true;
// console.log("returning to global took:", t1-t0)
// Nodes Selection now:
if(sels.length>0) {
TW.instance.selNgn.MultipleSelection2({nodes:sels});
TW.gui.selectionActive=true;
}
}
TW.pushState({
level: futurelevel
})
// Selection is unchanged, but all the nodes are new
// so we call MultipleSelection2 to set up node attributes
TW.instance.selNgn.MultipleSelection2({nodes:sels, noState:true});
if (! optionalTargetState) {
TW.pushState({
level: futurelevel
})
}
TW.partialGraph.camera.goTo({x:0, y:0, ratio:1.2, angle: 0})
TW.partialGraph.refresh()
......
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