개정판 9496adb3
pdf text import funct
Change-Id: Ib4ab227f2fd1c132c8e1ef90859af6f5868bfa31
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
3204 | 3204 |
if self.project.database.db_type == 'SQLite': |
3205 | 3205 |
for row in rows: |
3206 | 3206 |
#count = str(len(row["Count"].split(','))) |
3207 |
opcs.append({ "Drawing":row["Drawing"], "Line No":row["Line No"], "Symbol":row["Symbol"], "Count":row["Count"], "OPC":row["OPC"], "Index": row["Index"]}) |
|
3207 |
opcs.append({ "Drawing":row["Drawing"], "Line No":row["Line No"].replace('\n', ''), "Symbol":row["Symbol"], "Count":row["Count"], "OPC":row["OPC"], "Index": row["Index"]})
|
|
3208 | 3208 |
else: |
3209 | 3209 |
opcs = rows |
3210 | 3210 |
|
DTI_PID/DTI_PID/ImportTextFromPDFDialog.py | ||
---|---|---|
166 | 166 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
167 | 167 |
|
168 | 168 |
def make_text_box(self, text_node, position, height): |
169 |
import math |
|
170 |
|
|
169 | 171 |
try: |
170 | 172 |
loc = [self.text_scale[2] + position[0], self.text_scale[3] + (height - position[1])] |
171 | 173 |
|
172 | 174 |
text = text_node.text |
173 |
angle = 0#round(float(text_node.attrib['Angle']), 2)
|
|
175 |
angle = round(math.radians(float(text_node.attrib['Angle'])), 2)
|
|
174 | 176 |
|
175 | 177 |
#_height = self.text_scale[1] |
176 | 178 |
_height = round(float(text_node.attrib['Height']), 2) |
... | ... | |
181 | 183 |
#_width = round(_height * len(text) * self.text_scale[4]) |
182 | 184 |
_width = round(float(text_node.attrib['Width']), 2) |
183 | 185 |
|
186 |
|
|
187 |
if angle != 0: |
|
188 |
angle = 1.57 |
|
189 |
_height, _width = _width, _height |
|
190 |
loc[0], loc[1] = loc[0] + 10, loc[1] - _height - 10 |
|
191 |
|
|
192 |
''' |
|
184 | 193 |
allowed_error = 0.01 |
185 | 194 |
if abs(angle - 1.57) < allowed_error: |
186 | 195 |
_height, _width = _width, _height |
187 |
loc[0], loc[1] = loc[0] - _width, loc[1] - _height + _width |
|
196 |
loc[0], loc[1] = loc[0] - _width, loc[1] - _height + _width
|
|
188 | 197 |
elif abs(angle - 4.71) < allowed_error: |
189 | 198 |
_height, _width = _width, _height |
190 | 199 |
loc[0], loc[1] = loc[0] - _width, loc[1] + _height - _width |
200 |
''' |
|
191 | 201 |
|
192 | 202 |
rect = QRect(loc[0], loc[1], _width, _height) |
193 |
rect._text = text_node.text |
|
203 |
rect._text = text |
|
204 |
rect._angle = angle |
|
194 | 205 |
|
195 | 206 |
return rect |
196 | 207 |
|
197 | 208 |
except Exception as ex: |
198 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
|
|
199 |
f"{sys.exc_info()[-1].tb_lineno}"
|
|
209 |
from App import App
|
|
210 |
from AppDocData import MessageType
|
|
200 | 211 |
|
201 |
print(message) |
|
212 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
|
213 |
f"{sys.exc_info()[-1].tb_lineno}" |
|
214 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
202 | 215 |
|
203 | 216 |
|
204 | 217 |
def texts_to_xml(self, rects, symbol_areas): |
... | ... | |
241 | 254 |
# merge adjacent text box |
242 | 255 |
configs = app_doc_data.getConfigs('Text Recognition', 'Merge Size') |
243 | 256 |
mergeSize = int(configs[0].value) if 1 == len(configs) else 10 |
244 |
gap_size = 3
|
|
257 |
gap_size = 10
|
|
245 | 258 |
|
246 |
horizontals = rects |
|
259 |
horizontals = [rect for rect in rects if rect._angle == 0] |
|
260 |
verticals = [rect for rect in rects if rect not in horizontals] |
|
261 |
|
|
262 |
v_merges = [] |
|
263 |
for vertical1 in verticals: |
|
264 |
for vertical2 in verticals: |
|
265 |
if vertical1 is vertical2: |
|
266 |
continue |
|
267 |
if abs(vertical1.center().x() - vertical2.center().x()) < gap_size: |
|
268 |
t1, t2 = vertical1.top() - mergeSize, vertical2.top() - mergeSize |
|
269 |
b1, b2 = vertical1.bottom() + mergeSize, vertical2.bottom() + mergeSize |
|
270 |
l_x_y, s_x_y = [t1, b1], [t2, b2] |
|
271 |
if not (max(l_x_y) < min(s_x_y) or max(s_x_y) < min(l_x_y)): |
|
272 |
inserted = False |
|
273 |
for merge in v_merges: |
|
274 |
if vertical1 in merge and vertical2 in merge: |
|
275 |
inserted = True |
|
276 |
break |
|
277 |
elif vertical1 in merge and vertical2 not in merge: |
|
278 |
merge.append(vertical2) |
|
279 |
inserted = True |
|
280 |
break |
|
281 |
elif vertical2 in merge and vertical1 not in merge: |
|
282 |
merge.append(vertical1) |
|
283 |
inserted = True |
|
284 |
break |
|
285 |
if not inserted: |
|
286 |
v_merges.append([vertical1, vertical2]) |
|
247 | 287 |
|
248 | 288 |
h_merges = [] |
249 | 289 |
for horizontal1 in horizontals: |
... | ... | |
271 | 311 |
if not inserted: |
272 | 312 |
h_merges.append([horizontal1, horizontal2]) |
273 | 313 |
|
274 |
for merge in h_merges: |
|
314 |
for merge in h_merges + v_merges:
|
|
275 | 315 |
for rect in merge: |
276 | 316 |
if rect in rects: |
277 | 317 |
rects.remove(rect) |
278 | 318 |
else: |
279 | 319 |
pass |
280 | 320 |
|
281 |
for merge in h_merges: |
|
321 |
for merge in h_merges + v_merges:
|
|
282 | 322 |
max_x, max_y, min_x, min_y = 0, 0, sys.maxsize, sys.maxsize |
283 | 323 |
for rect in merge: |
284 | 324 |
if rect.left() < min_x: |
... | ... | |
291 | 331 |
max_y = rect.bottom() |
292 | 332 |
|
293 | 333 |
text = None |
294 |
for rect in sorted(merge, key=lambda param:param.left()): |
|
295 |
if text is None: |
|
296 |
text = rect._text |
|
297 |
elif text[-1] != '/' and text[-1] != '-' and text[-1] != '.': |
|
298 |
text = text + ' ' + rect._text |
|
299 |
else: |
|
300 |
text = text + rect._text |
|
334 |
angle = 0 |
|
335 |
if merge in h_merges: |
|
336 |
for rect in sorted(merge, key=lambda param:param.left()): |
|
337 |
angle = rect._angle |
|
338 |
if text is None: |
|
339 |
text = rect._text |
|
340 |
elif text[-1] != '/' and text[-1] != '-' and text[-1] != '.': |
|
341 |
text = text + ' ' + rect._text |
|
342 |
else: |
|
343 |
text = text + rect._text |
|
344 |
else: |
|
345 |
for rect in sorted(merge, key=lambda param:param.bottom(), reverse=True): |
|
346 |
angle = rect._angle |
|
347 |
if text is None: |
|
348 |
text = rect._text |
|
349 |
elif text[-1] != '/' and text[-1] != '-' and text[-1] != '.': |
|
350 |
text = text + ' ' + rect._text |
|
351 |
else: |
|
352 |
text = text + rect._text |
|
301 | 353 |
|
302 | 354 |
rect = QRect(min_x, min_y, max_x - min_x, max_y - min_y) |
303 | 355 |
rect._text = text |
356 |
rect._angle = angle |
|
304 | 357 |
rects.append(rect) |
305 | 358 |
# up to here |
306 | 359 |
|
... | ... | |
309 | 362 |
text = rect._text |
310 | 363 |
loc = [rect.left(), rect.top()] |
311 | 364 |
_width, _height = rect.width(), rect.height() |
365 |
angle = rect._angle |
|
312 | 366 |
|
313 | 367 |
_item = factory.createTextItem(TextInfo(text, 10, 10, 10, 10, 0)) # just for type check |
314 | 368 |
|
... | ... | |
316 | 370 |
item.setPlainText(text) |
317 | 371 |
item.loc = loc |
318 | 372 |
item.size = (_width, _height) |
319 |
item.angle = 0
|
|
373 |
item.angle = angle
|
|
320 | 374 |
|
321 | 375 |
for area in app_doc_data.getAreaList(): |
322 | 376 |
if area.contains([loc[0], loc[1]]): |
... | ... | |
350 | 404 |
|
351 | 405 |
return nodes |
352 | 406 |
except Exception as ex: |
353 |
from App import App |
|
407 |
from App import App |
|
408 |
from AppDocData import MessageType |
|
354 | 409 |
|
355 | 410 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
356 |
f"{sys.exc_info()[-1].tb_lineno}" |
|
411 |
f"{sys.exc_info()[-1].tb_lineno}"
|
|
357 | 412 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
358 | 413 |
|
359 | 414 |
def close(self): |
DTI_PID/DTI_PID/OPCRelationDialog.py | ||
---|---|---|
274 | 274 |
if not self.target or not lineNo1 or not lineNo2: |
275 | 275 |
return False |
276 | 276 |
|
277 |
if lineNo1.text() == lineNo2.text():
|
|
277 |
if lineNo1.text().replace('\n', '') == lineNo2.text().replace('\n', ''):
|
|
278 | 278 |
return True |
279 | 279 |
|
280 | 280 |
attrs1 = lineNo1.getAttributes(True) |
내보내기 Unified diff