Author Topic: DCL radiobutton alignment  (Read 15412 times)

0 Members and 1 Guest are viewing this topic.

Stefan

  • Bull Frog
  • Posts: 255
Re: DCL radiobutton alignment
« Reply #45 on: January 05, 2014, 10:44:12 AM »
Nicely done Stefan  :-)
Thank you Lee

Here is a generic function for a max 10x10 radio cluster, including dcl generator.
Note this is a demo function. The original one contains a test for list's validity and the option to accept argument list as a single dimension list, in which case a single column appears in dialog box.
Returns the label of selected tile.
Code - Auto/Visual Lisp: [Select]
  1. (defun radio_columns (title label l / file dcl i j dcl_id r)
  2.   ;; open dcl file
  3.   (setq file (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".dcl")
  4.         dcl  (open file "w")
  5.   )
  6.   ;; write dialog file
  7.   (write-line (strcat "radiobuttoncol : dialog { label = \"" title "\";") dcl)
  8.   (write-line (strcat ": boxed_row { label = \""
  9.                       label
  10.                       "\"; children_fixed_height = true; children_alignment = \"Top\";")
  11.               dcl)
  12.   (setq i 0)
  13.   (foreach col l
  14.     (setq j 0)
  15.     (write-line (strcat ": radio_column { key = \"" (itoa i) "\";") dcl)
  16.     (foreach row col
  17.       (write-line (strcat ": radio_button { label = \"" row "\"; key = \"" (itoa i) (itoa j) "\";}") dcl)
  18.       (setq j (1+ j))
  19.     )
  20.     (write-line "}" dcl)
  21.     (setq i (1+ i))
  22.   )
  23.   (write-line "}ok_cancel;}" dcl)
  24.   (close dcl)
  25.   ;;check global var *retb* if it's value matching list's dimension
  26.   ;;*retb* is a 2 chars string. First is column number, second is row number, 0-based index
  27.   ;;limits dialog to max 10/10 cols/rows
  28.   (or (and *retb*
  29.            (< (atoi (substr *retb* 1 1)) (length l))
  30.            (< (atoi (substr *retb* 2 1)) (length (nth (atoi (substr *retb* 1 1)) l)))
  31.       )
  32.       (setq *retb* "00")
  33.   )
  34.   ;start dialog
  35.   (if
  36.     (setq dcl_id (load_dialog file))
  37.      (if
  38.        (new_dialog "radiobuttoncol" dcl_id)
  39.         (progn
  40.           (repeat i (action_tile
  41.                       (itoa (setq i (1- i)))
  42.                       "(if (/= *retb* $value) (set_tile *retb* \"0\")) (setq *retb* $value)"
  43.                     )
  44.           )
  45.           (set_tile *retb* "1")
  46.           (setq r (start_dialog))
  47.           (unload_dialog dcl_id)
  48.         )
  49.      )
  50.   )
  51.   (if (findfile file) (vl-file-delete file))
  52.   (if (= r 1) (nth (atoi (substr *retb* 2 1)) (nth (atoi (substr *retb* 1 1)) l)))
  53. )
  54.  
  55.  
  56. (defun c:test ( / l tmp)
  57.   (repeat (1+ (rem (dos_random) 10))
  58.     (setq tmp nil)
  59.     (repeat (1+ (rem (dos_random) 10))
  60.       (setq tmp (cons (strcat (chr (+ 65 (rem (dos_random) 26))) (chr (+ 65 (rem (dos_random) 26)))) tmp))
  61.       )
  62.     (setq l (cons tmp l))
  63.     )
  64.   (radio_columns "Dialog Title" "Box Label" l)
  65.   )  

ymg

  • Swamp Rat
  • Posts: 725
Re: DCL radiobutton alignment
« Reply #46 on: January 05, 2014, 11:50:15 AM »
hmspe,

What tou are doing is defining a function "set_radios" and running it.

Although you are doing the action from the dialog box, it is essentially
the same as what we were doing with clrbut when resetting all buttons.

The way proposed is to use the keys of the radio-columns or radio-rows
and reset only the single tile that is ON in any rows or columns.

Stefan's way is most elegant, because it does away with the function call
and keeps everything in a logical way, where it belongs.

Whereby with the function, you either defined the clusters in the function or
you would need to pass it as a parameter.  This makes for spaghetti code.

It's a nice calculator you have there, although you could have written it
much more concisely. 

Looks like you like to type  :-)

ymg
« Last Edit: January 05, 2014, 12:18:50 PM by ymg »

hmspe

  • Bull Frog
  • Posts: 344
Re: DCL radiobutton alignment
« Reply #47 on: January 05, 2014, 09:30:13 PM »

Looks like you like to type  :-)

Not really.  This code is around 10 years old.  I think I've gotten a bit better at coding since then.  That said, I'm an engineer that occasionally writes code to automate my work, and trying to remember how elegant/compact/fast constructs work when you don't write code regularly is a challenge.  I'm more concerned with being able to maintain my code in the future.  Simple structure may not be as efficient but it is easy to maintain.  In this case the speed of simple code is more than adequate.  At a previous job where I wrote code for testing jet engines for use with 6MHz PC AT computers efficiency came first.  With a 3GHZ+ computer and writing for internal use only I'm only worried about "fast enough".

My intention was to provide a real world example that has been used in production.  The ODCL version is much nicer.

"Science is the belief in the ignorance of experts." - Richard Feynman

TheyCallMeJohn

  • Guest
Re: DCL radiobutton alignment
« Reply #48 on: January 09, 2014, 07:22:37 PM »
Thank you guys so much! I didn't realize this would turn into such a discussion. I would have been back sooner but I had bad case of the flu.

Like Hmspe, I am an engineer that occasionally writes code to remove what I see as inefficiencies. You all are way more experienced than I am so 9/10 of this is way over my head but I shall strive to figure out how to implement it into the code I already have written. The portion I posted is only a small simplified part of my larger program. Due to varying list lengths, I had write a lisp to write lisp and  DCL "On the Fly" (as Kenny with Afralisp put it),

I greatly appreciate all your help.


ymg

  • Swamp Rat
  • Posts: 725
Re: DCL radiobutton alignment
« Reply #49 on: January 10, 2014, 01:27:56 PM »
TheyCallMeJohn,

Was a long discussion, but out of it came Stefan's way which is very nice!!

And I see you sorted your problem.

ymg