Ejemplo n.º 1
0
     def __mouseReleaseEvent_ToolSelNone():
         
         X = coord.x()
         Y = coord.y()
         px_mousePressedAt_X = self.rootContainer.get("px_mousePressedAt_X")
         px_mousePressedAt_Y = self.rootContainer.get("px_mousePressedAt_Y")
         if px_mousePressedAt_X != sys.maxint and px_mousePressedAt_Y != sys.maxint: 
             polygons = [[(X,Y), (X,px_mousePressedAt_Y ), (px_mousePressedAt_X,px_mousePressedAt_Y),(px_mousePressedAt_X,Y)]]
             for key in keys:
                 element = self.activeGraphics.getb(key)
                 if element.isAttr("Shape"):
                     bFocus = True
                     shape = element.get("Shape")
                     X_obj = element.X
                     Y_obj = element.Y
 
                     for polygon in shape:
                         if polygon != None:
                             for point in polygon:
                                 idxCorner = helper.point_inside_polygon(X_obj + point[0], Y_obj + point[1],polygons)
                                 if len(idxCorner) == 0:
                                     bFocus = False
                     if bFocus:
                         objectsInFocus = list(self.activeGraphics.objectsInFocus )
                         objectsInFocus.append(element)
                         self.activeGraphics.objectsInFocus = objectsInFocus
         self.activeGraphics.set("ConnectorToModify", None )
         self.activeGraphics.set("idxPointModified" , None )              
Ejemplo n.º 2
0
        def __mouseReleaseEvent_ToolSelNone():
            
            X = coord.x()
            Y = coord.y()
            px_mousePressedAt_X = self.mainController.get(u"px_mousePressedAt_X")
            px_mousePressedAt_Y = self.mainController.get(u"px_mousePressedAt_Y")
            objectsInFocus = []   
            if px_mousePressedAt_X != sys.maxint and px_mousePressedAt_Y != sys.maxint: 
                polygons = [[(X,Y), (X,px_mousePressedAt_Y ), (px_mousePressedAt_X,px_mousePressedAt_Y),(px_mousePressedAt_X,Y)]]
                keys = self.activeGraphics.getChildKeys()  
                for key in keys:
                    element = self.activeGraphics.getb(key)
                    if element.isAttr(u"Shape"):
                        bFocus = True
                        shape = element.get(u"Shape")

                        for polygon in shape:
                            if polygon != None:
                                for point in polygon:
                                    idxCorner = helper.point_inside_polygon(point[0], point[1],polygons)
                                    if len(idxCorner) == 0:
                                        bFocus = False
                        if bFocus:
                            if element.get(u"bUnlock"):
                                objectsInFocus.append(element)
            
            command = u"select "
            for element in objectsInFocus:
                command += ( element.get("Name") + u" ")
            if len(objectsInFocus) > 0:
                self.mainController.execCommand(command)
Ejemplo n.º 3
0
        def bDialogue(X, Y, strShape, element):
            bDialog = False
            shape = element.get(strShape)

            if shape != None:
                idxPolygon = helper.point_inside_polygon(X, Y, shape)
                bDialog = not (len(idxPolygon) == 0)
            return bDialog
 def bDialogue(X,Y,strShape, element):
     bDialog = False
     shape = element.get(strShape)
    
     if shape != None:
         idxPolygon = helper.point_inside_polygon(X , Y,shape)
         bDialog = not (len(idxPolygon) == 0)
     return bDialog
Ejemplo n.º 5
0
 def mouseDoubleClickEvent(self, coord):
     
     bSimulationMode = self.rootContainer.get("bSimulationMode")
     if not bSimulationMode:
         bConnectorPloting = self.rootGraphics.get("bConnectorPloting")
         if bConnectorPloting: 
             keys = self.activeGraphics.getChildKeys()
             for key in keys:        
                 element = self.activeGraphics.getb(key)
                 types = inspect.getmro(type(element))
                 if PyLinXDataObjects.PX_PlottableProxyElement in types:
                     self.activeGraphics.delete(key)
                     break
             ConnectorPloting = self.rootGraphics.get("ConnectorPloting")
             self.activeGraphics.delete( ConnectorPloting.ID )
             self.rootGraphics.set("bConnectorPloting", False)
             self.rootContainer.set("idxToolSelected", helper.ToolSelected.none)
             self.repaint()
             
     else:
         X = coord.x()
         Y = coord.y()
         keys = self.activeGraphics.getChildKeys()
         for key in keys:
             element = self.activeGraphics.getb(key)
             types = inspect.getmro(type(element))
             bFocus = False
             if PyLinXDataObjects.PX_PlotableVarElement in types:
                 Shape_stim = element.get("Shape_stim")
                 if Shape_stim != None:
                     idxPolygon = helper.point_inside_polygon(X , Y,Shape_stim)
                     print idxPolygon
                     bFocus = not (len(idxPolygon) == 0)
                     if bFocus:
                         break
         if bFocus:
             values = PX_Dialogue_SimpleStimulate.getParams(self, element, self)          
             print values
Ejemplo n.º 6
0
        def mousePressEvent_tool_none():

            objInFocusOld = list(self.mainController.selection)
            objInFocus = self.activeGraphics.getObjectInFocus(coord)

            # Create HighlightObject if necessary.
            #  This is not done by command since
            #  the highlight rect is not considered
            #  to be part of the data
            # selecting clicked element by command
            #######################################

            len_objectsInFocus = len(objInFocus)
            if len(set(objInFocus).intersection(set(objInFocusOld))) == 0:
                if len_objectsInFocus == 0:
                    if len(self.mainController.selection) > 0:
                        self.mainController.execCommand(u"select")
                    PyLinXCoreDataObjects.PX_LatentPlottable_HighlightRect(
                        self.latentGraphics, coord.x(), coord.y())
                else:
                    if set(objInFocus) != set(self.mainController.selection):
                        usttObj = [obj.get(u"Name") for obj in objInFocus]
                        self.mainController.execCommand(u"select " +
                                                        u" ".join(usttObj))

            # move lines of connectors
            ##########################

            # Detect index of line to modify and save it in active graphics
            if len_objectsInFocus == 1:
                activeObject = objInFocus[0]
                if activeObject.isAttr(u"listPoints"):
                    objectInFocus = objInFocus[0]
                    shape = objectInFocus.get(u"Shape")
                    idxPolygons = helper.point_inside_polygon(x, y, shape)
                    if len(idxPolygons) == 1:
                        idxPolygon = idxPolygons[0]
                        if idxPolygon > 0:
                            # not sent via ustr-Command, since this information is only cached at the mainController
                            # for the final command. No data is changed here.
                            _id = unicode(activeObject.ID)
                            self.mainController.set(
                                u"ConnectModInfo",
                                (_id + u"_id" + _id, idxPolygon - 1))
                            return

            # Connecting Elements
            #####################

            # connecting has been started yet
            if self.mainController.bConnectorPloting:
                keys = self.activeGraphics.getChildKeys()
                objInFocus = None
                for key in keys:
                    element = self.activeGraphics.getb(key)
                    types = inspect.getmro(type(element))
                    if PyLinXCoreDataObjects.PX_PlottableElement in types and element.get(
                            u"bUnlock"):
                        objInFocus, idxPin = element.isPinInFocus(x, y)
                        if objInFocus != None:
                            if len(idxPin) == 1:
                                idxPin = idxPin[0]
                            break

                # case connecting of elements is not finished yet. No second Element has been clicked
                if objInFocus == None:
                    strVal = repr((x, y)).replace(u" ", u"")
                    strCommand_xy = u"@latent set ./PX_PlottableProxyElement.xy " + strVal
                    self.mainController.execCommand(strCommand_xy)

                # Case connecting of elements is finished. Second Element is clicked
                else:
                    # idxPin determined as the index of Pins in focus
                    setIdxConnectedInPins = objInFocus.get(
                        u"setIdxConnectedInPins")
                    if not (idxPin in setIdxConnectedInPins):
                        ConnectorPloting = self.mainController.get(
                            u"ConnectorPloting")
                        connectorName = ConnectorPloting.get(u"Name")
                        ustrCommand = u"@latent set ./" + connectorName + ".connectInfo (\"" + objInFocus.get(
                            u"Name") + u"\"," + unicode(idxPin) + u")"
                        self.mainController.execCommand(ustrCommand)

            # connecting has not been started yet
            else:
                # Starting connecting Elements
                keys = self.activeGraphics.getChildKeys()
                for key in keys:
                    element = self.activeGraphics.getb(key)
                    types = inspect.getmro(type(element))
                    if (PyLinXCoreDataObjects.PX_PlottableElement in types) \
                                and element.get(u"bUnlock"):
                        objInFocus, idxPin = element.isPinInFocus(x, y)
                        if len(idxPin) > 0:
                            idxPin = idxPin[0]
                        if objInFocus != None and (idxPin > -1):
                            strCommand = u"@latent new connector " + unicode(
                                element.ID
                            ) + u" idxOutPinConnectorPloting=" + unicode(
                                idxPin)
                            self.mainController.execCommand(strCommand)
        def mousePressEvent_tool_none():

            objInFocusOld = list(self.mainController.selection)
            objInFocus = self.activeGraphics.getObjectInFocus(coord)
            
            # Create HighlightObject if necessary.
            #  This is not done by command since
            #  the highlight rect is not considered
            #  to be part of the data
            # selecting clicked element by command
            #######################################
            
            len_objectsInFocus  = len(objInFocus)
            if len(set(objInFocus).intersection(set(objInFocusOld))) == 0:
                if len_objectsInFocus == 0:
                    if len(self.mainController.selection) > 0:
                        self.mainController.execCommand(u"select")
                    PyLinXDataObjects.PX_LatentPlottable_HighlightRect(self.latentGraphics,coord.x(), coord.y())
                else:
                    if set(objInFocus) != set(self.mainController.selection):                
                        usttObj = [obj.get("Name") for obj in objInFocus]
                        self.mainController.execCommand(u"select " + u" ".join(usttObj)) 
                

                    
            # move lines of connectors
            ##########################
            
            # Detect index of line to modify and save it in active graphics
            if len_objectsInFocus == 1:
                activeObject = objInFocus[0]
                if activeObject.isAttr(u"listPoints"):
                    listPoints = list(activeObject.get(u"listPoints"))
                    objectInFocus = objInFocus[0]
                    shape = objectInFocus.get(u"Shape")
                    elem0 = objectInFocus.elem0
                    idxPolygons = helper.point_inside_polygon(x, y, shape)
                    if len(idxPolygons) == 1:
                        idxPolygon = idxPolygons[0]
                        if idxPolygon > 0:
                            # not sent via ustr-Command, since this information is only cached at the mainController
                            # for the final command. No data is changed here.
                            self.mainController.set(u"ConnectModInfo", (activeObject.get("ID") ,idxPolygon - 1 ))
                            return 
                            
            # Connecting Elements
            #####################
            
            bConnectorPloting = self.mainController.get(u"bConnectorPloting")
            # connecting has been started yet
            if bConnectorPloting:
                # Determining if there is a endpoint in focus
                keys = self.activeGraphics.getChildKeys()
                objInFocus = None
                for key in keys:
                    element = self.activeGraphics.getb(key)
                    types = inspect.getmro(type(element))
                    if PyLinXDataObjects.PX_PlottableElement in types and element.get(u"bUnlock"): 
                        objInFocus, idxPin = element.isPinInFocus(x,y)
                        if objInFocus != None:
                            if len(idxPin) == 1:
                                idxPin = idxPin[0]
                            break  
                
                # case connecting of elements is not finished yet. No second Element has been clicked
                if objInFocus == None:                    
                    strVal = repr((x,y)).replace(u" ", u"")
                    #strCommand_xy = u"set ./PX_PlottableProxyElement.xy " + strVal
                    strCommand_xy = u"set @latent/PX_PlottableProxyElement.xy " + strVal
                    self.mainController.execCommand(strCommand_xy)
                
                # Case connecting of elements is finished. Second Element is clicked
                else:
                    # idxPin determined as the index of Pins in focus
                    setIdxConnectedInPins = objInFocus.get(u"setIdxConnectedInPins")
                    #print "setIdxConnectedInPins: ", setIdxConnectedInPins 
                    if not (idxPin in setIdxConnectedInPins):
                        ConnectorPloting = self.mainController.get(u"ConnectorPloting")
                        connectorName = ConnectorPloting.get(u"Name")
                        #ustrCommand = u"set ./" + connectorName + ".connectInfo (\"" + objInFocus.get(u"Name") + u"\"," + unicode(idxPin) + u")"
                        ustrCommand = u"set @latent/" + connectorName + ".connectInfo (\"" + objInFocus.get(u"Name") + u"\"," + unicode(idxPin) + u")"
                        self.mainController.execCommand(ustrCommand)
                                               
            # connecting has not been started yet
            else:
                # Starting connecting Elements
                keys = self.activeGraphics.getChildKeys()
                for key in keys:
                    element = self.activeGraphics.getb(key)
                    types = inspect.getmro(type(element))
                    if (PyLinXDataObjects.PX_PlottableElement in types) \
                                and element.get(u"bUnlock"):
                        objInFocus, idxPin = element.isPinInFocus(x,y)
                        if len(idxPin) > 0:
                            idxPin = idxPin[0]                         
                        if objInFocus != None and (idxPin > -1):
                            strCommand = u"new connector " + unicode( element.ID ) + u" idxOutPinConnectorPloting=" + unicode(idxPin)
                            self.mainController.execCommand(strCommand)
