Page 1 of 1

Restrict the shape connection areas

Posted: Tue Jul 07, 2009 1:07 pm
by 10548077
Hi guys,

1- I have a need that is dificult to explain. But i'll try.
When connecting squares, it should not allow connections between the square's corners.
The TeeEditor component must only allow to connect at the middle of a square's side (when I move the connection point at this position, I have a small circle around the red dot). That can be in upper, lower, left or right side.
In other words, seeing the image above, lock the possible connection points to the green circles.

2- Other question is to restrict the user to create points over the connection line.

Image:
Image

It's possible to restrict this by code?

Thanks.

Re: Restrict the shape connection areas

Posted: Thu Jul 09, 2009 8:14 am
by yeray
Hi Wheb,

Here is a little piece of code showing how to add a connection and insert a point between the origin and the destination points. I've simply modified a little bit the code from the demo Add Connection from TeeTree demo (Only Tree1, TreeNodeShape1 and TreeNodeShape2 created at design time):

Code: Select all

Connection : TTreeConnection;
//...
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  // Cosmetic. Set all nodes Cursor to HandPoint.
  for i:=0 to Tree1.Shapes.Count-1 do
      Tree1[i].Cursor:=crHandPoint;

  // Example. Create a connection from Node 1 to Node 2
  Connection:=TreeNodeShape1.AddConnection(TreeNodeShape2);
  Connection.Style:=csLine;
  Connection.Border.Style:=psSolid;
  Connection.Border.Color:=clBlue;

  with Connection.Points do
  begin
    Insert(1, 250, 250);
    ChangeXStyle(2,cpsToPercent);
    ChangeYStyle(2,cpsToPercent);
  end;
end;
Note that you can also modify a point from the current list changing its Item.X, Item.Y, Item.XValue, Item.YValue, Item.XStyle and Item.YStyle.