Ejemplo n.º 1
0
    def __init__(self, parent, path):
        
        try:
            dataObject = mdflib.mdf(path)
            fileType = PX_Signals.fileType.mdf
             
        
        except Exception as exc:
            
            try:
                dataObject = csvlib.CSVObject(path).data()
                fileType = PX_Signals.fileType.csv
            
            except Exception as exc2:
            
                strExp = str(exc)
                strExp2 = str(exc2)
                strText = u"Unable to open file - " + strExp + " - " + strExp2  
                helper.error(strText)
                return

        name = u"Signal"
        super(PX_Signals, self).__init__(parent, name, bIdSuffix = True, headObject = dataObject)
        self.set("fileType", fileType)
        
        self._BContainer__Attributes[u"pathMdfFile"] = path
        listVirtualAttributes = [u"signals", u"signalsFullData"]
        for key in self._BContainer__Head:
            listVirtualAttributes.append(key)
        self._BContainer__AttributesVirtual.extend(listVirtualAttributes)
Ejemplo n.º 2
0
 def on_accept(self):
     try:
         self.values = self.formWidget.getValues()
         self.result = True
     except:
         helper.error(u"Invalid Input! Please Try again!")
         self.result = False
         return
     self.values[u"StimulationFunction"] = self.stimFunction
     self.hide()
 def on_accept(self):
     try:
         self.values = self.formWidget.getValues()
         self.result = True
     except:
         helper.error(u"Invalid Input! Please Try again!")
         self.result = False
         return 
     self.values[u"StimulationFunction"] = self.stimFunction
     self.hide()
Ejemplo n.º 4
0
    def __init__(self, mainController, drawWidget=None):

        super(QtGui.QWidget, self).__init__()
        self.listItems = {}
        myBoxLayout = QtGui.QVBoxLayout()
        self.setLayout(myBoxLayout)
        self.toolbar = QtGui.QToolBar()
        self.mainController = mainController
        self.__objectHandler = mainController.getb(u"ObjectHandler")
        self.__projectController = mainController

        self.myListWidget = PX_Tab_SignalSelect_TreeView(
            self, self.listItems, mainDrawingWidget=drawWidget)
        self.myListWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.model = treeModel_Signals(self, self.myListWidget, self)
        self.myListWidget.setModel(self.model)

        # Signals
        #########

        self.connect(self.myListWidget, QtCore.SIGNAL("guiAction__plotSignal"),
                     self.plotSignal)
        self.connect(self.__projectController.mainWindow,
                     QtCore.SIGNAL(u"dataChanged__signals"),
                     self.updateSignalTab)
        self.connect(self.__projectController.mainWindow,
                     QtCore.SIGNAL(u"dataChanged__mapping"), self.repaint)
        self.connect(self.__projectController.mainWindow,
                     QtCore.SIGNAL(u"dataChanged__mapping"),
                     self.myListWidget.mainDrawingWidget.repaint)

        myBoxLayout.addWidget(self.toolbar)
        myBoxLayout.addWidget(self.myListWidget)

        ## Tool-Bar

        self.toolbar.setIconSize(QtCore.QSize(16, 16))

        # Add Action to Toolbar

        self.__actionLoad   = helper.loadAction(widget=self,  IconPath =u"./Recources/Icons/openSignal24.png", ToolTip=u"Load Signal File",\
                                        ShortCut=u"Ctrl+L", Callback=self.loadSignalFile, ToolBar=self.toolbar)
        self.__actionMap    = helper.loadAction(widget=self,  IconPath =u"./Recources/Icons/SignalMapping16.png", ToolTip=u"Map Signals by Name",\
                                        ShortCut=u"Ctrl+M", Callback=self.mapSignalsByName, ToolBar=self.toolbar)
        self.__actionDelMap = helper.loadAction(widget=self,  IconPath =u"./Recources/Icons/deleteMap16.png", ToolTip=u"Delete Mapping",\
                                                            Callback=self.delMap, ToolBar=self.toolbar)

        self.toolbar.setStyleSheet(u".QToolBar {border: 0px;}")
        self.SignalFileName = None
        self.SignalName = None

        # Turns interacive mode of matplotlib.pyplot on
        pyplot.ion()
        self.repaint()
 def on_accept(self):
     try:
         values = self.formWidget.getValues()
         self.result = True
     except:
         helper.error(u"Invalid Input! Please Try again!")
         self.result = False
         return 
     strValues = repr(values).replace(" ", "")
     objPath = self.variable.get(u"objPath")
     #ustrExec2 =  u"set " + objPath + u". " + unicode(strValues)
     ustrExec2 =  u"set " + objPath  + u" " + unicode(strValues)
     self.mainController.execCommand(ustrExec2)
     self.hide()
