Vagueness in TDrawLineTool Documentation - Help!

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Cornerstone
Newbie
Newbie
Posts: 6
Joined: Wed Oct 26, 2005 4:00 am

Vagueness in TDrawLineTool Documentation - Help!

Post by Cornerstone » Thu Aug 24, 2006 6:46 pm

The DrawLine Tool documentation is frustratingly poor. It has taken me 2 full days to get things to a point where they partially work. First I will describe what I want, then I will describe what I have.

I am using TChart 7.07 with Delphi 6 on windows XP Pro.

I would like a user to be able to hold down the left mouse button and draw a line from point A to Point B. When they lift the mouse the line is finalized. Then I would like them to be able to draw another separate line that is not necessarily connected to the first line. I would also like the user to be able to left click (In a different Mouse Mode) on an existing line to select it and drag that line to a new location without drawing another new line.

After 2 days of noodling and experimentation, I have been able to achieve the following:

a) I can draw multiple separate lines with the left mouse button as above, but, whether or not my mouse button is down, there is always a line between the last point that I lifted my mouse button up and the current mouse position (It is as though I am holding the mouse button down and drawing a line). This is undesirable behaviour.

b) I can select a line. but I cannot drag it around, as this blows away the selection.

pertinent code follows:

Code: Select all

procedure TMDIChartForm.MainChartMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then
  begin
     CurrStartPoint.X := x;
     CurrStartPoint.Y := y;
     TrendLineTool.EnableSelect := True;
     TrendLineTool.SelectNewLines := True;
     TrendLineTool.EnableDraw := True;
     TrendLineTool.Active := True;
   end;
end;

Code: Select all

procedure TMDIChartForm.MainChartMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  TempPoint: TPoint;
  TempLine: TDrawLine;

begin
   if Button = mbLeft then
   begin
     TempPoint.X := x;
     TempPoint.Y := y;
     TempLine := TDrawLine.Create(TrendLineTool.Lines);
     TempLine.StartPos := TrendLineTool.ScreenPoint(CurrStartPoint);
     TempLine.EndPos := TrendLineTool.ScreenPoint(TempPoint);

     TrendLineTool.Lines.Add;
     TrendLineTool.Lines.Items[TrendLineTool.Lines.Count - 1] := TempLine;
     TrendLineTool.Repaint;
     TrendLineTool.EnableDraw := False;
     end;
end;
According to the documentation, it sounded like one would not have to write any of this code to allow simple line drawing, selecting and moving, but that behaviour did nothing near what I wanted it to.

Please help soon as this is taking way longer than it should.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Aug 25, 2006 8:33 am

Hi Cornerstone,
I would like a user to be able to hold down the left mouse button and draw a line from point A to Point B. When they lift the mouse the line is finalized. Then I would like them to be able to draw another separate line that is not necessarily connected to the first line. I would also like the user to be able to left click (In a different Mouse Mode) on an existing line to select it and drag that line to a new location without drawing another new line.
That's exactly what TDrawLineTool, using all default settings, does. Just adding a TDrawLineTool to a chart the user can start drawing a line when pressing the left mouse button and stop drawing when releasing the left mouse button. The same operation can be done to draw more lines without them being connected to previous lines. Also, to select an drag an existing line the user will only have to move the mouse over a line, where the mouse cursor will change, press left mouse button and start dragging the line until the mouse button is released.

Can you please try creating a test project, drop a TChart into a form, open the chart editor and add a series and TDrawLineTool to the chart, populate the series with some random values and run the application. This example should work as I told above. If this doesn't work don't hesitate to contact us and if necessary I can send you an example of this.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Cornerstone
Newbie
Newbie
Posts: 6
Joined: Wed Oct 26, 2005 4:00 am

DrawLine Problem persists

Post by Cornerstone » Mon Aug 28, 2006 11:24 pm

Hello Narcis,

Thank-you for your prompt and concise response. As you directed I started a new project, added a chart, series, and DrawLine tool. I populated the series with some random data and Voila! This worked marvelously. I could draw and select lines exactly as I wanted to and exactly how you said the default behaviour was and exactly how I understood it was supposed to be. Unfortunately, when I simply added a new DrawLine tool to my existing Chart in my existing project, it behaved like a drawing program's "Polygon" tool. It kept appending any line I drew with the next line and even when I was not depressing the left mouse button, it was drawing a line from the previous vertex to wherever I moved my mouse. So, essentially I have one contiguous line with vertices wherever I left-click. Additionally, neither this "mega-line" nor any of its component lines are selected or selectable.

