node-opcua-modeler 2.64.0 → 2.65.1

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.
@@ -1,8 +1,7 @@
1
1
  /* eslint-disable max-statements */
2
2
  import {
3
3
  BaseNode,
4
- dumpReferenceDescription,
5
- Namespace,
4
+ INamespace,
6
5
  UADataType,
7
6
  UAObject,
8
7
  UAObjectType,
@@ -12,15 +11,13 @@ import {
12
11
  } from "node-opcua-address-space";
13
12
  import { coerceUInt32 } from "node-opcua-basic-types";
14
13
  import { NodeClass } from "node-opcua-data-model";
15
- import { NodeId } from "node-opcua-nodeid";
16
14
  import { StructureField } from "node-opcua-types";
17
15
  import { DataType } from "node-opcua-variant";
18
16
 
19
17
  import { displayNodeElement } from "./displayNodeElement";
20
18
  import { TableHelper } from "./tableHelper";
21
- import { dumpClassHierachry, graphVizToPlantUml, opcuaToDot } from "./to_graphivz";
22
19
 
23
- interface NamespacePriv2 {
20
+ interface NamespacePriv2 extends INamespace {
24
21
  nodeIterator(): IterableIterator<BaseNode>;
25
22
  _objectTypeIterator(): IterableIterator<UAObjectType>;
26
23
  _objectTypeCount(): number;
@@ -33,14 +30,16 @@ interface NamespacePriv2 {
33
30
  _aliasCount(): number;
34
31
  }
35
32
  export interface IWriter {
36
- writeLine(...args: any[]): void;
33
+ // eslint-disable-next-line no-unused-vars
34
+ writeLine(_str: string): void;
37
35
  }
38
- class Writer implements IWriter {
36
+
37
+ export class Writer implements IWriter {
39
38
  private readonly stream: string[] = [];
40
39
  constructor() {
41
40
  /* empty */
42
41
  }
43
- public writeLine(str: string) {
42
+ public writeLine(str: string): void {
44
43
  this.stream.push(str);
45
44
  }
46
45
  public toString(): string {
@@ -48,17 +47,18 @@ class Writer implements IWriter {
48
47
  }
49
48
  }
50
49
 
51
- export async function buildDocumentationToString(namespace: Namespace): Promise<string> {
50
+ export interface BuildDocumentationOptions {
51
+ node?: BaseNode;
52
+
53
+ dumpGraphics? :(writer: IWriter, type: UAObjectType | UAVariableType)=>void;
54
+ }
55
+
56
+ export async function buildDocumentationToString(namespace: INamespace, options?: BuildDocumentationOptions): Promise<string> {
52
57
  const writer = new Writer();
53
- await buildDocumentation(namespace, writer);
58
+ await buildDocumentation(namespace, writer, options);
54
59
  return writer.toString();
55
60
  }
56
61
 
57
- interface V {
58
- valueRank?: number;
59
- arrayDimensions?: number[];
60
- dataType: NodeId;
61
- }
62
62
  const toDataTypeStr = (p: BaseNode): string => {
63
63
  if (p.nodeClass === NodeClass.Variable) {
64
64
  const v = p as UAVariable;
@@ -74,7 +74,6 @@ const toDataTypeStr = (p: BaseNode): string => {
74
74
  return "";
75
75
  };
76
76
  function dataTypeEnumerationToMarkdown(dataType: UADataType): string {
77
- const addressSpace = dataType.addressSpace;
78
77
  const writer = new Writer();
79
78
 
80
79
  writer.writeLine("");
@@ -217,19 +216,73 @@ function dumpReferenceType(referenceType: UAReferenceType): string {
217
216
  writer.writeLine(str);
218
217
  return writer.toString();
219
218
  }
220
- export async function buildDocumentation(namespace: Namespace, writer: IWriter): Promise<void> {
221
- const addressSpace = namespace.addressSpace;
219
+
220
+ export function extractTypes(namespace: INamespace, options?: BuildDocumentationOptions) {
221
+ const namespacePriv = namespace as unknown as NamespacePriv2;
222
+ if (!options || !options.node) {
223
+ const dataTypes = [...namespacePriv._dataTypeIterator()];
224
+ const objectTypes = [...namespacePriv._objectTypeIterator()];
225
+ const variableTypes = [...namespacePriv._variableTypeIterator()];
226
+ const referenceTypes = [...namespacePriv._referenceTypeIterator()];
227
+ return { dataTypes, variableTypes, objectTypes, referenceTypes };
228
+ }
229
+ const node = options.node;
230
+
231
+ if (node.nodeClass === NodeClass.DataType) {
232
+ const dataTypes: UADataType[] = [];
233
+ let dataType = node as UADataType;
234
+ dataTypes.push(dataType);
235
+ while (dataType.subtypeOfObj && dataType.subtypeOfObj.nodeId.namespace === namespace.index) {
236
+ dataType = dataType.subtypeOfObj;
237
+ dataTypes.push(dataType);
238
+ }
239
+ return { dataTypes, variableTypes: [], objectTypes: [], dataTypeNode: [], referenceTypes: [] };
240
+ } else if (node.nodeClass === NodeClass.ObjectType) {
241
+ const objectTypes: UAObjectType[] = [];
242
+ let objectType = node as UAObjectType;
243
+ objectTypes.push(objectType);
244
+ while (objectType.subtypeOfObj && objectType.subtypeOfObj.nodeId.namespace === namespace.index) {
245
+ objectType = objectType.subtypeOfObj;
246
+ objectTypes.push(objectType);
247
+ }
248
+ return { dataTypes: [], variableTypes: [], objectTypes, dataTypeNode: [], referenceTypes: [] };
249
+ } else if (node.nodeClass === NodeClass.VariableType) {
250
+ const variableTypes: UAVariableType[] = [];
251
+ let variableType = node as UAVariableType;
252
+ variableTypes.push(variableType);
253
+ while (variableType.subtypeOfObj && variableType.subtypeOfObj.nodeId.namespace === namespace.index) {
254
+ variableType = variableType.subtypeOfObj;
255
+ variableTypes.push(variableType);
256
+ }
257
+ return { dataTypes: [], variableTypes, objectTypes: [], dataTypeNode: [], referenceTypes: [] };
258
+ }
259
+
260
+ const dataTypes = [...namespacePriv._dataTypeIterator()];
261
+ const objectTypes = [...namespacePriv._objectTypeIterator()];
262
+ const variableTypes = [...namespacePriv._variableTypeIterator()];
263
+ const referenceTypes = [...namespacePriv._referenceTypeIterator()];
264
+ return { dataTypes, variableTypes, objectTypes, referenceTypes };
265
+ }
266
+
267
+ export async function buildDocumentation(
268
+ namespace: INamespace,
269
+ writer: IWriter,
270
+ options?: BuildDocumentationOptions
271
+ ): Promise<void> {
272
+
273
+ options = options || {};
274
+
275
+ const namespacePriv = namespace as unknown as NamespacePriv2;
222
276
 
223
277
  const namespaceUri = namespace.namespaceUri;
224
278
  // -------- Documentation
225
279
 
226
- const nsIndex = addressSpace.getNamespaceIndex(namespaceUri);
280
+ const { dataTypes, objectTypes, variableTypes } = extractTypes(namespace, options);
227
281
 
228
282
  writer.writeLine("");
229
283
  writer.writeLine("# Namespace " + namespaceUri);
230
284
  writer.writeLine("");
231
285
 
232
- const namespacePriv = namespace as unknown as NamespacePriv2;
233
286
  // -------------- writeReferences
234
287
  if (namespacePriv._referenceTypeCount() > 0) {
235
288
  writer.writeLine("");
@@ -240,32 +293,34 @@ export async function buildDocumentation(namespace: Namespace, writer: IWriter):
240
293
  dumpReferenceType(referenceType);
241
294
  }
242
295
  }
296
+
243
297
  function d(node: BaseNode): string {
244
298
  return node.description ? node.description!.text!.toString() : "";
245
299
  }
300
+
246
301
  // -------------- writeDataType
247
- if (namespacePriv._dataTypeCount() > 0) {
302
+ if (dataTypes.length > 0) {
248
303
  writer.writeLine("");
249
304
  writer.writeLine("## DataTypes");
250
305
  writer.writeLine("");
251
- for (const dataType of namespacePriv._dataTypeIterator()) {
306
+ for (const dataType of dataTypes) {
252
307
  writer.writeLine("\n\n### " + dataType.browseName.name!.toString());
253
308
  writer.writeLine("");
254
309
  writer.writeLine(dataTypeToMarkdown(dataType));
255
310
  }
256
311
  }
257
312
  // -------------- writeObjectType
258
- if (namespacePriv._objectTypeCount() > 0) {
313
+ if (objectTypes.length > 0) {
259
314
  writer.writeLine("");
260
315
  writer.writeLine("## ObjectTypes");
261
316
  writer.writeLine("");
262
- for (const objectType of namespacePriv._objectTypeIterator()) {
317
+ for (const objectType of objectTypes) {
263
318
  writer.writeLine("\n\n### " + objectType.browseName.name!.toString());
264
319
  writer.writeLine(d(objectType));
265
320
 
266
- writer.writeLine(graphVizToPlantUml(dumpClassHierachry(objectType, { showBaseType: true, depth: 2 })));
267
-
268
- writer.writeLine(graphVizToPlantUml(opcuaToDot(objectType)));
321
+ if (options.dumpGraphics) {
322
+ await options.dumpGraphics(writer, objectType);
323
+ }
269
324
 
270
325
  // enumerate components
271
326
  writer.writeLine(displayNodeElement(objectType, { format: "markdown" }));
@@ -283,19 +338,18 @@ export async function buildDocumentation(namespace: Namespace, writer: IWriter):
283
338
  }
284
339
  }
285
340
  // -------------- writeVariableType
286
- if (namespacePriv._variableTypeCount() > 0) {
341
+ if (variableTypes.length > 0) {
287
342
  writer.writeLine("");
288
343
  writer.writeLine("## VariableTypes");
289
344
  writer.writeLine("");
290
- for (const variableType of namespacePriv._variableTypeIterator()) {
345
+ for (const variableType of variableTypes) {
291
346
  writer.writeLine("\n\n### " + variableType.browseName.name!.toString());
292
347
  writer.writeLine(d(variableType));
293
348
  writer.writeLine("");
294
349
 
295
- writer.writeLine(graphVizToPlantUml(dumpClassHierachry(variableType, { showBaseType: true, depth: 2 })));
296
-
297
- writer.writeLine(graphVizToPlantUml(opcuaToDot(variableType)));
298
-
350
+ if (options.dumpGraphics) {
351
+ await options.dumpGraphics(writer, variableType);
352
+ }
299
353
  // enumerate components
300
354
  writer.writeLine(displayNodeElement(variableType, { format: "markdown" }));
301
355
  for (const reference of variableType.allReferences()) {
@@ -307,3 +361,4 @@ export async function buildDocumentation(namespace: Namespace, writer: IWriter):
307
361
  }
308
362
  }
309
363
  }
364
+
package/source/index.ts CHANGED
@@ -6,8 +6,9 @@ export * from "./build_model_inner";
6
6
  export * from "./addExtensionObjectDataType";
7
7
  export * from "./symbol";
8
8
  export * from "./to_cvs";
9
- export * from "./to_graphivz";
10
9
  export * from "./generate_markdown_doc";
10
+ export * from "./tableHelper";
11
+
11
12
  //
12
13
  export * from "node-opcua-address-space";
13
14
  export * from "node-opcua-nodesets";
@@ -1,9 +1,9 @@
1
1
  import * as fs from "fs";
2
2
  import { Namespace } from "node-opcua-address-space";
3
- import { buildDocumentationToString } from "..";
3
+ import { BuildDocumentationOptions, buildDocumentationToString } from "..";
4
4
 
5
- export async function buildDocumentationToFile(namespace: Namespace, filename: string) {
6
- const str = await buildDocumentationToString(namespace);
5
+ export async function buildDocumentationToFile(namespace: Namespace, filename: string, options?: BuildDocumentationOptions) {
6
+ const str = await buildDocumentationToString(namespace, options);
7
7
  const stream = fs.createWriteStream("documentation.md");
8
8
  stream.write(str);
9
9
  await new Promise((resolve) => {
@@ -1,164 +0,0 @@
1
- /**
2
- * @module node-opcua-address-space
3
- */
4
- // tslint:disable:no-console
5
- /*
6
- * class Node {
7
- * { browseName: "string", nodeId: NodeId}
8
- * }
9
- * Transition {
10
- * browseName: "String"
11
- * fromState: Node
12
- * toState: Node
13
- * }
14
- * class SateMachineType {
15
- * initialState: Node
16
- * states: [ Node,Node, ...]
17
- * transitions: [Transition]
18
- * }
19
- * @param stateMachineType
20
- */
21
- import { BaseNode, UAState, UAStateMachineEx, UATransition, UAObject, UATransitionEx } from "node-opcua-address-space";
22
-
23
-
24
- export function dumpStateMachineToPlantUML(stateMachineType: UAStateMachineEx): string {
25
-
26
- const lines: string[] = [];
27
- function w(str: string) {
28
- lines.push(str);
29
- }
30
-
31
- function s(state: BaseNode) {
32
- return state? state.nodeId.value.toString() : "";
33
- }
34
-
35
- function n(state: BaseNode) {
36
- return state ? state.browseName.name!.toString() : "";
37
- }
38
-
39
- //w("@startuml "); // + stateMachineType.browseName.toString() + ".png");
40
- // initial state if any
41
-
42
- if (stateMachineType.initialState) {
43
- w(" [*] --> " + s(stateMachineType.initialState));
44
- w(" " + s(stateMachineType.initialState) + ":" + n(stateMachineType.initialState));
45
- } else {
46
- w("[*] --> [*]");
47
- }
48
-
49
- function t(transition: BaseNode) {
50
- let name = n(transition);
51
- name = name.replace(":", "");
52
- name = name.replace("To", "\\nTo\\n");
53
- name = name.replace("Transition", "\\nTransition");
54
- return name;
55
- }
56
-
57
- stateMachineType.states && stateMachineType.states.forEach((state: UAObject) => w(" " + s(state) + ": " + n(state)));
58
-
59
- stateMachineType.transitions && stateMachineType.transitions.forEach((transition: UATransitionEx) =>
60
- w(" " + s(transition.fromStateNode!) + " --> " + s(transition.toStateNode!) + " : " + t(transition))
61
- );
62
-
63
- // w("@enduml");
64
- return lines.join("\n");
65
-
66
- }
67
-
68
- /*
69
- @startuml
70
-
71
- 2930: Unshelved
72
-
73
- 2932: TimedShelved
74
-
75
- 2933: OneShotShelved
76
-
77
- 2930 --> 2932 : "2935\nUnshelvedToTimedShelved"
78
-
79
- 2930 --> 2933 : "2936\nUnshelvedToOneShotShelved"
80
-
81
- 2932 --> 2930 : "2940\nTimedShelvedToUnshelved"
82
-
83
- 2932 --> 2933 : "2942\nTimedShelvedToOneShotShelved"
84
-
85
- 2933 --> 2930 : "2943\nOneShotShelvedToUnshelved"
86
-
87
- 2933 --> 2932 : "2945\nOneShotShelvedToTimedShelved"
88
-
89
- @enduml
90
-
91
- */
92
-
93
- /*
94
- digraph finite_state_machine {
95
- rankdir=LR;
96
- size="8,5"
97
- node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8;
98
- node [shape = circle];
99
- LR_0 -> LR_2 [ label = "SS(B)" ];
100
- LR_0 -> LR_1 [ label = "SS(S)" ];
101
- LR_1 -> LR_3 [ label = "S($end)" ];
102
- LR_2 -> LR_6 [ label = "SS(b)" ];
103
- LR_2 -> LR_5 [ label = "SS(a)" ];
104
- LR_2 -> LR_4 [ label = "S(A)" ];
105
- LR_5 -> LR_7 [ label = "S(b)" ];
106
- LR_5 -> LR_5 [ label = "S(a)" ];
107
- LR_6 -> LR_6 [ label = "S(b)" ];
108
- LR_6 -> LR_5 [ label = "S(a)" ];
109
- LR_7 -> LR_8 [ label = "S(b)" ];
110
- LR_7 -> LR_5 [ label = "S(a)" ];
111
- LR_8 -> LR_6 [ label = "S(b)" ];
112
- LR_8 -> LR_5 [ label = "S(a)" ];
113
- }
114
- */
115
- export function dumpStateMachineToGraphViz(
116
- /*StateMachineProxy*/
117
- stateMachineType: UAStateMachineEx
118
- ): string {
119
- const lines: string[] = [];
120
- function w(str: string) {
121
- lines.push(str)
122
- }
123
-
124
- function s(state: BaseNode) {
125
- return state.nodeId.value.toString();
126
- }
127
-
128
- function n(state: BaseNode) {
129
- return state.browseName.name!.toString();
130
- }
131
-
132
- function s_full(state: BaseNode) {
133
- return s(state) + ' [ label = "' + n(state) + '" ]';
134
- }
135
-
136
- w("digraph finite_state_machine {");
137
- // initial state if any
138
-
139
- if (stateMachineType.initialState) {
140
- w("node [ shape = doublecircle];");
141
- w(" _" + s_full(stateMachineType.initialState!) + " ;");
142
- }
143
- w("node [ shape = circle];");
144
- stateMachineType.states.forEach((state: UAState) => w(" _" + s_full(state)));
145
-
146
- stateMachineType.transitions.forEach((transition) =>
147
- w(
148
- " _" +
149
- s(transition.fromStateNode!) +
150
- " -> _" +
151
- s(transition.toStateNode!) +
152
- " [ " +
153
- // " labeltooltip = \"" + i(transition) + "\" " +
154
- ', label = "' +
155
- n(transition) +
156
- '" ];'
157
- )
158
- );
159
-
160
- w("}");
161
-
162
- return lines.join("\n");
163
-
164
- }