K
Konrad Anton
Hello all,
I'm working on some kind of modelling tool where the user manipulates a
model (consisting of Entities and Associations between them, each coming
in several flavours) through a diagram (where Entity shapes are
represented by 2D shapes, e.g. squares, and Association shapes by 1D
connector shapes, e.g. arrows).
I'm using Visio 2007 Professional and VS2008, writing the add-in in C#
(if that matters).
When the user uses any 1D shape to connect two Entities, he expects the
shape to "become" an Association shape of the suitable flavour. If more
than one flavour is suitable, the add-in asks the user which flavour to
use. Sounds pretty feasible.
I've realised this using a ConnectAdded and a ConnectRemoved event handler.
* The ConnectAdded handler, given a Connect object, finds out which part
of the Connect is the 1D shape.
* For this shape, it checks if it is now connected to two Entity shapes
and hasn't been before (using something like a mapping from 1D shape's
Shape.GUID to a counter for the number of connected 2D shapes).
* If it is, the handler prompts the user about the flavour.
* It then drops a new Association shape from our stencil and copies
DoubleClick handler, Text(+) and ShapeData from old Association shape to
new Association shape.
* For each 2D shape connected to beginX or endX of the old 1D shape, it
glues the 2D shape to the beginX or endX of the new 1D shape.
* It deletes the old 1D shape.
Now the problem: when the user keeps on detaching a connector shape and
attaching it somewhere else, changing the flavour when prompted, then
after roughly 5 to 15 times, the Shape.Text of the newly dropped
connector shape is unwritable in (+), failing with a not-so-helpful
"Requested operation is presently disabled" COMException.
Last time I had such a problem, it was apparently caused by another
handler which asked an incoming Shape for its ID and its Document's ID.
When I deactivated that handler, the Shape.Text problem went away,
leaving me with the hypothesis that the .Document getter of the deleted
shape must have corrupted an internal data structure which wasn't used
until the next time Shape.Text was set.
Of course, I don't expect a complete solution from you, but perhaps
someone has had a similar problem, or notices that it's just forbidden
to drop shapes from an event handler or something.
Thanks in advance,
Konrad
I'm working on some kind of modelling tool where the user manipulates a
model (consisting of Entities and Associations between them, each coming
in several flavours) through a diagram (where Entity shapes are
represented by 2D shapes, e.g. squares, and Association shapes by 1D
connector shapes, e.g. arrows).
I'm using Visio 2007 Professional and VS2008, writing the add-in in C#
(if that matters).
When the user uses any 1D shape to connect two Entities, he expects the
shape to "become" an Association shape of the suitable flavour. If more
than one flavour is suitable, the add-in asks the user which flavour to
use. Sounds pretty feasible.
I've realised this using a ConnectAdded and a ConnectRemoved event handler.
* The ConnectAdded handler, given a Connect object, finds out which part
of the Connect is the 1D shape.
* For this shape, it checks if it is now connected to two Entity shapes
and hasn't been before (using something like a mapping from 1D shape's
Shape.GUID to a counter for the number of connected 2D shapes).
* If it is, the handler prompts the user about the flavour.
* It then drops a new Association shape from our stencil and copies
DoubleClick handler, Text(+) and ShapeData from old Association shape to
new Association shape.
* For each 2D shape connected to beginX or endX of the old 1D shape, it
glues the 2D shape to the beginX or endX of the new 1D shape.
* It deletes the old 1D shape.
Now the problem: when the user keeps on detaching a connector shape and
attaching it somewhere else, changing the flavour when prompted, then
after roughly 5 to 15 times, the Shape.Text of the newly dropped
connector shape is unwritable in (+), failing with a not-so-helpful
"Requested operation is presently disabled" COMException.
Last time I had such a problem, it was apparently caused by another
handler which asked an incoming Shape for its ID and its Document's ID.
When I deactivated that handler, the Shape.Text problem went away,
leaving me with the hypothesis that the .Document getter of the deleted
shape must have corrupted an internal data structure which wasn't used
until the next time Shape.Text was set.
Of course, I don't expect a complete solution from you, but perhaps
someone has had a similar problem, or notices that it's just forbidden
to drop shapes from an event handler or something.
Thanks in advance,
Konrad