Ejemplo n.º 1
0
    def init(self):
        self._nodeManager = NodeManager()
        self._connectionManager = ConnectionManager()
        self._viewerManager = ViewerManager()

        # connect undoRedoChanged signal
        self._nodeManager.undoRedoChanged.connect(self.emitUndoRedoChanged)
        self._connectionManager.undoRedoChanged.connect(
            self.emitUndoRedoChanged)
        self._viewerManager.undoRedoChanged.connect(self.emitUndoRedoChanged)

        return self
Ejemplo n.º 2
0
 def add_new_machine(self, config):
     memory = int(config.split()[0])
     mapSlots = int(config.split()[1])
     redSlots = int(config.split()[2])
     self.cluster.totalMapSlots += mapSlots
     self.cluster.totalRedSlots += redSlots
     self.cluster.nodes.append(NodeManager(self, memory, mapSlots,
                                           redSlots))
Ejemplo n.º 3
0
    def init(self):
        self._nodeManager = NodeManager()
        self._connectionManager = ConnectionManager()
        self._viewerManager = ViewerManager()

        # connect undoRedoChanged signal
        self._nodeManager.undoRedoChanged.connect(self.emitUndoRedoChanged)
        self._connectionManager.undoRedoChanged.connect(self.emitUndoRedoChanged)
        self._viewerManager.undoRedoChanged.connect(self.emitUndoRedoChanged)

        return self
Ejemplo n.º 4
0
 def handle_overflow(self, u):
     u1, u2 = self.split(u)
     # if u is root, create a new root with s1 and s2 as its' children
     if u.check_root():
         new_root = NodeManager()
         self.add_child_node(new_root, u1)
         self.add_child_node(new_root, u2)
         self.root = new_root
         self.update_mbr(new_root)
     # if u is not root, delete u, and set s1 and s2 as u's parent's new children
     else:
         w = u.parent
         # copy the information of s1 into u
         w.child_nodes.remove(u)
         self.add_child_node(w, u1)
         self.add_child_node(w, u2)
         if w.check_overflow():
             self.handle_overflow(w)
         self.update_mbr(w)
Ejemplo n.º 5
0
 def __init__(self):
     self.root = NodeManager()
Ejemplo n.º 6
0
    def split(self, u):
        # split u into s1 and s2
        best_s1 = NodeManager()
        best_s2 = NodeManager()
        best_perimeter = sys.maxsize
        # u is a leaf node
        if u.check_leaf():
            m = u.data_points.__len__()
            # create two different kinds of divides
            divides = [
                sorted(u.data_points, key=lambda data_point: data_point['x']),
                sorted(u.data_points, key=lambda data_point: data_point['y'])
            ]
            for divide in divides:
                for i in range(math.ceil(0.4 * B), m - math.ceil(0.4 * B) + 1):
                    s1 = NodeManager()
                    s1.data_points = divide[0:i]
                    self.update_mbr(s1)
                    s2 = NodeManager()
                    s2.data_points = divide[i:divide.__len__()]
                    self.update_mbr(s2)
                    if best_perimeter > s1.calculate_perimeter(
                    ) + s2.calculate_perimeter():
                        best_perimeter = s1.calculate_perimeter(
                        ) + s2.calculate_perimeter()
                        best_s1 = s1
                        best_s2 = s2

        # u is a internal node
        else:
            # create four different kinds of divides
            m = u.child_nodes.__len__()
            divides = [
                sorted(u.child_nodes,
                       key=lambda child_node: child_node.MBR['x_min']),
                sorted(u.child_nodes,
                       key=lambda child_node: child_node.MBR['x_max']),
                sorted(u.child_nodes,
                       key=lambda child_node: child_node.MBR['y_min']),
                sorted(u.child_nodes,
                       key=lambda child_node: child_node.MBR['y_max'])
            ]
            for divide in divides:
                for i in range(math.ceil(0.4 * B), m - math.ceil(0.4 * B) + 1):
                    s1 = NodeManager()
                    s1.child_nodes = divide[0:i]
                    self.update_mbr(s1)
                    s2 = NodeManager()
                    s2.child_nodes = divide[i:divide.__len__()]
                    self.update_mbr(s2)
                    if best_perimeter > s1.calculate_perimeter(
                    ) + s2.calculate_perimeter():
                        best_perimeter = s1.calculate_perimeter(
                        ) + s2.calculate_perimeter()
                        best_s1 = s1
                        best_s2 = s2

        for child in best_s1.child_nodes:
            child.parent = best_s1
        for child in best_s2.child_nodes:
            child.parent = best_s2

        return best_s1, best_s2
