Example #1
0
    def importActionTrigger(self):
        file_path, ext = QFileDialog.getOpenFileName(filter="*.dxf")
        if file_path:#如果选择了文件
            if ext != '*.dxf':
                QMessageBox.warning(None, "文件格式错误","只能导入.dxf格式的cad文件", QMessageBox.Yes)

            try:
                dxfReader = DxfReader(file_path)
                sections = dxfReader.ParseSections()
                layers = []#解析出的图层数据
                shapes = []#解析出的图元数据
                for section in sections:
                    if isinstance(section, TablesSection):#先解析出图层
                        tables = section.ParseTables(dxfTable.LAYER)
                        for table in tables:
                            entries = table.ParseEntries()
                            for entry in entries:
                                layers.append(entry.parse())
                    elif isinstance(section, EntitiesSection):
                        entities = section.ParseEntities(None)#解析出所有的图元
                        for entity in entities:
                            shapes.append(entity.parse())

                boards = []
                for layer in layers:
                    boards.append(ExInterFace.addBorad(layer["name"]))
                paintShape = ExInterFace.getPlugin('PaintShape')
                for shape in shapes:
                    for board in boards:
                        if board.name == shape['layer']:
                            paintShape.addShape(board, MainPlugin.ShapeFromObject(shape))
                            break
            except Exception as e:
                QMessageBox.critical(None, "文件解析出错", str(e),QMessageBox.Yes)
                print("异常:"+str(e))
Example #2
0
    def drawerItemChanged(self, item, checked):
        self.clearCurrentVar()
        Board = ExInterFace.getCurrentBoard()
        for action in self.paintShapeMenu.actions():
            action.setChecked(False)
        if checked:
            if item is self.__lineContenItem:
                MainPlugin.__state[Board.id] = MainPlugin.PAINT_LINE
                self.lineAction.setChecked(True)
            elif item is self.__arcContenItem:
                MainPlugin.__state[Board.id] = MainPlugin.PAINT_ARC
                self.arcAction.setChecked(True)
            elif item is self.__circleContenItem:
                MainPlugin.__state[Board.id] = MainPlugin.PAINT_CIRCLE
                self.circleAction.setChecked(True)
            elif item is self.__selectContenItem:
                MainPlugin.__state[Board.id] = MainPlugin.SELECT
                self.selectAction.setChecked(True)
            elif item is self.__handContenItem:
                MainPlugin.__state[Board.id] = MainPlugin.HAND
                self.handAction.setChecked(True)
            else:
                raise RuntimeError("未知错误 传入了未知的值")
        else:
            MainPlugin.__state[Board.id] = MainPlugin.FREE

        Board.repaint()

        ExInterFace.exclusive(self)
 def valueChanged(self, text):
     try:
         if self.shape and self.proName:
             setattr(self.shape, self.proName, self.getValue())  # 为shape赋值
             ExInterFace.getCurrentBoard().repaint()
     except ValueError as e:
         #没有找到',' 或者其他格式错误 不修改 直接赋予原值
         self.setText(self.oriValue)
Example #4
0
    def apply(self):
        #修改MainPlugin的中的值
        self.MainPlugin.unit_pixel = self.ui.unit_pixel.value()
        self.MainPlugin.unit = self.ui.unit.currentIndex()
        self.MainPlugin.font_size = self.ui.font_size.value()
        self.MainPlugin.background_color = self.ui.background_color.text()
        self.MainPlugin.line_width = self.ui.line_width.value()
        #保存到配置文件中
        self.MainPlugin.saveSetting()

        #调用Board接口修改背景色
        #这一句会调用setStyleSheet 所以会重绘
        ExInterFace.setBackgroundColor(self.MainPlugin.background_color)
Example #5
0
    def wheelEvent(self, QWheelEvent):

        Board = ExInterFace.getCurrentBoard()

        if MainPlugin.__state[Board.id] != MainPlugin.FREE:
            # 根据鼠标滚轮缩放
            if QWheelEvent.angleDelta().y() > 0:
                MainPlugin.__scale[Board.id] += 0.03
            else:
                MainPlugin.__scale[Board.id] -= 0.03
            Board.repaint()

        if MainPlugin.__state[Board.id] == MainPlugin.PAINT_LINE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_CIRCLE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_ARC:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_ARC0:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_CIRCLE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_LINE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.FREE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.MOVING_BOARD:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.SELECT:
            pass
Example #6
0
 def getSelectShapes(self):
     Board = ExInterFace.getCurrentBoard()
     result = []
     for shape in MainPlugin.__shapes[Board.id]:
         if shape.selected:
             result.append(shape)
     return result
Example #7
0
    def keyPressEvent(self, QKeyEvent):
        Board = ExInterFace.getCurrentBoard()

        key_value = QKeyEvent.key()

        if QKeyEvent.modifiers() == Qt.ControlModifier:
            if key_value == Qt.Key_Z:
                self.revokeAction.triggered.emit(True)
                #self.revokeActionTrigger()
            elif key_value == Qt.Key_X:
                self.forwardAction.triggered.emit(True)
                #self.forwardActionTrigger()

        if key_value == Qt.Key_Q:
            self.__drawerItem.setChecked(self.__lineContenItem, True)
        elif key_value == Qt.Key_W:
            self.__drawerItem.setChecked(self.__arcContenItem, True)
        elif key_value == Qt.Key_E:
            self.__drawerItem.setChecked(self.__circleContenItem, True)
        elif key_value == Qt.Key_R:
            self.__drawerItem.setChecked(self.__handContenItem, True)
        elif key_value == Qt.Key_T:
            self.__drawerItem.setChecked(self.__selectContenItem, True)
        elif key_value == Qt.Key_Escape:
            if MainPlugin.__state[
                    Board.
                    id] == MainPlugin.PAINTING_ARC0 or MainPlugin.__state[
                        Board.id] == MainPlugin.PAINTING_ARC1:
                MainPlugin.__state[Board.id] = MainPlugin.PAINT_ARC
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_CIRCLE:
                MainPlugin.__state[Board.id] = MainPlugin.PAINT_CIRCLE
                MainPlugin.__assist_circle[Board.id].setVisible(True)
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_LINE:
                MainPlugin.__state[Board.id] = MainPlugin.PAINT_LINE
        elif key_value == Qt.Key_Delete:
            self.deleteAction.triggered.emit(True)
            #self.deleteActionTrigger()

        if MainPlugin.__state[Board.id] == MainPlugin.PAINT_LINE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_CIRCLE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_ARC:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_ARC0:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_CIRCLE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_LINE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.FREE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.MOVING_BOARD:
            pass

        Board.repaint()
