예제 #1
0
 def execute(self, state: State) -> State:
     fm = copy.deepcopy(state.feature_model)
     parent = fm.get_feature_by_name(self.parent_name)
     parent_relation = Relation(parent=parent, children=[], card_min=0, card_max=0)
     feature = Feature(self.feature_name, [parent_relation])
     optional_relation = Relation(parent=parent, children=[feature], card_min=0, card_max=1)
     parent.add_relation(optional_relation)
     fm.features.append(feature)
     fm.relations.extend([parent_relation, optional_relation])
     fm.features_by_name[feature.name] = feature
     return FMState(fm, state.configurations)
예제 #2
0
 def execute(self, state: State) -> State:
     fm = copy.deepcopy(state.feature_model)
     parent = fm.get_feature_by_name(self.parent_name)
     parent_relation1 = Relation(parent=parent, children=[], card_min=0, card_max=0)
     child1 = Feature(self.feature_name1, [parent_relation1])
     parent_relation2 = Relation(parent=parent, children=[], card_min=0, card_max=0)
     child2 = Feature(self.feature_name2, [parent_relation2])
     alternative_relation = Relation(parent=parent, children=[child1, child2], card_min=1, card_max=1)
     parent.add_relation(alternative_relation)
     fm.features.extend([child1, child2])
     fm.relations.extend([parent_relation1, parent_relation2, alternative_relation])
     fm.features_by_name[child1.name] = child1
     fm.features_by_name[child2.name] = child2
     return FMState(fm, state.configurations)
    def _read_features(self, root_tree, parent: Feature) -> (List[Feature], List[Relation]):
        features = []
        children = []
        relations = []
        for child in root_tree:
            if not child.tag == "graphics":
                #children = []
                is_abstract = False
                if "abstract" in child.attrib and child.attrib['abstract']:
                    is_abstract = True
                feature = Feature(name=child.attrib['name'], relations=[], parent=parent, is_abstract=is_abstract)
                #r = Relation(parent=parent, children=[], card_min=0, card_max=0)
                #feature.add_relation(r)   # Relation for the parent.
                features.append(feature)
                children.append(feature)
                #relations.append(r)
                if root_tree.tag == "and":
                    if "mandatory" in child.attrib: # Mandatory feature
                        r = Relation(parent=parent, children=[feature], card_min=1, card_max=1)
                        parent.add_relation(r)
                        relations.append(r)
                    else:   # Optional feature
                        r = Relation(parent=parent, children=[feature], card_min=0, card_max=1)
                        parent.add_relation(r)
                        relations.append(r)

                if child.tag == "alt":
                    (alt_children, direct_children, children_relations) = self._read_features(child, feature)
                    r = Relation(parent=feature, children=direct_children, card_min=1, card_max=1)
                    feature.add_relation(r)
                    features.extend(alt_children)
                    relations.append(r)
                    relations.extend(children_relations)
                elif child.tag == "or":
                    (or_children, direct_children, children_relations) = self._read_features(child, feature)
                    r = Relation(parent=feature, children=direct_children, card_min=1, card_max=len(direct_children))
                    feature.add_relation(r)
                    features.extend(or_children)
                    relations.append(r)
                    relations.extend(children_relations)
                elif child.tag == "and":
                    (and_children, direct_children, children_relations) = self._read_features(child, feature)
                    features.extend(and_children)
                    relations.extend(children_relations)
        return (features, children, relations)
예제 #4
0
 def execute(self, state: 'State') -> 'State':
     fm = copy.deepcopy(state.feature_model)
     relation = Relation(parent=None, children=[], card_min=0, card_max=0)
     root_feature = Feature(self.feature_name, [relation])
     fm.root = root_feature
     fm.features = [root_feature]
     fm.relations = [relation]
     fm.features_by_name[root_feature.name] = root_feature
     return FMState(fm, state.configurations)
예제 #5
0
 def execute(self, state: State) -> State:
     fm = copy.deepcopy(state.feature_model)
     parent = fm.get_feature_by_name(self.parent_name)
     parent_relation = Relation(parent=parent, children=[], card_min=0, card_max=0)
     child = Feature(self.feature_name, [parent_relation])
     relation = next(r for r in parent.get_relations() if r.is_alternative())
     relation.add_child(child)
     fm.features.append(child)
     fm.relations.append(parent_relation)
     fm.features_by_name[child.name] = child
     return FMState(fm, state.configurations)