Exemplo n.º 1
0
    def createWidgets(self):
        logging.debug("In ProtractorAction::createWidgets()")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(
            ":/static/default/icon/48x48/transferidor.png"),
            QtGui.QIcon.Normal, QtGui.QIcon.Off)

        self.actionProtractor = QtGui.QAction(self.parent())
        self.actionProtractor.setCheckable(True)
        self.actionProtractor.setIcon(icon)
        self.actionProtractor.setObjectName("actionProtractor")
        self.actionProtractor.setText(
            QtGui.QApplication.translate("ProtractorAction", "&Protractor",
                                         None, QtGui.QApplication.UnicodeUTF8))

        self.parent().menuTools.addAction(self.actionProtractor)
        self.parent().toolBarTools.addAction(self.actionProtractor)

        parentProperties = self.parent().scrollAreaWidgetContents

        self.propertiesAction = ProtractorProperties(parentProperties)
        parentProperties.layout().addWidget(self.propertiesAction)
        self.propertiesAction.hide()
Exemplo n.º 2
0
class ProtractorAction(QtCore.QObject):

    def __init__(self, ilsa):
        logging.debug("In ProtractorAction::__init__()")
        super(ProtractorAction, self).__init__(ilsa.parentWidget())
        self._ilsa = ilsa
        self.protractor = None
        self._mouseEvent = 0
        self.createWidgets()
        self.createActions()
        self.propertiesAction.connect(self.propertiesAction.newProtractorButton,
                                QtCore.SIGNAL("clicked ( bool)"),
                                self.slotNewProtractor)
        self.propertiesAction.connect(self.propertiesAction.deleteProtractorButton,
                                QtCore.SIGNAL("clicked ( bool)"),
                                self.slotDeleteProtractor)

    def createWidgets(self):
        logging.debug("In ProtractorAction::createWidgets()")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(
            ":/static/default/icon/48x48/transferidor.png"),
            QtGui.QIcon.Normal, QtGui.QIcon.Off)

        self.actionProtractor = QtGui.QAction(self.parent())
        self.actionProtractor.setCheckable(True)
        self.actionProtractor.setIcon(icon)
        self.actionProtractor.setObjectName("actionProtractor")
        self.actionProtractor.setText(
            QtGui.QApplication.translate("ProtractorAction", "&Protractor",
                                         None, QtGui.QApplication.UnicodeUTF8))

        self.parent().menuTools.addAction(self.actionProtractor)
        self.parent().toolBarTools.addAction(self.actionProtractor)

        parentProperties = self.parent().scrollAreaWidgetContents

        self.propertiesAction = ProtractorProperties(parentProperties)
        parentProperties.layout().addWidget(self.propertiesAction)
        self.propertiesAction.hide()
    
    def uncheck(self, actionType):
        logging.debug("In ProtractorAction::uncheck()")
        if self.actionProtractor.isChecked():
            self.actionProtractor.setChecked(False)
            self.slotActionProtractor()

    def createActions(self):
        logging.debug("In ProtractorAction::createActions()")
        self.connect(self.actionProtractor, QtCore.SIGNAL("triggered()"),
                     self.slotActionProtractor)

    def slotActionProtractor(self):
        logging.debug("In ProtractorAction::slotActionProtractor()")
        if not self.actionProtractor.isChecked():
            self.propertiesAction.hide()
            self.parent().toolProperties.setVisible(False)
            if self.protractor:
                if self.protractor.status != 3:
                    self.desactivateProtactor()
            return
        self._ilsa.desactivateOthers("angle")
        self.parent().toolProperties.setVisible(True)
        self.propertiesAction.show()    
        if not self.protractor:   
            self.newProtactor()
            
    def slotNewProtractor(self, checked):
        logging.debug("In ProtractorAction::slotNewProtractor()")
        if self.protractor:
            if self.protractor.status != 3:
                return
        self.newProtactor()

    def newProtactor(self):
        logging.debug("In ProtractorAction::newProtactor()")
        self.protractor = Protractor()
        self.propertiesAction.addProtractor(self.protractor)
        self.scenesMap = {}
        self._mouseEvents = {}
        for scene in self._ilsa.scenes():
            if isinstance(scene, VtkImagePlane):
                self._mouseEvents[scene] = scene.addObserver("MouseMoveEvent", self.activateProtractor)
                self.scenesMap[scene.interactorStyle] = scene

    def slotDeleteProtractor(self, checked):
        logging.debug("In ProtractorAction::slotDeleteProtractor()")
        self.protractor.desactivate()
        if self._mouseEvents:
            for scene in self._ilsa.scenes():
                if isinstance(scene, VtkImagePlane):
                    scene.removeObserver(self._mouseEvents[scene])
            self._mouseEvents = {}
        self.protractor = self.propertiesAction.removeSelectedProtractor()

    def desactivateProtactor(self):
        logging.debug("In ProtractorAction::desactivateProtactor()")
        self.protractor.desactivate()
        if self._mouseEvents:
            for scene, observer in self._mouseEvents.items():
                scene.removeObserver(observer)
        self.slotDeleteProtractor(True)
        
    def activateProtractor(self, obj, evt):
        logging.debug("In ProtractorAction::activateProtractor()")
        if not self.protractor.started():
            scene = self.scenesMap[obj]
            self.protractor.scene = scene
        else:
            for scene in self._ilsa.scenes():
                if isinstance(scene, VtkImagePlane):
                    scene.removeObserver(self._mouseEvents[scene])
            self._mouseEvents = {}
    
    def removeScene(self, scene):
        logging.debug("In ProtractorAction::removeScene()")
        self.propertiesAction.removeScene(scene)