Pointwise Plugin SDK
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 }
PwCreateCaeByName
CAEP_EXPORTER PwCreateCaeByName(const char name[])
Create CAE exporter instance with given name.
Definition: apiCAEP.cxx:103
CAEP_RTITEM::elemType
PWP_BOOL elemType[PWGM_ELEMTYPE_SIZE]
Array of supported element-type flags.
Definition: apiCAEPUtils.h:180
apiUtils.h
Base plugin utilities.
CAEP_FORMATINFO::allowedVolumeConditions
PWP_BOOL allowedVolumeConditions
Set to PWP_TRUE if VCs are supported.
Definition: apiCAEP.h:129
PwCreateCaeById
CAEP_EXPORTER PwCreateCaeById(PWP_UINT32 id)
Create CAE exporter instance with given id.
Definition: apiCAEP.cxx:92
CAEP_RTITEM::pBCInfo
CAEP_BCINFO * pBCInfo
Pointer to an array of supported BC definitions.
Definition: apiCAEPUtils.h:140
PWGM_ELEMTYPE_TET
@ PWGM_ELEMTYPE_TET
3D, 4-sided (tetrahedral) grid element
Definition: apiGridModel.h:677
ARRAYSIZE
#define ARRAYSIZE(arrname)
Calculates the size of a statically declared array.
Definition: apiUtils.h:164
caepRtItem
CAEP_RTITEM caepRtItem[]
The runtime array of CAEP_RTITEM items.
Definition: apiCAEP.cxx:30
PWP_UINT32
unsigned int PWP_UINT32
32-bit unsigned integer
Definition: apiPWP.h:210
CAEP_RTITEM
The data representing a CAE exporter instance.
Definition: apiCAEPUtils.h:124
PwCaeEnumFileExt
const char * PwCaeEnumFileExt(CAEP_EXPORTER handle, PWP_UINT32 ndx)
Enumerate supported file extensions for a CAE exporter instance.
Definition: apiCAEP.cxx:197
PwCaeGetFileExtCount
PWP_UINT32 PwCaeGetFileExtCount(CAEP_EXPORTER handle)
Get the number of supported file extensions for a CAE exporter instance.
Definition: apiCAEP.cxx:234
PwCaeEnumVCs
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
caeuFindFormatByName
CAEP_RTITEM * caeuFindFormatByName(const char name[])
Find an item in caepRtItem[] by it's name.
Definition: apiCAEPUtils.cxx:38
PwCaeFormat
const char * PwCaeFormat(CAEP_EXPORTER handle, CAEP_FORMATINFO *pFormatInfo)
Get CAEP_FORMATINFO data for a CAE exporter handle.
Definition: apiCAEP.cxx:145
CAEP_FORMATINFO
The information returned for each supported CAEP exporter.
Definition: apiCAEP.h:98
PWGM_HGRIDMODEL
An opaque handle to a grid model.
Definition: apiGridModel.h:326
PWP_VOID
void PWP_VOID
no value
Definition: apiPWP.h:317
runtimeWrite.h
PwCaeGetBCCount
PWP_UINT32 PwCaeGetBCCount(CAEP_EXPORTER handle)
Get the number of BC's for a CAE exporter instance.
Definition: apiCAEP.cxx:222
CAEP_RTITEM::BCCnt
PWP_UINT32 BCCnt
The number of BC definitions.
Definition: apiCAEPUtils.h:146
CAEP_RTITEM::VCCnt
PWP_UINT32 VCCnt
The number of VC definitions.
Definition: apiCAEPUtils.h:160
CAEP_RTITEM::pFileExt
const char ** pFileExt
Pointer to an array of valid file extensions.
Definition: apiCAEPUtils.h:167
PWGM_ELEMTYPE_TRI
@ PWGM_ELEMTYPE_TRI
2D, 3-sided grid element
Definition: apiGridModel.h:676
PWGM_ELEMTYPE_POINT
@ PWGM_ELEMTYPE_POINT
0D, point grid element
Definition: apiGridModel.h:680
PWGM_ELEMTYPE_PYRAMID
@ PWGM_ELEMTYPE_PYRAMID
3D, 5-sided, quad-based grid element
Definition: apiGridModel.h:679
CAEP_VCINFO::phystype
const char * phystype
VC physical type name.
Definition: apiCAEP.h:169
PwCaeElementType
PWP_BOOL PwCaeElementType(CAEP_EXPORTER handle, PWGM_ENUM_ELEMTYPE which)
Test if CAE exporter instance supports the given element type.
Definition: apiCAEP.cxx:157
rtCaepSupportData.h
Defines Support Data for the CAEP_RTITEM Array.
PWGM_ELEMTYPE_BAR
@ PWGM_ELEMTYPE_BAR
1D, linear grid element
Definition: apiGridModel.h:673
PwCaeEnumBCs
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
runtimeCreate
PWP_BOOL runtimeCreate(CAEP_RTITEM *pRti)
Definition: cppstr/runtimeWrite.cxx:35
CAEP_FORMATINFO::name
const char * name
format Name.
Definition: apiCAEP.h:107
caepRuntimeCreate
static PWP_BOOL caepRuntimeCreate(CAEP_RTITEM *pRti)
Definition: apiCAEP.cxx:60
PWGM_ENUM_ELEMTYPE
PWGM_ENUM_ELEMTYPE
Element type ids.
Definition: apiGridModel.h:672
pwpCwdPop
int pwpCwdPop(void)
Restore the current directory.
Definition: pwpPlatform.cxx:486
PwDestroyCae
PWP_VOID PwDestroyCae(CAEP_EXPORTER *handle)
Destroy CAE exporter instance.
Definition: apiCAEP.cxx:114
caepRuntimeDestroy
static PWP_VOID caepRuntimeDestroy(CAEP_RTITEM *pRti)
Definition: apiCAEP.cxx:76
apiCAEP.h
Pointwise CAE Plugin API (CAEP-API)
PwCaeGetVCCount
PWP_UINT32 PwCaeGetVCCount(CAEP_EXPORTER handle)
Get the number of VC's for a CAE exporter instance.
Definition: apiCAEP.cxx:246
CAEP_RTITEM::pVCInfo
CAEP_VCINFO * pVCInfo
Pointer to an array of supported VC definitions.
Definition: apiCAEPUtils.h:153
caepFormatCnt
PWP_UINT32 caepFormatCnt
The number of entries in caepRtItem[] array.
Definition: apiCAEP.cxx:36
PWP_FALSE
#define PWP_FALSE
PWP_BOOL logical "false" value.
Definition: apiPWP.h:306
PWGM_ELEMTYPE_WEDGE
@ PWGM_ELEMTYPE_WEDGE
3D, extruded, tri/quad grid element
Definition: apiGridModel.h:678
PwGetCaeFormatCount
PWP_UINT32 PwGetCaeFormatCount()
Get the number of supported CAE exporters.
Definition: apiCAEP.cxx:138
caeuFileOpen
int caeuFileOpen(CAEP_RTITEM *pRti, const CAEP_WRITEINFO *pWriteInfo)
Prepare pRti for file I/O as specified by pWriteInfo.
Definition: apiCAEPUtils.cxx:438
PwCaeGridWrite
PWP_BOOL PwCaeGridWrite(CAEP_EXPORTER handle, PWGM_HGRIDMODEL model, const CAEP_WRITEINFO *pWriteInfo)
Initiates writing a grid model.
Definition: apiCAEP.cxx:258
caeuH2Rti
static CAEP_RTITEM * caeuH2Rti(CAEP_EXPORTER handle)
Definition: apiCAEP.cxx:44
PWP_BOOL
int PWP_BOOL
logical value
Definition: apiPWP.h:303
PwEnumCaeFormat
const char * PwEnumCaeFormat(PWP_UINT32 ndx, CAEP_FORMATINFO *pFormatInfo)
Enumerate CAEP_FORMATINFO data for all supported CAE exporters.
Definition: apiCAEP.cxx:127
CAEP_VCINFO
Volume condition definition information.
Definition: apiCAEP.h:166
rtCaepInitItems.h
Static Initialization Data for the CAEP_RTITEM Array.
CAEP_RTITEM::model
PWGM_HGRIDMODEL model
Runtime grid model handle to export.
Definition: apiCAEPUtils.h:216
caeuFindFormatById
CAEP_RTITEM * caeuFindFormatById(PWP_UINT32 id)
Find an item in caepRtItem[] by it's id.
Definition: apiCAEPUtils.cxx:23
CAEP_WRITEINFO
CAE export write control information.
Definition: apiCAEP.h:184
caeuFileClose
int caeuFileClose(CAEP_RTITEM *pRti, const CAEP_WRITEINFO *pWriteInfo)
Closes pRti for file I/O as specified by pWriteInfo.
Definition: apiCAEPUtils.cxx:176
PWP_TRUE
#define PWP_TRUE
PWP_BOOL logical "true" value.
Definition: apiPWP.h:309
CAEP_BCINFO
Boundary condition definition information.
Definition: apiCAEP.h:67
CAEP_RTITEM::pWriteInfo
const CAEP_WRITEINFO * pWriteInfo
Runtime export CAEP_WRITEINFO data.
Definition: apiCAEPUtils.h:222
CAEP_BCINFO::phystype
const char * phystype
BC physical type name.
Definition: apiCAEP.h:70
CAEP_RTITEM::ExtCnt
PWP_UINT32 ExtCnt
The number of valid file extensions.
Definition: apiCAEPUtils.h:173
apiPWPUtils.h
Data and functions useful to PWP-API compliant plugins.
CAEP_RTITEM::FormatInfo
CAEP_FORMATINFO FormatInfo
The CAE Plugin format data.
Definition: apiCAEPUtils.h:129
apiCAEPUtils.h
CAEP utilities.
runtimeDestroy
PWP_VOID runtimeDestroy(CAEP_RTITEM *pRti)
Definition: cppstr/runtimeWrite.cxx:41
runtimeWrite
PWP_BOOL runtimeWrite(CAEP_RTITEM *pRti, PWGM_HGRIDMODEL model, const CAEP_WRITEINFO *pWriteInfo)
Definition: cppstr/runtimeWrite.cxx:27
CAEP_EXPORTER
CAEP exporter instance handle.
Definition: apiCAEP.h:219
PWGM_ELEMTYPE_QUAD
@ PWGM_ELEMTYPE_QUAD
2D, 4-sided grid element
Definition: apiGridModel.h:675
PWGM_ELEMTYPE_HEX
@ PWGM_ELEMTYPE_HEX
3D, 6-sided (block) grid element
Definition: apiGridModel.h:674