Ejemplo n.º 6
0
 def cd(self, path):
     try:
         obj = self.getObjFromPath(path)
     except Exception as exp:
         errorString = u"Error PyLinXMainController,PyLinXMainController.cd: Failed to open " + path + \
                  " - " + unicode(Exception) 
         helper.error(errorString)
         return 
     if obj == None:
         errorString = u"Error PyLinXMainController,PyLinXMainController.cd - " + unicode(Exception) 
         helper.error(errorString)
         return
     self._activeFolder = obj
     return
Ejemplo n.º 7
0
 def __execCommand_cd(self, path):
     try:
         obj = self.activeFolder.getObjFromPath(path[0])
     except Exception as exp:
         errorString = u"Error PyLinXProjectController,PyLinXProjectController.cd: Failed to open " + path [0] + \
                  " - " + unicode(exp)
         helper.error(errorString)
         return
     if obj == None:
         errorString = u"Error PyLinXProjectController,PyLinXProjectController.cd - " + unicode(
             Exception)
         helper.error(errorString)
         return
     self.activeFolder = obj
     return
Ejemplo n.º 8
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.º 9
0
    def on_actionLoadProject(self):
         
        strPath = os.getcwd()
        _file, strSavePath = helper.showFileSelectionDialog(self.ui,strPath, bDir = False,strHeader ="Select File to load Project...",\
                                                     strExt = u"*.pyp",\
                                                     dialogType = u"load")  
 
        if _file == None:
            return
         
        old_Controller = self.mainController
 
        self.mainController = PyLinXMainController.PyLinXMainController(mainWindow = self )
        _file_read = _file.read()
 
        self.mainController.execScript(_file_read)
         
        old_Controller.delete()
        newProject = self.mainController.getb(u"rootGraphics")
        self.ui.drawWidget.newProject(self.mainController)
         
        rootGraphics = self.mainController.getb(u"rootGraphics")
        rootGraphics.set(u"strSavePath", strSavePath)          
 
        self.ui.drawWidget.repaint()
Ejemplo n.º 10
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.º 11
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.º 13
0
 def loadSignalFile(self):
     strPath = helper.showFileSelectionDialog(self,strPath = None, bDir = False, \
                                    strExt = u"All files (*.*);;MDF3 (*.dat *.mdf);;MDF4 (*.mf4)", \
                                    strHeader = u"Load Singal File",\
                                    dialogType = u"load",\
                                    bFileObject = False )
     if not strPath:
         return
     command = u"@signals new signalFile " + strPath
     self.mainController.execCommand(command)
Ejemplo n.º 14
0
        def __init__(self, commandString):
            self.__commandString = unicode(commandString)
            self.__rawList = helper.split(self.__commandString)
            self.__context = None
            self.__bExecutable = None
            self.__listCommand = []
            self.__strCommand = u""
            self.__firstPhrase = u""

            self.__initialize()
