Cycling through shapes on a diagram editor


Author
Message
Ron Sawyer
Ron Sawyer
Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)
Group: Forum Members
Posts: 16, Visits: 1
I have tried to implement this but am just not quite getting it...

In the editor, I want an easy way to select a shape that is underneath the current shape - but I don't want to send the current shape behind.

Let me give an example to try to better explain.

I have a circle on a diagram. Above it is a triangle, and above that is a rectangle.

The first click would select the rectangle so I could edit its properties.
I could then click in the same location to select the next shape below it - in this case the triangle.
I could then click again in the same location to select the next shape below that - the circle.

I want to preserve their Z-Order in the end diagram, I just want to edit the circle's properties without moving the shapes above it (or changing their Z-orders.)

Is this easily done?
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K

Hi,

You can get all 2D shapes under the mouse cursor using the following piece of code:

 

NPointF location = view.GetMousePositionInDevice();

NHitTestContext hitTestContext = view.ProvideDocumentHitTestContext();

NNodeList nodes = document.HitTest(location, -1, NFilters.Shape2D, hitTestContext);

                                                           

To select one of the shapes use:

 

view.Selection.SingleSelect(nodes[index]);



Best Regards,
Nevron Support Team


Ron Sawyer
Ron Sawyer
Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)
Group: Forum Members
Posts: 16, Visits: 1
Thank you for the very quick reply - and my apologies for not responding sooner.

The code you provided allowed me to add a solution that the product manager is happy with - and so things are mostly good. It isn't exactly as I described, but he is content.

I tried a different solution, which kind of works, but sometimes causes an exception. Since the other solution works, we aren't too worried, but I am kind of interested in what I'm missing/doing wrong.

In the nDrawingView1_Click event I check to see if the control key and the alt key is down. If so, I try to cycle through the shapes under the mouse (in our case, we have a class attached to the tag to store some custom properties) and then try to do a single select on the next shape under the mouse. Most of the time this works. Sometimes I get an exception. I am thinking that maybe the _click event is the wrong event? Is there a better one? here is the code:

if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
{



if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt)
{
try
{
//////////////////////////////////////
// Get a list of nodes under the
// mouse ointer
NPointF location = nDrawingView1.GetMousePositionInDevice();
NHitTestContext hitTestContext = nDrawingView1.ProvideDocumentHitTestContext();
NNodeList nodes = nDrawingDocumentEditors.HitTest(location, -1, NFilters.Shape2D, hitTestContext);
if (nodes != null)
{
if (nodes.Count > 1)
{
/////////////////////////////////////
// Go through each node and grab
// its tag.
int MyNodesSelectedIndex = 0;
for (int ii = 0; ii < nodes.Count; ii++)
{
NShape LclShape;
LclShape = nodes[ii] as NShape;
if (LclShape != null)
{
MentorCustomShapeTagBase LclTag;
LclTag = LclShape.Tag as MentorCustomShapeTagBase;
if (LclTag != null)
{
/////////////////////////////////////
// Compare the current tag with the
// tag on the property grid. If it
// is the right one, select the next
// one or wrap to the beginning of the
// list
if (propertyGrid1.SelectedObject != null)
{
if (LclTag == propertyGrid1.SelectedObject)
{
MyNodesSelectedIndex = ii + 1;
if (MyNodesSelectedIndex >= nodes.Count)
{
MyNodesSelectedIndex = 0;
}
break;
}
}
}
} // end if
}
try
{
nDrawingView1.Selection.SingleSelect(nodes[MyNodesSelectedIndex]);
}
catch (Exception ex)
{
string LclString = ex.Message;

}

}
}
}
catch (Exception ex)
{
string LclString = ex.Message; // for debug purposes
}
}
}
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K

Hi Ron,

What's the exception you get? May be it is best to send your sample project to support@nevron.com. We'll check on it and tell you what's wrong.



Best Regards,
Nevron Support Team


Ron Sawyer
Ron Sawyer
Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)
Group: Forum Members
Posts: 16, Visits: 1
I was *afraid* you'd ask for that...

The project is too large to send at this time - but it is fair enough that you want a sample. I think for now we'll stick with the solution we have and try to create a sample sometime in the future.

As always, thanks for the quick reply.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search