Ejemplo n.º 1
0
 def toElement(self):
     to_ret = Element("skiros:" + self.__class__.__name__, self._label)
     to_ret.setProperty("skiros:hasSubject", self._subject_key)
     to_ret.setProperty("skiros:hasObject", self._object_key)
     to_ret.setProperty("skiros:appliedOnType", self._owl_label)
     to_ret.setProperty("skiros:desiredState", self._desired_state)
     return to_ret
Ejemplo n.º 2
0
 def setTrue(self, ph, wmi):
     self._params = ph
     self._wm = wmi
     subj = self._params.getParamValue(self._subject_key)
     self._has_cache = True
     self._cache = deepcopy(subj)
     #print subj.printState(True)
     if subj.getIdNumber() < 0 and self._desired_state:
         self._cache_new = Element(subj._type, "==FAKE==")
         self._wm.add_element(self._cache_new, ":Scene-0", "contain")
         #print self._wm.printModel()
         self._params.specify(self._subject_key, self._cache_new)
         self._cache_new = deepcopy(self._cache_new)
     elif subj.getIdNumber() >= 0 and not self._desired_state:
         self._wm.remove_element(subj._id)
         subj._id = ""
         self._cache_new = subj
         self._params.specify(self._subject_key, self._cache_new)
     else:
         self._cache_new = self._cache
     return True
Ejemplo n.º 3
0
 def setTrue(self, ph, wmi):
     self._params = ph
     self._wm = wmi
     subj = self._params.getParamValue(self._subject_key)
     self._has_cache = True
     self._cache = deepcopy(subj)
     if subj.getIdNumber() < 0 and self._desired_state:
         self._cache_new = Element(subj._type, "==FAKE==")
         self._params.specify(self._subject_key, self._cache_new)
         self._cache_new = deepcopy(self._cache_new)
     elif subj.getIdNumber() >= 0 and not self._desired_state:
         subj._id = ""
         self._cache_new = subj
         self._params.specify(self._subject_key, self._cache_new)
     else:
         self._cache_new = self._cache
     return True
Ejemplo n.º 4
0
 def toElement(self):
     to_ret = Element("skiros:" + self.__class__.__name__, self._label)
     to_ret.setProperty("skiros:hasSubject", self._subject_key)
     to_ret.setProperty("skiros:desiredValue", self._value)
     return to_ret
Ejemplo n.º 5
0
class ConditionGenerate(ConditionBase):
    # TODO: understand: any difference with isSpecified?
    def __init__(self, clabel, subj, desired_state):
        self._subject_key = subj
        self._label = clabel
        self._desired_state = desired_state
        self._params = None
        self._setDescription()

    def isEqual(self, other):
        if isinstance(other, ConditionGenerate):
            return self._subject_key == other._subject_key and self._desired_state == other._desired_state
        else:
            return False

    def hasConflict(self, other):
        if isinstance(other, ConditionGenerate):
            return self._subject_key == other._subject_key and self._desired_state != other._desired_state
        else:
            return False

    def _setDescription(self):
        self._description = "[{}] {} ({})".format(self._label,
                                                  self._subject_key,
                                                  self._desired_state)

    def evaluate(self, ph, wmi):
        self._params = ph
        self._wm = wmi
        subj = self._params.getParamValue(self._subject_key)
        if subj.getIdNumber() >= 0 and self._desired_state:
            return True
        elif subj.getIdNumber() < 0 and not self._desired_state:
            return True
        else:
            return False

    def setTrue(self, ph, wmi):
        self._params = ph
        self._wm = wmi
        subj = self._params.getParamValue(self._subject_key)
        self._has_cache = True
        self._cache = deepcopy(subj)
        #print subj.printState(True)
        if subj.getIdNumber() < 0 and self._desired_state:
            self._cache_new = Element(subj._type, "==FAKE==")
            self._wm.add_element(self._cache_new, ":Scene-0", "contain")
            #print self._wm.printModel()
            self._params.specify(self._subject_key, self._cache_new)
            self._cache_new = deepcopy(self._cache_new)
        elif subj.getIdNumber() >= 0 and not self._desired_state:
            self._wm.remove_element(subj._id)
            subj._id = ""
            self._cache_new = subj
            self._params.specify(self._subject_key, self._cache_new)
        else:
            self._cache_new = self._cache
        return True

    def revert(self, ph, wmi):
        if self._has_cache:
            self._params = ph
            self._wm = wmi
            #print self._description + " {}".format(self._cache_new.printState())
            if self._cache_new.getIdNumber() >= 0 and self._cache.getIdNumber(
            ) < 0:
                self._wm.remove_element(self._cache_new._id)
            elif self._cache_new.getIdNumber() < 0 and self._cache.getIdNumber(
            ) >= 0:
                self._wm.add_element(self._cache, ":Scene-0", "contain")
            self._params.specify(self._subject_key, self._cache)
            self._has_cache = False
            return True
        return False

    def setDesiredState(self, ph):
        return

    def toElement(self):
        to_ret = Element("skiros:" + self.__class__.__name__, self._label)
        to_ret.setProperty("skiros:hasSubject", self._subject_key)
        to_ret.setProperty("skiros:desiredState", self._desired_state)
        return to_ret
Ejemplo n.º 6
0
 def toElement(self):
     to_ret = Element("skiros:" + self.__class__.__name__, self._label)
     to_ret.setProperty("skiros:desiredState", self._desired_state)
     return to_ret