Example #8
0
    def mousePressEvent(self, QMouseEvent):
        Board = ExInterFace.getCurrentBoard()
        # 坐标转换 将鼠标坐标转换为 常用数学坐标
        mousePos = MainPlugin.translatePt(QMouseEvent.pos(), Board)
        if QMouseEvent.button() == Qt.LeftButton:
            if MainPlugin.__state[Board.id] == MainPlugin.PAINT_LINE:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_CIRCLE:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_ARC:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_ARC0:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_ARC1:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_CIRCLE:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_LINE:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.FREE:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.MOVING_BOARD:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.HAND:
                #if not MainPlugin.__hand_start_pt[Board.id]:
                #MainPlugin.__hand_start_pt[Board.id] = ExPoint(mousePos)
                MainPlugin.__hand_start_pt[Board.id].x = QMouseEvent.pos().x(
                )  #这里使用Boadr坐标没有转换后的,移动就必须要一个原点固定的坐标系
                MainPlugin.__hand_start_pt[Board.id].y = QMouseEvent.pos().y()
                MainPlugin.__state[Board.id] = MainPlugin.HANDED
            elif MainPlugin.__state[Board.id] == MainPlugin.SELECT:
                pt = self.getPressPoint(mousePos)  #查找是否点击到点上
                selectedShapes = self.getSelectShapes()
                if pt and len(selectedShapes
                              ) == 1 and pt.parent == selectedShapes[0]:
                    # 如果点到了点且是当前选中的点 就开始准备移动
                    MainPlugin.__state[Board.id] = MainPlugin.MOVING_SHAPE
                    #放入撤销栈
                    MainPlugin.__go_back_stack[Board.id].append([
                        selectedShapes[0], "change",
                        copy.deepcopy(selectedShapes[0])
                    ])
                    MainPlugin.__changing_pt[Board.id] = pt
                else:
                    if not QMouseEvent.modifiers(
                    ) == Qt.ControlModifier:  #没有按下ctr 清空所有的选择
                        self.cancelAllSelected()
                    if MainPlugin.__hover_shape[Board.id]:  #有点到 图形上
                        MainPlugin.__hover_shape[
                            Board.id].origin_shape.selected = True
                        self.propertyDock.updateValues(
                            MainPlugin.__hover_shape[Board.id].origin_shape)
                    else:
                        self.propertyDock.clearAll()

        Board.repaint()
Example #9
0
    def deleteActionTrigger(self):
        #self.__drawerItem.setChecked(self.__selectContenItem, b)
        Board = ExInterFace.getCurrentBoard()
        for i in range(len(MainPlugin.__shapes[Board.id]) - 1, -1, -1):
            if MainPlugin.__shapes[Board.id][i].selected:
                deletedShape = MainPlugin.__shapes[Board.id].pop(i)
                MainPlugin.__go_back_stack[Board.id].append(
                    [deletedShape, "delete"])

        Board.repaint()
Example #10
0
 def getPressPoint(self,
                   mousePt):  #主要是用于获取 点击的点 来拉动修改图形 为了和checkHoverPoint解耦
     allPoints = []
     Board = ExInterFace.getCurrentBoard()
     # 生成所有的点列表
     for shape in MainPlugin.__shapes[Board.id]:
         allPoints += shape.getPoints()
     # 检查是否悬停到点上了
     for pt in allPoints:
         if pt.isPointNearShape(mousePt, 2.5,
                                MainPlugin) and pt.parent.selected:
             return pt
     return None
Example #11
0
 def mouseDoubleClickEvent(self, QMouseEvent):
     Board = ExInterFace.getCurrentBoard()
     if MainPlugin.__state[Board.id] == MainPlugin.PAINT_LINE:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_CIRCLE:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_ARC:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_ARC0:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_CIRCLE:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_LINE:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.FREE:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.MOVING_BOARD:
         pass
Example #12
0
 def keyReleaseEvent(self, QKeyEvent):
     Board = ExInterFace.getCurrentBoard()
     if MainPlugin.__state[Board.id] == MainPlugin.PAINT_LINE:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_CIRCLE:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_ARC:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_ARC0:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_CIRCLE:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_LINE:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.FREE:
         pass
     elif MainPlugin.__state[Board.id] == MainPlugin.MOVING_BOARD:
         pass
Example #13
0
    def forwardActionTrigger(self):
        Board = ExInterFace.getCurrentBoard()

        if not MainPlugin.__forward_stack[Board.id]:
            return

        revokeList = MainPlugin.__forward_stack[Board.id].pop()
        if revokeList[1] == "add":
            revokeList[1] = "delete"
            # 实际删除 即从__shape中移除
            MainPlugin.__shapes[Board.id].remove(revokeList[0])
        elif revokeList[1] == "delete":
            revokeList[1] = "add"
            MainPlugin.__shapes[Board.id].append(revokeList[0])
        elif revokeList[1] == "change":
            temp = copy.deepcopy(revokeList[0])
            MainPlugin.SynShapObj(revokeList[0], revokeList[2])
            revokeList[2] = temp
        MainPlugin.__go_back_stack[Board.id].append(revokeList)
