Pointwise Plugin SDK
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
apiGRDPUtils.cxx
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Pointwise Plugin utility functions
4  *
5  * (C) 2021 Cadence Design Systems, Inc. All rights reserved worldwide.
6  *
7  ***************************************************************************/
8 
9 #include <string.h>
10 
11 #include "apiPWP.h"
12 #include "apiGRDPUtils.h"
13 #include "apiGridModel.h"
14 #include "pwpPlatform.h"
15 
16 
19 {
20  GRDP_RTITEM *ret = 0;
21  PWP_UINT32 ii;
22  for (ii=0; ii < grdpFormatCnt; ++ii) {
23  if (id == grdpRtItem[ii].FormatInfo.id) {
24  ret = &(grdpRtItem[ii]);
25  break;
26  }
27  }
28  return ret;
29 }
30 
31 
33 grdpFindFormatByName (const char name[])
34 {
35  GRDP_RTITEM *ret = 0;
36  PWP_UINT32 ii;
37  for (ii=0; ii < grdpFormatCnt; ++ii) {
38  if (0 == strcmp(grdpRtItem[ii].FormatInfo.name, name)) {
39  ret = &(grdpRtItem[ii]);
40  break;
41  }
42  }
43  return ret;
44 }
45 
46 
49 {
50  PWP_BOOL ret = PWP_FALSE;
51  if (pRti) {
52  pRti->progTotal = 0;
53  pRti->progComplete = 0;
54  pRti->clocks[GRDP_CLKS_PROGUPDATE] =
55  pRti->clocks[GRDP_CLKS_PROGINIT] = clock();
56  pRti->opAborted = PWP_FALSE;
57  ret = PwuProgressBegin(pRti->pApiData->apiInfo.name, cnt);
58  pRti->opAborted |= !ret;
59  }
60  return ret;
61 }
62 
63 
66 {
67  PWP_BOOL ret = PWP_FALSE;
68  if (pRti && (total > 0)) {
69  pRti->progComplete = 0;
70  pRti->progTotal = total;
71  ret = !pRti->opAborted;
72  pRti->clocks[GRDP_CLKS_BEGSTEP] = clock();
73  }
74  return ret;
75 }
76 
77 
80 {
81  PWP_BOOL ret = PWP_FALSE;
82  if (pRti && !pRti->opAborted) {
83  // send update a max of 2 times per second
84  const clock_t DELAY = (CLOCKS_PER_SEC / 2);
85  pRti->clocks[GRDP_CLKS_PROGINCR] = clock();
86  ++pRti->progComplete;
87  if (DELAY <= GRDP_RT_CLKS_DIFF(pRti, GRDP_CLKS_PROGUPDATE,
89  ret = PwuProgressStatus (pRti->pApiData->apiInfo.name,
90  pRti->progComplete, pRti->progTotal);
91  pRti->clocks[GRDP_CLKS_PROGUPDATE] =
92  pRti->clocks[GRDP_CLKS_PROGINCR];
93  pRti->opAborted |= !ret;
94  }
95  else {
96  ret = PWP_TRUE;
97  }
98  }
99  return ret;
100 }
101 
102 /*------------------------------------*/
103 static void
104 sendDiffTimeMsg(GRDP_RTITEM *pRti, const char txt[], clock_t diff)
105 {
106  if (pRti) {
107  PWP_INT32 hours;
108  PWP_INT32 minutes;
109  PWP_INT32 seconds;
110  char msg[512];
111  char *p = msg;
112  if (txt && txt[0]) {
113  strcpy(p, txt);
114  strcat(p, ": ");
115  p += strlen(p);
116  }
117  GRDP_CLKS_TO_HMS(diff, hours, minutes, seconds);
118  sprintf(p, "%ld:%02ld:%02ld (h:mm:ss) / %ld msec", (long)hours,
119  (long)minutes, (long)seconds, (long)GRDP_CLKS_TO_MSECS(diff));
120  grdpSendDebugMsg(pRti, msg, 0);
121  }
122 }
123 
124 /*------------------------------------*/
125 static void
126 sendClkDiffTimeMsg(GRDP_RTITEM *pRti, const char txt[],
127  GRDP_ENUM_CLOCKS startId, GRDP_ENUM_CLOCKS endId)
128 {
129  if (pRti) {
130  sendDiffTimeMsg(pRti, txt,
131  GRDP_RT_CLKS_DIFF(pRti, startId, endId));
132  }
133 }
134 
135 
136 PWP_BOOL
138 {
139  PWP_BOOL ret = PWP_FALSE;
140  if (pRti) {
141  pRti->clocks[GRDP_CLKS_ENDSTEP] = clock();
142  pRti->progComplete = 0;
143  pRti->progTotal = 0;
145  pRti->opAborted |= !ret;
146  sendClkDiffTimeMsg(pRti, "Step time", GRDP_CLKS_BEGSTEP,
148  }
149  return ret;
150 }
151 
152 
153 PWP_BOOL
155 {
156  if (pRti) {
157  pRti->clocks[GRDP_CLKS_PROGEND] = clock();
158  pRti->progTotal = 0;
159  pRti->progComplete = 0;
160  pRti->clocks[GRDP_CLKS_PROGUPDATE] = 0;
161  PwuProgressEnd(pRti->pApiData->apiInfo.name, ok);
162  sendClkDiffTimeMsg(pRti, "Export time", GRDP_CLKS_PROGINIT,
164  }
165  return ok;
166 }
167 
168 
169 void
170 grdpSendDebugMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
171 {
172  if (0 != pRti) {
173  PwuSendDebugMsg(pRti->pApiData->apiInfo.name, txt, code);
174  }
175 }
176 
177 
178 void
179 grdpSendInfoMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
180 {
181  if (0 != pRti) {
182  PwuSendInfoMsg(pRti->pApiData->apiInfo.name, txt, code);
183  }
184 }
185 
186 
187 void
188 grdpSendWarningMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
189 {
190  if (0 != pRti) {
191  PwuSendWarningMsg(pRti->pApiData->apiInfo.name, txt, code);
192  }
193 }
194 
195 
196 void
197 grdpSendErrorMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
198 {
199  if (0 != pRti) {
200  PwuSendErrorMsg(pRti->pApiData->apiInfo.name, txt, code);
201  }
202 }
203 
204 
205 
206 PWP_BOOL
207 grdpPublishValueDefinition(const char name[], PWP_ENUM_VALTYPE type, const char value[],
208  const char access[], const char desc[], const char range[])
209 {
210  PWP_BOOL ret = PWP_FALSE;
211  ret = PwuPublishValueDefinition(GRDP_VALUE_GROUP, name, type, value, access, desc,
212  range);
213  return ret;
214 }
215 
216 
217 PWP_BOOL
218 grdpAssignInfoValue(const char name[], const char value[], const bool create)
219 {
220  return PwuAssignValue(GRDP_INFO_GROUP, name, value, create);
221 }
222 
223 
224 PWP_BOOL
225 grdpAssignInfoValueInt(const char name[], const PWP_INT value, const bool create)
226 {
227  return PwuAssignValueInt(GRDP_INFO_GROUP, name, value, create);
228 }
229 
230 
231 PWP_BOOL
232 grdpAssignInfoValueUInt(const char name[], const PWP_UINT value, const bool create)
233 {
234  return PwuAssignValueUInt(GRDP_INFO_GROUP, name, value, create);
235 }
236 
237 
238 PWP_BOOL
239 grdpAssignInfoValueReal(const char name[], const PWP_REAL value, const bool create)
240 {
241  return PwuAssignValueReal(GRDP_INFO_GROUP, name, value, create);
242 }
243 
244 
245 PWP_BOOL
246 grdpAssignInfoValueBool(const char name[], const bool value, const bool create)
247 {
248  return PwuAssignValueUInt(GRDP_INFO_GROUP, name, (value ? 1 : 0), create);
249 }
250 
251 
252 PWP_BOOL
253 grdpAssignInfoValueEnum(const char name[], const char value[], const bool create)
254 {
255  return PwuAssignValueEnum(GRDP_INFO_GROUP, name, value, create);
256 }
PWP_BOOL grdpPublishValueDefinition(const char name[], PWP_ENUM_VALTYPE type, const char value[], const char access[], const char desc[], const char range[])
Creates a collection of key/value pairs that represent a published grid import attribute definition...
PWP_ENUM_VALTYPE
Supported PWP-API getValue() transfer types.
Definition: apiPWP.h:696
The data representing a grid importer instance.
Definition: apiGRDPUtils.h:117
unsigned int PWP_UINT32
32-bit unsigned integer
Definition: apiPWP.h:210
Pointwise Plugin API (PWP-API)
GRDP_RTITEM grdpRtItem[]
The runtime array of GRDP_RTITEM items.
Definition: apiGRDP.cxx:27
PWP_BOOL PwuPublishValueDefinition(const char group[], const char name[], PWP_ENUM_VALTYPE type, const char value[], const char access[], const char desc[], const char range[])
Create a value.
static void sendDiffTimeMsg(GRDP_RTITEM *pRti, const char txt[], clock_t diff)
PWP_BOOL PwuAssignValue(const char group[], const char name[], const char value[], bool createIfNotExists)
Assign or create a value.
PWP_BOOL grdpAssignInfoValueReal(const char name[], const PWP_REAL value, const bool create)
Creates a key/PWP_REAL-value pair that defines a GRDP info attribute.
#define GRDP_CLKS_TO_MSECS(c)
Returns the clock value c as milli seconds (PWP_INT32). Only whole ms values are possible.
Definition: apiGRDPUtils.h:688
void PwuSendInfoMsg(const char api[], const char txt[], PWP_UINT32 code)
Send an info text message (PWP_MSGID_INFO) to the framework.
GRDP_RTITEM * grdpFindFormatByName(const char name[])
Find an item in grdpRtItem[] by it&#39;s name.
PWP_BOOL PwuAssignValueInt(const char group[], const char name[], PWP_INT value, bool createIfNotExists)
void grdpSendDebugMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
Send a debug text message (PWP_MSGID_DEBUG) to the framework.
PWU_RTITEM * pApiData
Pointer to the associated PWU_RTITEM structure.
Definition: apiGRDPUtils.h:126
PWP_BOOL PwuProgressBegin(const char api[], PWP_UINT32 totalSteps)
Send a progress begin message (PWP_MSGID_PROGBEGIN) to the framework.
Pointwise Grid Model API Specification (PWGM-API)
void grdpSendErrorMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
Send an error text message (PWP_MSGID_ERROR) to the framework.
PWP_BOOL grdpAssignInfoValueInt(const char name[], const PWP_INT value, const bool create)
Creates a key/PWP_INT-value pair that defines a GRDP info attribute.
#define GRDP_CLKS_TO_HMS(c, h, m, s)
Returns the clock value c decomposed into hours, minutes, and seconds (PWP_INT32). That is, c == (h * 3600 + m * 60 + s) * CLOCKS_PER_SEC.
Definition: apiGRDPUtils.h:713
#define PWP_TRUE
PWP_BOOL logical &quot;true&quot; value.
Definition: apiPWP.h:309
PWP_BOOL grdpAssignInfoValue(const char name[], const char value[], const bool create)
Creates a key/string-value pair that defines a GRDP info attribute.
Cross Platform Functions.
PWP_BOOL grdpProgressEnd(GRDP_RTITEM *pRti, const PWP_BOOL ok)
Ends all progress tracking.
PWP_BOOL grdpAssignInfoValueBool(const char name[], const bool value, const bool create)
Creates a key/bool-value pair that defines a GRDP info attribute.
PWP_UINT32 grdpFormatCnt
The number of entries in grdpRtItem[] array.
Definition: apiGRDP.cxx:33
PWP_BOOL PwuAssignValueEnum(const char group[], const char name[], const char value[], bool createIfNotExists)
void PwuSendWarningMsg(const char api[], const char txt[], PWP_UINT32 code)
Send a warning text message (PWP_MSGID_WARNING) to the framework.
GRDP utilities.
#define GRDP_VALUE_GROUP
Definition: apiGRDP.h:49
PWP_BOOL grdpProgressInit(GRDP_RTITEM *pRti, PWP_UINT32 cnt)
Initializes a progress tracking session.
int PWP_BOOL
logical value
Definition: apiPWP.h:303
#define GRDP_RT_CLKS_DIFF(rti, startId, endId)
Returns the clock time difference between startId and endId as clocks[endId] - clocks[startId]. The ids are validated.
Definition: apiGRDPUtils.h:645
void PwuSendDebugMsg(const char api[], const char txt[], PWP_UINT32 code)
Send a debug text message (PWP_MSGID_DEBUG) to the framework.
#define GRDP_INFO_GROUP
Definition: apiGRDP.h:53
static void sendClkDiffTimeMsg(GRDP_RTITEM *pRti, const char txt[], GRDP_ENUM_CLOCKS startId, GRDP_ENUM_CLOCKS endId)
void PwuSendErrorMsg(const char api[], const char txt[], PWP_UINT32 code)
Send an error text message (PWP_MSGID_ERROR) to the framework.
GRDP_RTITEM * grdpFindFormatById(PWP_UINT32 id)
Find an item in grdpRtItem[] by it&#39;s id.
GRDP_ENUM_CLOCKS
Supported GRDP clock id values.
Definition: apiGRDPUtils.h:95
PWP_BOOL PwuAssignValueReal(const char group[], const char name[], PWP_REAL value, bool createIfNotExists)
void grdpSendWarningMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
Send a warning text message (PWP_MSGID_WARNING) to the framework.
PWP_BOOL grdpProgressEndStep(GRDP_RTITEM *pRti)
Completes a progress tracking major step.
PWP_BOOL grdpProgressIncr(GRDP_RTITEM *pRti)
Completes a progress tracking sub-step.
PWP_BOOL PwuAssignValueUInt(const char group[], const char name[], PWP_UINT value, bool createIfNotExists)
PWP_UINT32 PWP_UINT
unsigned integer same size as void*
Definition: apiPWP.h:285
void PwuProgressEnd(const char api[], PWP_BOOL ok)
Send a progress end message (PWP_MSGID_PROGEND) to the framework.
const char * name
full API spec name
Definition: apiPWP.h:655
PWP_BOOL grdpProgressBeginStep(GRDP_RTITEM *pRti, PWP_UINT32 total)
Begins a progress tracking step.
PWP_INT32 PWP_INT
integer same size as void*
Definition: apiPWP.h:282
PWP_BOOL PwuProgressStatus(const char api[], PWP_UINT32 complete, PWP_UINT32 total)
Send a progress status message (PWP_MSGID_PROGSTATUS, value &gt;= 0) to the framework.
PWP_BOOL grdpAssignInfoValueEnum(const char name[], const char value[], const bool create)
Creates a key/enum-value pair that defines a GRDP info attribute.
PWP_BOOL PwuProgressNextStep(const char api[])
Send a progress &quot;next step&quot; message (PWP_MSGID_PROGSTATUS, value = -1) to the framework.
PWP_APIINFO apiInfo
The PWP-API instance information.
Definition: apiPWPUtils.h:48
void grdpSendInfoMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
Send an info text message (PWP_MSGID_INFO) to the framework.
double PWP_REAL
64-bit real
Definition: apiPWP.h:264
#define PWP_FALSE
PWP_BOOL logical &quot;false&quot; value.
Definition: apiPWP.h:306
int PWP_INT32
32-bit integer
Definition: apiPWP.h:207
PWP_BOOL grdpAssignInfoValueUInt(const char name[], const PWP_UINT value, const bool create)
Creates a key/PWP_UINT-value pair that defines a GRDP info attribute.