Dynamic forms

J

jmss

Guest
Hi,

Is there a way to create dynamic forms in SKILL? For example: a pull-
down button cycling through a number from 1 to 5 and when the number
is chosen a corresponding number of tabs appear or a corresponding
number of additional fields appear in the same form.

Thanks and regards,
Joăo M. S. Silva
 
Silva,
hiAddFields() and hiDeleteFields() can do this.

regards,
Suresh
jmss wrote:
Hi,

Is there a way to create dynamic forms in SKILL? For example: a pull-
down button cycling through a number from 1 to 5 and when the number
is chosen a corresponding number of tabs appear or a corresponding
number of additional fields appear in the same form.

Thanks and regards,
Joăo M. S. Silva
 
On Thu, 23 Aug 2007 21:19:13 +0530, Suresh Jeevanandam
<sureshj@DELETETHISti.com> wrote:

Silva,
hiAddFields() and hiDeleteFields() can do this.

regards,
Suresh
jmss wrote:
Hi,

Is there a way to create dynamic forms in SKILL? For example: a pull-
down button cycling through a number from 1 to 5 and when the number
is chosen a corresponding number of tabs appear or a corresponding
number of additional fields appear in the same form.

Thanks and regards,
Joăo M. S. Silva
Here's an example of form creation, including some dynamic fields. I wrote this
quite a while ago. BTW, the prefix "ofer" is because I initially wrote it as an
example to demonstrate it to somebody called "Ofer"...

/* oferExample.il

Author A.D.Beckett
Group Custom IC (UK), Cadence Design Systems Ltd.
Language SKILL
Date Feb 09, 1999
Modified Mar 02, 1999
By A.D.Beckett

Example code to demonstrate how to use various form functions,
use of loading and saving templates, dynamic field addition, etc.

Note that the templates don't include the values of the
dynamic fields - that's an exercise for the reader!

***************************************************

SCCS Info: @(#) oferExample.il 03/02/99.14:02:59 1.2

*/

/***************************************************************
* *
* oferCreateForm() *
* *
* Create the main form *
* *
***************************************************************/

procedure(oferCreateForm()
let((libName cellName viewName browse userData templateFile templateLoad
templateSave
sep1 sep2 sep3 radio optionTwo optionThree)
; template loading and saving
templateFile=hiCreateStringField(
?name 'templateFile
?prompt "Template File"
)
templateLoad=hiCreateButton(
?name 'templateLoad
?buttonText "Load"
?callback "oferLoadTemplate()"
)
templateSave=hiCreateButton(
?name 'templateSave
?buttonText "Save"
?callback "oferSaveTemplate()"
)
; cellView specification
sep1=hiCreateSeparatorField(?name 'sep1)
libName=hiCreateStringField(
?name 'libName
?prompt "Library Name"
?callback "ddsUpdateSyncWithForm()"
)
cellName=hiCreateStringField(
?name 'cellName
?prompt "Cell Name"
?callback "ddsUpdateSyncWithForm()"
)
viewName=hiCreateStringField(
?name 'viewName
?prompt "View Name"
?callback "ddsUpdateSyncWithForm()"
)
browse=hiCreateButton(
?name 'browse
?buttonText "Browse"
?callback "oferSyncBrowser()"
)
sep2=hiCreateSeparatorField(?name 'sep2)
; example radio button
radio=hiCreateRadioField(
?name 'radio
?prompt "Radio"
?choices list("One" "Two" "Three")
?value "One"
?callback list("oferRadioButtonCB()")
)
; extra entries for radio button options two and three
; these won't be mapped to start off with.
optionTwo=hiCreateStringField(
?name 'optionTwo
?prompt "Option for Two"
)
optionThree=hiCreateStringField(
?name 'optionThree
?prompt "Option for Three"
)
; the user data button
sep3=hiCreateSeparatorField(?name 'sep3)
userData=hiCreateButton(
?name 'userData
?buttonText "User Data"
?callback "oferDisplayUserDataForm()"
)
hiCreateAppForm(
?name 'oferExampleForm
?formTitle "Ofer's example form"
?fields
list(
list(templateFile 0:0 600:30 200)
list(templateLoad 100:5 45:20)
list(templateSave 150:5 45:20)
list(sep1 0:35 600:0)
list(libName 0:40 600:30 200)
list(cellName 0:70 600:30 200)
list(viewName 0:100 600:30 200)
list(browse 200:130 100:25)
list(sep2 0:165 600:0)
list(radio 0:190 600:0 200)
list(sep3 0:205 600:0)
list(userData 200:220 100:25)
)
)
; store the extra fields on the form, ready for later
oferExampleForm->extraFields=
list(nil 'optionTwo optionTwo
'optionThree optionThree)
oferExampleForm
)
)

/***************************************************************
* *
* oferCreateUserDataForm() *
* *
* Creates the user data form *
* *
***************************************************************/

procedure(oferCreateUserDataForm()
let((userFilename userRadio)
userFilename=hiCreateStringField(
?name 'userFilename
?prompt "Filename"
)
userRadio=hiCreateRadioField(
?name 'userRadio
?choices list("a" "b" "c" "d")
?value "a"
?prompt "Another Radio"
)
; example - don't bother filling
hiCreateAppForm(
?name 'oferUserDataForm
?formTitle "Ofer's User Data"
?fields list(
userFilename
userRadio
)
)
)
)

/***************************************************************
* *
* oferSaveTemplate() *
* *
* Callback code to save the template *
* *
***************************************************************/

procedure(oferSaveTemplate()
let( (fileName fport)
fileName=oferExampleForm->templateFile->value
when(fileName==""
error("Must specify template filename")
)
fport=outfile(fileName)
unless(fport
error("Could not write to template file %s" fileName)
)
fprintf(fport "oferKeys='(nil\n")
; output all of the main form keys
foreach(key '(libName cellName viewName radio)
fprintf(fport " %s %L\n" key get(oferExampleForm key)->value)
)
; output all of the user data form keys
foreach(key '(userFilename userRadio)
fprintf(fport " %s %L\n" key get(oferUserDataForm key)->value)
)
; end of the file
fprintf(fport ")\n")
close(fport)
)
)


/***************************************************************
* *
* oferLoadTemplate() *
* *
* Callback code to load the template *
* *
***************************************************************/

procedure(oferLoadTemplate()
let( (fileName fport)
fileName=oferExampleForm->templateFile->value
when(fileName==""
error("Must specify template filename")
)
; load it, and trap any errors. The file is just skill
; code, so can be loaded.
errset(load(fileName) t)
; the keys are all in a disembodied property list called oferKeys
; input all of the main form keys
; use get(), because oferKeys->key won't work, because the key variable
; needs to be evaluated.
foreach(key '(libName cellName viewName radio)
when(get(oferKeys key)
get(oferExampleForm key)->value=get(oferKeys key)
)
)
; output all of the user data form keys
foreach(key '(userFilename userRadio)
when(get(oferKeys key)
get(oferUserDataForm key)->value=get(oferKeys key)
)
)
)
)

/***************************************************************
* *
* oferSyncBrowser() *
* *
* Synchronise with the browser *
* *
***************************************************************/

procedure(oferSyncBrowser()
ddsSyncWithForm(
oferExampleForm
'browse
'libName
'cellName
'viewName
)
)

/****************************************************************
* *
* oferRadioButtonCB() *
* *
* Callback for the radio button on the form - this adds or *
* subtracts the dynamic fields. The dynamic fields *
* are created at startup, and stored in a disembodied property *
* list on the form, and the form positions are calculated based *
* on the current positions of fields on the form. *
* *
****************************************************************/

procedure(oferRadioButtonCB()
let((radioVal newOffset newPosition oldPosition
(currentOffset 0) (fieldHeight 30) newYcoord)
; determine the offset of the bottom fields at the moment
when(oferExampleForm->optionTwo
currentOffset=currentOffset+fieldHeight
)
when(oferExampleForm->optionThree
currentOffset=currentOffset+fieldHeight
)
; determine the offset that we want, based on the radio
; button value
radioVal=oferExampleForm->radio->value
newOffset=case(radioVal
("Two" fieldHeight)
("Three" fieldHeight*2)
(t 0)
)
; shift the two bottom fields by the appropriate amount
foreach(field '(sep3 userData)
; calculate the new position from the old, offset accordingly
oldPosition=car(hiGetFieldInfo(oferExampleForm field))
newPosition=xCoord(oldPosition):yCoord(oldPosition)
+newOffset-currentOffset
hiMoveField(
oferExampleForm
field
newPosition
)
)
; delete form fields if they're not needed
when(radioVal=="One" && oferExampleForm->optionTwo
hiDeleteField(oferExampleForm 'optionTwo))
when(radioVal!="Three" && oferExampleForm->optionThree
hiDeleteField(oferExampleForm 'optionThree))
; determine where the extra fields will be placed
newYcoord=yCoord(car(hiGetFieldInfo(oferExampleForm 'radio)))+10
; add the two fields if they're needed and not there already
when(radioVal=="Two" || radioVal=="Three"
unless(oferExampleForm->optionTwo
hiAddField(oferExampleForm
list(oferExampleForm->extraFields->optionTwo
0:newYcoord 600:30 200))
)
)
when(radioVal=="Three"
unless(oferExampleForm->optionThree
hiAddField(oferExampleForm
list(oferExampleForm->extraFields->optionThree
0:newYcoord+fieldHeight 600:30 200))
)
)
))


/***************************************************************
* *
* oferDisplayUserDataForm() *
* *
* Display the user data form - callback from the main form. *
* *
***************************************************************/

procedure(oferDisplayUserDataForm()
hiDisplayForm(oferUserDataForm)
)

/****************************************************************
* *
* oferExampleFormCB(form) *
* *
* The form callback - doesn't do much except print out what has *
* been entered *
* *
****************************************************************/

procedure(oferExampleFormCB(form)
printf("You entered cellView %s/%s/%s\n"
form->libName->value
form->cellName->value
form->viewName->value
)
printf("The radio button was set to %s\n"
form->radio->value
)
printf("And the user data fields were\nfilename: %s\nradio: %s\n"
oferUserDataForm->userFilename->value
oferUserDataForm->userRadio->value
)
)

/***************************************************************
* *
* oferExample() *
* *
* Main entry point *
* *
***************************************************************/

procedure(oferExample()
unless(boundp('oferExampleForm)
oferCreateForm()
)
unless(boundp('oferUserDataForm)
oferCreateUserDataForm()
)
hiDisplayForm(oferExampleForm)
)

--
Andrew Beckett
Senior Solution Architect
Cadence Design Systems, UK.
 
Here's an example of form creation, including some dynamic fields. I wrote this
quite a while ago. BTW, the prefix "ofer" is because I initially wrote it as an
example to demonstrate it to somebody called "Ofer"...
I end up using the invisibility property of the fields. The advantage
is that the fields must be created a-priori but the advantage is that
their values remain stored even if the user changes the number of
fields.

Thanks anyway. Maybe in the future I'll migrate to hiAdd and
hiDeleteField, since they're more elegant and robust.
 

Welcome to EDABoard.com

Sponsor

Back
Top