Example #14
0
    def __init__(self, name):
        super().__init__(name)
        self.__drawerItem = DrawerItem("绘图")
        self.__allContentItem = []  #方便循环调用

        #实例化drawerContentItem 即用于侧边栏的按钮
        self.__lineContenItem = DrawerContentItem(
            "直线(&Q)",
            parent=self.__drawerItem,
            icon=QIcon(":/paintshape_res/img/line.png"))
        self.__allContentItem.append(self.__lineContenItem)

        self.__arcContenItem = DrawerContentItem(
            "圆弧(&W)",
            parent=self.__drawerItem,
            icon=QIcon(":/paintshape_res/img/arc.png"))
        self.__allContentItem.append(self.__arcContenItem)

        self.__circleContenItem = DrawerContentItem(
            "圆(&E)",
            parent=self.__drawerItem,
            icon=QIcon(":/paintshape_res/img/circle.png"))
        self.__allContentItem.append(self.__circleContenItem)

        self.__handContenItem = DrawerContentItem(
            "Hand(&R)",
            parent=self.__drawerItem,
            icon=QIcon(":/paintshape_res/img/hand.png"))
        self.__allContentItem.append(self.__handContenItem)

        self.__selectContenItem = DrawerContentItem(
            "选择(&T)",
            parent=self.__drawerItem,
            icon=QIcon(":/paintshape_res/img/select.png"))
        self.__allContentItem.append(self.__selectContenItem)

        #添加到drawerItem
        self.__drawerItem.addContentItems(self.__allContentItem)

        #创建属性dockwidget
        self.propertyDock = ShapePropertyDockWidget("图形属性")
        self.propertyDock.setMinimumWidth(300)

        #菜单
        self.paintShapeMenu = QMenu("绘图")

        self.lineAction = QAction(QIcon(":/paintshape_res/img/line.png"),
                                  "直线(&Q)",
                                  self.paintShapeMenu)  #讲道理 这里可以用eval简化写法
        self.lineAction.setCheckable(True)
        self.lineAction.triggered.connect(self.lineActionToggled)
        self.lineAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.lineAction)

        self.arcAction = QAction(QIcon(":/paintshape_res/img/arc.png"),
                                 "圆弧(&W)", self.paintShapeMenu)
        self.arcAction.setCheckable(True)
        self.arcAction.triggered.connect(self.arcActionToggled)
        self.arcAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.arcAction)

        self.circleAction = QAction(QIcon(":/paintshape_res/img/circle.png"),
                                    "圆(&E)", self.paintShapeMenu)
        self.circleAction.setCheckable(True)
        self.circleAction.triggered.connect(self.circleActionToggled)
        self.circleAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.circleAction)

        self.handAction = QAction(QIcon(":/paintshape_res/img/hand.png"),
                                  "Hand(&R)", self.paintShapeMenu)
        self.handAction.setCheckable(True)
        self.handAction.triggered.connect(self.handActionToggled)
        self.handAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.handAction)

        self.selectAction = QAction(QIcon(":/paintshape_res/img/select.png"),
                                    "选择(&T)", self.paintShapeMenu)
        self.selectAction.setCheckable(True)
        self.selectAction.triggered.connect(self.selectActionToggled)
        self.selectAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.selectAction)

        self.deleteAction = QAction(QIcon(":/paintshape_res/img/delete.png"),
                                    "删除选中(&Delete)", self.paintShapeMenu)
        self.deleteAction.triggered.connect(self.deleteActionTrigger)
        self.deleteAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.deleteAction)

        self.revokeAction = QAction(QIcon(":/paintshape_res/img/revoke.png"),
                                    "撤销(ctr+Z)", self.paintShapeMenu)
        self.revokeAction.triggered.connect(self.revokeActionTrigger)
        self.revokeAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.revokeAction)

        self.forwardAction = QAction(QIcon(":/paintshape_res/img/forward.png"),
                                     "前进(ctr+X)", self.paintShapeMenu)
        self.forwardAction.triggered.connect(self.forwardActionTrigger)
        self.forwardAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.forwardAction)

        self.showPropertyDockAction = QAction(
            QIcon(":/paintshape_res/img/show.png"), "显示属性窗口",
            self.paintShapeMenu)
        self.showPropertyDockAction.triggered.connect(self.propertyDock.show)
        self.showPropertyDockAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.showPropertyDockAction)

        #连接contentItem的点击信号
        for item in self.__allContentItem:
            item.clickedSignal.connect(self.drawerItemChanged)

        self.__settingWidget = PaintShapSettingWidget(MainPlugin)

        #读取配置文件
        MainPlugin.conf.read(MainPlugin.conf_path)

        MainPlugin.background_color = MainPlugin.conf.get(
            "setting", "background_color")
        MainPlugin.unit_pixel = MainPlugin.conf.getint("setting", "unit_pixel")
        MainPlugin.unit = MainPlugin.conf.getint("setting", "unit")
        MainPlugin.font_size = MainPlugin.conf.getint("setting", "font_size")
        MainPlugin.line_width = MainPlugin.conf.getint("setting", "line_width")

        #为widget赋值
        self.__settingWidget.ui.background_color.setText(
            MainPlugin.background_color)
        self.__settingWidget.ui.unit.setCurrentIndex(MainPlugin.unit)
        self.__settingWidget.ui.unit_pixel.setValue(MainPlugin.unit_pixel)
        self.__settingWidget.ui.font_size.setValue(MainPlugin.font_size)
        self.__settingWidget.ui.line_width.setValue(MainPlugin.line_width)

        #调用接口设置
        ExInterFace.setBackgroundColor(MainPlugin.background_color)
 def currentIndexChangedSlot(self, index):
     if self.shape and self.proName:
         setattr(self.shape, self.proName, self.getValue())
         ExInterFace.getCurrentBoard().repaint()
 def valueChangedSlot(self, value):
     if self.shape and self.proName:
         setattr(self.shape, self.proName, self.getValue())  # 为shape赋值
         ExInterFace.getCurrentBoard().repaint()
