Drawing Program

Discussion in 'Open Source Projects' started by dennishea, May 22, 2008.

  1. dennishea

    dennishea Active Member Licensed User

    This is something I started and need a lot of help with. I put a wordpad file and source code with dll's that I started with. The wordpad file discribes the basic way I have it set up to function with whats done so far.

    updated zip file.

    Attached Files:

    Last edited: May 27, 2008
  2. klaus

    klaus Expert Licensed User

    Hi dennishea,

    I had a look at your program and have some questions and suggestions.

    - what is the main purpose of the program ?
    - do you want bitmap graphics or vector graphics, in the second case don't you need scaling with zoom and unzoom ?
    - still in the second do you want to have closed surfaces, then they could be solid or hollow ?

    Data structure, for vector graphics:
    You could have a structure like:
    - a list of points
    with the coordinates x,y

    - a list of lines
    with Type and Data depending on the type
    Type: Line Data: 1st point index, 2nd point index not the coordinates !
    Type: Arc1 Data: center point index, radius, angle1, angle2
    Type: Arc2 Data: 1st point index, 2nd point index, radius
    Type: Arc3 Data: 1st point index, 2nd point index, 3rd point index

    - a list of surfaces
    with Type and Data depending on the type, solid or hollow
    Type: Rectangle Data: upper left point index, lower right point index
    the two other points are calculated (angle if you want to rotate it)
    Type: Circle1 Data: center point index, radius
    Type: Sector1 Data: radius1 line index, radius2 line index, arc index
    Type: General Data: number of lines, line indexes

    If you have a line with segments the end point of a segment and the beginning point of the next segment is the same point. If you change the coordinates of that point both segments will be changed and the surface too.

    A rectangle can be defined by 2 points (and angle) or 4 lines.
    in the first case if you change the coordinates of one point both lines should be changed.
    in the second case it's not really a rectangle but a special case of a General surface, if you change the coordinates of one point it will no longer be a rectangle.

    I hope this is understandable!

    As a user I would prefer having buttons in a toolbox instead of the menu it gives a better overview of the possibilities and active functions.

    For the circle it would be interesting to be able to move the mouse for the radius, and display the circle in function of the mouse position and with the MouseUp event set the final values. Same for rectangle and ellipse.

    For the grid I would suggest you to use a variable for the grid width instead of a number so if once you want to change it you just change the variable value and the rest is automatic, otherwise you would have to change x times the number.

    To calculate the radius you don't need to use the Max and Min functions, a power of two is always positive.

    Your routine to draw the arcs is only valid for small radiuses, with a radius of 100 the arc becomes a dotted line. Colin9876's routine is more universal in setting the angle step to the inverse of the radius.

    In the drawing routines it would be more universal to transmit variables instead of dealing with the textbox contents in the routine.
    Ex: DrawLine(x1, y1, x2, y2, col)

    I put some of these suggestions in the joined program.

    Best regards and good luck !

    Attached Files:

  3. Rioven

    Rioven Active Member Licensed User

    Hi dennishea,

    I like the idea once the application could produce an accurate scaled drawings.

    It will be useful for its scale accurateness once printed-out on several paper sizes.

    Once the application have zoom and pan feature, then this is way to go!

    By the way...have you thought that the application should have drawing operation steps or style based on some popular CAD applications, like AutoCAD, Microstation or similar?

    Best regards,
  4. dennishea

    dennishea Active Member Licensed User

    @klaus & rioven

    My intention is to have a super stripped down version of autocad lite
    Things it needs
    2snap to.
    bmid point.
    cend point.
    dcenter point "for circle and arc".
    ethere are others but not sure they are a necessity.
    3ability to size the drawing before starting.
    4scroll leftrightupdown.
    5it needs to be scalable to as tight as tolerance as possible.
    6snap two points on drawing and get distance or angle           
    enter relative or absolute data manually
    printing would be nice but bmp is printable.

    or vector  I do not know difference or which is better for task.

    In your list of surfaces you use the word indexcould you explain in simpler or 
    more detailedAt this point I realize I don't have the education to do this by 
    myself. I don'
    t expect people to do this for me but a tiny example or point me 
    in right direction 
    for informationThanks for both your time and klaus's examples.

    I hope I have given enough to shed some light.

  5. klaus

    klaus Expert Licensed User

    Hi dennishea,

    Yes, now the light is switched on !

    To do what you want to do, you need to use vector graphics.

    In vector graphics the points are stored in a list with their physical coordinates, the point index is it's position in that list. Lines are referred to these points and the graphic is a 'just' a display of it. The accuracy is garantied by the physical values.

    In bitmap graphics you 'just color dots' the pixels. If you want to zoom you loose accuracy.

    What do I mean with indexes?
    Take the example of a line:
    The line is determined by two points:
    let's say point 3 and point 4 in the point list, 3 and 4 are the indexes.
    In the line parameters the points are referred to by their position in the point list rather than with the points coordinates.
    A same point can belong to more than one line.

    The line belongs to a surface, in the surface parameter only the position of the line in the line list is stored.

    I will look to make a first sample how I would see a program like this, and submit it as soon as there is something testable.

    Best regards.
    Last edited: May 25, 2008
  6. dennishea

    dennishea Active Member Licensed User

    Hi klaus Thanks very much for your :sign0085:. :)
  7. ceaser

    ceaser Active Member Licensed User


    Hi Klaus and Dennishea

    What I have done is to give the user an input sheet, where the person can enter the limits of the 4 corners of the screen. I then calculate a ratio between the screen size and the limits entered. This constant is then applied to the X and Y positions on the screen. The drawing information that is kept in the database is still correct, but when it gets plotted on the PPC, it gets adjusted by this ratio.:confused:

    Vice versa is also true. When you plot a line on the PPC, it gets adjusted by this ratio...i.e. line(1000,1000,2000,2000) will get plotted on the screen as (50,50,100,100) depending on the ratio.

    I should finish all the basic drawing stuff (lines, circles, arc...) by the end of the week and I will post it here again.

    I have not given the zoom functions much attention yet.

  8. klaus

    klaus Expert Licensed User

    Hi Micheal,
    Having a scaling factor for the pixel with the physical area and the display pixel dimensions was obvious to me. For me the open question was, when the these parameters are defined the scaling factor is given and there is no way to change it afterwords. And also in connection with the zoom.

    Hi dennishea,
    In all my programs I use variables for the parameters and save them just in simple text files.
    At loading I allocate the values to the variables.
    I used, until now, tables only when I needed them to display data.

    Best regards.
    Last edited: May 28, 2008
  9. dennishea

    dennishea Active Member Licensed User

    Hi klaus & ceaser

    At klaus

    Do you mean like an ini file for setting variable default or last used settings? Like default grid size, drawing size, inches or mm's, etc etc. In auto cad lite I believe min x,y or 0,0 is bottom left and max top right. Drawing size would be determined by the size of what I'm drawing. I'm assuming that the data you save would also contain drawing size, weather it was set up in inche
    's or mm's with the coordinates of your lines, circles, arcs, and what not following. The table I've created holds the beginning and end points for lines, the center xy beginning angle end angle and radius for arc, and xy center and radius for circles. If there is a more efficient way of saving all the coordinates I would really like to learn it, the reason I used table is because it was the easiest for me. I will create and ini file for settings I want a template to start with and if I change them the changes can stay with that drawing file. I am just giving information for why I did what I did and if it's not the best direction for this type of program I would appreciate any help getting pointed in the right direction.

    At ceaser

    I like your image buttons. They do give visual support that this is a cad like program. In order to get the program to fire up I copied your zoomall jpg to create zoomin, zoomout and zoombox so the program would fire. I haven't tried to look thru it to see what works.

    Thanks again for the support and help you both have given.

    :) Denny :)
    Last edited: May 28, 2008
  10. klaus

    klaus Expert Licensed User

    In my mind there would be 3 files.

    - An *.ini, init file saving the general parameters of the program, independant of the drawing data.
    - Do you want to be prompted before leaving the program ?
    - Load the last used file at start-up ?
    - Selcted language

    - A *.cfg , configuration file for the general parameters of the drawing (grid size, darwing size etc.) with the last used values. But these parameters must also be saved in the *.dat file.

    - A *.dat or any other extension (*.c2d for example), the data of the geomety, this file must include the congig data used for that particular drawing. But, when beginning a new drawing the user can choose another configuration.

    An example of how I use this is in the Wine Cellar application http://www.basic4ppc.com/forum/share-your-creations/2136-wine-cellar-manager.html,
    where the *.cfg files exist in different languages.
    Wine.ini init file
    WineE.cfg english config file
    WineF.cfg french config file
    *.vin data files.

    All these files are simple text files.

    That's, for me, the simple way to do it.

    I hope that in a few days I will have something to show.
    At the moment I am still defining the user interface and the data structure.

    Best regards.
  11. ceaser

    ceaser Active Member Licensed User


    Hi Dennishea

    I have not touched the zoom functions yet, but I should be able to come up with something by the end of the week. In the meantime I have resolved the scale issue and I am adding all the drawing functions in.

    I am not yet sure about the structure of the file holding the drawing info, but maybe Klaus can help us with it.:sign0085:KLAUS

    At the moment I am following very much the same structure as that of DXF, but I don't think that it is the most efficient.

    I will post it by the end of this week on the forum.

  12. klaus

    klaus Expert Licensed User

    I am looking for the physical units.
    I am used to metric units m, cm, mm

    what units do you use inch, foot ?

    Micheal what do you use in your Land surveying, foot or even mile ?

    My program is still in progress, some of the drawing routies work.
    Now I am looking for configuration, saving and loading.
    And then scaling and zooming.
    The data structure needs still some checks depending on above subjects.

    Just a screenshot to show where I am, as soon as the above subjects work I will post the source.

    Best regards.

    Attached Files:

    • CAD.jpg
      File size:
      21.9 KB
  13. dennishea

    dennishea Active Member Licensed User

    Hi klaus

    Most of what I use is inches or millimeter. I figured when I got the drawing mechanism's working I would work on the conversions for those two. Most of what I would use it for would be up to 6 inches or 152 mm. The main thing is accuracy to 2 decimal places. I looked at your wine cellar program and I think I understand how you lay out ini and cfg files. Your programs are good examples of how to make a good assembled program. In that they are a good reference to follow.

    Best wishes Denny :) :sign0188:
  14. ceaser

    ceaser Active Member Licensed User


    Hi Klaus

    In Land Surveying we use mostly meters and centimeters. I have figured the zoom in and zoom out routines and will be posting my latest effort on the forum this weekend.

    From Darkest Africa! (Eskom has switched our power off again!)
  15. klaus

    klaus Expert Licensed User

    Thank you both,

    In a first step i will include m, cm, mm, inches.

    Micheal, were you laid off ?

    Best Regards.
  16. ceaser

    ceaser Active Member Licensed User


    Hi Klaus

    What do you mean if I was laid off?

  17. klaus

    klaus Expert Licensed User

    I translated the french words chômage technique, what means in an other words temporary unemployement for technical reasons.
    And the translation in my dictinary gave me :
    chômage technique > to be laid off ?

    Best regards.
  18. ceaser

    ceaser Active Member Licensed User


    Hi Klaus

    Thanks for the concern:) But no I am not laid off!! I have so much work, it is coming out of my ears! At the moment I am busy with a big surveying project in the DRC(Congo).

    How's the CAD program coming on?

    Something else. I will not have enough time to convert everything in NSBasic over to B4PPC before the end of June, but seeing that NSBasic also compiles to an "exe" file, surely I can mix B4PPC and NSBasic using the shell function? Or Not??

  19. bdiscount

    bdiscount Active Member Licensed User

    When did NSbasic compile to an exe. I have 7.0 its just as bad as 5.0
  20. klaus

    klaus Expert Licensed User

    Hi ceasar and dennishea,

    You will find in the attachment a first sample of my CAD program.
    Some functions work but of course not all yet.
    The Grid , Magnet, Scaling are not yet implemented. Some drawing functions neither.
    You can only draw straight Lines, Rectangles, Circles, Ellipses and Polygones.
    You save and recall a data file. The config is not yet saved.
    When the cursor is selected, you can select a point and modify it's coordinates and confirm.

    I don't want do give too many explanations now beacause there will for shure be a lot of modifications. I send it mainly for the data structure.

    The next 4 days I will be abroad and probably will not have the opportunity to look at the forum. I will answer your question when I am back.

    Best regards.

    Attached Files:

    Last edited: Jun 6, 2008
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice