프로젝트

일반

사용자정보

개정판 50bad001

ID50bad0014781be5b973aa5e7bd136cbb976f4013
상위 3420de15
하위 5ddf3ffe

김연진이(가) 5년 이상 전에 추가함

issue #1197 도면저장 : SaveAs 메뉴 추가

Change-Id: I21a290a80e0f9ad736ee2a57b9217ac1cc7e27c8

차이점 보기:

HYTOS/HYTOS/App.py
34 34
            self.loadStyleSheet(os.path.dirname(os.path.realpath(__file__)) + '\\{}'.format(configs[0].value))
35 35
            self.stylesheet_name = configs[0].value
36 36
        else:
37
            self.loadStyleSheet(os.path.dirname(os.path.realpath(__file__)) + '\\coffee')
38
            self.stylesheet_name = 'coffee'
37
            self.loadStyleSheet(os.path.dirname(os.path.realpath(__file__)) + '\\pagefold')
38
            self.stylesheet_name = 'pagefold'
39 39

  
40 40
        ### load language file
41 41
        self._translator = None
HYTOS/HYTOS/AppDocData.py
810 810
        res = []
811 811
        try:
812 812
            # Creates or opens a file called mydb with a SQLite3 DB
813
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
814
            db = sqlite3.connect(dbPath)
813
            #dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
814
            #db = sqlite3.connect(dbPath)
815
            db = sqlite3.connect(self.activeDrawing.path)
815 816
            # Get a cursor object
816 817
            cursor = db.cursor()
817 818

  
......
1172 1173
            self.configTable = []
1173 1174
            try:
1174 1175
                # Creates or opens a file called mydb with a SQLite3 DB
1175
                dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
1176
                dbPath = self.getAppDbPath()
1176 1177
                conn = sqlite3.connect(dbPath)
1177 1178
                # Get a cursor object
1178 1179
                cursor = conn.cursor()
......
1352 1353
            # Close the db connection
1353 1354
            conn.close()
1354 1355

  
1355
    def deleteDrawingByUID(self, drawing):
1356
    def deleteDrawingByName(self, drawingName):
1356 1357
        """ delete given drawing """
1357 1358
        conn = sqlite3.connect(self.getAppDbPath())
1358 1359
        with conn:
......
1360 1361
                # Get a cursor object
1361 1362
                cursor = conn.cursor()
1362 1363

  
1363
                sql = 'delete from Drawings where UID=?'
1364
                param = (drawing.UID,)
1364
                sql = 'delete from Drawings where Name=?'
1365
                param = (drawingName,)
1365 1366
                cursor.execute(sql, param)
1366 1367
                
1367 1368
                conn.commit()
......
3146 3147
    def getUnits(self):
3147 3148
        unitsList = []
3148 3149

  
3149
        try:
3150
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
3151

  
3152
            conn = sqlite3.connect(dbPath)
3150
        try:            
3151
            conn = sqlite3.connect(self.activeDrawing.path)
3153 3152
            cursor = conn.cursor()
3154 3153
            sql = 'Select UID, Key, Value From Units'
3155 3154
            try:
HYTOS/HYTOS/ConfigurationDialog.py
20 20

  
21 21
        self.ui = Configuration_UI.Ui_ConfigurationDialog()
22 22
        self.ui.setupUi(self)
23
        self.ui.comboBox_Pressure.currentIndexChanged.connect(self.onPpressurechanged) 
23
        self.ui.comboBox_Pressure.currentIndexChanged.connect(self.onPressurechanged) 
24 24

  
25 25

  
26 26
        self.initialize()
27 27
        
28
    def onPpressurechanged(self, index):
28
    def onPressurechanged(self, index):
29 29

  
30 30
        unit = self.ui.comboBox_Pressure.itemText(index)
31 31
        if unit == 'kg/cm2':
......
42 42
            self.ui.lineEdit_CurrentBarometricPressure.setText('0.101325')