Ejemplo n.º 7
0
class ButtleManager(QtCore.QObject):
    """
        This class catches events from QML, and manages them by calling the right manager or the right methods in core.
        It's like the front manager, which delegate to other managers.
        This class also catches events from QML about undo / redo.
    """
    def init(self):
        self._nodeManager = NodeManager()
        self._connectionManager = ConnectionManager()
        self._viewerManager = ViewerManager()

        # connect undoRedoChanged signal
        self._nodeManager.undoRedoChanged.connect(self.emitUndoRedoChanged)
        self._connectionManager.undoRedoChanged.connect(
            self.emitUndoRedoChanged)
        self._viewerManager.undoRedoChanged.connect(self.emitUndoRedoChanged)

        return self

    ############### getters ###############

    def getNodeManager(self):
        return self._nodeManager

    def getConnectionManager(self):
        return self._connectionManager

    def getViewerManager(self):
        return self._viewerManager

    ############### UNDO & REDO ###############

    @QtCore.Slot()
    def undo(self):
        """
            Calls the cmdManager to undo the last command.
        """
        cmdManager = CommandManager()
        cmdManager.undo()

        # emit undo/redo display
        self.emitUndoRedoChanged()

        # if we need to update params or viewer
        buttleData = ButtleDataSingleton().get()
        buttleData.currentParamNodeChanged.emit()
        buttleData.currentViewerNodeChanged.emit()

    @QtCore.Slot()
    def redo(self):
        """
            Calls the cmdManager to redo the last command.
        """
        cmdManager = CommandManager()
        cmdManager.redo()

        # emit undo/redo display
        self.emitUndoRedoChanged()

        # if we need to update params or viewer
        buttleData = ButtleDataSingleton().get()
        buttleData.currentParamNodeChanged.emit()
        buttleData.currentViewerNodeChanged.emit()

    def signalUndoRedo(self):
        self.undoRedoChanged.emit()

    def canUndo(self):
        """
            Calls the cmdManager to return if we can undo or not.
        """
        cmdManager = CommandManager()
        return cmdManager.canUndo()

    def canRedo(self):
        """
            Calls the cmdManager to return if we can redo or not.
        """
        cmdManager = CommandManager()
        return cmdManager.canRedo()

    ############### DELETION ###############
    @QtCore.Slot()
    def deleteSelection(self):
        buttleData = ButtleDataSingleton().get()
        if (buttleData.currentConnectionWrapper):
            self._connectionManager.disconnect(
                buttleData.currentConnectionWrapper)
        else:
            self._nodeManager.destructionNodes()

    ################################################## DATA EXPOSED TO QML ##################################################

    @QtCore.Signal
    def changed(self):
        pass

    def emitUndoRedoChanged(self):
        self.changed.emit()

    # undo redo
    canUndo = QtCore.Property(bool, canUndo, notify=changed)
    canRedo = QtCore.Property(bool, canRedo, notify=changed)

    # managers
    nodeManager = QtCore.Property(QtCore.QObject,
                                  getNodeManager,
                                  constant=True)
    connectionManager = QtCore.Property(QtCore.QObject,
                                        getConnectionManager,
                                        constant=True)
    viewerManager = QtCore.Property(QtCore.QObject,
                                    getViewerManager,
                                    constant=True)
Ejemplo n.º 8
0
class ButtleManager(QtCore.QObject):
    """
        This class catches events from QML, and manages them by calling the right manager or the right methods in core.
        It's like the front manager, which delegate to other managers.
        This class also catches events from QML about undo / redo.
    """

    def init(self):
        self._nodeManager = NodeManager()
        self._connectionManager = ConnectionManager()
        self._viewerManager = ViewerManager()

        # connect undoRedoChanged signal
        self._nodeManager.undoRedoChanged.connect(self.emitUndoRedoChanged)
        self._connectionManager.undoRedoChanged.connect(self.emitUndoRedoChanged)
        self._viewerManager.undoRedoChanged.connect(self.emitUndoRedoChanged)

        return self

    ############### getters ###############

    def getNodeManager(self):
        return self._nodeManager

    def getConnectionManager(self):
        return self._connectionManager

    def getViewerManager(self):
        return self._viewerManager

    ############### UNDO & REDO ###############

    @QtCore.Slot()
    def undo(self):
        """
            Calls the cmdManager to undo the last command.
        """
        cmdManager = CommandManager()
        cmdManager.undo()

        # emit undo/redo display
        self.emitUndoRedoChanged()

        # if we need to update params or viewer
        buttleData = ButtleDataSingleton().get()
        buttleData.currentParamNodeChanged.emit()
        buttleData.currentViewerNodeChanged.emit()

    @QtCore.Slot()
    def redo(self):
        """
            Calls the cmdManager to redo the last command.
        """
        cmdManager = CommandManager()
        cmdManager.redo()

        # emit undo/redo display
        self.emitUndoRedoChanged()

        # if we need to update params or viewer
        buttleData = ButtleDataSingleton().get()
        buttleData.currentParamNodeChanged.emit()
        buttleData.currentViewerNodeChanged.emit()

    def signalUndoRedo(self):
        self.undoRedoChanged.emit()

    def canUndo(self):
        """
            Calls the cmdManager to return if we can undo or not.
        """
        cmdManager = CommandManager()
        return cmdManager.canUndo()

    def canRedo(self):
        """
            Calls the cmdManager to return if we can redo or not.
        """
        cmdManager = CommandManager()
        return cmdManager.canRedo()

    ############### DELETION ###############
    @QtCore.Slot()
    def deleteSelection(self):
        buttleData = ButtleDataSingleton().get()
        if(buttleData.currentConnectionWrapper):
            self._connectionManager.disconnect(buttleData.currentConnectionWrapper)
        else:
            self._nodeManager.destructionNodes()

    ################################################## DATA EXPOSED TO QML ##################################################

    @QtCore.Signal
    def changed(self):
        pass

    def emitUndoRedoChanged(self):
        self.changed.emit()

    # undo redo
    canUndo = QtCore.Property(bool, canUndo, notify=changed)
    canRedo = QtCore.Property(bool, canRedo, notify=changed)

    # managers
    nodeManager = QtCore.Property(QtCore.QObject, getNodeManager, constant=True)
    connectionManager = QtCore.Property(QtCore.QObject, getConnectionManager, constant=True)
    viewerManager = QtCore.Property(QtCore.QObject, getViewerManager, constant=True)