## Extending SimpleGraph

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

### Extending SimpleGraph

I have extended TSimpleGraph with two new nodes:

Code: Select all
  { TPictureNode }  TPictureNode = class( TPolygonalNode )  protected    procedure DefineVertices( const ARect: TRect; var Points: TPoints ); override;  public Canvas: TCanvas;  end;  { TPostnetNode }  TPostnetNode = class( TGraphNode )  protected    procedure Initialize; override; // this creates a TBarcode Component    procedure BoundsChanged( dX, dY, dCX, dCY: Integer ); override; // this redraws the barcode    procedure DrawPostnet( Canvas: TCanvas ); // method to draw the barcode    function CreateRegion: HRGN; override;    procedure DrawBorder( Canvas: TCanvas ); override;    function LinkIntersect( const LinkPt: TPoint; const LinkAngle: Double ): TPoints; override;  end;{ TPostnetNode }procedure TPostnetNode.Initialize;begin  Height := 80;  Width := 300;  fBarcode := TStPNBarCode.Create( nil );  fBarcode.Top := 50;  fBarcode.Left := 230;  fBarcode.Height := 80;  fBarcode.Width := 300;  fBarcode.Visible := False;  fBarcode.PostalCode := '12345';  DrawPostnet( fBackground.Bitmap.Canvas );  Invalidate;  inherited Initialize;end;procedure TPostnetNode.Destroy;begin  fBarcode.Free;end;procedure TPostnetNode.BoundsChanged( dX, dY, dCX, dCY: Integer );begin  DrawPostnet( fBackground.Bitmap.Canvas );  inherited BoundsChanged( dX, dY, dCX, dCY );end;procedure TPostnetNode.DrawPostnet( Canvas: TCanvas );var  P: TPoint;begin  P := Point( 0, 0 );  fBarCode.PaintToCanvas( fBackground.Bitmap.Canvas, P );end;procedure TPostnetNode.DrawBorder( Canvas: TCanvas );begin  Canvas.Rectangle( Left, Top, Left + Width, Top + Height );end;function TPostnetNode.LinkIntersect( const LinkPt: TPoint; const LinkAngle: Double ): TPoints;begin  Result := IntersectLineRect( LinkPt, LinkAngle, BoundsRect );end;function TPostnetNode.CreateRegion: HRGN;begin  Result := CreateRectRgn( Left, Top, Left + Width + 1, Top + Height + 1 );end;

Both nodes funcion except that in order to see the barcode I have to open a background image for the barcode to become visible.

The barcode is painted as:
Code: Select all
procedure TPostnetNode.DrawPostnet( Canvas: TCanvas );var  P: TPoint;begin  P := Point( 0, 0 );  fBarCode.PaintToCanvas( fBackground.Bitmap.Canvas, P );end;

All I need is a canvas so is a fBackground.Bitmap necessary?

The Postnet barcode is from the now open source TurboPower SysTools package so the number of units that has to be added to the TSimpleGraph is only four small SysTools units.

My questions are:

1. What is the best way to create a picture node and a postnet barcode node to TSimpleGraph?

2. Should both the TPictureNode and the TPostnetNode be created as a TPolygonalNode or a TGraphNode?

3. How would you create the background bitmap when the TPostnetNode is created? Where would you create the background bitmap to draw the Postnet barcode?

4. I assume that the best place to get access to a TCanvas is the background bitmap or can a TCanvas be used?

5. Are you interested in looking over the changes when I finish.

Regards,

Bill
w2m
w2m
Senior Member

Posts: 76
Joined: March 8th, 2003, 7:11 pm
Location: New York, USA

### New Simple Graph Nodes Success

I have managed to add three new nodes to TSimpleGraph:

TPictureNode
TPostnetNode
TMemoNode

TPictureNode is basically a TGraphNode and works well.
TPostnetNode is a TGraphNode that draws Postnet barcode. It supports Zipcode, ZipPlus4 and DeliveryPoint. It works well. The barcode can be changed at runtime by entering a zipcode on the main toolbar.
TMemoNode is a TPolygonalNode at the moment. It is created and appears as a MemoNode but unfortunately I can not figure out how to override the default double clicking that shows the objects properties. So at the moment, you can not edit or even see the TMemo.

