Draw boxes and lines, move them, and zoom

Blitz3D Forums/Blitz3D Beginners Area/Draw boxes and lines, move them, and zoom

hollifd(Posted 2016) [#1]
Still struggling with what seems should be simple. Can anyone point me in the right direction with this?

I am importing a 2D CAD file (DXF) format. I need to draw some "tooling" rectangles on the screen. I need to move the tooling and change the size of the tooling. I need to be able to move the "part" around on the screen and be able to zoom in on the part and tooling to get a better look. I am struggling with the methods to do this. I will show you my code below and would appreciate some help with this. If you have an idea, you can use rectangles to show me how it is done. This is a simulation tool that will allow me to setup a pressbrake (a machine used to bend steel into 3D shapes).

Thanks for any help.
Here is my code...



Below is the contents of the c:\Temp\junkoriginal5.txt file
Just paste this into a text file named c:\Temp\junkoriginal5.txt




hollifd(Posted 2016) [#2]
Got the moving and zooming figured out.

*** Still need help with the rotating and flipping functions at the bottom.

If you need the CAD data, you can paste the DXF CAD data from the section above to a text file on: c:\temp\junkoriginal.txt

Here is my code so far:




Kryzon(Posted 2016) [#3]
Give it a try (I changed the filename so watch out):



If you know C++ then I recommend that you try using the Qt library, it's got a lot of functionality for making visual applications like designers etc. It has graphics primitives (arcs, circles, lines etc.) and does transformations for you, like rotating, moving and scaling things with simple functions.

It's LGPL licensed, which allows you to make proprietary (closed-source) applications and sell them, you just need to distribute the Qt DLLs with your program.

http://doc.qt.io/qt-5/examples-graphicsview.html


hollifd(Posted 2016) [#4]
Kryzon,
Thanks for the code and I appreciate the time you have taken to try to help me. It does not seem to work exactly as I need. I don't know why I cannot wrap my brain around this problem. I have made some progress and have attached the latest version of the code below. When the user presses the R key, I want the entire "part" picture to rotate by the amount the user requests (Ex: 10 Deg CCW.)




Kryzon(Posted 2016) [#5]
When you rotate something, you rotate it around a point. Without specifying that point you can't do it.
That example I posted chose to rotate each line around their centre, so each line had a different rotation point.

If you want to rotate the entire arrangement of parts in your scene then you need to specify the point that they will rotate around before anything else.

In design programs this is usually the centre of the bounding rectangle of the selection -- that is, you have a bunch of selected objects and you rotate them all around the centre of the rectangle that encloses all objects.
This is not the same as the average centre (sum all positions and divide by the number of objects) because this would make the centre closer to clusters than separate objects far away.


hollifd(Posted 2016) [#6]
OK. I'll have another look at it after work tonight. I am thinking I want to rotate about the origin 0,0. I think I need to move the part to 0,0, rotate all of the geometry and then move it back to the original location. I'll try to work with this tonight. Thanks again for helping me with this. I am excited about the progress I have made so far and can't wait until it is finished. It will allow me to program for a machine offline without the operators from having to do it while the machine is not running.


Kryzon(Posted 2016) [#7]
If you move each part to 0,0 then they all will be rotated separately. If you want to rotate them all by the same point you need to subtract the location of that point from each part, rotate each part, then add back the location of the point.

You subtract the same point from all different parts no matter where they are, and this is what makes them all rotate around the same point.
When you subtract the location of that point from the location of the part it's as if you're viewing that point as the "origin", and all parts rotate around it.


hollifd(Posted 2016) [#8]
Kryzon...I am very close with your help. I am still having an issue with the arcs drawing correctly. If you press the R button a bunch of times, you will see the problem. Do you know what I have done wrong?




Kryzon(Posted 2016) [#9]
Your arc drawing code needs angles between (0, 359), so in the RotatePart function you need wrap the angles of the arc to that range.

This is the RotatePart function alone, with that correction (plus some stuff cut out from the circle and arc parts):




hollifd(Posted 2016) [#10]
Works perfectly! Thanks for your help. I couldn't have gotten this to work without your help. I really appreciate it.


hollifd(Posted 2016) [#11]
What are some better ways to get input from the user? Rather than hitting Function keys and keyboard keys, is there a better way and how is it done?




Kryzon(Posted 2016) [#12]
Standard in software is a combination of mouse + keyboard. People should be able to click and drag things like vertices etc.

I don't know how much time you have left to make this tool, if you were hired to make it etc. but I really recommend using BlitzMax and MaxGUI (you can find a tutorial series here), or even C++ and Qt like I mentioned before.
If you want people to feel familiar with your program then you need to use a GUI library so you can have things like buttons, menus, sliders etc. that look the same as those of other programs that they use.

I also suggest improving your code. If you have separate kinds of parts (circle, arc, line etc.), make one Type for each instead of having the same type that includes unused parameters to all types of objects.
C++ or BlitzMax will help you in this regard as they have more advanced ways to use classes (user types). The better you organise things, the less chances of making bugs.

An example of what you can do with Types in BlitzMax:




Guy Fawkes(Posted 2016) [#13]
Don't listen to him. He's nothing but an indoctrination of what the system WANT him to be. Be your OWN programmer! USE the methods these indoctrinators tell you NOT to use! And break FREE from your "college" program. It's nothing but a prison for your mind. Prison being a constant bad-intention loop even if you mean well. DON'T FALL FOR IT! Sure! C++ & Blitzmax are nice! BUT! It will take you YEARS to do something you already have within you in Blitz3D in "A" year if not MONTHS!

Oh! And for the record. Say whatever you all want because I am not responding to ANYONE who thinks indoctrination by going to "college" is cool & / or OK!

Here's a hint : Use the Code Snippets, bud! You'll find your way!

Infact, here's the links to both the Code Archives thread & the Code Archives pages:

Code Archives PAGE:

http://www.blitzbasic.com/codearcs/codearcs.php

Code Archives THREAD:

http://www.blitzbasic.com/codearcs/topics.php

HAVE AT IT!

Have honor within yourself!

~GF


hollifd(Posted 2016) [#14]
OK. Got it. I am not a programmer. This is a project that I am doing for my team of sheet metal fabricators. I am trying to create a way to allow people in the office to simulate a pressbrake and create a program that can be sent out to the machine to make production parts.

The basic concept is this:
1) Use the CAD system to export out a 2D DXF file
2) Extract the lines, arcs from the DXF file and open them up and display in Blitz
3) Click on each "bend line" and enter bend angle, bend direction, backgage settings, etc.
4) Add tooling to the Blitz screen and position for each bend
5)Export out all of these data points that can be formatted into a program that can make the pressbrake bend the parts

I do understand your points about my code and I do intend to clean it up after I get all of the concepts working.

There is more professional grade software available but it is very expensive...about $40K so I am creating the "poor man's" version. It is rinky dink but will allow me and my team to take a big step forward and increase our productivity.

I am having a lot of fun doing it. I am learning a lot and I am thankful for your help. If I can get everything working like I want, then I'll look at redoing it in BlitzMax or something else. I have always wanted to learn C++ but have not committed the time. At a glance, it seems very complicated.

Thanks again for all of your help. I am stunned that people that I don't know and don't know me are willing to dedicate their personal time to help out.


hollifd(Posted 2016) [#15]
This link is an example of what I would like to be able to accomplish someday. Does anyone know how this type of 3D simulation is accomplished? how can I take any 2D flat part like the one I have been using in my code above and convert it into something that can be shown and simulated bending?

link to video on youtube: https://www.youtube.com/watch?v=3YP0Xxxqjrw


hollifd(Posted 2016) [#16]
For anyone interested in my project. Here is my latest version:




hollifd(Posted 2016) [#17]
I can't figure out why my "CAMERA" functionality is not working properly. If you run the code below and press the F10 or F11 keys, you will see that the graphics do not pan left and right like I want. It pans at an angle rather than just left and right. Can anyone find my error or suggest another way to be able to pan left / right? I am using my Scale value to zoom in and out and that is working fine for me...but I need some way to pan left and right.

Thanks for any help you can offer,

Here is the contents of the CAD file for this program...
*** copy this data into a text file on C:\Temp\junkoriginal5.txt



Here is the main program code...



Kryzon(Posted 2016) [#18]
In your drawing code you're adding CenterY to all coordinates:
Line CenterY# + SX# * MyScale#, CenterY# - SY# * MyScale#, CenterY# + EX# * MyScale#, CenterY# - EY# * MyScale#
The signature of the Line function is Line( x1, y1, x2, y2 ), with all parameters being of integer type.


hollifd(Posted 2016) [#19]
I think I added the CenterY# so that my drawing would appear in the middle of the screen. When I remove the CenterY#, the drawing goes off screen to the upper left corner. Do you know how I can fix it?

latest version of code here...




hollifd(Posted 2016) [#20]
Kryzon...
I forgot to say Thanks, so...Thanks again for the help.

Next things I need to implement:

*** I need to be able to click on 2 lines and add a new line that is parallel and exactly in between the 2 lines picked

*** I need to be able to click on 2 lines and display a vertical distance, if lines are horizontal, or a horizontal distance if the 2 lines are vertical.

*** I need to click on a line on the part, rotate it to horizontal, then move the part up to the centerline of the "bed" or centerscreen.

*** I need to be able to click on a line and edit the properties of the line, like BendDirection, Angle, X, Z, settings, etc.

*** I need to be able to capture all of the positions for the gages, tooling, part and save them somehow and be able to recall them and "play" them back. Example: The part is a sheet metal part that can have 1 or more bends. For each bend, I will position the tooling, part and gages. After positioning these things for bend 1, I will save the data and move on to the next bend. Once all of the bends have been processed, I will want to recall the data for each bend and play them back on the screen. Finally, when the user is satisfied, all of the data for all of the bends will be exported out so that I can massage it to make a program that will be used at our pressbrake to do the actual physical bending.


hollifd(Posted 2016) [#21]
Zooming and panning problem is better now. I discovered the Origin command and that seems to have helped me out. I still think I have something wrong but it seems to work so I am marching forward.

If you have ideas or suggestions that would improve what I am doing, please let me know.

I am starting to work on the code to save the bend data the user has entered and be able to read it back in and "play" all of the movements.

Is there a SPLIT command in Blitz like in VBA or VB? This would help me a bunch reading comma separated data back into Blitz without having to parse all of the data with my code.


latest version of code is below...




Kryzon(Posted 2016) [#22]
When I remove the CenterY#, the drawing goes off screen to the upper left corner. Do you know how I can fix it?

You need to add CenterX to all X coordinates and CenterY to all Y coordinates. This should prevent the parts from sliding diagonally which is caused by adding the same value to all coordinates.


hollifd(Posted 2016) [#23]
Thanks Kryzon. I'm not using CenterX and CenterY now but I'll revisit that later if needed. What timezone are you in? I couldn't sleep last night thinking about this dang project so I logged on and I noticed you responded to one of my questions around midnight Eastern time. Do you program for a living or just for fun?


hollifd(Posted 2016) [#24]
What IDE do you use? I am using the default IDE that came with Blitz3D when I bought it many years ago. It is very difficult to work with. Is there anything better that you would recommend?


Kryzon(Posted 2016) [#25]
The problem is that Blitz3D is a 10+ year old product, so most of the options that were available at that time have been discontinued in expired websites or need patches to work with the latest version of Windows.
This is also reflected in the amount of people here that would be able to help you.

There seems to be IDEal left. I haven't used it:
http://www.blitzbasic.com/Community/posts.php?topic=105793#1294830
http://www.blitzbasic.com/Community/posts.php?topic=105599 (patch thread?)

Additionally, try BlitzPlus instead of Blitz3D (download at the bottom of this page, you need to be logged in).
BlitzPlus allows you to make a GUI for your program, it should feel more natural. The language syntax is the same as Blitz3D without the 3D functions (in fact, if you copy and paste your program it should work as it is).
At the very least you can add a menu bar, buttons and sliders to the window, and slowly work your way into a tool that is usable for production. There is also a code archives section with examples for inspiration: http://www.blitzbasic.com/codearcs/codearcs.php?cat=10&order=&asc=&lang_id=1

You can use this tool as a visual designer for the interface of your program (you need to build it with BlitzPlus first to get the .EXE -- this also means that this tool itself was made with BlitzPlus):
https://github.com/wiebow/guide

Anyway, best of luck.


hollifd(Posted 2016) [#26]
OK. I'll give that a try. I am trying to get this wrapped up good enough so I can start using it at work. I plan to keep plowing thru this until I get something I can use then look at BP.

I have added some EDIT LINES ability for anyone interested. Right mouse click near the mid point of a line and it should SNAP to the midpoint and display some options for editing. I don't really like it but it kinda works. I am sure my ideas are not the best so don't laugh too much. I will keep plugging away.

The next problem I have and don't have any good ideas is how can I allow the user to set certain properties for every BEND line and save the settings along the way and then allow the user to PLAY back all of the positions that he / she has set.

Latest version of code is below

.


hollifd(Posted 2016) [#27]
My Math is very weak and looking for some help drawing my ARCS after flipping the part (mirror about the Y Axis). Would someone (Kryzon?) bail me out with my ARC flipping function?

The latest version of my code is below. Please look at the ARC section in the FlipPart function.




Blitzplotter(Posted 2016) [#28]
There seems to be IDEal left. I haven't used it:


IDeal is awesome, the workspace function is great for having numerous tabs open with respect to a project.


Kryzon(Posted 2016) [#29]
	For ga.MyArcs = Each MyArcs
		;*** Need help with this code.  The arcs are not drawing correctly after flipping (Mirror about the Y Axis).  My Math is very weak.
		
		ga\SX# = ga\SX# * -1
		
		Local startCos#	= -Cos( ga\SA ) ;Negating the 'cosine' (the horizontal component) so it flips around the vertical axis.
		Local startSin#	= Sin( ga\SA )
		
		Local endCos#	= -Cos( ga\EA )
		Local endSin#	= Sin( ga\EA )

		ga\SA = ( ATan2( endSin, endCos ) + 360 ) Mod 360
		ga\EA = ( ATan2( startSin, startCos ) + 360 ) Mod 360
	
	Next



hollifd(Posted 2016) [#30]
Kryzon...
Thanks! Your code works perfectly!

You are the best!

Thanks again,
David