Write a PCL class that creates a simple form with a single button on it. Pressing the button should display a message in the MSC.Patran history window, e.g., “Help me I’m being pushed around!”
-
Built-in functions:
ui_form_create(callback, x_loc, y_loc, position, width, @
height, label, iconname)
ui_button_create(parent, callback, x_loc, y_loc, width, @
height, label, flag, highlight)
ui_form_display(classname)
-
Your class should contain the following functions:
init(), display(), button_cb()
Extra credit: Using ui_wid_set(…) in the button callback function, have the label on the button change after it has been pressed to “Push Me Again!”
Extra credit: Add a “Cancel” button to hide the form. In its callback function use the ui_form_hide(…) function to hide the form.
The constants to define the standard widget sizes and spacing are defined in the include file appforms.p (see Appendix D). These definitions are linked into your file by using the C-preprocessor statement #include.
#include “appforms.p”
-
The substitutions are made using the C-preprocessor program cpp.
-
Only PCL programs that build forms need these constants and therefore need to run this program.
-
The C-preprocessor is run with the following syntax:
cpp –I
/customization –C –P filename.pcl filename.pob
Where
/customization is the path to the directory where the appforms.p file resides. The output of this operation (filename.pob) can then be compiled using !!input or !!compile.
-
Generally, you will want to use make and Makefiles to automatically execute cpp. A sample Makefile is included on the next page.
-
Additionally, the MSC.Patran shareware utilities also include some functions for compiling that automatically execute cpp. See Appendix F for the details on these functions.
The C-Preprocessor and Include Files
Make Files -
Make file are typically used to compile PCL programs when many functions or forms are involved.
-
Make files are a UNIX utility used for compiling programs.
-
Make files will automatically run cpp and then compile the PCL into a library.
-
Make only recompiles the files that were edited.
-
Make will work with many different files and functions in a single Makefile.
-
A sample make file can be found in the customization directory:
# Name of the target pcl library
PclLibrary = hole.plb
# List of .pob files that go into the library
# Each of these files should have a corresponding .pcl file
PclObjects = insert_hole.pob \
update_props.pob
# List of possible include files
# If any of these is touched, all .pcl files will be blindly recompiled
IncludeFiles = /msc/patran2001/customization
# Script for invoking the standalone pcl compiler
PCLCOMP = /msc/patran2001/customization/Pclcomp
# Command for compiling a single preprocessed pcl source file
COMPILE = $(PCLCOMP) $(PCFLAGS) -pob $*.CPP
# Possible locations for finding the executable for cpp
CPPLIST = /usr/lang/cpp /usr/ccs/lib/cpp /lib/cpp /usr/lib/cpp
# cpp arguments for preprocessing a single pcl source file
CPPARGS = -I$(IncludeFiles) -C $*.pcl >$*.CPP
# Define the possible file suffixes
.SUFFIXES: .pcl .pob .plb
# Make sure that the bourne shell is used to invoke subcommands
The C-Preprocessor and Include Files
SHELL = /bin/sh
# Define a rule for converting a .pcl source file to a .pob object.
# This rule is somewhat ugly because 1) it attempts to intelligently
# locate the cpp executable given that it often is not on the default
# search path and 2) we need to make sure that the .pob file gets
# deleted if the compilation fails! We use "@" carefully so as to not
# clutter the screen while make is running.
.pcl.pob:
@ rm -f $*.ERROR
@ CPP='' ; \
for i in $(CPPLIST) ; do \
if [ -f $$i ] ; then \
CPP="$$i" ; \
fi ; \
done ; \
echo "$$CPP $(CPPARGS)" ; \
$$CPP $(CPPARGS)
@echo $(COMPILE)
-@ $(COMPILE) ; \
if [ $$? -ne 0 ] ; then \
rm -rf $*.pob ; \
touch $*.ERROR ; \
else \
# rm -rf $*.CPP ; \
exit 0 ; \
fi
@ echo
@ if [ -f $*.ERROR ] ; then \
rm -f $*.ERROR ; \
exit 1 ; \
else \
exit 0 ; \
fi
# Merge all .pobs into the target
$(PclLibrary): $(PclObjects)
$(PCLCOMP) $(PCFLAGS) -m tmp.plb $(PclObjects) ;\
mv tmp.plb $(PclLibrary) ;\
rm -f tmp.plb *.pob
# Define the include file dependencies
$(PclObjects): $(IncludeFiles)
# Finally, define a "clean" rule
clean:
rm -f $(PclObjects) $(PclLibrary) *.CPP Makefile.log tmp.plb
Exercise 9: Callbacks
Write a PCL function that creates a form with 3 toggles and 2 databoxes that accept football scores. Hitting the “Apply” button writes the scores to the session file.
-
Only 1 toggle should be selected at a time. That is, selecting one toggle should deselect any other toggle that is selected.
-
The toggles should be in a frame.
-
Selecting a particular toggle should update the team names (labels) on the databoxes.
-
Built-in functions:
ui_form_create(callback, x_loc, y_loc, position, width, height, label, iconname)
ui_frame_create(parent, callback, x_loc, y_loc, width, height, label)
ui_toggle_create(parent, callback, x_loc, y_loc, label)
ui_databox_create(parent, callback, x_loc, y_loc, label_length, box_length, @
label, value, label_above, datatype, num_vals)
ui_button_create(parent, callback, x_loc, y_loc, width, height, label, flag, @
highlight)
ui_separator_create(parent, callback, x_loc, y_loc, width, horizontal_flag)
ui_wid_set(widget, parameter, value)
-
Your class should contain the following functions:
i
Extra credit: A better way to create this form would be to use a switch instead of toggles. Replace the toggles with a switch using the ui_switch_create(…) and ui_item_create(…) functions.
nit(), display(), cancel_btn_cb(), apply_btn_cb(), multiple toggle_cb()
E
FORM_X_LOC, FORM_Y_LOC
xercise 9
Share with your friends: |