If anyone wants to assist me with the TMemoNode let me know. I can send you the revised source as well as the 4 barcode units.

If I am sucessful with TMemoNode the improved TSimpleGraph could be used to create mailing labels complete with postnet barcodes.

Regards,

Bill
w2m
w2m
Senior Member

Posts: 76
Joined: March 8th, 2003, 7:11 pm
Location: New York, USA

### Added 3rd node To TSimpleGraph

I added a third node to TSimpleGraph.

It is a TMemoNode. It works but I think it could be better.

Does anyone know how to access a parent control is a class? This was the most dificult part of creating the TMemoNode.

Regards,

Bill
w2m
w2m
Senior Member

Posts: 76
Joined: March 8th, 2003, 7:11 pm
Location: New York, USA

Sorry, I didn't understand your question. I guess you need to know which control should be the parent of memo. If this is the question, the answer is SimpleGraph.

Generally, SimpleGraph has a poor architecture because originally it was designed for other purpose. Because of that it is very difficult to add new functionality to it. A long time ago I started to create a new update (v3.0) but it became a mess and I stopped working on that.
Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

Kambiz,

If you are interested I can send you my revised source code and a revised demo if you would like to take a quick look at it and give me any comments.

Bill
w2m
w2m
Senior Member

Posts: 76
Joined: March 8th, 2003, 7:11 pm
Location: New York, USA

Yes, please send it.
Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

### Simple Graph 2.63 Beta

Here is the source code and beta of TSimpleGraph. It adds a TPostnetNode, TPictureNode, TMemoNode, TRichEditNode and a TEditNode.
The demo has been revised to handle the new nodes. Most of the code that I added has a // w2m remark. The units required for Postnet is also in the zip file.

I had to remove some rtf and other files in the orginal zip file to get it under 1 mb in order to upload it.

June 1, 2008- w2m
Added 5 new Nodes
TImageNode, TPostnetNode, TMemoNode, TRichEditNode, TEditNode

TPostnetNode requires: StDefine.inc
StBarPN.pas
StBase.pas, StConst.pas, StStrL.pas
from Open Source TurboPower Systools

Features:
1. Postnet supports zipcode, zipplus4 and delivery point barcodes
2. TMemoNode and TEditNode supports font name and size
3. TRichEditNode supports font name and size and font styles

Known Problems:
1. Selection of TMemoNode, TRichEditNode, TEditNode only at edge of object. Vertices boxes repainting needs improvement.
2. TMemoNode, TRichEditNode, TEditNode Zooming is not correct
3. Maybe change selection of TMemoNode, TRichEditNode, TEditNodes to selection anywhere on edit control, then double click to go into
edit mode.
4. TMemoNode, TRichEditNode, TEditNode flicker when resizing
5. Printing contents of all edit nodes do not print.

Have not tested streaming.
Attachments
SimpleGraph263Beta.zip
Simple Graph 2.63 beta
w2m
w2m
Senior Member

Posts: 76
Joined: March 8th, 2003, 7:11 pm
Location: New York, USA

Managing Delphi controls on SG is very difficult or maybe impossible. The most problem arise becase of different measurement units of SG controls and Delphi controls. In SG all units are in graph units but in Delphi controls units are in pixels. Only when graph is displayed in actual size, one graph unit is equal to one pixel.

As a workaround, you can render the Delphi control on the SG canvas and only when the node is clicked, show the actual control for user input. This workaround solves all the mentioned problems.

A better - and maybe easier - way is to forget about Delphi controls and create a specific node class for each control by yourself. Actually IE does this trick for web controls. In IE except ListBox and ComboBox, other form elements are not Windows control and are rendered by IE.
Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

Did you try the demo and look at the source code?
w2m
w2m
Senior Member

Posts: 76
Joined: March 8th, 2003, 7:11 pm
Location: New York, USA

Yes I did. Of course, with some problem because I have Delphi 7.
Kambiz

Kambiz