;WINDE.LSP and WINDP.LSP                       Version 1.0
;
;   Written by:  Gregory A. Green              Copywrite 1990
;                LaserWorks Consultants
;
;                209 Plaza Place
;                N. Augusta, SC  29841
;
;   These programs are being distributed as Shareware -- you may use these
;   programs for a trial period not to exceed 20 days.  Beyond that time you
;   are required to register and remit $15 for continued use of these programs.
;   Send check payable to Gregory Green to the address given above.
;
;   The author assumes no responsibility for the use of these programs -- 
;   neither loss to drawings, nor to hardware. (Usual Non-Liability statement!)
;   The responsibility for the use of these programs resides solely with the
;   owner of the hardware.
;
;  ----------------------------------------------------------------------------
;
;   Routine for drawing elevation views of windows of the Andersen double-hung
;   window.  Allows user to select number of panes.
;
(defun C:WINDE ( / U_OSMODE U_BLIPMODE WFL1 WFL2 WFL3 WFL4 WFL5 WFL6
                   WFILLC WFIURC WFILRC WFIULC WFOULC WFOURC WFOLRC UINPUT
                   OFFSETANGLE WEOFFSET UOFFSETPT WM1 WM2 G1 G2 G3 G4 PANEROW
                   W1 W2 W3 W4 W5 W6 W7 W8 PANES PANEDIST PANEDRAW PANEHEIGHT)
  (setvar "cmdecho" 0)
  (setq U_OSMODE (getvar "osmode")
        U_BLIPMODE (getvar "blipmode")
        U_LTSCALE (getvar "ltscale")
        U_CELTYPE (getvar "celtype")
        U_CLAYER (getvar "clayer")
        U_MENUNAME (getvar "menuname"))
;
; Set program defaults
;
  (setvar "LTSCALE" 10.0)
  (if (not NPANEROWS)                ; Set default window pane rows
    (setq NPANEROWS 2)
  )
  (if (not NPANES)                   ; Set default window panes per row
    (setq NPANES 3)
  )
  (if (not WEWIDTH)                  ; Set default window width
    (setq WEWIDTH 36)
  )
  (if (not WEHEIGHT)                 ; Set default window height
    (setq WEHEIGHT 60)
  )
  (if (not WSELTYPE)                 ; Set default window dimensions select mode
    (setq WSELTYPE "D")
  )
  (setq WEOFFSET 0.0)                ; Set offset distance default to zero
; 
; Get information of window location and size from user
;
  (setvar "blipmode" 0)
  (setq USELTYPE (strcase (getstring (strcat "\nSelect window dimensions by: Box/Distance <" WSELTYPE ">"))))
  (if USELTYPE
    (setq WSELTYPE USELTYPE)
  )
  (command "MENU" "windows")
  (menucmd "S=CLR")
  (menucmd "S=OSNAPB")
  (if (= WSELTYPE "B")
    (progn
      (setq WFILLC (getpoint "\nSelect the window-frame inside lower-left corner:"))
      (setq WFIURC (getcorner WFILLC "\nSelect the window-frame inside upper-right corner:"))
      (setq UOFFSETPT (getpoint WFILLC "\nPick the window-frame offset distance <0.0>:"))
      (if uoffsetpt
        (progn
          (setq WEOFFSET (distance WFILLC UOFFSETPT))
          (setq OFFSETANGLE (angle WFILLC UOFFSETPT))
          (setq WFILLC (polar WFILLC OFFSETANGLE WEOFFSET))
          (setq WFIURC (polar WFIURC OFFSETANGLE WEOFFSET))
        )
      )
    )
    (progn
      (setq WFILLC (getpoint "\nSelect the window-frame inside lower-left corner:"))
      (menucmd "S=CLR")
      (menucmd "S=CALCNUM")
      (setq UEWIDTH (getdist wfillc (strcat "\nPick the window-frame width <" (rtos WEWIDTH 4 2) ">:")))
      (if UEWIDTH
        (setq WEWIDTH UEWIDTH)
      )
      (setq UEHEIGHT (getdist WFILLC (strcat "\nPick the window-frame height <" (rtos WEHEIGHT 4 2) ">:")))
      (if UEHEIGHT
        (setq WEHEIGHT UEHEIGHT)
      )
      (menucmd "S=CLR")
      (setq UOFFSETPT (getpoint WFILLC "\nPick the window-frame offset distance <0.0>:"))
      (if UOFFSETPT
        (setq WFILLC (polar WFILLC (angle WFILLC UOFFSETPT) (distance WFILLC UOFFSETPT)))
      )
      (setq WFIURC (list (+ (car WFILLC) WEWIDTH) (+ (cadr WFILLC) WEHEIGHT) (caddr WFILLC)))
    )
  )
  (setq UINPUT nil)
  (while (not UINPUT)
    (setq UINPUT (strcase (getstring "\nDraw window panes? <Y>")))
    (cond
      ((= UINPUT "Y")
        (setq DRAWPANE "Y")
        (setq UINPUT T)
      )
      ((= UINPUT "N")
        (setq DRAWPANE "N")
        (setq UINPUT T)
      )
      ((= UINPUT "")
        (setq DRAWPANE "Y")
        (setq UINPUT T)
      )
      (T
        (princ "\n\nImproper entry, Please enter again...")
        (setq UINPUT nil)
      )
    )
  )
  (if (= DRAWPANE "Y")
    (progn
      (setq UPANES (getint (strcat "\nEnter the number of pane-rows per section of the window <" (rtos NPANEROWS 2 0) ">:")))
      (if UPANES
        (setq NPANEROWS UPANES)
      )
      (setq UPANES (getint (strcat "\nEnter the number of panes per row of the window <" (rtos NPANES 2 0) ">:")))
      (if UPANES
        (setq NPANES UPANES)
      )
      (terpri)
      (terpri)
    )
  )
;
; Set the window frame points (WFI-window frame inside)
;                             (WFO-window frame outside)
;                             (WFL-window frame ledge)
;
  (setq WFILRC (list (car WFIURC) (cadr WFILLC) (caddr WFILLC))
        WFIULC (list (car WFILLC) (cadr WFIURC) (caddr WFIURC))
        WFOLLC (polar WFILLC 3.9270 2.1213)
        WFOULC (polar WFIULC 2.3562 2.1213)
        WFOURC (polar WFIURC 0.7854 2.1213)
        WFOLRC (polar WFILRC 5.4978 2.1213)
        WFL1 (polar WFILLC 3.1416 2.0)
        WFL2 (polar WFILLC 3.1416 3.5)
        WFL3 (polar WFL2 4.7124 3.5)
        WFL6 (polar WFILRC 0.0 2.0)
        WFL5 (polar WFILRC 0.0 3.5)
        WFL4 (polar WFL5 4.7124 3.5))
;
; Set the window points
;
  (setq WHALF (/ (distance WFILLC WFIULC) 2.0)
        WM1 (polar WFILLC 1.5708 WHALF)
        WM2 (polar WFILRC 1.5708 WHALF)
        W1 (polar WFIULC 5.4978 2.82842)
        W4 (polar WFIURC 3.9270 2.82842)
        W6 (polar WFILLC 0.7854 2.82842)
        W7 (polar WFILRC 2.3562 2.82842)
        W2 (polar WM1 0.7854 2.82842)
        W3 (polar WM2 2.3562 2.82842)
        W5 (polar WM1 0.0 2.0)
        W8 (polar WM2 3.1416 2.0))
;
; Draw the window frame and ledge
;
  (command "LAYER" "s" "symbols" "")
  (command "LINE" WFILLC WFILRC WFIURC WFIULC "c")
  (command "LINE" WFOLLC WFOLRC WFOURC WFOULC "c")
  (command "LINE" WFL1 WFL2 WFL3 WFL4 WFL5 WFL6 "")
;
; Draw the window glass frame
;
  (command "LINE" WM1 WM2 "")
  (command "LINE" W1 W2 W3 W4 "c")
  (command "LINE" W5 W6 W7 W8 "")
;
; Draw the upper window panes
;
  (if (= DRAWPANE "Y")
    (progn
      (command "LINETYPE" "s" "dashed" "")
      (setq PANEDIST (/ (distance W1 W4) NPANES)
            PANEDRAW (- NPANES 1)
            PANEROW (- NPANEROWS 1)
            G1 W1
            G2 W2)
      (repeat PANEDRAW
        (setq G3 (polar G1 0.0 PANEDIST)
              G4 (polar G2 0.0 PANEDIST))
        (command "LINE" G3 G4 "")
        (setq G1 G3
              G2 G4)
      )
      (setq PANEHEIGHT (/ (distance W1 W2) (float NPANEROWS))
            G3 W2
            G4 W3)
      (repeat panerow
        (setq G1 (polar G3 1.5708 PANEHEIGHT)
              G2 (polar G4 1.5708 PANEHEIGHT))
        (command "LINE" G1 G2 "")
        (setq G3 G1
              G4 G2)
      )
;
; Draw the lower window panes
;
      (setq G1 W5
            G2 W6)
      (repeat PANEDRAW
        (setq G3 (polar G1 0.0 PANEDIST)
              G4 (polar G2 0.0 PANEDIST))
        (command "LINE" G3 G4 "")
        (setq G1 G3
              G2 G4)
      )
      (setq PANEHEIGHT (/ (distance W5 W6) (float NPANEROWS))
            G3 W6
            G4 W7)
      (repeat panerow
        (setq G1 (polar G3 1.5708 PANEHEIGHT)
              G2 (polar G4 1.5708 PANEHEIGHT))
        (command "LINE" G1 G2 "")
        (setq G3 G1
              G4 G2)
      )
      (command "LINETYPE" "s" U_CELTYPE "")
      (setvar "ltscale" U_LTSCALE)
    )
  )
;
; Reset layer and reset user system variables
;
  (setvar "osmode" U_OSMODE)
  (setvar "blipmode" U_BLIPMODE)
  (command "LAYER" "s" U_CLAYER "")
  (command "MENU" U_MENUNAME)
  (princ)
)
;
;  ----------------------------------------------------------------------------
;
;   Routine for drawing plan views of windows.  Will break the wall as specified
;   by the user; requires minimum responses and can insert the window at any
;   wall angle.  See NOTES below concerning layer names for wall and window
;   symbols.
;
(defun C:WINDP ( / U_OSMODE U_BLIPMODE WANGLE1 WANGLE2 WANGLEA WANGLEB WTHK WOFFSET
                    HWTHK W1 W2 W3 W4 G1 G2 L1 L2 L3 L4 CPT OCPT UWIDTH TPI FPI)
  (setvar "cmdecho" 0)
  (setq U_OSMODE (getvar "osmode")
        U_BLIPMODE (getvar "blipmode")
        U_CLAYER (getvar "clayer")
        U_MENUNAME (getvar "menuname"))
;
; Set program defaults
;
  (if (not WWIDTH)                     ; Set default window half-width
    (setq WWIDTH 24)
  )
  (if (not BRKWALL)                    ; Set default for wall opening
    (setq BRKWALL "Y")
  )
; 
; Get information of window location and size from user
;
  (command "MENU" "windows")
  (menucmd "S=OSNAPB")
  (setq CPT (getpoint "\nSelect on the inside wall surface, the center point of the window:"))
  (setvar "osmode" 128)
  (setq OCPT (getpoint CPT "\nSelect a point on the outside wall surface near window center point:"))
  (setvar "blipmode" 0)
  (setvar "osmode" 0)
  (setq UOFFSETPT (getpoint CPT (strcat "\nPick the window center-point offset distance: <0.0>")))
  (if UOFFSETPT
    (progn
      (setq WOFFSET (distance CPT UOFFSETPT))
      (setq WANGLE2 (angle CPT UOFFSETPT))
      (setq CPT (polar CPT WANGLE2 WOFFSET))
      (setq OCPT (polar OCPT WANGLE2 WOFFSET))
    )
  )
  (setq UWIDTH nil)
  (setq UWIDTH (getdist CPT (strcat "\nPoint to or enter the half-width of the window: <" (rtos WWIDTH 4 2) ">")))
  (if UWIDTH
    (setq WWIDTH UWIDTH)
  )
  (setvar "osmode" 0)
;
; Determine if wall requires cutting
;
  (setq UINPUT nil)
  (while (not UINPUT)
    (setq UINPUT (strcase (getstring (strcat "\nDoes wall require cutting (y/n)? <" BRKWALL ">"))))
    (cond
      ((= UINPUT "Y")
        (setq BRKWALL UINPUT)
        (setq UINPUT T)
      )
      ((= UINPUT "N")
        (setq BRKWALL UINPUT)
        (setq UINPUT T)
      )
      ((= UINPUT "")
        (setq UINPUT T)
      )
      (T 
        (progn
          (princ "\n\nImproper entry, Please enter again...")
          (setq UINPUT nil)
        )
      )
    )
  )
;
; Determine the wall angles, wall points of the window opening, the ledge
; points and the glass points
;
  (setq WANGLE1 (angle CPT OCPT)
        WANGLEA (- WANGLE1 (/ pi 2))
        WANGLEB (+ WANGLE1 (/ pi 2))
        WTHK (distance CPT OCPT)
        HWTHK (/ WTHK 2.0))
  (if (< WANGLEA 0)
    (setq WANGLEA (+ WANGLEA (* 2 pi)))
  )
  (if (> WANGLEB (* 2 pi))
    (setq WANGLEB (- WANGLEA (* 2 pi)))
  )
  (setq W1 (polar CPT WANGLEA WWIDTH)
        W2 (polar CPT WANGLEB WWIDTH)
        W3 (polar OCPT WANGLEA WWIDTH)
        W4 (polar OCPT WANGLEB WWIDTH)
        L1 (polar OCPT WANGLEA (+ WWIDTH 1.5))
        L4 (polar OCPT WANGLEB (+ WWIDTH 1.5))
        L2 (polar L1 WANGLE1 1.5)
        L3 (polar L4 WANGLE1 1.5)
        G1 (polar W1 WANGLE1 HWTHK)
        G2 (polar W2 WANGLE1 HWTHK))
;
; Determine if wall opening is required (NOTE: Set the layer to another layer if
; the wall is located on another layer as specified by user)
;
  (if (= BRKWALL "Y")
    (progn
      (command "LAYER" "s" "0" "")
      (command "BREAK" W1 W2)
      (command "BREAK" W3 W4)
      (command "LINE" W1 W3 "")
      (command "LINE" W2 W4 "")
      (command "LAYER" "s" U_CLAYER "")
    )
  )
;
; Draw the window glass and ledge (NOTE: This assumes the layer "symbols" is
; created in the drawing -- if not either change the layer name to one you
; desire or create the layer in your drawing).
;
  (command "LAYER" "s" "symbols" "")
  (command "LINE" G1 G2 "")
  (command "LINE" W3 W4 "")
  (command "LINE" L1 L2 L3 L4 "")
;
; Reset system variables and menu
;
  (setvar "osmode" U_OSMODE)
  (setvar "blipmode" U_BLIPMODE)
  (command "LAYER" "s" U_CLAYER "")
  (command "MENU" U_MENUNAME)
  (princ)
)
