Author Topic: Strangeness in DCL Slider  (Read 1150 times)

0 Members and 1 Guest are viewing this topic.

Giuseppe Beatrice

  • Newt
  • Posts: 43
Strangeness in DCL Slider
« on: May 09, 2016, 04:49:57 AM »
Hello guys. I'm trying to build a dialog box with a slider, the number of which is variable; I enclose the result of my efforts hoping it will be useful to someone.
There is still something that I can not explain.
1) I think the statement in line 56 is wrong, and that the correct one is in the line 57, but it happens exactly the opposite, and I can not explain such behavior!  :opps:
2) If I substitute the block 55-67 with the block 42-54 (that I thinked was correct), the function doesn't work!!  :sick:
3) Why the function runs correctly, even without the instruction in line 68, that close the DCL?  :yelling:
Can anyone suggest to me why "action_tile" doesn't work as I think?
Code - Auto/Visual Lisp: [Select]
  1. (defun SLIDER-DCL  (Title$ valin@ sld@@ nomsl@ dir_slider$ / cnt1# cnt2# keybsl$ keypar@ keypar@@ varsl@ keysl@ keysl@@ ptxt@ slin@ fin@  Return#)
  2.   ;;----------------------------------------------------------------------------------------------------------------------------
  3.   (defun ADEG_VALORI-VARIABILI  (in@ ng@ / ng# fin@)
  4.     (setq ng# (length ng@))
  5.     (setq fin@ (LM:FLATTEN (mapcar '(lambda (x / tmp@) (repeat ng# (setq tmp@ (append tmp@ (list x))))) in@))));_ fine defun
  6.   ;;------------------------------------------------
  7.   (defun LM:FLATTEN  (l)
  8.     (if (atom l)
  9.       (list l)
  10.       (append (LM:flatten (car l))
  11.               (if (cdr l)
  12.                 (LM:flatten (cdr l))))))
  13.   ;;------------------------------------------------
  14.   (defun SET_PARAGR (kpar$ ptxt$ val$)
  15.     (set_tile kpar$ (strcat ptxt$ ": " val$ "%" )));_ fine defun
  16.   ;;----------------------------------------------------------------------------------------------------------------------------
  17.   (setq cnt1# 0
  18.         cnt2# 0)
  19.   (setq keybsl$ (strcat "Slider" dir_slider$)) ;_ nome base chiave variabili slider (per distinguere se verticale o orizzontale)
  20.   (mapcar '(lambda (sl@ /)
  21.              (setq cnt1# (1+ cnt1#))
  22.              (mapcar '(lambda (nomsl$)
  23.                         (setq cnt2# (1+ cnt2#))
  24.                         (setq keysl@ (append keysl@ (list (strcat keybsl$ (itoa cnt2#))))) ;_ chiave tile slider ("SliderV1" "SliderV2" etc.)
  25.                         (setq varsl@ (mapcar '(lambda (nom) (strcat nom "$")) keysl@)) ;_ nomi delle variabili usate per letture e settaggi chiavi slider
  26.                         (setq keypar@ (append keypar@ (list (strcat "txt" (itoa cnt2#)))))) ;_ chiave progressiva tile txt del paragrafo ("txt1" "txt2" etc.)
  27.                      nomsl@))
  28.           sld@@) ;_ costruzione chiavi per slider e testi dei paragrafi
  29.   (setq valin@ (ADEG_VALORI-VARIABILI valin@ nomsl@));_ replicazione valori iniziali di riempimento per adeguarlo al numero di slider
  30.   (repeat (length sld@@) (setq ptxt@ (append ptxt@ nomsl@)));_ lista dei prefissi di testo da anteporre al riempimento (IS o LF) ripetuta per il numero di slider
  31.   (mapcar '(lambda (varsl$ in$) (set (read varsl$) in$)) varsl@ valin@);_ settaggio variabili slider ai valori iniziali
  32.   (setq fname (vl-filename-mktemp "dcl.dcl"))  
  33.   (CR_DLG_SLIDER fname sld@@ keypar@ keysl@ "" )
  34.   (setq dcl_id (load_dialog fname)) ;_ caricamento DCL
  35.   (if (not (new_dialog "temp" dcl_id)) ;_ inizio dialogo
  36.     (exit))                             ; Set Dialog Initial Settings
  37. ;;;------Settaggi iniziali DCL
  38.   (set_tile "Title" Title$) ;_ titolo dcl scritto settando sempre la chiave della finestra di dialogo che si chiama sempre "Title"
  39. ;;;  (mapcar '(lambda (ksl$ sl$ /) (set_tile ksl$ sl$)) keysl@ slin@) ;_ settaggio di ciascun slider al valore iniziale
  40. ;;;  (mapcar '(lambda (ptxt$ kpar$ txt$ /) (set_tile kpar$ (strcat ptxt$ ":" txt$ "%"))) ptxt@ keypar@ slin@) ;_ settaggio di ciascun paragrafo al valore della slider
  41.   ;;------Azioni
  42. ;;;  (mapcar '(lambda (ksl$ varsl$ kpar$ ptxt$ / slset$ par$ parset$ aux$)           
  43. ;;;          
  44. ;;;          (setq par$ (strcat ptxt$ ": " (rtos (atof (eval (read varsl$))) 2 0) "%"))      
  45. ;;;          
  46. ;;;          (set_tile kpar$ par$ ) ;_ scrittura testo relativo nel paragrafo)
  47. ;;;          (set_tile ksl$ (strcat (rtos (atof (eval (read varsl$))) 2 0) "%")) ;_ settaggio tile slider al valore rappresentato da varsl$
  48. ;;;          (action_tile ksl$ "(setq aux$ $value)") ;_ il valore della tile slider ksl$ setta la variabile ausiliaria
  49. ;;;          (set (read varsl$) aux$);_ la variabile varsl$ assume il valore della variabile ausiliaria
  50. ;;;          )
  51. ;;;       keysl@
  52. ;;;       varsl@
  53. ;;;       keypar@
  54. ;;;       ptxt@)
  55.   (mapcar '(lambda (ksl$ varsl$ kpar$ ptxt$ / slset$ par$ parset$)           
  56.              (setq slset$ (strcat "(setq " varsl$ " $value)"));_ funzione interpretata correttamente da action_tile???!!!
  57. ;;;          (setq slset$ (strcat "(set (read " varsl$ ") $value)"));_ dà un errore quando letta da action_tile, perché al posto della var. varsl$ viene passato il suo valore???
  58.              (setq par$ (strcat ptxt$ ": " (rtos (atof (eval (read varsl$))) 2 0) "%"))      
  59.              (setq parset$ (strcat "(SET_PARAGR \"" kpar$ "\" \"" ptxt$ "\" $value)"))
  60.              (set_tile kpar$ par$ ) ;_ scrittura testo relativo nel paragrafo)
  61.              (set_tile ksl$ (strcat (rtos (atof (eval (read varsl$))) 2 0) "%")) ;_ settaggio tile slider al valore rappresentato da varsl$
  62.              (action_tile ksl$ (strcat slset$ parset$)) ;_ il valore della tile slider ksl$ lancia le istruzioni a e b
  63.              )
  64.           keysl@
  65.           varsl@
  66.           keypar@
  67.           ptxt@)
  68. ;;;  (action_tile "accept" "(done_dialog 1)")
  69.   (setq Return# (start_dialog)) ;_ var. Return# restituisce il valore di done_dialog (in questo caso dovrebbe essere solo e sempre 1, visto che c'è solo tasto ok!)
  70.   (unload_dialog dcl_id) ;_ scarico programma con il valore di done_dialog
  71.   (vl-file-delete fname) ;_ eliminazione file temporaneo DCL
  72.   (setq fin@ (mapcar '(lambda (varsl$) (atof (eval (read varsl$)))) varsl@))
  73.   (mapcar '(lambda (var) (set (read var) nil)) varsl@)
  74.   );_ fine defun
  75.  
  76. (defun CR_DLG_SLIDER  (fname cvd@@ keypar@ keysl@ subtitle$ / keypar@@ keysl@@ dlg@ ckey# fn)
  77.   ;;--------------------------------------------------------------------------------------------------------------------------------------
  78.   (defun GROUPBYNUM  (lst n / r)
  79.     (if lst
  80.       (cons (reverse (repeat n
  81.                        (setq r   (cons (car lst) r)
  82.                              lst (cdr lst))
  83.                        r))
  84.             (GROUPBYNUM lst n))))
  85.   ;;-------------------------------------
  86.   (defun DCL_STARTDLG  (width# / width$)
  87.     (if width# ;_ se la larghezza effettiva totale della finestra di dialogo è passata da funzione chiamante...
  88.       (setq width$ (strcat "width= " (itoa width#) " ;")) ;_ ... larghezza effettiva passata da funzione chiamante
  89.       (setq width$ "width= 40 ;")) ;_ oppure
  90.     (list (strcat "temp : dialog {key = \"Title\";  label = \"\"; " width$)))
  91.   ;;-------------------------------------
  92.   (defun DCL_SLIDER  (keysl$ slmin# slmax# / keysl$)
  93.     (cond ((wcmatch keysl$ "*H*") (setq layout$ "layout = horizontal"))
  94.           ((wcmatch keysl$ "*V*") (setq layout$ "layout = vertical")))
  95.     (list (strcat ": slider {"
  96.                   layout$
  97.                   "; key = \""
  98.                   keysl$
  99.                   "\"; min_value = "
  100.                   (itoa slmin#)
  101.                   "; max_value = "
  102.                   (itoa slmax#)
  103.                   "; small_increment = "
  104.                   (itoa (/ (- slmax# slmin#) 10))
  105.                   "; big_increment = "
  106.                   (itoa (/ (- slmax# slmin#) 4))
  107.                   ";
  108.  height = 8.43;  fixed_height = true;  is_tab_stop = false;}")))
  109.   ;;-------------------------------------
  110.   (defun DCL_PARGRPH_ANON  (str@ key@ / maxstr$ startpar$ fin@ txt@)
  111.     (setq maxstr$ (itoa (apply 'max (mapcar 'strlen str@)))) ;_ lunghezza substringa massima della lista
  112.     (setq startpar$ (list (strcat ": paragraph {width= " maxstr$ " ;"))) ;_ riga iniziale paragrafo (larghezza calcolata pari al numero massimo di caratteri)
  113.     (setq fin@ (append fin@ startpar$)) ;_ prima riga lista finale
  114.     (setq txt@ (mapcar '(lambda (x) (strcat ":text_part {key=\"" x "\"; value=\"\" ; alignment = centered ;}"))
  115.                        key@)) ;_ righe di testo raggruppate in lista
  116.     (setq fin@ (append fin@ txt@)) ;_ aggiunta righe di testo a fin@
  117.     (setq fin@ (append fin@ '("}"))) ;_ aggiunta parentesi graffa chiusura paragrafo
  118.     )
  119.   ;;--------------------------------------------------------------------------------------------------------------------------------------
  120.   (mapcar '(lambda (var val@) (set var (GROUPBYNUM val@ (/ (length keysl@) (length cvd@@)))))
  121.           '(keypar@@ keysl@@)
  122.           (list keypar@ keysl@))
  123.   (setq fn (open fname "w"))
  124.   (setq dlg@ (DCL_STARTDLG nil)) ;_ istruzioni iniziali di apertura (var. Title non interessata poiché chiave della DCL è sempre "Title", passata solo var. larghezza a nil)
  125.   (setq dlg@ (append dlg@ '(": column {"))) ;_ apertura colonna generale unica per contenimento di tutte le istruzioni, compreso OK finale
  126.   (setq dlg@ (append dlg@ (list (strcat ": boxed_row { label = \"" subtitle$ "\" ;")))) ;_ apertura riga di inserimento slider e paragrafo, con sottotitolo
  127.   (mapcar '(lambda (cvd@ keypar@ keysl@ / cvd$ tipsld$)
  128.              (setq cvd$    (car cvd@)
  129.                    tipsld$ (cdr cvd@)) ;_ fissiamo il tipo di slider anche se per ora non lo usiamo
  130.              (setq dlg@ (append dlg@ (list (strcat ": boxed_column { label = \"" cvd$ "\" ;")))) ;_ colonna di ogni singola gola con nome tipo cunicolo)
  131.              (setq dlg@ (append dlg@ (list (strcat ": row {")))) ;_ riga delle slider
  132.              (mapcar '(lambda (keysl$)
  133.                         (setq dlg@ (append dlg@ '(": column {"))) ;_ prima riga, con slider
  134.                         (setq dlg@ (append dlg@ (DCL_SLIDER keysl$ 0 100))) ;_ nome chiave (direzione slider "V" o "H" inserita in esso) + valori min. e max slider                    
  135.                         (setq dlg@ (append dlg@ '("}")))) ;_ chiusura colonna singola slider
  136.                      keysl@)
  137.              (setq dlg@ (append dlg@ (list (strcat "}")))) ;_ chiusura riga delle slider
  138.              (setq dlg@ (append dlg@ (list (strcat ": row {")))) ;_ riga del paragrafo
  139.              (mapcar '(lambda (keypar$)
  140.                         (setq dlg@ (append dlg@ '(": column {"))) ;_ prima riga, con slider
  141.                         (setq dlg@ (append dlg@ (DCL_PARGRPH_ANON (list "IS  100%") (list keypar$)))) ;_ istruz. paragrafo con stringa-tipo max e chiave in forma di lista
  142.                         (setq dlg@ (append dlg@ '("}")))) ;_ chiusura colonna singola slide
  143.                      keypar@)
  144.              (setq dlg@ (append dlg@ (list (strcat "}")))) ;_ chiusura riga del paragrafo
  145.              (setq dlg@ (append dlg@ '("}")))) ;_ chiusura colonna cunicolo
  146.           cvd@@
  147.           keypar@@
  148.           keysl@@)
  149.   (setq dlg@ (append dlg@ '("}"))) ;_ chiusura rigo unico
  150.   (setq dlg@ (append dlg@ '("spacer; ok_only;"))) ;_ inserimento tasto OK
  151.   (setq dlg@ (append dlg@ '("}"))) ;_ chiusura colonna generale
  152.   (setq dlg@ (append dlg@ '("}"))) ;_ parentesi graffa chiusura dialogo
  153.   (mapcar '(lambda (istr$) (write-line istr$ fn)) dlg@) ;_ scrittura file con tutte le istruzioni
  154.   (close fn));_ fine defun DCL_STARTDLG
  155.  
  156.  
  157.  
  158. (setq Title$ "COEFF. RIEMPIM. MAX PROGETTO")
  159. (setq sld@@ (mapcar 'cons
  160.                    (list "CUNICOLI" "TUBI & CORR." "CUN. ESISTENTI" "FUNI" "CUN. OPERE CIV.")
  161.                    (list "true" "true" "false" "false" "false")))
  162. (setq crin@ (mapcar 'itoa '(20 80 100 100 100)))
  163. (setq nomsl@ '("IS" "LF"))
  164.  
  165. (setq res@ (SLIDER-DCL Title$ crin@ sld@@ nomsl@ "V" ))
  166. [/code
« Last Edit: May 09, 2016, 05:20:43 AM by Giuseppe Beatrice »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Strangeness in DCL Slider
« Reply #1 on: May 09, 2016, 05:53:30 AM »
Ad #3:
You may not know this but you can also specify actions in the DCL file. The default ok_only tile already has an action attached in this manner.

Giuseppe Beatrice

  • Newt
  • Posts: 43
Re: Strangeness in DCL Slider
« Reply #2 on: May 09, 2016, 10:11:56 AM »
My best thanks for the clarification.
I hope the other two questions find quick responses too.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Strangeness in DCL Slider
« Reply #3 on: May 10, 2016, 06:03:07 AM »
Ad #1:
Maybe this will help you understand:
Code - Auto/Visual Lisp: [Select]
  1. (setq myVar "myInt")
  2.  
  3. (strcat "(setq " myVar " 1)")  => "(setq myInt 1)"
  4. (setq myInt 1)                 => 1
  5.  
  6. (strcat "(set (read " myVar ") 1)") => "(set (read myInt) 1)"
  7. (set (read myInt) 1)                => ; error : expected <STRING> at [READ]
  8.  
  9. (strcat "(set (read \"" myVar "\") 1)") => "(set (read \"myInt\") 1)"
  10. (set (read "myInt") 1)                  => 1

Giuseppe Beatrice

  • Newt
  • Posts: 43
Re: Strangeness in DCL Slider
« Reply #4 on: May 10, 2016, 09:52:02 AM »
Many thanks Roy, you're the best: fast and clear! :yes: