!   TITLE:  configuration.mac (MANAGEMENT)
!
!
!   OBJECTIVE:
!
!   This macro stores (or restores) the current (or previous) configuration
!   of the database. (i.e., the currently selected set of keypoints, lines,
!   areas, volumes, nodes, elements, active CS and entity maximums)
!
!
!   COMMAND SYNTAX:
!
!                              (1)          (2)
!           CONFIGURATION, save/restore, extra_grp
!
!
!   ARGUMENTS:
!
!       (1) save/restore = save OR restore the database configuration:
!
!             a.) 0 (or blank) = save the current selected solid model and
!                                finite element (FE) entities. (SAVE MODE)
!
!             b.) 1 = restore (select) the solid model and FE entities
!                     saved in the previous run of this macro in save mode.
!
!             c.) -1 = unselect the solid model and FE entities saved in the
!                      previous run of this macro in save mode.
!
!             d.) -2 = delete any currently saved configurations
!                      (i.e., delete all existing component groups created
!                           by this macro in save mode)
!
!       (2) extra_grp = initiate extra configuration groups for storing
!                       or retrieving (default is 0):
!
!               N (where N is an integer group number) = 0 .. 5
!
!
!   DESCRIPTION:
!
!   The database configuration is the current selected entities, the current
!   active coordinate system (CS) and the current entity maximums. The entities,
!   and parameters holding the entity maximums, are summarized as follows:
!
!       Solid Model Entities:       1.) keypoints (KP)
!                                   2.) lines (L)
!                                   3.) areas (A)
!                                   4.) volumes (V)
!
!       Finite Element Entities:    5.) nodes (N)
!                                   6.) elements (E)
!
!       Active Coordinate System:   7.) coordinate system (CS)
!
!       Current Entity Maximumus:   8.) KM, LM, AM, VM, NM, and EM
!
!   When this macro is run with the argument = 0 (or blank), the current
!   database configuration is saved.
!
!   Each succesive run of this macro with the argument = 1, the database is
!   restored back to the configuration saved in the previous run of this
!   macro in SAVE MODE (argument = 0).
!
!   A saved configuration may be restored as many times as desired. A
!   configuration will not not be overwritten until this macro is run again
!   in SAVE MODE, overwriting the previous saved configuration.
!
!   If it is desired to have additional configurations for saving and
!   retrieving, then additional groups may be employed using argument 2.
!   In using this argument, an integer value, N, where 1 <= N <= 5, may be
!   employed. Therefore, if an additional group, say group 1, is needed,
!   simply using a '1' in argument 2 will initiate that new configuration
!   group. Likewise if a '2' is used, then that extra configuration is group
!   2, etc.
!
!   For storing/retrieving/deleting that group, simply place the desired group
!   number in argument 2, along with the desired action in argument 1.
!
!   In this way, nested configurations may be employed without interfering
!   with each saved group.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
save__=arg1
xcgrp__=arg2
!
*if,xcgrp__,eq,0,then
    *if,save__,eq,0,then
        *get,acs_____,active,,csys
        !
        kmaxhld_=km
        lmaxhld_=lm
        amaxhld_=am
        vmaxhld_=vm
        nmaxhld_=nm
        emaxhld_=em
        !
        cm,kgrp____,kp
        cm,lgrp____,line
        cm,agrp____,area
        cm,vgrp____,volu
        cm,ngrp____,node
        cm,egrp____,elem
        !
        cmgrp,curgrp__,kgrp____,lgrp____,agrp____,vgrp____,ngrp____,egrp____
    *elseif,save__,eq,1,then
        !
        ! Type of component Cname:
        !       1=Nodes, 2=Elements, 6=Keypoints, 7=Lines, 8=Areas, 9=Volumes,
        !       11-15=Subcomponents
        !       (11=subcomponent at level 1, 12=subcomponent at level 2, etc.).
        !
        *get,ktyp____,comp,kgrp____,type
        *get,ltyp____,comp,lgrp____,type
        *get,atyp____,comp,agrp____,type
        *get,vtyp____,comp,vgrp____,type
        *get,ntyp____,comp,ngrp____,type
        *get,etyp____,comp,egrp____,type
        !
        *if,ktyp____,eq,6,then
            cmsel,s,kgrp____
        *endif
        !
        *if,ltyp____,eq,7,then
            cmsel,s,lgrp____
        *endif
        !
        *if,atyp____,eq,8,then
            cmsel,s,agrp____
        *endif
        !
        *if,vtyp____,eq,9,then
            cmsel,s,vgrp____
        *endif
        !
        *if,ntyp____,eq,1,then
            cmsel,s,ngrp____
        *endif
        !
        *if,etyp____,eq,2,then
            cmsel,s,egrp____
        *endif
        !
        km=kmaxhld_
        lm=lmaxhld_
        am=amaxhld_
        vm=vmaxhld_
        nm=nmaxhld_
        em=emaxhld_
        !
        csys,acs_____
        !
        *set,ktyp____
        *set,ltyp____
        *set,atyp____
        *set,vtyp____
        *set,ntyp____
        *set,etyp____
    *elseif,save__,eq,-1,then
        cmsel,u,curgrp__
    *elseif,save__,eq,-2,then
        cmdele,kgrp____
        cmdele,lgrp____
        cmdele,agrp____
        cmdele,vgrp____
        cmdele,ngrp____
        cmdele,egrp____
        cmdele,curgrp__
        *set,acs_____
    *endif
    !
    *set,save__,
    !
    *if,arg3,eq,0,then
        /replot
    *endif
*elseif,xcgrp__,eq,1,then
    config_1,save__
*elseif,xcgrp__,eq,2,then
    config_2,save__
*elseif,xcgrp__,eq,3,then
    config_3,save__
*elseif,xcgrp__,eq,4,then
    config_4,save__
*elseif,xcgrp__,eq,5,then
    config_5,save__
*endif
!
*if,prkey_,eq,1,then
    /go
*endif