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 » Problem in example code (Tried SplitterFrame yet minor problem.)
Re: Problem in example code [message #45846 is a reply to message #45844] Tue, 12 January 2016 17:00 Go to previous messageGo to next message
vegaonline is currently offline  vegaonline
Messages: 35
Registered: December 2015
Location: Mumbai, India
Member

koldo wrote on Tue, 12 January 2016 18:27
Hello Abhijit

For the ScatterCtrl the best for you would be to open ScatterCtrl_demo and reading for example tab1_Basic.cpp.

For example you can declare a Vector<Pointf> data in a safe place (as a class member, for example), fill it with the data from your file and do this:

void Tab1_Basic::Init()
{
	CtrlLayout(*this);	
	SizePos();
	
	data << Pointf(10, 26) << Pointf(20, 37) << Pointf(30, 31) << Pointf(40, 33) << Pointf(50, 28);
	scatter.AddSeries(data).Legend("Series 1").Fill().MarkBorderColor();
	
	scatter.SetRange(60, 50).SetMajorUnits(10, 10);
	scatter.ShowInfo().ShowContextMenu().ShowPropertiesDlg().SetPopText("h", "v", "v2").SetMouseHandling(true, true);
	scatter.SetLegendPos(Point(20, 20));
}


Dear Koldo,

Thanks a lot for the reply. I have already seen the scattercontrol example. However, my problem is that if filename="......" known then how can I load data and place in Pointf vector? I did not see cin type of function. At the same time, if I use LoadFromFile(filename) then string will be loaded.

Actually I am confused and can't formulate exact code.

Best regards,
Abhijit
Re: Problem in example code [message #45848 is a reply to message #45846] Wed, 13 January 2016 09:17 Go to previous messageGo to next message
vegaonline is currently offline  vegaonline
Messages: 35
Registered: December 2015
Location: Mumbai, India
Member

Beside this I find that I am unable to put items in the droplist or in the array (arrayCtrl). I tried to refer by doPlot.array which did not report any error while nothing was printed in the droplist.
Re: Problem in example code [message #45878 is a reply to message #45720] Tue, 19 January 2016 07:55 Go to previous messageGo to next message
vegaonline is currently offline  vegaonline
Messages: 35
Registered: December 2015
Location: Mumbai, India
Member

UP
Re: Problem in example code [message #45880 is a reply to message #45878] Tue, 19 January 2016 10:19 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello vegaonline

I understand that your issue is that you do not know how to get data from a text file, lets say a .csv file, and fill with it a C++ vector or an U++ Vector, isn't it?


Best regards
Iñaki
Re: Problem in example code [message #45881 is a reply to message #45880] Tue, 19 January 2016 10:27 Go to previous messageGo to next message
vegaonline is currently offline  vegaonline
Messages: 35
Registered: December 2015
Location: Mumbai, India
Member

koldo wrote on Tue, 19 January 2016 14:49
Hello vegaonline

I understand that your issue is that you do not know how to get data from a text file, lets say a .csv file, and fill with it a C++ vector or an U++ Vector, isn't it?



Two points.

(i) I want to read a csv data file and take into U++ vector. Can I do like C++ vectors which is easy?
(ii) When I try to put items in droplist associated to a layout, I see nothing. Pl. see last attachment.
Re: Problem in example code [message #45882 is a reply to message #45881] Tue, 19 January 2016 15:44 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Vegaonline

You can load text files in many ways. In Bazaar/Functions4U there are two functions:

- ReadCSVFile(): Simpler to use
- ReadCSVFileByLine(): It can read huge text files

For example:

Vector<Vector <Value> > ReadCSVFile(
	const String fileName,		// File name
	char separator = ',', 		// Separator between data
	bool bycols = true, 		// Data is in columns, not in rows
	bool removeRepeated = true, 	// Remove repeated rows
	char decimalSign = '.', 	// Decimal sign (it may be ',' instead
	bool onlyStrings = false	// if false, it tries to use the appropriate number type, if not it consider everything as strings
);


Best regards
Iñaki
Re: Problem in example code [message #45884 is a reply to message #45881] Tue, 19 January 2016 21:16 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

vegaonline wrote on Tue, 19 January 2016 10:27
(i) I want to read a csv data file and take into U++ vector. Can I do like C++ vectors which is easy?

As Koldo already said, there is many ways. I like this one:
FileIn f("/path/to/my.file");
String ln = f.GetLine();
String val1, val2;
Vector<double> x, y;
while( !f.IsEof()) {
	SplitTo(ln, '\t', val1, val2);  // for tab delimited values, change delimiter as needed
	x.Add(StrDbl(TrimBoth(val1)));
	y << StrDbl(TrimBoth(val2));    // this is same as y.Add, just bit easier to read in some cases
	ln = f.GetLine();
}


vegaonline wrote on Tue, 19 January 2016 10:27
(ii) When I try to put items in droplist associated to a layout, I see nothing. Pl. see last attachment.

You are actually doing it right in your code:
	doPlot.pltType.Add(0,"2D");
	doPlot.pltType.Add(1,"3D");
	doPlot.pltType.Add(2,"Contour");

The problem is, that this pice of code is in function doPlt, that is never called, so all the initialization it should perform never happens. move the DropList initialization to the constructor of your class and it will work as expected.

Best regards,
Honza

PS: I'm sorry it took me so long to answer. Those two questions required me to look in to the code and test it, so it took longer than simple questions that I can answer from top of my head.
Re: Problem in example code [message #45886 is a reply to message #45720] Wed, 20 January 2016 10:12 Go to previous messageGo to next message
vegaonline is currently offline  vegaonline
Messages: 35
Registered: December 2015
Location: Mumbai, India
Member

Dear Kolbo and Honza,

Thanks a lot for the reply and kind help.

@Honza I am grateful to you for illustrating so lucidly in spite of your busy schedule.

Adding initialization in constructor solved DropList problem.

However, for plotting say scatter plot, one needs Vector<Pointf> V type of data. Here I am reading Vector<double> x, y;

I tried :

Vector<double> x, y;
VectorMap<double, double> P1;
while (!inF.IsEof()) {
		SplitTo(ln, ',', val1, val2);  // for tab delimited values, change delimiter as needed
		x.Add(StrDbl(TrimBoth(val1)));
		y << StrDbl(TrimBoth(val2));    // this is same as y.Add, just bit easier to read in some cases
		P1<<(x,y);           //<--------------------------------- CHECK 
		ln = inF.GetLine();
		doPlot.array.Add(val1);
		doPlot.array.Add(val2);
	}


Here, I wanted to put val1 and val2 to P1 as (val1, val2) so that I may take P1 to scatter. However, it is not successfull. Also
I am unable to show data in arrayCtrl array.

Best Regards
Abhijit

[Updated on: Wed, 20 January 2016 10:15]

Report message to a moderator

Re: Problem in example code [message #45887 is a reply to message #45886] Wed, 20 January 2016 10:57 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi,

You can simply construct Pointf from two doubles: Pointf(x, y). So the code would be:
Vector<Pointf> data;
while (!inF.IsEof()) {
		SplitTo(ln, ',', val1, val2);
		double x = StrDbl(TrimBoth(val1));
		double y = StrDbl(TrimBoth(val2));
		data.Add(Pointf(x,y));
		ln = inF.GetLine();
	}


Honza
Re: Problem in example code [message #45888 is a reply to message #45887] Wed, 20 January 2016 11:24 Go to previous messageGo to next message
vegaonline is currently offline  vegaonline
Messages: 35
Registered: December 2015
Location: Mumbai, India
Member

dolik.rce wrote on Wed, 20 January 2016 15:27
Hi,

You can simply construct Pointf from two doubles: Pointf(x, y). So the code would be:
Vector<Pointf> data;
while (!inF.IsEof()) {
		SplitTo(ln, ',', val1, val2);
		double x = StrDbl(TrimBoth(val1));
		double y = StrDbl(TrimBoth(val2));
		data.Add(Pointf(x,y));
		ln = inF.GetLine();
	}


Honza


Thanks a lot. What would happen for 3D data having (x, y, z) for contour plot?
Best,
Abhijit
Re: Problem in example code [message #45889 is a reply to message #45888] Wed, 20 January 2016 13:50 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
As far as I know we cannot plot 3D data yet.

Best regards
Iñaki
Re: Problem in example code [message #45890 is a reply to message #45889] Wed, 20 January 2016 16:56 Go to previous messageGo to next message
vegaonline is currently offline  vegaonline
Messages: 35
Registered: December 2015
Location: Mumbai, India
Member

koldo wrote on Wed, 20 January 2016 18:20
As far as I know we cannot plot 3D data yet.


Hi Koldo,

Thanks for the insight. However, then can I use Python here like embedding?
The reason is that I need to plot 2D and 3D with contour plotting and I used matplotlib.pyplot for 3D plotting using Anaconda.

Best Regards
Abhijit
Re: Problem in example code [message #45896 is a reply to message #45890] Fri, 22 January 2016 10:12 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Sorry, I do not have any idea about python.

Best regards
Iñaki
Re: Problem in example code [message #45897 is a reply to message #45896] Fri, 22 January 2016 10:39 Go to previous messageGo to next message
vegaonline is currently offline  vegaonline
Messages: 35
Registered: December 2015
Location: Mumbai, India
Member

Dear Koldo,

Thanks.

I have a confusion. Suppose I have a class Testing which is declared as TopWindow. Now let there be another class Plotting
as ParentCtrl. I can declare "Plotting plt" in the construction of class Testing so that I may access methods of Plotting
from Testing by using "plt.funcInPlotting".

Is there any way by which I can also refer a variable/methods of Testing from a function of Plotting?

Best Regards
Abhijit
Re: Problem in example code [message #45898 is a reply to message #45897] Fri, 22 January 2016 14:06 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

vegaonline wrote on Fri, 22 January 2016 10:39
I have a confusion. Suppose I have a class Testing which is declared as TopWindow. Now let there be another class Plotting
as ParentCtrl. I can declare "Plotting plt" in the construction of class Testing so that I may access methods of Plotting
from Testing by using "plt.funcInPlotting".

Is there any way by which I can also refer a variable/methods of Testing from a function of Plotting?

Short answer: You can pass reference or pointer to Testing when constructing the Plotting instance, or when calling its function.

Slightly longer answer: There is many ways to do that, some better and some worse. But all of them are actually not connected to U++ in any way. This is a matter of general C++ application design. If you want to write complex applications in C++ you should already know this.

Honza
Re: Problem in example code [message #45941 is a reply to message #45898] Fri, 29 January 2016 13:05 Go to previous messageGo to next message
vegaonline is currently offline  vegaonline
Messages: 35
Registered: December 2015
Location: Mumbai, India
Member

Thanks a lot.

I have another problem. I have a layout containing lots of EditField and DropList etc. I want to store in a file. I though to save in JSON file. I am using the following snippets.
filename1 = "";
	PWDir="/home/vega/MyApps/Flasher/DAT/";
	fs1.PreSelect(PWDir);
	fs1.Types("*.inp");
	if (fs1.ExecuteSaveAs(NULL))
		filename1 = ~fs1;

	for (Ctrl *q = GetFirstChild(); q; q=q->GetNext())
		if (dynamic_cast<EditField *> (q)) {
			String id = q->GetLayoutId();
			PromptOK(id);
			if (id.GetCount())
				json(id, ~*q);
		}
	SaveFile(ConfigFile(filename1), json);



I find that SaveAs window comes and after entering filename to store, the file is not stored.

How can I solve the issue?

Best Regards
Abhijit

[Updated on: Fri, 29 January 2016 13:06]

Report message to a moderator

Re: Problem in example code [message #45942 is a reply to message #45720] Fri, 29 January 2016 20:43 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Abhijit,

I don't immediately see any problem with your code, without actually running it...

If I were you, I'd try to add some logging into key places of the code, to figure out where exactly is the problem. Use LOG and DUMP macros, which produce a log when the application is compiled in debug mode. To see the log, just press Alt+L or go to Debug > View the logfile. I'd start with adding DUMP(json) after the loop. Also, I guess you already tried inspecting the values of id, by adding PromptOK. Does it show the names of fields you are expecting?

Also, the code seems little over-complicated. Have a look at examples in reference/Jsonize. It displays exactly what you want, saving large structures into json file (just not as dynamically as you try to do it). Also reference/SelectFile might be of some help.

Best regards,
Honza
Re: Problem in example code [message #45944 is a reply to message #45942] Sat, 30 January 2016 06:37 Go to previous messageGo to next message
vegaonline is currently offline  vegaonline
Messages: 35
Registered: December 2015
Location: Mumbai, India
Member

dolik.rce wrote on Sat, 30 January 2016 01:13
Hi Abhijit,

I don't immediately see any problem with your code, without actually running it...

If I were you, I'd try to add some logging into key places of the code, to figure out where exactly is the problem. Use LOG and DUMP macros, which produce a log when the application is compiled in debug mode. To see the log, just press Alt+L or go to Debug > View the logfile. I'd start with adding DUMP(json) after the loop. Also, I guess you already tried inspecting the values of id, by adding PromptOK. Does it show the names of fields you are expecting?

Also, the code seems little over-complicated. Have a look at examples in reference/Jsonize. It displays exactly what you want, saving large structures into json file (just not as dynamically as you try to do it). Also reference/SelectFile might be of some help.

Best regards,
Honza



Hi Honza,

Thanks. Earlier I tried to see the DUMP file and now again I checked. It reports " json = {}". Also PromptOK did not show as the code did not go through that "IF" loop " if (dynamic_cast<EditField *> (q)) ".

Best,
Abhi
Re: Problem in example code [message #45946 is a reply to message #45944] Sat, 30 January 2016 09:33 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi,

I'm still not sure it is really good idea to this dynamically, but here is a working method:
	void StoreToJson() {
		Json json;
		for (Ctrl *q = GetFirstChild(); q; q=q->GetNext()) {
			if (dynamic_cast<EditField *> (q)) {
				String id = q->GetLayoutId();
				if (id.GetCount())
					json(id, ~*q);
			}
		}
		SelectFileOut out("*.*");
		if (out.IsOpen())
			out << json << "\n";
	}

It is actually almost the same as the code you posted. Full code is in the attached archive. Just click anywhere in the window to trigger the save as dialog. I'm not sure why it didn't work for you. Only thing I can think of is that you didn't assign names to the editfields in the layout.

Honza
Re: Problem in example code [message #45950 is a reply to message #45946] Sat, 30 January 2016 16:37 Go to previous messageGo to previous message
vegaonline is currently offline  vegaonline
Messages: 35
Registered: December 2015
Location: Mumbai, India
Member

dolik.rce wrote on Sat, 30 January 2016 14:03
Hi,

I'm still not sure it is really good idea to this dynamically, but here is a working method:
	void StoreToJson() {
		Json json;
		for (Ctrl *q = GetFirstChild(); q; q=q->GetNext()) {
			if (dynamic_cast<EditField *> (q)) {
				String id = q->GetLayoutId();
				if (id.GetCount())
					json(id, ~*q);
			}
		}
		SelectFileOut out("*.*");
		if (out.IsOpen())
			out << json << "\n";
	}

It is actually almost the same as the code you posted. Full code is in the attached archive. Just click anywhere in the window to trigger the save as dialog. I'm not sure why it didn't work for you. Only thing I can think of is that you didn't assign names to the editfields in the layout.

Honza


Dear Honza,

Thanks a lot. Your technique for SelectFileOut is working and one file is created while the content is "{}". It means json content was not made. Probably you are right that dynamic_cast is not working. EditFields have dedicated names. Here "if (dynamic_cast<EditField *> (q)) { " is not true.

Is there any other way to bypass dynamic_cast?

best
Abhi
Previous Topic: Issues using 2015.2 version
Next Topic: How to build FREBSD *.so in Windows?
Goto Forum:
  


Current Time: Fri Mar 29 12:52:09 CET 2024

Total time taken to generate the page: 0.02210 seconds