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