-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBlock.ts
More file actions
99 lines (93 loc) · 3.3 KB
/
Block.ts
File metadata and controls
99 lines (93 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { CodeBlock } from './CodeBlock.js';
import { KopCodeHelper } from '../CodeGen/KopCodeHelper.js';
export class Block {
name: string;
number: number = 0;
private codeBlock: CodeBlock;
title: string | undefined;
titleEnglish: string | undefined;
comment: string | undefined;
commentEnglish: string | undefined;
author: string | undefined;
blockInterface: string;
constructor(name: string, title: string, codeBlock: CodeBlock) {
this.name = name;
this.title = title;
this.codeBlock = codeBlock;
this.blockInterface = `
<Interface>
<Sections xmlns="http://www.siemens.com/automation/Openness/SW/Interface/v2">
<Section Name="Input" />
<Section Name="Output" />
<Section Name="InOut" />
<Section Name="Temp" />
<Section Name="Constant" />
<Section Name="Return">
<Member Name="Ret_Val" Datatype="Void" />
</Section>
</Sections>
</Interface>
`;
}
getCode(): string {
const idRef = { value: 0 };
let code = this.getBlockHeader(idRef);
code += new KopCodeHelper(this.codeBlock).getXml(idRef);
code += this.getBlockFooter(idRef);
return code;
}
getBlockHeader(idRef: { value: number }): string {
const header = `
<SW.Blocks.FC ID="${idRef.value++}">
<AttributeList>
${this.author !== undefined && this.author !== null ? '<HeaderAuthor>' + this.author + '</HeaderAuthor>' : ''}
<HeaderFamily>General</HeaderFamily>
<HeaderVersion>1.0</HeaderVersion>
<MemoryLayout>Optimized</MemoryLayout>
<Name>${this.name}</Name>
${this.number !== 0 ? '<Number>' + this.number + '</Number>' : ''}
<Namespace />
<ProgrammingLanguage>LAD</ProgrammingLanguage>
</AttributeList>
<ObjectList>`;
return header;
}
getBlockFooter(idRef: { value: number }): string {
const footer = `
<MultilingualText ID="${idRef.value++}" CompositionName="Title">
<ObjectList>
<MultilingualTextItem ID="${idRef.value++}" CompositionName="Items">
<AttributeList>
<Culture>de-DE</Culture>
<Text>${this.title}</Text>
</AttributeList>
</MultilingualTextItem>
<MultilingualTextItem ID="${idRef.value++}" CompositionName="Items">
<AttributeList>
<Culture>en-GB</Culture>
<Text>${this.titleEnglish ?? ''}</Text>
</AttributeList>
</MultilingualTextItem>
</ObjectList>
</MultilingualText>
<MultilingualText ID="${idRef.value++}" CompositionName="Comment">
<ObjectList>
<MultilingualTextItem ID="${idRef.value++}" CompositionName="Items">
<AttributeList>
<Culture>de-DE</Culture>
<Text>${this.comment ?? ''}</Text>
</AttributeList>
</MultilingualTextItem>
<MultilingualTextItem ID="${idRef.value++}" CompositionName="Items">
<AttributeList>
<Culture>en-GB</Culture>
<Text>${this.commentEnglish ?? ''}</Text>
</AttributeList>
</MultilingualTextItem>
</ObjectList>
</MultilingualText>
</ObjectList>
</SW.Blocks.FC>`;
return footer;
}
}