Commit ba844cc0 authored by Romain Loth's avatar Romain Loth

CTRL+Z extended to changeLevel

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