프로젝트

일반

사용자정보

개정판 f2b6c353

IDf2b6c35384db60dcd791cc2e4bbff8e6f9b0d261
상위 771eb98a
하위 b83baa12, 03940dd1

백흠경이(가) 3년 이상 전에 추가함

issue #1652: SymbolSvgItem에 flip_symbol 함수 추가

Change-Id: If1b4dc1348d60f18214d63798249825a11d82bda

차이점 보기:

HYTOS/HYTOS/Shapes/SymbolSvgItem.py
80 80
        self.category = ''
81 81
        self.type = ''
82 82
        self.angle = 0
83
        self._scaleX = 1
84
        self._scaleY = 1
83
        self._scales = [1, 1]
85 84
        self.origin = None
86 85
        self.loc = None
87 86
        self.size = None
......
244 243

  
245 244
        return res
246 245

  
247
    def buildItem(self, name, _type, angle, scaleX, scaleY, loc, origin, connPts, dbUid=None, pointsUids=None, index=None):
246
    def buildItem(self, name, _type, angle, scales: list, loc, origin, connPts, dbUid=None, pointsUids=None, index=None):
248 247
        """build symbol item"""
249 248

  
250 249
        from App import App
......
264 263
            self.index = index
265 264
            self.type = _type
266 265
            self.angle = angle
267
            self._scaleX = scaleX
268
            self._scaleY = scaleY
266
            self._scales = scales
269 267
            self.loc = loc
270 268

  
271 269
            app_doc_data = AppDocData.instance()
......
1745 1743
            y = componentInfos[0]['Comp_Y']  # Y@Components
1746 1744
            angle = componentInfos[0]['Rotation']  # Rotation@Components
1747 1745
            #scale = componentInfos[0]['Scale']  # Scale@Components
1748
            scaleX = componentInfos[0]['ScaleX']  # ScaleX@Components
1749
            scaleY = componentInfos[0]['ScaleY']  # ScaleY@Components
1746
            scales = [float(componentInfos[0]['ScaleX'], float(componentInfos[0]['ScaleY']))  # scale x, scale y
1750 1747

  
1751 1748
            pt = []
1752 1749
            pt.append(float(x))
......
1763 1760

  
1764 1761
            item = SymbolSvgItem.createItem(_type, uid, None, 0, dbUid)
1765 1762
            item.setVisible(False)
1766
            item.buildItem(name, _type, float(angle), scaleX,scaleY , pt, origin, connPts, dbUid, pointsUids, index)
1763
            item.buildItem(name, _type, float(angle), scales , pt, origin, connPts, dbUid, pointsUids, index)
1767 1764
            item.tag_no = tag_no
1768 1765
            item.build_label()
1769 1766

  
......
1922 1919

  
1923 1920
    def addSvgItemToScene(self, scene):
1924 1921
        """add svg item to scene"""
1925
        self.setScale(self._scaleX)
1926
        # scale down for label
1927
        for conn, label in self.desc_labels.items():
1928
            label.setScale(1 / self._scaleX)
1929
        # up to here
1922
        
1923
        try:
1924
            scene.addItem(self)
1925
            self.setTransformOriginPoint(QPointF(self.symbolOrigin[0], self.symbolOrigin[1]))  # affect only to rotation
1926
            trans = QTransform()
1927
            trans.scale(self._scales[0], self._scales[1])
1928
            self.setTransform(trans)
1929
            self.rotate(self.angle)
1930
            pt = trans.map(self.symbolOrigin[0], self.symbolOrigin[1])
1931
            self.setPos(self.origin[0] - pt[0], self.origin[1] - pt[1])
1932
            
1933
            # scale down for label
1934
            trans = QTransform()
1935
            trans.scale(1/ self._scales[0], 1 / self._scales[1])
1936
            for conn, label in self.desc_labels.items():
1937
                label.setTransform(trans)
1938
            # up to here
1939
        except Exception as ex:
1940
            from App import App
1941
            from AppDocData import MessageType
1930 1942

  
1931
        transform = QTransform()
1932
        transform.translate(self.loc[0] + self.symbolOrigin[0], self.loc[1] + self.symbolOrigin[1])
1933
        transform.rotateRadians(-self.angle)
1934
        transform.translate(-self.symbolOrigin[0], -self.symbolOrigin[1])
1935
        self.setTransform(transform)
1936
        scene.addItem(self)
1943
            message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
1944
                      f"{sys.exc_info()[-1].tb_lineno}"
1945
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1937 1946

  
1938 1947
    '''
1939 1948
        @brief      
......
1972 1981
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1973 1982

  
1974 1983
        self.transfer.onRemoved.emit(self)
1984
        
1985
    def flip_symbol(self, horizontal=True) -> None:
1986
        """flip symbol"""
1987
        trans = self.transform()
1988
        rect = self.boundingRect()
1989
        if horizontal:    # horizontal flip
1990
            trans.scale(-1, 1)
1991
            trans.translate(-rect.width(), 0)
1992
        else:  # vertical flip
1993
            trans.scale(1, -1)
1994
            trans.translate(0, -rect.height())
1975 1995

  
1976
    '''
1977
        @brief      get standard point
1978
        @author     kyouho
1979
        @date       2018.07.25
1980
    '''
1996
        self.resetTransform()
1997
        self.setTransform(trans)
1981 1998

  
1982 1999
    def getCurrentPoint(self):
2000
        """get current point"""
1983 2001

  
1984 2002
        pointList = []
1985 2003
        pointList.append(self.symbolOrigin)

내보내기 Unified diff