Crainiate Community

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

Only allow connections between ports?

Last post 05-29-2008 9:45 AM by Mathy. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 05-28-2008 2:40 PM

    • Mathy
    • Top 10 Contributor
    • Joined on 07-16-2007
    • Posts 19

    Only allow connections between ports?

    Is this possible? I would like something like click on port, drag to other port, finished! So clicking + dragging anywhere else is not possible.

    • 194.7.161.130
  • 05-28-2008 11:10 PM In reply to

    Re: Only allow connections between ports?

    Each shape and port class has a Direction property which can be set to In, Out or None.If you set all the shapes to None, lines cant be docked by the user. 

    • 86.130.74.248
  • 05-29-2008 8:13 AM In reply to

    • Mathy
    • Top 10 Contributor
    • Joined on 07-16-2007
    • Posts 19

    Re: Only allow connections between ports?

     But this does not stop you from drawing undocked lines on the model, which is what I want to avoid.

    • 194.7.161.130
  • 05-29-2008 9:09 AM In reply to

    Re: Only allow connections between ports?

     I guess you would have to override UpdateElements in Model class. It is called just before any changes are commited (at least this is how I see it), and you can ignore or modify the changes that are to be done to the model.

    You need to inspect RenderDesign.Actions and discard them if there is a line to be created that is not docked to any element or port. I do have similar mechanism in my implementation and it works very well, but I've done it a long time ago, so I'm not sure if I gave you enough information.

    Best regards,
    Ireneusz Patalas
     

    • 87.105.212.19
  • 05-29-2008 9:45 AM In reply to

    • Mathy
    • Top 10 Contributor
    • Joined on 07-16-2007
    • Posts 19

    Re: Only allow connections between ports?

     I solved it like this:


            protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
            {
                if (Runtime.InteractiveMode != InteractiveMode.AddConnector || CurrentMouseElements.MouseMoveElement is Port)
                {
                    base.OnMouseDown(e);
                }
            }

            protected override void UpdateElements()
            {
                object o = RenderDesign.Actions[0];
                if (o is Connector)
                {
                    Connector c = (Connector)o;
                    if (!(c.End.Port is Port))
                    {
                        Lines.Remove(c.ActionElement.Key);
                        RenderDesign.Actions.RemoveAt(0);
                    }
                }
                base.UpdateElements();
            }

    • 194.7.161.130
Page 1 of 1 (5 items)