Ejemplo n.º 15
0
    def __init__(self, mainController,   drawWidget = None  ):
        
        super(QtGui.QWidget,self).__init__()
        self.listItems={}
        myBoxLayout = QtGui.QVBoxLayout()
        self.setLayout(myBoxLayout)
        self.toolbar = QtGui.QToolBar()
        self.mainController = mainController
        self.__signalsFolder = mainController.getb(u"signalFiles")
        self.__objectHandler = mainController.getb(u"ObjectHandler")       

        self.myListWidget = PX_Tab_SignalSelect_TreeView(self, self.listItems, mainDrawingWidget = drawWidget )  
        self.myListWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.model = treeModel_Signals(self, self.myListWidget, self)
        self.myListWidget.setModel(self.model)
        
        self.connect(self.myListWidget, QtCore.SIGNAL("plotSignal"), self.plotSignal)
        
        myBoxLayout.addWidget(self.toolbar)
        myBoxLayout.addWidget(self.myListWidget)

        ## Tool-Bar

        self.toolbar.setIconSize (QtCore.QSize(16,16))
        
        # Add Action to Toolbar
        
        self.__actionLoad = helper.loadAction(widget=self,  IconPath =u"./Recources/Icons/openSignal24.png", ToolTip=u"Load Signal File",\
                                        ShortCut=u"Ctrl+L", Callback=self.loadSignalFile, ToolBar=self.toolbar)
        self.__actionMap  = helper.loadAction(widget=self,  IconPath =u"./Recources/Icons/SignalMapping16.png", ToolTip=u"Map Signals by Name",\
                                        ShortCut=u"Ctrl+M", Callback=self.mapSignalsByName, ToolBar=self.toolbar)
        self.__actionDelMap= helper.loadAction(widget=self,  IconPath =u"./Recources/Icons/deleteMap16.png", ToolTip=u"Delete Mapping",\
                                                            Callback=self.delMap, ToolBar=self.toolbar)

        
        self.toolbar.setStyleSheet(u".QToolBar {border: 0px;}")
        self.SignalFileName = None
       
        
        
        # Turns interacive mode of matplotlib.pyplot on
        pyplot.ion()
        self.repaint()
Ejemplo n.º 16
0
    def on_actionLoadProject(self):

        strPath = os.getcwd()
        _file, strSavePath = PyLinXHelper.showFileSelectionDialog(self.ui,strPath, bDir = False,strHeader ="Select File to load Project...",\
                                                     strExt = u"*.pyp",\
                                                     dialogType = u"load")

        self.__loadFile(_file)

        rootGraphics = self.mainController.getb(u"rootGraphics")
        rootGraphics.set(u"strSavePath", strSavePath)
Ejemplo n.º 17
0
 def on_accept(self):
     try:
         values = self.formWidget.getValues()
         self.result = True
     except:
         helper.error(u"Invalid Input! Please Try again!")
         self.result = False
         return
     values[u"StimulationFunction"] = self.stimFunction
     strValues = repr(values).replace(" ", "")
     objPath = self.variable.objPath
     #stimFunction = self.variable.get(u"StimulationFunction")
     print self.stimFunction
     attributeToSet = PX_Templ.PX_DiagData.StimAttribute[self.stimFunction]
     print "objPath", objPath
     ustrExec2 = u"set " + objPath[:
                                   -1] + u"." + attributeToSet + u" " + unicode(
                                       strValues)
     self.mainController.execCommand(ustrExec2)
     self.hide()
Ejemplo n.º 18
0
    def on_actionLoadProject(self):
         
        strPath = os.getcwd()
        _file, strSavePath = PyLinXHelper.showFileSelectionDialog(self.ui,strPath, bDir = False,strHeader ="Select File to load Project...",\
                                                     strExt = u"*.pyp",\
                                                     dialogType = u"load")  
 
        self.__loadFile(_file)

        rootGraphics = self.mainController.getb(u"rootGraphics")
        rootGraphics.set(u"strSavePath", strSavePath)           
Ejemplo n.º 19
0
 def on_actionSave_As(self):
     if self.mainController.isAttr(u"strSavePath"):
         strSavePath_old = self.mainController.get(u"strSavePath")
         (strPath, strSavePath_old_file) = os.path.split(strSavePath_old)
     else:
         strPath = os.getcwd()
     strSavePath= PyLinXHelper.showFileSelectionDialog(self.ui,strPath, bDir = False, strExt = u"*.pyp", \
                                                 strHeader =u"Select File to save Project...",\
                                                 dialogType = u"save",\
                                                 bFileObject = False)
     (strSavePath_base, strSavePath_ext) = os.path.splitext(strSavePath)
     if not strSavePath_ext == u"pyp":
         strSavePath = strSavePath_base + u".pyp"
     self.__saveProject(strSavePath)
