프로젝트

일반

사용자정보

개정판 b9dd2fb5

IDb9dd2fb5be6e91089df3a4a2426fc8f7196d2e8a
상위 bbc263db
하위 819f1454

함의성이(가) 2년 이상 전에 추가함

cad import add importing option

Change-Id: I3c611e1b6e4b071eb2302efa309165f3a8ef5d8e

차이점 보기:

DTI_PID/DTI_PID/ImportTextFromCADDialog.py
273 273
        configs = app_doc_data.getConfigs('Cad Offset', 'Y Scale')
274 274
        self.ui.doubleSpinBox_2.setValue(float(configs[0].value)) if 1 == len(configs) else \
275 275
                self.ui.doubleSpinBoxScale.setValue(0.5)
276
        configs = app_doc_data.getConfigs('Cad State', 'Line')
277
        self.ui.checkBoxLine.setChecked(bool(int(configs[0].value))) if 1 == len(configs) else \
278
                self.ui.checkBoxLine.setChecked(False)
279
        configs = app_doc_data.getConfigs('Cad State', 'Text')
280
        self.ui.checkBoxText.setChecked(bool(int(configs[0].value))) if 1 == len(configs) else \
281
                self.ui.checkBoxText.setChecked(True)
282
        configs = app_doc_data.getConfigs('Cad State', 'Symbol')
283
        self.ui.checkBoxSymbol.setChecked(bool(int(configs[0].value))) if 1 == len(configs) else \
284
                self.ui.checkBoxSymbol.setChecked(False)
276 285

  
277 286
        self.text_scale = None
278 287
        self.id2_bbox = None
......
288 297
        self.ui.pushButtonAuto.clicked.connect(self.autoCalOffset)
289 298
        self.ui.checkBoxAuto.stateChanged.connect(self.autoStateChanged)
290 299

  
300
        configs = app_doc_data.getConfigs('Cad State', 'Auto')
301
        self.ui.checkBoxAuto.setChecked(bool(int((configs[0].value)))) if 1 == len(configs) else \
302
                self.ui.checkBoxAuto.setChecked(True)
303

  
291 304
    def autoStateChanged(self, checkState):
292 305
        if checkState is int(Qt.Checked):
293 306
            self.ui.spinBoxX.setEnabled(False)
......
353 366
        autocad_xml_path = os.path.join(os.path.dirname(_file), os.path.splitext(os.path.basename(_file))[0] + '.xml')
354 367
        matches = [id2_xml_file for id2_xml_file in id2_xml_files if id2_xml_file.replace(file_name, '').upper() == '.XML']
355 368

  
356
        '''
357
        id2_xml_path = os.path.join(temp_path, matches[0])
358
        id2_xml = parse(id2_xml_path)
359
        id2_xml_root = id2_xml.getroot()
360

  
361
        size_area = app_doc_data.getArea('Size')
362
        if size_area:
363
            id2_bbox = [size_area.x, size_area.y, size_area.width, size_area.height]
364
        else:
365
            id2_bbox = [0, 0,
366
                        int(id2_xml_root.find('SIZE').text.split(',')[0]),
367
                        int(id2_xml_root.find('SIZE').text.split(',')[1])]
368
        '''
369

  
370 369
        if matches:
371 370
            try:
371
                id2_xml_path = os.path.join(temp_path, matches[0])
372
                id2_xml = parse(id2_xml_path)
373
                id2_xml_root = id2_xml.getroot()
374

  
372 375
                autocad_xml = parse(autocad_xml_path)
373 376
                autocad_xml_root = autocad_xml.getroot()
374 377
                
......
434 437
                    dy_2 = abs(cad_item_loc_1[1] - cad_item_loc_2[1])
435 438
                    scale_y = dy_1 / dy_2
436 439

  
437
                    self.ui.spinBoxX.setValue(text_loc_1[0])
438
                    self.ui.spinBoxY.setValue(text_loc_1[1])
439
                    self.ui.spinBoxTextX.setValue(cad_item_loc_1[0])
440
                    self.ui.spinBoxTextY.setValue(cad_item_loc_1[1])
