FB CAD

User projects written in or related to FreeBASIC.
Post Reply
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

FB CAD

Post by owen »

FB CAD by Owen Reese
A cad program developed by freeBASIC programmers written in freeBASIC for the pupose of :
1. Learning how to code in freeBASIC
2. Creating a free basic cad program for all to use (freely)
3. Learning and understanding math
4. Inspiring Creativity.

http://www.fbcadcam.com

Image
Last edited by owen on Oct 21, 2018 1:25, edited 43 times in total.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

For example:

Post by owen »

Pressing Esc to end the program saves the drawing in file called "drawing.dxf" if you choose "Y" for yes.

Screen Layout:
The left side is used for drawing information, buttons and line color/layer selection. The right side is used for the drawing area.

Functionality:

While moving the mouse in the drawing area the x y coordinate of the mouse are shown on the left.

While drawing a line the line's length, angle and x2,y2 are shown on the left.

To draw a line:
Left click in the drawing area and move the mouse. The new line's x1,y1 is defined by the initial mousex,y position.

The line's x2,y2 follows the mouse(x,y). By left clicking a second time a new line is created and stored in an array.
By default a second line is beginning drawn in which it's x1,y1 was that of the x2,y2 of the previous line.

Either continue to draw lines by moving the mouse about and left clicking to define the beging and ending points of lines or ESC out of the line drawing mode by pressing the Escape key one time.

While drawing lines there are several options available by pressing keys:
Some of these options are available by using the buttons on the left.

"O" - Ortho mode: Draw vertical or horizontal lines by pressing "O". This turns ortho mode "ON" or "OFF"

"S" - Snap to the end point of another line. By positioning the mouse near the end point of another line and pressing "S" either the lines beginning or ending point will be set to that of the highlighted point.

"M" - Snap to the mid point of another line. By positioning the mouse over an existing line and pressing "M" either the lines beginning or ending point will be set the that of the highlighted line.

"L" - Set the length of a line as you are drawing it to:
A specified length - Enter the length an press return or set the length to that of another line's length by first having positioned the mouse over another line prior to pressing "L". Note: the angle of the line is determined either by the current angle or the set angle (setting the angle of a line is done by pressing "A").

"A" or "a"

"a" - Set the angle of a line by first starting a new line then press "a" and either:
Enter the angle such as 33 and press enter or use @33 to set the angle relative to that of the last selected angle. (by default the last selected angle is that of the last line drawn. Otherwise, the selected angle is set by highlighting another line prior to pressing "a")

"A" - Use "A" to set the angle relative the last line drawn - No need to enter the @.


"X" or "Y"
As a line is being drawn, it's end point is restricted to either x or y of the last selected lines x1,y1 or x2,y2 depending of which end point was highlighted.

To select objects in the drawing area for the purpose of deleting them or moving, copying, rotating, flipping etc... you have two options:
To select objects turn off all of the top buttons L,C,A,E (line, circle, arc, ellipse)
1st option is to position the mouse over an object and either press "g" or left click
2nd option is to box select one or more objects by left clicking once, release, move the mouse, drawing a box around the objects, and clicking a second time to sellect all items in the box.
Last edited by owen on Mar 06, 2007 5:59, edited 2 times in total.
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Post by maddogg6 »

Im using a recent CVS version of FB.
Using -lang qb...

I needed to add this: (around line 153)

Code: Select all

        Dim as INTEGER mousex, mousey, mousew, mouseb
Which is just before this:

Code: Select all

        GETMOUSE mousex, mousey, mousew , mouseb
Otherwise it gave me type mismatch error on 'mousex' with out dim'ing it first.

Nice work btw - but I didnt try importing the DXF into anything tho.

edit: using -lang fb and -lang deprecated gave a whole bunch of errors/warnings.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

rev1

Post by owen »

added maddogs requirement to dim mouse params
ps. i was able to import drawing.dxf into autocad2k - i was kinda using ac2k to verify my math was correct.
Last edited by owen on Feb 16, 2007 18:17, edited 1 time in total.
Ryan
Posts: 695
Joined: Jun 10, 2005 2:13
Location: Louisville, KY
Contact:

Post by Ryan »

Cool little program... I congratulate you on a great start!
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

new stuff

Post by owen »

added:
"I" - Import drawing.dxf into the current drawing. Currenly this is limitted to only those files that were created with FB-Cad.

"G" - Group: In order to delete, move or modifiy one or more lines,
Position the mouse over an existing line and press "g" to add it to the group.

"Del" - Delete group. Any lines in a group will be erased from the drawing area but not deleted from the array.

"Ctrl-Z" - Undo: Pending. Will Sequentially restore line's last state, i.e. if a line was previously deleted it will be restored.
Last edited by owen on Feb 16, 2007 18:18, edited 1 time in total.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

