Giving any settings to graphobjects

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

Giving any settings to graphobjects

Postby elias » December 7th, 2005, 4:46 pm

OK, I'd like to give graphobjects any settings throuhg the MainForm, without changing Tsimplegraph too much. I want to write in the Main, for example:

Code: Select all
  SimpleGraph.DefaultNodeClass := TRectangularNode;
  SimpleGraph.CommandMode := cmInsertNode;
  SimpleGraph.DEFAULTNODESETTINGS(linkable, resizable, 32,32)
    //Where linkable means that I can stablish links at this Node, resizable that the node can be resized, and the number would indicate the size of this node.


Everything about making nodes unlinkables and unresizables is already written in the simplegraph.pas, but I like you to suggests me how to implement this .DEFAULTNODESETTINGS. Perhaps like a Property? I'm not sure if a Property could have more than a value. Maybe using flags? Controls like SaveDialog have a Property (Options) with a Set of boolean subproperties, but I don't know if I could use integer Subproperties? Any idea?
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby elias » December 7th, 2005, 5:29 pm

Maybe it would be possible to add a function like:

Code: Select all
  SimpleGraph.DefaultNodeClass := TRectangularNode;
  SimpleGraph.CommandMode := cmInsertNode;
  SimpleGraph.LastNodeInserted.Linkable:=true;
  SimpleGraph.LastNodeInserted.resizable:=false;
  etc...


I hope you understand what I mean and can give me some help ¿??
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby Kambiz » December 10th, 2005, 9:45 am

Why you don't use OnObjectInsert event? Here is an example:

Code: Select all
type
  PNodeSettings = ^TNodeSettings;
  TNodeSettings = record
    Linkable: Boolean;
    Resizable: Boolean;
  end;

var
  LastNodeInserted: TNodeSettings;

procedure TForm1.SimpleGraphObjectInsert(Graph: TSimpleGraph;
  GraphObject: TGraphObject);
var
  pSettings: PNodeSettings;
begin
  if GraphObject is TGraphNode then
  begin
    New(pSettings);
    pSettings^ := LastNodeInserted;
    GraphObject.Tag := Integer(pSettings);
  end;
end;

procedure TForm1.SimpleGraphObjectRemove(Graph: TSimpleGraph;
  GraphObject: TGraphObject);
var
  pSettings: PNodeSettings;
begin
  if GraphObject.Tag <> 0 then
  begin
    pSettings := PNodeSettings(GraphObject.Tag);
    GraphObject.Tag := 0;
    Dispose(pSettings);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SimpleGraph.DefaultNodeClass := TRectangularNode;
  SimpleGraph.CommandMode := cmInsertNode;
  LastNodeInserted.Linkable := True;
  LastNodeInserted.Resizable := False;
end;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby elias » December 12th, 2005, 4:31 pm

Hello!

There are two kinds when inserting a node in my simplegraph.pas; one of them like you wrote originally, and another one when the node should have a size predeterminated. I have implemented it at Tsimplegraph like you can see in the image:

[img][img]http://img528.imageshack.us/img528/4244/dibujo8xv.png[/img]

So the matter is that: when I insert a Unresizable predeterminated sized node, I have to modify the code (.OnMouseUp, .OnMouseDown, .OnMouseMove) to create the node: I can'not set the resizable property after inserting the node. Any idea to make it elegant?

I'm thinking
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby elias » December 12th, 2005, 6:36 pm

I thought that I could to use a property like DEFAULTNODESETTINGS that would contain any subproperties. I have write this code inside simplegraph.pas; I think it would be appropiate...

Code: Select all
{ TDEFAULTNODESETTINGS }

  TDEFAULTNODESETTINGS = class(TPersistent)//(TPersistent)is this right?
  private
    fResizable:boolean;
    fLinkable:boolean;
    fwidth:integer;
    fheight:integer;
    procedure SetResizable(value:boolean);
    procedure SetLinkable(value:boolean);
    procedure SetWidth(value:integer);
    procedure SetHeight(value:integer);
  published
    property Resizable: boolean read fResizable write SetResizable;
    property Linkable: boolean read fLinkable write SetLinkable;
    property Width: Integer read fWidth write SetWidth;
    property Height: Integer read fHeight write SetHeight;
  end;


