Ejemplo n.º 1
0
    def get_contents2(self, bricks, states):
        """
         Builds the state (step 2)

        :param bricks: Map[String,Brick], the bricks of the application
        :param states: Map[String, State], the states of the application
        :return:
        :raises: UndefinedBrick, if the brick the transition operates on is not defined
        :raises: UndefinedState, if the target state is not defined

        This method builds the transition attribute.
        A 2-step build is required (due to the meta-model) to get references right while avoiding bad typing tricks
        such as passing a TransitionBuilder instead of a Transition.
        """
        if self.state not in states.keys():
            raise UndefinedState()
        tmp_transitions = []
        for t in self.transitions:
            if t.sensor not in bricks.keys():
                raise UndefinedBrick()
            if t.next_state not in states.keys():
                raise UndefinedState()
            if isinstance(t, TransitionBuilder):
                transition = Transition(bricks[t.sensor],
                                        t.value,
                                        states[t.next_state],
                                        comparison=t.comparison,
                                        read=t.readMode)
            elif isinstance(t, LogicTransitionBuilder):
                transition = LogicTransition(bricks[t.transition.sensor],
                                             t.transition.value, t.type,
                                             bricks[t.sensor], t.value,
                                             states[t.next_state])
            tmp_transitions += [transition]
        states[self.state].transitions = tmp_transitions
Ejemplo n.º 2
0
    def get_contents(self, bricks, states):
        """
        Builds the transition.

        :param bricks: Map[String,Brick], the bricks of the application
        :param states: Map[String,State], the states of the application
        :return: Transition, the transition to build
        :raises: UndefinedBrick, if the transition references an undefined brick
        :raises: UndefinedState, if the transition references an undefined state
        """
        if self.sensor not in bricks.keys():
            raise UndefinedBrick()
        if self.next_state not in states.keys():
            raise UndefinedState()
        if self.comparison != None and self.read_mode != None:
            return Transition(bricks[self.sensor],
                              self.value,
                              states[self.next_state],
                              comparison=self.comparison,
                              read=self.read_mode)
        elif self.comparison != None:
            return Transition(bricks[self.sensor],
                              self.value,
                              states[self.next_state],
                              comparison=self.comparison)
        elif self.read_mode != None:
            return Transition(bricks[self.sensor],
                              self.value,
                              states[self.next_state],
                              read=self.read_mode)
        else:
            return Transition(bricks[self.sensor], self.value,
                              states[self.next_state])
    def get_contents(self, bricks):
        """
        Builds the action.

        :param bricks: Map[String,Brick] the bricks of the application
        :return: Action, the action to build
        :raises: UndefinedBrick, if the action references an undefined brick
        """
        if self.actuator not in bricks.keys():
            raise UndefinedBrick()
        return Action(self.data, bricks[self.actuator])
Ejemplo n.º 4
0
 def get_contents2(self, bricks, states, modes):
     if self.initState not in states.keys():
         raise UndefinedState()
     tmp_transitions = []
     for t in self.transitions:
         if t.sensor not in bricks.keys():
             raise UndefinedBrick()
         if t.next_state not in modes.keys():
             raise UndefinedMode()
         if isinstance(t, TransitionBuilder):
             transition = Transition(bricks[t.sensor], t.value, modes[t.next_state], comparison=t.comparison, read=t.readMode)
         elif isinstance(t, LogicTransitionBuilder): #A REVOIR
             transition = LogicTransition(bricks[t.transition.sensor], t.transition.value, t.type, bricks[t.sensor], t.value, states[t.next_state])
         tmp_transitions += [transition]
     modes[self.mode].transitions = tmp_transitions
     """
    def get_contents(self, bricks, states):
        """
        Builds the transition.

        :param bricks: Map[String,Brick], the bricks of the application
        :param states: Map[String,State], the states of the application
        :return: Transition, the transition to build
        :raises: UndefinedBrick, if the transition references an undefined brick
        :raises: UndefinedState, if the transition references an undefined state
        """
        if self.sensor not in bricks.keys():
            raise UndefinedBrick()
        if self.next_state not in states.keys():
            raise UndefinedState()
        return LogicTransition(bricks[self.transition.sensor],
                               self.transition.value, self.type,
                               bricks[self.sensor], self.value,
                               states[self.next_state])
Ejemplo n.º 6
0
    def get_contents2(self, bricks, states):
        """
         Builds the state (step 2)

        :param bricks: Map[String,Brick], the bricks of the application
        :param states: Map[String, State], the states of the application
        :return:
        :raises: UndefinedBrick, if the brick the transition operates on is not defined
        :raises: UndefinedState, if the target state is not defined

        This method builds the transition attribute.
        A 2-step build is required (due to the meta-model) to get references right while avoiding bad typing tricks
        such as passing a TransitionBuilder instead of a Transition.
        """
        if self.transition.sensor not in bricks.keys():
            raise UndefinedBrick()
        if self.state not in states.keys():
            raise UndefinedState()
        if self.transition.next_state not in states.keys():
            raise UndefinedState()
        transition = Transition(bricks[self.transition.sensor],
                                self.transition.value,
                                states[self.transition.next_state])
        states[self.state].transition = transition
Ejemplo n.º 7
0
 def get_contents(self, bricks):
     for b in self.bricks:
         if b not in bricks.keys():
             raise UndefinedBrick()
     return Printer(self.timestamp, self.pType, self.bricks)