2023-03-03 14:43:11 +01:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
2024-03-29 17:00:53 +01:00
|
|
|
"strconv"
|
2023-03-03 14:43:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type MxGraphModel struct {
|
|
|
|
XMLName xml.Name `xml:"mxGraphModel"`
|
|
|
|
|
|
|
|
Root struct {
|
2024-03-28 14:43:33 +01:00
|
|
|
XMLName xml.Name `xml:"root"`
|
|
|
|
MxCell []MxCell `xml:"mxCell"`
|
|
|
|
MxObject *[]MxObject `xml:"object"`
|
2023-03-03 14:43:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type MxCell struct {
|
|
|
|
XMLName xml.Name `xml:"mxCell"`
|
|
|
|
ID string `xml:"id,attr"`
|
|
|
|
Parent *string `xml:"parent,attr"`
|
|
|
|
RID *string `xml:"rID,attr"`
|
|
|
|
Source *string `xml:"source,attr"`
|
|
|
|
Target *string `xml:"target,attr"`
|
2024-03-28 14:43:33 +01:00
|
|
|
Rtype *string `xml:"rType,attr"`
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type MxObject struct {
|
|
|
|
XMLName xml.Name `xml:"object"`
|
|
|
|
ID string `xml:"id,attr"`
|
|
|
|
Settings []xml.Attr `xml:",any,attr"`
|
|
|
|
MxCell MxCell `xml:"mxCell"`
|
2023-03-03 14:43:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type mxissue struct {
|
|
|
|
msg string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mxissue) Error() string {
|
|
|
|
return m.msg
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMxIssue(message string) error {
|
|
|
|
return &mxissue{message}
|
|
|
|
}
|
2024-03-29 17:00:53 +01:00
|
|
|
|
|
|
|
// mxCell inside object tags are create twice when unmarshalling
|
|
|
|
// once as they appear in the xml inside the MxObject struct and once in the MxCell struct
|
|
|
|
// so once retrieved from object we remove them from the root's MxCell list
|
|
|
|
func (m *MxGraphModel) removeMxCell(id string){
|
|
|
|
int_id,_ := strconv.Atoi(id)
|
|
|
|
int_id = int_id + 1
|
|
|
|
cell_id := strconv.Itoa(int_id)
|
|
|
|
|
|
|
|
for i, cell := range(m.Root.MxCell){
|
|
|
|
if cell.ID == cell_id {
|
|
|
|
m.Root.MxCell = append(m.Root.MxCell[:i],m.Root.MxCell[i+1:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|