-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCAPI_LineSpacings.pas
301 lines (273 loc) · 9.61 KB
/
CAPI_LineSpacings.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
unit CAPI_LineSpacings;
interface
uses
CAPI_Utils,
CAPI_Types,
LineSpacing;
function LineSpacings_Get_Count(): Integer; CDECL;
function LineSpacings_Get_First(): Integer; CDECL;
function LineSpacings_Get_Next(): Integer; CDECL;
function LineSpacings_Get_Name(): PAnsiChar; CDECL;
procedure LineSpacings_Set_Name(const Value: PAnsiChar); CDECL;
function LineSpacings_Get_Nconds(): Integer; CDECL;
procedure LineSpacings_Set_Nconds(Value: Integer); CDECL;
function LineSpacings_Get_Phases(): Integer; CDECL;
procedure LineSpacings_Set_Phases(Value: Integer); CDECL;
function LineSpacings_Get_Units(): Integer; CDECL;
procedure LineSpacings_Set_Units(Value: Integer); CDECL;
procedure LineSpacings_Get_Xcoords(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
procedure LineSpacings_Get_Xcoords_GR(); CDECL;
procedure LineSpacings_Set_Xcoords(ValuePtr: PDouble; ValueCount: TAPISize); CDECL;
procedure LineSpacings_Get_Ycoords(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
procedure LineSpacings_Get_Ycoords_GR(); CDECL;
procedure LineSpacings_Set_Ycoords(ValuePtr: PDouble; ValueCount: TAPISize); CDECL;
procedure LineSpacings_Get_AllNames(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CDECL;
procedure LineSpacings_Get_AllNames_GR(); CDECL;
function LineSpacings_Get_idx(): Integer; CDECL;
procedure LineSpacings_Set_idx(Value: Integer); CDECL;
implementation
uses
CAPI_Constants,
sysutils,
DSSGlobals,
LineUnits,
UComplex, DSSUcomplex,
Line,
UcMatrix,
DSSClass,
DSSHelper;
//------------------------------------------------------------------------------
function _activeObj(DSS: TDSSContext; out obj: TLineSpacingObj): Boolean; inline;
begin
Result := False;
obj := NIL;
if InvalidCircuit(DSS) then
Exit;
obj := DSS.LineSpacingClass.GetActiveObj;
if obj = NIL then
begin
if DSS_CAPI_EXT_ERRORS then
begin
DoSimpleMsg(DSS, 'No active %s object found! Activate one and retry.', ['LineSpacing'], 8989);
end;
Exit;
end;
Result := True;
end;
//------------------------------------------------------------------------------
function LineSpacings_Get_Count(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.LineSpacingClass.ElementCount;
end;
//------------------------------------------------------------------------------
function LineSpacings_Get_First(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.LineSpacingClass.First;
end;
//------------------------------------------------------------------------------
function LineSpacings_Get_Next(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.LineSpacingClass.Next;
end;
//------------------------------------------------------------------------------
function LineSpacings_Get_Name(): PAnsiChar; CDECL;
var
pLineSpacing: TLineSpacingObj;
begin
Result := NIL; // signify no name
if not _activeObj(DSSPrime, pLineSpacing) then
Exit;
Result := DSS_GetAsPAnsiChar(DSSPrime, pLineSpacing.Name);
end;
//------------------------------------------------------------------------------
procedure LineSpacings_Set_Name(const Value: PAnsiChar); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
if not DSSPrime.LineSpacingClass.SetActive(Value) then
DoSimpleMsg(DSSPrime, 'LineSpacing "%s" not found in Active Circuit.', [Value], 51008);
// Still same active object if not found
end;
//------------------------------------------------------------------------------
function LineSpacings_Get_Nconds(): Integer; CDECL;
var
pLineSpacing: TLineSpacingObj;
begin
Result := 0;
if not _activeObj(DSSPrime, pLineSpacing) then
Exit;
Result := pLineSpacing.NWires;
end;
//------------------------------------------------------------------------------
procedure LineSpacings_Set_Nconds(Value: Integer); CDECL;
var
pLineSpacing: TLineSpacingObj;
begin
if (Value < 1) then
begin
DoSimpleMsg(DSSPrime, 'Invalid number of conductors (%d) sent via C-API. Please use a value within the valid range (>0).', [Value], 183);
end;
if not _activeObj(DSSPrime, pLineSpacing) then
Exit;
pLineSpacing.FNConds := Value;
pLineSpacing.PropertySideEffects(ord(TLineSpacingProp.NConds), 0);
end;
//------------------------------------------------------------------------------
function LineSpacings_Get_Phases(): Integer; CDECL;
var
pLineSpacing: TLineSpacingObj;
begin
Result := 0;
if not _activeObj(DSSPrime, pLineSpacing) then
Exit;
Result := pLineSpacing.NPhases;
end;
//------------------------------------------------------------------------------
procedure LineSpacings_Set_Phases(Value: Integer); CDECL;
var
pLineSpacing: TLineSpacingObj;
begin
if not _activeObj(DSSPrime, pLineSpacing) then
Exit;
pLineSpacing.DataChanged := TRUE;
pLineSpacing.NPhases := Value;
end;
//------------------------------------------------------------------------------
procedure LineSpacings_Set_Units(Value: Integer); CDECL;
var
pLineSpacing: TLineSpacingObj;
begin
if not _activeObj(DSSPrime, pLineSpacing) then
Exit;
pLineSpacing.Units := Value;
pLineSpacing.DataChanged := TRUE;
end;
//------------------------------------------------------------------------------
function LineSpacings_Get_Units(): Integer; CDECL;
var
pLineSpacing: TLineSpacingObj;
begin
Result := 0;
if not _activeObj(DSSPrime, pLineSpacing) then
Exit;
Result := pLineSpacing.Units;
end;
//------------------------------------------------------------------------------
procedure LineSpacings_Set_Ycoords(ValuePtr: PDouble; ValueCount: TAPISize); CDECL;
var
pLineSpacing: TLineSpacingObj;
begin
if not _activeObj(DSSPrime, pLineSpacing) then
Exit;
with pLineSpacing do
begin
if NWires <> ValueCount then
begin
DoSimpleMsg(
'The number of values provided (%d) does not match the number of wires (%d).',
[ValueCount, NWires],
183);
Exit;
end;
Move(ValuePtr^, FY[1], ValueCount * SizeOf(Double));
DataChanged := TRUE;
end;
end;
//------------------------------------------------------------------------------
procedure LineSpacings_Get_Ycoords(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
var
pLineSpacing: TLineSpacingObj;
begin
if not _activeObj(DSSPrime, pLineSpacing) then
begin
DefaultResult(ResultPtr, ResultCount);
Exit;
end;
with pLineSpacing do
begin
DSS_RecreateArray_PDouble(ResultPtr, ResultCount, NWires);
Move(FY[1], ResultPtr^, ResultCount^ * SizeOf(Double));
end;
end;
procedure LineSpacings_Get_Ycoords_GR(); CDECL;
// Same as LineSpacings_Get_Ycoords but uses global result (GR) pointers
begin
LineSpacings_Get_Ycoords(DSSPrime.GR_DataPtr_PDouble, @DSSPrime.GR_Counts_PDouble[0])
end;
//------------------------------------------------------------------------------
procedure LineSpacings_Set_Xcoords(ValuePtr: PDouble; ValueCount: TAPISize); CDECL;
var
pLineSpacing: TLineSpacingObj;
begin
if not _activeObj(DSSPrime, pLineSpacing) then
Exit;
with pLineSpacing do
begin
if NWires <> ValueCount then
begin
DoSimpleMsg(
'The number of values provided (%d) does not match the number of wires (%d).',
[ValueCount, NWires],
183);
Exit;
end;
Move(ValuePtr^, FX[1], ValueCount * SizeOf(Double));
DataChanged := TRUE;
end;
end;
//------------------------------------------------------------------------------
procedure LineSpacings_Get_Xcoords(var ResultPtr: PDouble; ResultCount: PAPISize); CDECL;
var
pLineSpacing: TLineSpacingObj;
begin
if not _activeObj(DSSPrime, pLineSpacing) then
begin
DefaultResult(ResultPtr, ResultCount);
Exit;
end;
with pLineSpacing do
begin
DSS_RecreateArray_PDouble(ResultPtr, ResultCount, NWires);
Move(FX[1], ResultPtr^, ResultCount^ * SizeOf(Double));
end;
end;
procedure LineSpacings_Get_Xcoords_GR(); CDECL;
// Same as LineSpacings_Get_Xcoords but uses global result (GR) pointers
begin
LineSpacings_Get_Xcoords(DSSPrime.GR_DataPtr_PDouble, @DSSPrime.GR_Counts_PDouble[0])
end;
//------------------------------------------------------------------------------
procedure LineSpacings_Get_AllNames(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CDECL;
begin
DefaultResult(ResultPtr, ResultCount);
if InvalidCircuit(DSSPrime) then
Exit;
Generic_Get_AllNames(ResultPtr, ResultCount, DSSPrime.LineSpacingClass.ElementList, False);
end;
procedure LineSpacings_Get_AllNames_GR(); CDECL;
// Same as LineSpacings_Get_AllNames but uses global result (GR) pointers
begin
LineSpacings_Get_AllNames(DSSPrime.GR_DataPtr_PPAnsiChar, @DSSPrime.GR_Counts_PPAnsiChar[0])
end;
//------------------------------------------------------------------------------
function LineSpacings_Get_idx(): Integer; CDECL;
begin
Result := DSSPrime.LineSpacingClass.ElementList.ActiveIndex
end;
//------------------------------------------------------------------------------
procedure LineSpacings_Set_idx(Value: Integer); CDECL;
begin
if DSSPrime.LineSpacingClass.ElementList.Get(Value) = NIL then
DoSimpleMsg(DSSPrime, 'Invalid %s index: "%d".', ['LineSpacing', Value], 656565);
end;
//------------------------------------------------------------------------------
end.