w-mesh-tecplot 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci-test.yml +3 -3
- package/README.md +1 -1
- package/dist/w-mesh-tecplot.umd.js +1 -1
- package/docs/WMeshTecplot.mjs.html +2 -2
- package/docs/convertColumn.mjs.html +177 -0
- package/docs/convertLay.mjs.html +153 -0
- package/docs/execExportPng.mjs.html +185 -0
- package/docs/global.html +1274 -2
- package/docs/index.html +2 -2
- package/docs/parseSliceData.mjs.html +173 -0
- package/docs/parseViewData.mjs.html +328 -0
- package/g.read.mjs +1 -1
- package/g.write.mjs +1 -1
- package/package.json +4 -4
- package/src/_tecplot_simple_hole.lay.tmp +1862 -0
- package/src/_tecplot_simple_mesh.lay.tmp +1859 -0
- package/src/_tecplot_simple_slice.lay.tmp +1862 -0
- package/src/convertColumn.mjs +13 -0
- package/src/convertLay.mjs +81 -0
- package/src/execExportPng.mjs +22 -3
- package/src/parseSliceData.mjs +101 -0
- package/src/parseViewData.mjs +13 -1
- package/toolg/gDistRollup.mjs +4 -0
|
@@ -9,12 +9,12 @@ jobs:
|
|
|
9
9
|
|
|
10
10
|
strategy:
|
|
11
11
|
matrix:
|
|
12
|
-
node-version: [
|
|
12
|
+
node-version: [24.x]
|
|
13
13
|
|
|
14
14
|
steps:
|
|
15
|
-
- uses: actions/checkout@
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
16
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
17
|
-
uses: actions/setup-node@
|
|
17
|
+
uses: actions/setup-node@v4
|
|
18
18
|
with:
|
|
19
19
|
node-version: ${{ matrix.node-version }}
|
|
20
20
|
- run: npm cache clean -f
|
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ A tool for Tecplot data.
|
|
|
12
12
|
To view documentation or get support, visit [docs](https://yuda-lyu.github.io/w-mesh-tecplot/global.html).
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
|
+
|
|
15
16
|
### Using npm(ES6 module):
|
|
16
17
|
```alias
|
|
17
18
|
npm i w-mesh-tecplot
|
|
@@ -29,7 +30,6 @@ npm i w-mesh-tecplot
|
|
|
29
30
|
import fs from 'fs'
|
|
30
31
|
import wmt from './src/WMeshTecplot.mjs'
|
|
31
32
|
|
|
32
|
-
|
|
33
33
|
let fpIn = './_mesh/mesh.json'
|
|
34
34
|
let fpOut = './_mesh/cv2tecplot.dat'
|
|
35
35
|
let name = 'cv2tecplot'
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<nav >
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#WMeshTecplot">WMeshTecplot</a></li><li><a href="global.html#readTecplot">readTecplot</a></li><li><a href="global.html#writeTecplot">writeTecplot</a></li></ul>
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#WMeshTecplot">WMeshTecplot</a></li><li><a href="global.html#convertColumn">convertColumn</a></li><li><a href="global.html#convertLay">convertLay</a></li><li><a href="global.html#eachSliceValue">eachSliceValue</a></li><li><a href="global.html#execExportPng">execExportPng</a></li><li><a href="global.html#parseSliceData">parseSliceData</a></li><li><a href="global.html#parseViewData">parseViewData</a></li><li><a href="global.html#readTecplot">readTecplot</a></li><li><a href="global.html#writeTecplot">writeTecplot</a></li></ul>
|
|
33
33
|
|
|
34
34
|
</nav>
|
|
35
35
|
|
|
@@ -264,7 +264,7 @@ export default WMeshTecplot
|
|
|
264
264
|
<br class="clear">
|
|
265
265
|
|
|
266
266
|
<footer>
|
|
267
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.
|
|
267
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Thu Jul 02 2026 17:41:30 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
268
268
|
</footer>
|
|
269
269
|
|
|
270
270
|
<script>prettyPrint();</script>
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>convertColumn.mjs - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#WMeshTecplot">WMeshTecplot</a></li><li><a href="global.html#convertColumn">convertColumn</a></li><li><a href="global.html#convertLay">convertLay</a></li><li><a href="global.html#eachSliceValue">eachSliceValue</a></li><li><a href="global.html#execExportPng">execExportPng</a></li><li><a href="global.html#parseSliceData">parseSliceData</a></li><li><a href="global.html#parseViewData">parseViewData</a></li><li><a href="global.html#readTecplot">readTecplot</a></li><li><a href="global.html#writeTecplot">writeTecplot</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">convertColumn.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import get from 'lodash-es/get.js'
|
|
49
|
+
import each from 'lodash-es/each.js'
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 將柱狀(box)元素陣列轉換為Tecplot brick所需之節點與元素資料
|
|
54
|
+
*
|
|
55
|
+
* 各輸入元素以中心點(x、y、z)與長寬高(dx、dy、dz)展開為8個角節點,節點與元素皆帶有材料mat與類型type。
|
|
56
|
+
*
|
|
57
|
+
* @param {Array} eles 輸入元素物件陣列,各元素含x、y、z、dx、dy、dz、mat、type
|
|
58
|
+
* @return {Object} 回傳物件,含nodes(節點物件陣列,各含x、y、z、mat、type)與eles(元素物件陣列,各含nodes節點索引陣列、mat、type)
|
|
59
|
+
* @example
|
|
60
|
+
*
|
|
61
|
+
* let r = convertColumn([{ x: 0, y: 0, z: 0, dx: 1, dy: 1, dz: 1, mat: 1, type: 0 }])
|
|
62
|
+
* // => { nodes: [...], eles: [...] }
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
function convertColumn(eles) {
|
|
66
|
+
|
|
67
|
+
//ns, es
|
|
68
|
+
let ns = []
|
|
69
|
+
let es = []
|
|
70
|
+
|
|
71
|
+
//addNode
|
|
72
|
+
let addNode = (_n) => {
|
|
73
|
+
let x = get(_n, 0, 0)
|
|
74
|
+
let y = get(_n, 1, 0)
|
|
75
|
+
let z = get(_n, 2, 0)
|
|
76
|
+
let mat = get(_n, 3, 0)
|
|
77
|
+
let type = get(_n, 4, 0)
|
|
78
|
+
let n = {
|
|
79
|
+
x,
|
|
80
|
+
y,
|
|
81
|
+
z,
|
|
82
|
+
mat,
|
|
83
|
+
type,
|
|
84
|
+
}
|
|
85
|
+
ns.push(n)
|
|
86
|
+
return ns.length
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//addEle
|
|
90
|
+
let addEle = (ele) => {
|
|
91
|
+
|
|
92
|
+
//params
|
|
93
|
+
let xc = get(ele, 'x', 0)
|
|
94
|
+
let yc = get(ele, 'y', 0)
|
|
95
|
+
let zc = get(ele, 'z', 0)
|
|
96
|
+
let dx = get(ele, 'dx', 0)
|
|
97
|
+
let dy = get(ele, 'dy', 0)
|
|
98
|
+
let dz = get(ele, 'dz', 0)
|
|
99
|
+
let mat = get(ele, 'mat', 0)
|
|
100
|
+
let type = get(ele, 'type', 0)
|
|
101
|
+
|
|
102
|
+
//min and max
|
|
103
|
+
let xmin = xc - dx / 2
|
|
104
|
+
let xmax = xc + dx / 2
|
|
105
|
+
let ymin = yc - dy / 2
|
|
106
|
+
let ymax = yc + dy / 2
|
|
107
|
+
let zmin = zc - dz / 2
|
|
108
|
+
let zmax = zc + dz / 2
|
|
109
|
+
|
|
110
|
+
//n and ind, 皆預設提供mat與type
|
|
111
|
+
let n1 = [xmin, ymin, zmin, mat, type]
|
|
112
|
+
let ind1 = addNode(n1)
|
|
113
|
+
let n2 = [xmax, ymin, zmin, mat, type]
|
|
114
|
+
let ind2 = addNode(n2)
|
|
115
|
+
let n3 = [xmax, ymax, zmin, mat, type]
|
|
116
|
+
let ind3 = addNode(n3)
|
|
117
|
+
let n4 = [xmin, ymax, zmin, mat, type]
|
|
118
|
+
let ind4 = addNode(n4)
|
|
119
|
+
let n5 = [xmin, ymin, zmax, mat, type]
|
|
120
|
+
let ind5 = addNode(n5)
|
|
121
|
+
let n6 = [xmax, ymin, zmax, mat, type]
|
|
122
|
+
let ind6 = addNode(n6)
|
|
123
|
+
let n7 = [xmax, ymax, zmax, mat, type]
|
|
124
|
+
let ind7 = addNode(n7)
|
|
125
|
+
let n8 = [xmin, ymax, zmax, mat, type]
|
|
126
|
+
let ind8 = addNode(n8)
|
|
127
|
+
|
|
128
|
+
//nodes
|
|
129
|
+
let nodes = [ind1, ind2, ind3, ind4, ind5, ind6, ind7, ind8]
|
|
130
|
+
|
|
131
|
+
//push
|
|
132
|
+
es.push({
|
|
133
|
+
nodes,
|
|
134
|
+
mat,
|
|
135
|
+
type,
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
//addEle
|
|
141
|
+
each(eles, (ele) => {
|
|
142
|
+
addEle(ele)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
nodes: ns,
|
|
147
|
+
eles: es,
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
export default convertColumn
|
|
153
|
+
</code></pre>
|
|
154
|
+
</article>
|
|
155
|
+
</section>
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
</div>
|
|
163
|
+
|
|
164
|
+
<br class="clear">
|
|
165
|
+
|
|
166
|
+
<footer>
|
|
167
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Thu Jul 02 2026 17:41:30 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
168
|
+
</footer>
|
|
169
|
+
|
|
170
|
+
<script>prettyPrint();</script>
|
|
171
|
+
<script src="scripts/polyfill.js"></script>
|
|
172
|
+
<script src="scripts/linenumber.js"></script>
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
</body>
|
|
177
|
+
</html>
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>convertLay.mjs - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#WMeshTecplot">WMeshTecplot</a></li><li><a href="global.html#convertColumn">convertColumn</a></li><li><a href="global.html#convertLay">convertLay</a></li><li><a href="global.html#eachSliceValue">eachSliceValue</a></li><li><a href="global.html#execExportPng">execExportPng</a></li><li><a href="global.html#parseSliceData">parseSliceData</a></li><li><a href="global.html#parseViewData">parseViewData</a></li><li><a href="global.html#readTecplot">readTecplot</a></li><li><a href="global.html#writeTecplot">writeTecplot</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">convertLay.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import path from 'path'
|
|
49
|
+
import fs from 'fs'
|
|
50
|
+
import { fileURLToPath } from 'url'
|
|
51
|
+
import each from 'lodash-es/each.js'
|
|
52
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
53
|
+
import sep from 'wsemi/src/sep.mjs'
|
|
54
|
+
import parseViewData from './parseViewData.mjs'
|
|
55
|
+
import parseSliceData, { eachSliceValue } from './parseSliceData.mjs'
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
//範本與本模組同層(src/), 以模組位置定位, 不受執行cwd影響
|
|
59
|
+
let __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
60
|
+
let fpMesh = path.join(__dirname, '_tecplot_simple_mesh.lay.tmp')
|
|
61
|
+
let fpHole = path.join(__dirname, '_tecplot_simple_hole.lay.tmp')
|
|
62
|
+
let fpSlice = path.join(__dirname, '_tecplot_simple_slice.lay.tmp')
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 由來源Tecplot的lay套用內建範本,另存為展示用lay
|
|
66
|
+
*
|
|
67
|
+
* 視角設定(三軸範圍、旋轉原點、視角位置、角度、視距)由來源lay經parseViewData內部解析後,替換範本內對應佔位符;當type為'slice'時,另由parseSliceData就地移植切片起訖點座標與中間切片數,來源lay缺少者沿用範本預設。
|
|
68
|
+
*
|
|
69
|
+
* @param {String} fpInLay 輸入來源Tecplot的lay檔案位置字串,供內部解析視角與切片設定
|
|
70
|
+
* @param {String} fnInDat 輸入資料集名稱字串,替換範本內{fn}佔位符
|
|
71
|
+
* @param {String} type 輸入範本類型字串,可選'mesh'、'hole'、'slice'
|
|
72
|
+
* @param {String} fpOutLay 輸入另存展示用lay之檔案位置字串
|
|
73
|
+
* @example
|
|
74
|
+
*
|
|
75
|
+
* convertLay('./ttt.lay', 'abc', 'mesh', './out_mesh.lay')
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
let convertLay = (fpInLay, fnInDat, type, fpOutLay) => {
|
|
79
|
+
|
|
80
|
+
let c = ''
|
|
81
|
+
if (type === 'mesh') {
|
|
82
|
+
c = fs.readFileSync(fpMesh, 'utf8')
|
|
83
|
+
}
|
|
84
|
+
else if (type === 'hole') {
|
|
85
|
+
c = fs.readFileSync(fpHole, 'utf8')
|
|
86
|
+
}
|
|
87
|
+
else if (type === 'slice') {
|
|
88
|
+
c = fs.readFileSync(fpSlice, 'utf8')
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new Error(`invalid type[${type}]`)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//視角19鍵由來源lay內部解析(與slice對稱), 併入fn(來源lay給不出的輸出名)後替換範本佔位符
|
|
95
|
+
let kp = {
|
|
96
|
+
...parseViewData(fpInLay),
|
|
97
|
+
fn: fnInDat,
|
|
98
|
+
}
|
|
99
|
+
each(kp, (v, k) => {
|
|
100
|
+
c = c.replaceAll(`{${k}}`, v)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
//slice型: 由來源lay就地移植切片起訖點座標與中間切片數
|
|
104
|
+
//容錯: 走訪範本內每個切片數值, 來源有值就覆寫, 來源缺的沿用範本預設並console.log提醒
|
|
105
|
+
if (type === 'slice') {
|
|
106
|
+
let src = parseSliceData(fpInLay)
|
|
107
|
+
let vs = sep(c, '\n')
|
|
108
|
+
let miss = []
|
|
109
|
+
eachSliceValue(vs, (key, k, val) => {
|
|
110
|
+
if (isestr(src[key])) {
|
|
111
|
+
vs[k] = vs[k].replace(/=[^\r\n]*/, `= ${src[key]}`) //保留範本縮排與換行, 只換等號後的值
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
miss.push(key)
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
if (miss.length > 0) {
|
|
118
|
+
console.log(`[convertLay] slice提醒: 來源lay[${fpInLay}]缺少下列切片設定, 已沿用範本預設: ${miss.join(', ')}`)
|
|
119
|
+
}
|
|
120
|
+
c = vs.join('\n')
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
fs.writeFileSync(fpOutLay, c, 'utf8')
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
export default convertLay
|
|
129
|
+
</code></pre>
|
|
130
|
+
</article>
|
|
131
|
+
</section>
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
<br class="clear">
|
|
141
|
+
|
|
142
|
+
<footer>
|
|
143
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Thu Jul 02 2026 17:41:30 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
144
|
+
</footer>
|
|
145
|
+
|
|
146
|
+
<script>prettyPrint();</script>
|
|
147
|
+
<script src="scripts/polyfill.js"></script>
|
|
148
|
+
<script src="scripts/linenumber.js"></script>
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
</body>
|
|
153
|
+
</html>
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>execExportPng.mjs - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#WMeshTecplot">WMeshTecplot</a></li><li><a href="global.html#convertColumn">convertColumn</a></li><li><a href="global.html#convertLay">convertLay</a></li><li><a href="global.html#eachSliceValue">eachSliceValue</a></li><li><a href="global.html#execExportPng">execExportPng</a></li><li><a href="global.html#parseSliceData">parseSliceData</a></li><li><a href="global.html#parseViewData">parseViewData</a></li><li><a href="global.html#readTecplot">readTecplot</a></li><li><a href="global.html#writeTecplot">writeTecplot</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">execExportPng.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import path from 'path'
|
|
49
|
+
import fs from 'fs'
|
|
50
|
+
import get from 'lodash-es/get.js'
|
|
51
|
+
import trim from 'lodash-es/trim.js'
|
|
52
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
53
|
+
import isnum from 'wsemi/src/isnum.mjs'
|
|
54
|
+
import now2strp from 'wsemi/src/now2strp.mjs'
|
|
55
|
+
import execProcess from 'wsemi/src/execProcess.mjs'
|
|
56
|
+
import fsIsFile from 'wsemi/src/fsIsFile.mjs'
|
|
57
|
+
import fsRenameFile from 'wsemi/src/fsRenameFile.mjs'
|
|
58
|
+
import fsDeleteFile from 'wsemi/src/fsDeleteFile.mjs'
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 呼叫Tecplot執行檔執行巨集(*.mcr),將lay輸出(export)為png圖檔
|
|
63
|
+
*
|
|
64
|
+
* 內部產生暫存巨集與暫存png,透過Tecplot批次模式產圖後改名至fpOut,並清除暫存檔;產圖失敗時throw。
|
|
65
|
+
*
|
|
66
|
+
* @param {String} fpLay 輸入Tecplot的lay檔案位置字串
|
|
67
|
+
* @param {String} fpOut 輸入另存png圖檔之檔案位置字串
|
|
68
|
+
* @param {Object} [opt={}] 輸入設定物件,預設{}
|
|
69
|
+
* @param {String} [opt.head] 輸入巨集開頭字串,預設'#!MC 1400'
|
|
70
|
+
* @param {String} [opt.fpExe] 輸入Tecplot執行檔位置字串,預設'C:\\Program Files\\Tecplot\\Tec360 2013R1\\bin\\tec360.exe'
|
|
71
|
+
* @param {Number} [opt.widthPic=1000] 輸入輸出圖片寬度數字,預設1000
|
|
72
|
+
* @return {Promise} 回傳Promise,resolve回傳undefined,reject回傳錯誤訊息
|
|
73
|
+
* @example
|
|
74
|
+
*
|
|
75
|
+
* await execExportPng('./ttt.lay', './out.png')
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
let execExportPng = async(fpLay, fpOut, opt = {}) => {
|
|
79
|
+
|
|
80
|
+
//d
|
|
81
|
+
let head = get(opt, 'head', '')
|
|
82
|
+
if (!isestr(head)) {
|
|
83
|
+
head = `#!MC 1400`
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//fpExe
|
|
87
|
+
let fpExe = get(opt, 'fpExe', '')
|
|
88
|
+
if (!isestr(fpExe)) {
|
|
89
|
+
fpExe = `C:\\Program Files\\Tecplot\\Tec360 2013R1\\bin\\tec360.exe`
|
|
90
|
+
}
|
|
91
|
+
if (!fsIsFile(fpExe)) {
|
|
92
|
+
throw new Error(`opt.fpExe[${fpExe}] does not exist`)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//widthPic
|
|
96
|
+
let widthPic = get(opt, 'widthPic')
|
|
97
|
+
if (!isnum(widthPic)) {
|
|
98
|
+
widthPic = 1000
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//fpLay
|
|
102
|
+
fpLay = path.resolve(fpLay)
|
|
103
|
+
|
|
104
|
+
//id
|
|
105
|
+
let id = now2strp()
|
|
106
|
+
|
|
107
|
+
//fpTempPng
|
|
108
|
+
let fpTempPng = `./_tecplot_pic_${id}.png`
|
|
109
|
+
fpTempPng = path.resolve(fpTempPng)
|
|
110
|
+
|
|
111
|
+
//fpTempMcr
|
|
112
|
+
let fpTempMcr = `./_tecplot_export_${id}.mcr`
|
|
113
|
+
fpTempMcr = path.resolve(fpTempMcr)
|
|
114
|
+
|
|
115
|
+
if (true) {
|
|
116
|
+
|
|
117
|
+
let t = `
|
|
118
|
+
|
|
119
|
+
${head}
|
|
120
|
+
# Created by Tecplot
|
|
121
|
+
|
|
122
|
+
$!EXPORTSETUP EXPORTFORMAT = PNG
|
|
123
|
+
$!EXPORTSETUP IMAGEWIDTH = ${widthPic}
|
|
124
|
+
$!EXPORTSETUP EXPORTFNAME = '${fpTempPng}'
|
|
125
|
+
$!EXPORT
|
|
126
|
+
EXPORTREGION = CURRENTFRAME
|
|
127
|
+
|
|
128
|
+
`
|
|
129
|
+
t = trim(t) //head要放第一列, 故需要trim
|
|
130
|
+
|
|
131
|
+
fs.writeFileSync(fpTempMcr, t, 'utf8')
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//execProcess
|
|
136
|
+
let prog = fpExe
|
|
137
|
+
let args = ['-b', fpLay, '-p', fpTempMcr]
|
|
138
|
+
await execProcess(prog, args) //預設spawn
|
|
139
|
+
|
|
140
|
+
//b
|
|
141
|
+
let b = fsIsFile(fpTempPng)
|
|
142
|
+
|
|
143
|
+
//fsRenameFile
|
|
144
|
+
if (b) {
|
|
145
|
+
fsRenameFile(fpTempPng, fpOut)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
//fsDeleteFile
|
|
149
|
+
fsDeleteFile(fpTempPng)
|
|
150
|
+
fsDeleteFile(fpTempMcr)
|
|
151
|
+
|
|
152
|
+
//check
|
|
153
|
+
if (!b) {
|
|
154
|
+
throw new Error(`can not export fpOut[${fpOut}]`)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
export default execExportPng
|
|
161
|
+
</code></pre>
|
|
162
|
+
</article>
|
|
163
|
+
</section>
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
</div>
|
|
171
|
+
|
|
172
|
+
<br class="clear">
|
|
173
|
+
|
|
174
|
+
<footer>
|
|
175
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Thu Jul 02 2026 17:41:30 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
176
|
+
</footer>
|
|
177
|
+
|
|
178
|
+
<script>prettyPrint();</script>
|
|
179
|
+
<script src="scripts/polyfill.js"></script>
|
|
180
|
+
<script src="scripts/linenumber.js"></script>
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
</body>
|
|
185
|
+
</html>
|