Example #17
0
 def cancelAllSelected(self):
     Board = ExInterFace.getCurrentBoard()
     for shape in MainPlugin.__shapes[Board.id]:
         shape.selected = False
Example #18
0
    def mouseReleaseEvent(self, QMouseEvent):

        Board = ExInterFace.getCurrentBoard()

        # 坐标转换 将鼠标坐标转换为 常用数学坐标
        mousePos = MainPlugin.translatePt(QMouseEvent.pos(), Board)

        matchedPt = self.getMatchedPoint(mousePos, Board)

        if QMouseEvent.button() == Qt.LeftButton:
            if MainPlugin.__state[Board.id] == MainPlugin.PAINT_LINE:
                #matchedPt = self.getMatchedPoint(mousePos, Board)
                MainPlugin.__painting_shape[Board.id] = ExLine(
                    matchedPt.x, matchedPt.y, mousePos.x, mousePos.y)
                MainPlugin.__state[Board.id] = MainPlugin.PAINTING_LINE
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_CIRCLE:
                MainPlugin.__painting_shape[Board.id] = ExCircle(
                    matchedPt.x, matchedPt.y, 0)
                MainPlugin.__assist_circle[Board.id].setVisible(False)
                MainPlugin.__state[Board.id] = MainPlugin.PAINTING_CIRCLE
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_ARC:
                MainPlugin.__painting_shape[Board.id] = ExArc()
                MainPlugin.__assist_line[Board.id] = ExLine()
                MainPlugin.__assist_line[Board.id].setPenStyle(Qt.DotLine)
                MainPlugin.__painting_shape[Board.id].setPt0(matchedPt)
                MainPlugin.__assist_line[Board.id].setPt0(matchedPt)
                MainPlugin.__state[Board.id] = MainPlugin.PAINTING_ARC0
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_ARC0:
                if matchedPt != MainPlugin.__painting_shape[Board.id].pt0:
                    MainPlugin.__state[Board.id] = MainPlugin.PAINTING_ARC1
                    MainPlugin.__painting_shape[Board.id].setPt1(matchedPt)
                    MainPlugin.__assist_line[Board.id].setPt1(matchedPt)
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_ARC1:
                if MainPlugin.__painting_shape[Board.id].isVisible(
                ) and not matchedPt == MainPlugin.__painting_shape[
                        Board.
                        id].pt0 and not matchedPt == MainPlugin.__painting_shape[
                            Board.id].pt1:
                    MainPlugin.__state[Board.id] = MainPlugin.PAINT_ARC
                    MainPlugin.__painting_shape[Board.id].setPt2(matchedPt)
                    MainPlugin.__shapes[Board.id].append(
                        MainPlugin.__painting_shape[Board.id])

                    #增加到go_back中
                    MainPlugin.addShapeCompeleted(
                        MainPlugin.__painting_shape[Board.id])

                    MainPlugin.__painting_shape[Board.id] = None
                    MainPlugin.__assist_line[Board.id] = None

            elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_CIRCLE:
                if MainPlugin.__painting_shape[Board.id]:
                    MainPlugin.__shapes[Board.id].append(
                        MainPlugin.__painting_shape[Board.id])
                    MainPlugin.__assist_circle[Board.id].setVisible(True)
                    MainPlugin.__assist_circle[Board.id].centerPt = matchedPt
                    # 增加到go_back中
                    MainPlugin.addShapeCompeleted(
                        MainPlugin.__painting_shape[Board.id])
                MainPlugin.__state[Board.id] = MainPlugin.PAINT_CIRCLE

            elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_LINE:
                if MainPlugin.__painting_shape[Board.id]:
                    MainPlugin.__shapes[Board.id].append(
                        MainPlugin.__painting_shape[Board.id])
                    # 增加到go_back中
                    MainPlugin.addShapeCompeleted(
                        MainPlugin.__painting_shape[Board.id])
                    MainPlugin.__painting_shape[Board.id] = None
                MainPlugin.__state[Board.id] = MainPlugin.PAINT_LINE

            elif MainPlugin.__state[Board.id] == MainPlugin.FREE:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.MOVING_BOARD:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.SELECT:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.HANDED:
                MainPlugin.__state[Board.id] = MainPlugin.HAND
            elif MainPlugin.__state[Board.id] == MainPlugin.MOVING_SHAPE:
                MainPlugin.__state[Board.id] = MainPlugin.SELECT  #鼠标松开 返回到选择状态
                MainPlugin.__hover_shape[Board.id] = None
        elif QMouseEvent.button() == Qt.RightButton:
            if MainPlugin.__state[Board.id] == MainPlugin.PAINT_LINE:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_CIRCLE:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_ARC:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_ARC0:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_CIRCLE:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_LINE:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.FREE:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.MOVING_BOARD:
                pass
            elif MainPlugin.__state[Board.id] == MainPlugin.SELECT:
                pass

        Board.repaint()
