-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDSSClass.cpp
395 lines (309 loc) · 10.7 KB
/
DSSClass.cpp
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#pragma hdrstop
#include "DSSClass.h"
#include "DSSObject.h"
#include "CktElement.h"
#include "DSSGlobals.h"
namespace DSSClass
{
/*--------------------------------------------------------------*/
/* DSSClasses Implementation
{--------------------------------------------------------------*/
//TDSSClasses::TDSSClasses() {};
TDSSClasses::TDSSClasses()
{
//inherited();
}
/*--------------------------------------------------------------*/
TDSSClasses::~TDSSClasses()
{
// todo check: inherited::Destroy;
}
/*--------------------------------------------------------------*/
void TDSSClasses::Set_New(void* Value)
{
DSSClassList[ActiveActor].Set_New(Value); // Add to pointer list
ActiveDSSClass[ActiveActor] = (TDSSClass*)Value; // Declare to be active
ClassNames[ActiveActor].Add(ActiveDSSClass[ActiveActor]->get_myClass_name()); // Add to classname list
}
/*--------------------------------------------------------------*/
/* DSSClass Implementation
{--------------------------------------------------------------*/
TDSSClass::TDSSClass()
: ElementNameList(THashList(100)),
ElementList(TPointerList(20))
{
ActiveElement = 0;
ActiveProperty = 0;
NumProperties = 0;
DSSClassType = 0;
ElementNamesOutOfSynch = false;
Saved = false;
// inherited::Create();
PropertyName = NULL;
PropertyHelp = NULL;
PropertyIdxMap = NULL;
RevPropertyIdxMap = NULL;
ActiveElement = 0;
ActiveProperty = 0;
ElementNamesOutOfSynch = false;
}
/*--------------------------------------------------------------*/
TDSSClass::~TDSSClass()
{
int i = 0;
// Get rid of space occupied by strings
/*for (int stop = NumProperties, i = 1; i <= stop; i++)
PropertyName[i] = "";
for (int stop = NumProperties, i = 1; i <= stop; i++)
PropertyHelp[i] = "";
delete[] PropertyName;
delete[] PropertyHelp;
delete[] PropertyIdxMap;
delete[] RevPropertyIdxMap; */
// todo check: inherited::Destroy;
}
/*--------------------------------------------------------------*/
int TDSSClass::get_ActiveElement()
{
return ActiveElement;
}
/*--------------------------------------------------------------*/
int TDSSClass::NewObject(std::string ObjName)
{
int result = 0;
result = 0;
DoErrorMsg(String("Reached base class of TDSSClass for device \"") + ObjName + "\"", "N/A", "Should be overridden.", 780);
return result;
}
void TDSSClass::Set_Active(int Value)
{
if ((Value > 0) && (Value <= ElementList.get_myNumList()))
{
ActiveElement = Value;
ActiveDSSObject[ActiveActor] = ElementList.Get(ActiveElement);
// Make sure Active Ckt Element agrees if is a ckt element
// So COM interface will work
if (dynamic_cast<TDSSCktElement*>((TDSSObject*)ActiveDSSObject[ActiveActor]) != nullptr)
ActiveCircuit[ActiveActor]->Set_ActiveCktElement((TDSSCktElement*)ActiveDSSObject[ActiveActor]);
}
}
int TDSSClass::Edit(int ActorID)
{
int result = 0;
result = 0;
DoSimpleMsg("virtual function TDSSClass.Edit called. Should be overriden.", 781);
return result;
}
int TDSSClass::Init(int Handle, int ActorID)
{
int result = 0;
result = 0;
DoSimpleMsg("virtual function TDSSClass.Init called. Should be overriden.", 782);
return result;
}
int TDSSClass::AddObjectToList(void* Obj)
{
int result = 0;
ElementList.Set_New(Obj); // Stuff it in this collection's element list
ElementNameList.Add(((TDSSObject*)Obj)->get_Name());
if (((unsigned int)ElementList.get_myNumList()) > 2 * ElementNameList.InitialAllocation)
ReallocateElementNameList();
ActiveElement = ElementList.get_myNumList();
result = ActiveElement; // Return index of object in list
return result;
}
bool TDSSClass::SetActive(string ObjName)
{
bool result = false;
int idx = 0;
result = false;
// Faster to look in hash list 7/7/03
if (ElementNamesOutOfSynch)
ResynchElementNameList();
idx = ElementNameList.Find(ObjName);
if (idx > 0)
{
ActiveElement = idx;
ActiveDSSObject[ActiveActor] = ElementList.Get(idx);
result = true;
}
return result;
}
void* TDSSClass::Find(string ObjName)
{
void* result = NULL;
int idx = 0;
result = NULL;
if (ElementNamesOutOfSynch)
ResynchElementNameList();
// Faster to look in hash list 7/7/03
idx = ElementNameList.Find(ObjName);
if (idx > 0)
{
ActiveElement = idx;
result = ElementList.Get(idx);
}
return result;
}
void* TDSSClass::GetActiveObj() // Get address of active obj of this class
{
void* result = NULL;
ActiveElement = ElementList.get_myActiveItem();
if (ActiveElement > 0)
result = ElementList.Get(ActiveElement);
else
result = NULL;
return result;
}
String TDSSClass::Get_FirstPropertyName()
{
String result;
ActiveProperty = 0;
result = Get_NextPropertyName();
return result;
}
String TDSSClass::Get_NextPropertyName()
{
String result;
ActiveProperty++;
if (ActiveProperty <= NumProperties)
result = PropertyName[ActiveProperty];
else
result = "";
return result;
}
string TDSSClass::get_myClass_name()
{
return Class_Name;
}
int TDSSClass::PropertyIndex(string Prop)
// find property value by string
{
int result = 0; // Default result if not found
int i = 0;
for (i = 0; i < NumProperties; i++)
{
if (CompareText(Prop, PropertyName[i]) == 0)
{
result = PropertyIdxMap[i];
break;
}
}
return result;
}
void TDSSClass::CountProperties()
{
NumProperties = NumProperties + 1;
}
void TDSSClass::DefineProperties()
{
ActiveProperty = ActiveProperty + 1;
PropertyName[ActiveProperty] = "like";
PropertyHelp[ActiveProperty] = "Make like another object, e.g.:" + CRLF + CRLF + "New Capacitor.C2 like=c1 ...";
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int TDSSClass::ClassEdit(const void* ActiveObj, const int ParamPointer)
{
int result = 0;
// continue parsing with contents of Parser
result = 0;
if (ParamPointer > 0)
/*# with TDSSObject(ActiveObj) do */
{
const TDSSObject& with0 = *(TDSSObject*)ActiveObj;
{
switch (ParamPointer)
{
case 1:
MakeLike(Parser[ActiveActor]->MakeString_());
break; // Like command (virtual)
}
}
}
return result;
}
int TDSSClass::MakeLike(string ObjName)
{
int result = 0;
result = 0;
DoSimpleMsg("virtual function TDSSClass.MakeLike called. Should be overriden.", 784);
return result;
}
int TDSSClass::Get_ElementCount()
{
int result = 0;
result = ElementList.get_myNumList();
return result;
}
int TDSSClass::Get_First()
{
int result = 0;
if (ElementList.get_myNumList() == 0)
result = 0;
else
{
ActiveElement = 1;
ActiveDSSObject[ActiveActor] = ElementList.Get_First();
// Make sure Active Ckt Element agrees if is a ckt element
// So COM interface will work
if (dynamic_cast<TDSSCktElement*>((TDSSObject*)ActiveDSSObject[ActiveActor]) != nullptr)
ActiveCircuit[ActiveActor]->Set_ActiveCktElement((TDSSCktElement*)(ActiveDSSObject[ActiveActor]));
result = ActiveElement;
}
return result;
}
int TDSSClass::Get_Next()
{
int result = 0;
ActiveElement++;
if (ActiveElement > ElementList.get_myNumList())
result = 0;
else
{
ActiveDSSObject[ActiveActor] = ElementList.Get_Next();
// Make sure Active Ckt Element agrees if is a ckt element
// So COM interface will work
if (dynamic_cast<TDSSCktElement*>((TDSSObject*)ActiveDSSObject[ActiveActor]) != nullptr)
ActiveCircuit[ActiveActor]->Set_ActiveCktElement((TDSSCktElement*)(ActiveDSSObject[ActiveActor]));
result = ActiveElement;
}
return result;
}
void TDSSClass::AddProperty(string PropName, int CmdMapIndex, string HelpString)
{
ActiveProperty++;
PropertyName[ActiveProperty - 1] = PropName;
PropertyHelp[ActiveProperty - 1] = HelpString;
PropertyIdxMap[ActiveProperty - 1] = CmdMapIndex; // Maps to internal object property index
RevPropertyIdxMap[CmdMapIndex - 1] = ActiveProperty;
}
void TDSSClass::AllocatePropertyArrays()
{
int i = 0;
PropertyName = new string[NumProperties + 1];
PropertyHelp = new string[NumProperties + 1];
PropertyIdxMap = new int[NumProperties + 1];
RevPropertyIdxMap = new int[NumProperties + 1];
ActiveProperty = 0; // initialize for AddPropert
/*initialize PropertyIdxMap to take care of legacy items*/
for (int stop = NumProperties, i = 1; i <= stop; i++)
PropertyIdxMap[i - 1] = i;
for (int stop = NumProperties, i = 1; i <= stop; i++)
RevPropertyIdxMap[i - 1] = i;
}
void TDSSClass::ReallocateElementNameList()
{
int i = 0;
/*Reallocate the device name list to improve the performance of searches*/
ElementNameList = THashList(2 * ElementList.get_myNumList()); // make a new one
// Do this using the Names of the Elements rather than the old list because it might be
// messed up if an element gets renamed
for (int stop = ElementList.get_myNumList(), i = 1; i <= stop; i++)
ElementNameList.Add((*(TDSSObject*)(ElementList.Get(i))).get_Name());
}
void TDSSClass::ResynchElementNameList()
{
ReallocateElementNameList();
ElementNamesOutOfSynch = false;
}
}// namespace DSSClass