pxDoc - Common Libraries and Plugins
- Importing sources into your workspace
- Common Services / org.pragmaticmodeling.pxdoc.common.lib
- EMF Services / org.pragmaticmodeling.pxdoc.emf.lib
- Diagram Services / org.pragmaticmodeling.pxdoc.diagrams.lib
- Images Services / org.pragmaticmodeling.pxdoc.images.lib
pxDoc Common Libraries and Plugins are a set of pxDoc Modules and/or Java classes or interfaces providing useful capabilities reusable in any pxDoc Generator. Among others, you can:
- query and include diagrams from your models,
- provide generic templates for EMF model,
- manipulate images (convert to AWT, split large images on several pages...)
- ...
The language renderers are part of the pxDoc common plugins but they are described in a dedicated section.
Importing sources into your workspace
You can of course import the common libraries in your workspace to get a view on the common Modules and libraries included in pxDoc
Common Services / org.pragmaticmodeling.pxdoc.common.lib
CommonServices.pxdoc Module
The CommonServices.pxdoc module provides generic templates and functions that can be used by every documentation generator:
CommonServices setup OPTIONAL - When using the CommonServices module in your generator, you can inject your custom instance of IDescriptionProvider (see example below). |
The IDescriptionProvider Interface
Among all properties that an object can hold, its human readable descriptions play a particular role. They are usually generated early when documenting an object, while other business properties are treated differently in following document sections. The IDescriptionProvider interface gives the ability to return a description for every object processed by a pxDoc generator, as well as the expected description format (e.g., html, raw text, markdown...) It is also responsible to provide a valid bookmark id for every object processed during generation, and decide which objects should be generated with a bookmark. |
The class DefaultDescriptionProvider is the default implementation of IDescriptionProvider. It returns null as a description for every object, but is able to generate valid bookmarks for every object.
If you plan to use the CommonServices module, you will need to :
- provide your own IDescriptionProvider by subclassing DefaultDescriptionProvider and provide your own implementations of the getDescription*(*) methods.
- inject your IDescriptionProvider instance to the CommonServices when starting the generation (in the root template):
root template main(Object model) { // Commons lib configuration : set a description provider able to get information about object description descriptionProvider = new MyDescriptionProvider(this) document { // content... } }
EMF Services / org.pragmaticmodeling.pxdoc.emf.lib
The EmfServices module is a set of templates and functions that allow to generate documentation for any EMF EObject. It takes benefit of the reflective EMF API to transform EObjects into documentation. It defines two ways of EObject-to-doc transformation:
You can get your documentation for an EObject by invoking the genericDoc template: var int level = 1 var boolean recursive = true apply genericDoc(anEObject, DocKind.^table, level, recursive) With:
And because some EObject's attributes are too technical, or rarely/never used, the EmfServices module provide a way to filter some EStructuralFeature from the generation. This is the role of the field excludedFeatures, which you can access the following way: root template main(Object model) { // exclude some EClasses excludedEClasses += EcorePackage.Literals.EANNOTATION // exclude EStructualFeatures excludedFeatures += EcorePackage.Literals.ECLASSIFIER__DEFAULT_VALUE excludedFeatures += EcorePackage.Literals.EMODEL_ELEMENT__EANNOTATIONS document { // content... } } |
The EmfServices.pxdoc files contains comments to explain each template. Do not hesitate to have a look at it.
You can also refer to the EMF Example to see how these templates can be used.
EmfServices setup
OPTIONAL - When using the EmfServices module in your generator, you can inject your custom instances of:
- labelProvider = myLabelProvider
- contentProvider = myContentProvider
OPTIONAL - You can also define filters to exclude some model elements or features from the generation, by adding EClass or EStructuralFeature to the two following sets:
- excludedEClasses += MyEmfPackage.Literals.MY_CLASS
- excludedFeatures += MyEmfPackage.Literals.MY_CLASS__FEATURE
Diagram Services / org.pragmaticmodeling.pxdoc.diagrams.lib
pxDoc Diagrams metamodel
A very simple EMF metamodel has been defined to manipulate diagrams in pxDoc. It is composed of a root object Diagrams, which contains a list of Diagram.
pxDoc Diagrams runtime
The diagrams library provides a set of interfaces to query diagrams from an object.
The diagrams library provides a set of interfaces to query diagrams from an object:
The Diagram library provides useful templates to include diagrams. You can also find samples in the examples provided with the pxDoc enablers |
DiagramServices.pxdoc Module
Diagram queries with queryDiagrams(Object)
Samples of queries:
// diagrams owned by the 'model' object var List<Diagram> ownedDiagrams = queryDiagrams(model).execute; // all diagrams owned directly and indirectly by the 'model' object var allOwnedDiagrams = queryDiagrams(model).searchNested.execute; // diagrams owned by the 'model' object, with some content var ownedNonEmptyDiagrams = queryDiagrams(model).notEmpty.execute; // look for a diagram owned by 'model' and named 'A diagram name' var diagramsByName = queryDiagrams(model).name('A diagram name').execute; // look for a diagram owned by 'model' with name staring with 'ABC' var diagramsByNameStartingWith = queryDiagrams(model).nameStartsWith('ABC').execute; // diagrams by type var diagramsByType_CDB = queryDiagrams(model).type('CDB').execute; var diagramsByType_ES = queryDiagrams(model).type('ES').execute; var diagramsByType_CDI = queryDiagrams(model).type('CDI').execute; // diagrams with type 'CDB' and name starting with 'MyString' var cdbStartingWithMyString = queryDiagrams(model).type('CDB').nameStartsWith('MyString').execute;
Include diagrams with the includeDiagram(Diagram) template
You can use the includeDiagram template to include your diagrams:
// Get a list of matching diagrams var List<Diagram> myDiagrams = queryDiagrams(model).execute; // insert the list of diagrams apply includeDiagram(myDiagrams)
Or you can also insert diagrams with your own template, as shown in the following example:
// To insert the diagram image by yourself: for (diagram : myDiagrams) { // use the pxdoc 'image' keyword with diagram image file path // stored in the 'path' diagram attribute (was 'data' in pxDoc v1.1 and previous). image path:diagram.path // add a title with a style #Figure keepWithNext align:center { diagram.name } // include diagram documentation if any if (!diagram.documentation.empty) { #BodyText {diagram.documentation} } }
And you can get the source diagram object to extract some information from it (get the semantic elements...):
for (diagram : myDiagrams) { //Below, 'MyDiagramType' to be replaced according to your environment: 'DDiagram' for Sirius, 'Diagram' for Papyrus... var myDiagramObject=diagram.diagramObject as MyDiagramType // Do whatever you need with the object... }
DiagramServices setup
REQUIRED - When using the DiagramServices module in your generator, you must inject an IDiagramProvider suited to your target platform.
diagramProvider = myToolDiagramProvider
Images Services / org.pragmaticmodeling.pxdoc.images.lib
Set of functions allowing to:
|