sample dxf file

Post by owen »

sample dxf file - save as drawing.dxf
oops - for some reason the text gets modified in the code block so I commented it all. When you copy this text you'll need to uncomment it and then save as drawing.dxf

Code: Select all

' 0
'SECTION
' 2
'TABLES
' 0
'TABLE
' 2
'LAYER
' 70
'15
' 0
'LAYER
' 2
'MYLAYER1
' 62
'162
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER2
' 62
'92
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER3
' 62
'132
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER4
' 62
'12
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER5
' 62
'212
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER6
' 62
'32
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER7
' 62
'9
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER8
' 62
'8
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER9
' 62
'5
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER10
' 62
'3
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER11
' 62
'4
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER12
' 62
'1
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER13
' 62
'6
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER14
' 62
'2
' 6
'CONTINUOUS
' 70
'0
' 0
'LAYER
' 2
'MYLAYER15
' 62
'7
' 6
'CONTINUOUS
' 70
'0
' 0
'ENDTAB
' 0
'ENDSEC
' 0
'SECTION
' 2
'ENTITIES
' 0
'LINE
' 8
'MYLAYER14
' 10
'379
' 20
'452
' 30
'0
' 11
'302
' 21
'452
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'302
' 20
'452
' 30
'0
' 11
'281
' 21
'308
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'281
' 20
'308
' 30
'0
' 11
'296
' 21
'308
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'379
' 20
'452
' 30
'0
' 11
'376.835396603924
' 21
'437.157005284051
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'376.835396603924
' 20
'437.157005284051
' 30
'0
' 11
'315.835396603924
' 21
'437.157005284051
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'353.917698301962
' 20
'372.578502642025
' 30
'0
' 11
'305.417698301962
' 21
'372.578502642025
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'305.417698301962
' 20
'372.578502642025
' 30
'0
' 11
'296
' 21
'308
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'356.082301698038
' 20
'387.421497357975
' 30
'0
' 11
'307.582301698038
' 21
'387.421497357975
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'307.582301698038
' 20
'387.421497357975
' 30
'0
' 11
'315.835396603924
' 21
'437.157005284051
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'353.917698301962
' 20
'372.578502642025
' 30
'0
' 11
'356.082301698038
' 21
'387.421497357975
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'406
' 20
'452
' 30
'0
' 11
'384.999999999999
' 21
'308
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'384.999999999999
' 20
'308
' 30
'0
' 11
'450
' 21
'308
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'406
' 20
'452
' 30
'0
' 11
'471.000000000001
' 21
'452
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'471.000000000001
' 20
'452
' 30
'0
' 11
'480.835396603924
' 21
'437.157005284051
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'450
' 20
'308
' 30
'0
' 11
'464.164603396075
' 21
'322.842994715949
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'460.5
' 20
'380
' 30
'0
' 11
'474.664603396076
' 21
'394.842994715949
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'474.664603396076
' 20
'394.842994715949
' 30
'0
' 11
'480.835396603924
' 21
'437.157005284051
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'464.164603396075
' 20
'322.842994715949
' 30
'0
' 11
'470.335396603923
' 21
'365.157005284051
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'470.335396603923
' 20
'365.157005284051
' 30
'0
' 11
'460.5
' 21
'380
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'409.417698301961
' 20
'372.578502642025
' 30
'0
' 11
'402.164603396075
' 21
'322.842994715949
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'418.835396603924
' 20
'437.157005284051
' 30
'0
' 11
'411.582301698037
' 21
'387.421497357975
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'409.417698301961
' 20
'372.578502642025
' 30
'0
' 11
'444.417698301962
' 21
'372.578502642025
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'411.582301698037
' 20
'387.421497357975
' 30
'0
' 11
'446.582301698038
' 21
'387.421497357975
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'418.835396603924
' 20
'437.157005284051
' 30
'0
' 11
'453.835396603925
' 21
'437.157005284051
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'402.164603396075
' 20
'322.842994715949
' 30
'0
' 11
'437.164603396076
' 21
'322.842994715949
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'437.164603396076
' 20
'322.842994715949
' 30
'0
' 11
'451.329206792151
' 21
'337.685989431899
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'444.417698301962
' 20
'372.578502642025
' 30
'0
' 11
'454.253094905885
' 21
'357.735507926076
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'454.253094905885
' 20
'357.735507926076
' 30
'0
' 11
'451.329206792151
' 21
'337.685989431899
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'453.835396603925
' 20
'437.157005284051
' 30
'0
' 11
'463.670793207848
' 21
'422.314010568102
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'446.582301698038
' 20
'387.421497357975
' 30
'0
' 11
'460.746905094113
' 21
'402.264492073924
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'460.746905094113
' 20
'402.264492073924
' 30
'0
' 11
'463.670793207848
' 21
'422.314010568102
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'550
' 20
'387.421497357975
' 30
'0
' 11
'538.417698301962
' 21
'308
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'538.417698301962
' 20
'308
' 30
'0
' 11
'615.417698301962
' 21
'308
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'615.417698301962
' 20
'308
' 30
'0
' 11
'617.582301698037
' 21
'322.842994715949
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'555.582301698037
' 20
'322.842994715949
' 30
'0
' 11
'617.582301698037
' 21
'322.842994715949
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'550
' 20
'387.421497357975
' 30
'0
' 11
'627
' 21
'387.421497357975
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'627
' 20
'387.421497357975
' 30
'0
' 11
'624.835396603924
' 21
'372.578502642026
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'624.835396603924
' 20
'372.578502642026
' 30
'0
' 11
'562.835396603924
' 21
'372.578502642026
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'562.835396603924
' 20
'372.578502642026
' 30
'0
' 11
'555.582301698037
' 21
'322.842994715949
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'639
' 20
'308
' 30
'0
' 11
'639
' 21
'347.710748678988
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'639
' 20
'347.710748678988
' 30
'0
' 11
'674
' 21
'347.710748678988
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'674
' 20
'347.710748678988
' 30
'0
' 11
'674
' 21
'308
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'674
' 20
'308
' 30
'0
' 11
'660
' 21
'308
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'660
' 20
'308
' 30
'0
' 11
'660
' 21
'335
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'660
' 20
'335
' 30
'0
' 11
'647
' 21
'335
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'647
' 20
'335
' 30
'0
' 11
'647
' 21
'308
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'647
' 20
'308
' 30
'0
' 11
'639
' 21
'308
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'656.5
' 20
'347.710748678988
' 30
'0
' 11
'656.5
' 21
'387.421497357975
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'656.5
' 20
'387.421497357975
' 30
'0
' 11
'639
' 21
'347.710748678988
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'656.5
' 20
'387.421497357975
' 30
'0
' 11
'674
' 21
'347.710748678988
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'698
' 20
'389
' 30
'0
' 11
'686
' 21
'296
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'686
' 20
'296
' 30
'0
' 11
'743
' 21
'335
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'743
' 20
'335
' 30
'0
' 11
'698
' 21
'389
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'705
' 20
'359
' 30
'0
' 11
'700
' 21
'319
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'700
' 20
'319
' 30
'0
' 11
'723
' 21
'337
' 31
'0
' 0
'LINE
' 8
'MYLAYER14
' 10
'723
' 20
'337
' 30
'0
' 11
'705
' 21
'359
' 31
'0
' 0
'ENDSEC
' 0
'EOF
'
Use "I" to import the dxf file
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

