Pointwise Plugin SDK
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
apiCAEP.cxx
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * CAEP Plugin example
4  *
5  * (C) 2021 Cadence Design Systems, Inc. All rights reserved worldwide.
6  *
7  ***************************************************************************/
8 
9 #include <stdio.h>
10 #include <string.h>
11 #include <stddef.h>
12 #include <time.h>
13 
14 // Define this on the build command line for verbose build messages
15 // #define SHOW_PWP_MESSAGES
16 #include "apiCAEP.h"
17 
18 #include "apiCAEPUtils.h"
19 #include "apiPWPUtils.h"
20 #include "apiUtils.h"
21 #include "runtimeWrite.h"
22 
23 
24 //************************************************
25 // impl-defined CAE format support data
26 //************************************************
27 #include "rtCaepSupportData.h"
28 
29 /*------------------------------------*/
31  //************************************************
32  // impl-defined CAE format data
33  //************************************************
34 # include "rtCaepInitItems.h"
35 };
37 
38 
39 /* Safely casts the incoming CAEP_EXPORTER handle to a CAEP_RTITEM*.
40  NOTE: caeuH2Rti() needs to be here to gain compile-time access
41  to caepRtItem array.
42 */
43 static CAEP_RTITEM *
45 {
46  CAEP_RTITEM *ret = 0;
47  if (handle) {
48  ptrdiff_t diff = ((char*)handle) - (char*)caepRtItem;
49  ptrdiff_t mod = diff % sizeof(caepRtItem[0]);
50  if ((0 == mod) && (0 <= diff) &&
51  (diff < (ptrdiff_t)sizeof(caepRtItem))) {
52  ret = ((CAEP_RTITEM*)handle);
53  }
54  }
55  return ret;
56 }
57 
58 
59 static PWP_BOOL
61 {
62  // SDK common stuff here
63 
64  //char msg[1024] = "caepRuntimeCreate() ";
65  //strcat(msg, pRti->FormatInfo.group);
66  //strcat(msg, "/");
67  //strcat(msg, pRti->FormatInfo.name);
68  //caeuSendDebugMsg(pRti, msg, 0);
69 
70  // Now, let plugin have control
71  return runtimeCreate(pRti);
72 }
73 
74 
75 static PWP_VOID
77 {
78  // SDK common stuff here
79 
80  //char msg[1024] = "caepRuntimeDestroy() ";
81  //strcat(msg, pRti->FormatInfo.group);
82  //strcat(msg, "/");
83  //strcat(msg, pRti->FormatInfo.name);
84  //caeuSendDebugMsg(pRti, msg, 0);
85 
86  // Now, let plugin have control
87  return runtimeDestroy(pRti);
88 }
89 
90 
93 {
95  if (ret && !caepRuntimeCreate(ret)) {
96  ret = 0; // caepRuntimeCreate failed!
97  }
98  return (CAEP_EXPORTER)ret;
99 }
100 
101 
103 PwCreateCaeByName(const char name[])
104 {
105  CAEP_RTITEM* ret = caeuFindFormatByName(name);
106  if (ret && !caepRuntimeCreate(ret)) {
107  ret = 0; // caepRuntimeCreate failed!
108  }
109  return (CAEP_EXPORTER)ret;
110 }
111 
112 
113 PWP_VOID
115 {
116  if (handle) {
117  CAEP_RTITEM* pRti = caeuH2Rti(*handle);
118  if (pRti) {
119  caepRuntimeDestroy(pRti);
120  }
121  *handle = 0;
122  }
123 }
124 
125 
126 const char*
128 {
129  const char* ret = (ndx < caepFormatCnt) ? caepRtItem[ndx].FormatInfo.name : 0;
130  if (ret && pFormatInfo) {
131  *pFormatInfo = caepRtItem[ndx].FormatInfo;
132  }
133  return ret;
134 }
135 
136 
139 {
140  return caepFormatCnt;
141 }
142 
143 
144 const char*
146 {
147  CAEP_RTITEM *pRti = caeuH2Rti(handle);
148  const char* ret = pRti ? pRti->FormatInfo.name : 0;
149  if (ret && pFormatInfo) {
150  *pFormatInfo = pRti->FormatInfo;
151  }
152  return ret;
153 }
154 
155 
156 PWP_BOOL
158 {
159  PWP_BOOL ret = PWP_FALSE;
160  CAEP_RTITEM *pRti = caeuH2Rti(handle);
161  if (pRti) {
162  switch (which) {
163  case PWGM_ELEMTYPE_BAR:
164  case PWGM_ELEMTYPE_HEX:
165  case PWGM_ELEMTYPE_QUAD:
166  case PWGM_ELEMTYPE_TRI:
167  case PWGM_ELEMTYPE_TET:
168  case PWGM_ELEMTYPE_WEDGE:
170  case PWGM_ELEMTYPE_POINT:
171  ret = pRti->elemType[which];
172  break;
173  case PWGM_ELEMTYPE_SIZE: // silence compiler warning
174  break;
175  }
176  }
177  return ret;
178 }
179 
180 
181 const char*
183 {
184  const char* ret = 0;
185  CAEP_RTITEM *pRti = caeuH2Rti(handle);
186  if (pRti) {
187  ret = (ndx < pRti->BCCnt) ? pRti->pBCInfo[ndx].phystype : 0;
188  if (ret && pBCInfo) {
189  *pBCInfo = pRti->pBCInfo[ndx];
190  }
191  }
192  return ret;
193 }
194 
195 
196 const char*
198 {
199  const char* ret = 0;
200  CAEP_RTITEM *pRti = caeuH2Rti(handle);
201  ret = (pRti && (ndx < pRti->ExtCnt)) ? pRti->pFileExt[ndx] : 0;
202  return ret;
203 }
204 
205 
206 const char*
208 {
209  const char* ret = 0;
210  CAEP_RTITEM *pRti = caeuH2Rti(handle);
211  if (pRti && pRti->FormatInfo.allowedVolumeConditions) {
212  ret = (ndx < pRti->VCCnt) ? pRti->pVCInfo[ndx].phystype : 0;
213  if (ret && pVCInfo) {
214  *pVCInfo = pRti->pVCInfo[ndx];
215  }
216  }
217  return ret;
218 }
219 
220 
223 {
224  PWP_UINT32 ret = 0;
225  CAEP_RTITEM *pRti = caeuH2Rti(handle);
226  if (pRti) {
227  ret = pRti->BCCnt;
228  }
229  return ret;
230 }
231 
232 
235 {
236  PWP_UINT32 ret = 0;
237  CAEP_RTITEM *pRti = caeuH2Rti(handle);
238  if (pRti) {
239  ret = pRti->ExtCnt;
240  }
241  return ret;
242 }
243 
244 
247 {
248  PWP_UINT32 ret = 0;
249  CAEP_RTITEM *pRti = caeuH2Rti(handle);
250  if (pRti && pRti->FormatInfo.allowedVolumeConditions) {
251  ret = pRti->VCCnt;
252  }
253  return ret;
254 }
255 
256 
257 PWP_BOOL
259  const CAEP_WRITEINFO *pWriteInfo)
260 {
261  PWP_BOOL ret = PWP_FALSE;
262  CAEP_RTITEM *pRti = caeuH2Rti(handle);
263  if (model && caeuFileOpen(pRti, pWriteInfo)) {
264  pRti->model = model;
265  pRti->pWriteInfo = pWriteInfo;
266  pRti->opAborted = PWP_FALSE;
267  // give impl control!
268  ret = runtimeWrite(pRti, model, pWriteInfo);
269  if (!ret && !pRti->opAborted) {
270  // if failure returned, force opAborted TRUE so caeuFileClose() will
271  // clean up auto-generated files correctly.
272  pRti->opAborted = PWP_TRUE;
273  }
274  // we opened it! we close it!
275  caeuFileClose(pRti, pWriteInfo);
276  // force cwd back to original location
277  while (0 == pwpCwdPop());
278  }
279  return ret;
280 }
PWP_BOOL runtimeWrite(CAEP_RTITEM *pRti, PWGM_HGRIDMODEL model, const CAEP_WRITEINFO *pWriteInfo)
3D, 6-sided (block) grid element
Definition: apiGridModel.h:674
CAEP_EXPORTER PwCreateCaeById(PWP_UINT32 id)
Create CAE exporter instance with given id.
Definition: apiCAEP.cxx:92
unsigned int PWP_UINT32
32-bit unsigned integer
Definition: apiPWP.h:210
CAEP_RTITEM * caeuFindFormatById(PWP_UINT32 id)
Find an item in caepRtItem[] by it&#39;s id.
const char * PwCaeEnumVCs(CAEP_EXPORTER handle, PWP_UINT32 ndx, CAEP_VCINFO *pVCInfo)
Enumerate CAEP_VCINFO data for a CAE exporter instance.
Definition: apiCAEP.cxx:207
2D, 4-sided grid element
Definition: apiGridModel.h:675
Static Initialization Data for the CAEP_RTITEM Array.
const char * PwCaeFormat(CAEP_EXPORTER handle, CAEP_FORMATINFO *pFormatInfo)
Get CAEP_FORMATINFO data for a CAE exporter handle.
Definition: apiCAEP.cxx:145
static CAEP_RTITEM * caeuH2Rti(CAEP_EXPORTER handle)
Definition: apiCAEP.cxx:44
3D, 4-sided (tetrahedral) grid element
Definition: apiGridModel.h:677
void PWP_VOID
no value
Definition: apiPWP.h:317
#define ARRAYSIZE(arrname)
Calculates the size of a statically declared array.
Definition: apiUtils.h:164
The information returned for each supported CAEP exporter.
Definition: apiCAEP.h:98
int caeuFileOpen(CAEP_RTITEM *pRti, const CAEP_WRITEINFO *pWriteInfo)
Prepare pRti for file I/O as specified by pWriteInfo.
PWP_UINT32 BCCnt
The number of BC definitions.
Definition: apiCAEPUtils.h:146
static PWP_VOID caepRuntimeDestroy(CAEP_RTITEM *pRti)
Definition: apiCAEP.cxx:76
PWP_UINT32 PwCaeGetFileExtCount(CAEP_EXPORTER handle)
Get the number of supported file extensions for a CAE exporter instance.
Definition: apiCAEP.cxx:234
2D, 3-sided grid element
Definition: apiGridModel.h:676
const char * PwCaeEnumFileExt(CAEP_EXPORTER handle, PWP_UINT32 ndx)
Enumerate supported file extensions for a CAE exporter instance.
Definition: apiCAEP.cxx:197
PWP_BOOL allowedVolumeConditions
Set to PWP_TRUE if VCs are supported.
Definition: apiCAEP.h:129
CAEP_FORMATINFO FormatInfo
The CAE Plugin format data.
Definition: apiCAEPUtils.h:129
PWP_UINT32 PwCaeGetBCCount(CAEP_EXPORTER handle)
Get the number of BC&#39;s for a CAE exporter instance.
Definition: apiCAEP.cxx:222
PWP_BOOL runtimeCreate(CAEP_RTITEM *pRti)
#define PWP_TRUE
PWP_BOOL logical &quot;true&quot; value.
Definition: apiPWP.h:309
const char * phystype
BC physical type name.
Definition: apiCAEP.h:70
1D, linear grid element
Definition: apiGridModel.h:673
const char * PwCaeEnumBCs(CAEP_EXPORTER handle, PWP_UINT32 ndx, CAEP_BCINFO *pBCInfo)
Enumerate CAEP_BCINFO data for a CAE exporter instance.
Definition: apiCAEP.cxx:182
Base plugin utilities.
CAEP_VCINFO * pVCInfo
Pointer to an array of supported VC definitions.
Definition: apiCAEPUtils.h:153
PWP_UINT32 caepFormatCnt
The number of entries in caepRtItem[] array.
Definition: apiCAEP.cxx:36
const char * name
format Name.
Definition: apiCAEP.h:107
PWP_VOID PwDestroyCae(CAEP_EXPORTER *handle)
Destroy CAE exporter instance.
Definition: apiCAEP.cxx:114
CAEP_RTITEM caepRtItem[]
The runtime array of CAEP_RTITEM items.
Definition: apiCAEP.cxx:30
PWP_BOOL PwCaeElementType(CAEP_EXPORTER handle, PWGM_ENUM_ELEMTYPE which)
Test if CAE exporter instance supports the given element type.
Definition: apiCAEP.cxx:157
const CAEP_WRITEINFO * pWriteInfo
Runtime export CAEP_WRITEINFO data.
Definition: apiCAEPUtils.h:222
CAEP utilities.
int caeuFileClose(CAEP_RTITEM *pRti, const CAEP_WRITEINFO *pWriteInfo)
Closes pRti for file I/O as specified by pWriteInfo.
PWGM_ENUM_ELEMTYPE
Element type ids.
Definition: apiGridModel.h:672
PWP_UINT32 PwCaeGetVCCount(CAEP_EXPORTER handle)
Get the number of VC&#39;s for a CAE exporter instance.
Definition: apiCAEP.cxx:246
Volume condition definition information.
Definition: apiCAEP.h:166
3D, 5-sided, quad-based grid element
Definition: apiGridModel.h:679
const char * phystype
VC physical type name.
Definition: apiCAEP.h:169
int pwpCwdPop(void)
Restore the current directory.
0D, point grid element
Definition: apiGridModel.h:680
PWP_BOOL PwCaeGridWrite(CAEP_EXPORTER handle, PWGM_HGRIDMODEL model, const CAEP_WRITEINFO *pWriteInfo)
Initiates writing a grid model.
Definition: apiCAEP.cxx:258
int PWP_BOOL
logical value
Definition: apiPWP.h:303
Defines Support Data for the CAEP_RTITEM Array.
CAE export write control information.
Definition: apiCAEP.h:184
3D, extruded, tri/quad grid element
Definition: apiGridModel.h:678
Pointwise CAE Plugin API (CAEP-API)
PWP_UINT32 PwGetCaeFormatCount()
Get the number of supported CAE exporters.
Definition: apiCAEP.cxx:138
Boundary condition definition information.
Definition: apiCAEP.h:67
const char * PwEnumCaeFormat(PWP_UINT32 ndx, CAEP_FORMATINFO *pFormatInfo)
Enumerate CAEP_FORMATINFO data for all supported CAE exporters.
Definition: apiCAEP.cxx:127
PWP_UINT32 VCCnt
The number of VC definitions.
Definition: apiCAEPUtils.h:160
const char ** pFileExt
Pointer to an array of valid file extensions.
Definition: apiCAEPUtils.h:167
CAEP_RTITEM * caeuFindFormatByName(const char name[])
Find an item in caepRtItem[] by it&#39;s name.
CAEP_BCINFO * pBCInfo
Pointer to an array of supported BC definitions.
Definition: apiCAEPUtils.h:140
PWP_VOID runtimeDestroy(CAEP_RTITEM *pRti)
The data representing a CAE exporter instance.
Definition: apiCAEPUtils.h:124
static PWP_BOOL caepRuntimeCreate(CAEP_RTITEM *pRti)
Definition: apiCAEP.cxx:60
PWP_UINT32 ExtCnt
The number of valid file extensions.
Definition: apiCAEPUtils.h:173
An opaque handle to a grid model.
Definition: apiGridModel.h:326
CAEP exporter instance handle.
Definition: apiCAEP.h:219
PWGM_HGRIDMODEL model
Runtime grid model handle to export.
Definition: apiCAEPUtils.h:216
#define PWP_FALSE
PWP_BOOL logical &quot;false&quot; value.
Definition: apiPWP.h:306
CAEP_EXPORTER PwCreateCaeByName(const char name[])
Create CAE exporter instance with given name.
Definition: apiCAEP.cxx:103
PWP_BOOL elemType[PWGM_ELEMTYPE_SIZE]
Array of supported element-type flags.
Definition: apiCAEPUtils.h:180
Data and functions useful to PWP-API compliant plugins.