Filters
[Previous]  [Next] 
|
User Manual [Previous]  [Next] FiltersA filter directive in Umple can be used to select only a certain part of a model (i.e. a set of classes including their associations) and ignore the rest. It is particularly designed to allow creation of different diagrams from the same model. However it could also be as a way of building a particular version of the system that only has certain features. It is one of Umple's separation of concerns mechanisms. There are two types of filter statements, named and unnamed. An unnamed filter statement is active by default, and tells the system to include only certain indicated classes (multiple such filters are shown in the example below). A named filter statement is ignored until activated with an includeFilter statement (the example below shows two named filters appearing after the Filter 7 comment). Filters can be used to describe a particular diagram (or system version). There can be any number of named filters, but only one unnamed filter should be active at one time.
Within a filter directive, one can specify
Consider wrapping filter statements within mixsets. This will allow you to turn on and off various filters using command line arguments. Load the example below into UmpleOnline and uncomment any of the filter statements, one at at a time, to see the effect of filtering. The comment just before each filter statement describes the effect. Note that the named filters described as Filter 7 have been left uncommented as they are ignored until the un-named filter following them is activated. Example// Example to demonstrate filters. Uncomment one of // the filters shown below to display a different // diagram, or generate a different subset of the // code // This model describes abstract art consisting of // various shapes connected in 3-D space, some // of which can contain others. // Filter 1. Show only Shape3D // filter {include Shape3D;} // Filter 2: Show classes connected to Model3D with // one hop // filter {include Model3D; hops {association 1;}} // Filter 3: Show classes related to qualities // filter {namespace qualities ;} // Filter 4: Show Shape3D, its subclasses and all // their connections // filter {include Shape3D; hops {sub 1;}} // Filter 5: Including also includes parents // filter { include Cube;} // Filter 6: Show two classes and their neighbours // filter {include Surface, Model3D; hops {association 1;}} // Filters 7: Named filters and use of the named filter filter 7 {include Connector; hops {association 1;}} filter 7a {include Cube;} // includes its parents // filter {includeFilter 7,7a;} // Filters 8: Including classes that are associated // will always show the associations // filter { include Colour, SurfaceQuality;} // Filter 9: Use of patterns //filter { include M????3D,*Polyhedron;} // Filter 10: Excluding those that start with P (except superclasses) // filter { include ~P*;} class Point3D { Double x; Double y; Double z; } class Model3D { depend Qualities.*; depend Shapes.*; name; 1 -- * Shape3D; 1 -- * Connector; } namespace Qualities; class Colour { Integer red; Integer green; Integer blue; } class SurfaceQuality { * -> 1 Colour; Float reflectance; Float transparency; } namespace Shapes; // Shape3Ds are nodes, they can also contain other // Models inside themselves. class Shape3D { // All surfaces, points, connections // are relative to the centre which acts // as the Shapes origin. // The centre also positions the shape in 3-space. * -> 1 Point3D centre; // An Internal 3D model appears inside a Shape3D // All points are relative to the shape's centre 0..1 containingShape -<@> 0..1 Model3D internalModel; } // A surface is used to describe the shape // of one of the sides of a polyhedron // points are relative to the centre of the // polyhedron. The points must fall on some // 3D plane. class Surface { * -> * Point3D; * -> 1 SurfaceQuality; } // Connectors are sticks connecting 3D Shapes class Connector { * -> 2 Point3D ends; * -- 2 Shape3D connectedShapes; Double radius; * -- 1 SurfaceQuality; } class Sphere { isA Shape3D; Double radius; * -> 1 SurfaceQuality; } class Polyhedron { depend Qualities.*; isA Shape3D; 1 -- * Surface; } class RegularPolyhedron { isA Polyhedron; } class Cube { isA RegularPolyhedron; } strictness ignore 42; // hide namespace warnings Load the above code into UmpleOnline Syntaxassociation : [=modifier:immutable]? [[associationEnd]] [=arrow:--  |->  |<-  |><  |<@>-  |-<@>] [[associationEnd]] ; filter : filter  ( [filterName]  )? {  ([[filterStatement]]  )* } filterStatement- : [[filterCombinedValue]] | [[filterNamespace]] | [[filterValue]] | [[hops]] hops- : hops {([[super]] | [[sub]] | [[association]])*} filterValue : include ([classname]) ( , [classname] )*; super : super [superNum]; sub : sub [subNum]; association : association [associationNum]; filterNamespace : namespace [Namespace] (, [Namespace])* ; filterCombinedValue : includeFilter ([filterName]) ( , [filterName] )*; |