441

  
442
                    '''
443 440
                    offset_x = text_loc_1[0] - cad_item_loc_1[0] * scale_x
444 441
                    drawing_height = int(id2_xml_root.find('SIZE').text.split(',')[1])
445
                    offset_y = text_loc_1[1] - (drawing_height - cad_item_loc_1[1] * scale_y)
442
                    offset_y = text_loc_1[1] - (drawing_height - cad_item_loc_1[1] * scale_y) + cad_item_loc_1[2] * scale_y
446 443

  
447 444
                    self.ui.spinBoxTextX.setValue(offset_x)
448 445
                    self.ui.spinBoxX.setValue(offset_x)
......
450 447
                    self.ui.spinBoxTextY.setValue(offset_y)
451 448
                    self.ui.spinBoxY.setValue(offset_y)
452 449
                    self.ui.spinBoxSymbolY.setValue(offset_y)
453
                    '''
454 450
                    self.ui.doubleSpinBox.setValue(scale_x)
455 451
                    self.ui.doubleSpinBox_2.setValue(scale_y)
456 452

  
......
460 456

  
461 457
                message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
462 458
                          f"{sys.exc_info()[-1].tb_lineno}"
463
                QMessageBox.warning(self, self._tr('Warning'), message)
459
                QMessageBox.warning(self, 'Warning', message)
464 460

  
465 461
    def on_load_line_type_mapping(self):
466 462
        """load ID2-AutoCAD """
......
499 495

  
500 496
                message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
501 497
                          f"{sys.exc_info()[-1].tb_lineno}"
502
                QMessageBox.warning(self, self._tr('Warning'), message)
498
                QMessageBox.warning(self, 'Warning', message)
503 499

  
504 500
        model = LineTypeMappingModel()
505 501
        model.invisibleRootItem()
......
527 523
        self.ui.treeViewLineType.resizeColumnToContents(2)
528 524
        self.ui.treeViewLineType.expandAll()
529 525

  
526
        self.ui.label.setHidden(True)
527
        self.ui.spinBoxX.setHidden(True)
528
        self.ui.spinBoxY.setHidden(True)
529
        self.ui.label_8.setHidden(True)
530
        self.ui.spinBoxSymbolX.setHidden(True)
531
        self.ui.spinBoxSymbolY.setHidden(True)
532
        self.ui.label_3.setText('Offset(x, y, text scale) : ')
533

  
530 534
    def on_load_symbol_mapping(self):