Ejemplo n.º 20
0
 def on_actionSave_As(self):
     if self.mainController.isAttr(u"strSavePath"):
         strSavePath_old = self.mainController.get(u"strSavePath")
         (strPath, strSavePath_old_file) = os.path.split(strSavePath_old)
     else:
         strPath = os.getcwd()
     strSavePath= helper.showFileSelectionDialog(self.ui,strPath, bDir = False, strExt = u"*.pyp", \
                                                 strHeader =u"Select File to save Project...",\
                                                 dialogType = u"save",\
                                                 bFileObject = False)
     (strSavePath_base,strSavePath_ext) = os.path.splitext(strSavePath)
     if not  strSavePath_ext == u"pyp":
         strSavePath = strSavePath_base + u".pyp"
     self.__saveProject(strSavePath)
Ejemplo n.º 21
0
    def __init__(self, parent, path):

        try:
            dataObject = mdflib.mdf(path)
            fileType = PX_Signals.fileType.mdf

        except Exception as exc:

            try:
                dataObject = csvlib.CSVObject(path).data()
                fileType = PX_Signals.fileType.csv

            except Exception as exc2:

                strExp = str(exc)
                strExp2 = str(exc2)
                strText = u"Unable to open file - " + strExp + " - " + strExp2
                helper.error(strText)
                return

        name = u"Signal"
        super(PX_Signals, self).__init__(parent,
                                         name,
                                         bIdSuffix=True,
                                         headObject=dataObject)
        self.set("fileType", fileType)

        self._BContainer__Attributes[u"pathMdfFile"] = path
        for key in self._BContainer__Head:
            self._dictGetCallbacks.addCallback(key,
                                               lambda: self.get_signal(key))
        self.__projectController = parent.getRoot(
            PyLinXCtl.PyLinXProjectController.PyLinXProjectController)

        self.__projectController.mainWindow.emit(
            QtCore.SIGNAL(u"dataChanged_signals"))
Ejemplo n.º 22
0
 def loadSignalFile(self):
     
     strPath = helper.showFileSelectionDialog(self,strPath = None, bDir = False, \
                                    strExt = u"All files (*.*);;MDF3 (*.dat *.mdf);;MDF4 (*.mf4)", \
                                    strHeader = u"Load Singal File",\
                                    dialogType = u"load",\
                                    bFileObject = False )
     if not strPath:
         return
     command = u"new signalFile " + strPath 
     newSignalFile = self.mainController.execCommand(command)
     signals = newSignalFile.get(u"signals")
     masterSignals = newSignalFile.get(u"masterSignals")
     self.SignalFileName= newSignalFile.get(u"Name")
     
     self.model.loadSignals(signals, self.SignalFileName, masterSignals)
     self.myListWidget.setHeaderHidden(False)
     self.repaint()
Ejemplo n.º 23
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.º 24
0
    def __init__(self, mainController):

        super(QtGui.QWidget, self).__init__()
        self.listItems = {}
        myBoxLayout = QtGui.QVBoxLayout()
        self.setLayout(myBoxLayout)
        self.toolbar = QtGui.QToolBar()
        self.mainController = mainController
        self.__objectHandler = mainController.getb(u"ObjectHandler")
        objects = self.__objectHandler.listObjects
        self.widget = PX_Tab_Recorder_TreeView(self, self.listItems)
        self.model = treeModel_Recorder(self, objects, self.widget, self)
        #self.model = treeModel_Recorder(self,objects, self )
        self.__recorder_RecordState = PX_ObjectHandler.PX_ObjectHandler.recorderState.off
        self.__recorder_VariablesToRecord = self.__objectHandler.get(
            u"recorder_VariablesToRecord")
        self.__recorder_fileFormat = self.__objectHandler.get(
            u"recorder_fileFormat")

        self.listItems = {}

        # Initialize Model
        VariablesToRecord = self.__objectHandler.listObjects
        self.model.loadObjects(VariablesToRecord)

        self.widget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.widget.setModel(self.model)

        myBoxLayout.addWidget(self.toolbar)
        myBoxLayout.addWidget(self.widget)

        ## Tool-Bar

        self.toolbar.setIconSize(QtCore.QSize(16, 16))

        # Add Action to Toolbar

        self.__actionRecordFull = helper.loadAction(widget=self,\
                                                    IconPath =u"./Recources/Icons/recordFull16.png",\
                                                    ToolTip=u"Record all Variables",\
                                                    ShortCut=u"Ctrl+L", \
                                                    Callback=self.recordAll, \
                                                    ToolBar=self.toolbar, \
                                                    checkable = True)
        self.__actionRecordPart = helper.loadAction(widget=self,  \
                                                    IconPath =u"./Recources/Icons/recordPart16.png", \
                                                    ToolTip=u"Record selected Variables",\
                                                    ShortCut=u"Ctrl+M", \
                                                    Callback=self.recordPart, \
                                                    ToolBar=self.toolbar, \
                                                    checkable = True)

        emptyWidget = QtGui.QWidget()
        emptyWidget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Preferred)
        self.toolbar.addWidget(emptyWidget)

        # Selector for output file format
        self.__comboBoxFileFormat = QtGui.QComboBox()
        self.__comboBoxFileFormat.addItem(u"mdf")
        self.__comboBoxFileFormat.addItem(u"csv")
        self.__comboBoxFileFormat.setToolTip(u"Select Output FIle Format")
        self.__comboBoxFileFormat.currentIndexChanged.connect(
            self.__onIndexComboFileForamtChangeed)
        self.toolbar.addWidget(self.__comboBoxFileFormat)

        self.toolbar.setStyleSheet(u".QToolBar {border: 0px;}")
        self.SignalFileName = None
        self.repaint()