¿Any comments?

PD: I have another idea:

Code: Select all
{ TDEFAULTNODESETTINGS }

  TDEFAULTNODESETTINGS = class(TPersistent)//(TPersistent)is this right?
  private
    fResizable:boolean;
    fLinkable:boolean;
    fwidth:integer;
    fheight:integer;
    fClass: TGraphNodeClass;  //THIS
    procedure SetResizable(value:boolean);
    procedure SetLinkable(value:boolean);
    procedure SetWidth(value:integer);
    procedure SetHeight(value:integer);
  published
    property Resizable: boolean read fResizable write SetResizable;
    property Linkable: boolean read fLinkable write SetLinkable;
    property Width: Integer read fWidth write SetWidth;
    property Height: Integer read fHeight write SetHeight;
    property Class: TGraphNodeClass read fDefaultNodeClass write fDefaultNodeClass;   //...AND THIS
  end;


So I could give settings from the MainForm to a certain node like follows:

Code: Select all
SimpleGraph.CommandMode := cmInsertNode;
SimpleGraph.DEFAULTNODESETTINGS.Linkable:=true;
SimpleGraph.DEFAULTNODESETTINGS.Resizable:=false;
SimpleGraph.DEFAULTNODESETTINGS.Width:=32;
SimpleGraph.DEFAULTNODESETTINGS.Height:=32;
//...
SimpleGraph.DEFAULTNODESETTINGS.brush.color:=999; //  :)
//...
SimpleGraph.DEFAULTNODESETTINGS.Class := TRectangularNode; //????????



I would be very pleased to see any suggestions you can give me... or a better idea than this one...

Thanks.
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby Kambiz » December 13th, 2005, 6:42 am

You did it in the right way.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby elias » December 13th, 2005, 8:40 am

:)
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby elias » December 27th, 2005, 9:59 pm

Hi Kambiz; I had modified Simplegraph.pas like follows
Code: Select all
function TSimpleGraph.InsertNode(pBounds: PRect; ANodeClass: TGraphNodeClass): TGraphNode;
begin
  BeginUpdate;
  try
    SelectedObjects.Clear;
    if ANodeClass = nil then
      ANodeClass := DEFAULTNODESETTINGS.DesiredClass;//DefaultNodeClass;
    Result := ANodeClass.Create(Self);
    if pBounds <> nil then
      Result.BoundsRect := pBounds^;
    Result.State := osNone;
    Result.Selected := True;
    Result.Resizable:=DEFAULTNODESETTINGS.Resizable;
    Result.Linkable:= DEFAULTNODESETTINGS.Linkable;
    Result.Brush:= DEFAULTNODESETTINGS.Brush;
    Result.Text:= DEFAULTNODESETTINGS.text;
    Result.Pen:= DEFAULTNODESETTINGS.Pen;
    Result.Hint:=DEFAULTNODESETTINGS.Hint;
    Result.Visible:=DEFAULTNODESETTINGS.Visible;
    Result.Font:= DEFAULTNODESETTINGS.Font;
  finally
    EndUpdate;
  end;
end;

...using DEFAULTNODESETTINGS how I explained before. The matter is that DEFAULTNODESETTINGS is not necesary to assign this properties:
Code: Select all
    Result.Linkable:= DEFAULTNODESETTINGS.Linkable;
    Result.Brush:= DEFAULTNODESETTINGS.Brush;
    Result.Text:= DEFAULTNODESETTINGS.text;
    Result.Pen:= DEFAULTNODESETTINGS.Pen;
    Result.Hint:=DEFAULTNODESETTINGS.Hint;
    Result.Visible:=DEFAULTNODESETTINGS.Visible;
    Result.Font:= DEFAULTNODESETTINGS.Font;

... except because if I change it from the main, BeginUpdate and EndUpdate will be run 7 times. You wrote a piece of code to make changes to the lastnodeinserted (LastNodeInserted), but I'm not convinced.

