Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Adding a text box in a scatterDraw/ScatterCtrl
Adding a text box in a scatterDraw/ScatterCtrl [message #47612] Tue, 07 February 2017 09:46 Go to next message
Giorgio is currently offline  Giorgio
Messages: 70
Registered: August 2015
Member
Hi there,
I am experimenting with ScatterDraw/ScatterCtrl. I have the need to add some kind of "text box" in a scatter. This is because I need to explain why a graph all of sudden change its behaviour. To give you some context: the graph describes the speed of a production line; usually it is almost constant, but sometimes it drops because of a breakdown of some component on the line. Is there a way to add some kind of text box?
Thanks,
Giorgio
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #47613 is a reply to message #47612] Wed, 08 February 2017 08:35 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2740
Registered: August 2008
Location: Basque Country
Senior Veteran
Hi Giorgio

Do you want the text located in a specific point
- of the control (coordinates relative to the Control) or
- of the Scatter data (coordinates relative to the data plotted; if plot is scrolled or zoomed, text would be scrolled or zoomed too)


Best regards
Koldo
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #47614 is a reply to message #47613] Wed, 08 February 2017 09:20 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 70
Registered: August 2015
Member
Hi Koldo,
the latter (text located in a specific point of the Scatter data; I was actually trying to overload the DoPaint function, but it is a little bit over my knowledge.
Regards,
Giorgio
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #47615 is a reply to message #47614] Wed, 08 February 2017 11:34 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2740
Registered: August 2008
Location: Basque Country
Senior Veteran
OK. I always wanted to implement an OnPaint() or WhenPaint() callback to let the user to paint things... now it is the opportunity Smile

Best regards
Koldo
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #47616 is a reply to message #47615] Wed, 08 February 2017 12:02 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 70
Registered: August 2015
Member
That's fantastic! And of course I will give any feedback / user testing required Very Happy
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #47620 is a reply to message #47616] Fri, 10 February 2017 14:12 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2740
Registered: August 2008
Location: Basque Country
Senior Veteran
An advance:

index.php?t=getfile&id=5196&private=0


Best regards
Koldo
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #47621 is a reply to message #47620] Fri, 10 February 2017 15:38 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 70
Registered: August 2015
Member
Hi Koldo,
it seems really good, much beyond what I asked for; if you need some user testing just give me the new library and I will be more than happy to test it.
Regards,
Giorgio
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #47622 is a reply to message #47621] Fri, 10 February 2017 23:15 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2740
Registered: August 2008
Location: Basque Country
Senior Veteran
Hi Giorgio

Sources are updated. ScatterCtrl demo includes tab17_UserPaint including it.
Provisional interface uses:
- GetPlotWidth(), GetPlotHeight() to get plot area size in pixels
- Pointf GetPosPrimary(double x, double y) 
  double GetSizeX(double cx) 		
  double GetSizeYPrimary(double cy) 	
  Pointf GetPosSecondary(double x, double y)
  double GetSizeYSecondary(double cy)
to get positions and sizes from plot units to pixel units.


As I do not know how to use templates in callbacks, it is used instead this:
	void OnPainter(Painter &w)		{OnPaint(w);}
	void OnDraw(Draw &w)			{OnPaint(w);}
	
	template <class T>
	void OnPaint(T& w) {
	...
 	}

Advice is acknowledged.


Best regards
Koldo

[Updated on: Fri, 10 February 2017 23:15]

Report message to a moderator

Re: Adding a text box in a scatterDraw/ScatterCtrl [message #48103 is a reply to message #47622] Wed, 17 May 2017 12:11 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 70
Registered: August 2015
Member
Hi Koldo,
it took me ages to test it... the project was stopped and then it suddenly restarted some weeks ago.

A little bit of context: there is an application used on a couple production lines in the factory I work for. This application registers automatically (in a db) the speed of the production line: the line operate on cables and can treat x meters of cable per minute depending on the type of operation. The machinist, using another applications, enters in the db what is doing (setting up the machine, running the machine...) and what product-id he is working on. The goal is to put together all the information to have a report on the production of each shift. This is the result:

https://pasteboard.co/7jRIiP3B3.png

-Using the standard scatter function AddSeries() I draw the blue line (the speed);
-I created also the green, red yellow, bars (those bars says what the operator is doing: running setting up etc.) with AddSeries(), but with a little trick: it is a very thick line with just two points: the first is the begin of e.g running time, the second is the end;

Now comes in the new method OnPaint; with that method:
-I add a letter on the bars to explains what the bar represents (e.g. 'R' for running);
-I add the product-id that has been processed (e.g. 160997100A-60-2 represents a certain type of cable).

That works very well, the problems come when I print or scroll the report:

https://pasteboard.co/7jQzP6HMn.png
https://pasteboard.co/7jStsxNhI.png

When I scroll the report:
-The texts stay "fixed" while the graphs are resized

When I print the report:
-All the texts are very small;
-The bars have rounded edges.

I had a look at the code of the tab "User paint" of the ScatterCtrl_Demo and saw that using scaled font you do not have the same problem I have, so is just a matter of checking the code and understand how scaled font works.

So, the feedback is that the UserPaint callback provides all the needed functionality, it works as expected and has no bugs (consider that the application that generates the report has been used on a daily basis by a couple of users for about 3 weeks and they have not found any problem).

Thanks a lot for your effort!
Regards,
Gio

[Updated on: Wed, 17 May 2017 12:14]

Report message to a moderator

Re: Adding a text box in a scatterDraw/ScatterCtrl [message #48104 is a reply to message #48103] Wed, 17 May 2017 17:04 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2740
Registered: August 2008
Location: Basque Country
Senior Veteran
Hello Gio

I am very happy that everything is going well.

When you say "when I print the report" do you mean when saving it to a file or when copying it to the clipboard?
Could you include more details about the problems?


Best regards
Koldo
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #48105 is a reply to message #48104] Wed, 17 May 2017 17:43 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 70
Registered: August 2015
Member
In my class I have a method Preview (I think I copied it from the ScattrCtrl_demo) as follows:

void OeeReport::Preview()
{
	Report r;

	r.Landscape();
	Size pageSize = r.GetPageSize();
	Drawing drw = scOee.GetDrawing();
	r.DrawDrawing(0, 0, pageSize.cx, pageSize.cy, drw);

	Perform(r);
}


scOee is the ScatterCtrl in the graphical interface (the .lay file) where my report is.

Regards,
Gio
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #48113 is a reply to message #47612] Fri, 19 May 2017 13:11 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 70
Registered: August 2015
Member
Got the time to work a little bit on the project this morning and solved the problem related to the font dimension and the text that did not scroll when the graphic was scrolled.
The only thing I do not understand is why when the graph is inside the scatter control showed on screen, bars have "squared" edges, while when in print-preview the report bars have rounded edges.
The code to preview the report is almost identical to that used in the ScatterCtrl_demo.

Scatter Control
https://pasteboard.co/87VQcUcfo.png

Print preview
https://pasteboard.co/87XAZsL8V.png
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #48141 is a reply to message #48113] Thu, 25 May 2017 20:07 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2740
Registered: August 2008
Location: Basque Country
Senior Veteran
Hello Giorgio

An update has been uploaded setting default Painter line caps. Please try it.


Best regards
Koldo
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #48143 is a reply to message #48141] Fri, 26 May 2017 14:45 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 70
Registered: August 2015
Member
Hi Koldo,
thank you for you prompt support.

I have noticed something weird with this release.

This is the application compiled with the old version:

https://ibb.co/hjKz5v

This is the one with the the new version:

https://ibb.co/cuMJyF

A little background: to draw the big bars in the lower part of the screen I use this code

Vector<Pointf> b_temp = {};
b_temp << Pointf(t_in, posBarre) << Pointf(t_fine, posBarre);
barre.Add(b_temp);

...

for(int i = 0; i < barre.size(); i++){

  ...

  scOee.AddSeries(barre[i]).NoMark().Stroke(30, t_color).Dash(LINE_SOLID).Legend(AsString(i));
}



To draw the light green line I use the following code:

Vector<Pointf> v_media_temp = {};
v_media_temp << Pointf(t_in, lista_ml_l[i].QuestaMLav.v_media ) << Pointf(t_fine, lista_ml_l[i].QuestaMLav.v_media);
vel_media.Add(v_media_temp);

...

for(int i = 0; i < vel_media.size(); i++)
{

  ...

  scOee.AddSeries(vel_media[i]).NoMark().Stroke(1, LtGreen).Dash(LINE_SOLID).Legend("vm"+AsString(i));
}


The important thing here is that both the big bars and the light green line share the same x (t_in in my code). Thus, they are aligned. This is what happened with the old version, but with the new version they are no more aligned.

As far as regards, the report, I still get round edges:

https://ibb.co/gEXQdF

Regards,
Gio
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #48159 is a reply to message #48143] Mon, 29 May 2017 12:45 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2740
Registered: August 2008
Location: Basque Country
Senior Veteran
Dear Giorgio

The problem is that you use Painter to render the control, but Draw is used to render to the Clipboard and the plot legend.

In Windows, Draw uses GDI API, and it sets pen using U++ function SetDrawPen(), that calls CreatePen(). However, CreatePen() by default uses rounded caps (see this link).

To solve this, it would be necessary to review U++ drawing to use SetDrawPen() with PS_GEOMETRIC | PS_ENDCAP_SQUARE | PS_SOLID.

I think the easiest solution would be just to use OnPaint capability filling rectangles instead of 30 points thick lines.

If you would need a sample I can include something for you in Controls4U_demo.


Best regards
Koldo
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #48255 is a reply to message #48159] Mon, 12 June 2017 11:52 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 70
Registered: August 2015
Member
Hi Koldo,
thank you for your suggestion: I drew the bars inside OnPaint and finally I got squared edges.
Regards,
Gio
Re: Adding a text box in a scatterDraw/ScatterCtrl [message #48261 is a reply to message #48255] Tue, 13 June 2017 09:51 Go to previous message
koldo is currently offline  koldo
Messages: 2740
Registered: August 2008
Location: Basque Country
Senior Veteran
Excellent Giorgio Smile

Best regards
Koldo
Previous Topic: Serial Package Baazar
Next Topic: Save sccatterCtrl to png: resolution
Goto Forum:
  


Current Time: Sun Jun 25 22:51:06 CEST 2017

Total time taken to generate the page: 0.01067 seconds