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