path.lsp

ddpath.dcl
gp_box1 : dialog {
   label = "path";
   : boxed_radio_row {
      label = "Forma delle piastrelle";
      : radio_button {
         label = "Poligono";
         key = "gp_poly";
      }
      : radio_button {
         label = "Cerchio";
         key = "gp_circ";
         value = "1";
      }
   }
   : edit_box {
      label = "Raggio della piastrella";
      key = "gp_trad";
      edit_width = 6;
   }
   : edit_box {
      label = "Spaziatura fra le piastrelle";
      key = "gp_spac";
      edit_width = 6;
   }
   : edit_box {
      label = "Numero di lati";
      key = "gp_side";
      edit_width = 4;
   }
   : row {
      : spacer { width = 1; }
      : button {
         label = "OK";
         key = "accept";
         width = 8;
         fixed_width = true;
      }
      : button {
         label = "Annulla";
         is_cancel =true;
         key = "cancel";
         width = 8;
         fixed_width = true;
      }
      : spacer { width = 1; }
   }
}
path.lsp
(defun g2r (a)
 (* pi (/ a 180.0))
)

(defun gpuser ()
 (setq sp (getpoint "\nPunto inizio vialetto: "))
 (setq ep (getpoint "\nPunto fine vialetto: "))
 (setq hwidth (getdist "\nMezza larghezza del vialetto: " sp))
 (setq pangle (angle sp ep))
 (setq plength (distance sp ep))
 (setq width (* 2 hwidth))
 (setq angp90 (+ pangle (g2r 90)))
 (setq angm90 (- pangle (g2r 90)))
)

(defun drawout ()
 (command "_pline"
  (setq p (polar sp angm90 hwidth))
  (setq p (polar p pangle plength))
  (setq p (polar p angp90 width))
  (polar p (+ pangle (g2r 180)) plength) "_close"
 )
)

(defun gp_dialog ()
 (setq tshape "Cerchio")
 (setq trad 0.5)
 (setq tspac 0.1)
 (setq tsides 8)
 (setq dcl_id (load_dialog "ddpath.dcl"))
 (if (not (new_dialog "gp_box1" dcl_id)) (exit))
 (set_tile "gp_trad" "0.5")
 (set_tile "gp_spac" "0.1")
 (mode_tile "gp_side" 1)
 (set_tile "gp_side" "8")
 (action_tile "gp_circ" 
    "(setq tshape \"Cerchio\")(mode_tile \"gp_side\" 1)")
 (action_tile "gp_poly"
    "(setq tshape \"Poligono\")(mode_tile \"gp_side\" 0)")
 (action_tile "cancel" "(done_dialog)(setq gperr \"\")(exit)")
 (action_tile "accept"
    (strcat
      "(progn (setq trad (atof (get_tile \"gp_trad\")))"
      "(setq tspac (atof (get_tile \"gp_spac\")))"
      "(setq tsides (atoi (get_tile \"gp_side\")))"
      " (done_dialog))"
    )
  )
  (start_dialog)
  (unload_dialog dcl_id)
  (if (= tshape "Cerchio")
     (defun gp_tile () (command "_circle" pltile trad))
     (defun gp_tile () (command "_polygon" tsides pltile "" trad))
  )
)

(defun gp_err (msg)
 (setq *error* olderr)
 (if (not gperr)
  (princ (strcat "\nErrore: " msg))
  (princ gperr)
 )
 (if sblip (setvar "blipmode" sblip))
 (if scmde (setvar "cmdecho" scmde))
 (princ)
)

(defun drow (pd offset)
 (setvar "snapang" pangle)
 (setq pfirst (polar sp pangle pd))
 (setq pctile (polar pfirst angp90 offset))
 (setq pltile pctile)
 (while (< (distance pfirst pltile) (- hwidth trad))
  (gp_tile)
  (setq pltile (polar pltile angp90 (+ tspac trad trad)))
 )
 (setq pltile (polar pctile angm90 (+ tspac trad trad)))
 (while (< (distance pfirst pltile) (- hwidth trad))
  (gp_tile)
  (setq pltile (polar pltile angm90 (+ tspac trad trad)))
 )
)

(defun drawtiles ()
 (setq pdist (+ trad tspac))
 (setq off 0.0)
 (while (<= pdist (- plength trad))
  (drow pdist off)
  (setq pdist
   (+ pdist (* (+ tspac trad trad) (sin (g2r 60)))))
  (if (= off 0.0)
   (setq off (* (+ tspac trad trad) (cos (g2r 60))))
   (setq off 0.0)
  )
 )
)

(defun c:path ()
 (setq olderr *error*
   *error* gp_err
   sblip nil
   scmde nil
   gperr nil
 )
 (gpuser)
 (setq sblip (getvar "blipmode"))
 (setq scmde (getvar "cmdecho"))
 (setq sang (getvar "snapang"))
 (setvar "blipmode" 0)
 (setvar "cmdecho" 0)
 (command "osnap" "_non")
 (drawout)
 (gp_dialog)
 (drawtiles)
 (setvar "blipmode" sblip)
 (setvar "cmdecho" scmde)
 (setvar "snapang" sang)
 (setq *error* olderr)
 (princ)
)
;;;eof