-
Notifications
You must be signed in to change notification settings - Fork 5
/
block.go
82 lines (73 loc) · 2.21 KB
/
block.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
package dxf
type Block struct {
handle Handle
endBlockHandle Handle
IsInPaperSpace bool
Layer string
Name string
BasePoint Point
XrefName string
Entities []Entity
Description string
}
func NewBlock() *Block {
return &Block{
Layer: "0",
}
}
func (b *Block) assignHandles(nextHandle uint32) uint32 {
b.handle = Handle(nextHandle)
nextHandle++
b.endBlockHandle = Handle(nextHandle)
nextHandle++
for i := range b.Entities {
e := &b.Entities[i]
(*e).SetHandle(Handle(nextHandle))
nextHandle++
}
return nextHandle
}
func (b *Block) getBlockPairs(version AcadVersion) (pairs []CodePair) {
pairs = make([]CodePair, 0)
pairs = append(pairs, NewStringCodePair(0, "BLOCK"))
if version >= R13 {
pairs = append(pairs, NewStringCodePair(5, stringFromHandle(b.handle)))
pairs = append(pairs, NewStringCodePair(100, "AcDbEntity"))
}
if b.IsInPaperSpace {
pairs = append(pairs, NewShortCodePair(67, shortFromBool(b.IsInPaperSpace)))
}
pairs = append(pairs, NewStringCodePair(8, b.Layer))
if version >= R13 {
pairs = append(pairs, NewStringCodePair(100, "AcDbBlockBegin"))
}
pairs = append(pairs, NewStringCodePair(2, b.Name))
pairs = append(pairs, NewShortCodePair(70, 0)) // flags
pairs = append(pairs, NewDoubleCodePair(10, b.BasePoint.X))
pairs = append(pairs, NewDoubleCodePair(20, b.BasePoint.Y))
pairs = append(pairs, NewDoubleCodePair(30, b.BasePoint.Z))
if version >= R12 {
pairs = append(pairs, NewStringCodePair(3, b.Name))
}
pairs = append(pairs, NewStringCodePair(1, b.XrefName))
if len(b.Description) > 0 {
pairs = append(pairs, NewStringCodePair(4, b.Description))
}
for i := range b.Entities {
e := &b.Entities[i]
pairs = append(pairs, allCodePairs(*e, version)...)
}
pairs = append(pairs, NewStringCodePair(0, "ENDBLK"))
pairs = append(pairs, NewStringCodePair(5, stringFromHandle(b.endBlockHandle)))
if version >= R13 {
pairs = append(pairs, NewStringCodePair(100, "AcDbEntity"))
}
if b.IsInPaperSpace {
pairs = append(pairs, NewShortCodePair(67, shortFromBool(b.IsInPaperSpace)))
}
pairs = append(pairs, NewStringCodePair(8, b.Layer))
if version >= R13 {
pairs = append(pairs, NewStringCodePair(100, "AcDbBlockEnd"))
}
return
}