Pointwise Plugin SDK
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
apiGRDP.cxx
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * GRDP 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 #include <string>
15 
16 //#define SHOW_PWP_MESSAGES
17 #include "apiGRDP.h"
18 
19 #include "apiGRDPUtils.h"
20 #include "apiPWPUtils.h"
21 #include "apiUtils.h"
22 #include "PwpCwd.h"
23 #include "runtimeReadGrid.h"
24 
25 
26 
28  //************************************************
29  // impl-defined grid import format data
30  //************************************************
31 # include "rtGrdpInitItems.h"
32 };
34 
35 
36 
37 /* Safely casts the incoming GRDP_IMPORTER handle to a GRDP_RTITEM*.
38  NOTE: grdpH2Rti() needs to be here to gain compile-time access
39  to grdpRtItem array.
40 */
41 static GRDP_RTITEM *
43 {
44  GRDP_RTITEM *ret = 0;
45  if (handle) {
46  ptrdiff_t diff = ((char*)handle) - (char*)grdpRtItem;
47  ptrdiff_t mod = diff % sizeof(grdpRtItem[0]);
48  if ((0 == mod) && (0 <= diff) &&
49  (diff < (ptrdiff_t)sizeof(grdpRtItem))) {
50  ret = ((GRDP_RTITEM*)handle);
51  }
52  }
53  return ret;
54 }
55 
56 
57 
58 static PWP_BOOL
60 {
61  // SDK common stuff here
62 
63  // Now, let plugin have control
64  return runtimeReadGridCreate(pRti);
65 }
66 
67 
68 static PWP_VOID
70 {
71  // SDK common stuff here
72 
73  // Now, let plugin have control
74  return runtimeReadGridDestroy(pRti);
75 }
76 
77 
78 
81 {
83  if (ret && !grdpRuntimeCreate(ret)) {
84  ret = 0; // grdpRuntimeCreate failed!
85  }
86  return (GRDP_IMPORTER)ret;
87 }
88 
89 
91 PwCreateGrdpByName(const char name[])
92 {
93  GRDP_RTITEM* ret = grdpFindFormatByName(name);
94  if (ret && !grdpRuntimeCreate(ret)) {
95  ret = 0; // grdpRuntimeCreate failed!
96  }
97  return (GRDP_IMPORTER)ret;
98 }
99 
100 
101 PWP_VOID
103 {
104  if (handle) {
105  GRDP_RTITEM* pRti = grdpH2Rti(*handle);
106  if (pRti) {
107  grdpRuntimeDestroy(pRti);
108  }
109  *handle = 0;
110  }
111 }
112 
113 
114 const char*
116 {
117  const char* ret = (ndx < grdpFormatCnt) ? grdpRtItem[ndx].FormatInfo.name : 0;
118  if (ret && pFormatInfo) {
119  *pFormatInfo = grdpRtItem[ndx].FormatInfo;
120  }
121  return ret;
122 }
123 
124 
127 {
128  return grdpFormatCnt;
129 }
130 
131 
132 const char*
134 {
135  GRDP_RTITEM *pRti = grdpH2Rti(handle);
136  const char* ret = pRti ? pRti->FormatInfo.name : 0;
137  if (ret && pFormatInfo) {
138  *pFormatInfo = pRti->FormatInfo;
139  }
140  return ret;
141 }
142 
143 
144 class FileDestPwpCwd : public PwpCwd {
145 public:
146  FileDestPwpCwd(const PWP_ENUM_FILEDEST id, const char *fileDest) :
147  PwpCwd()
148  {
149  switch (id) {
151  case PWP_FILEDEST_BASENAME: {
152  std::string dir(fileDest);
153  size_t pos = dir.rfind('/');
154  if (std::string::npos != pos) {
155  // if "/path/to/filename.ext" cdw to "/path/to/"
156  push(dir.substr(0, pos + 1).c_str());
157  }
158  break; }
159  case PWP_FILEDEST_FOLDER:
160  push(fileDest);
161  break;
162  default:
163  // NOP
164  break;
165  }
166  }
167 
169  {
170  }
171 };
172 
173 
174 PWP_BOOL
176  const GRDP_READINFO *pReadInfo)
177 {
178  PWP_BOOL ret = PWP_FALSE;
179  GRDP_RTITEM *pRti = grdpH2Rti(handle);
180  if (PWGM_HGRIDMODEL_ISVALID(model)) {
181  pRti->model = model;
182  pRti->pReadInfo = pReadInfo;
183  pRti->opAborted = PWP_FALSE;
184  // make fileDest's path the cwd
185  FileDestPwpCwd loc(pRti->FormatInfo.fileDest, pReadInfo->fileDest);
186  // give impl control!
187  ret = runtimeReadGrid(pRti);
188  // loc dtor will force cwd back to original location
189  }
190  return ret;
191 }
const char * PwGrdpFormat(GRDP_IMPORTER handle, GRDP_FORMATINFO *pFormatInfo)
Get GRDP_FORMATINFO data for a GRDP importer handle.
Definition: apiGRDP.cxx:133
PWP_BOOL PwGridRead(GRDP_IMPORTER handle, PWGM_HGRIDMODEL model, const GRDP_READINFO *pReadInfo)
Initiates reading a grid model.
Definition: apiGRDP.cxx:175
GRDP importer instance handle.
Definition: apiGRDP.h:144
bool push(const char *dir)
Sets the current working directory.
Definition: PwpCwd.cxx:27
The data representing a grid importer instance.
Definition: apiGRDPUtils.h:117
unsigned int PWP_UINT32
32-bit unsigned integer
Definition: apiPWP.h:210
GRDP_RTITEM grdpRtItem[]
The runtime array of GRDP_RTITEM items.
Definition: apiGRDP.cxx:27
GRDP_IMPORTER PwCreateGrdpByName(const char name[])
Create GRDP importer instance with given name.
Definition: apiGRDP.cxx:91
void PWP_VOID
no value
Definition: apiPWP.h:317
#define ARRAYSIZE(arrname)
Calculates the size of a statically declared array.
Definition: apiUtils.h:164
GRDP_RTITEM * grdpFindFormatByName(const char name[])
Find an item in grdpRtItem[] by it&#39;s name.
PWGM_HGRIDMODEL model
Runtime grid model handle to import.
Definition: apiGRDPUtils.h:157
static PWP_BOOL grdpRuntimeCreate(GRDP_RTITEM *pRti)
Definition: apiGRDP.cxx:59
Grid import read control information.
Definition: apiGRDP.h:108
const char * name
format Name.
Definition: apiGRDP.h:79
#define PWGM_HGRIDMODEL_ISVALID(h)
returns non-zero value if handle is valid
Definition: apiGridModel.h:328
static PWP_VOID grdpRuntimeDestroy(GRDP_RTITEM *pRti)
Definition: apiGRDP.cxx:69
Base plugin utilities.
PWP_UINT32 grdpFormatCnt
The number of entries in grdpRtItem[] array.
Definition: apiGRDP.cxx:33
Manipulates the current working directory.
Definition: PwpCwd.h:56
GRDP utilities.
PWP_VOID PwDestroyGrdp(GRDP_IMPORTER *handle)
Destroy GRDP importer instance.
Definition: apiGRDP.cxx:102
GRDP_IMPORTER PwCreateGrdpById(PWP_UINT32 id)
Create GRDP importer instance with given id.
Definition: apiGRDP.cxx:80
static GRDP_RTITEM * grdpH2Rti(GRDP_IMPORTER handle)
Definition: apiGRDP.cxx:42
int PWP_BOOL
logical value
Definition: apiPWP.h:303
PWP_UINT32 PwGetGrdpFormatCount()
Get the number of supported GRDP importers.
Definition: apiGRDP.cxx:126
PWP_BOOL runtimeReadGrid(GRDP_RTITEM *pRti)
GRDP_RTITEM * grdpFindFormatById(PWP_UINT32 id)
Find an item in grdpRtItem[] by it&#39;s id.
The information returned for each supported GRDP importer.
Definition: apiGRDP.h:70
FileDestPwpCwd(const PWP_ENUM_FILEDEST id, const char *fileDest)
Definition: apiGRDP.cxx:146
GRDP_FORMATINFO FormatInfo
The Grid Import Plugin format data.
Definition: apiGRDPUtils.h:122
PWP_VOID runtimeReadGridDestroy(GRDP_RTITEM *pRti)
PWP_ENUM_FILEDEST
File destination types.
Definition: apiPWP.h:743
PWP_BOOL runtimeReadGridCreate(GRDP_RTITEM *pRti)
An opaque handle to a grid model.
Definition: apiGridModel.h:326
Static Initialization Data for the GRDP_RTITEM Array.
const char * PwEnumGrdpFormat(PWP_UINT32 ndx, GRDP_FORMATINFO *pFormatInfo)
Enumerate GRDP_FORMATINFO data for all supported GRDP importers.
Definition: apiGRDP.cxx:115
const GRDP_READINFO * pReadInfo
Runtime grid import settings.
Definition: apiGRDPUtils.h:163
PWP_ENUM_FILEDEST fileDest
Specifies the desired output destination type.
Definition: apiGRDP.h:93
const char * fileDest
requested file destination.
Definition: apiGRDP.h:111
#define PWP_FALSE
PWP_BOOL logical &quot;false&quot; value.
Definition: apiPWP.h:306
Data and functions useful to PWP-API compliant plugins.
Pointwise Grid Import Plugin API (GRDP-API)