Page 1 of 1

Vagueness in TDrawLineTool Documentation - Help!

Posted: Thu Aug 24, 2006 6:46 pm
by 9343921
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.

Posted: Fri Aug 25, 2006 8:33 am
by narcis
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.

DrawLine Problem persists

Posted: Mon Aug 28, 2006 11:24 pm
by 9343921
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?

Posted: Tue Aug 29, 2006 8:19 am
by narcis
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.

Posted: Mon Sep 04, 2006 9:05 pm
by 9343921
Hi Narcis, I posted applicable code in the newsgroup attachments as you asked. I hope that helps.

Cornerstone

Posted: Wed Sep 06, 2006 8:31 pm
by 9343921
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

Posted: Thu Sep 07, 2006 8:10 am
by narcis
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.

Posted: Tue Sep 12, 2006 2:40 pm
by narcis
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.

Posted: Wed Sep 20, 2006 6:29 pm
by 9343921
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

Posted: Thu Sep 21, 2006 7:53 am
by narcis
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.

Posted: Sat Sep 23, 2006 8:23 pm
by 9343921
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

Posted: Mon Sep 25, 2006 7:37 am
by narcis
Hi Cornerstone,

You could try what Marjan wrote here for clonning TeeChart tools.