saving custom data into artist states?

Discussion in 'Cadence' started by S. Badel, Jun 3, 2004.

  1. S. Badel

    S. Badel Guest

    Is there a way i can save additional data in an artist state,
    I mean a clean way without hacking anything ?

    I'd like to implement an extension to artist and would like
    the data to be saved when one uses 'save state', and retrieved
    when 'load state'.

    I noticed tools like parametric analysis or monte-carlo do have
    their own saving mechanism (not practical), moreover
    i couldn't find anything in the documentation. The only way I'm
    thinking of is to Hack the sevSaveState() procedure, or the
    Save State menu item.

    Thanks,

    Stéphane
     
    S. Badel, Jun 3, 2004
    #1
  2. I don't think there's any public way of doing this - sorry!

    There are some PCRs to unify the things that aren't part of the main states
    (like Monte Carlo and Parametric analysis) - but it's not been done yet.
    Perhaps when that happens an API might be added? (wild speculation on
    my part - don't take that as fact)

    Andrew.
     
    Andrew Beckett, Jun 3, 2004
    #2
  3. S. Badel

    Erik Wanta Guest

    Stéphane:
    We have done the hack you describe. The code below saves artist
    states as cell views allowing for DM software to check in/out. I also
    improved on the parametric and optization load/save state functions.
    It would be nice if Cadence would adopt this as it has greatly
    improved our ability to repeat simulations. I also wrote a similar
    functionality for assura states so that they could be saved as cell
    views.

    ;---------- start of data.reg file -------
    ;;//
    ;;//
    ;;DataFormat artistStates {
    ;; Pattern = artist.sim; // Name of the file holding
    the actual design data
    ;; Default_Editor = artistStates; // The program used to
    view the data
    ;; Co_Managed = *.state artist.sim master.tag;
    ;;}

    ;; Register the state application if not previously registered
    when(!deViewTypeIsRegistered("artistStates")

    ;register the artist states view
    deRegApp(
    ?appName "artistStates"
    ?appTrigger 'artist_stateAppTrig ; Dummy function
    ?dataTrigger 'artist_stateDataTrig
    ?enableTrigger 'artist_stateEnableTrig ; Dummy function
    ?viewType "artistStates"
    ?widgetType "none"
    )
    ) ; when

    ;overload aaAddEventCB to overload state functions after artist is up
    when((getd('aaAddEventCB)&&(!boundp('MOTOaaAddEventCB)))

    ;get pointer to original function aaAddEventCB
    MOTOaaAddEventCB=getd('aaAddEventCB)

    ;; Set to debug mode so that the original functions can be
    overloaded
    sstatus(debugMode t)

    ;overload aaAddEventCB
    procedure(aaAddEventCB(@rest argList)
    prog(()

    ;overload original artist states functions after analog artist
    is up
    when((getd('sevLoadState)&&(!boundp('MOTOsevLoadState)))
    ;overload original artist states functions
    MOTOsevStateWrapper()
    )

    ;try to overload optimization state functions
    MOTOoptimStateWrapper()

    ;try to overload parametric state functions
    MOTOparaStateWrapper()

    ;; always call the original function
    apply(MOTOaaAddEventCB argList)

    return(t)

    ) ; prog
    ) ; procedure aaAddEventCB

    ;; turn debugMode off
    sstatus(debugMode nil)

    ) ; when

    ;overload optimization state functions
    procedure(MOTOoptimStateWrapper()
    prog(()

    when((getd('ohiLoadState)&&(!boundp('MOTOohiLoadState)))
    MOTOohiLoadState=getd('ohiLoadState)

    sstatus(debugMode t)

    ;overload ohiLoadState
    procedure(ohiLoadState(opt_session)
    prog((cv)

    ;get the design cell view
    cv=asiGetTopCellView(sevEnvironment(opt_session))

    ;create all the cell directories for the library
    MOTOcreateArtistCellStateDirs(cv~>libName
    opt_session~>sevSimSession)

    ;copy states from the state cell view to the default state
    save dir
    MOTOcopyStatesFromCell(cv~>libName cv~>cellName
    opt_session~>sevSimSession)

    ;; Call the original load state procedure.
    apply(MOTOohiLoadState list(opt_session))

    return(t)

    ) ; prog
    ) ; procedure ohiLoadState

    sstatus(debugMode nil)

    ) ; when

    return(t)
    ) ; prog
    ) ; procedure MOTOoptimStateWrapper

    ;overload parametric state functions
    procedure(MOTOparaStateWrapper()
    prog(()

    when((getd('apaSaveCB)&&(!boundp('MOTOapaSaveCB)))

    MOTOapaSaveCB=getd('apaSaveCB)
    ;MOTOapaRecallCB=getd('apaRecallCB)

    sstatus(debugMode t)

    ;overload apaSaveCB
    procedure(apaSaveCB(window)
    prog((asi_session paras)

    ;get artist session
    asi_session=_apaGetSimSessionObj(window)

    ;create parametric save state form
    hiCreateAppForm(
    ?name 'paras
    ?formTitle "Parametric Analysis Save"
    ?buttonLayout 'OKCancel
    ?callback "MOTOsaveStateParam(paras)"
    ?fields list(
    hiCreateStringField(
    ?name 'state_name
    ?prompt "Save As"
    ?defValue "state1"
    )
    )
    ) ; hiCreateAppForm

    ;hide session and window in form
    paras->asi_session=asi_session
    paras->window=window

    ;display form
    hiDisplayForm(paras)

    return(t)

    ) ; prog
    ) ; procedure apaSaveCB

    ;overload apaRecallCB
    procedure(apaRecallCB(window)
    prog((asi_session cv paral)

    ;get artist session
    asi_session=_apaGetSimSessionObj(window)

    ;get the design cell view
    cv=asiGetTopCellView(asi_session)

    ;create parametric load state form
    hiCreateAppForm(
    ?name 'paral
    ?formTitle "Parametric Analysis Load"
    ?buttonLayout 'OKCancel
    ?callback "MOTOloadStateParam(paral)"
    ?fields list(
    hiCreateCyclicField(
    ?name 'lib
    ?prompt "Library"
    ?choices ddGetLibList()~>name
    ?defValue cv~>lib~>name
    ?callback "MOTOsetParamCells(paral)"
    )

    hiCreateCyclicField(
    ?name 'cell
    ?prompt "Cell"
    ?choices cv~>lib~>cells~>name
    ?defValue cv~>cell~>name
    ?callback "MOTOsetParamSimandStates(paral)"
    )

    hiCreateCyclicField(
    ?name 'sim
    ?prompt "Simulator"
    ?choices asiGetSimulatorList()
    ?defValue asiGetSimName(asi_session)
    ?callback "MOTOsetParamStates(paral)"
    )

    hiCreateListBoxField(
    ?name 'state
    ?prompt "States"
    ?choices list("")
    )
    )
    ) ; hiCreateAppForm

    ;save session simulator in form
    paral->simulator=asiGetSimName(asi_session)
    paral->window=window

    ;set simulator and states list
    MOTOsetParamSimandStates(paral)

    ;display load parametric states form
    hiDisplayForm(paral)

    return(t)

    ) ; prog
    ) ; procedure apaRecallCB

    sstatus(debugMode nil)

    ) ; when

    return(t)

    ) ; prog
    ) ; procedure MOTOparaStateWrapper

    ;set the cells with parametric states in load form
    procedure(MOTOsetParamCells(paral)
    prog(()

    ;set cells
    paral->cell->choices=ddGetObj(paral->lib->value)~>cells~>name

    ;set simulators and states list
    MOTOsetParamSimandStates(paral)

    return(t)

    ) ; prog
    ) ; procedure

    ;set the simulator list and state list
    procedure(MOTOsetParamSimandStates(paral)
    prog((cellId simList simName)

    ;get cellId
    cellId=ddGetObj(paral->lib->value paral->cell->value)

    ;initialize simList
    simList=list(paral->sim->value)

    foreach(viewId cellId~>views

    ;when parametric state
    when(member("param.state" viewId~>files~>name)

    ;get simulator name
    simName=nth(1 parseString(viewId~>name "_"))

    ;add simulator to simulator list if not there already
    when(!member(simName simList)
    simList=cons(simName simList)
    ) ; when
    ) ; when
    ) ; foreach

    ;set simulator choices
    paral->sim->choices=simList

    ;set simulator
    paral->sim->value=paral->simulator

    ;set states list
    MOTOsetParamStates(paral)

    return(t)

    ) ; prog
    ) ; procedure

    ;set the parametric state list
    procedure(MOTOsetParamStates(paral)
    prog((cellId states simName stateName)

    ;get cellId
    cellId=ddGetObj(paral->lib->value paral->cell->value)

    ;initialize states list
    states=nil

    foreach(viewId cellId~>views
    when(member("param.state" viewId~>files~>name)

    ;get state simulator name
    simName=nth(1 parseString(viewId~>name "_"))

    ;get state name
    stateName=buildString(tail(tail(parseString(viewId~>name
    "_"))) "_")

    ;add state to state list if simulator matches simulator in
    form
    when(paral->sim->value==simName
    states=cons(stateName states)
    ) ; when
    ) ; when
    ) ; foreach

    ;set the states list
    paral->state->choices=states

    return(t)
    ) ; prog
    ) ; procedure

    ;save parametric state
    procedure(MOTOsaveStateParam(form)
    prog((cv simName stateName viewName viewId dfIIStateDir)

    ;get the design cell view
    cv=asiGetTopCellView(form->asi_session)

    ;get simulator name
    simName=asiGetSimName(form->asi_session)

    ;get state name
    stateName=form->state_name->value

    ;; Create the view name to be used.
    viewName=strcat("state_" simName "_" stateName)

    ;determine if view already exists
    ;get view Id
    viewId=ddGetObj(cv~>libName cv~>cellName viewName "artist.sim")

    ;view doesn't exist, therefore create view
    when(!viewId
    ;create view
    viewId=ddGetObj(cv~>libName cv~>cellName viewName "artist.sim"
    nil "w" )
    ) ; when!

    when(!viewId~>isWritable
    ;checkout call
    ddAutoCheckout(viewId)
    ) ; when !writable

    ;checkout failed, error out
    when(!viewId~>isWritable
    error("View could not be opened for edit.")
    ) ; when checkout failed

    ;base cell view directory
    dfIIStateDir=strcat("/" buildString(remove("artist.sim"
    parseString(ddGetObjWritePath(viewId) "/")) "/"))

    ;create state in cell view
    apaSave(form->window strcat(dfIIStateDir "/param.state"))

    return(t)

    ) ; prog
    ) ; procedure MOTOsaveStateParam

    ;load parametric state
    procedure(MOTOloadStateParam(form)
    prog((viewName viewId para_state_file)

    if(car(form->state->value) then
    ;get view name
    viewName=strcat("state_" form->sim->value "_"
    car(form->state->value))
    else
    error("no state selected")
    ) ; if

    ;get viewId
    viewId=ddGetObj(form->lib->value form->cell->value viewName)

    when(viewId
    ;get parametric state file
    para_state_file=strcat(ddGetObjReadPath(viewId)
    "/param.state")

    if(isFile(para_state_file) then
    ;create state in cell view
    apaRecall(form->window para_state_file)
    else
    error("state file doesn't exist")
    ) ; if
    ) ; when

    return(t)

    ) ; prog
    ) ; procedure MOTOloadStateParam

    ;overload original state functions
    procedure(MOTOsevStateWrapper()
    prog(()

    when(!boundp('MOTOsevLoadState)

    /*
    ;one would think they could just load simui.cxt,
    optimization.cxt, and
    ;paraplot.cxt and then overload the appropriate functions. This
    is not
    ;the case which requires the overloading to take place later.
    See the
    ;overloading of aaAddEventCB kludge above.

    ;load original artist UI functions so that they can be
    overloaded
    when(isFile(prependInstallPath("etc/context/simui.cxt"))
    when(!isContextLoaded(prependInstallPath("etc/context/simui.cxt"))
    loadContext(prependInstallPath("etc/context/simui.cxt"))
    loadContext(prependInstallPath("etc/context/optimization.cxt"))
    loadContext(prependInstallPath("etc/context/paraplot.cxt"))
    ) ; ** when !isContextLoaded
    ) ;
    */

    ;; Get pointers to the original functions and store in global
    variables.
    MOTOsevLoadState=getd('sevLoadState)
    MOTOsevLoadStateFromForm=getd('sevLoadStateFromForm)
    MOTOsevSaveStateFromForm=getd('sevSaveStateFromForm)
    MOTOsevUpdateLoadStateForm=getd('sevUpdateLoadStateForm)

    ;; Set to debug mode so that the original functions can be
    overloaded
    sstatus(debugMode t)

    ;overload sevLoadState
    procedure(sevLoadState(sev_session)
    prog((cv)

    when(sev_session

    ;get the design cell view
    cv=asiGetTopCellView(sevEnvironment(sev_session))

    ;create all the cell directories for the library
    MOTOcreateArtistCellStateDirs(cv~>libName sev_session)

    ;copy states from the state cell view to the default state
    save dir
    MOTOcopyStatesFromCell(cv~>libName cv~>cellName
    sev_session)

    ;; Call the original load state procedure.
    apply(MOTOsevLoadState list(sev_session))

    ) ; when

    return(t)

    ) ; prog
    ) ; procedure sevLoadState

    ;overload sevLoadStateFromForm
    procedure(sevLoadStateFromForm(sev_session form allComponentDefs
    loadComponentFunc)
    prog(()

    ;; Checks the state model file list and prompts if there are
    ;; differences from what is in system now.
    ;; No reason to check if the model setup option is turned
    off.
    when(form->components->modelSetup->value!=nil
    MOTOcheckModelFileList(sev_session form)
    ) ; when

    ;load artist state
    apply(MOTOsevLoadStateFromForm list(sev_session form
    allComponentDefs loadComponentFunc))

    return(t)

    ) ; prog
    ) ; procedure sevLoadStateFromForm

    ;overload sevSaveStateFromForm
    procedure(sevSaveStateFromForm(sev_session form allComponentDefs
    parentDir saveComponentFunc)
    prog((cv viewName simName stateName defaultSaveDir
    defaultStateDir retdd dfIIStateDir viewId)

    ;;dprint(sev_session form allComponentDefs parentDir
    saveComponentFunc)

    ;get session cell view
    cv=asiGetTopCellView(sevEnvironment(sev_session))

    ;get simulator name
    simName=asiGetSimName(sevEnvironment(sev_session))

    ;optimizer state check
    if(parentDir==".asd_optimization" then
    ;artist states directory
    ;the optimizer passes the optSession which is different
    than the sevSession
    defaultSaveDir=MOTOgetStateSaveDir(sev_session~>sevSimSession)
    else
    ;artist states directory
    defaultSaveDir=MOTOgetStateSaveDir(sev_session)
    )

    ;get state name
    stateName=form->name->value

    ;; Create the view name to be used.
    viewName=strcat("state_" simName "_" stateName)

    ;determine if view already exists
    ;get view Id
    viewId=ddGetObj(cv~>libName cv~>cellName viewName
    "artist.sim")

    ;view doesn't exist, therefore create view
    when(!viewId
    ;create view
    viewId=ddGetObj(cv~>libName cv~>cellName viewName
    "artist.sim" nil "w" )
    ) ; when!

    when(!viewId~>isWritable
    ;checkout call
    ddAutoCheckout(viewId)
    ) ; when

    ;checkout failed, error out
    when(!viewId~>isWritable
    error("View could not be opened for edit.")
    ) ; when

    ;base cell view directory
    dfIIStateDir=strcat("/" buildString(remove("artist.sim"
    parseString(ddGetObjWritePath(viewId) "/")) "/"))

    ;base state directory
    defaultStateDir=strcat(defaultSaveDir "/" cv~>libName "/"
    cv~>cellName "/" parentDir "/" stateName)

    ;; Call the original save state procedure to copy the states
    to the artist states directory
    apply(MOTOsevSaveStateFromForm list(sev_session form
    allComponentDefs parentDir saveComponentFunc))

    ;; Copy states to cell view
    if(isDir(defaultStateDir) then

    ;copy each file to cell view with .state suffix
    foreach(fl getDirFiles(defaultStateDir)

    when((!isDir(fl) && !rexMatchp("^.nfs*" fl))

    ;regular and optimizer states both have a file
    called variables
    ;they are different, therefore change the optim file
    name
    when((fl=="variables" &&
    parentDir==".asd_optimization")
    fl="variablesoptim"
    ) ; when

    ;copy state file to cell view
    retdd=shell(sprintf(nil "\\cp %s/%s %s/%s.state"
    defaultStateDir fl dfIIStateDir fl))

    when(!retdd
    warn("Could not copy state to (lib cell view):
    (%s %s %s)\n\n From: %s\n" viewId~>lib~>name
    viewId~>cell~>name viewId~>view~>name defaultStateDir)
    ) ; when

    ) ; when
    ) ; foreach
    ) ; if

    return(t)

    ) ; prog
    ) ; procedure

    procedure(sevUpdateLoadStateForm(@rest argList)
    prog((changeType sev_session fm cellName libName)

    ;get the property that the user is changing
    changeType=nth(1 argList)

    ;; only update cells when library change is made.
    if(member(changeType list('lib 'cell)) then

    ;get the sevSession
    sev_session=nth(0 argList)

    ;get the load state form
    fm=hiGetCurrentForm()

    when(fm

    ;get the lib name
    libName=fm~>lib~>value

    when(libName

    ;get the cell name
    cellName=fm~>cell~>value

    if(member(changeType list('lib)) then

    ;; create cell state directories for the library
    MOTOcreateArtistCellStateDirs(libName
    sev_session)

    ) ; if

    ;copy states from cell view to default states
    directory
    MOTOcopyStatesFromCell(libName cellName sev_session)

    ) ; when
    ) ; when

    ) ; if

    ;call original function
    apply(MOTOsevUpdateLoadStateForm argList)

    return(t)

    ) ; prog
    ) ; procedure

    ) ; when

    ;; unset debug mode
    sstatus(debugMode nil)

    return(t)

    ) ; prog
    ) ; procedure

    procedure(MOTOcreateArtistCellStateDirs(libName sev_session)
    ;; Creates the basic library directories needed.
    prog((libId defaultSaveDir cells defaultStateDir)

    printf("INFO - Scanning library %s for cells containing artist
    states.\n" libName)

    ;get default artist states directory
    defaultSaveDir=MOTOgetStateSaveDir(sev_session)

    ;get library id
    libId=ddGetObj(libName)

    ;create state library directory if it doesn't exist
    when(!isDir(strcat(defaultSaveDir "/" libId~>name))
    when(isWritable(strcat(defaultSaveDir "/" libId~>name))
    createDir(strcat(defaultSaveDir "/" libId~>name))
    ) ; when
    ) ; when

    ;find all the state cells in the library
    cells=setof(cell libId~>cells setof(view cell~>views
    substring(view~>name 1 6)=="state_"))

    foreach(cellId cells

    ;get default state directory
    defaultStateDir=strcat(defaultSaveDir "/" libId~>name "/"
    cellId~>name)

    ;; See if we need to create the directory
    when(!isDir(defaultStateDir)
    when(isWritable(defaultSaveDir) && createDir(defaultStateDir)

    ;; Now we need to create an empty file for some reason
    shell(strcat("touch " defaultStateDir "/.sevSaveDir"))
    ) ; when
    ) ; when
    ) ; foreach

    printf("Found %d cells with artist states.\n" length(cells))

    return(t)

    ) ; prog
    ) ; procedure

    ; Copies all the states from cell view to the state directory.
    procedure(MOTOcopyStatesFromCell(libName cellName sev_session)
    prog((fileName words simName cellId dfIIStateDir defaultStateDir words
    simName stateName warnTxt
    retdd time1 time2 printName defaultSaveDir invalidStateViews
    regularStateFiles optimStateFiles regularState
    optimState stateCount strl)

    ;get default artist states directory
    defaultSaveDir=MOTOgetStateSaveDir(sev_session)

    ;get cell db id
    cellId=ddGetObj(libName cellName)

    ;regular state file list
    regularStateFiles=list("analyses.state" "convergence.state"
    "environmentOptions.state" "graphicalStimuli.state"
    "modelSetup.state" "outputs.state"
    "rfstim.state" "sensList.state" "simulationFiles.state"
    "simulatorOptions.state" "spList.state"
    "waveformSetup.state" "variables.state")

    ;optimizer state file list
    optimStateFiles=list("algoOptions.state" "envOptions.state"
    "objectivesConstraints.state" "plottingOptions.state"
    "variablesoptim.state")

    ;copy all states for the current cell
    foreach(viewId cellId~>views

    ;every state view has an artist.sim file
    when(member("artist.sim" viewId~>files~>name)

    regularState=nil
    optimState=nil
    stateCount=0

    ;determine if an optimizer and or regular state is saved in
    the cell view
    foreach(file viewId~>files~>name

    when(member(file regularStateFiles)
    regularState=t
    ) ; when

    when(member(file optimStateFiles)
    optimState=t
    ) ; when
    ) ; foreach

    ;update state count
    when(regularState || optimState
    stateCount++
    ) ; when

    ;copy both optimizer and regular state if they both exist
    for(i 1 stateCount

    ;get artist state view directory path
    dfIIStateDir=ddGetObjReadPath(viewId)

    ;convert state name into a list
    ;0 "state"
    ;1 simulator name
    ;2 state name
    words=parseString(viewId~>name "_")

    ;check for valid state name
    if(length(words)<3||nth(0 words)!="state" then
    invalidStateViews=cons(list(libName cellName
    viewId~>name) invalidStateViews)

    else

    ;get simulator name
    simName=car(parseString(nth(1 words) "-"))

    ;Need to change the sim name if it is an optimization
    state.
    printName=simName

    when(((stateCount==1 && optimState) || (i==2))
    simName=".asd_optimization"
    printName="optimization"
    ) ; when

    ;get state name
    stateName=buildString(tail(tail(words)) "_")

    ;get default artist state directory
    defaultStateDir=strcat(defaultSaveDir "/" libName "/"
    cellName "/" simName "/" stateName)

    ;; if directory does not exists then create it
    when(!isDir(defaultStateDir)

    retdd=shell(sprintf(nil "mkdir -p %s"
    defaultStateDir))

    when(!retdd
    warn("Could not create the states directory.
    Load state failed.")
    warn("%s Will not copy state from (lib
    cell view): (%s %s %s)\n\n To: %s\n\n" warnTxt libName
    cellName viewId~>name defaultStateDir)
    ) ; when
    ) ; when

    ;copy state from cell view to state directory
    when(isDir(defaultStateDir)

    when(!isFile(strcat(defaultStateDir "/.sevSaveDir"))
    shell(strcat("touch " defaultStateDir
    "/.sevSaveDir"))
    ) ; when

    foreach(fl viewId~>files~>name

    strl=strlen(fl)

    when(strl>6
    ;remove the .state suffix
    fileName=substring(fl 1 (strl-6))

    ;; Only copy files back that end in .state
    when(substring(fl (strl-4))=="state"
    time1=fileTimeModified(strcat(dfIIStateDir
    "/" fl))

    time2=fileTimeModified(strcat(defaultStateDir "/" fileName))

    ;; copy state if cell view state is newer
    than state in save dir
    when((time2==nil)||(time1&&(time1>time2))

    ;print update message
    sprintf(nil "INFO-Updating state %s %s
    from (lib cell view) (%s %s %s)\n" printName stateName libName
    cellName viewId~>name)

    ;kludge as both a regular and optim
    state both have variables files
    when(fl=="variablesoptim" &&
    ((stateCount==1 && optimState) || (i==2))
    fl=="variables"
    )

    ;copy state from cellview to default
    state directory
    retdd=shell(sprintf(nil "\\cp %s/%s
    %s/%s" dfIIStateDir fl defaultStateDir fileName))

    ;unable to copy state to default state
    directory
    when(!retdd
    warn("Could not copy state from (lib
    cell view): (%s %s %s)\n To: %s\n" libName cellName
    viewId~>name defaultStateDir)
    ) ; when
    ) ; when
    ) ; when
    ) ; when
    ) ; foreach
    ) ; when
    ) ; if
    ) ; for
    ) ; when
    ) ; foreach

    ;print warning for invalid state views
    when(invalidStateViews

    warn("Some State cell view names are invalid.")
    warn("This can only happen if the cell has been manually copied
    or renamed.")
    warn("Please rename the cell to make it accessable.")
    warn("The name of a Simulation State cell view must conform to
    the following standard:")
    warn("state_<simulator name>_<name of state>")
    warn("The following cells do not conform to this standard are
    not accessable by load state:")

    foreach(invalidStateView invalidStateViews
    warn("%L" invalidStateView)
    ) ; foreach

    ) ; when

    return(t)

    ) ; prog
    ) ; procedure

    ;get the saveDir (directory to save artist states)
    procedure(MOTOgetStateSaveDir(sev_session)
    prog((saveDir)

    ;Give warning if asimenv saveDir is not set.
    ;This should never happen as it is set in the CDS installation @
    ;$CDSHOME/tools/dfII/etc/tools/asimenv/.cdsenv
    when(!envGetVal("asimenv" "saveDir")
    warn("The default save state directory is not defined, please
    check your installation.")
    ) ; when

    ;Warning if asimenv saveDir is not the same as sev_session~>saveDir
    ;Session->Options->Save State Directory sets sev_session~>saveDir
    when(sev_session~>saveDir&&envGetVal("asimenv" "saveDir")
    when((envGetVal("asimenv" "saveDir")!=sev_session~>saveDir)
    warn("Default Save State Directory: %s" envGetVal("asimenv"
    "saveDir"))
    warn("Session Save State Directory: %s" sev_session~>saveDir)
    ) ; when

    saveDir=sev_session~>saveDir
    ) ; when

    when(!sev_session~>saveDir&&envGetVal("asimenv" "saveDir")
    saveDir=envGetVal("asimenv" "saveDir")
    ) ; when

    when(!sev_session~>saveDir&&!envGetVal("asimenv" "saveDir")
    error("Can't determine artist save state directory.")
    ) ; when

    return(simplifyFilename(saveDir))
    ) ; prog
    ) ; procedure

    ;The artist state data trigger.
    procedure(artist_stateDataTrig(argList)
    prog((viewType warnTxt)

    ;get view type (artistStates)
    viewType=argList->viewType

    ;print warning if viewType is not registered
    when(!member(viewType deGetAllViewTypes())

    warnTxt=sprintf(nil " WARNING - %s NOT REGISTERED \n\n"
    viewType)
    warnTxt=strcat(warnTxt " Please verify that you have
    registered the viewType.\n")
    warnTxt=strcat(warnTxt " There are a predefined set of
    locations of data registration\n")
    warnTxt=strcat(warnTxt " files based you you
    particular installation. Please contact\n")
    warnTxt=strcat(warnTxt " you local CAD support or look
    up data registration in documentation.\n")

    ;display warning
    hiDisplayAppDBox(?name 'notRegistered
    ?dboxBanner strcat(viewType " NOT REGISTERED")
    ?dboxText warnTxt
    ?buttonLayout 'Close
    )
    ) ; when

    ;display warning
    hiDisplayAppDBox(?name 'useArtist
    ?dboxBanner "Use Analog Artist"
    ?dboxText "Use Session->Load State in analog artist to load the
    state."
    ?buttonLayout 'Close
    )

    return(t)

    ) ; prog
    ) ; procedure

    ;artist states app trigger
    procedure(artist_stateAppTrig(@rest argList)
    ;; Currently nothing is done in this procedure.
    ;; printf( " INFO - This is the Artist State App Trigger.\n")
    t
    )

    ;artist states enable trigger
    procedure(artist_stateEnableTrig(@rest argList)
    ;; Currently nothing is done in this procedure.
    ;; printf( " INFO - This is the Artist State Enable Trigger.\n")
    t
    )

    ; Reads the modelSetup file and returns the model files as a list.
    procedure(MOTOreadModelFile(file)
    prog((filep rdLine string modelFiles)

    when(!isFile(file)
    error("unable to open %s" file)
    ) ; when

    ;get input file port
    filep=infile(file)

    ;error out if can't open file port
    when(!filep
    error("unable to open %s" file)
    ) ; when

    string="modelFiles = '"
    while(gets(rdLine filep)
    string=strcat(string rdLine)
    ) ; while

    loadstring(string)

    return(modelFiles)

    ) ; ** prog **
    ) ; ** procedure MOTOreadModelFile **

    ;gives warning if the state model list is different than the
    ;system defined model list.
    procedure(MOTOcheckModelFileList(sev_session form)
    prog((cv asi_session simName stateName defaultSaveDir defaultStateDir
    modelSetupFile
    stateModelList systemModelList diff str ret)

    ;get artist session
    asi_session=sevEnvironment(sev_session)

    ;get session cell view
    cv=asiGetTopCellView(asi_session)

    ;get simulator name
    simName=asiGetSimName(asi_session)

    ;get state name
    stateName=car(form->name->value)

    ;artist states directory
    defaultSaveDir=MOTOgetStateSaveDir(sev_session)

    ;get default artist state directory
    defaultStateDir=strcat(defaultSaveDir "/" cv~>libName "/"
    cv~>cellName "/" simName "/" stateName)

    ;get state defined model file
    modelSetupFile=strcat(defaultStateDir "/modelSetup")

    ;get system defined model list
    systemModelList=asiGetEnvOptionVal(asi_session "modelFiles")

    when(systemModelList && isFile(modelSetupFile)

    ;get state defined model list
    stateModelList=MOTOreadModelFile(modelSetupFile)

    ;compare state and system model lists
    diff=setof(filex stateModelList member(filex
    systemModelList)==nil)

    when(diff

    str="The model files specified in the artist state\n"
    str=strcat(str "do not match the default project model
    files.\n\n")
    str=strcat(str "Are you sure that you want to load the
    artist\n")
    str=strcat(str "state model files?")

    ret=hiDisplayAppDBox(
    ?name 'mdiff
    ?dboxBanner "Model File Discrepancy"
    ?dboxText str
    ?dialogType hicQuestionDialog
    ?buttonLayout 'YesNo
    ?defaultButton 2
    ) ; hiDisplayAppDBox

    ;No, don't load state model files
    when(!ret

    ;; Turn off the from option to load the state model setup
    form->components->modelSetup->value=nil
    ) ; when

    ) ; when
    ) ; when

    return(t)

    ) ; prog
    ) ; procedure
     
    Erik Wanta, Jun 10, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.