개정판 8a0b11c0
issue #610: 라인의 flow direction을 바꿀때 연결된 아이템의 flow direction도 함께 바꾸도록 개선
Change-Id: Ie93439b0edd2d4a6c3ffe82b7b1649536fa9ea90
DTI_PID/DTI_PID/Shapes/EngineeringLineItem.py | ||
---|---|---|
594 | 594 |
def is_piping(self, strong=False): |
595 | 595 |
""" return true if piping line """ |
596 | 596 |
if strong: |
597 |
return (self._lineType == 'Primary' or self._lineType == 'Secondary')
|
|
597 |
return self._lineType == 'Primary' or self._lineType == 'Secondary'
|
|
598 | 598 |
else: |
599 |
return (self._lineType == 'Primary' or self._lineType == 'Secondary' or self._lineType == 'Connect To Process') |
|
599 |
return self._lineType == 'Primary' or self._lineType == 'Secondary' or \ |
|
600 |
self._lineType == 'Connect To Process' |
|
600 | 601 |
|
601 | 602 |
''' |
602 | 603 |
@brief check if two lines are extendable |
... | ... | |
745 | 746 |
if conn.isOverlapConnector(connector): |
746 | 747 |
conn.connectedItem = None |
747 | 748 |
|
748 |
def arrange_flow_direction(self, _from): |
|
749 |
def arrange_flow_direction(self, _from, reverse=False):
|
|
749 | 750 |
""" reverse if from is connected to second connector """ |
750 |
if not _from: raise ValueError |
|
751 |
if not _from: |
|
752 |
raise ValueError |
|
751 | 753 |
|
752 |
if self.connectors[1].connectedItem == _from: self.reverse() |
|
754 |
if not reverse and self.connectors[0].connectedItem != _from: |
|
755 |
self.reverse() |
|
756 |
elif reverse and self.connectors[1].connectedItem != _from: |
|
757 |
self.reverse() |
|
753 | 758 |
|
754 |
''' |
|
755 |
@brief reverse line |
|
756 |
@author humkyung |
|
757 |
@date 2018.07.03 |
|
758 |
''' |
|
759 |
def find_connected_objects(self): |
|
760 |
"""find all connected items except equipment and instrument""" |
|
761 |
from EngineeringLineItem import QEngineeringLineItem |
|
762 |
from EngineeringEquipmentItem import QEngineeringEquipmentItem |
|
763 |
from EngineeringInstrumentItem import QEngineeringInstrumentItem |
|
764 |
from SymbolSvgItem import SymbolSvgItem |
|
765 |
|
|
766 |
left_visited, right_visited = [self], [self] |
|
767 |
|
|
768 |
try: |
|
769 |
left_pool, right_pool = [self.connectors[0].connectedItem] if self.connectors[0].connectedItem else [], \ |
|
770 |
[self.connectors[1].connectedItem] if self.connectors[1].connectedItem else [] |
|
771 |
|
|
772 |
while left_pool: |
|
773 |
obj = left_pool.pop() |
|
774 |
|
|
775 |
if issubclass(type(obj), QEngineeringEquipmentItem) or (len(obj.connectors) > 2): |
|
776 |
continue |
|
777 |
|
|
778 |
left_visited.append(obj) |
|
779 |
|
|
780 |
if (type(obj) is QEngineeringLineItem and self.is_piping(True)) or issubclass(type(obj), SymbolSvgItem): |
|
781 |
founds = [conn.connectedItem for conn in obj.connectors if |
|
782 |
conn.connectedItem and conn.connectedItem not in left_visited and |
|
783 |
2 == len(conn.connectedItem.connectors)] |
|
784 |
for found in founds: |
|
785 |
matches = [conn.connectedItem for conn in found.connectors if conn.connectedItem is obj] |
|
786 |
if matches: |
|
787 |
left_pool.append(found) |
|
788 |
|
|
789 |
while right_pool: |
|
790 |
obj = right_pool.pop() |
|
791 |
|
|
792 |
if issubclass(type(obj), QEngineeringEquipmentItem) or (len(obj.connectors) > 3): |
|
793 |
continue |
|
794 |
|
|
795 |
right_visited.append(obj) |
|
796 |
|
|
797 |
if (type(obj) is QEngineeringLineItem and self.is_piping(True)) or issubclass(type(obj), SymbolSvgItem): |
|
798 |
founds = [conn.connectedItem for conn in obj.connectors if |
|
799 |
conn.connectedItem and conn.connectedItem not in right_visited and |
|
800 |
2 == len(conn.connectedItem.connectors)] |
|
801 |
for found in founds: |
|
802 |
matches = [conn.connectedItem for conn in found.connectors if conn.connectedItem is obj] |
|
803 |
if matches: |
|
804 |
right_pool.append(found) |
|
805 |
except Exception as ex: |
|
806 |
from App import App |
|
807 |
from AppDocData import MessageType |
|
808 |
|
|
809 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
810 |
sys.exc_info()[-1].tb_lineno) |
|
811 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
812 |
|
|
813 |
return left_visited, right_visited |
|
814 |
|
|
815 |
def reverse(self, auto=False): |
|
816 |
"""revere the line""" |
|
817 |
from EngineeringLineItem import QEngineeringLineItem |
|
818 |
from SymbolSvgItem import SymbolSvgItem |
|
759 | 819 |
|
760 |
def reverse(self): |
|
761 | 820 |
line = self.line() |
762 | 821 |
self.setLine(QLineF(line.p2(), line.p1())) |
763 | 822 |
self.connectors[0], self.connectors[1] = self.connectors[1], self.connectors[0] |
764 | 823 |
self.update_arrow() |
765 | 824 |
self.update() |
766 | 825 |
|
826 |
if auto: |
|
827 |
left, right = self.find_connected_objects() |
|
828 |
|
|
829 |
if left: |
|
830 |
connected_item = self |
|
831 |
for obj in left[1:]: |
|
832 |
if type(obj) is QEngineeringLineItem: |
|
833 |
obj.arrange_flow_direction(connected_item, True) |
|
834 |
|
|
835 |
connected_item = obj |
|
836 |
|
|
837 |
if right: |
|
838 |
connected_item = self |
|
839 |
for obj in right[1:]: |
|
840 |
if type(obj) is QEngineeringLineItem: |
|
841 |
obj.arrange_flow_direction(connected_item) |
|
842 |
|
|
843 |
connected_item = obj |
|
844 |
|
|
767 | 845 |
''' |
768 | 846 |
@brief add flow arrow |
769 | 847 |
@author humkyung |
... | ... | |
1253 | 1331 |
def keyPressEvent(self, event): |
1254 | 1332 |
if self.isSelected() and event.key() == Qt.Key_Delete: |
1255 | 1333 |
self.scene().removeItem(self) |
1256 |
elif event.key() == Qt.Key_C: |
|
1257 |
self.reverse() |
|
1334 |
elif event.key() == Qt.Key_C and self.is_piping(True):
|
|
1335 |
self.reverse(True)
|
|
1258 | 1336 |
elif event.key() == Qt.Key_A: |
1259 | 1337 |
self.toggleFlowMark() |
1260 | 1338 |
|
내보내기 Unified diff