;;;     ACAD.MNL (Also duplicated as ACADFULL.MNL for Windows.)
;;;     Copyright (C) 1992, 1993, 1994 by Autodesk, Inc.
;;;
;;;     Permission to use, copy, modify, and distribute this software
;;;     for any purpose and without fee is hereby granted, provided
;;;     that the above copyright notice appears in all copies and 
;;;     that both that copyright notice and the limited warranty and 
;;;     restricted rights notice below appear in all supporting 
;;;     documentation.
;;;
;;;     AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  
;;;     AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF 
;;;     MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
;;;     DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE 
;;;     UNINTERRUPTED OR ERROR FREE.
;;;
;;;     Use, duplication, or disclosure by the U.S. Government is subject to 
;;;     restrictions set forth in FAR 52.227-19 (Commercial Computer 
;;;     Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 
;;;     (Rights in Technical Data and Computer Software), as applicable. 
;;;
;;;     AutoLISP routines used by the AutoCAD Release 13 Standard Menu.
;;;
;;;     This file is loaded automatically following the menu ACAD.  

(princ ;|ACAD_MNL_1|;"\nAutoCAD Release 13 menu utilities ")


;;;=== Icon Menu Functions ===

;;;  View -> Layout -> Tiled Viewports...

(defun ai_tiledvp_chk (new)
  (setq m:err *error* *error* *merrmsg*)
  (if (= (getvar "TILEMODE") 0)
    (progn
      (princ ;|ACAD_MNL_2|;"\n** Command not allowed unless TILEMODE is set to 1 (On) **")
      (princ)
    )
    (progn
      (if new
        (menucmd "I=ACAD.IMAGE_VPORTI")
        (menucmd "I=IMAGE_VPORTI")
      )
      (menucmd "I=*")
    )
  )
  (setq *error* m:err m:err nil)
  (princ)
)

(defun ai_tiledvp (num ori / ai_tiles_g ai_tiles_cmde)
  (setq m:err *error* *error* *merrmsg*
        ai_tiles_cmde (getvar "CMDECHO")
        ai_tiles_g (getvar "GRIDMODE")
  )
  (setvar "CMDECHO" 0)
  (setvar "GRIDMODE" 0)
  (cond ((= num 1)
         (command "_.VPORTS" "_SI")
         (setvar "GRIDMODE" ai_tiles_g)
        )
        ((< num 4)
         (command "_.VPORTS" "_SI")
         (command "_.VPORTS" num ori)
         (setvar "GRIDMODE" ai_tiles_g)
        )
        ((= ori nil)
         (command "_.VPORTS" "_SI")
         (command "_.VPORTS" num)
         (setvar "GRIDMODE" ai_tiles_g)
        )
        ((= ori ;|ACAD_MNL_3|;"_L")
         (command "_.UNDO" "_M")
         (command "_.VPORTS" "_SI")
         (command "_.VPORTS" "2" "")
         (setvar "CVPORT" (car (cadr (vports))))
         (command "_.VPORTS" "2" "")
         (command "_.VPORTS" "_J" "" (car (cadr (vports))))
         (setvar "CVPORT" (car (cadr (vports))))
         (command "_.VPORTS" "3" "_H")
         (setvar "GRIDMODE" ai_tiles_g)
         (setvar "CVPORT" (car (cadddr (vports))))
         (setvar "GRIDMODE" ai_tiles_g)
         (setvar "CVPORT" (car (cadddr (vports))))
         (setvar "GRIDMODE" ai_tiles_g)
         (setvar "CVPORT" (car (cadddr (vports))))
         (setvar "GRIDMODE" ai_tiles_g)
         (command "_.UNDO" "_E")
        )
        (T
         (command "_.UNDO" "_M")
         (command "_.VPORTS" "_SI")
         (command "_.VPORTS" "2" "")
         (command "_.VPORTS" "2" "")
         (setvar "CVPORT" (car (caddr (vports))))
         (command "_.VPORTS" "_J" "" (car (caddr (vports))))
         (setvar "CVPORT" (car (cadr (vports))))
         (command "_.VPORTS" "3" "_H")
         (setvar "GRIDMODE" ai_tiles_g)
         (setvar "CVPORT" (car (cadddr (vports))))
         (setvar "GRIDMODE" ai_tiles_g)
         (setvar "CVPORT" (car (cadddr (vports))))
         (setvar "GRIDMODE" ai_tiles_g)
         (setvar "CVPORT" (car (cadddr (vports))))
         (setvar "GRIDMODE" ai_tiles_g)
         (command "_.UNDO" "_E")
        )
  )
  (setq *error* m:err m:err nil)
  (setvar "CMDECHO" ai_tiles_cmde)
  (princ)
)

;;;=== Tablet Swap Functions ===

(defun ai_tab1 ()
  (setq T_Menu (read (ai_popmenucfg "T_Menu")))
  (if (= (logand 1 T_Menu) 1)
    (progn
      (ai_putmenucfg "T_Menu" (itoa (setq T_Menu (- T_Menu 1))))
      (if (< (getvar "EXPERT") 4)
        (princ ;|ACAD_MNL_4|;"\nAlternate tablet area 1 unloaded.")
      )
      (menucmd "T1=TABLET1")
      (if (< (getvar "EXPERT") 1)
        (princ ;|ACAD_MNL_5|;"\nThis area is for your personal applications and menu items.\n")
      )
    )
    (progn 
      (ai_putmenucfg "T_Menu" (itoa (setq T_Menu (+ T_Menu 1))))
      (if (< (getvar "EXPERT") 4)
        (princ ;|ACAD_MNL_6|;"\nAlternate tablet area 1 loaded.  ")
      )
      (menucmd "T1=TABLET1ALT")
      (if (< (getvar "EXPERT") 1)
        (princ ;|ACAD_MNL_7|;"\nThis area is for your personal applications and menu items.\n")
      )
    )
  )
  (princ)
)

(defun ai_tab2 ()
  (setq T_Menu (read (ai_popmenucfg "T_Menu")))
  (if (= (logand 2 T_Menu) 2)
    (progn
      (ai_putmenucfg "T_Menu" (itoa (setq T_Menu (- T_Menu 2))))
      (if (< (getvar "EXPERT") 4)
        (princ ;|ACAD_MNL_8|;"\nAlternate tablet area 2 unloaded.  ")
      )
      (menucmd "T2=TABLET2")
      (if old_wv (setvar "WORLDVIEW" old_wv))
      (if (< (getvar "EXPERT") 1)
        (princ ;|ACAD_MNL_9|;"\nCommands operate transparently: VPOINT and DVIEW in Worldview mode.\n")
      )
    )
    (progn
      (ai_putmenucfg "T_Menu" (itoa (setq T_Menu (+ T_Menu 2))))
      (setq old_wv (getvar "WORLDVIEW"))
      (setvar "WORLDVIEW" 0)
      (if (< (getvar "EXPERT") 4)
        (princ ;|ACAD_MNL_10|;"\nAlternate tablet area 2 loaded.  ")
      )
      (menucmd "T2=TABLET2ALT")
      (if (< (getvar "EXPERT") 1)
        (princ ;|ACAD_MNL_11|;"\nZoom and other commands issue CTRL-C's: VPOINT and DVIEW in current UCS mode.\n")
      )
    )
  )
  (princ)
)

(defun ai_tab3 ()
  (setq T_Menu (read (ai_popmenucfg "T_Menu")))
  (if (= (logand 4 T_Menu) 4)
    (progn
      (ai_putmenucfg "T_Menu" (itoa (setq T_Menu (- T_Menu 4))))
      (if (< (getvar "EXPERT") 4)
        (princ ;|ACAD_MNL_12|;"\nAlternate tablet area 3 unloaded.  ")
      )
      (menucmd "T3=TABLET3")
      (if (< (getvar "EXPERT") 1)
        (princ ;|ACAD_MNL_13|;"\nSelect Imperial units from the Numeric menu.\n")
      )
    )
    (progn
      (ai_putmenucfg "T_Menu" (itoa (setq T_Menu (+ T_Menu 4))))
      (if (< (getvar "EXPERT") 4)
        (princ ;|ACAD_MNL_14|;"\nAlternate tablet area 3 loaded.  ")
      )
      (menucmd "T3=TABLET3ALT")
      (if (< (getvar "EXPERT") 1)
        (princ ;|ACAD_MNL_15|;"\nSelect Metric units from the Numeric menu.\n")
      )
    )
  )
  (princ)
)

(defun ai_tab4 ()
  (setq T_Menu (read (ai_popmenucfg "T_Menu")))
  (if (= (logand 8 T_Menu) 8)
    (progn
      (ai_putmenucfg "T_Menu" (itoa (setq T_Menu (- T_Menu 8))))
      (if (< (getvar "EXPERT") 4)
        (princ ;|ACAD_MNL_16|;"\nAlternate tablet area 4 unloaded.  ")
      )
      (menucmd "T4=TABLET4")
      (if (< (getvar "EXPERT") 1)
        (princ ;|ACAD_MNL_17|;"\nObject snap modes issue overrides: commands do NOT repeat.\n")
      )
    )
    (progn
      (ai_putmenucfg "T_Menu" (itoa (setq T_Menu (+ T_Menu 8))))
      (if (< (getvar "EXPERT") 4)
        (princ ;|ACAD_MNL_18|;"\nAlternate tablet area 4 loaded.  ")
      )
      (menucmd "T4=TABLET4ALT")
      (if (< (getvar "EXPERT") 1)
        (princ ;|ACAD_MNL_19|;"\nObject snap modes issue running modes: commands repeat.\n")
      )
    )
  )
  (princ)
)

;;;=== General Utility Functions ===

;;; ai_popmenucfg -- retrieve parameter from cfg settings
;;; <param> is a string specifiying the parameter
 
(defun ai_popmenucfg (param)
  (set (read param) (getcfg (strcat "CfgData/Menu/" param)))
)

;;; ai_putmenucfg -- store parameter in cfg settings
;;; <param> is a string specifiying the parameter
;;; <cfgval> is the value for that parameter

(defun ai_putmenucfg (param cfgval)
  (setcfg (strcat "CfgData/Menu/" param) cfgval)
)

(defun *merr* (msg)
  (setq *error* m:err m:err nil)
  (princ)
)

(defun *merrmsg* (msg)
  (princ msg)
  (setq *error* m:err m:err nil)
  (princ)
)

(defun c:rectang ( / cmde pt1 pt2)
  (setq m:err *error* *error* *merr*
        cmde (getvar "CMDECHO")
  )
  (setvar "CMDECHO" 0)
  (setq pt1 (getpoint ;|ACAD_MNL_20|;"\nFirst corner: ")
        pt2 (getcorner pt1 ;|ACAD_MNL_21|;"\nOther corner: ")
  )
  (command "_.PLINE" pt1 "_non" (list (car pt1) (cadr pt2))
                   pt2 "_non" (list (car pt2) (cadr pt1))
           "_C"
  )
  (setvar "CMDECHO" cmde)
  (setq *error* m:err m:err nil)
  (princ)
)

;|ACAD_MNL_28|;                                                     

(defun ai_showedge_alert ()
   (alert ;|ACAD_MNL_26|;"Invisible edges will be shown after next Regeneration.")
   (princ)
)

(defun ai_hideedge_alert ()
   (alert ;|ACAD_MNL_27|;"Invisible edges will be HIDDEN after next Regeneration.")
   (princ)
)

;;;=== Menu Functions ===

(defun ai_rootmenus ()
  (setq T_MENU 0)
  (menucmd "S=S")
  (menucmd "S=ACAD.S")
  (princ)
)

(defun ai_fms ( / fmsa fmsb)
  (setq m:err *error* *error* *merr*)
  (if (getvar "TILEMODE") (setvar "TILEMODE" 0))
  (setq fmsa (vports) fmsb (nth 0 fmsa))
  (if (member 1 fmsb)
    (if (> (length fmsa) 1)
      (command "_.MSPACE")
      (progn
        (command "_.MVIEW")
        (while (eq 1 (logand 1 (getvar "CMDACTIVE")))
          (command pause)
        )
        (command "_.MSPACE")
      )
    )
  )
  (setq *error* m:err m:err nil)
  (princ)
)

(defun ai_propchk ( / a)
  (setq m:err *error* *error* *merr*)
  (if (not (setq a (ssget "I")))
      (setq a (ssget))
  )
  (if (> (sslength a) 1)
    (progn
      (if (not ddchprop)
        (load "ddchprop")
      )
      (setq *error* m:err m:err nil)
      (ddchprop a)
    )
    (progn
      (if (not ddmodify)
        (load "ddmodify")
      )
      (setq *error* m:err m:err nil)
      (ddmodify (ssname a 0))
    )
  )
  (princ)
)

(defun ai_onoff (var)
  (setvar var (abs (1- (getvar var))))
  (princ)
)


;;; Pop menu Draw/ Dim/ Align Text/ Centered
;;; Toolbar Dimensions/ Align Text/ Centered

(defun ai_dim_cen (/ ai_sysvar ai_dim_ss)
  (setq ai_sysvar (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (cond
    ((setq ai_dim_ss (ssget "P"))
      (command "_dimoverride" "_dimjust" 0 "" ai_dim_ss "" 
               "_dimtedit" ai_dim_ss "_h")
    )
    (T nil)
  )
  (setvar "cmdecho" ai_sysvar)
  (princ)
)

;;; Set alternate tablet menus based on cfg settings
(defun set_alt_tabs ()

   ;; check for active tablet areas
   (setq T_Menu (read (ai_popmenucfg "T_Menu")))
   (mapcar
     '(lambda (x y z)
        (if (= (logand x T_Menu) x)
            (progn
              (menucmd (strcat "T" y "=TABLET" y "ALT"))
              (if (/= "" (getcfg "CfgData/Editor/TabletMenusActive"))
                  (eval z)
              )
            )
        )
      )
   '(1 2 4 8)
   '("1" "2" "3" "4")
   '(
      (princ ;|ACAD_MNL_6|;"\nAlternate tablet area 1 loaded.  ")
      (princ ;|ACAD_MNL_10|;"\nAlternate tablet area 2 loaded.  ")
      (princ ;|ACAD_MNL_14|;"\nAlternate tablet area 3 loaded.  ")
      (princ ;|ACAD_MNL_18|;"\nAlternate tablet area 4 loaded.  ")
    )
  )
   (if (and (/= "" (getcfg "CfgData/Editor/TabletMenusActive"))
            (/= 0 T_Menu)
       )
       (terpri)
   )

   (setq set_alt_tabs nil)

)

;; If no Tablet menu data exists, insert defaults
(if (or (not (setq T_Menu (ai_popmenucfg "T_Menu")))
        (= "" T_Menu)
    )
    ;; check for hardware lock
    (if (/= "" (getvar "_linfo"))
        (ai_putmenucfg "T_Menu" "4")
        (ai_putmenucfg "T_Menu" "0")
    )
)

;;; Restore alternate tablets upon menu load
(set_alt_tabs)

(setvar "MENUCTL" 1)

;; Load AutoVision menu if AutoVision is installed, and we are on Windows.
(if (and 
      (wcmatch (getvar "platform") "*Windows*")
      (AutoVisionPresent)
    )
    (progn 
      (setq filedia (getvar "FILEDIA"))
      (setq cmdecho (getvar "CMDECHO"))
      (setvar "FILEDIA" 0)
      (setvar "CMDECHO" 0)
      (command "_.MENUUNLOAD" "autovis")
      (command "_.MENULOAD" "autovis.mnu")
      (menucmd "P7=+autovis.pop1")
      (setvar "FILEDIA" filedia)
      (setvar "CMDECHO" cmdecho)
    )
)

(princ ;|ACAD_MNL_25|;"loaded.")
(princ)