Example #19
0
 def actionChanged(self):
     ExInterFace.exclusive(self)
Example #20
0
    def mouseMoveEvent(self, QMouseEvent):
        Board = ExInterFace.getCurrentBoard()
        mousePos = MainPlugin.translatePt(QMouseEvent.pos(), Board)

        # 开了Tracking所以只要鼠标移动就会调用,不用按下左键

        # 检查 并设置悬停

        # 只有在选中模式下 才有shape的hover
        if MainPlugin.__state[Board.id] == MainPlugin.SELECT:
            self.checkHoverShape(mousePos, Board)

        #在绘制,绘制中,选中 都可以有 hover点和匹配
        # 原则是点到点 就不会点到shape
        if MainPlugin.__state[Board.id] < MainPlugin.SELECT:
            self.checkHoverPoint(mousePos, Board)
            self.checkMatch(mousePos, Board)

        #一定要在上面代码的后面
        matchedPt = self.getMatchedPoint(mousePos, Board)

        if MainPlugin.__state[Board.id] == MainPlugin.PAINT_LINE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_CIRCLE:
            if not MainPlugin.__assist_circle[Board.id]:
                MainPlugin.__assist_circle[Board.id] = ExCircle(matchedPt, 10)
                MainPlugin.__assist_circle[Board.id].setPenStyle(Qt.DotLine)
            MainPlugin.__assist_circle[Board.id].centerPt = matchedPt
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_ARC:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_ARC0:
            if MainPlugin.__assist_line[Board.id]:
                MainPlugin.__assist_line[Board.id].setPt1(matchedPt)
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_ARC1:
            if MainPlugin.__painting_shape[Board.id]:
                if not matchedPt == MainPlugin.__painting_shape[
                        Board.
                        id].pt0 and not matchedPt == MainPlugin.__painting_shape[
                            Board.id].pt1:
                    #MainPlugin.__painting_shape
                    MainPlugin.__painting_shape[Board.id].setPt2(matchedPt)
                    if not MainPlugin.__painting_shape[Board.id].calculate():
                        MainPlugin.__painting_shape[Board.id].setVisible(False)
                    else:
                        MainPlugin.__painting_shape[Board.id].setVisible(True)
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_CIRCLE:
            if MainPlugin.__painting_shape[Board.id]:
                #计算半径
                r = math.sqrt(
                    (matchedPt.x -
                     MainPlugin.__painting_shape[Board.id].centerPt.x)**2 +
                    (matchedPt.y -
                     MainPlugin.__painting_shape[Board.id].centerPt.y)**2)
                MainPlugin.__painting_shape[Board.id].r = r
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_LINE:
            if MainPlugin.__painting_shape[Board.id]:
                #matchedPt = self.getMatchedPoint(mousePos, Board)
                MainPlugin.__painting_shape[Board.id].setPt1(
                    matchedPt.x, matchedPt.y)
        elif MainPlugin.__state[Board.id] == MainPlugin.FREE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.MOVING_BOARD:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.HANDED:
            MainPlugin.__origin_position[Board.id].x += (
                QMouseEvent.pos().x() -
                MainPlugin.__hand_start_pt[Board.id].x) / MainPlugin.unit_pixel
            MainPlugin.__origin_position[Board.id].y -= (
                QMouseEvent.pos().y() -
                MainPlugin.__hand_start_pt[Board.id].y) / MainPlugin.unit_pixel
            MainPlugin.__hand_start_pt[Board.id].x = QMouseEvent.pos().x()
            MainPlugin.__hand_start_pt[Board.id].y = QMouseEvent.pos().y()
        elif MainPlugin.__state[Board.id] == MainPlugin.MOVING_SHAPE:
            #直接修改 hover_pt的值
            MainPlugin.__changing_pt[Board.id].x = matchedPt.x
            MainPlugin.__changing_pt[Board.id].y = matchedPt.y

            if not MainPlugin.__changing_pt[
                    Board.id].parent.calculate():  #需要间接计算一下
                MainPlugin.__changing_pt[Board.id].parent.setVisible(False)
            else:
                MainPlugin.__changing_pt[Board.id].parent.setVisible(True)

        Board.repaint()
