Implementing hierarchical selection

Hi,

I would like implement hierarchical multiselection.
I have a subgraph containing child GoNodes and both suggraph and nodes are selectable. But using Ctrl +Mouse, when user selects a
child and then parent, I would like to deselect the child and other
selected children of siubgraph if any and set selection to only subgraph.
I tried using OnObjectselected/selectionfinished but it is getting
called repeatedly for each selection. Could you please suggest
on how overcome this.
Thanks,

Down inside the GoSelection class, where it is adding an object to the selection, it adds the new object to the selection, and raises the OnObjectSelected for that object.

but then... what WAS the primary select may not be anymore, so GoSelection does:
oldprimary.OnLostSelection(this);
view.RaiseObjectLostSelection(oldprimary);
oldprimary.OnGotSelection(this);
view.RaiseObjectGotSelection(oldprimary);
It does this because primary selection handles may appear different than secondary handles, and it's telling the object... you've lost primary selection, but you are now part of the secondary selection.
Are you trying to always avoid having a child selected if the parent SubGraph is, or just in the case where the child is selected, then the parent?

Hi,

I am trying avoid a scenario where both parent and its children are
selected. This forms a invalid condition for my application. If a parent
is selected, it is assumed that all of its children are selected. So
I would like to always reset selection of all children, when a parent is selected. That is at any point of time, there should not be a parent
as well as any of its child together in the selection list. There can be
a child or its parent but not both.
Thanks/

ok… the code below handles the first case (selecting child, then parent) but not the reverse.

using System;
using System.Collections.Generic;
using System.Text;
using Northwoods.Go;
namespace SubGraphApp {
[Serializable]
class GoToolSelectingSubGraph : GoToolSelecting {
public GoToolSelectingSubGraph(GoView v) : base(v) { }
private void DeselectChildren(GoSubGraph subG) {
foreach (GoObject o in subG) {
View.Selection.Remove(o);
GoSubGraph sg = o as GoSubGraph;
if (sg != null) {
// make sure children aren't selected.
DeselectChildren(sg);
}
}
}
public override void DoSelect(GoInputEventArgs evt) {
base.DoSelect(evt);
if (this.CurrentObject != null && evt.Control) {
GoSubGraph sg = this.CurrentObject as GoSubGraph;
if (sg != null) {
// make sure children aren't selected.
DeselectChildren(sg);
}
}
}
}

}
use this tool via
goView1.ReplaceMouseTool(typeof(GoToolSelecting), new GoToolSelectingSubGraph(goView1));
I can finish this in the morning if you need me to... but you may have it worked out by then.

Here’s the rest of it… the DeselectParents bit.

[code]

using System;
using System.Collections.Generic;
using System.Text;
using Northwoods.Go;
namespace SubGraphApp {
[Serializable]
class GoToolSelectingSubGraph : GoToolSelecting {
public GoToolSelectingSubGraph(GoView v) : base(v) { }
private void DeselectChildren(GoSubGraph subG) {
foreach (GoObject o in subG) {
View.Selection.Remove(o);
GoSubGraph sg = o as GoSubGraph;
if (sg != null) {
// make sure children aren't selected.
DeselectChildren(sg);
}
}
}
private void DeselectParents(GoObject obj) {
GoSubGraph parent = obj.Parent as GoSubGraph;
while (parent != null) {
View.Selection.Remove(parent);
parent = parent.Parent as GoSubGraph;
}
}
public override void DoSelect(GoInputEventArgs evt) {
base.DoSelect(evt);
if (this.CurrentObject != null && evt.Control) {
GoSubGraph sg = this.CurrentObject as GoSubGraph;
if (sg != null) {
// make sure children aren't selected.
DeselectChildren(sg);
}
DeselectParents(this.CurrentObject);
}
}
}
}
[/code]

actually, you said “Ctrl-mouse” in your first note… but looking at this again, I think you get into “bad states” (by your definition) with the shift-key as well. Removing the evt.Control above fixes that.

Hi,

Thanks alot. All our custom selection rules are working now.
Thanks/-