From 9624328ada0f4f78ad9448e13c25b53f37a99beb Mon Sep 17 00:00:00 2001 From: Yvan Lussaud Date: Fri, 9 Aug 2024 16:39:58 +0200 Subject: [PATCH] Fixed #173 Add a method RequirementAddOn.add_module(Architecture, CapellaModule) and RequirementAddOn.remove_module(Architecture, CapellaModule). --- .../Python4Capella/simplified_api/capella.py | 27 ++++++++-- .../simplified_api/capella_header.py | 3 ++ .../simplified_api/requirement.py | 21 ++++++++ .../classes/RequirementAddOn.addModule.txt | 7 +++ .../classes/RequirementAddOn.removeModule.txt | 10 ++++ .../Capella Light Metamodel.capella | 54 +++++++++++++++++-- tests/Python4CapellaTests/capella_tests.py | 14 +++++ 7 files changed, 126 insertions(+), 10 deletions(-) create mode 100644 plugins/org.eclipse.python4capella.gen/resources/customizations/classes/RequirementAddOn.addModule.txt create mode 100644 plugins/org.eclipse.python4capella.gen/resources/customizations/classes/RequirementAddOn.removeModule.txt diff --git a/plugins/Python4Capella/simplified_api/capella.py b/plugins/Python4Capella/simplified_api/capella.py index 485bddc..4abdac9 100644 --- a/plugins/Python4Capella/simplified_api/capella.py +++ b/plugins/Python4Capella/simplified_api/capella.py @@ -618,6 +618,23 @@ def get_owned_property_value_pkgs(self) -> List[PropertyValuePkg]: """ return create_e_list(self.get_java_object().getOwnedPropertyValuePkgs(), PropertyValuePkg) +class ModellingArchitecture(PropertyValuePkgContainer): + """ + Java class: org.polarsys.capella.core.data.capellacore.ModellingArchitecture + The element containing all definitions from the Operational Analysis. + The Operational Analysis aims at defining what the users of the system need to accomplish + """ + e_class = get_e_classifier("http://www.polarsys.org/capella/core/core/" + capella_version(), "ModellingArchitecture") + def __init__(self, java_object = None): + if java_object is None: + JavaObject.__init__(self, create_e_object_from_e_classifier(self.e_class)) + elif isinstance(java_object, ModellingArchitecture): + JavaObject.__init__(self, java_object.get_java_object()) + elif self.e_class.isInstance(java_object): + JavaObject.__init__(self, java_object) + else: + raise AttributeError("Passed object is not compatible with " + self.__class__.__name__ + ": " + str(java_object)) + class Diagram(JavaObject): """ A generic Capella diagram @@ -1058,7 +1075,7 @@ def set_description(self, value: str): """ self.get_java_object().setDescription(value) -class OperationalAnalysis(PropertyValuePkgContainer): +class OperationalAnalysis(ModellingArchitecture): """ Java class: org.polarsys.capella.core.data.oa.OperationalAnalysis The element containing all definitions from the Operational Analysis. @@ -1413,7 +1430,7 @@ def get_realizing_component_exchanges(self) -> List[ComponentExchange]: """ return create_e_list(self.get_java_object().getRealizingComponentExchanges(), ComponentExchange) -class SystemAnalysis(PropertyValuePkgContainer): +class SystemAnalysis(ModellingArchitecture): """ Java class: org.polarsys.capella.core.data.ctx.SystemAnalysis The element containing all definitions from the System Analysis. @@ -1670,7 +1687,7 @@ def get_involved_actors(self) -> List[SystemActor]: res.append(specific_cls(system_comp)) return res -class LogicalArchitecture(PropertyValuePkgContainer): +class LogicalArchitecture(ModellingArchitecture): """ Java class: org.polarsys.capella.core.data.la.LogicalArchitecture The element containing all definitions from the Logical Architecture. @@ -1862,7 +1879,7 @@ def get_owned_physical_link_categories(self) -> List[PhysicalLinkCategory]: """ return create_e_list(self.get_java_object().getOwnedPhysicalLinkCategories(), PhysicalLinkCategory) -class PhysicalArchitecture(PropertyValuePkgContainer): +class PhysicalArchitecture(ModellingArchitecture): """ Java class: org.polarsys.capella.core.data.pa.PhysicalArchitecture The element containing all definitions from the Physical Architecture. @@ -2116,7 +2133,7 @@ def get_allocated_physical_functions(self): """ return capella_query_by_name(self, "Allocated Physical Functions") -class EPBSArchitecture(PropertyValuePkgContainer): +class EPBSArchitecture(ModellingArchitecture): """ Java class: org.polarsys.capella.core.data.epbs.EPBSArchitecture The element containing all definitions from the End-Product Breakdown Structure. diff --git a/plugins/Python4Capella/simplified_api/capella_header.py b/plugins/Python4Capella/simplified_api/capella_header.py index 868cd5c..44a45cc 100644 --- a/plugins/Python4Capella/simplified_api/capella_header.py +++ b/plugins/Python4Capella/simplified_api/capella_header.py @@ -28,6 +28,9 @@ class EnumerationPropertyLiteral: class PropertyValuePkgContainer: pass +class ModellingArchitecture: + pass + class Diagram: pass diff --git a/plugins/Python4Capella/simplified_api/requirement.py b/plugins/Python4Capella/simplified_api/requirement.py index 415178d..b6fae88 100644 --- a/plugins/Python4Capella/simplified_api/requirement.py +++ b/plugins/Python4Capella/simplified_api/requirement.py @@ -99,6 +99,27 @@ def get_capella_types_folders(capellaElement: CapellaElement): if capella_types_folder_e_class.isInstance(extension): res.append(CapellaTypesFolder(extension)) return res + @staticmethod + def add_module(architecture: ModellingArchitecture, module: CapellaModule): + """ + Parameters: architecture: ModellingArchitecture, module: CapellaModule + """ + """ + Add the given CapellaModule to the given ModellingArchitecture + """ + architecture.get_java_object().getOwnedExtensions().add(module.get_java_object()) + @staticmethod + def remove_module(architecture: ModellingArchitecture, module: CapellaModule): + """ + Parameters: architecture: ModellingArchitecture, module: CapellaModule + """ + """ + Remove the given CapellaModule from the given ModellingArchitecture + """ + try: + architecture.get_java_object().getOwnedExtensions().remove(module.get_java_object()) + except Exception: + pass class CapellaModule(EObject): """ diff --git a/plugins/org.eclipse.python4capella.gen/resources/customizations/classes/RequirementAddOn.addModule.txt b/plugins/org.eclipse.python4capella.gen/resources/customizations/classes/RequirementAddOn.addModule.txt new file mode 100644 index 0000000..65be5ea --- /dev/null +++ b/plugins/org.eclipse.python4capella.gen/resources/customizations/classes/RequirementAddOn.addModule.txt @@ -0,0 +1,7 @@ + @staticmethod + def add_module(architecture: ModellingArchitecture, module: CapellaModule): + """ + Add the given CapellaModule to the given ModellingArchitecture + """ + architecture.get_java_object().getOwnedExtensions().add(module.get_java_object()) + diff --git a/plugins/org.eclipse.python4capella.gen/resources/customizations/classes/RequirementAddOn.removeModule.txt b/plugins/org.eclipse.python4capella.gen/resources/customizations/classes/RequirementAddOn.removeModule.txt new file mode 100644 index 0000000..ed55ee8 --- /dev/null +++ b/plugins/org.eclipse.python4capella.gen/resources/customizations/classes/RequirementAddOn.removeModule.txt @@ -0,0 +1,10 @@ + @staticmethod + def remove_module(architecture: ModellingArchitecture, module: CapellaModule): + """ + Remove the given CapellaModule from the given ModellingArchitecture + """ + try: + architecture.get_java_object().getOwnedExtensions().remove(module.get_java_object()) + except Exception: + pass + diff --git a/specification/Capella Light Metamodel/Capella Light Metamodel.capella b/specification/Capella Light Metamodel/Capella Light Metamodel.capella index 2db1621..1a59e1d 100644 --- a/specification/Capella Light Metamodel/Capella Light Metamodel.capella +++ b/specification/Capella Light Metamodel/Capella Light Metamodel.capella @@ -2104,6 +2104,14 @@ id="211dbd7b-1b4c-4d49-ae53-37a44bac41b7" name="" value="*"/> + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Python4CapellaTests/capella_tests.py b/tests/Python4CapellaTests/capella_tests.py index e95b952..b453bc3 100644 --- a/tests/Python4CapellaTests/capella_tests.py +++ b/tests/Python4CapellaTests/capella_tests.py @@ -34150,6 +34150,20 @@ def test_RequirementAddOn_get_capella_types_folders(self): tested.get_capella_types_folders(param1) pass + def test_RequirementAddOn_add_module(self): + tested = RequirementAddOn() + param1 = EPBSArchitecture() + param2 = CapellaModule() + tested.add_module(param1, param2) + pass + + def test_RequirementAddOn_remove_module(self): + tested = RequirementAddOn() + param1 = EPBSArchitecture() + param2 = CapellaModule() + tested.remove_module(param1, param2) + pass + def test_CapellaModule_owned_diagrams_getter(self): tested = CapellaModule() tested.get_owned_diagrams()