QT C++ code samples

More
08 Jun 2019 20:53 - 08 Jun 2019 21:04 #136306 by Grotius
QT C++ code samples was created by Grotius
Why post something about QT C++?

QT C++ is a nice option if we want to make a stand alone program, that could be anything up to Linuxcnc.

In my case like a dxf2gcode program or a parametric g-code generator program with a dynamic visual product output.

I started in GTK+ almost 3 year's ago with python only for linuxcnc gui's, later on i started project's in C for writing linuxcnc components. Some time ago i switched to QT C++ because i was lost to achieve a stable GTK+ OpenGL solution.
At the moment i am learning C++. The benefit of C++ is that it can be used in combination with C. My goal is to provide some basic examples in this topic over time. I hope the non experienced C++ user's like me can find out how the provided code is working.

Attached is a basic simple QT project example how to use local and global variables within a user gui.
Why is this code important? It's a building block to make parametric user input's for a g-code generator possible.

You can open the project by loading the .pro file.
To execute the already compiled program, unzip untitled1 and type in terminal : ./untitled1

If their are experienced QT user's. I am looking for very basic OpenGL examples how to draw lines etc. Don't hesitate to provide a example over here.

Picture of program gui :


The attached video is what i want to learn coming time, we can use this with QT C++, very cool !!
Attachments:
Last edit: 08 Jun 2019 21:04 by Grotius.
The following user(s) said Thank You: phillc54, tommylight

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

More
09 Jun 2019 08:45 #136355 by pl7i92
Replied by pl7i92 on topic QT C++ code samples
very nice
i think that is well over the top of many machine users
that just want to have a user button to there machine
you as a machine builder are sure the target users
and your customers will pay for it to add this button to your system

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

More
09 Jun 2019 19:46 - 09 Jun 2019 20:01 #136397 by Grotius
Replied by Grotius on topic QT C++ code samples
Attached a code example for drawing a line with the QT C++ OpenGLWidget.

This is the first example that lives on the internet which can draw a line with the new OpenGLWidget trough a
input field and execute button. I am proud to provide this bare basic code example on this forum !
It will be looked and downloaded by many people all over the world over the coming years. I think programming student's are
very happy with this code example. It's a nice start.

The example is clean written so user's can verify the code quite easy.

1. You can insert a value in the gui input text box. This value is limited to float value's with 2 decimal's accuracy.
2. The value of the input box is passed trough a extern variable to a different C++ file that does the OpenGL code.
3. The button passes the new value into the variable.
4. Screen is updated with timer function.
5. Provided is a basic zoom in and zoom out function that can be connected to the gui.
6. The file's are commented.
7. This example can be expanded to a g-code generator or a cad program.
8. A picture resource file example is provided.
9. Do not use a extern variable name like x for testing. This x is already used in OpenGL code, the error it will give will result in scratching your head a few hours. Use a name like xx or xvalue instead.
10. The application has a console output.
11. The code is working with latest QT release 5.12.3

Screen shot of the program output :


The QT C++ project files are attached. To open the project in QT select the .pro file.
To install QT, visit : www.qt.io/download

To try the already compiled program, unzip the untitled.zip file and type in terminal : ./untitled

@Maximilian,

I have to think about your suggestion "over the top". ;)
Attachments:
Last edit: 09 Jun 2019 20:01 by Grotius.
The following user(s) said Thank You: tommylight

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

More
09 Jun 2019 20:10 - 09 Jun 2019 20:11 #136399 by BigJohnT
Replied by BigJohnT on topic QT C++ code samples
While possibly over the top of machine users, on the other hand it's right in line for machine builders who know a bit of code.

I should do a project in C++ soon, just finished one in C and program in Python all the time.

JT
Last edit: 09 Jun 2019 20:11 by BigJohnT.
The following user(s) said Thank You: Grotius

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

More
09 Jun 2019 20:52 - 09 Jun 2019 20:55 #136401 by Grotius
Replied by Grotius on topic QT C++ code samples
@John Thornton,

Which C++ project are you interested in to make?

I have a question for you about coding.

If we have a dxf cad file sorted out for example in c, we can display both attached object's directly into a c coded g-code viewer, like a modified program example as above that works with c array's.

Only issue is, the dxf cad file output has no logic about :

G41 <D-> (left of programmed path)
G42 <D-> (right of programmed path)

So the cad file sometimes take's the path of G41 and sometimes takes the pat'h of G42.
There is no logic in that so far as i can see in the cad output. So it's a guess that has to be solved. Making a program that
works with G41 and G42 is in my perspective the future for Linuxcnc. Microstep machine's are also working this way.

