geomcli 0.5.12 → 0.5.14
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/dist/index.d.ts +7 -0
- package/dist/index.js +595 -0
- package/dist/index.js.map +1 -0
- package/package.json +7 -2
- package/.eslintignore +0 -17
- package/.eslintrc.cjs +0 -24
- package/.prettierignore +0 -15
- package/.prettierrc +0 -8
- package/src/geom_cli.ts +0 -550
- package/src/geom_write.ts +0 -136
- package/src/index.test.ts +0 -16
- package/src/index.ts +0 -6
- package/tsconfig.json +0 -14
- package/vitest.config.ts +0 -7
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geomcli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.14",
|
|
4
4
|
"description": "the nodejs companion library of geometrix",
|
|
5
5
|
"private": false,
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/charlyoleg2/parametrix.git"
|
|
9
9
|
},
|
|
10
|
-
"homepage": "https://github.com/charlyoleg2/parametrix/pkg/geomcli#readme",
|
|
10
|
+
"homepage": "https://github.com/charlyoleg2/parametrix/tree/main/pkg/geomcli#readme",
|
|
11
11
|
"keywords": [
|
|
12
12
|
"cad",
|
|
13
13
|
"programmatic",
|
|
@@ -63,6 +63,11 @@
|
|
|
63
63
|
"default": "./dist/index.js"
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
+
"files": [
|
|
67
|
+
"dist",
|
|
68
|
+
"!dist/**/*.test.*",
|
|
69
|
+
"!dist/**/*.spec.*"
|
|
70
|
+
],
|
|
66
71
|
"types": "./dist/index.d.ts",
|
|
67
72
|
"type": "module"
|
|
68
73
|
}
|
package/.eslintignore
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
.DS_Store
|
|
2
|
-
node_modules
|
|
3
|
-
/build
|
|
4
|
-
/.svelte-kit
|
|
5
|
-
/package
|
|
6
|
-
.env
|
|
7
|
-
.env.*
|
|
8
|
-
!.env.example
|
|
9
|
-
|
|
10
|
-
# Ignore files for PNPM, NPM and YARN
|
|
11
|
-
pnpm-lock.yaml
|
|
12
|
-
package-lock.json
|
|
13
|
-
yarn.lock
|
|
14
|
-
|
|
15
|
-
# ignore recommended by eslint
|
|
16
|
-
vitest.config.ts
|
|
17
|
-
dist/
|
package/.eslintrc.cjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
extends: [
|
|
3
|
-
'eslint:recommended',
|
|
4
|
-
'plugin:@typescript-eslint/recommended-type-checked',
|
|
5
|
-
//'plugin:@typescript-eslint/strict-type-checked',
|
|
6
|
-
'plugin:@typescript-eslint/stylistic-type-checked',
|
|
7
|
-
'prettier'
|
|
8
|
-
],
|
|
9
|
-
plugins: ['@typescript-eslint'],
|
|
10
|
-
parser: '@typescript-eslint/parser',
|
|
11
|
-
parserOptions: {
|
|
12
|
-
//sourceType: 'module',
|
|
13
|
-
//ecmaVersion: 2020,
|
|
14
|
-
project: true,
|
|
15
|
-
tsconfigRootDir: __dirname
|
|
16
|
-
},
|
|
17
|
-
root: true
|
|
18
|
-
//env: {
|
|
19
|
-
// browser: true,
|
|
20
|
-
// es2021: true,
|
|
21
|
-
// node: true
|
|
22
|
-
//},
|
|
23
|
-
//ignorePatterns: ['*.cjs'],
|
|
24
|
-
};
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
package/src/geom_cli.ts
DELETED
|
@@ -1,550 +0,0 @@
|
|
|
1
|
-
// geom_cli.ts
|
|
2
|
-
|
|
3
|
-
import type { tParamVal, tGeom, tSubDesign, tPageDef, tAllPageDef, tSubInst } from 'geometrix';
|
|
4
|
-
import { PType, EFormat, designParam, prefixLog, paramListToVal } from 'geometrix';
|
|
5
|
-
import { geom_write, writeParams, readParams } from './geom_write';
|
|
6
|
-
import yargs from 'yargs';
|
|
7
|
-
import { hideBin } from 'yargs/helpers';
|
|
8
|
-
import { version } from '../package.json';
|
|
9
|
-
|
|
10
|
-
function get_design_array(dList: tAllPageDef): string[] {
|
|
11
|
-
const rDesignArray = Object.keys(dList);
|
|
12
|
-
return rDesignArray;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function selectDesign(dList: tAllPageDef, selD: string): tPageDef {
|
|
16
|
-
if (!Object.keys(dList).includes(selD)) {
|
|
17
|
-
console.log(`err918: design ${selD} is not defined`);
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
|
20
|
-
return dList[selD];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function selectDesignN(dList: tAllPageDef, selD: string): string {
|
|
24
|
-
const theD = selectDesign(dList, selD);
|
|
25
|
-
const dName = theD.pDef.partName;
|
|
26
|
-
return dName;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function parseModif(modif: string[], printLog: boolean): tParamVal {
|
|
30
|
-
const pVal: tParamVal = {};
|
|
31
|
-
const arrayLen = modif.length;
|
|
32
|
-
if (arrayLen % 2 === 1) {
|
|
33
|
-
throw `err903: length ${arrayLen} of modif string array is odd!`;
|
|
34
|
-
}
|
|
35
|
-
for (let i = 0; i < arrayLen / 2; i++) {
|
|
36
|
-
const valStr = modif[2 * i + 1];
|
|
37
|
-
const val = parseFloat(valStr);
|
|
38
|
-
if (isNaN(val)) {
|
|
39
|
-
throw `err908: ${valStr} is not a number!`;
|
|
40
|
-
}
|
|
41
|
-
pVal[modif[2 * i]] = val;
|
|
42
|
-
}
|
|
43
|
-
const pValLen = Object.keys(pVal).length;
|
|
44
|
-
if (printLog && pValLen > 0) {
|
|
45
|
-
const rlog = `info308: ${pValLen} parameters of modifier`;
|
|
46
|
-
console.log(rlog);
|
|
47
|
-
}
|
|
48
|
-
return pVal;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function computeGeom(
|
|
52
|
-
dList: tAllPageDef,
|
|
53
|
-
selD: string,
|
|
54
|
-
paramPath: string,
|
|
55
|
-
modif: string[],
|
|
56
|
-
printLog: boolean
|
|
57
|
-
): tGeom {
|
|
58
|
-
const theD = selectDesign(dList, selD);
|
|
59
|
-
let rlog = `Compute design ${selD} (${theD.pDef.partName}):\n`;
|
|
60
|
-
const dParam = designParam(theD.pDef);
|
|
61
|
-
try {
|
|
62
|
-
dParam.applyParamVal(readParams(paramPath, printLog));
|
|
63
|
-
dParam.applyParamVal(parseModif(modif, printLog));
|
|
64
|
-
} catch (emsg) {
|
|
65
|
-
console.log('err271: error while applying new parameters');
|
|
66
|
-
console.log(emsg);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
const simtime = 0;
|
|
70
|
-
const dGeom = theD.pGeom(simtime, dParam.getParamVal());
|
|
71
|
-
//checkGeom(dGeom);
|
|
72
|
-
rlog += prefixLog(dGeom.logstr, dParam.partName);
|
|
73
|
-
if (dGeom.calcErr) {
|
|
74
|
-
rlog += `err907: Error while computing ${theD.pDef.partName}\n`;
|
|
75
|
-
console.log(rlog);
|
|
76
|
-
process.exit(1);
|
|
77
|
-
} else {
|
|
78
|
-
rlog += `${theD.pDef.partName} successfully computed\n`;
|
|
79
|
-
}
|
|
80
|
-
if (printLog) {
|
|
81
|
-
console.log(rlog);
|
|
82
|
-
}
|
|
83
|
-
return dGeom;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function get_figure_array(
|
|
87
|
-
dList: tAllPageDef,
|
|
88
|
-
selD: string,
|
|
89
|
-
paramPath: string,
|
|
90
|
-
modif: string[]
|
|
91
|
-
): string[] {
|
|
92
|
-
const dGeom = computeGeom(dList, selD, paramPath, modif, false);
|
|
93
|
-
const rfigN = Object.keys(dGeom.fig);
|
|
94
|
-
return rfigN;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function get_subdesign_array(
|
|
98
|
-
dList: tAllPageDef,
|
|
99
|
-
selD: string,
|
|
100
|
-
paramPath: string,
|
|
101
|
-
modif: string[]
|
|
102
|
-
): tSubDesign {
|
|
103
|
-
const dGeom = computeGeom(dList, selD, paramPath, modif, false);
|
|
104
|
-
const subd = dGeom.sub;
|
|
105
|
-
return subd;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function get_subd(
|
|
109
|
-
dList: tAllPageDef,
|
|
110
|
-
selD: string,
|
|
111
|
-
subdN: string,
|
|
112
|
-
paramPath: string,
|
|
113
|
-
modif: string[],
|
|
114
|
-
printLog: boolean
|
|
115
|
-
): tSubInst {
|
|
116
|
-
const theD = selectDesign(dList, selD);
|
|
117
|
-
const dGeom = computeGeom(dList, selD, paramPath, modif, printLog);
|
|
118
|
-
if (!Object.keys(dGeom.sub).includes(subdN)) {
|
|
119
|
-
console.log(`err207: sub-design ${subdN} not defined in partName ${theD.pDef.partName}`);
|
|
120
|
-
process.exit(1);
|
|
121
|
-
}
|
|
122
|
-
const rSubd = dGeom.sub[subdN];
|
|
123
|
-
if (printLog) {
|
|
124
|
-
const rlog = `Subdesign ${subdN} (${rSubd.partName}) of ${selD} (${theD.pDef.partName}):\n`;
|
|
125
|
-
console.log(rlog);
|
|
126
|
-
}
|
|
127
|
-
return rSubd;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const c_fileFormat = [
|
|
131
|
-
'json_param',
|
|
132
|
-
'svg_all_figures',
|
|
133
|
-
'dxf_all_figures',
|
|
134
|
-
'pax_all',
|
|
135
|
-
'scad_3d_openscad',
|
|
136
|
-
'js_3d_openjscad',
|
|
137
|
-
'zip_all'
|
|
138
|
-
];
|
|
139
|
-
|
|
140
|
-
function get_outopt_array(
|
|
141
|
-
dList: tAllPageDef,
|
|
142
|
-
selD: string,
|
|
143
|
-
paramPath: string,
|
|
144
|
-
modif: string[]
|
|
145
|
-
): string[] {
|
|
146
|
-
const rOutOpt: string[] = [];
|
|
147
|
-
const figN = get_figure_array(dList, selD, paramPath, modif);
|
|
148
|
-
const subdN = Object.keys(get_subdesign_array(dList, selD, paramPath, modif));
|
|
149
|
-
for (const figNi of figN) {
|
|
150
|
-
rOutOpt.push(`svg__${figNi}`);
|
|
151
|
-
}
|
|
152
|
-
for (const figNi of figN) {
|
|
153
|
-
rOutOpt.push(`dxf__${figNi}`);
|
|
154
|
-
}
|
|
155
|
-
for (const subdNi of subdN) {
|
|
156
|
-
rOutOpt.push(`json_sub_param_${subdNi}`);
|
|
157
|
-
}
|
|
158
|
-
for (const ffi of c_fileFormat) {
|
|
159
|
-
rOutOpt.push(`${ffi}`);
|
|
160
|
-
}
|
|
161
|
-
return rOutOpt;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
enum EWrite {
|
|
165
|
-
eEGOPARAMS,
|
|
166
|
-
eSUBDPARAMS,
|
|
167
|
-
eOTHERS
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
interface tEFormat {
|
|
171
|
-
eWrite: EWrite;
|
|
172
|
-
eFormat: EFormat;
|
|
173
|
-
eFace: string;
|
|
174
|
-
eSubdesign: string;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function decompose_outopt(outopt: string): tEFormat {
|
|
178
|
-
let rWrite = EWrite.eOTHERS;
|
|
179
|
-
let rFormat = EFormat.ePAX;
|
|
180
|
-
let rFace = 'all';
|
|
181
|
-
let rSubD = '';
|
|
182
|
-
const reSvg = /^svg__/;
|
|
183
|
-
const reDxf = /^dxf__/;
|
|
184
|
-
const reSubP = /^json_sub_param_/;
|
|
185
|
-
if (outopt.match(reSvg)) {
|
|
186
|
-
rFace = outopt.replace(reSvg, '');
|
|
187
|
-
rFormat = EFormat.eSVG;
|
|
188
|
-
rWrite = EWrite.eOTHERS;
|
|
189
|
-
} else if (outopt.match(reDxf)) {
|
|
190
|
-
rFace = outopt.replace(reDxf, '');
|
|
191
|
-
rFormat = EFormat.eDXF;
|
|
192
|
-
rWrite = EWrite.eOTHERS;
|
|
193
|
-
} else if (outopt.match(reSubP)) {
|
|
194
|
-
rSubD = outopt.replace(reSubP, '');
|
|
195
|
-
rWrite = EWrite.eSUBDPARAMS;
|
|
196
|
-
} else {
|
|
197
|
-
switch (outopt) {
|
|
198
|
-
case 'json_param':
|
|
199
|
-
rWrite = EWrite.eEGOPARAMS;
|
|
200
|
-
break;
|
|
201
|
-
case 'svg_all_figures':
|
|
202
|
-
rFormat = EFormat.eSVGALL;
|
|
203
|
-
rWrite = EWrite.eOTHERS;
|
|
204
|
-
break;
|
|
205
|
-
case 'dxf_all_figures':
|
|
206
|
-
rFormat = EFormat.eDXFALL;
|
|
207
|
-
rWrite = EWrite.eOTHERS;
|
|
208
|
-
break;
|
|
209
|
-
case 'pax_all':
|
|
210
|
-
rFormat = EFormat.ePAX;
|
|
211
|
-
rWrite = EWrite.eOTHERS;
|
|
212
|
-
break;
|
|
213
|
-
case 'scad_3d_openscad':
|
|
214
|
-
rFormat = EFormat.eOPENSCAD;
|
|
215
|
-
rWrite = EWrite.eOTHERS;
|
|
216
|
-
break;
|
|
217
|
-
case 'js_3d_openjscad':
|
|
218
|
-
rFormat = EFormat.eJSCAD;
|
|
219
|
-
rWrite = EWrite.eOTHERS;
|
|
220
|
-
break;
|
|
221
|
-
case 'zip_all':
|
|
222
|
-
rFormat = EFormat.eZIP;
|
|
223
|
-
rWrite = EWrite.eOTHERS;
|
|
224
|
-
break;
|
|
225
|
-
default:
|
|
226
|
-
rFormat = EFormat.ePAX;
|
|
227
|
-
rWrite = EWrite.eOTHERS;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
const eFormat: tEFormat = { eWrite: rWrite, eFormat: rFormat, eFace: rFace, eSubdesign: rSubD };
|
|
231
|
-
return eFormat;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function list_designs(dList: tAllPageDef, detail: boolean) {
|
|
235
|
-
let rlog = 'List of available designs:\n';
|
|
236
|
-
for (const [idx, dname] of get_design_array(dList).entries()) {
|
|
237
|
-
rlog += `${(idx + 1).toString().padStart(4, ' ')} : ${dname}\n`;
|
|
238
|
-
if (detail) {
|
|
239
|
-
rlog += ` ${dList[dname].pDef.partName}\n`;
|
|
240
|
-
rlog += ` ${dList[dname].pTitle}\n`;
|
|
241
|
-
rlog += ` ${dList[dname].pDescription}\n`;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
console.log(rlog);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function list_parameters(dList: tAllPageDef, selD: string, paramPath: string, modif: string[]) {
|
|
248
|
-
const theD = selectDesign(dList, selD);
|
|
249
|
-
let rlog = `List of parameters of the design ${selD} (${theD.pDef.partName}):\n`;
|
|
250
|
-
const dParam = designParam(theD.pDef);
|
|
251
|
-
try {
|
|
252
|
-
dParam.applyParamVal(readParams(paramPath, true));
|
|
253
|
-
dParam.applyParamVal(parseModif(modif, true));
|
|
254
|
-
} catch (emsg) {
|
|
255
|
-
console.log('err272: error while applying new parameters');
|
|
256
|
-
console.log(emsg);
|
|
257
|
-
process.exit(1);
|
|
258
|
-
}
|
|
259
|
-
const paramVal = dParam.getParamVal();
|
|
260
|
-
const nameLength = 20;
|
|
261
|
-
const unitLength = 8;
|
|
262
|
-
const nameLabel = 'name'.padEnd(nameLength, ' ');
|
|
263
|
-
const unitLabel = 'unit'.padEnd(unitLength, ' ');
|
|
264
|
-
rlog += ` # : ${nameLabel} current ${unitLabel} init min max step\n`;
|
|
265
|
-
for (const [idx, pa] of theD.pDef.params.entries()) {
|
|
266
|
-
const idx2 = (idx + 1).toString().padStart(4, ' ');
|
|
267
|
-
const pname = pa.name.padEnd(nameLength, ' ');
|
|
268
|
-
const pcurr = paramVal[pa.name];
|
|
269
|
-
const pcurrP = pcurr.toString().padStart(6, ' ');
|
|
270
|
-
const punit = pa.unit.padEnd(unitLength, ' ');
|
|
271
|
-
const pinit = pa.init.toString().padStart(6, ' ');
|
|
272
|
-
switch (pa.pType) {
|
|
273
|
-
case PType.eCheckbox:
|
|
274
|
-
rlog += `${idx2} : ${pname} checkbox ${pcurr} ${pa.init}\n`;
|
|
275
|
-
break;
|
|
276
|
-
case PType.eDropdown:
|
|
277
|
-
rlog += `${idx2} : ${pname} ${pcurr} ${pa.init}`;
|
|
278
|
-
for (const [optI, optN] of pa.dropdown.entries()) {
|
|
279
|
-
rlog += ` ${optI}:${optN}`;
|
|
280
|
-
}
|
|
281
|
-
rlog += '\n';
|
|
282
|
-
break;
|
|
283
|
-
default:
|
|
284
|
-
rlog += `${idx2} : ${pname} ${pcurrP} ${punit} ${pinit} ${pa.min} ${pa.max} ${pa.step}\n`;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
console.log(rlog);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function list_figures(dList: tAllPageDef, selD: string, paramPath: string, modif: string[]) {
|
|
291
|
-
const dPartName = selectDesignN(dList, selD);
|
|
292
|
-
const figN = get_figure_array(dList, selD, paramPath, modif);
|
|
293
|
-
let rlog = `List of figures of the design ${selD} (${dPartName}):\n`;
|
|
294
|
-
for (const [idx, figNi] of figN.entries()) {
|
|
295
|
-
const idx2 = (idx + 1).toString().padStart(4, ' ');
|
|
296
|
-
rlog += `${idx2} : ${figNi}\n`;
|
|
297
|
-
}
|
|
298
|
-
console.log(rlog);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function list_subdesigns(dList: tAllPageDef, selD: string, paramPath: string, modif: string[]) {
|
|
302
|
-
const dPartName = selectDesignN(dList, selD);
|
|
303
|
-
const subdA = get_subdesign_array(dList, selD, paramPath, modif);
|
|
304
|
-
const subdN = Object.keys(subdA);
|
|
305
|
-
let rlog = `List of sub-designs of the design ${selD} (${dPartName}):\n`;
|
|
306
|
-
for (const [idx, subdNi] of subdN.entries()) {
|
|
307
|
-
const idx2 = (idx + 1).toString().padStart(4, ' ');
|
|
308
|
-
const subd = subdA[subdNi];
|
|
309
|
-
const ori = `[ ${subd.orientation[0]}, ${subd.orientation[1]}, ${subd.orientation[2]}]`;
|
|
310
|
-
const pos = `[ ${subd.position[0]}, ${subd.position[1]}, ${subd.position[2]}]`;
|
|
311
|
-
const subdNp = subdNi.padEnd(15, ' ');
|
|
312
|
-
const subdPp = subd.partName.padEnd(15, ' ');
|
|
313
|
-
rlog += `${idx2} : ${subdNp} ${subdPp} orientation: ${ori} position: ${pos}\n`;
|
|
314
|
-
}
|
|
315
|
-
console.log(rlog);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
function list_subd_parameters(
|
|
319
|
-
dList: tAllPageDef,
|
|
320
|
-
selD: string,
|
|
321
|
-
subdN: string,
|
|
322
|
-
paramPath: string,
|
|
323
|
-
modif: string[]
|
|
324
|
-
) {
|
|
325
|
-
const subdParam = get_subd(dList, selD, subdN, paramPath, modif, true).dparam;
|
|
326
|
-
const nameLength = 20;
|
|
327
|
-
const nameLabel = 'name'.padEnd(nameLength, ' ');
|
|
328
|
-
let rlog = ` # : ${nameLabel} value init changed\n`;
|
|
329
|
-
for (const [idx, ipaN] of Object.keys(subdParam).entries()) {
|
|
330
|
-
const idx2 = (idx + 1).toString().padStart(4, ' ');
|
|
331
|
-
const paN = ipaN.padEnd(nameLength, ' ');
|
|
332
|
-
const pa = subdParam[ipaN];
|
|
333
|
-
const paVal = pa.val.toString().padStart(6, ' ');
|
|
334
|
-
const paInit = pa.init.toString().padStart(6, ' ');
|
|
335
|
-
rlog += `${idx2} : ${paN} ${paVal} ${paInit} ${pa.chg ? 'changed' : ''}\n`;
|
|
336
|
-
}
|
|
337
|
-
console.log(rlog);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
function list_outopt(dList: tAllPageDef, selD: string, paramPath: string, modif: string[]) {
|
|
341
|
-
const dPartName = selectDesignN(dList, selD);
|
|
342
|
-
let rlog = `List of outputs of the design ${selD} (${dPartName}):\n`;
|
|
343
|
-
const outOpt = get_outopt_array(dList, selD, paramPath, modif);
|
|
344
|
-
for (const [idx, oneOpt] of outOpt.entries()) {
|
|
345
|
-
const idx2 = (idx + 1).toString().padStart(4, ' ');
|
|
346
|
-
rlog += `${idx2} : ${oneOpt}\n`;
|
|
347
|
-
}
|
|
348
|
-
console.log(rlog);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
let cmd_write = false;
|
|
352
|
-
async function geom_cli(iArgs: string[], dList: tAllPageDef, outDir = 'output') {
|
|
353
|
-
const argv = yargs(hideBin(iArgs))
|
|
354
|
-
.scriptName('geom_cli')
|
|
355
|
-
.version(version)
|
|
356
|
-
.usage('Usage: $0 <global-options> command <command-argument>')
|
|
357
|
-
.example([
|
|
358
|
-
['$0 list-designs', 'list the available designs'],
|
|
359
|
-
['$0 list-designs-detailed', 'list the available designs with detailed information'],
|
|
360
|
-
['$0 -d heliostat/rake compute-log', 'compute and print the log'],
|
|
361
|
-
['$0 -d heliostat/swing list-outopt', 'list possible output-format-options'],
|
|
362
|
-
['$0 -d heliostat/rod write zip_all', 'write a zip file']
|
|
363
|
-
])
|
|
364
|
-
.option('design', {
|
|
365
|
-
alias: 'd',
|
|
366
|
-
type: 'string',
|
|
367
|
-
description: 'design to be used by the command',
|
|
368
|
-
default: ''
|
|
369
|
-
})
|
|
370
|
-
.option('param', {
|
|
371
|
-
alias: 'p',
|
|
372
|
-
type: 'string',
|
|
373
|
-
array: false,
|
|
374
|
-
description: 'path to the input parameter file',
|
|
375
|
-
default: ''
|
|
376
|
-
})
|
|
377
|
-
.option('modif', {
|
|
378
|
-
alias: 'm',
|
|
379
|
-
nargs: 2,
|
|
380
|
-
type: 'string',
|
|
381
|
-
description: 'modify parameter values <paramName> <paramValue>',
|
|
382
|
-
default: ''
|
|
383
|
-
})
|
|
384
|
-
.option('outDir', {
|
|
385
|
-
alias: 'o',
|
|
386
|
-
type: 'string',
|
|
387
|
-
description: 'the path of the directory where to write the output files',
|
|
388
|
-
default: outDir
|
|
389
|
-
})
|
|
390
|
-
.option('outFileName', {
|
|
391
|
-
type: 'string',
|
|
392
|
-
description: 'Rename the output filename',
|
|
393
|
-
default: ''
|
|
394
|
-
})
|
|
395
|
-
.command(['list-designs', 'list'], 'list the available designs', {}, () => {
|
|
396
|
-
list_designs(dList, false);
|
|
397
|
-
})
|
|
398
|
-
.command('list-designs-detailed', 'list the available designs with details', {}, () => {
|
|
399
|
-
list_designs(dList, true);
|
|
400
|
-
})
|
|
401
|
-
.command('list-parameters', 'list the parameters of the selected design', {}, (argv) => {
|
|
402
|
-
//console.log(argv)
|
|
403
|
-
list_parameters(
|
|
404
|
-
dList,
|
|
405
|
-
argv.design as string,
|
|
406
|
-
argv.param as string,
|
|
407
|
-
argv.modif as string[]
|
|
408
|
-
);
|
|
409
|
-
})
|
|
410
|
-
.command('list-figures', 'list the figures of the selected design', {}, (argv) => {
|
|
411
|
-
list_figures(
|
|
412
|
-
dList,
|
|
413
|
-
argv.design as string,
|
|
414
|
-
argv.param as string,
|
|
415
|
-
argv.modif as string[]
|
|
416
|
-
);
|
|
417
|
-
})
|
|
418
|
-
.command('list-subdesigns', 'list the subdesigns of the selected design', {}, (argv) => {
|
|
419
|
-
list_subdesigns(
|
|
420
|
-
dList,
|
|
421
|
-
argv.design as string,
|
|
422
|
-
argv.param as string,
|
|
423
|
-
argv.modif as string[]
|
|
424
|
-
);
|
|
425
|
-
})
|
|
426
|
-
.command(
|
|
427
|
-
'list-subd-parameters <subdN>',
|
|
428
|
-
'list the parameters of subdesigns',
|
|
429
|
-
{},
|
|
430
|
-
(argv) => {
|
|
431
|
-
list_subd_parameters(
|
|
432
|
-
dList,
|
|
433
|
-
argv.design as string,
|
|
434
|
-
argv.subdN as string,
|
|
435
|
-
argv.param as string,
|
|
436
|
-
argv.modif as string[]
|
|
437
|
-
);
|
|
438
|
-
}
|
|
439
|
-
)
|
|
440
|
-
.command('compute-log', 'Compute and print the log without writing file', {}, (argv) => {
|
|
441
|
-
computeGeom(
|
|
442
|
-
dList,
|
|
443
|
-
argv.design as string,
|
|
444
|
-
argv.param as string,
|
|
445
|
-
argv.modif as string[],
|
|
446
|
-
true
|
|
447
|
-
);
|
|
448
|
-
})
|
|
449
|
-
.command(
|
|
450
|
-
'list-outopt',
|
|
451
|
-
'list the possible output format options of the selected design',
|
|
452
|
-
{},
|
|
453
|
-
(argv) => {
|
|
454
|
-
list_outopt(
|
|
455
|
-
dList,
|
|
456
|
-
argv.design as string,
|
|
457
|
-
argv.param as string,
|
|
458
|
-
argv.modif as string[]
|
|
459
|
-
);
|
|
460
|
-
}
|
|
461
|
-
)
|
|
462
|
-
.command('write <outopt>', 'write the output format file', {}, () => {
|
|
463
|
-
cmd_write = true;
|
|
464
|
-
})
|
|
465
|
-
.demandCommand(1)
|
|
466
|
-
.help()
|
|
467
|
-
.strict()
|
|
468
|
-
.parseSync();
|
|
469
|
-
//console.log(argv.$0);
|
|
470
|
-
//console.log(argv.design);
|
|
471
|
-
//console.log(argv.param);
|
|
472
|
-
//console.log(argv.modif);
|
|
473
|
-
//console.log(argv.outDir);
|
|
474
|
-
//console.log(argv);
|
|
475
|
-
if (cmd_write) {
|
|
476
|
-
const iOutDir = argv.outDir;
|
|
477
|
-
if (iOutDir === '') {
|
|
478
|
-
console.log("err638: option 'outDir' is set to empty string. Nothing written!");
|
|
479
|
-
process.exit(1);
|
|
480
|
-
}
|
|
481
|
-
const selD = argv.design;
|
|
482
|
-
const outopt = argv.outopt as string;
|
|
483
|
-
const paramPath = argv.param;
|
|
484
|
-
const paramModif = argv.modif as unknown as string[];
|
|
485
|
-
const theD = selectDesign(dList, selD);
|
|
486
|
-
// check if outopt is valid
|
|
487
|
-
const outOpt = get_outopt_array(dList, selD, paramPath, paramModif);
|
|
488
|
-
if (!outOpt.includes(outopt)) {
|
|
489
|
-
console.log(`err639: outopt ${outopt} is not a valid option`);
|
|
490
|
-
process.exit(1);
|
|
491
|
-
}
|
|
492
|
-
// end of check of outopt
|
|
493
|
-
//let rlog = `Write ${outopt} of ${selD} (${theD.pDef.partName}):\n`;
|
|
494
|
-
let rlog = '';
|
|
495
|
-
const oOpt = decompose_outopt(outopt);
|
|
496
|
-
const dParam = designParam(theD.pDef);
|
|
497
|
-
try {
|
|
498
|
-
dParam.applyParamVal(readParams(paramPath, false));
|
|
499
|
-
dParam.applyParamVal(parseModif(paramModif, false));
|
|
500
|
-
} catch (emsg) {
|
|
501
|
-
console.log('err273: error while applying new parameters');
|
|
502
|
-
console.log(emsg);
|
|
503
|
-
process.exit(1);
|
|
504
|
-
}
|
|
505
|
-
computeGeom(dList, selD, paramPath, paramModif, true);
|
|
506
|
-
try {
|
|
507
|
-
if (oOpt.eWrite === EWrite.eEGOPARAMS) {
|
|
508
|
-
rlog += writeParams(
|
|
509
|
-
dParam.partName,
|
|
510
|
-
dParam.getParamVal(),
|
|
511
|
-
iOutDir,
|
|
512
|
-
argv.outFileName
|
|
513
|
-
);
|
|
514
|
-
} else if (oOpt.eWrite === EWrite.eSUBDPARAMS) {
|
|
515
|
-
const subD = get_subd(dList, selD, oOpt.eSubdesign, paramPath, paramModif, false);
|
|
516
|
-
rlog += writeParams(
|
|
517
|
-
subD.partName,
|
|
518
|
-
paramListToVal(subD.dparam),
|
|
519
|
-
iOutDir,
|
|
520
|
-
argv.outFileName
|
|
521
|
-
);
|
|
522
|
-
} else {
|
|
523
|
-
const simtime = 0;
|
|
524
|
-
rlog += await geom_write(
|
|
525
|
-
dParam.partName,
|
|
526
|
-
theD.pGeom,
|
|
527
|
-
simtime,
|
|
528
|
-
dParam.getParamVal(),
|
|
529
|
-
oOpt.eFormat, // output-format
|
|
530
|
-
//EFormat.eSVG,
|
|
531
|
-
//EFormat.eDXF,
|
|
532
|
-
//EFormat.ePAX,
|
|
533
|
-
//EFormat.eOPENSCAD,
|
|
534
|
-
//EFormat.eJSCAD,
|
|
535
|
-
//EFormat.eZIP,
|
|
536
|
-
oOpt.eFace, // selected-2d-face
|
|
537
|
-
iOutDir, // output-directory
|
|
538
|
-
argv.outFileName // output-filename
|
|
539
|
-
);
|
|
540
|
-
}
|
|
541
|
-
} catch (emsg) {
|
|
542
|
-
console.log('err279: error while writing file');
|
|
543
|
-
console.log(emsg);
|
|
544
|
-
process.exit(1);
|
|
545
|
-
}
|
|
546
|
-
console.log(rlog);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
export { geom_cli };
|