update

Post by owen »

Added 2 new sub routines

altofxm:
newlength= (fxm-x1) / cos ( angle2*PI/180 )
gosub atolength2
return
altofym:
newlength= (y1-fym) / sin ( angle2*PI/180 )
gosub atolength2
return

These routines are called by pressing "X" or "Y" while drawing a line at a spcified angle. For example: Their purpose is to allow a line to be drawn at 45 degrees and setting the end point (x2 / y2 ) to that of another line's x value while maintaing the specified angle of 45 degrees.
Last edited by owen on Feb 16, 2007 18:20, edited 1 time in total.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

using option explicit

Post by owen »

I had a bunch of erros in the code.
Tested using FBIde 0.4.6 and FBC 0.16 using option explicit.
Last edited by owen on Feb 16, 2007 18:21, edited 1 time in total.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

added some buttons

Post by owen »

So far it can only draw lines, ie. no circles yet.
I added some buttons to click on in order to change the snap to settings. Snapping to the end points of lines is still available by pressing "S" on the keyboard, or "M" to snap to mid points, etc...
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

code is getting real sloppy

Post by owen »

I added copy, move, rotate functionality.
Skyler
Posts: 242
Joined: Sep 26, 2006 16:30

Post by Skyler »

Sounds cool. Keep working. :-)
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

additions

Post by owen »

added flip vertical, horizontal, both and copy flips
obelisk
Posts: 2
Joined: Jul 16, 2006 1:34

Post by obelisk »

Very cool!
Can't wait for arcs and circles.

Keep up the great work.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

added zoom and pan

Post by owen »

zoom with the mouse wheel or by using the Z or z buttons

pan - turn the pan button on and hold / drag with the left mouse

note: the left mouse is also used for drawing and selecting so disable pan if it is enabled
Post Reply