Example code

An example here is provided to demonstrate the definition and usage of a custom import filter.

Documentation for the example

As it is briefly described here, import filters can be used to drive the import process by selecting which SubSystem blocks should be imported as the a leaf of the hierarchy tree. Using filters the internal blocks of the filtered SubSystems will not be present in the imported EMF model. This approach is useful when certain blocks - based on their parameter values and properties - are not important from a certain aspect.

For an import job arbitrary number of filters can be registered.

In the following we discuss the definition/usage of an import filter using the uploaded example source code.

Create an Eclipse plug-in project

Filters are registered to Massif using the extension mechanism of Eclipse. To use this platform service, we created an Eclipse plug-in project, the example project it is called hu.bme.mit.massif.examples.filter.

We added the following projects to the list of required bundles in the project’s MANIFEST.MF file:

  • hu.bme.mit.massif.simulink.api

  • hu.bme.mit.massif.communication

Create an extension

We created a filter extension to the extension point with ID hu.bme.mit.massif.simulink.api.import.filters. (See plugin.xml). We provided a unique identifier and created an implementation class to the interface IBlockImportFilter called MaskFilter.

Implement the filter interface

Due to technical requirements, a public constructor without parameters must be implemented in the filter class (can have an empty body, like in the example).

Additionally, there are 3 methods in the IBlockImportFilter interface that has to be overridden:

  • getName(): This method should return the name of the filter as a String. In the example it is MaskFilter.

  • getDescription(): Returns a (short) explanation about the function and purpose of the filter.

  • filter(MatlabCommandFactory commandFactory, String blockFQN): Returns a Boolean deciding whether the internal blocks of the SubSystem block with the fully qualified name blockFQN should be ignored/filtered (value true is returned) or not (value false is returned). The received commandFactory can be used to execute commands within Matlab, allowing the filter to query the parameters of the blocks.

Usage of the filter

When the filter is successfully created and the plug-in is loaded and started within Eclipse, the filter appears in the preference page under Window/Preferences/Simulink Preferences/Model Import Preferences. Then, like the inbuilt filters, it can be selected using a checkbox. The filter is also registered to the import popup window.