-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.go
150 lines (133 loc) · 3.41 KB
/
profile.go
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package topotypes
import (
"encoding/json"
"errors"
"github.com/flywave/topotypes/profile"
"github.com/flywave/topotypes/utils"
)
const (
TOPO_PROFILE_TYPE_NONE = profile.TYPE_NONE
TOPO_PROFILE_TYPE_TRIANGLE = profile.TYPE_TRIANGLE
TOPO_PROFILE_TYPE_RECTANGLE = profile.TYPE_RECTANGLE
TOPO_PROFILE_TYPE_CIRC = profile.TYPE_CIRC
TOPO_PROFILE_TYPE_ELIPS = profile.TYPE_ELIPS
TOPO_PROFILE_TYPE_POLYGON = profile.TYPE_POLYGON
TOPO_PROFILE_TYPE_L_STEEL = profile.TYPE_L_STEEL
)
func ProfileTypeToString(tp int) string {
switch tp {
case TOPO_PROFILE_TYPE_TRIANGLE:
return "triangle"
case TOPO_PROFILE_TYPE_RECTANGLE:
return "rectangle"
case TOPO_PROFILE_TYPE_CIRC:
return "circ"
case TOPO_PROFILE_TYPE_ELIPS:
return "ellipse"
case TOPO_PROFILE_TYPE_POLYGON:
return "polygon"
case TOPO_PROFILE_TYPE_L_STEEL:
return "lsteel"
default:
return ""
}
}
func StringToProfileType(tp string) int {
if utils.StrEquals(tp, "triangle") {
return TOPO_PROFILE_TYPE_TRIANGLE
} else if utils.StrEquals(tp, "rectangle") {
return TOPO_PROFILE_TYPE_RECTANGLE
} else if utils.StrEquals(tp, "circ") {
return TOPO_PROFILE_TYPE_CIRC
} else if utils.StrEquals(tp, "ellipse") {
return TOPO_PROFILE_TYPE_ELIPS
} else if utils.StrEquals(tp, "polygon") {
return TOPO_PROFILE_TYPE_POLYGON
} else if utils.StrEquals(tp, "lsteel") {
return TOPO_PROFILE_TYPE_L_STEEL
} else if utils.StrEquals(tp, "arc") {
}
return TOPO_PROFILE_TYPE_NONE
}
type TopoProfile profile.Profile
type TopoTriangle profile.Triangle
func NewTopoTriangle() *TopoTriangle {
t := TopoTriangle{}
t.Type = ProfileTypeToString(TOPO_PROFILE_TYPE_TRIANGLE)
return &t
}
type TopoRectangle profile.Rectangle
func NewTopoRectangle() *TopoRectangle {
t := TopoRectangle{}
t.Type = ProfileTypeToString(TOPO_PROFILE_TYPE_RECTANGLE)
return &t
}
type TopoCirc profile.Circ
func NewTopoCirc() *TopoCirc {
t := TopoCirc{}
t.Type = ProfileTypeToString(TOPO_PROFILE_TYPE_CIRC)
return &t
}
type TopoElips profile.Elips
func NewTopoElips() *TopoElips {
t := TopoElips{}
t.Type = ProfileTypeToString(TOPO_PROFILE_TYPE_ELIPS)
return &t
}
type TopoPolygon profile.Polygon
func NewTopoPolygon() *TopoPolygon {
t := TopoPolygon{}
t.Type = ProfileTypeToString(TOPO_PROFILE_TYPE_POLYGON)
return &t
}
func ProfileUnMarshal(inter interface{}) (interface{}, error) {
switch pro := inter.(type) {
case map[string]interface{}:
v, ok := pro["type"]
t, ok2 := v.(string)
if !ok || !ok2 {
return nil, errors.New("profile type error")
}
pro_t := StringToProfileType(t)
js, er := json.Marshal(inter)
if er != nil {
return nil, er
}
var pf interface{}
switch pro_t {
case TOPO_PROFILE_TYPE_TRIANGLE:
pf = NewTopoTriangle()
case TOPO_PROFILE_TYPE_RECTANGLE:
pf = NewTopoRectangle()
case TOPO_PROFILE_TYPE_CIRC:
pf = NewTopoCirc()
case TOPO_PROFILE_TYPE_ELIPS:
pf = NewTopoElips()
case TOPO_PROFILE_TYPE_POLYGON:
pf = NewTopoPolygon()
case profile.TYPE_L_STEEL:
pf = profile.NewLShape()
default:
return nil, errors.New("profile type error")
}
e := json.Unmarshal(([]byte)(js), pf)
if e != nil {
return nil, e
}
return pf, nil
case []interface{}:
var pros []interface{}
for _, p := range pro {
if p != nil {
p, err := ProfileUnMarshal(p)
if err != nil {
return nil, err
}
pros = append(pros, p)
}
}
return pros, nil
default:
return nil, errors.New("profile type error")
}
}