Crainiate Community

Support and discussion for users of Crainiate component software products
Welcome to Crainiate Community Sign in | Join | Help
in Search

Connect line and disconnect line

Last post 10-17-2007 7:55 PM by mmcguirk. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 08-02-2007 1:22 AM

    Connect line and disconnect line

    There is a line, I can move this line to a table then this line will connect to the table, use the same way this line will be disconnected the table.

    My question is that before and after connection and disconnection is there any event I can capture ? Because I want to do something at that exact moment. Of course I can capture all kind of mouse event to handle this problem but it is a big work. So I think to do all by myself is not the first choice.

     Thanks a lot

     

     

    • 24.80.169.44
  • 08-02-2007 8:16 AM In reply to

    Re: Connect line and disconnect line

    Hello,

    you can use OnUpdateActions event of the Model class. AFAIK is it being called just after the interactive operation, but before the elements are redrawn (so you can still change the connection in that event).

    There is the Actions property in the event object that contains references to every involved element.
    I figured out that in case of changing the connection (at least reassigning it to another element) the first element is the connector being moved. Newly connected elements can be accessed by connector.Start.DockedElement and connector.End.DockedElement.
    Next two elements in the e.Actions collection are the previously connected elements (Start and End respectively) and they can match the newly connected elements if you dragged the connection to the same element (there was no logical change, but the event is raised), so you can check whether the connection was changed and perform some actions according to that.

    As I wrote above, you can even change the connection in that event, for example to prevent some user actions you can force to restore the connection to the previous state (this is what I do in my application).
    If you need further help, please let me know, I'll try to help.
    • 83.3.189.82
  • 08-02-2007 7:46 PM In reply to

    Re: Connect line and disconnect line

    You can use the model.Runtime.CanDock property and override this to determine exactly which docking operation are allowed by the user.

    You can then use the great advice above (bere in mind that UpdateActions is fired after the actions have been applied to the model), or hook into the line.Start.DockChanged / line.End.DockChanged events.

    To capture the DockChanged event for the interactively drawn element, use the line.UpdateElement property to return a clone of the line being updated.

    • 86.155.94.155
  • 08-02-2007 9:42 PM In reply to

    Re: Connect line and disconnect line

    Could you tell me how to capture the line.Start.DockChanged / line.End.DockChanged events ? I hope that I can capture these events in a visual way, like capture click event of button controler. If I have to use other way to capture these events then could you give a sample ? (segment of source code is pretty good.)

     

    • 64.59.144.88
  • 08-02-2007 9:49 PM In reply to

    Re: Connect line and disconnect line

    Hi,

    Your advice is great, it can work very well. But one thing is not comfortable for me. Once I moved a line (not connect, not disconnect), the event will be raised too. So I have to do more to handle this problem, a little upset. Do you have any idea about this ?

     

    • 64.59.144.88
  • 08-03-2007 9:38 AM In reply to

    Re: Connect line and disconnect line

    As I wrote earlier you have to detect whether the connection was changed.

    e.Actions[0] is the new line
    e.Actions[1] is the old Start docked element
    e.Actions[2] is the old End docked element

    All you have to do is to compare the newline.Start.DockedElement with e.Actions[1] and the same for the End element respectively. If they are all the same, the connection was not changed and you don't have to perform any special actions.

    This line.Start.DockChanged and line.End.DockChanged events seems to be better (and they are not raised if you just move a line).
    I didn't know about that. I am wondering if I can still restore the connection in that event. CanDock won't help me, because when I return false there and release the button on forbidden element the connection will be left unconnected on that element, which is not good for me. It should be restored to its previous state.
    I do it by changing the connector.Start.Shape and connector.End.Shape, but will this DockChanged event be called then ?
    It could cause a forever loop when changed from inside of this event, so maybe I should remove these event handler for a moment of restoring the line or is it safe ?
    • 83.3.189.82
  • 08-03-2007 11:16 AM In reply to

    Re: Connect line and disconnect line

    What needs to happen is that the action is cancelled when the docked element is incorrect according to your business logic.

    To do this, you need to create a subclass of the model class and override UpdateElements. Remove any of the actions from RenderDesign.Actions that you do not want to be updated.

    Filed under: ,
    • 86.155.94.155
  • 08-03-2007 1:28 PM In reply to

    Re: Connect line and disconnect line

    Thanks, it does work, but there is a problem.
    UpdateElements method is called before line.Start.DockChanged (and line.End as well), so I think these events are not good for making a decision about whether to restore the connection or not, because it is already too late for that.
    I think I'll have to stick to my current solution - to manually restore a connection in UpdateActions event - unless you can tell me what can be better for that.
    Not every UpdateElements call must be related to changing connection, so I would have to check the RenderDesign.Actions for that (like I do now in UpdateActions). The only advantage I see of making this decision in UpdateElements and not in UpdateActions is that I would not have to restore the connection manually - just remove the element from the Actions collection.
    • 83.3.189.82
  • 10-12-2007 3:32 PM In reply to

    Re: Connect line and disconnect line

    If I have 2 shapes, with ports, and I disconnect a line connecting the shapes, the UpdateActions event args are line this.

    e.Actions[0] = the line

    e.Action[1] = the start shape

    e.Action[2] = the end shape

    What I need to know is which port the line was connected to.

    • 69.221.86.182
  • 10-15-2007 10:41 AM In reply to

    Re: Connect line and disconnect line

    The line will have an ActionElement property set to the original line object. The Start.Port and End.Port properties should contain the original Port references.

    • 86.43.88.2
  • 10-17-2007 7:55 PM In reply to

    Re: Connect line and disconnect line

    James Westgate:

    The line will have an ActionElement property set to the original line object. The Start.Port and End.Port properties should contain the original Port references.

    Here is the code I have:

        if (e.Actions[0] is Line)

        {

            Line line = (Line)e.Actions[0];

        }

    The watch window shows that line.UpdateElement is null.

    Is this something that has been fixed since version 4.1.2780.38323?

    • 69.221.86.182
Page 1 of 1 (11 items)