개정판 d6d52487
issue #622: 도면 저장 시 현재 작업 영역을 저장하여 도면을 열때 저장한 작업 영역을 복원한다
Change-Id: I9ce43ba30908e4058fee7fdca2701989d7d05d00
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
3719 | 3719 |
|
3720 | 3720 |
return result |
3721 | 3721 |
|
3722 |
def saveToDatabase(self, items, show_progress=None): |
|
3722 |
def saveToDatabase(self, items, rect: QRectF, show_progress=None):
|
|
3723 | 3723 |
""" save given items to database """ |
3724 | 3724 |
# delete all datas of current drawing |
3725 | 3725 |
drawing_name = self.activeDrawing.name |
3726 | 3726 |
drawing_uid = self.activeDrawing.UID |
3727 | 3727 |
|
3728 |
queries = {'first':[], 'second':[]}
|
|
3728 |
queries = {'first': [], 'second': []}
|
|
3729 | 3729 |
for item in items: |
3730 | 3730 |
if hasattr(item, 'toSql_return_separately'): |
3731 | 3731 |
sql, sqlLater = item.toSql_return_separately() |
... | ... | |
3825 | 3825 |
sys.exc_info()[-1].tb_lineno) |
3826 | 3826 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
3827 | 3827 |
|
3828 |
self.update_view_region(self.activeDrawing) |
|
3829 |
|
|
3830 |
def update_view_region(self, drawing): |
|
3831 |
"""update view region""" |
|
3832 |
with self.project.database.connect() as conn: |
|
3833 |
try: |
|
3834 |
# Get a cursor object |
|
3835 |
cursor = conn.cursor() |
|
3836 |
|
|
3837 |
# check if there is view region |
|
3838 |
sql = f"select count(*) from Views where Drawings_UID=?" |
|
3839 |
params = [drawing.UID] |
|
3840 |
cursor.execute(self.project.database.to_sql(sql), params) |
|
3841 |
rows = cursor.fetchall() |
|
3842 |
if rows[0][0]: |
|
3843 |
sql = f"update Views set X=?,Y=?,Width=?,Height=? where Drawings_UID=?" |
|
3844 |
params = (drawing.view_rect.x(), drawing.view_rect.y(), |
|
3845 |
drawing.view_rect.width(), drawing.view_rect.height(), drawing.UID) |
|
3846 |
else: |
|
3847 |
sql = f"insert into Views(Drawings_UID,X,Y,Width,Height) values(?,?,?,?,?)" |
|
3848 |
params = (drawing.UID, drawing.view_rect.x(), drawing.view_rect.y(), |
|
3849 |
drawing.view_rect.width(), drawing.view_rect.height()) |
|
3850 |
|
|
3851 |
sql = self.project.database.to_sql(sql) |
|
3852 |
cursor.execute(sql, params) |
|
3853 |
# Catch the exception |
|
3854 |
except Exception as ex: |
|
3855 |
|
|
3856 |
from App import App |
|
3857 |
message = 'error occurred({}\\n{}) in {}:{}'.format(repr(ex), sql, |
|
3858 |
sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
3859 |
sys.exc_info()[-1].tb_lineno) |
|
3860 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
3861 |
|
|
3828 | 3862 |
''' |
3829 | 3863 |
@brief set equipment data list |
3830 | 3864 |
@author humkyung |
... | ... | |
3891 | 3925 |
with self.project.database.connect() as conn: |
3892 | 3926 |
try: |
3893 | 3927 |
cursor = conn.cursor() if self.project.database.db_type == 'SQLite' else conn.cursor(as_dict=True) |
3894 |
sql = 'select UID,[NAME],[DATETIME] from Drawings' |
|
3895 |
cursor.execute(sql) |
|
3928 |
if self.project.database.db_type == 'SQLite': |
|
3929 |
sql = 'select UID, [NAME], [DATETIME], IFNULL(B.[X], 0) as X, IFNULL(B.[Y], 0) as Y, ' \ |
|
3930 |
'IFNULL(B.[Width], 0) as Width, IFNULL(B.[Height], 0) as Height from Drawings A ' \ |
|
3931 |
'left join Views B on A.UID = B.Drawings_UID' |
|
3932 |
else: |
|
3933 |
sql = 'select UID, [NAME], [DATETIME], ISNULL(B.[X], 0) as X, ISNULL(B.[Y], 0) as Y, ' \ |
|
3934 |
'ISNULL(B.[Width], 0) as Width, ISNULL(B.[Height], 0) as Height from Drawings A ' \ |
|
3935 |
'left join Views B on A.UID = B.Drawings_UID' |
|
3936 |
|
|
3937 |
cursor.execute(self.project.database.to_sql(sql)) |
|
3896 | 3938 |
for row in cursor.fetchall(): |
3897 |
res.append(Drawing(row['UID'], row['NAME'], row['DATETIME'])) |
|
3939 |
rect = QRectF(float(row['X']), float(row['Y']), float(row['Width']), float(row['Height'])) |
|
3940 |
res.append(Drawing(row['UID'], row['NAME'], row['DATETIME'], rect)) |
|
3898 | 3941 |
# Catch the exception |
3899 | 3942 |
except Exception as ex: |
3900 | 3943 |
from App import App |
DTI_PID/DTI_PID/Commands/SaveWorkCommand.py | ||
---|---|---|
34 | 34 |
from EngineeringUnknownItem import QEngineeringUnknownItem |
35 | 35 |
|
36 | 36 |
try: |
37 |
appDocData = AppDocData.instance()
|
|
37 |
app_doc_data = AppDocData.instance()
|
|
38 | 38 |
|
39 | 39 |
all_items = self.target_scene.items() |
40 |
"""get view region""" |
|
41 |
viewer = self.target_scene.views()[0] |
|
42 |
rect = viewer.viewport().rect() |
|
43 |
view_rect = viewer.mapToScene(rect).boundingRect() |
|
44 |
"""up to here""" |
|
40 | 45 |
|
41 | 46 |
items = [] |
42 | 47 |
|
... | ... | |
44 | 49 |
if issubclass(type(item), QEngineeringAbstractItem): |
45 | 50 |
items.append(item) |
46 | 51 |
|
47 |
''' |
|
48 |
titleBlockProps = appDocData.getTitleBlockProperties() |
|
49 |
titleBlockItems = [] |
|
50 |
for item in items: |
|
51 |
if type(item) is QEngineeringTextItem: |
|
52 |
for titleBlockProp in titleBlockProps: |
|
53 |
if item.area == titleBlockProp[0]: |
|
54 |
titleBlockItems.append(item) |
|
55 |
''' |
|
56 |
|
|
57 | 52 |
db_items = [item for item in items if issubclass(type(item), QEngineeringAbstractItem) and |
58 | 53 |
type(item) is not QGraphicsBoundingBoxItem and |
59 | 54 |
type(item) is not QEngineeringErrorItem and |
60 | 55 |
type(item) is not QEngineeringLineNoTextItem] |
61 | 56 |
db_items.extend([item for item in items if type(item) is QEngineeringLineNoTextItem]) |
62 |
db_items.extend([line for line in appDocData.tracerLineNos if type(line) is QEngineeringTrimLineNoTextItem])
|
|
63 |
db_items.append(appDocData._connected_items_lists)
|
|
64 |
configs = appDocData.getConfigs('Data Save', 'Unknown Xml Only')
|
|
57 |
db_items.extend([line for line in app_doc_data.tracerLineNos if type(line) is QEngineeringTrimLineNoTextItem])
|
|
58 |
db_items.append(app_doc_data._connected_items_lists)
|
|
59 |
configs = app_doc_data.getConfigs('Data Save', 'Unknown Xml Only')
|
|
65 | 60 |
if configs and int(configs[0].value) is -1: |
66 | 61 |
db_items.extend([item for item in items if type(item) is QEngineeringUnknownItem]) |
67 | 62 |
|
68 |
appDocData.saveToDatabase(db_items, self.show_progress)
|
|
63 |
app_doc_data.saveToDatabase(db_items, view_rect, self.show_progress)
|
|
69 | 64 |
|
70 | 65 |
self.resultStr = SaveWorkCommand.save_to_xml(items) |
71 | 66 |
|
72 | 67 |
""" update drawing's modified time """ |
73 |
drawings = appDocData.getDrawings()
|
|
74 |
drawing = [drawing for drawing in drawings if appDocData.imgName == os.path.splitext(drawing.name)[0]]
|
|
68 |
drawings = app_doc_data.getDrawings()
|
|
69 |
drawing = [drawing for drawing in drawings if app_doc_data.imgName == os.path.splitext(drawing.name)[0]]
|
|
75 | 70 |
if drawing[0]: |
76 | 71 |
drawing[0].datetime = datetime.now().strftime('%Y-%m-%d %H:%M:%S') |
77 |
appDocData.saveDrawings(drawing)
|
|
72 |
app_doc_data.saveDrawings(drawing)
|
|
78 | 73 |
except Exception as ex: |
79 | 74 |
from AppDocData import MessageType |
80 | 75 |
|
81 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
|
82 |
sys.exc_info()[-1].tb_lineno)
|
|
76 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
|
|
77 |
f"{sys.exc_info()[-1].tb_lineno}"
|
|
83 | 78 |
self.display_message.emit(MessageType.Error, message) |
84 | 79 |
|
85 | 80 |
@staticmethod |
... | ... | |
144 | 139 |
from App import App |
145 | 140 |
from AppDocData import MessageType |
146 | 141 |
|
147 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
|
148 |
sys.exc_info()[-1].tb_lineno)
|
|
142 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
|
|
143 |
f"{sys.exc_info()[-1].tb_lineno}"
|
|
149 | 144 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
DTI_PID/DTI_PID/Drawing.py | ||
---|---|---|
4 | 4 |
import os |
5 | 5 |
import sys |
6 | 6 |
import uuid |
7 |
from PyQt5.QtCore import * |
|
7 | 8 |
from PIL import PngImagePlugin, JpegImagePlugin |
8 | 9 |
from PIL import Image |
9 | 10 |
from PIL.ImageQt import ImageQt |
... | ... | |
50 | 51 |
|
51 | 52 |
|
52 | 53 |
class Drawing: |
53 |
''' |
|
54 |
@brief construction |
|
55 |
@author humkyung |
|
56 |
@date 2018.07.07 |
|
57 |
''' |
|
54 |
"""This is drawing class""" |
|
58 | 55 |
|
59 |
def __init__(self, uid, name, datetime): |
|
56 |
def __init__(self, uid, name, datetime, rect: QRectF = QRectF()):
|
|
60 | 57 |
import uuid |
61 | 58 |
app_doc_data = AppDocData.instance() |
62 | 59 |
|
... | ... | |
72 | 69 |
self.UID = uid |
73 | 70 |
|
74 | 71 |
self._image = None |
75 |
self._image_origin = None # do not modify just copy |
|
72 |
self._image_origin = None # do not modify just copy
|
|
76 | 73 |
self.width = 0 |
77 | 74 |
self.height = 0 |
78 | 75 |
self._attrs = [['Drawing No', ''], ['Rev No', ''], ['Unit', '']] # attributes |
76 |
self._view_rect = rect |
|
79 | 77 |
self._modified = False |
80 | 78 |
|
81 | 79 |
def __del__(self): |
... | ... | |
100 | 98 |
return os.path.join(app_doc_data.project.getDrawingFilePath(), self.name) |
101 | 99 |
|
102 | 100 |
@property |
101 |
def view_rect(self): |
|
102 |
return self._view_rect |
|
103 |
|
|
104 |
@view_rect.setter |
|
105 |
def view_rect(self, value): |
|
106 |
self._view_rect = value |
|
107 |
|
|
108 |
@property |
|
103 | 109 |
def contents(self): |
104 | 110 |
"""getter of drawing image""" |
105 | 111 |
|
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
378 | 378 |
self.settings.setValue('geometry', self.saveGeometry()) |
379 | 379 |
self.settings.setValue('windowState', self.saveState()) |
380 | 380 |
# TODO: need to modify |
381 |
|
|
382 |
"""save current view region""" |
|
383 |
app_doc_data = AppDocData.instance() |
|
384 |
if app_doc_data.activeDrawing: |
|
385 |
rect = self.graphicsView.viewport().rect() |
|
386 |
app_doc_data.activeDrawing.view_rect = self.graphicsView.mapToScene(rect).boundingRect() |
|
387 |
app_doc_data.update_view_region(app_doc_data.activeDrawing) |
|
388 |
"""up to here""" |
|
389 |
|
|
381 | 390 |
# self.save_drawing_if_necessary() |
382 | 391 |
AppDocData.instance().clear() |
383 | 392 |
event.accept() |
... | ... | |
817 | 826 |
return False |
818 | 827 |
return True |
819 | 828 |
|
820 |
''' |
|
821 |
@brief action save click event |
|
822 |
@author kyouho |
|
823 |
@date 2018.08.09 |
|
824 |
@history 2018.11.02 euisung add line data list db update |
|
825 |
humkyung save saved time to database |
|
826 |
2018.11.05 euisung add note data list db update |
|
827 |
2018.11.05 euisung add db delete process before save |
|
828 |
2018.11.12 euisung db part move new method to dbUpdate |
|
829 |
''' |
|
830 |
|
|
831 | 829 |
def actionSaveCliked(self): |
830 |
"""save current drawing""" |
|
832 | 831 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
833 | 832 |
from SaveWorkCommand import SaveWorkCommand |
834 | 833 |
|
... | ... | |
849 | 848 |
|
850 | 849 |
items = self.graphicsView.scene().items() |
851 | 850 |
|
852 |
''' |
|
853 |
# for check line disappear bug |
|
854 |
disappear_lines = [line for line in app_doc_data.lines if line not in items] |
|
855 |
''' |
|
856 |
|
|
857 |
''' |
|
858 |
for item in items: |
|
859 |
if issubclass(type(item), QEngineeringAbstractItem): |
|
860 |
app_doc_data.allItems.append(item) |
|
861 |
if issubclass(type(item), QEngineeringTextItem): |
|
862 |
app_doc_data.texts.append(item) |
|
863 |
''' |
|
864 |
|
|
865 |
''' |
|
866 |
# for check line disappear bug |
|
867 |
if disappear_lines: |
|
868 |
app_doc_data.allItems.extend(disappear_lines) |
|
869 |
for dis_line in disappear_lines: |
|
870 |
self.addMessage.emit(MessageType.Check, f"disapper line from scene : {str(dis_line)}") |
|
871 |
''' |
|
872 |
|
|
873 |
''' |
|
874 |
itemTypes = [] |
|
875 |
for item in items: |
|
876 |
typeExist = False |
|
877 |
for itemType in itemTypes: |
|
878 |
if type(item) is itemType: |
|
879 |
typeExist = True |
|
880 |
break |
|
881 |
if not typeExist: |
|
882 |
itemTypes.append(type(item)) |
|
883 |
''' |
|
884 |
|
|
885 | 851 |
self._save_work_cmd = SaveWorkCommand(self.graphicsView.scene()) |
886 | 852 |
self._save_work_cmd.show_progress.connect(self.progress_bar.setValue) |
887 | 853 |
self._save_work_cmd.display_message.connect(self.onAddMessage) |
... | ... | |
889 | 855 |
|
890 | 856 |
self._save_work_cmd.start() |
891 | 857 |
except Exception as ex: |
892 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
|
893 |
sys.exc_info()[-1].tb_lineno)
|
|
858 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
|
|
859 |
f"{sys.exc_info()[-1].tb_lineno}"
|
|
894 | 860 |
self.addMessage.emit(MessageType.Error, message) |
895 | 861 |
|
896 | 862 |
def save_finished(self): |
... | ... | |
1013 | 979 |
self.graphicsView.scene().removeItem(self.actionVendor.tag._polyline) |
1014 | 980 |
self.actionVendor.tag.reset() |
1015 | 981 |
|
1016 |
''' |
|
1017 |
@brief Fit Window |
|
1018 |
@author Jeongwoo |
|
1019 |
@date 2018.06.27 |
|
1020 |
@history 2018.06.27 Jeongwoo Chnage method to initialize command [Set None → DefaultCommand] |
|
1021 |
''' |
|
1022 |
|
|
1023 |
def fitWindow(self, action): |
|
982 |
def fitWindow(self, view_rect: QRectF = QRectF()): |
|
983 |
"""Fit Window""" |
|
1024 | 984 |
self.graphicsView.useDefaultCommand() |
1025 | 985 |
self.graphicsView.zoomImageInit() |
1026 | 986 |
|
987 |
if view_rect: |
|
988 |
self.graphicsView.zoom_rect(view_rect) |
|
989 |
|
|
1027 | 990 |
def scene_changed(self): |
1028 | 991 |
"""update modified flag""" |
1029 | 992 |
|
... | ... | |
1596 | 1559 |
|
1597 | 1560 |
self.changeViewCheckedState(True) |
1598 | 1561 |
self.setWindowTitle(self.title) |
1562 |
self.fitWindow(drawing.view_rect) |
|
1599 | 1563 |
|
1600 | 1564 |
# save alarm |
1601 | 1565 |
self.save_alarm_enable(True, True) |
1602 | 1566 |
except Exception as ex: |
1603 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
|
1604 |
sys.exc_info()[-1].tb_lineno)
|
|
1567 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
|
|
1568 |
f"{sys.exc_info()[-1].tb_lineno}"
|
|
1605 | 1569 |
self.addMessage.emit(MessageType.Error, message) |
1606 | 1570 |
|
1607 | 1571 |
return self.path |
DTI_PID/DTI_PID/QtImageViewer.py | ||
---|---|---|
249 | 249 |
|
250 | 250 |
return file_path |
251 | 251 |
|
252 |
def zoom_rect(self, rect: QRectF) -> None: |
|
253 |
"""zoom window within given rectangle""" |
|
254 |
self.fitInView(rect, Qt.KeepAspectRatio) |
|
255 |
if not self.zoomStack: |
|
256 |
self.zoomStack = [] |
|
257 |
|
|
258 |
self.zoomStack.append(rect) |
|
259 |
|
|
260 |
|
|
252 | 261 |
''' |
253 | 262 |
@history 2018.06.27 Jeongwoo Change zoom rule (Qt.KeepAspectRatioByExpanding → Qt.KeepAspectRatio) |
254 | 263 |
''' |
... | ... | |
270 | 279 |
self.aspectRatioMode) # Show entire image (use current aspect ratio mode). |
271 | 280 |
|
272 | 281 |
def zoomImageInit(self): |
273 |
#from EngineeringConnectorItem import QEngineeringConnectorItem |
|
274 |
|
|
275 | 282 |
if self.hasImage(): |
276 | 283 |
self.zoomStack = [] |
277 | 284 |
self.updateViewer() |
278 | 285 |
self.setCursor(QCursor(Qt.ArrowCursor)) |
279 | 286 |
|
280 |
#for conn in [item for item in self.scene().items() if type(item) is QEngineeringConnectorItem]: |
|
281 |
# conn.setVisible(False) |
|
282 |
|
|
283 | 287 |
''' |
284 | 288 |
@brief Zoom in & out image |
285 | 289 |
@author Jeongwoo |
내보내기 Unified diff