AVEVA PDMS PML 二次开发之模糊查找工具FuzzySearch
在AVEVA Plant(PDMS)/AVEVA Marine中,要查找一个不是很清楚的元素可能有些不便,使用PML开发了一个模糊查找的小工具,如下图所示:
使用方法:
1. 在key word中输入需要查找的部件的名字或名字的一部分;
2. 也可输入通配符,如*表示求知的任意几个字符, ?表示求知的一个字符;
3. 查找到的元素将会在列表中显示出来,在列表中选择,将会在模型中定位到选择的元素;
2012.12.6
看很多人比较喜欢这个工具,将其源代码陈列如下:
1 -------------------------------------------------------------------------------
2 -- Copyright (C) 2010 eryar@163.com All Rights Reserved.
3 --
4 -- File: FuzzySearch.pmlfrm
5 -- Type: Form Definition
6 -- Group: Application
7 -- Keyword: MDS
8 -- Module: DESIGN
9 --
10 -- Author: eryar@163.com
11 -- Created: 2012-8-15 19:22
12 --
13 -- Description: Fuzzy search element.
14 --
15 -------------------------------------------------------------------------------
16 setup form !!fuzzysearch
17 !this.formtitle = 'Fuzzy Search'
18 !this.cancelCall = '!this.OnCancel()'
19 !this.formRevision = '0.1v'
20
21 frame .fuzzySearchFrame
22 text .tKeyWord 'Key Word:' width 18 is string
23 button .bGo 'Go' callback '!this.OnOk()'
24 button .bHelp '?' callback '!this.OnHelp()'
25 list .lResult at xmin.tKeyWord ymax+0.2 width 36 height 16
26 exit
27
28 path down
29
30 button .bCancel 'Cancel' callback '!this.OnCancel()'
31
32 exit
33 -------------------------------------------------------------------------------
34 --
35 -- Method: fuzzySearch()
36 --
37 -- Description: default constructor.
38 --
39 -- Method Type: Function/Procedure
40 -- Arguments:
41 -- [#] [R/RW] [Data Type] [Description]
42 -- Return:
43 -- [Data Type] [Description]
44 --
45 -------------------------------------------------------------------------------
46 define method .fuzzysearch()
47 !this.lResult.callback = '!this.zoomSelection()'
48 endmethod
49 -------------------------------------------------------------------------------
50 --
51 -- Method: apply()
52 --
53 -- Description: apply the operation.
54 --
55 -- Method Type: Function/Procedure
56 -- Arguments:
57 -- [#] [R/RW] [Data Type] [Description]
58 -- Return:
59 -- [Data Type] [Description]
60 --
61 -------------------------------------------------------------------------------
62 define method .OnOk()
63 -- 1. Check the input name;
64 if(!this.tKeyWord.val.Empty()) then
65 !!alert.message('Please input the key word!')
66 return
67 endif
68
69 -- 2. Collect all elements for the whole world;
70 var !allElements collect all for world
71
72 -- 3. Search the element include the keyword;
73 -- If include the keyword, add the element to
74 -- the result list.
75 !dtext = array()
76 !rtext = array()
77 !strName= string()
78 !strKeyWord = !this.tKeyword.val
79
80 do !element values !allElements
81 --
82 !current = object dbref(!element)
83 !strName = !current.namn
84
85 if(!strName.MatchWild(!strKeyWord)) then
86 !dtext.append(!strName)
87 !rtext.append(!element)
88 endif
89
90 enddo
91
92 -- 4. Add to the result list.
93 !this.lResult.dtext = !dtext
94 !this.lResult.rtext = !rtext
95
96 endmethod
97 -------------------------------------------------------------------------------
98 --
99 -- Method: ZoomSelection()
100 --
101 -- Description: Zoom to the selected element.
102 --
103 -- Method Type: Function/Procedure
104 -- Arguments:
105 -- [#] [R/RW] [Data Type] [Description]
106 -- Return:
107 -- [Data Type] [Description]
108 --
109 -------------------------------------------------------------------------------
110 define method .ZoomSelection()
111 !selection = !this.lResult.Selection()
112 !selected = object dbref(!selection)
113
114 -- Zoom to selection.
115 add $!selected
116 auto $!selected
117
118 endmethod
119 -------------------------------------------------------------------------------
120 --
121 -- Method: OnCancel()
122 --
123 -- Description:
124 --
125 -- Method Type: Function/Procedure
126 -- Arguments:
127 -- [#] [R/RW] [Data Type] [Description]
128 -- Return:
129 -- [Data Type] [Description]
130 --
131 -------------------------------------------------------------------------------
132 define method .OnCancel()
133 !this.hide()
134 endmethod
135 -------------------------------------------------------------------------------
136 --
137 -- Method: OnHelp()
138 --
139 -- Description: Show how to use information.
140 --
141 -- Method Type: Function/Procedure
142 -- Arguments:
143 -- [#] [R/RW] [Data Type] [Description]
144 -- Return:
145 -- [Data Type] [Description]
146 --
147 -------------------------------------------------------------------------------
148 define method .OnHelp()
149 !!alert.message('In the KeyWord * for any number of characters and ? for any single chararcter.')
150 endmethod
151 -------------------------------------------------------------------------------