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 /**************************************/
62 static PWP_BOOL
64 {
65  // SDK common stuff here
66 
67  //char msg[1024] = "caepRuntimeCreate() ";
68  //strcat(msg, pRti->FormatInfo.group);
69  //strcat(msg, "/");
70  //strcat(msg, pRti->FormatInfo.name);
71  //caeuSendDebugMsg(pRti, msg, 0);
72 
73  // Now, let plugin have control
74  return runtimeCreate(pRti);
75 }
76 
77 
78 static PWP_VOID
80 {
81  // SDK common stuff here
82 
83  //char msg[1024] = "caepRuntimeDestroy() ";
84  //strcat(msg, pRti->FormatInfo.group);
85  //strcat(msg, "/");
86  //strcat(msg, pRti->FormatInfo.name);
87  //caeuSendDebugMsg(pRti, msg, 0);
88 
89  // Now, let plugin have control
90  return runtimeDestroy(pRti);
91 }
92 
93 
94 /**************************************/
97 {
99  if (ret && !caepRuntimeCreate(ret)) {
100  ret = 0; // caepRuntimeCreate failed!
101  }
102  return (CAEP_EXPORTER)ret;
103 }
104 
105 /**************************************/
107 PwCreateCaeByName(const char name[])
108 {
109  CAEP_RTITEM* ret = caeuFindFormatByName(name);
110  if (ret && !caepRuntimeCreate(ret)) {
111  ret = 0; // caepRuntimeCreate failed!
112  }
113  return (CAEP_EXPORTER)ret;
114 }
115 
116 /**************************************/
117 PWP_VOID
119 {
120  if (handle) {
121  CAEP_RTITEM* pRti = caeuH2Rti(*handle);
122  if (pRti) {
123  caepRuntimeDestroy(pRti);
124  }
125  *handle = 0;
126  }
127 }
128 
129 /**************************************/
130 const char*
132 {
133  const char* ret = (ndx < caepFormatCnt) ? caepRtItem[ndx].FormatInfo.name : 0;
134  if (ret && pFormatInfo) {
135  *pFormatInfo = caepRtItem[ndx].FormatInfo;
136  }
137  return ret;
138 }
139 
140 /**************************************/
143 {
144  return caepFormatCnt;
145 }
146 
147 /**************************************/
148 const char*
150 {
151  CAEP_RTITEM *pRti = caeuH2Rti(handle);
152  const char* ret = pRti ? pRti->FormatInfo.name : 0;
153  if (ret && pFormatInfo) {
154  *pFormatInfo = pRti->FormatInfo;
155  }
156  return ret;
157 }
158 
159 /**************************************/
160 PWP_BOOL
162 {
163  PWP_BOOL ret = PWP_FALSE;
164  CAEP_RTITEM *pRti = caeuH2Rti(handle);
165  if (pRti) {
166  switch (which) {
167  case PWGM_ELEMTYPE_BAR:
168  case PWGM_ELEMTYPE_HEX:
169  case PWGM_ELEMTYPE_QUAD:
170  case PWGM_ELEMTYPE_TRI:
171  case PWGM_ELEMTYPE_TET:
172  case PWGM_ELEMTYPE_WEDGE:
174  case PWGM_ELEMTYPE_POINT:
175  ret = pRti->elemType[which];
176  break;
177  case PWGM_ELEMTYPE_SIZE: // silence compiler warning
178  break;
179  }
180  }
181  return ret;
182 }
183 
184 /**************************************/
185 const char*
187 {
188  const char* ret = 0;
189  CAEP_RTITEM *pRti = caeuH2Rti(handle);
190  if (pRti) {
191  ret = (ndx < pRti->BCCnt) ? pRti->pBCInfo[ndx].phystype : 0;
192  if (ret && pBCInfo) {
193  *pBCInfo = pRti->pBCInfo[ndx];
194  }
195  }
196  return ret;
197 }
198 
199 /**************************************/
200 const char*
202 {
203  const char* ret = 0;
204  CAEP_RTITEM *pRti = caeuH2Rti(handle);
205  ret = (pRti && (ndx < pRti->ExtCnt)) ? pRti->pFileExt[ndx] : 0;
206  return ret;
207 }
208 
209 /**************************************/
210 const char*
212 {
213  const char* ret = 0;
214  CAEP_RTITEM *pRti = caeuH2Rti(handle);
215  if (pRti && pRti->FormatInfo.allowedVolumeConditions) {
216  ret = (ndx < pRti->VCCnt) ? pRti->pVCInfo[ndx].phystype : 0;
217  if (ret && pVCInfo) {
218  *pVCInfo = pRti->pVCInfo[ndx];
219  }
220  }
221  return ret;
222 }
223 
224 /**************************************/
227 {
228  PWP_UINT32 ret = 0;
229  CAEP_RTITEM *pRti = caeuH2Rti(handle);
230  if (pRti) {
231  ret = pRti->BCCnt;
232  }
233  return ret;
234 }
235 
236 /**************************************/
239 {
240  PWP_UINT32 ret = 0;
241  CAEP_RTITEM *pRti = caeuH2Rti(handle);
242  if (pRti) {
243  ret = pRti->ExtCnt;
244  }
245  return ret;
246 }
247 
248 /**************************************/
251 {
252  PWP_UINT32 ret = 0;
253  CAEP_RTITEM *pRti = caeuH2Rti(handle);
254  if (pRti && pRti->FormatInfo.allowedVolumeConditions) {
255  ret = pRti->VCCnt;
256  }
257  return ret;
258 }
259 
260 /**************************************/
261 PWP_BOOL
263  const CAEP_WRITEINFO *pWriteInfo)
264 {
265  PWP_BOOL ret = PWP_FALSE;
266  CAEP_RTITEM *pRti = caeuH2Rti(handle);
267  if (model && caeuFileOpen(pRti, pWriteInfo)) {
268  pRti->model = model;
269  pRti->pWriteInfo = pWriteInfo;
270  pRti->opAborted = PWP_FALSE;
271  // give impl control!
272  ret = runtimeWrite(pRti, model, pWriteInfo);
273  // we opened it! we close it!
274  caeuFileClose(pRti, pWriteInfo);
275  // force cwd back to original location
276  while (0 == pwpCwdPop());
277  }
278  return ret;
279 }
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:96
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:211
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:149
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:79
PWP_UINT32 PwCaeGetFileExtCount(CAEP_EXPORTER handle)
Get the number of supported file extensions for a CAE exporter instance.
Definition: apiCAEP.cxx:238
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:201
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:226
PWP_BOOL runtimeCreate(CAEP_RTITEM *pRti)
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:186
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:118
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:161
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:250
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:262
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:142
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:131
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:63
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:107
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.