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 ((nullptr != pRti) && (which < ARRAYSIZE(pRti->elemType))) {
162  ret = pRti->elemType[which];
163  }
164  return ret;
165 }
166 
167 
168 const char*
170 {
171  const char* ret = 0;
172  CAEP_RTITEM *pRti = caeuH2Rti(handle);
173  if (pRti) {
174  ret = (ndx < pRti->BCCnt) ? pRti->pBCInfo[ndx].phystype : 0;
175  if (ret && pBCInfo) {
176  *pBCInfo = pRti->pBCInfo[ndx];
177  }
178  }
179  return ret;
180 }
181 
182 
183 const char*
185 {
186  const char* ret = 0;
187  CAEP_RTITEM *pRti = caeuH2Rti(handle);
188  ret = (pRti && (ndx < pRti->ExtCnt)) ? pRti->pFileExt[ndx] : 0;
189  return ret;
190 }
191 
192 
193 const char*
195 {
196  const char* ret = 0;
197  CAEP_RTITEM *pRti = caeuH2Rti(handle);
198  if (pRti && pRti->FormatInfo.allowedVolumeConditions) {
199  ret = (ndx < pRti->VCCnt) ? pRti->pVCInfo[ndx].phystype : 0;
200  if (ret && pVCInfo) {
201  *pVCInfo = pRti->pVCInfo[ndx];
202  }
203  }
204  return ret;
205 }
206 
207 
210 {
211  PWP_UINT32 ret = 0;
212  CAEP_RTITEM *pRti = caeuH2Rti(handle);
213  if (pRti) {
214  ret = pRti->BCCnt;
215  }
216  return ret;
217 }
218 
219 
222 {
223  PWP_UINT32 ret = 0;
224  CAEP_RTITEM *pRti = caeuH2Rti(handle);
225  if (pRti) {
226  ret = pRti->ExtCnt;
227  }
228  return ret;
229 }
230 
231 
234 {
235  PWP_UINT32 ret = 0;
236  CAEP_RTITEM *pRti = caeuH2Rti(handle);
237  if (pRti && pRti->FormatInfo.allowedVolumeConditions) {
238  ret = pRti->VCCnt;
239  }
240  return ret;
241 }
242 
243 
244 PWP_BOOL
246  const CAEP_WRITEINFO *pWriteInfo)
247 {
248  PWP_BOOL ret = PWP_FALSE;
249  CAEP_RTITEM *pRti = caeuH2Rti(handle);
250  if (model && caeuFileOpen(pRti, pWriteInfo)) {
251  pRti->model = model;
252  pRti->pWriteInfo = pWriteInfo;
253  pRti->opAborted = PWP_FALSE;
254  // give impl control!
255  ret = runtimeWrite(pRti, model, pWriteInfo);
256  if (!ret && !pRti->opAborted) {
257  // if failure returned, force opAborted TRUE so caeuFileClose() will
258  // clean up auto-generated files correctly.
259  pRti->opAborted = PWP_TRUE;
260  }
261  // we opened it! we close it!
262  caeuFileClose(pRti, pWriteInfo);
263  // force cwd back to original location
264  while (0 == pwpCwdPop());
265  }
266  return ret;
267 }
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
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:184
PwCaeGetFileExtCount
PWP_UINT32 PwCaeGetFileExtCount(CAEP_EXPORTER handle)
Get the number of supported file extensions for a CAE exporter instance.
Definition: apiCAEP.cxx:221
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:194
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:209
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
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.
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:169
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:233
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
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:245
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