QT C++ code samples

More
27 Jun 2019 16:31 - 27 Jun 2019 20:14 #138006 by Grotius
Replied by Grotius on topic QT C++ code samples
Today i started a coding technique with a new filosofy. It's just fall, stand up, and try again, and try to expand our limited knowledge.

We really need to load the entire dxf file into the memory of the linux pc.
And after the file is loaded into a huge array (memory), we can do calculation's like cosinus for i and j, sorting, swapping, hashing etc.
An sich manipulating an array is quite easy to do.

For the contour recognize i use the matching of double values from x,y,z value's. Double value's are big values that can be round off by pc in different way's. So it's dangerous to do without any safetybeld.
So we use a relative change and difference formula for this with a tollerance user input value.

Just made a program template that could be very interesting for the dxf decoder program.

The idea is to load the dxf file into a multi dimension array at once.



As you see. The core of the program can be very compact this way. The array is also easy to expand after all.
We can export from source to svg, stl, etc with a extra array line.... The program flow is perfect.

In fact the multidimensional array can be seen as the heartbeat of the program. It's inside a C++ class wich is a part of the program.

Some one could ask me : In some cases you could better use a "integer" instead of a "double" in the <double>multidimensional array?

The problem is. If i wrote the source code for the array's in C and C++. Mixing double's and integers, strings, etc in the same array would be possible for sure ! But that time will come soon. QT is the first that will do that. It will be called the QArray.
Attachments:
Last edit: 27 Jun 2019 20:14 by Grotius.

Please Log in or Create an account to join the conversation.

More
27 Jun 2019 21:08 #138033 by rodw
Replied by rodw on topic QT C++ code samples
It seems to me that the next lesson on C coding you need is about structures and pointers. A structure gathers the attributes about your object with different data types into one easy to understand variable object.
So then you can create an array of structures which will be much easier and cleaner to understand
So this brings you to needing to understand pointers so you can use a pointer variable to point to the array element you wish to access
And then finally, this application may well lend itself to a linked list which means you would define a new structure containing your dxf structure an two pointers (next and previous). This lets you build a dynamic system where each element knows where the one before it lives and the one after it lives (the first one has a NULL for previous and the last one has a NULL for next). Linked lists are extremely powerful advanced techniques because you can reorder the list just by manipulating the pointers.

So master pointers by writing your own versions of some of the string functions and new ones like upperstr() and lowerstr()
Then learn about structures and how to access them by use of a pointer
Then you will be able to think bout a linked list
Read some of the Linuxcnc source code in the emc folder and understand how it manages data.

By then, you will be a master kenobi of C
The following user(s) said Thank You: Grotius

Please Log in or Create an account to join the conversation.

More
28 Jun 2019 22:00 #138137 by Grotius
Replied by Grotius on topic QT C++ code samples
Hi Rod,

Thanks for your reply.

By then, you will be a master kenobi of C
It's not my purpose to become a good programmer. Sometimes i read abracadabra code.. And i think, i will never
understand this.

It's my purpose to write something for the community that can be helpful for at least 10-15 years.
The community has given Linux, Linuxcnc and so on.
It's my job now to give something back to the community. If this course takes time, it will be so.
Every day i become more and more powerful in coding. So i keep faith. Giving up is the easy part.

I made the same template for a structure, see the picture. The structure is indeed very easy in usage.



What i did not show in the previous post is that all variables are defined as extern variables.
This has to do with the OpenGL viewer that lives in a other C++ class and uses the extern variables to display the graphical output.
For example, when the program is upgraded with autonesting in future, we need the same exernal variables in the Autonesting Class.

I tested the Structure as extern structure for usage with extern variables, but this seems a problem at this moment.

The coding of a Array input field is just a little more work, because i will have to look at the input field number [] instead of a easy name when using a Structure.
Attachments:
The following user(s) said Thank You: tommylight, rodw

Please Log in or Create an account to join the conversation.

More
29 Jun 2019 20:14 - 29 Jun 2019 21:38 #138191 by Grotius
Replied by Grotius on topic QT C++ code samples
I used the Array template today.

Made a simple cad drawing :


The dxf Decoder output screen :


The used Array : (not dynamic allocating extra memory at this moment, limited to 2 milion gcode lines at this moment)


OpenGL reading the Array : ( it looks for the cad colors also.... )


The array is working very nice and has a 3d template.
The opengl is a 3d double output format. Perfect ! The dxf Decoder is fully 3d.

Todo :
Make some nice 3d views in the dxf Decoder OpenGL screen. Zoom in and zoom out is working on mouse scroll button.
I have to adapt the left mouse button to move the drawing, and connect the right mouse button to do a 3d rotate manipulation.
Attachments:
Last edit: 29 Jun 2019 21:38 by Grotius.
The following user(s) said Thank You: phillc54, tommylight

Please Log in or Create an account to join the conversation.

