TTree ConnectionPoints

TeeTree VCL for Borland Delphi and C++ Builder.
Post Reply
SStone
Newbie
Newbie
Posts: 1
Joined: Thu Dec 02, 2004 5:00 am

TTree ConnectionPoints

Post by SStone » Fri Jun 17, 2005 10:30 pm

I have 2 TreeNodeShapes with a connection between them. I try and add some additional points to the connection. The added points appear but the end points are no longer "linked" to the Shapes. I've tried reassigning the ToShape,FromShape nothing. How can you progamatically reconnect the connection to the shapes ??
I'm missing something.
Thanks,

Sample Code.
var
nd : TTreeNodeShape;
nd2 : TTreeNodeShape;
cn : TTreeConnection;
cp : TConnectionPoint;
p : TPen;
begin
t1.Designing := true;
nd := t1.Items.AddChild(nil,'Hello?');
nd.Style := tssRectangle;
nd.Top := 120;
nd.left := 120;

nd2 := t1.Items.AddChild(nil,'World');
nd2.Style := tssRectangle;
nd2.Top := 120;
nd2.left := 320;

cn := nd.addconnection(nd2);

cn.Points.add(cpsfixed,120,cpsfixed,120);
cn.Points.add(cpsfixed,220,cpsfixed,220);
cn.Points.add(cpsfixed,320,cpsfixed,120);

cn.Border.SmallDots := false;
cn.Border.Style := pssolid;
cn.border.width := 1;
cn.SimpleText := 'Stuff';
cn.FromShape := nd;
cn.ToShape := nd2;

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Mon Jun 20, 2005 11:14 pm

Hi,

With cpsFixed you tell teeTree to put a point on a fixed x,y position.
You should use the following code:

Code: Select all

  cn.Points.Add(cpsAutoFrom, 120, cpsAutoFrom, 120);
  cn.Points.Add(cpsPrevious, 100, cpsPrevious, 100);
  cn.Points.Add(cpsAutoTo, 320, cpsAutoTo, 120);
with cpsAutoFrom and cpsAutoTo you attach the connection to the From and To shape respectively. The provided x and y values are not really needed in this case, since they are set by the from and to shapes, however there is a slight difference, you can see this by using the following code instead (look ath the starting position of the connection):

Code: Select all

  cn.Points.Add(cpsAutoFrom, 0, cpsAutoFrom, 0);
There are several other ways to add/insert points (you are not always obliged to proved a connectionpointstyle). e.g. If you create the third point at another moment, you can also use the following code (in this case we use the insert instead of the add method):

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  nd : TTreeNodeShape;
  nd2 : TTreeNodeShape;
  cn : TTreeConnection;
begin
  t1.Designing := true;
  nd := t1.Items.AddChild(nil,'Hello?');
  nd.Style := tssRectangle;
  nd.Top := 120;
  nd.left := 120;

  nd2 := t1.Items.AddChild(nil,'World');
  nd2.Style := tssRectangle;
  nd2.Top := 120;
  nd2.left := 320;

  cn := nd.addconnection(nd2);
  cn.Style := csLine;

  cn.Border.SmallDots := false;
  cn.Border.Style := pssolid;
  cn.border.width := 1;
  cn.SimpleText := 'Stuff';
end;

procedure TForm1.Button2Click(Sender: TObject);
var
cn : TTreeConnection;
begin
  //one of the possible ways to select a connection
  cn := t1.Connections[0];  
  //insert a point to the already existing code
  cn.Points.Insert(1, 220,220);
  cn.Repaint;
end;



The different ways to specify the connection points coordinates:

Code: Select all

 
 cpsAutoFrom           Automatic position on the "From" node
 cpsAutoTo             Automatic position on the "To" node
 cpsFromPercent        + / - percent on "From" size
 cpsToPercent          + / - percent on "To" size
 cpsFromRel            + / - pixels relative from "From" node origin
 cpsToRel              + / - pixels relative from "To" node origin
 cpsPrevious           + / - pixels relative to Previous Point in array
 cpsNext               + / - pixels relative to Next Point array
 cpsFixed              Fixed XY pixel position
Regards,
Tom

Post Reply