Fetch Color, Border Color properties of ports/components

Hi,

I am trying to fetch ‘Style’ attributes of elements like color, border color, label color etc which are visible within ‘Properties’ tab of an element after selecting the element in the diagram, but I couldn’t find any inbuilt function or couldn’t find any such way using interpreter. Could anyone help me out with this?

Thanks,

You can have a look at this thread, it explain most methods you can use to get/set colors. In this thread you will have more context on how to get the diagram elements. Finally this thread focus more on layout but might also be interesting.

If you need more help let me know.

1 Like

Thanks @YvanLussaud, I’ve tried with the inputs provided in the mentioned resources.

While I successfully retrieved the desired properties, I encountered difficulty in filtering the properties exclusively for physical ports. To inspect which element properties were being considered, I attempted to print all the elements. This revealed that elements such as physical ports, physical components, and physical links were all being printed. Although I used a for loop to fetch general properties like names and descriptions for physical ports [se.get_physical_architecture().get_all_contents_by_type(PhysicalPort)], employing methods like get_representing_diagrams() , getRepresentation() , and getRepresentationElements() resulted in fetching all other elements too (like links, components etc). Unfortunately, I am struggling to filter the physical ports based on their class name.

Additionally, I’ve observed that the color properties (RGB values) I successfully fetched are duplicated, and the ports also appear to be duplicated. I’m uncertain whether these ports originate from a single diagram or if they are being fetched from multiple diagrams. I am working on [PAB] diagram right now. I have Capella 1.4.2 version installed. Do you have any suggestions on how I can exclusively retrieve the properties for the desired port or select only the desired elements from the diagram?

Also, I am looking to fetch the color of the ports like yellow, blue, green etc. Any suggestions on how to fetch the string value of the color?

You can use the following code to check if a given Java Object is a PhysicalPort:

e_class = get_e_classifier("http://www.polarsys.org/capella/core/cs/" + capella_version(), "PhysicalPort")
java_object = PhysicalPort().get_java_object()
print(e_class.isInstance(java_object))

Colors only exists at the Java level, so if they are duplicated it probably comes from the Java API. I think each customized color has its own instance created when the model is loaded.
For PhysicalPorts they might only be duplicated at the Python level. I noticed some unexpected behavior and opened two issues one for hash and one for equals methods that should be implemented/double checked. To check if two Python object reference the same Java Object you can use the following code:

print(port1.get_java_object().toString())
print(port2.get_java_object().toString())

You should see the memory address ater the @, if they are the same it’s the same object.

A sample code to get a representation and list its PhysicalPort

#(hardcoded) gets a DRepresentation Descriptor for the first diagram of the first function....
diagram = se.get_all_contents_by_type(SystemFunction)[1].get_representing_diagrams()[0]
#gets the representation
representation = diagram.get_java_object().getRepresentation()

physical_port_e_class = get_e_classifier("http://www.polarsys.org/capella/core/cs/" + capella_version(), "PhysicalPort")

for repElement in representation.getRepresentationElements():
   capella_element = repElement.getTarget()
    if physical_port_e_class.isInstance(capella_element):
        print(capella_element.getName())

The getTarget() method navigates from the repesentation element (graphical element)
to its semantic element, here a Capella element.

I don’t think you will be able to get the String representation of a Color without some hardcoded values. You can have a look at this class for HTML values.

Thanks @YvanLussaud for the detailed explanation

In the get_representing_digrams()[0] method, does ‘0’ indicate the 0th index element from the list of all diagrams in the model i.e. the first diagram?

Most of the elements in my case are repeated in several diagrams and some elements are unique to one specific diagram, which is causing duplication and confusion

In my case, I think I require a way to fetch elements from the diagram rather than fetching elements and then fetching their associated diagrams which I have been trying to do until now. At present, the basic element properties are fetched without any trouble, but when the diagram methods are used to fetch the style properties, that is when there is a duplication issue and a mismatch between the capella element associated basic properties and style properties occurs.

To change my approach, I have first tried fetching all the diagrams in the model (figured it out), and now I want to fetch desired Capella elements, for e.g. ports from the diagrams (need assistance), followed by their basic properties (figured it out) and then their style properties (figured it out). Is there any way to do it? or any other better way to solve my query?

Also, is there any resource to better understand how the different diagram methods work?

  1. It gets the first diagram where the second contained SystemFunction is the target of the diagram. It’s not the list of elements visible on a diagram.

  2. representation.getRepresentationElements() gets the list of all represented element on a diagram. It’s the list of graphical element, and calling getTarget() on it gets the semantic element. In the case of Capella the semantic element is a CapellaElement.

  3. If you want the list of semantic elements represented on the diagram you should use 2). I don’t understand where is the problem if you already have the diagram. A diagram is a representation.

For more implementation details you can check Capella and Sirius metamodels:

  • For Capella, you can check its metamodels available here. You can use Ecore Tools to create a graphical representation.

  • Capella is build on top of Sirius, it provides graphical representations. Sirius also have its own metamodels:

Let me know if you more help. You can also share a small portion of your code and mayde the corresponding error if any, so I can better understand your issue.