Contents of Chapter 9 9 Exercises
Sections 1 – 3 listed on the next page.
5. Add the programs for opening the file chooser for the Open and Save Buttons.
Exercises
Exercise 5
EXTRA
Change the value for the attribute that sets the scroll position in the text editor when a new text is opened. Set the values so, that the upper left corner of the text is visible.
The attributes for the VS_TEXT_ EDITOR can be found from the Visual SCIL Objects manual.
Set the properties for the text editor so, that when a text is opened the upper left corner of the text will be visible.
ABB Oy, P288 (En ), 31 1MR751 495-MTR
Exercise 6
6
Add the following features tothe dialog (dlg_Setup) created in the exercise 3.
If the text in the text editor is changed a confirmation dialog will appear when trying to close the Setup dialog or when trying to open another text. The user can select weather to continue (OK) or abort (Cancel).
Exercise 6
Exercises
Create the private method Show_Message in the dialog (dlg_Setup).
#if argument(1)=="CLOSE" #then @v_Apply=(- ".set ._open=FALSE",-
"PARENT._queue_for_execution("".On_Exit"")",- ".delete THIS")
#if argument(1)=="OPEN" #then @v_Apply=(- ".set ._open=FALSE",-
"PARENT._queue_for_execution("".On_Open"")",- ".delete THIS")
.create THIS\ndg_Notice = vs_notice_dialog(- _notice_icon = "ICON_CAUTION",-
_title = "Confirmation",-
_text = "Continue without saving?",- _has_ok = TRUE,-
_has_cancel = TRUE,-
_geometry = list(x=-500, y=-500, w=100, h=100),- _apply = %v_Apply,-
These are the attributes for the VS_NOTICE_DIALOG object. For more information see Visual SCIL Objects manual.
ABB Oy, P288 (En ), 33 1MR751 495-MTR
Exercise 6
Create two private methods (On_Open, On_Exit) in the dialog (dlg_Setup).
.set THIS._open=FALSE .delete THIS @t_Action="OPEN" mdl_File_Chooser.Set_Mode("OPEN") mdl_File_Chooser.Set_Caller_Action("ROOT.File_Open") mdl_File_Chooser.Select_Path_Selection("PATH") .set mdl_File_Chooser._open = TRUE
mdl_File_Chooser.Set_Path("USER_PAR") On_Exit
On_Open
Exercise 6
Exercises
Change the NOTIFYmethods for the
Open and Save buttons.
#if PARENT\txe_Editor._text_is_modified==TRUE #then- PARENT.Show_Message("OPEN")
#else PARENT.On_OPEN @t_Action="SAVE"
PARENT\mdl_File_Chooser.Set_Mode("SAVE")
PARENT\mdl_File_Chooser.Set_Caller_Action("ROOT.File_Save") .set PARENT\mdl_File_Chooser._open = TRUE
ABB Oy, P288 (En ), 35 1MR751 495-MTR
Exercise 6
Do the changes listed below in the following two methods.
#if THIS\txe_Editor._text_is_modified==TRUE #then- THIS.Show_Message(“CLOSE”)
#else THIS.On_Exit
#if PARENT\txe_Editor._text_is_modified==TRUE #then- PARENT.Show_Message(“CLOSE”)
#else PARENT.On_Exit
CLOSE_NOTIFYmethod for the dialog (dlg_Setup)
NOTIFYmethod for the OK button (btn_OK) THIS.On_Exit
PARENT.On_Exit
Exercise 6
Exercises
Make the following changes in the public method
Notify_File_Chooser.
@l_File_Attr=argument(1)
#if (l_File_Attr:Vt_event=="APPLY") and (%t_Action=="OPEN") #then #block .set THIS\txe_Editor._text_vector=-
read_text(l_File_Attr:Vt_absolute_full_path) .set txe_Editor._text_is_modified=FALSE
txe_Editor._scroll_position_into_view(1,1) #block_end
#if (l_File_Attr:Vt_event=="APPLY") and (%t_Action=="SAVE") #then #block @i_Status=write_text(l_File_Attr:Vt_absolute_full_path,-
THIS\txe_Editor._text_vector,0) .set txe_Editor._text_is_modified=FALSE #block_end
ABB Oy, P288 (En ), 37 1MR751 495-MTR
Exercise 7
7
Create a VS_DIALOG (dlg_P_Object)in the object list and add the following features to the dialog.
The dialog contains a VS_NOTEBOOK with two pages. On the Setup page conditions for searching process objects can be set. On the Process Objects pages the search result is displayed.
Exercises
Exercise 7
Create a new dialog in the Object List and name it dlg_P_Object..
Set these attributes on the Window page for the dlg_P_Object dialog.
Enter the dialog title in the Text Translation Database.
ABB Oy, P288 (En ), 39 1MR751 495-MTR
Exercise 7
Name: btn_CloseTitle: @btn_Close (Close)
Insert the following objects to the dialog.
PARENT.On_Exit
Name: nbk_Notebook Title:
Create the private method
On_Exitin the dialog .
.set THIS._open=FALSE .delete THIS
Write the following line in the CLOSE_NOTIFYmethod for the dialog.
THIS.On_Exit
Exercises
Exercise 7
Edit the VS_NOTEBOOK and add two VS_NOTEBOOK_PAGEs to it.
ABB Oy, P288 (En ), 41 1MR751 495-MTR
Exercise 7
Name: nbp_ObjectsTitle: @nbp_Objects (Process Objects)
Insert these objects on the nbp_Objects notebook page. Name: lst_Objects Title Name: hdr_Header Title:
Edit the first page and do the following:
Edit the second page and do the following:
Exercises
Exercise 7
Name: nbp_Setup
Title: @nbp_Setup (Setup)
Name: chk_IU
Title: @chk_IU (In Use (IU)) Name: chk_SS
Title: @chk_SS (Switch State (SS)) Name: chk_PT
Name: lbl_Condition
Title: @lbl_Condition (Search Condition)
Name: btn_Search Title: @btn_Search (Search) Name: box_Attr Title: @box_Attr (Attributes) Name: lbl_Count Title: @lbl_Count (Objects Found:) Name: lbl_Found Title:
ABB Oy, P288 (En ), 43 1MR751 495-MTR
Exercise 7
Open the nbp_Setup page and create the following three private methods:
#error ignore
@v_Attributes=vector()
#if THIS\chk_IU._value==1 #then @v_Attributes=append(%v_Attributes,"IU") #if THIS\chk_SS._value==1 #then @v_Attributes=append(%v_Attributes,"SS") #if THIS\chk_PT._value==1 #then @v_Attributes=append(%v_Attributes,"PT") #if THIS\chk_ZT._value==1 #then @v_Attributes=append(%v_Attributes,"ZT") @i_Status=status
@l_Objects=application_object_list(0,"IX","A","F","",- THIS\txt_Condition._text,%v_Attributes)
@i_Status=status
#if %i_Status<>0 #then @i_Count=0 #else @i_Count=l_Objects:Vcount #error stop
#if %i_Count>0 #then- #loop_with i=1.. %i_Count
@v_LN(%i)=l_Objects:VLN(%i)
#if THIS\chk_IU._value==1 #then @v_IU(%i)=dec(l_Objects:VIU(%i)) #if THIS\chk_SS._value==1 #then @v_SS(%i)=dec(l_Objects:VSS(%i)) #if THIS\chk_PT._value==1 #then @v_PT(%i)=dec(l_Objects:VPT(%i)) #if THIS\chk_ZT._value==1 #then @v_ZT(%i)=times(l_Objects:VZT(%i)) #loop_end
Name:Get_Objects
This method searches for process objects with the conditions given on the Setup page.
Exercises
Exercise 7
THIS.Reset_Search THIS.Get_Objects @v_Attr=("IU","SS","PT","ZT") .set THIS\lbl_Found._title=dec(%i_Count) #if %i_Count>0 #then #block@i_Headers=THIS\chk_IU._value+THIS\chk_SS._value+- THIS\chk_PT._value+THIS\chk_ZT._value+1
@i_Width=263 div %i_Headers
PARENT\\lst_Objects._set_cell_text_range(1,1,"VERTICAL",%v_LN)
.create PARENT\\hdr_Header\hdi_LN = VS_HEADER_ITEM(_width=%i_Width, _title="LN") @i_Col=2
#loop_with i=1..4 @t_Tmp=%v_Attr(%i)
#if THIS\chk_'t_Tmp'._value==1 #then #block
PARENT\\lst_Objects._set_cell_text_range(1,%i_Col,"VERTICAL",%v_'t_Tmp') .create PARENT\\hdr_Header\hdi_'t_Tmp' =-
VS_HEADER_ITEM(_width=%i_Width, _title=%t_Tmp)
Name: On_Search
This method starts the search and is called when the search button is pressed.
This loop creates the header items to the header on the objects page.
ABB Oy, P288 (En ), 45 1MR751 495-MTR
Exercise 7
.set PARENT\\lst_Objects._row_count=0 @v_LN=vector() @v_IU=vector() @v_SS=vector() @v_PT=vector() @v_ZT=vector() #error ignore .delete PARENT\\hdr_Header\hdi_LN .delete PARENT\\hdr_Header\hdi_IU .delete PARENT\\hdr_Header\hdi_SS .delete PARENT\\hdr_Header\hdi_PT .delete PARENT\\hdr_Header\hdi_ZT #error stop Name: Reset_SearchThis method resets the previous search before starting a new one.
Write the following lines in the
ITEM_RESIZEDmethod for the header on the objects page. @v_Items=THIS._child_objects
#loop_with i=1.. length(%v_Items) @t_Tmp=%v_Items(%i)
PARENT\lst_Objects._set_column_width(%i,THIS\'t_Tmp'._width) #loop_end
This method resizes the list columns according to
the size of the header items. Write the following line in the NOTIFYmethod for the search button on the setup page.
PARENT.On_Search
Exercises
Exercise 7
EXTRA
Create a menu item in the main dialog that opens the dialog created in exercise 7.
ABB Oy, P288 (En ), 47 1MR751 495-MTR
Exercise 8
Create a main dialog with the following features.
A tree from where process objects or command procedures can be selected.
A list showing the logical names of available objects from
the selected category. 2x
When double clicking on a row in the list the IU and CM (OX for process objects) attributes for the object in question will be displayed in the check box and the text field.
A button that terminates the dialog.
8
Exercises
Exercise 8
Create a VS_MAIN_DIALOG and insert the following
nine objects. VS_TREE Name: tre_Objects Title: <none> VS_LIST Name: lst_Objects Title: <none> VS_CHECK_BOX Name: chk_IU Title: In Use VS_TEXT Name: txt_CM VS_BUTTON Name: btn_Close Title: Close
ABB Oy, P288 (En ), 49 1MR751 495-MTR
Exercise 8
Change the following three attributes for the text box.
#if THIS._value==1 #then .set THIS._value=0 #else .set THIS._value=1
Write the following program in the
actionmethod for the check box.
Also create an icon and a title to the dialog and arrange the components using the geometry management.
Exercises
Exercise 8
.set ROOT._open=FALSE .delete ROOT ROOT.On_ExitCreate a private method (On_Exit) in the VS_MAIN_DIALOG (main)
Write these two lines in the private method.
Write this line in the CLOSE_NOTIFY method for the VS_MAIN_DIALOG (Main).
Write this line in the NOTIFY method ROOT.On_Exit
ABB Oy, P288 (En ), 51 1MR751 495-MTR
Exercise 8
.load APL = Vs_Image("Sys_Tool/Images16.vso", "Apl_Local_Hot") .load PO = Vs_Image("Sys_Tool/Images16.vso", "Obj_Process_Object") .load PO_AI = Vs_Image("Sys_Tool/Images16.vso", "Obj_Process_Object") .load PO_BI = Vs_Image("Sys_Tool/Images16.vso", "Obj_Process_Object") .load CP = Vs_Image("Sys_Tool/Images16.vso", "Obj_Command_Procedure") tre_Objects._add_root_node
tre_Objects._set_row_text(1,"Objects") tre_Objects._set_row_image(1,"ROOT\APL") tre_Objects._set_row_id(1,"ROOT_NODE") tre_Objects._expand_node(1)
Write the following program in the Init method of the main dialog.
Load the images for the tree nodes and leaves. The file image16.vso contains predefined images.
Create the root node for the tree.
Expand the root node.
tre_Objects._add_node(1,1) tre_Objects._set_row_text(2,"Process Objects") tre_Objects._set_row_image(2,"ROOT\PO") tre_Objects._set_row_id(2,"PO") tre_Objects._add_node(1,2) tre_Objects._set_row_text(3,"Command Procedures") tre_Objects._set_row_image(3,"ROOT\CP") tre_Objects._set_row_id(3,"CP") tre_Objects._add_leaf(2,1) tre_Objects._set_row_text(3,"Binary Input (10)") tre_Objects._set_row_image(3,"ROOT\PO") tre_Objects._set_row_id(3,"BI") tre_Objects._add_leaf(2,2) tre_Objects._set_row_text(4,"Analog Input (10)") tre_Objects._set_row_image(4,"ROOT\PO") tre_Objects._set_row_id(4,"AI")
Exercises
Exercise 8
Create these two private methods in the main dialog.
Create_Nodes
Create two nodes under the root node.
Create_Leafs
Create two leafs under the process object node.
ABB Oy, P288 (En ), 53 1MR751 495-MTR
Exercise 8
#local l_Tmpl_Tmp=application_object_list(0,"ix","A","","","PT==9 and IX==10") .set ROOT\lst_Objects._row_count=0
ROOT\lst_Objects._set_cell_text_range(1,1,"VERTICAL",l_Tmp.ln) ROOT\lst_Objects._scroll_position_into_view(1,1)
#local l_Tmp
l_Tmp=application_object_list(0,"ix","A","","","PT==3 and IX==10") .set ROOT\lst_Objects._row_count=0 ROOT\lst_Objects._set_cell_text_range(1,1,"VERTICAL",l_Tmp.ln) ROOT\lst_Objects._scroll_position_into_view(1,1) #local l_Tmp l_Tmp=application_object_list(0,"c") .set ROOT\lst_Objects._row_count=0 ROOT\lst_Objects._set_cell_text_range(1,1,"VERTICAL",l_Tmp.ln) ROOT\lst_Objects._scroll_position_into_view(1,1)
Create the following private methods in the main dialog.
List_AI
Lists the logical names of all process objects of analog input type in the list.
List_BI
Lists the logical names of all process objects of binary input type in the list.
List_CP
Lists the logical names of all commandprocedures in the list.
Exercises
Exercise 8
#if argument(1)==1 #then ROOT.Create_Nodes #if argument(1)==2 #then ROOT.Create_Leafs #return TRUE
.set ROOT\chk_IU._value=0 .set ROOT\txt_CM._text=""
#if THIS._get_row_id(argument(1))=="BI" #then ROOT.List_BI #else_if THIS._get_row_id(argument(1))=="AI" #then ROOT.List_AI #else .set ROOT\lst_Objects._row_count=0
.set ROOT\chk_IU._value=0 .set ROOT\txt_CM._text=""
#if THIS._get_row_id(argument(1))=="CP" #then ROOT.List_CP #else .set ROOT\lst_Objects._row_count=0
Modify the following action methods in the tree object.
Handle_Expand_Node
This method is activated when a node is expanded.
Leaf_Selected
This method is activated when a leaf is selected.
Node_Selected
This method is activated when a node is selected.
Uncheck check box and empty the text box.
ABB Oy, P288 (En ), 55 1MR751 495-MTR
Exercise 8
#local t_Tmp, l_Tmp t_Tmp=THIS._get_cell_text(THIS._selected_row,1) #if (ROOT\tre_Objects._get_row_id(ROOT\tre_Objects._selected_row))=="CP"- #then #block l_Tmp=fetch(0,"C",t_Tmp) .set ROOT\txt_CM._text=l_Tmp.cm#if l_Tmp.iu==1 #then .set ROOT\chk_IU._value=1 #else .set ROOT\chk_IU._value=0
#block_end #if (ROOT\tre_Objects._get_row_id(ROOT\tre_Objects._selected_row))=="BI"- or (ROOT\tre_Objects._get_row_id(ROOT\tre_Objects._selected_row))=="AI"- #then #block l_Tmp=fetch(0,"P",t_Tmp,10) .set ROOT\txt_CM._text=l_Tmp.ox
#if l_Tmp.iu==1 #then .set ROOT\chk_IU._value=1 #else .set ROOT\chk_IU._value=0
#block_end
Write the following program in the double_clickmethod in the list.
Set the check box and text properties depending on the command procedure IU and CM attribute values.
Set the check box and text properties depending on the process object (index 10) IU and OX attribute values.
Exercises
Exercise 8
EXTRA
Add a node for data objects to the tree. When the node is selected the data object logical names are shown in the list.
Hints:
• The data object image name
ABB Oy, P288 (En ), 57 1MR751 495-MTR
Exercise 9
Create a main dialog with the following features.
A graph where two data sets are shown.
Two labels that show the hairline intersection points with the two data sets if the hairline is enabled.
Enable / disable hairline
9
Exercises
Exercise 9
Create a VS_MAIN_DIALOG and insert the following
nine objects. VS_GRAPH Name: gra_Graph Title: <none> VS_LABEL Name: lbl_Y1 Title: Y1: VS_LABEL Name: lbl_Y1 Title: Y1: VS_CHECK_BOX Name: chk_Hairline Title: Y2: Hairline Enabled
ABB Oy, P288 (En ), 59 1MR751 495-MTR
Exercise 9
Create the following private method in the main dialog.
.set gra_Graph._background_color="BLACK" ;Add x-axis
gra_Graph._add_x_axis(1,"INTEGER","bottom",2,0) ;Set x-axis properties
@l_x_axis_prop = list(min = 0,- max = 60,- time_unit = "SECONDS",- time_format = "",- annotation_increment = 10,- annotation_font = ("M",3),- annotation_color = "RED",- tick_increment = 5,- axis_color = "GREEN",- axis_title = "Seconds",- axis_title_font = ("M",2),- axis_title_color = "YELLOW",- display_axis_title_enabled=TRUE,- grid_mode = "NONE",- grid_line_width = 1,- grid_color = "BLACK",- grid_line_style = "SOLID") gra_Graph._set_x_axis_properties(1, %l_x_axis_prop) Graph_Setup
Create and set the properties for the graph x- and y-axis.
Method continues on the following page Add the x-axis to
the graph.
Set the x-axis properties. Note that all the attributes for the x-axis have to be included even if they are not needed since there are no default values.
;Add y-axis
gra_Graph._add_y_axis(2,"INTEGER", "bottom", 1,0) ;Set y-axis properties
@l_y_axis_prop=list(min = 0,- max = 100,- annotation_increment = 50,- annotation_font = ("M",3),- annotation_color = "RED",- tick_increment = 10,- axis_color = "GREEN",- axis_title = "",- axis_title_font = ("M",1),- axis_title_color = "BLACK",- display_axis_title_enabled = FALSE,- grid_mode = "NONE",- grid_line_width = 1,- grid_color = "BLACK",- grid_line_style = "SOLID")
Exercises
Exercise 9
Method continued from the previous page
… Graph_Setup
Create and set the properties for the graph x- and y-axis.
Add the y-axis to the graph.
ABB Oy, P288 (En ), 61 1MR751 495-MTR
Exercise 9
;Add data set
gra_Graph._add_data_set(1,1,2) gra_Graph._add_data_set(2,1,2) ;Data set properties
@l_data_set_prop = list(title = "Random 1",- default_color = "RED",- show_line = TRUE,- marker_shape = "DOT",- marker_color = "YELLOW",- status_0_color = "RED",- status_9_color = "WHITE") gra_Graph._set_data_set_properties(1,%l_data_set_prop) @l_data_set_prop2 = list(title = "Random 2",-
default_color = "YELLOW",- show_line = TRUE,- marker_shape = "DOT",- marker_color = "YELLOW",- status_0_color = "YELLOW",- status_9_color = "WHITE") gra_Graph._set_data_set_properties(2,%l_data_set_prop2)
Create the following private method in the main dialog.
Data_Setup
Create and set the properties for the graph x- and y-axis.
Add the two data sets to the graph.
Set the properties for the two data sets. As with the x- and y-axis, all attributes have to be included even if they are not used.
Exercises
Exercise 9
#if chk_Hairline._value==1 #then @b_Enabled=TRUE #else @b_Enabled=FALSE
@l_hairline_prop = list(color = "GREEN",- enabled = %b_Enabled,- line_style = "ONOFFDASH",- line_width = 1,-
position = 50)
gra_Graph._set_hairline_properties(1,%l_hairline_prop) #if chk_Hairline._value==1 #then #block
@l_Data1=gra_Graph._get_hairline_intersection_point(1,1,FALSE) @l_Data2=gra_Graph._get_hairline_intersection_point(1,2,FALSE) .set lbl_Y1._title="Y1: "+dec(l_Data1:vy_value,6,2)
.set lbl_Y2._title="Y2: "+dec(l_Data2:vy_value,6,2) #block_end
#else #block
.set lbl_Y1._title="Y1: " .set lbl_Y2._title="Y2: " #block_end
Create the following private methods in the main dialog.
Hairline_Setup
Set the properties for the graph hairline.
Hairline_Value
Get the intersection points for the hairline and the data set values.
ABB Oy, P288 (En ), 63 1MR751 495-MTR