Example #21
0
#-*- encoding:utf-8 -*-
import sys
from PyQt5.QtWidgets import QApplication
import PyQt5.sip
from business import MainWindow, ExInterFace

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mw = MainWindow()
    ExInterFace.init(mw)
    ExInterFace.addBorad("new")
    mw.showMaximized()
    sys.exit(app.exec())
Example #22
0
 def boardSwitched(self, curindex):
     Board = ExInterFace.getCurrentBoard()
     MainPlugin.__state[Board.id] = self.getCurrentSelectedState()
Example #23
0
    def paintEvent(self, QPaintEvent):
        Board = ExInterFace.getCurrentBoard()
        painter = QPainter(Board)
        painter.setRenderHint(QPainter.Antialiasing, True)  #打开反走样
        #在坐标转换之前先绘制文字

        #坐标系转换为 y朝上和x朝右的通用数学坐标系
        painter.setWindow(0, Board.height(), Board.width(), -Board.height())
        painter.translate(
            MainPlugin.__origin_position[Board.id].x * MainPlugin.unit_pixel,
            MainPlugin.__origin_position[Board.id].y * MainPlugin.unit_pixel)
        painter.scale(MainPlugin.__scale[Board.id],
                      MainPlugin.__scale[Board.id])

        #绘制十字原点
        MainPlugin.__origin_cross.drawIt(painter, MainPlugin.__scale[Board.id])

        #绘制图形
        for shape in MainPlugin.__shapes[Board.id]:
            shape.draw(painter, MainPlugin)

        if MainPlugin.__state[
                Board.id] <= MainPlugin.PAINTING_CIRCLE and MainPlugin.__state[
                    Board.id] >= MainPlugin.PAINTING_LINE:
            #绘制正在绘制的图形
            if MainPlugin.__painting_shape[Board.id]:
                MainPlugin.__painting_shape[Board.id].draw(painter, MainPlugin)

        if MainPlugin.__state[Board.id] == MainPlugin.PAINT_LINE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_CIRCLE:
            # 在绘制圆的时候使用
            if MainPlugin.__assist_circle[Board.id]:
                MainPlugin.__assist_circle[Board.id].draw(painter, MainPlugin)
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINT_ARC:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_ARC0:
            if MainPlugin.__assist_line[Board.id]:
                MainPlugin.__assist_line[Board.id].draw(painter, MainPlugin)
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_ARC1:
            if MainPlugin.__assist_line[Board.id]:
                MainPlugin.__assist_line[Board.id].draw(painter, MainPlugin)
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_CIRCLE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.PAINTING_LINE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.FREE:
            pass
        elif MainPlugin.__state[Board.id] == MainPlugin.MOVING_BOARD:
            pass

        if MainPlugin.__state[Board.id] == MainPlugin.SELECT:
            if MainPlugin.__hover_shape[Board.id]:
                MainPlugin.__hover_shape[Board.id].draw(painter, MainPlugin)

        if MainPlugin.__state[
                Board.id] >= MainPlugin.PAINT_LINE and MainPlugin.__state[
                    Board.id] <= MainPlugin.MOVING_SHAPE:

            # 绘制悬停对象
            if MainPlugin.__hover_point[Board.id]:
                MainPlugin.__hover_point[Board.id].draw(painter, MainPlugin)

            # 绘制 匹配到的虚线
            vLine = None
            hLine = None
            if MainPlugin.__matched_x[Board.id]:
                vLine = FreeLine(MainPlugin.__matched_x[Board.id], 0,
                                 MainPlugin.__matched_x[Board.id],
                                 Board.height())
            if MainPlugin.__matched_y[Board.id]:
                hLine = FreeLine(0, MainPlugin.__matched_y[Board.id],
                                 Board.width(),
                                 MainPlugin.__matched_y[Board.id])
            if vLine:
                vLine.draw(painter, MainPlugin)
            if hLine:
                hLine.draw(painter, MainPlugin)
Example #24
0
from business import ExInterFace
from .MainPlugin import MainPlugin

mp = MainPlugin("PhaseArray")
ExInterFace.register(mp)
Example #25
0
 def addShapeCompeleted(shape):
     board = ExInterFace.getCurrentBoard()
     MainPlugin.__go_back_stack[board.id].append([shape,
                                                  "add"])  #用shape对象自身来索引