Could I have possibly set some type of generic property in some other portion of my app that would affect the default behaviour of the TDrawLineTool?

One clue that might be helpful in diagnosing my problem is the following: It is clear to me that I have done something to simulate a "pseudo" OnMouseMove event. Though I use neither the Form's OnMouseMove event, nor the Chart's OnMouseMove event, nor do I use OnBeforeDraw or OnAfterDraw, but for some reason, the chart's canvas seems to be refreshing itself every time I move the mouse. Could it have something to do with another cursor tool that may be inactive or invisible while I am drawing these frustrating, incorrect lines?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Aug 29, 2006 8:19 am

Hi Cornerstone,

Could you please send us an example we can run "as-is" to reproduce this problem here? You can post your files at news://www.steema.net/steema.public.attachments newsgroup.

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Cornerstone
Newbie
Newbie
Posts: 6
Joined: Wed Oct 26, 2005 4:00 am

Post by Cornerstone » Mon Sep 04, 2006 9:05 pm

Hi Narcis, I posted applicable code in the newsgroup attachments as you asked. I hope that helps.

Cornerstone

Cornerstone
Newbie
Newbie
Posts: 6
Joined: Wed Oct 26, 2005 4:00 am

Post by Cornerstone » Wed Sep 06, 2006 8:31 pm

Hello Narcis,

I have never posted code via a newsreader before and I was hoping you could respond just to let me know if you received my code snippets that you requested just so I know if I need to send again.

Thanks

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Sep 07, 2006 8:10 am

Hi Cornerstone,

Yes, we have received the code and we will look at it ASAP. However it will be very difficult for us to find the problem without being able to run a project where we can reproduce it.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Sep 12, 2006 2:40 pm

Hi Cornerstone,

It's very difficult for us to guess which the problem is without being able to reproduce it. However, it's most likely that the problem is related with the mouse events you use. Your application may be firing OnMouseDown.

You could try commenting everything you do at the mouse event, if necessary, remove the other tools to guess when the problem happens.

If the problem is related to the mouse event you could try calling Abort method after adding a DrawLine tool so that the OnMouseDown event is not constantly fired.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Cornerstone
Newbie
Newbie
Posts: 6
Joined: Wed Oct 26, 2005 4:00 am

Post by Cornerstone » Wed Sep 20, 2006 6:29 pm

Hi Narcis,

Thank-you so much for your suggestion. I actually found the problem in the OnMouseUp event, which seems very weird. I don't understand how the OnMouseUp event can influence whether a line follows the mouse when you move it, but indeed that was the solution. Incidentally, if I want to force a paint of the DrawLineTool Lines when Chart.AutoRepaint is set to False, how do I do that? Calling Chart.Repaint, or DrawLineTool.Repaint does not seem to do the trick. Thanks a lot for your help.

Cornerstone

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Sep 21, 2006 7:53 am

Hi Cornerstone,

You can try using Chart1.Draw. However you have to use it very carefully because you could easily fall into an endless loop of the chart constantly repainting itself.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Cornerstone
Newbie
Newbie
Posts: 6
Joined: Wed Oct 26, 2005 4:00 am

Post by Cornerstone » Sat Sep 23, 2006 8:23 pm

Hello Again Narcis,

I have developed a real time charting app in which individual charts are added on MDIChildren forms (theoretically you could have as many charts open as your system could handle). In this app, the user can have 2 or more charts open that are the same data, but scaled differently. I have been able to solve all the problems except propagating a TDrawLine drawn on one chart to a scaled version on on or more other charts. In your opinion, what is the best way to have a TDrawLine or multiple TDrawLines appear in other charts of the same data that may be scaled differently? I have tried a few approaches with poor results.

Thanks again Narcis,
Cornerstone

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Sep 25, 2006 7:37 am

Hi Cornerstone,

You could try what Marjan wrote here for clonning TeeChart tools.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply