Skip to content

Commit

Permalink
Fixed #168 Improve the PVMT API.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Aug 13, 2024
1 parent f377805 commit b9a5a9a
Show file tree
Hide file tree
Showing 18 changed files with 3,226 additions and 3 deletions.
51 changes: 50 additions & 1 deletion plugins/Python4Capella/simplified_api/capella.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,42 @@ def get_owned_enumeration_property_types(self) -> List[EnumerationPropertyType]:
Returns: EnumerationPropertyType[*]
"""
return create_e_list(self.get_java_object().getOwnedEnumerationPropertyTypes(), EnumerationPropertyType)
def get_owned_property_value_by_name(self, p_v_name: str) -> PropertyValue:
"""
Parameters: PVName: String
Returns: PropertyValue
"""
for property_value in self.get_owned_property_values():
if property_value.get_name() == p_v_name:
return property_value
return None
def get_applied_property_value_by_name(self, p_v_name: str) -> PropertyValue:
"""
Parameters: PVName: String
Returns: PropertyValue
"""
for property_value in self.get_applied_property_values():
if property_value.get_name() == p_v_name:
return property_value
return None
def get_owned_property_value_group_by_name(self, p_v_g_name: str) -> PropertyValueGroup:
"""
Parameters: PVGName: String
Returns: PropertyValueGroup
"""
for property_value_group in self.get_owned_property_value_groups():
if property_value_group.get_name() == p_v_g_name:
return property_value_group
return None
def get_applied_property_value_group_by_name(self, p_v_g_name: str) -> PropertyValueGroup:
"""
Parameters: PVGName: String
Returns: PropertyValueGroup
"""
for property_value_group in self.get_applied_property_value_groups():
if property_value_group.get_name() == p_v_g_name:
return property_value_group
return None

class Constraint(CapellaElement):
"""
Expand Down Expand Up @@ -519,13 +555,18 @@ def get_value(self) -> Any:
"""
if self.java_object.eClass().getName() == "BooleanPropertyValue":
return self.get_java_object().isValue()
elif self.java_object.eClass().getName() == "EnumerationPropertyValue":
return EnumerationPropertyLiteral(self.get_java_object().getValue())
else:
return self.get_java_object().getValue()
def set_value(self, value: Any):
"""
Parameters: value: String
"""
self.get_java_object().setValue(value)
if isinstance(value, JavaObject):
self.get_java_object().setValue(value.get_java_object())
else:
self.get_java_object().setValue(value)
def get_valued_elements(self) -> List[CapellaElement]:
"""
Returns: CapellaElement[*]
Expand Down Expand Up @@ -584,6 +625,14 @@ def get_owned_literals(self) -> List[EnumerationPropertyLiteral]:
Returns: EnumerationPropertyLiteral[*]
"""
return create_e_list(self.get_java_object().getOwnedLiterals(), EnumerationPropertyLiteral)
def get_owned_literal_by_name(self, literalName: str) -> EnumerationPropertyLiteral:
"""
Parameters: PVName: String
Returns: EnumerationPropertyLiteral
"""
for literal in self.get_owned_literals():
if literal.get_name() == literalName:
return literal

class EnumerationPropertyLiteral(CapellaElement):
"""
Expand Down
112 changes: 112 additions & 0 deletions plugins/Python4Capella/simplified_api/pvmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ def __init__(self, java_object = None):
"""
JavaObject.__init__(self, java_object)
@staticmethod
def get_system_engineering(capellaElement: CapellaElement) -> SystemEngineering:
"""
"""
"""
"""
container = capellaElement.get_java_object()
if container is None:
return container
else:
system_engineering_e_class = get_e_classifier("http://www.polarsys.org/capella/core/modeller/" + capella_version(), "SystemEngineering")
if system_engineering_e_class.isInstance(container):
return SystemEngineering(container)
else:
return PVMT.get_system_engineering(JavaObject(container.eContainer()))
@staticmethod
def get_p_v_names(elem: CapellaElement) -> List[str]:
"""
Parameters: elem: CapellaElement
Expand Down Expand Up @@ -65,5 +80,102 @@ def get_p_v_group_names(elem: CapellaElement) -> List[str]:
for group in elem.get_java_object().getOwnedPropertyValueGroups():
res.append(group.getName())
return res
@staticmethod
def get_property_value_group(systemEngineering: SystemEngineering, propertyValuePackageName: str, propertyValueGroupName: str) -> PropertyValueGroup:
"""
Parameters: systemEngineering: SystemEngineering, propertyValuePackageName: String, propertyValueGroupName: String
Returns: PropertyValueGroup
"""
project = systemEngineering.get_java_object().eContainer()
for ext_package in project.getOwnedPropertyValuePkgs():
if ext_package.getName() == "EXTENSIONS":
for pv_package in ext_package.getOwnedPropertyValuePkgs():
if pv_package.getName() == propertyValuePackageName:
for pv_group in pv_package.getOwnedPropertyValueGroups():
if pv_group.getName() == propertyValueGroupName:
return PropertyValueGroup(pv_group)
@staticmethod
def get_property_value(systemEngineering: SystemEngineering, propertyValuePackageName: str, propertyValueGroupName: str, propertyValueName: str) -> PropertyValue:
"""
Parameters: systemEngineering: SystemEngineering, propertyValuePackageName: String, propertyValueGroupName: String, propertyValueName: String
Returns: PropertyValue
"""
pvg = PVMT.get_property_value_group(systemEngineering, propertyValuePackageName, propertyValueGroupName)
if pvg:
for pv in pvg.get_owned_property_values():
if pv.get_name() == propertyValueName:
return pv
@staticmethod
def get_enumeration_property_type(systemEngineering: SystemEngineering, propertyValuePackageName: str, typeName: str) -> EnumerationPropertyType:
"""
Parameters: systemEngineering: SystemEngineering, propertyValuePackageName: String, typeName: String
Returns: EnumerationPropertyType
"""
project = systemEngineering.get_java_object().eContainer()
for ext_package in project.getOwnedPropertyValuePkgs():
if ext_package.getName() == "EXTENSIONS":
for pv_package in ext_package.getOwnedPropertyValuePkgs():
if pv_package.getName() == propertyValuePackageName:
for type in pv_package.getOwnedEnumerationPropertyTypes():
if type.getName() == typeName:
return EnumerationPropertyType(type)
@staticmethod
def get_applied_property_value(elem: CapellaElement, propertyValuePackageName: str, propertyValueGroupName: str, propertyValueName: str) -> PropertyValue:
"""
Parameters: elem: CapellaElement, propertyValuePackageName: String, propertyValueGroupName: String, propertyValueName: String
Returns: PropertyValue
"""
"""
Parameters: elem: CapellaElement, propertyValuePackageName: String, propertyValueGroupName: String, propertyValueName: String
Returns: PropertyValue
"""
systemEngineering = PVMT.get_system_engineering(elem)
pv = PVMT.get_property_value(systemEngineering, propertyValuePackageName, propertyValueGroupName, propertyValueName)
pvg = PropertyValueGroup(pv.get_java_object().eContainer())
if pvg:
for applied_pvg in elem.get_applied_property_value_groups():
if applied_pvg.get_applied_property_value_groups().contains(pvg):
for owned_pv in applied_pvg.get_owned_property_values():
if owned_pv.get_applied_property_values().contains(pv):
return owned_pv
@staticmethod
def get_or_apply_property_value_group(elem: CapellaElement, propertyValuePackageName: str, propertyValueGroupName: str) -> PropertyValue:
"""
Parameters: elem: CapellaElement, propertyValuePackageName: String, propertyValueGroupName: String
Returns: PropertyValue
"""
systemEngineering = PVMT.get_system_engineering(elem)
pvg = PVMT.get_property_value_group(systemEngineering, propertyValuePackageName, propertyValueGroupName)
if pvg:
for applied_pvg in elem.get_applied_property_value_groups():
if applied_pvg.get_applied_property_value_groups().contains(pvg):
return applied_pvg
pvg_to_apply = PropertyValueGroup()
pvg_to_apply.set_name(propertyValuePackageName + "." + propertyValueGroupName)
pvg_to_apply.get_applied_property_value_groups().add(pvg)
elem.get_applied_property_value_groups().add(pvg_to_apply)
elem.get_owned_property_value_groups().add(pvg_to_apply)
for pv in pvg.get_owned_property_values():
pv_to_apply = PropertyValue(None, pv.get_java_object().eClass().getName())
pv_to_apply.set_name(pv.get_name())
pv_to_apply.get_applied_property_values().add(pv)
pv_to_apply.set_value(pv.get_value())
if pv.get_java_object().eClass().getName() == "EnumerationPropertyValue":
pv_to_apply.get_java_object().setType(pv.get_java_object().getType())
pvg_to_apply.get_owned_property_values().add(pv_to_apply)
@staticmethod
def remove_applied_property_value_group(elem: CapellaElement, propertyValuePackageName: str, propertyValueGroupName: str):
"""
Parameters: elem: CapellaElement, propertyValuePackageName: String, propertyValueGroupName: String
"""
systemEngineering = PVMT.get_system_engineering(elem)
pvg = PVMT.get_property_value_group(systemEngineering, propertyValuePackageName, propertyValueGroupName)
if pvg:
for applied_pvg in elem.get_applied_property_value_groups():
if applied_pvg.get_applied_property_value_groups().contains(pvg):
elem.get_applied_property_value_groups().remove(applied_pvg)
elem.get_owned_property_value_groups().remove(applied_pvg)
EObject.delete_e_object(applied_pvg)
break


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def get_applied_property_value_by_name(self, p_v_name: str) -> PropertyValue:
for property_value in self.get_applied_property_values():
if property_value.get_name() == p_v_name:
return property_value
return None

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def get_applied_property_value_group_by_name(self, p_v_g_name: str) -> PropertyValueGroup:
for property_value_group in self.get_applied_property_value_groups():
if property_value_group.get_name() == p_v_g_name:
return property_value_group
return None

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def get_owned_property_value_by_name(self, p_v_name: str) -> PropertyValue:
for property_value in self.get_owned_property_values():
if property_value.get_name() == p_v_name:
return property_value
return None

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def get_owned_property_value_group_by_name(self, p_v_g_name: str) -> PropertyValueGroup:
for property_value_group in self.get_owned_property_value_groups():
if property_value_group.get_name() == p_v_g_name:
return property_value_group
return None

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def get_owned_literal_by_name(self, literalName: str) -> EnumerationPropertyLiteral:
for literal in self.get_owned_literals():
if literal.get_name() == literalName:
return literal

Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
def __init__(self, java_object = None):
JavaObject.__init__(self, java_object)
@staticmethod
def get_system_engineering(capellaElement: CapellaElement) -> SystemEngineering:
"""
"""
container = capellaElement.get_java_object()
if container is None:
return container
else:
system_engineering_e_class = get_e_classifier("http://www.polarsys.org/capella/core/modeller/" + capella_version(), "SystemEngineering")
if system_engineering_e_class.isInstance(container):
return SystemEngineering(container)
else:
return PVMT.get_system_engineering(JavaObject(container.eContainer()))

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@staticmethod
def get_applied_property_value(elem: CapellaElement, propertyValuePackageName: str, propertyValueGroupName: str, propertyValueName: str) -> PropertyValue:
"""
Parameters: elem: CapellaElement, propertyValuePackageName: String, propertyValueGroupName: String, propertyValueName: String
Returns: PropertyValue
"""
systemEngineering = PVMT.get_system_engineering(elem)
pv = PVMT.get_property_value(systemEngineering, propertyValuePackageName, propertyValueGroupName, propertyValueName)
pvg = PropertyValueGroup(pv.get_java_object().eContainer())
if pvg:
for applied_pvg in elem.get_applied_property_value_groups():
if applied_pvg.get_applied_property_value_groups().contains(pvg):
for owned_pv in applied_pvg.get_owned_property_values():
if owned_pv.get_applied_property_values().contains(pv):
return owned_pv

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@staticmethod
def get_enumeration_property_type(systemEngineering: SystemEngineering, propertyValuePackageName: str, typeName: str) -> EnumerationPropertyType:
project = systemEngineering.get_java_object().eContainer()
for ext_package in project.getOwnedPropertyValuePkgs():
if ext_package.getName() == "EXTENSIONS":
for pv_package in ext_package.getOwnedPropertyValuePkgs():
if pv_package.getName() == propertyValuePackageName:
for type in pv_package.getOwnedEnumerationPropertyTypes():
if type.getName() == typeName:
return EnumerationPropertyType(type)

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@staticmethod
def get_or_apply_property_value_group(elem: CapellaElement, propertyValuePackageName: str, propertyValueGroupName: str) -> PropertyValue:
systemEngineering = PVMT.get_system_engineering(elem)
pvg = PVMT.get_property_value_group(systemEngineering, propertyValuePackageName, propertyValueGroupName)
if pvg:
for applied_pvg in elem.get_applied_property_value_groups():
if applied_pvg.get_applied_property_value_groups().contains(pvg):
return applied_pvg
pvg_to_apply = PropertyValueGroup()
pvg_to_apply.set_name(propertyValuePackageName + "." + propertyValueGroupName)
pvg_to_apply.get_applied_property_value_groups().add(pvg)
elem.get_applied_property_value_groups().add(pvg_to_apply)
elem.get_owned_property_value_groups().add(pvg_to_apply)
for pv in pvg.get_owned_property_values():
pv_to_apply = PropertyValue(None, pv.get_java_object().eClass().getName())
pv_to_apply.set_name(pv.get_name())
pv_to_apply.get_applied_property_values().add(pv)
pv_to_apply.set_value(pv.get_value())
if pv.get_java_object().eClass().getName() == "EnumerationPropertyValue":
pv_to_apply.get_java_object().setType(pv.get_java_object().getType())
pvg_to_apply.get_owned_property_values().add(pv_to_apply)

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@staticmethod
def get_property_value(systemEngineering: SystemEngineering, propertyValuePackageName: str, propertyValueGroupName: str, propertyValueName: str) -> PropertyValue:
pvg = PVMT.get_property_value_group(systemEngineering, propertyValuePackageName, propertyValueGroupName)
if pvg:
for pv in pvg.get_owned_property_values():
if pv.get_name() == propertyValueName:
return pv

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@staticmethod
def get_property_value_group(systemEngineering: SystemEngineering, propertyValuePackageName: str, propertyValueGroupName: str) -> PropertyValueGroup:
project = systemEngineering.get_java_object().eContainer()
for ext_package in project.getOwnedPropertyValuePkgs():
if ext_package.getName() == "EXTENSIONS":
for pv_package in ext_package.getOwnedPropertyValuePkgs():
if pv_package.getName() == propertyValuePackageName:
for pv_group in pv_package.getOwnedPropertyValueGroups():
if pv_group.getName() == propertyValueGroupName:
return PropertyValueGroup(pv_group)

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@staticmethod
def remove_applied_property_value_group(elem: CapellaElement, propertyValuePackageName: str, propertyValueGroupName: str):
systemEngineering = PVMT.get_system_engineering(elem)
pvg = PVMT.get_property_value_group(systemEngineering, propertyValuePackageName, propertyValueGroupName)
if pvg:
for applied_pvg in elem.get_applied_property_value_groups():
if applied_pvg.get_applied_property_value_groups().contains(pvg):
elem.get_applied_property_value_groups().remove(applied_pvg)
elem.get_owned_property_value_groups().remove(applied_pvg)
EObject.delete_e_object(applied_pvg)
break

Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
def get_value(self) -> Any:
if self.java_object.eClass().getName() == "BooleanPropertyValue":
return self.get_java_object().isValue()
elif self.java_object.eClass().getName() == "EnumerationPropertyValue":
return EnumerationPropertyLiteral(self.get_java_object().getValue())
else:
return self.get_java_object().getValue()
def set_value(self, value: Any):
self.get_java_object().setValue(value)
if isinstance(value, JavaObject):
self.get_java_object().setValue(value.get_java_object())
else:
self.get_java_object().setValue(value)

Loading

0 comments on commit b9a5a9a

Please sign in to comment.