Ejemplo n.º 8
0
        def mousePressEvent_tool_none():
            objInFocusOld = list(self.activeGraphics.objectsInFocus)
            #objInFocus = self.activeGraphics.getObjectInFocus(X,Y)
            objInFocus = self.activeGraphics.getObjectInFocus(coord)
            if len(set(objInFocus).intersection(set(objInFocusOld))) > 0:
                pass
            else:      
                self.activeGraphics.objectsInFocus = objInFocus
                if len(objInFocus) == 0:
                    highlightObject = PyLinXDataObjects.PX_LatentPlottable_HighlightRect(coord.x(), coord.y())
                    self.activeGraphics.paste(highlightObject)
                    
            # move lines of connectors
            len_objectsInFocus  = len(objInFocus)
            if len_objectsInFocus == 1:
                activeObject = objInFocus[0]
                if activeObject.isAttr("listPoints"):
                    listPoints = list(activeObject.get("listPoints"))
                    objectInFocus = objInFocus[0]
                    shape = objectInFocus.get("Shape")
                    elem0 = objectInFocus.elem0
                    X_obj = elem0.X
                    Y_obj = elem0.Y
                    idxPolygons = helper.point_inside_polygon(x - X_obj , y - Y_obj, shape)
                    if len(idxPolygons) == 1:
                        idxPolygon = idxPolygons[0]
                        if idxPolygon > 0:
                            self.activeGraphics.set("ConnectorToModify", activeObject )
                            self.activeGraphics.set("idxPointModified" , idxPolygon -1)
                            
                            
            # Connecting Elements
    
            bConnectorPloting = self.rootGraphics.get("bConnectorPloting")
            if bConnectorPloting:
                # Determining if there is a endpoint in focus
                keys = self.activeGraphics.getChildKeys()
                objInFocus = None
                for key in keys:
                    element = self.activeGraphics.getb(key)
                    types = inspect.getmro(type(element))
                    if PyLinXDataObjects.PX_PlotableElement in types: 
                        objInFocus, idxPin = element.isPinInFocus(x,y)
                        if objInFocus != None:
                            if len(idxPin) == 1:
                                idxPin = idxPin[0]
                            break  
                if objInFocus == None:
                
                    # case there is no second element
                    proxyElem = self.activeGraphics.getb("PX_PlottableProxyElement")
                    ConnectorPloting = self.rootGraphics.get("ConnectorPloting")
                    X0 = ConnectorPloting.X
                    Y0 = ConnectorPloting.Y
                    listPoints = list(ConnectorPloting.get("listPoints"))
                    len_listPoints = len(listPoints)
                    if len_listPoints > 1:
                        lastPoint_minus_1 = listPoints[-2]
                    else:
                        lastPoint_minus_1 = sys.maxint
                    x_diff = X - X0
                    y_diff = Y - Y0 
                    if len_listPoints % 2 == 0:
                        if abs(x_diff - lastPoint_minus_1) < 12 and len_listPoints > 1:
                            listPoints[-1] = y_diff
                        else:
                            listPoints.append(x_diff)
                    else:
                        if abs(y_diff - lastPoint_minus_1) < 12 and len_listPoints > 1:
                            listPoints[-1] = x_diff
                        else:
                            listPoints.append(y_diff)
                    ConnectorPloting.set("listPoints", listPoints)
                    proxyElem.X = x
                    proxyElem.Y = y
                    
                else:
                    # idxPin determined as the index of Pins in focus
                    setIdxConnectedInPins = objInFocus.get("setIdxConnectedInPins")
                    #print "setIdxConnectedInPins (2): ", setIdxConnectedInPins
                    if idxPin in setIdxConnectedInPins:
                        bConnect = False
                    else:
                        bConnect = True
                
                    #print "bConnect: ", bConnect
                    if bConnect:
                        # connecting the connector to the second element                
                        for key in keys:        
                            element = self.activeGraphics.getb(key)
                            types = inspect.getmro(type(element))
                            if PyLinXDataObjects.PX_PlottableProxyElement in types:
                                self.activeGraphics.delete(key)
                                #print "Proxy Deleted!"
                                break
                        ConnectorPloting = self.rootGraphics.get("ConnectorPloting")
                        ConnectorPloting.elem1 = objInFocus
                        #ConnectorPloting.idxInPin = idxPin 
                        # TODO: the convention for the idx of input Puns is not consistent ?
                        #print "-->idxPin: ", idxPin
                        #print "id(0): ", id(ConnectorPloting) 
                        ConnectorPloting.idxInPin = idxPin
                        #print "id(1): ", id(ConnectorPloting)
                        setIdxConnectedInPins.add(idxPin)
                        objInFocus.set("setIdxConnectedInPins", setIdxConnectedInPins)
                        self.rootGraphics.set("bConnectorPloting", False)
                        objInFocus.idxActiveInPins = []
                        
                        elem0 = ConnectorPloting.elem0
                        setIdxConnectedOutPins = elem0.get("setIdxConnectedOutPins")
                        idxOutPinConnectorPloting = self.rootGraphics.get("idxOutPinConnectorPloting")
                        setIdxConnectedOutPins.add(idxOutPinConnectorPloting)
                        elem0.set("setIdxConnectedOutPins", setIdxConnectedOutPins)
                        self.rootGraphics.set("idxOutPinConnectorPloting", None)

            else:
                # Starting connecting Elements
                keys = self.activeGraphics.getChildKeys()
                for key in keys:
                    element = self.activeGraphics.getb(key)
                    types = inspect.getmro(type(element))
                    if PyLinXDataObjects.PX_PlotableElement in types:
                        objInFocus, idxPin = element.isPinInFocus(x,y)
                        if len(idxPin) > 0:
                            idxPin = idxPin[0]                         
                        if objInFocus != None and (idxPin > -1):
                            proxyElem = PyLinXDataObjects.PX_PlottableProxyElement(x,y)
                            self.activeGraphics.paste(proxyElem)
                            newConnector = PyLinXDataObjects.PX_PlottableConnector(element, proxyElem)
                            self.activeGraphics.paste(newConnector,  bHashById=True)
                            self.rootGraphics.set("bConnectorPloting", True)
                            self.rootGraphics.set("idxOutPinConnectorPloting", idxPin)
                            self.rootGraphics.set("ConnectorPloting", newConnector)