So i made a if/else c code to look if the path is G41 or if the path is G42.
But in the most right picture, my logic is working in about 90% of the times. Does the logic takes a 1000 lines of code to keep up at 100% succes rate?



How can we solve this bottleneck easy?

Maybe you have a idea i overlooked so far.
Attachments:
Last edit: 09 Jun 2019 20:55 by Grotius.

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

More
09 Jun 2019 22:38 #136413 by BigJohnT
Replied by BigJohnT on topic QT C++ code samples
How do you determine the direction now?

Just off the top of my head you need to know what side of the path the user wants to cut ie which side is a part and which side is scrap. So that takes user input.

Next if it is a milling application you need to know the direction ie climb or conventional cut, for plasma it usually doesn't matter much.

Yea DXF files can be a mess I wrote a golang tool to import a DXF and starting with the first element it found spit out G code. I was impressed with the speed but dislike the language restrictions about files and such.

Not sure what I want to do in C++ I need to finish up my 7i92 configuration tool first so I'll have all the Mesa Ethernet cards with a simple configuration tool. I know pnccnof does some amazing things but I feel that it is to intimidating for fresh users.

JT

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

More
09 Jun 2019 23:00 - 09 Jun 2019 23:00 #136417 by Grotius
Replied by Grotius on topic QT C++ code samples
@JT,

How do you determine the direction now?
I look if the dxf go's clockwise or counterclockwise by a c coded structure.

It looks for differnent common patron's, but that could be over a 1000 option's if you want to be 100% sure. My code looks like reverse ingeneering a dxf file. So that is why i was complaining about Autodesk. They are really a mess making company at dxf level. Unbelievable in my opinion to provide nothing about direction within files over a 10.000 lines mostly filled with crap. They missed the point as developer in this case 100% for sure. Or there was another reason to make dust in the wind last 25 years.

Not sure what I want to do in C++ I need to finish up my 7i92 configuration tool first so I'll have all the Mesa Ethernet cards with a simple configuration tool. I know pnccnof does some amazing things but I feel that it is to intimidating for fresh users.

Just an idea to make money. Ethercat is used for Hotel door locking system's and more because it's quite safe.
More and more hotels are fitted with Ethercat solution worldwide, mostly of time 5 star + hotels will use Ethercat solutions.
Hotels need a central user interface gui coded in C++. So maybe in your country you can such a project for your own.

In fact to use the Ethercat with bare C is just fun. It's used in 2 person's deep sea submarine's. So think about your solution.
Maybe you want to make a solared powered suntracker and keep the star's in line with the QT C++ interface.
You have a canvais example over here : blog.qt.io/blog/2015/05/27/introducing-qt-canvas3d/



I wonder what your C++ program will be?
Last edit: 09 Jun 2019 23:00 by Grotius.

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

More
09 Jun 2019 23:38 #136425 by BigJohnT
Replied by BigJohnT on topic QT C++ code samples
Have you looked at using VTK for the screen rendering?

JT

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

More
11 Jun 2019 21:49 - 11 Jun 2019 22:08 #136665 by Grotius
Replied by Grotius on topic QT C++ code samples
@JT,

It looks like VTK is huge. Thanks for the tip !

I made a sample QT C++ program for plasma cutting a rectangular shape.
The user input is updating the OpenGL screen output, mouse zoom in and out is working.
The code is so far not tested in Linuxcnc. But is has kerf width offset and a lead in.
I am thinking about making a bevel option now. We can visualize this 3d in OpenGL.


Another view of the output with 2 decimal float value's ;) :



Attached the QT project files. If QT is installed, select the .pro file and you are on the run !
Attached the compiled program, to try it in linux, unzip the untitled.zip and type in terminal : ./untitled

Have fun !!
This is a basic example program that can be expanded to your needs.

Things i like to learn soon is how to program the lead in point by a mouse click !!

Edit, I forgot one line for displaying the lead-in into the g-code output :
 ui->plainTextEdit_3->appendPlainText("G0 X" + QString::number(leadin*-1) + " Y" + QString::number(leadin*-1));
Attachments:
Last edit: 11 Jun 2019 22:08 by Grotius.
The following user(s) said Thank You: tommylight

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

More
11 Jun 2019 23:43 #136676 by BigJohnT
Replied by BigJohnT on topic QT C++ code samples
When we tested VTK against gremlin VTK was a 100 times faster.

JT

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

Time to create page: 0.205 seconds
Powered by Kunena Forum