I think the best way to make this is using the OnInsertNodeEvent ¿What do you think?
...well, I think the problem it's that the event runs inside TSimpleGraph.ObjectListChanged, so the BeginUpdate and EndUpdate will be run 7 times again...
I suggest that the DoObjectInsert(GraphObject); should be in function TSimpleGraph.InsertNode like follows:
Code: Select all
function TSimpleGraph.InsertNode(pBounds: PRect; ANodeClass: TGraphNodeClass): TGraphNode;
begin
  BeginUpdate;
  try
    SelectedObjects.Clear;
    if ANodeClass = nil then
      ANodeClass := DEFAULTNODESETTINGS.DesiredClass;//DefaultNodeClass;
    Result := ANodeClass.Create(Self);
    if pBounds <> nil then
      Result.BoundsRect := pBounds^;
    Result.State := osNone;
    Result.Selected := True;
    Result.Resizable:=DEFAULTNODESETTINGS.Resizable;
    DoObjectInsert(GraphObject)
  finally
    EndUpdate;
  end;
end;

And too:
Code: Select all
function TSimpleGraph.LinkNodes(FromNode, ToNode: TGraphNode;
  ALinkClass: TGraphLinkClass): TGraphLink;
begin
  Result := nil;
  if IsValidLink(nil, FromNode, ToNode) then
  begin
    BeginUpdate;
    try
      SelectedObjects.Clear;
      if ALinkClass = nil then
        ALinkClass := DEFAULTLINKSETTINGS.DesiredClass;
      Result := ALinkClass.Create(Self);
      Result.FromNode := FromNode;
      Result.ToNode := ToNode;
      Result.State := osNone;
      Result.Selected := True;
      DoObjectInsert(GraphObject)
    finally
      EndUpdate;
    end;
  end;
end;

So BeginUpdate and EndUpdate will be run just once...

Well, I don't have time now to test this what I'm telling you but
What dou you think??


PD:When I have my simplegraph.pas modified at my way i will send you to you take a look (I hope you like any of my ideas)
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby Kambiz » December 29th, 2005, 8:47 am

I'm going to add an Options property to the nodes (for Resizable, Movable, Linkable, etc.), and an OnObjectCreate event to the control itself for more felexibility.

I only need some more time to do these tasks.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby elias » January 3rd, 2006, 9:03 pm

:( Looking around this topic I realized that there were not problems with BeginUpdate and EndUpdate; the problem was just in my head (these procedures were made to run just once the drawing, no matter how many times runned); so I use now the OnNodeInsert event how you did; and i have no problem; About the resizing and linking, I'm using this properties:
Code: Select all
TGraphNode = class(TGraphObject)
  published
    property Linkable: boolean read fLinkable write SetLinkable;      //Can link
    property Resizable: boolean read fResizable write SetResizable; //Can resize before inserted 

TSimpleGraph = class(TCustomControl)
  public 
    property DefaultNodeClass: TGraphNodeClass read fDefaultNodeClass write fDefaultNodeClass;//How you wrote
  published
    property DefaultNodeFixed: boolean read fDefaultNodeFixed write SetDefaultNodeFixed default false;//Can resize after inserted
    property DefaultNodeWidth: integer read fDefaultNodeWidth write SetDefaultNodeWidth default 32;// Default Width for SetDefaultNodeFixed:=true
    property DefaultNodeHeight: integer read fDefaultNodeHeight write SetDefaultNodeHeight default 32;// Default Height for SetDefaultNodeFixed:=true

I will send the SimpleGraph.pas you to see it; in order that I have it written already; maybe you like how I implemented it...
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby elias » January 4th, 2006, 1:40 pm

As soon as I could I sent you my changed SimpleGraph.pas at your mail; you can watch it and use whatever you want (if useful).
May use WinMerge to compare. Elías.
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby kokkoras » January 24th, 2006, 5:05 pm

Kambiz wrote:I'm going to add an Options property to the nodes (for Resizable, Movable, Linkable, etc.), and an OnObjectCreate event to the control itself for more felexibility.

I only need some more time to do these tasks.


I grab the oportunity to mention this:
http://www.delphiarea.com/forum/viewtopic.php?t=614
User avatar
kokkoras
Moderator
Moderator
 
Posts: 317
Joined: March 12th, 2005, 11:19 pm
Location: Thessaloniki, Greece


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 2 guests