Managing Library Protection

You can manage the protection level for a library hierarchy using a graphical interface. The protection is applied when you encrypt the library.

Note: You can manage the protection of models and other classes the same way, but the main use is for library hierarchies.

In this scenario you manage the protection of a library with two subpackages. The packages are protected as "Icon" and "Diagram"; for the full list of protection levels and explanations, see the table below.


Before you begin:
  1. Create a library with the name MyLibrary. For more information about how to create a library, see Creating a Modelica Library or Dymola Behavior Library.
  2. In that library, create two packages with the names MySubpackage1 and MySubpackage2. For more information about how to create a class of type package, see Creating an Empty Class or Extending from an Existing Class.
  1. From the Package Browser, right-click MyLibrary and select Visibility for Encryption .
  2. To display the hierarchy, expand MyLibrary.
  3. Select protection levels for the subpackages:

    By default, the protection level of all classes is Documentation.

    1. Right-click MySubpackage1 and select Icon.
    2. Right-click MySubpackage2 and select Diagram.
    In the Modelica text of the packages, the following annotations are inserted:
    Package Annotation
    MyLibrary Annotation (Protection(access=Access.documentation));
    MySubpackage1 Annotation (Protection(access=Access.icon));
    MySubpackage2 Annotation (Protection(access=Access.diagram));
  4. To encrypt the library MyLibrary, export it as a library with the option Encrypt exported data activated.

    For more information, see Exporting a Library or a Model to a Modelica File.

    The library is exported with the selected protection levels activated.

Protection levels are specified by annotations. The following table describes the result for each annotation:

Protection Annotation Result
<none>, that is, selecting Default (no setting) The protection level is set according to the enclosing class. See note 1.
Protection(Access.hide) The class is not shown anywhere (it is not possible to inspect any part of the class). See note 2.
Protection(Access.icon) The class can be instantiated and the following items of the class are accessible:
  • public parameters
  • constants
  • input and output variables
  • public connectors
  • icon annotation
  • class name
  • class description text
Protection(Access.documentation) Same as Access.icon and additional accessible item:
  • documentation annotation
This protection level is the default protection level when encrypting a class, even if not specified in the Modelica text. See note 3.
Protection(Access.diagram) Same as Access.documentation and additional accessible items:
  • diagram annotation
  • all components and connect equations that have a graphical annotation
Protection(Access.nonPackageText) Same as Access.diagram and additional accessible item (if the class is not a package):
  • the whole class definition
Note: The class definition cannot be copied.
Protection(Access.nonPackageDuplicate) Same as Access.nonPackageText and additionally (if the class is not a package) the class (or part of the class) can be copied and pasted.
Protection(Access.packageText) Same as Access.diagram (note: not including all rights of Access.nonPackageDuplicate) and additional accessible item:
  • the whole class definition
Note: The class definition cannot be copied.
Protection(Access.packageDuplicate) Same as Access.packageText and additionally the class (or part of the class) can be copied and pasted.
Notes:
  1. This setting is typically used when you want to specify that a certain class does not need a specific protection setting; the protection level set by enclosing classes are sufficient. If no relevant setting is found, the default value corresponding to Access.documentation is used when encrypting.
  2. Be careful with Protection(Access.hide). By default, Hide protected classes is activated in Me > Preferences > App Preferences > 3D Modeling > Systems Modeling and Execution > Dymola Behavior Modeling , the Editor tab, the Connection group. This option hides protected classes in the Package Browser (even before encryption). For more information, see Native Apps Preferences Guide: Editor.
  3. The generation of HTML documentation is normally performed before encryption. For this reason it is important to set the correct protection level before generating HTML documentation. For more information about generating HTML documentation, see Exporting HTML Documentation.