More
30 Jun 2019 21:26 #138257 by tommylight
Replied by tommylight on topic QT C++ code samples
Very nice! Thank you.

Please Log in or Create an account to join the conversation.

More
01 Jul 2019 17:53 - 01 Jul 2019 18:29 #138314 by Grotius
Replied by Grotius on topic QT C++ code samples
It's getting to be nice in a moment...

I started a brand new QT project today, the DxfDecoder project needs to be more structured to become Sheetcam and Fusion competitive in the future.

Project setup, to be expanded :


Terminal output of a dxf file array : ( Parallel Multidimensional Array's are the core of good luck !!)


I did a trick. I made one array's for Integers values and one array for Double values. The 2 array's are working parallel.
So it's more efficient coded. Every day we learn about mistakes !

Very nice! Thank you.
Thanks Tommy !!

It looks promising so far to me. In the beginning of the new QT project i will write some code special for contour recognizing.
This is the most difficult part, and hope to pass that part soon.

Constructing a formula (algoritme) for autonesting i must investegate.
Mayby OpenGL has already classes that can look if object's are in collision, if not i try to write some abracadabra code for this.

For now it's all about sorting the array that is loaded in memory. (look for matching color codes, sort lines and arc's to objects's etc)
Manipulating array's is just like sorting text files. I was started that way in C about year ago, but i have to use the pc memory (loaded array) to do user defined trick's and output G41.1 and G41.2 on request.

The sorting class with a tolerance input. If user has a bad cad drawing, it even can make a closed contour !!
It looks like a abs formula, but now written for dummies like me. :lol:


@Phill,
I had have a global look at your plasmac manual. I think you could publish this document.
Thanks for your work!! Remember you could use or integrate the Thermal Dynamics cutting charts open source, i have approval for this.

@Rodw,
Thanks for your plasma document. My cap off for your work !! Where do you keep the time for this?
Nice to see Linuxcnc is growing exponential related to plasma.

I can't believe i am writing a C++ coded cam program. Why do i do this ??
Attachments:
Last edit: 01 Jul 2019 18:29 by Grotius.
The following user(s) said Thank You: rodw

Please Log in or Create an account to join the conversation.

More
01 Jul 2019 22:50 #138341 by tommylight
Replied by tommylight on topic QT C++ code samples

. Why do i do this ??

That is a question for future generations ! :)
The following user(s) said Thank You: Grotius

Please Log in or Create an account to join the conversation.

More
01 Jul 2019 23:02 #138346 by rodw
Replied by rodw on topic QT C++ code samples


@Rodw,
Thanks for your plasma document. My cap off for your work !! Where do you keep the time for this?
Nice to see Linuxcnc is growing exponential related to plasma.

Thanks for the feedback, we'll get it published now. Phill is looking after that for me and I paid my graphic artist to do a couple of graphics so its all original content with no copyright issues.

I can't believe i am writing a C++ coded cam program. Why do i do this ??


Because you love it!

I have not had the time to follow your project but if you are sorting arrays, google "bubble sort" as its the most efficient (eg fastest) but if you stop using arrays and used dynamically allocated memory and linked lists, sorting becomes even quicker becasue you are just changing the linked list pointers (*previous and *next) rather than copying data from one array element to another.
The following user(s) said Thank You: Grotius

Please Log in or Create an account to join the conversation.

More
01 Jul 2019 23:57 #138358 by Grotius
Replied by Grotius on topic QT C++ code samples
I paid my graphic artist to do a couple of graphics so its all original content with no copyright issues.
I saw indeed pictures i never have seen before... Nice work!! I can share some cost's with you.

linked lists
www.tutorialspoint.com/cplusplus-program...t-singly-linked-list
for QT : doc.qt.io/qt-5/qlinkedlist.html

Please Log in or Create an account to join the conversation.

More
02 Jul 2019 09:52 #138386 by rodw
Replied by rodw on topic QT C++ code samples

I paid my graphic artist to do a couple of graphics so its all original content with no copyright issues.
I saw indeed pictures i never have seen before... Nice work!! I can share some cost's with you.

linked lists
www.tutorialspoint.com/cplusplus-program...t-singly-linked-list
for QT : doc.qt.io/qt-5/qlinkedlist.html


Now you are talking. Its a fairly advanced stuff as you need to uses structures and pointers so there is some prerequisite knowledge.. But if you don't use them, you are not really a C programmer. (well not an efficient one anyway!) This also looks good.
www.geeksforgeeks.org/linked-list-set-1-introduction/
Some times, it is useful to mainatin a double linked list so each element knows where the one before it is as well as the next one in front. This actually allows you to move an element in the list to any other location in the list very easilly. I'm a bit rusty on this stuff so you will be on your own!

I'm fine with the costs, my small contribution to the Open source movement :P
The following user(s) said Thank You: tommylight, Grotius

Please Log in or Create an account to join the conversation.

Time to create page: 0.227 seconds
Powered by Kunena Forum