531 535
        """
532 536
        load symbol mapping setting
......
707 711
        configs.append(Config('Cad Offset', 'Scale', self.ui.doubleSpinBoxScale.value()))
708 712
        configs.append(Config('Cad Offset', 'X Scale', self.ui.doubleSpinBox.value()))
709 713
        configs.append(Config('Cad Offset', 'Y Scale', self.ui.doubleSpinBox_2.value()))
714
        configs.append(Config('Cad State', 'Auto', int(self.ui.checkBoxAuto.isChecked())))
715
        configs.append(Config('Cad State', 'Line', int(self.ui.checkBoxLine.isChecked())))
716
        configs.append(Config('Cad State', 'Text', int(self.ui.checkBoxText.isChecked())))
717
        configs.append(Config('Cad State', 'Symbol', int(self.ui.checkBoxSymbol.isChecked())))
710 718

  
711 719
        model = self.ui.treeViewLineType.model()
712 720
        for row in range(model.rowCount()):
......
785 793
            min_x, min_y, max_x, max_y, width, height = None, None, None, None, None, None
786 794

  
787 795
            img = AppDocData.my_imread(file_path=img_file_path)
788
            width = img.shape[1]
789
            height = img.shape[0]
796
            _width = img.shape[1]
797
            _height = img.shape[0]
790 798
            img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
791 799
            img = cv2.bitwise_not(img)  # background should be 'BLACK'
792 800
            contours, hierarchy = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
......
799 807

  
800 808
            del img
801 809

  
802
            return min_x, min_y, max_x - min_x, max_y - min_y, width, height
810
            return min_x, min_y, max_x - min_x, max_y - min_y, _width, _height
803 811

  
804 812
        if not self._dwgs:
805 813
            QMessageBox.information(self, self.tr('Information'), self.tr('There is no selected file(s)'))
......
912 920
                        autocad_bbox = [min_values[0], min_values[1],
913 921
                                        max_values[0] - min_values[0], max_values[1] - min_values[1]]
914 922

  
915
                        scale_x = id2_bbox[2] / autocad_bbox[2] \
916
                            if self.ui.doubleSpinBox.value() < 1 else self.ui.doubleSpinBox.value()
917
                        scale_y = id2_bbox[3] / autocad_bbox[3] \
918
                            if self.ui.doubleSpinBox_2.value() < 1 else self.ui.doubleSpinBox_2.value()
919
                        self.scales = [scale_x, scale_y]
920
                        offsets = [id2_bbox[0] - autocad_bbox[0] * scale_x, id2_bbox[5] + id2_bbox[1]]
921
                        self.offsets = offsets + [autocad_bbox[1]]
923
                        if self.ui.checkBoxAuto.isChecked():
924
                            scale_x = id2_bbox[2] / autocad_bbox[2]
925
                            scale_y = id2_bbox[3] / autocad_bbox[3]
926
                            self.scales = [scale_x, scale_y]
927
                            offsets = [id2_bbox[0] - autocad_bbox[0] * scale_x, id2_bbox[3] + id2_bbox[1]]
928
                            self.offsets = offsets + [autocad_bbox[1]]
929
                        else:
930
                            self.scales = [self.ui.doubleSpinBox.value(), self.ui.doubleSpinBox_2.value()]
931
                            self.offsets = [self.ui.spinBoxTextX.value(), self.ui.spinBoxTextY.value(), id2_bbox[5]]
922 932

  
923 933
                        if 'Text' in will_be_converted_items:
924 934
                            for record in blk_tbl_record.iter('AcDbText'):
......
978 988

  
979 989
    def convert_to_image_coords(self, pt):
980 990
        """convert autocad coordinates to image coordinates"""
981
        return [pt[0] * self.scales[0] + self.offsets[0], (self.offsets[2] - pt[1]) * self.scales[1] + self.offsets[1]]
991
        if self.ui.checkBoxAuto.isChecked():
992
            return [pt[0] * self.scales[0] + self.offsets[0], (self.offsets[2] - pt[1]) * self.scales[1] + self.offsets[1]]
993
        else:
994
            return [pt[0] * self.scales[0] + self.offsets[0], self.offsets[2] - pt[1] * self.scales[1] + self.offsets[1]]
982 995

  
983 996
    def symbol_to_xml(self, blk_ref_node, mapping_configs: list) -> str:
984 997
        """try to convert block reference element to id2 xml"""
......
1086 1099
                    angle = angle - math.pi * 2 if angle > math.pi * 2 else angle
1087 1100

  
1088 1101
            _height = round(float(text_node.attrib['Height']) * self.scales[1])
1089
            #loc[1] -= _height
1102
            loc[1] -= _height
1090 1103
            _width = round(_height * len(text) * self.text_scale)
1091 1104
            #_width = round(float(text_node.attrib['Width']))
1092 1105

  
DTI_PID/DTI_PID/ImportTextFromCAD_UI.py
184 184
        self.retranslateUi(ImportTextFromCADDialog)
185 185
        self.tabWidgetEntities.setCurrentIndex(0)
186 186
        QtCore.QMetaObject.connectSlotsByName(ImportTextFromCADDialog)
187
        ImportTextFromCADDialog.setTabOrder(self.spinBoxX, self.spinBoxY)
188
        ImportTextFromCADDialog.setTabOrder(self.spinBoxY, self.spinBoxTextX)
189
        ImportTextFromCADDialog.setTabOrder(self.spinBoxTextX, self.spinBoxTextY)
190
        ImportTextFromCADDialog.setTabOrder(self.spinBoxTextY, self.doubleSpinBoxScale)
191
        ImportTextFromCADDialog.setTabOrder(self.doubleSpinBoxScale, self.spinBoxSymbolX)
192
        ImportTextFromCADDialog.setTabOrder(self.spinBoxSymbolX, self.spinBoxSymbolY)
193
        ImportTextFromCADDialog.setTabOrder(self.spinBoxSymbolY, self.lineEdit)
194
        ImportTextFromCADDialog.setTabOrder(self.lineEdit, self.lineEdit_2)
195
        ImportTextFromCADDialog.setTabOrder(self.lineEdit_2, self.doubleSpinBox)
196
        ImportTextFromCADDialog.setTabOrder(self.doubleSpinBox, self.doubleSpinBox_2)
197
        ImportTextFromCADDialog.setTabOrder(self.doubleSpinBox_2, self.checkBoxAuto)
198
        ImportTextFromCADDialog.setTabOrder(self.checkBoxAuto, self.pushButtonSave)
199
        ImportTextFromCADDialog.setTabOrder(self.pushButtonSave, self.checkBoxLine)
200
        ImportTextFromCADDialog.setTabOrder(self.checkBoxLine, self.checkBoxText)
201
        ImportTextFromCADDialog.setTabOrder(self.checkBoxText, self.checkBoxSymbol)
202
        ImportTextFromCADDialog.setTabOrder(self.checkBoxSymbol, self.pushButtonImport)
203
        ImportTextFromCADDialog.setTabOrder(self.pushButtonImport, self.pushButtonClose)
204
        ImportTextFromCADDialog.setTabOrder(self.pushButtonClose, self.pushButtonAuto)
205
        ImportTextFromCADDialog.setTabOrder(self.pushButtonAuto, self.listViewExcludeLayers)
206
        ImportTextFromCADDialog.setTabOrder(self.listViewExcludeLayers, self.lineEditCAD)
207
        ImportTextFromCADDialog.setTabOrder(self.lineEditCAD, self.toolButtonCAD)
208
        ImportTextFromCADDialog.setTabOrder(self.toolButtonCAD, self.tabWidgetEntities)
209
        ImportTextFromCADDialog.setTabOrder(self.tabWidgetEntities, self.treeViewLineType)
210
        ImportTextFromCADDialog.setTabOrder(self.treeViewLineType, self.treeViewSymbolMapping)
187 211

  
188 212
    def retranslateUi(self, ImportTextFromCADDialog):
189 213
        _translate = QtCore.QCoreApplication.translate
DTI_PID/DTI_PID/UI/ImportTextFromCAD.ui
352 352
   </item>
353 353
  </layout>
354 354
 </widget>
355
 <tabstops>
356
  <tabstop>spinBoxX</tabstop>
357
  <tabstop>spinBoxY</tabstop>
358
  <tabstop>spinBoxTextX</tabstop>
359
  <tabstop>spinBoxTextY</tabstop>
360
  <tabstop>doubleSpinBoxScale</tabstop>
361
  <tabstop>spinBoxSymbolX</tabstop>
362
  <tabstop>spinBoxSymbolY</tabstop>
363
  <tabstop>lineEdit</tabstop>
364
  <tabstop>lineEdit_2</tabstop>
365
  <tabstop>doubleSpinBox</tabstop>
366
  <tabstop>doubleSpinBox_2</tabstop>
367
  <tabstop>checkBoxAuto</tabstop>
368
  <tabstop>pushButtonSave</tabstop>
369
  <tabstop>checkBoxLine</tabstop>
370
  <tabstop>checkBoxText</tabstop>
371
  <tabstop>checkBoxSymbol</tabstop>
372
  <tabstop>pushButtonImport</tabstop>
373
  <tabstop>pushButtonClose</tabstop>
374
  <tabstop>pushButtonAuto</tabstop>
375
  <tabstop>listViewExcludeLayers</tabstop>
376
  <tabstop>lineEditCAD</tabstop>
377
  <tabstop>toolButtonCAD</tabstop>
378
  <tabstop>tabWidgetEntities</tabstop>
379
  <tabstop>treeViewLineType</tabstop>
380
  <tabstop>treeViewSymbolMapping</tabstop>
381
 </tabstops>
355 382
 <resources>
356 383
  <include location="../res/MainWindow.qrc"/>
357 384
 </resources>

내보내기 Unified diff

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