-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
173 lines (128 loc) · 4.89 KB
/
test.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from object.base.arc import Circle
from object.base.blank import BlankFunction
from object.architecture.wall import WallFunction
from object import *
from handler import *
import socket
from os.path import exists
import sys
import json
#--------------------------------------------------
def Test_combine1() -> None:
b = BlankFunction.nemo(Cord(0,0), Cord(100, 300))
b2 = BlankFunction.nemo(Cord(100,0), Cord(200, 100))
b3 = BlankFunction.nemo(Cord(100,200), Cord(200, 300))
w = WallFunction.blank2Wall(b)
w2 = WallFunction.blank2Wall(b2)
w3 = WallFunction.blank2Wall(b3)
cad = DxfHandler()
WallFunction.combineWall(w, w2)
WallFunction.combineWall(w,w3)
cad.drawWall(w)
cad.drawWall(w2)
cad.drawWall(w3)
cad.saveDxf('Output', 'sample2.dxf')
def Test_combine2() -> None:
b = BlankFunction.nemo(Cord(0,0), Cord(100, 100))
b2 = BlankFunction.nemo(Cord(100,0), Cord(200, 100))
w = WallFunction.blank2Wall(b)
w2 = WallFunction.blank2Wall(b2)
cad = DxfHandler()
WallFunction.combineWall(w, w2)
cad.drawWall(w)
cad.drawWall(w2)
cad.saveDxf('Output', 'sample2.dxf')
def Test_makeNemoRoom() -> None:
w = WallFunction.nemoRoom(Cord(0,0), Cord(1000, 1000), 200.)
cad = DxfHandler()
cad.drawWall(w)
cad.saveDxf('Output', 'sample3.dxf')
def Test_makeBlank() -> None:
w = WallFunction.nemoRoom(Cord(0,0), Cord(1000, 1000), 200.)
cad = DxfHandler()
b = BlankFunction.nemo(Cord(200,-200), Cord(400,0))
WallFunction.makeBlank(w, b)
cad.drawWall(w)
cad.saveDxf('Output', 'sample3.dxf')
def Test_makeBlank2() -> None:
b = BlankFunction.nemo(Cord(0,0), Cord(100, 1000))
w = WallFunction.blank2Wall(b)
cad = DxfHandler()
b = BlankFunction.nemo(Cord(0, 200), Cord(100,300))
WallFunction.makeBlank(w, b)
cad.drawWall(w)
cad.saveDxf('Output', 'sample3.dxf')
def Test_door() -> None:
ar = {'garo': 1000., 'sero': 200., 'doke': 40., 'frame': 50.}
d1 = Door(cord= Cord(0,0), degree= 0, doorType= Door.NORMAL_LEFT, attr= ar)
d2 = Door(cord= Cord(1100,0), degree= 0, doorType= Door.NORMAL_RIGHT, attr= ar)
d3 = Door(cord= Cord(0,0), degree= 90, doorType= Door.NORMAL_LEFT, attr= ar)
cad = DxfHandler()
cad.drawDoor(d1)
cad.drawDoor(d2)
cad.drawDoor(d3)
cad.saveDxf('Output', 'sample4.dxf')
def Test_Circle() -> None:
c = Circle(Cord(10,10), 10.)
l = Line(Cord(0,0), Cord(10,10))
cad = DxfHandler()
cad.drawLine(l, DxfHandler.LAYER_CENTER)
cad.drawCircle(c, DxfHandler.LAYER_CENTER)
cad.saveDxf('Output', 'sample4.dxf')
def Test_Arc() -> None:
arc = Arc(Cord(10,10), 10., 0, 180)
cad = DxfHandler()
cad.drawArc(arc, DxfHandler.LAYER_WINDOW)
cad.saveDxf('Output', 'sample4.dxf')
def Test_readJson():
jsonInter = JsonInterpreter()
jsonInter.loadJson('test_house.json')
print(jsonInter.json)
def Test_readDraw(fileName):
jsonInter = JsonInterpreter()
jsonInter.loadJson(fileName)
jsonInter.convert2Obj()
cadH = DxfHandler()
cadH.drawJsonInter(jsonInter)
cadH.saveDxf('Output', fileName + '.dxf')
def Test_Communicate():
# 서버 주소랑 포트번호
host = '172.30.1.40'
port = 8080
#소켓 통신
server_sock = socket.socket(socket.AF_INET)
server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_sock.bind((host, port))
server_sock.listen(1)
while True:
print("기다리는 중")
client_sock, addr = server_sock.accept()
if client_sock:
print("Connected by", addr)
# 여기 부분에서 안드로이드->파이썬 json data를 가져와야함.
data = bytearray(client_sock.recv(1024))[2:]
info = json.loads(data)
filename = "commuicate.json"
Test_readDraw(filename)
data_transferred = 0
if not exists('Output'+'\\'+filename + '.dxf'):
print("no file")
sys.exit()
print("파일 %s 전송 시작" % 'Output'+'\\'+filename + '.dxf')
with open('Output'+'\\'+filename + '.dxf', 'rb') as f:
try:
data = f.read(1024) # 1024바이트 읽는다
while data: # 데이터가 없을 때까지
data_transferred += client_sock.send(data) # 1024바이트 보내고 크기 저장
data = f.read(1024) # 1024바이트 읽음
print("전송완료 %s, 전송량 %d" % (filename + '.dxf', data_transferred))
except Exception as ex:
print(ex)
finally:
break
client_sock.close()
server_sock.close()
#--------------------------------------------
if __name__ =='__main__':
Test_readDraw('test_house3.json')
pass