44 lines
963 B
Go
44 lines
963 B
Go
package builders
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"plcopenxmlbuilder/models"
|
|
"schema"
|
|
)
|
|
|
|
type Twincat3Builder struct {
|
|
}
|
|
|
|
func NewTwincat3Builder() *Twincat3Builder {
|
|
return &Twincat3Builder{}
|
|
}
|
|
|
|
func (tc *Twincat3Builder) Marshal(s *schema.Project) ([]byte, error) {
|
|
plcopenxml := models.NewPLCopenXML()
|
|
|
|
proj := plcopenxml.AddProject()
|
|
proj.AddFileHeader(s.Information.CompanyName, s.Information.ProductName, s.Information.Version)
|
|
proj.AddContentHeader(s.ProjectName)
|
|
app := proj.AddApplication(models.URL_PLCOPENXML, models.HANDLE_IMPLEMENTATION)
|
|
|
|
switch s.GenerateType {
|
|
//PLC
|
|
case 0:
|
|
err := app.AddResources(s)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
//Application
|
|
case 1:
|
|
//Files
|
|
case 2:
|
|
}
|
|
|
|
content, err := xml.MarshalIndent(plcopenxml.Project, " ", " ")
|
|
content = append([]byte(xml.Header), content...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return append([]byte(xml.Header), content...), nil
|
|
}
|