43 43

  
44 44
        self.ui.label_PressureUnit.setText(unit)
45
        
46

  
47

  
48

  
49
        
50
        
51
        uid = self.ui.comboBox_Pressure.itemData(index)
52
        
45
    
53 46

  
54 47
    def initialize(self):       
55 48
        self.ui.comboBox_Flowrate_Mass.clear()
HYTOS/HYTOS/Configuration_UI.py
18 18
        font.setFamily("맑은 고딕")
19 19
        ConfigurationDialog.setFont(font)
20 20
        icon = QtGui.QIcon()
21
        icon.addPixmap(QtGui.QPixmap(":/images/Configuration.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
21
        icon.addPixmap(QtGui.QPixmap(":/images/HYTOS.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
22 22
        ConfigurationDialog.setWindowIcon(icon)
23 23
        self.formLayout = QtWidgets.QFormLayout(ConfigurationDialog)
24 24
        self.formLayout.setObjectName("formLayout")
......
220 220
        font.setBold(False)
221 221
        font.setWeight(50)
222 222
        self.radioButton.setFont(font)
223
        self.radioButton.setChecked(True)
223 224
        self.radioButton.setObjectName("radioButton")
224 225
        self.horizontalLayout_7.addWidget(self.radioButton)
225 226
        self.radioButton_2 = QtWidgets.QRadioButton(self.groupBox)
......
578 579

  
579 580
    def retranslateUi(self, ConfigurationDialog):
580 581
        _translate = QtCore.QCoreApplication.translate
581
        ConfigurationDialog.setWindowTitle(_translate("ConfigurationDialog", "HYTOS Configuration"))
582
        ConfigurationDialog.setWindowTitle(_translate("ConfigurationDialog", "Configuration"))
582 583
        self.groupBox_2.setTitle(_translate("ConfigurationDialog", "Sheet Information"))
583 584
        self.label_8.setText(_translate("ConfigurationDialog", "Approved By :"))
584 585
        self.label.setText(_translate("ConfigurationDialog", "Checked By :"))
HYTOS/HYTOS/MainWindow.py
78 78
            self.statusbar.addWidget(self._label_mouse)
79 79
            self.showMaximized()
80 80

  
81
            _translate = QCoreApplication.translate
82
            version = QCoreApplication.applicationVersion()
83
            self.setWindowTitle(_translate(App.NAME  + "({})".format(version), App.NAME + "({})".format(version)))
84

  
81
            self.setMainWindowTitle()
82
            
85 83
            self.graphicsView = QtImageViewer.QtImageViewer(self)
86 84
            self.graphicsView.setParent(self.centralwidget)
87 85
            self.graphicsView.useDefaultCommand() 
......
104 102
            # connect signals and slots
105 103
            self.actionGroup.triggered.connect(self.actionGroupTriggered)
106 104
            self.actionClose.triggered.connect(self.close)
107
            self.actionNew.triggered.connect(self.new_drawing)
105
            self.actionNew.triggered.connect(self.on_new_drawing)
108 106
            self.actionOpen.triggered.connect(self.on_open_drawing)
109 107
            self.actionSave.triggered.connect(self.actionSaveCliked)
110 108
            self.actionCalculation.triggered.connect(self.calculation)
......
153 151
            action.triggered.connect(partial(self.load_language, file))
154 152
        # up to here
155 153

  
154
    def setMainWindowTitle(self, drawingName = None):   
155
        _translate = QCoreApplication.translate
156
             
157
        version = QCoreApplication.applicationVersion()
158
        if drawingName is None:
159
            self.setWindowTitle(_translate(App.NAME  + "({})".format(version), App.NAME + "({})".format(version)))
160
        else:
161
            self.setWindowTitle(_translate(App.NAME  + "({}) - {}".format(version, drawingName), App.NAME + "({}) - {}".format(version, drawingName)))
162

  
163

  
164

  
156 165
    def openContextMenu(self, position):
157 166
        indexes = self.treeWidgetDrawingList.selectedIndexes()
158 167
        if len(indexes) > 0:
......
168 177
            item = self.treeWidgetDrawingList.itemAt(itemPosition)
169 178

  
170 179
            if level == 0:            
171
                newDrawingAction = menu.addAction(self.tr('New Drawing'))
180
                newDrawingAction = menu.addAction(self.tr('New...'))
172 181
                newDrawingAction.triggered.connect(lambda: self.newDrawingActionClickEvent(item))
173 182
                menu.addAction(newDrawingAction)
174 183
            elif level == 1:            
175
                editDrawingAction = menu.addAction(self.tr("Edit Drawing"))
176
                editDrawingAction.triggered.connect(lambda: self.editDrawingActionClickEvent(item))
177
                menu.addAction(editDrawingAction)
184
                saveAsDrawingAction = menu.addAction(self.tr("Save As..."))
185
                saveAsDrawingAction.triggered.connect(lambda: self.saveAsDrawingActionClickEvent(item))
186
                menu.addAction(saveAsDrawingAction)
178 187

  
179
                deleteDrawingAction = menu.addAction(self.tr("Delete Drawing"))
188
                deleteDrawingAction = menu.addAction(self.tr("Delete"))
180 189
                deleteDrawingAction.triggered.connect(lambda: self.deleteDrawingActionClickEvent(item))
181 190
                menu.addAction(deleteDrawingAction)
182 191

  
183 192
            menu.exec_(self.treeWidgetDrawingList.viewport().mapToGlobal(position))
184 193

  
194
    def on_new_drawing(self):
195
        self.new_drawing()
185 196

  
186 197
    def newDrawingActionClickEvent(self, item):
187 198
        self.new_drawing()
188 199

  
189
    def editDrawingActionClickEvent(self, item):
190
        from DrawingDialog import QDrawingDialog
191

  
192
        uid = item.text(2)
193

  
194
        dlg = QDrawingDialog(self)
195
        drawingName = dlg.showDialog(uid)
196
        if drawingName:
197
            self.load_drawing_list()
200
    def saveAsDrawingActionClickEvent(self, item):
201
        sourceDb = item.text(2)
202
                        
203
        self.saveAs_drawing(sourceDb)
198 204

  
199 205
    def deleteDrawingActionClickEvent(self, item):
200 206
        """ delete selected drawing """
201 207
        try:
202 208
            msg = QMessageBox(self)
203 209
            msg.setIcon(QMessageBox.Question)
204
            msg.setText(self.tr('Do you want to delete drawing?\nThis work cannot be recovered.'))
205
            msg.setWindowTitle(self.tr("Delete Drawing"))
210
            msg.setText(self.tr('Do you want to delete drawing on list?\nHowever, Actual drawing is not deleted.'))
211
            msg.setWindowTitle(self.tr("Delete"))
206 212
            msg.setStandardButtons(QMessageBox.Ok|QMessageBox.Cancel)
207 213

  
208 214
            if QMessageBox.Ok == msg.exec_():
209
                drawing = item.data(0, Qt.UserRole)
215
                drawingName = item.text(0)
216
                drawingPath = item.text(2)
217
            
210 218
                app_doc_data = AppDocData.instance()
211
                
212
                if app_doc_data.activeDrawing is not None:                    
213
                    app_doc_data.activeDrawing = None
219
                app_doc_data.deleteDrawingByName(drawingPath)
214 220

  
215
                if self.graphicsView.hasImage():
216
                    self.graphicsView.clearImage()
217
                    self.graphicsView.scene.clear()
221
                if drawingName == app_doc_data.activeDrawing.name and drawingPath == app_doc_data.activeDrawing.path:
222
                    app_doc_data.activeDrawing = None
218 223

  
219
                app_doc_data.deleteDrawingByUID(drawing)
224
                    if self.graphicsView.hasImage():
225
                        self.graphicsView.clearImage()
226
                        self.graphicsView.scene.clear()
220 227

  
221
                self.load_drawing_list()                
222
                self.initTableWidgetHMB()
228
                    self.initTableWidgetHMB()
223 229

  
230
                self.load_drawing_list()                            
224 231
        except Exception as ex:
225 232
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
226 233
            self.addMessage.emit(MessageType.Error, message)
......
296 303
        self.treeWidgetDrawingList.setHeaderHidden(False)
297 304
        self.treeWidgetDrawingList.header().setStretchLastSection(True)
298 305
        self.treeWidgetDrawingList.header().setDefaultAlignment(Qt.AlignCenter)
299
        self.treeWidgetDrawingList.setHeaderLabels([self.tr('Name'), self.tr('DateTime'), self.tr('Uid')])
306
        self.treeWidgetDrawingList.setHeaderLabels([self.tr('Name'), self.tr('DateTime'), self.tr('Path')])
300 307
        self.treeWidgetDrawingList.header().setSectionResizeMode(0, QHeaderView.ResizeToContents)
301 308
        self.treeWidgetDrawingList.header().setSectionResizeMode(1, QHeaderView.ResizeToContents)
302 309
        self.treeWidgetDrawingList.header().setSectionResizeMode(2, QHeaderView.ResizeToContents)
......
388 395
            self.treeWidgetDrawingList.root = QTreeWidgetItem(self.treeWidgetDrawingList, [self.tr('Drawings'), ''])
389 396
                      
390 397
            for drawing in drawings:
391
                item = QTreeWidgetItem(self.treeWidgetDrawingList.root, [drawing.name, drawing.date_time])
398
                item = QTreeWidgetItem(self.treeWidgetDrawingList.root, [drawing.name, drawing.date_time, drawing.path])
392 399
                item.setData(0, Qt.UserRole, drawing)
393 400
                            
394 401
            self.treeWidgetDrawingList.root.setText(0, self.tr('Drawings')+'({})'.format(self.treeWidgetDrawingList.root.childCount()))
......
400 407
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
401 408
            self.addMessage.emit(MessageType.Error, message)
402 409

  
403
    def open_selected_drawing(self, item, column):
410
    def open_selected_drawing(self, item):
404 411
        """ open selected drawing """
405
        drawing = item.data(0, Qt.UserRole)
406
        if drawing:
407
            self.open_border_file()
408
            self.load_data(drawing)
412
        path = item.text(2)
413
        if os.path.exists(path):
414
            self.open_drawing(path)
415

  
409 416

  
410 417
    def dbUpdate(self):
411 418
        '''
......
478 485
                    self.progress.setAutoClose(True)
479 486
                    self.progress.setMinimum(0)
480 487
                    self.progress.resize(600,100)
481
                    self.progress.setWindowTitle(self.tr("Save Drawing"))
488
                    self.progress.setWindowTitle(self.tr("Save"))
482 489
                    self.progress.show()
483 490

  
484 491
                    self.save_drawing_data()
......
669 676

  
670 677
        try:
671 678
            appDocData = AppDocData.instance()
672
            if appDocData.imgName is None or appDocData.activeDrawing is None:
679
            if appDocData.activeDrawing is None:
673 680
                self.showImageSelectionMessageBox()
674 681
                return
675 682
           
......
711 718
        from ConfigurationDialog import QConfigurationDialog
712 719

  
713 720
        appDocData = AppDocData.instance()
714
        if appDocData.imgName is None or appDocData.activeDrawing is None:
721
        if appDocData.activeDrawing is None:
715 722
            self.showImageSelectionMessageBox()
716 723
            return
717 724
            
......
781 788
            self.onCommandRejected()
782 789

  
783 790
            app_doc_data.activeDrawing = drawing
784

  
791
            self.setMainWindowTitle(drawing.path)
785 792
            self.initTableWidgetHMB()
786 793
            ## Load data on database     
787 794

  
......
796 803
                    self.progress.setAutoClose(True)
797 804
                    self.progress.setMinimum(0)
798 805
                    self.progress.resize(600,100)
799
                    self.progress.setWindowTitle(self.tr("Open Drawing"))
806
                    self.progress.setWindowTitle(self.tr("Load data..."))
800 807
                    self.progress.show()
801 808

  
802 809
                    self.load_components(components)
......
813 820
            self.addMessage.emit(MessageType.Error, message)
814 821

  
815 822

  
823
    def saveAs_drawing(self, sourceDb):
824
        import uuid
825
        from shutil import copyfile
826
        from datetime import datetime 
827
        from Drawing import Drawing
828

  
829
        workspace = self.getWorkSpace()
830

  
831
        options = QFileDialog.Options()
832
        options |= QFileDialog.DontUseNativeDialog
833
        name , _ = QFileDialog.getSaveFileName(self, self.tr('Save As'), workspace, 'HYTOS Files (*.hytos)', options=options)
834
        if name:
835
            if os.path.splitext(name)[1] != '.hytos': name += '.hytos'
836

  
837
            app_doc_data = AppDocData.instance()
838
            # copy template.db to name
839
            copyfile(sourceDb, name)
840

  
841
            matches = [drawing for drawing in app_doc_data.getDrawings() if os.path.exists(drawing.path) and os.path.samefile(drawing.path, name)]
842
            if not matches:
843
                drawing = Drawing(str(uuid.uuid4()), name, str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
844
                app_doc_data.saveDrawing(drawing)
845
            else:
846
                drawing = Drawing(str(matches[0].UID), name, str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
847
                app_doc_data.updateDrawing(drawing)
848
                
849
            self.load_drawing_list()
850
            self.open_border_file()
851
            self.load_data(drawing)
852
    
853

  
816 854
    '''
817 855
        @brief      create new drawing
818 856
        @author     yeonjin
......
824 862
        from datetime import datetime 
825 863
        from Drawing import Drawing
826 864

  
865
        workspace = self.getWorkSpace()
866

  
827 867
        options = QFileDialog.Options()
828 868
        options |= QFileDialog.DontUseNativeDialog
829
        name , _ = QFileDialog.getSaveFileName(self, self.tr('New Drawing'), '', 'HYTOS Files (*.hytos)', options=options)
869
        name , _ = QFileDialog.getSaveFileName(self, self.tr('New'), workspace, 'HYTOS Files (*.hytos)', options=options)
830 870
        if name:
831 871
            if os.path.splitext(name)[1] != '.hytos': name += '.hytos'
832 872

  
833 873
            app_doc_data = AppDocData.instance()
834 874
            # copy template.db to name
835 875
            copyfile(app_doc_data.getTemplateDbPath(), name)
876

  
836 877
            matches = [drawing for drawing in app_doc_data.getDrawings() if os.path.exists(drawing.path) and os.path.samefile(drawing.path, name)]
837 878
            if not matches:
838 879
                drawing = Drawing(str(uuid.uuid4()), name, str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
......
840 881
            else:
841 882
                drawing = Drawing(str(matches[0].UID), name, str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
842 883
                app_doc_data.updateDrawing(drawing)
843

  
884
                
844 885
            self.load_drawing_list()
845 886
            self.open_border_file()
846 887
            self.load_data(drawing)
847 888
    
848 889
    def on_open_drawing(self):
849 890
        """ open selected drawing by user """
891
        workspace = self.getWorkSpace()
892

  
850 893
        options = QFileDialog.Options()
851 894
        options |= QFileDialog.DontUseNativeDialog
852
        name, _ = QFileDialog.getOpenFileName(self, 'Open Drawing', '', 'HYTOS File(*.hytos)', options=options)
895
        name, _ = QFileDialog.getOpenFileName(self, 'Open', workspace, 'HYTOS File(*.hytos)', options=options)
853 896
        if name: self.open_drawing(name)
854 897

  
855 898
    def open_drawing(self, name):
......
872 915
        self.open_border_file()
873 916
        self.load_data(drawing)
874 917

  
918

  
919
    def getWorkSpace(self):
920
        """ get work space path """
921
        app_doc_data = AppDocData.instance()
922

  
923
        configs = app_doc_data.getAppConfigs('option', 'WorkSpace')
924
        if configs and len(configs) == 1:
925
            return configs[0].value
926
        else:
927
            return os.getcwd()
928

  
875 929
    def changeViewCheckedState(self, checked, clear=True):
876 930
        '''
877 931
            @brief      change view checked state
HYTOS/HYTOS/Pump_UI.py
120 120
        self.lineEdit_TagNo.setFont(font)
121 121
        self.lineEdit_TagNo.setAlignment(QtCore.Qt.AlignCenter)
122 122
        self.lineEdit_TagNo.setObjectName("lineEdit_TagNo")
123
        self.label_5.raise_()
124
        self.lineEdit_Elevation.raise_()
125
        self.label_ElevationUnit.raise_()
126
        self.label_9.raise_()
127
        self.lineEdit_Vapor_Pressure.raise_()
128
        self.label_Vapor_PressureUnit.raise_()
129
        self.label_3.raise_()
130
        self.lineEdit_Pressure_Drop.raise_()
131
        self.label_PressureUnit.raise_()
132
        self.label_2.raise_()
133
        self.lineEdit_TagNo.raise_()
134
        self.label_Img.raise_()
123 135
        self.buttonBox = QtWidgets.QDialogButtonBox(PumpDialog)
124 136
        self.buttonBox.setGeometry(QtCore.QRect(272, 176, 156, 23))
125 137
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
HYTOS/HYTOS/UI/Configuration.ui
16 16
   </font>
17 17
  </property>
18 18
  <property name="windowTitle">
19
   <string>HYTOS Configuration</string>
19
   <string>Configuration</string>
20 20
  </property>
21 21
  <property name="windowIcon">
22 22
   <iconset resource="../res/Resource.qrc">
23
    <normaloff>:/images/Configuration.png</normaloff>:/images/Configuration.png</iconset>
23
    <normaloff>:/images/HYTOS.png</normaloff>:/images/HYTOS.png</iconset>
24 24
  </property>
25 25
  <layout class="QFormLayout" name="formLayout">
26 26
   <item row="0" column="0" colspan="2">
......
384 384
                    <property name="text">
385 385
                     <string>Project</string>
386 386
                    </property>
387
                    <property name="checked">
388
                     <bool>true</bool>
389
                    </property>
387 390
                   </widget>
388 391
                  </item>
389 392
                  <item>
HYTOS/HYTOS/UI/Pump.ui
317 317
     <set>Qt::AlignCenter</set>
318 318
    </property>
319 319
   </widget>
320
   <zorder>label_5</zorder>
321
   <zorder>lineEdit_Elevation</zorder>
322
   <zorder>label_ElevationUnit</zorder>
323
   <zorder>label_9</zorder>
324
   <zorder>lineEdit_Vapor_Pressure</zorder>
325
   <zorder>label_Vapor_PressureUnit</zorder>
326
   <zorder>label_3</zorder>
327
   <zorder>lineEdit_Pressure_Drop</zorder>
328
   <zorder>label_PressureUnit</zorder>
329
   <zorder>label_2</zorder>
330
   <zorder>lineEdit_TagNo</zorder>
331
   <zorder>label_Img</zorder>
320 332
  </widget>
321 333
  <widget class="QDialogButtonBox" name="buttonBox">
322 334
   <property name="geometry">

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)