1
2 """
3 """
4
5 __author__ = "Keysight Technologies, Inc."
6 __version__ = "1.0"
9 '''
10 decorator to print exception to output
11 '''
12 def op(*args, **kwargs):
13 try:
14 return func(*args, **kwargs)
15 except:
16 import traceback
17 print traceback.format_exc()
18 op.__name__ == func.__name__
19 op.__doc__ == func.__doc__
20 return op
21
24 for l in lst:
25 if not hasattr(l, "resultType") or l.resultType!="SParameters":
26 return False
27 return True
28
30 qls = []
31 newTypeS = { "Voltage (V)" : "V",
32 "Current (I)" : "I" ,
33 "Impedance" : "Impedance" ,
34 "Component Loss" : "ComponentLoss",
35 }[newType]
36 for q in ql:
37 q.resultType = newTypeS
38 qls.append( q )
39 return qls
40
41 @_printexception
42 -def _showView( ql, newType ):
43 import empro
44 ql = _changeResultType( ql, newType )
45 empro.gui.ResultViewingUtils.displayDefaultViewForResultQueries( ql )
46
50 R=()
51 freqPlan=()
52 freqs=s[1,1].real.dimension(0)
53 numFreqs=freqs.size()
54
55 for k in range(0,numFreqs):
56 freqPlan+=(freqs[k],)
57 Rval=(-1/y[i,j][k]).real
58 R+=(Rval,)
59
60 return (R,freqPlan)
61
64 import math
65 L=()
66 freqPlan=()
67 freqs=s[1,1].real.dimension(0)
68 numFreqs=freqs.size()
69
70 for k in range(0,numFreqs):
71 if freqs[k]>0.0:
72 freqPlan+=(freqs[k],)
73 Lval=(-1/y[i,j][k]).imag/(2*math.pi*freqs[k])
74 L+=(Lval,)
75 return (L,freqPlan)
76
80 import math
81 C=()
82 freqPlan=()
83 freqs=s[1,1].real.dimension(0)
84 numFreqs=freqs.size()
85
86 for k in range(0,numFreqs):
87 if freqs[k]>0.0:
88 freqPlan+=(freqs[k],)
89 Cval=(-1/(1/(y[i,i][k]+y[i,j][k])).imag)/(2*math.pi*freqs[k])
90 C+=(Cval,)
91 return (C,freqPlan)
92
93 @_printexception
94 -def _showRLCView( ql, newType, whatComponent ):
95 import empro
96 from empro.toolkit import portparam
97 from empro.toolkit import dataset
98 from empro.toolkit import graphing
99
100 Ss = {}
101 Ys = {}
102
103 derivFunction, captionPrefix, unitClassStr = {
104 'R' : ( _computeRes, "R (Ohm) ", "ELECTRIC_RESISTANCE", ),
105 'L' : (_computeInd, "L (H) ", "INDUCTANCE", ),
106 'C' : (_computeCap, "C (F) ", "ELECTRIC_CAPACITANCE", ),
107 }[whatComponent]
108
109 toolTips = {
110 'R' : "R = -1/Y[i,j]",
111 'L' : "L = imag(-1/Y[i,j])/(2*PI*Frequency)",
112 'C' : "C = imag(-1/(1/(Y[i,i]+Y[i,j])))/(2*PI*Frequency)",
113 }
114
115 for q in ql:
116 if q.simulationId not in Ss:
117 s = portparam.getSMatrix(sim=q.simulationId)
118 if not s.isSquare():
119 simId = str(q.simulationId)
120 empro.gui.MessageBox.critical("Failed to show result", "Can not show derived result. S-Parameters are not complete for simulation %(simId)s." % vars(), empro.gui.Ok, empro.gui.Ok)
121 return
122 y = portparam.stoy(s)
123 Ss[q.simulationId] = s
124 Ys[q.simulationId] = y
125
126 Rg=()
127 for q in ql:
128 try:
129 s = Ss[q.simulationId]
130 y = Ys[q.simulationId]
131
132 q.resultType = "SParameters"
133 i, j = empro.gui.ResultViewingUtils.getSParameterDesignation(q)
134 if i<0 or j<0:
135 continue
136
137 Rres = derivFunction(s, y, i, j)
138 R = Rres[0]
139 Freq= dataset.makeDataSet(Rres[1],unitClass="FREQUENCY")
140 caption = "Simulation %s: " % q.simulationId
141 Rcap=captionPrefix + caption
142 Res=dataset.makeDataSet(R,name=Rcap, dimensions=[Freq],unitClass=unitClassStr)
143 Rg+=(Res,)
144 except:
145 pass
146
147 if Rg:
148 name = whatComponent + " vs. frequency"
149 graph = graphing.showXYGraph(Rg,title=name + "\n" + toolTips[whatComponent])
150 graph.name = name
151 empro.gui.activeProjectView().showGraph( graph )
152
153 @_printexception
154 -def _showSmith( ql, newType ):
155 import empro
156 ql = _changeResultType( ql, newType )
157 empro.gui.ResultViewingUtils.showSmithChartFor( ql, -1 )
158
161 import empro
162 ql = _changeResultType( ql, newType )
163 empro.gui.ResultViewingUtils.doView1DResultsFor( ql )
164
167 import empro
168 ql = _changeResultType( ql, newType )
169 empro.gui.ResultViewingUtils.doCopyPythonCommand( ql )
170
173 '''
174 '''
175 import empro
176 if not _allSParameters(selection):
177 return
178
179 addDerivedResultMenu = empro.core.ApplicationPreferences.getPreference("CompactResults",True) != "false"
180 for q in selection:
181 if q.outputObjectId[0] == "CircuitMatrix":
182 addDerivedResultMenu = False
183 if not addDerivedResultMenu:
184 return None
185
186 empro.internal._showListsActions = []
187 derivMenu = empro.gui.Menu("Derived Results")
188
189 for derivativeName in ["Voltage (V)","Current (I)","Impedance", "Component Loss"]:
190 menu = empro.gui.Menu(derivativeName)
191 ql = _changeResultType( selection, derivativeName )
192
193 if empro.gui.ResultViewingUtils.canDoGraphViewsFor( ql ) or empro.gui.ResultViewingUtils.canDoFieldViewsFor(ql):
194 viewAction = empro.gui.Action("View (default)")
195 viewAction.onTriggered = lambda x, y=ql,z=derivativeName: _showView( y, z )
196 empro.internal._showListsActions.append( viewAction )
197 menu.addAction( viewAction )
198
199 if empro.gui.ResultViewingUtils.canDoSmithChartFor( ql ):
200 viewSmithAction = empro.gui.Action("View Smith Chart")
201 viewSmithAction.onTriggered = lambda x, y=ql,z=derivativeName: _showSmith( y, z )
202 empro.internal._showListsActions.append( viewSmithAction )
203 menu.addAction( viewSmithAction )
204
205 if empro.gui.ResultViewingUtils.canDoView1DResultsFor( ql ):
206 createLineAction = empro.gui.Action("Create Line Graph...")
207 createLineAction.onTriggered = lambda x, y=ql,z=derivativeName: _showLineAction( y, z )
208 empro.internal._showListsActions.append( createLineAction )
209 menu.addAction( createLineAction )
210
211 if empro.gui.ResultViewingUtils.canDoPythonCommand( ql ):
212 copyPythonAction = empro.gui.Action("Copy Python Expression")
213 copyPythonAction.onTriggered = lambda x, y=ql,z=derivativeName: _copyPythonExpression( y, z )
214 empro.internal._showListsActions.append( copyPythonAction )
215 menu.addAction( copyPythonAction )
216
217 derivMenu.addMenu(menu)
218
219
220 projectIds = set([q.projectId for q in selection])
221
222 toolTips = {
223 'R' : "Resistance computed as\nR = -1/Y[i,j]",
224 'L' : "Inductance computed as\nL = imag(-1/Y[i,j])/(2*PI*Frequency)",
225 'C' : "Capacitance computed as\nC = imag(-1/(1/(Y[i,i]+Y[i,j])))/(2*PI*Frequency)",
226 }
227
228
229 if len(projectIds) == 1 and empro.activeProject.rootDir==projectIds.pop():
230 if empro.gui.ResultViewingUtils.canDoView1DResultsFor( selection ):
231 for derivativeName, component in [ ("R (Zref=50 Ohm)", 'R'), ("L (Zref=50 Ohm)", 'L'), ("C (Zref=50 Ohm)", 'C')]:
232 menu = empro.gui.Menu(derivativeName)
233 viewAction = empro.gui.Action("View (default)")
234 viewAction.toolTip = toolTips[ component ]
235 viewAction.statusTip = toolTips[ component ]
236 viewAction.whatsThis = toolTips[ component ]
237 viewAction.onTriggered = lambda x, y=selection,z=derivativeName,w=component: _showRLCView( y, z, w )
238 empro.internal._showListsActions.append( viewAction )
239 menu.addAction( viewAction )
240 derivMenu.addMenu(menu)
241
242 return derivMenu
243
244 """
245
246 Use this file as add-on by uncommenting the next lines and placing it in the add-on
247 location.
248
249 def _defineAddon():
250 from empro.toolkit import addon
251 return addon.AddonDefinition(onContextMenu=_onContextMenu)
252
253 """
256 """
257 Used by the platform to dynamically extend the context menu of the results browser. As a user
258 this can be done through the add-on mechanics.
259 """
260 tempMenu = _onContextMenu( queryList, [type(x) for x in queryList] )
261 if tempMenu:
262 menu.addMenu( tempMenu )
263