-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathHImage.py
154 lines (130 loc) · 6.07 KB
/
HImage.py
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
151
152
153
154
from Object import Object
from Object import PyProperty
import geom
import wx
import cad
type = 0
class HImage(Object):
def __init__(self, filepath = None):
Object.__init__(self, 0)
self.filepath = filepath
self.texture_number = None
self.width = None
self.height = None
self.textureWidth = None
self.textureHeight = None
self.bottom_left = None
self.bottom_right = None
self.top_right = None
self.top_left = None
self.opacity = 1.0
def GetIconFilePath(self):
return wx.GetApp().cad_dir + '/icons/picture.png'
def GetTypeString(self):
return "Image"
def GetTitle(self):
return 'Picture - ' + self.filepath
def GetType(self):
return type
def GetBox(self):
box = geom.Box3D()
if self.bottom_left != None:
box.InsertPoint(self.bottom_left.x, self.bottom_left.y, self.bottom_left.z)
box.InsertPoint(self.bottom_right.x, self.bottom_right.y, self.bottom_right.z)
box.InsertPoint(self.top_right.x, self.top_right.y, self.top_right.z)
box.InsertPoint(self.top_left.x, self.top_left.y, self.top_left.z)
return box
def GetProperties(self):
properties = []
properties.append(PyProperty("opacity", 'opacity', self))
properties += Object.GetProperties(self)
return properties
def OnGlCommands(self, select, marked, no_color):
if self.texture_number == None:
image = wx.Image(self.filepath)
if not image.IsOk():
self.texture_number = 0
return
self.width = image.GetWidth()
self.height = image.GetHeight()
if self.bottom_left == None:
self.bottom_left = geom.Point3D(0,0,0)
self.bottom_right = geom.Point3D(self.width,0,0)
self.top_right = geom.Point3D(self.width,self.height,0)
self.top_left = geom.Point3D(0,self.height,0)
self.texture_number, self.textureWidth = cad.GenTexture(image.GetData(), None, self.width, self.height, image.HasAlpha())
if self.texture_number == 0:
return
if self.bottom_left != None:
cad.DrawImageQuads(self.width, self.height, self.textureWidth, self.texture_number, self.bottom_left, self.bottom_right, self.top_right, self.top_left, self.opacity, no_color, marked)
def GetGrippers(self, just_for_endof):
if self.bottom_left != None:
cad.AddGripper(cad.GripData(self.bottom_left, cad.GripperType.Stretch, 0))
cad.AddGripper(cad.GripData(self.bottom_right, cad.GripperType.Stretch, 0))
cad.AddGripper(cad.GripData(self.top_right, cad.GripperType.Stretch, 0))
cad.AddGripper(cad.GripData(self.top_left, cad.GripperType.Stretch, 0))
def Stretch(self):
p = cad.GetStretchPoint()
shift = cad.GetStretchShift()
if p == self.bottom_left:
self.bottom_left = self.bottom_left + shift
if p == self.bottom_right:
self.bottom_right = self.bottom_right + shift
if p == self.top_right:
self.top_right = self.top_right + shift
if p == self.top_left:
self.top_left = self.top_left + shift
def Transform(self, mat):
self.bottom_left.Transform(mat)
self.bottom_right.Transform(mat)
self.top_right.Transform(mat)
self.top_left.Transform(mat)
def WriteXml(self):
cad.SetXmlValue('filepath', self.filepath.replace('\\','/'))
cad.SetXmlValue('x00', self.bottom_left.x)
cad.SetXmlValue('x01', self.bottom_left.y)
cad.SetXmlValue('x02', self.bottom_left.z)
cad.SetXmlValue('x10', self.bottom_right.x)
cad.SetXmlValue('x11', self.bottom_right.y)
cad.SetXmlValue('x12', self.bottom_right.z)
cad.SetXmlValue('x20', self.top_right.x)
cad.SetXmlValue('x21', self.top_right.y)
cad.SetXmlValue('x22', self.top_right.z)
cad.SetXmlValue('x30', self.top_left.x)
cad.SetXmlValue('x31', self.top_left.y)
cad.SetXmlValue('x32', self.top_left.z)
cad.SetXmlValue('opacity', self.opacity)
Object.WriteXml(self)
def ReadXml(self):
self.filepath = cad.GetXmlValue('filepath')
if self.bottom_left == None:
self.bottom_left = geom.Point3D(0,0,0)
self.bottom_right = geom.Point3D(0,0,0)
self.top_right = geom.Point3D(0,0,0)
self.top_left = geom.Point3D(0,0,0)
self.bottom_left.x = float(cad.GetXmlValue('x00'))
self.bottom_left.y = float(cad.GetXmlValue('x01'))
self.bottom_left.z = float(cad.GetXmlValue('x02'))
self.bottom_right.x = float(cad.GetXmlValue('x10'))
self.bottom_right.y = float(cad.GetXmlValue('x11'))
self.bottom_right.z = float(cad.GetXmlValue('x12'))
self.top_right.x = float(cad.GetXmlValue('x20'))
self.top_right.y = float(cad.GetXmlValue('x21'))
self.top_right.z = float(cad.GetXmlValue('x22'))
self.top_left.x = float(cad.GetXmlValue('x30'))
self.top_left.y = float(cad.GetXmlValue('x31'))
self.top_left.z = float(cad.GetXmlValue('x32'))
self.opacity = float(cad.GetXmlValue('opacity'))
Object.ReadXml(self)
def MakeACopy(self):
copy = HImage()
copy.CopyFrom(self)
return copy
def CopyFrom(self, o):
self.filepath = o.filepath
self.bottom_left = geom.Point3D(o.bottom_left)
self.bottom_right = geom.Point3D(o.bottom_right)
self.top_right = geom.Point3D(o.top_right)
self.top_left = geom.Point3D(o.top_left)
self.opacity = o.opacity
Object.CopyFrom(self, o)