Ejemplo n.º 25
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)
Ejemplo n.º 26
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.º 28
0
    def __init__(self, mainController):
        
        super(QtGui.QWidget,self).__init__()
        self.listItems={}
        myBoxLayout = QtGui.QVBoxLayout()
        self.setLayout(myBoxLayout)
        self.toolbar = QtGui.QToolBar()
        self.mainController = mainController
        self.__objectHandler = mainController.getb(u"ObjectHandler")
        objects = self.__objectHandler.get(u"listObjects")
        self.widget = PX_Tab_Recorder_TreeView(self, self.listItems)  
        self.model = treeModel_Recorder(self,objects, self.widget )
        self.__recorder_RecordState =  PX_ObjectHandler.PX_ObjectHandler.recorderState.off
        self.__recorder_VariablesToRecord = self.__objectHandler.get(u"recorder_VariablesToRecord")
        self.__recorder_fileFormat = self.__objectHandler.get(u"recorder_fileFormat")

        self.listItems = {}
        
        # Initialize Model
        VariablesToRecord = self.__objectHandler.get(u"listObjects")
        self.model.loadObjects(VariablesToRecord)

        
        self.widget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.widget.setModel(self.model)
        
        myBoxLayout.addWidget(self.toolbar)
        myBoxLayout.addWidget(self.widget)

        ## Tool-Bar

        self.toolbar.setIconSize (QtCore.QSize(16,16))
        
        # Add Action to Toolbar
        
        self.__actionRecordFull = helper.loadAction(widget=self,\
                                                    IconPath =u"./Recources/Icons/recordFull16.png",\
                                                    ToolTip=u"Record all Variables",\
                                                    ShortCut=u"Ctrl+L", \
                                                    Callback=self.recordAll, \
                                                    ToolBar=self.toolbar, \
                                                    checkable = True)
        self.__actionRecordPart = helper.loadAction(widget=self,  \
                                                    IconPath =u"./Recources/Icons/recordPart16.png", \
                                                    ToolTip=u"Record selected Variables",\
                                                    ShortCut=u"Ctrl+M", \
                                                    Callback=self.recordPart, \
                                                    ToolBar=self.toolbar, \
                                                    checkable = True)
        
        emptyWidget = QtGui.QWidget()
        emptyWidget.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Preferred)
        self.toolbar.addWidget(emptyWidget)
        
        
        # Selector for output file format
        self.__comboBoxFileFormat = QtGui.QComboBox()
        self.__comboBoxFileFormat.addItem(u"mdf")
        self.__comboBoxFileFormat.addItem(u"csv")
        self.__comboBoxFileFormat.setToolTip(u"Select Output FIle Format")
        self.__comboBoxFileFormat.currentIndexChanged.connect(self.__onIndexComboFileForamtChangeed)
        self.toolbar.addWidget(self.__comboBoxFileFormat)

        
        self.toolbar.setStyleSheet(u".QToolBar {border: 0px;}")
        self.SignalFileName = None
        self.repaint()