TPC GenDoc2 v1.2.0 Tutorial
TPC GenDoc2 v1.2.0 Tutorial
2
Gendoc2 v1.2.0 tutorial
2010/11/30
What’s new (since 1.1.0) ?
Inputs GenDoc2
Acceleo
Extract
scripts M2T
Acceleo
Template document Template Generated document
EMF models
• Or on Eclipse MarketPlace :
http://marketplace.eclipse.org/content/gendoc2
• Step1 : Create the template document using a text editor (Word or Open Office)
Create a document and add all non generated information
• Write in the document all information that will not be generated from the models
Cover page
Header, footer
Chapter title
…
• Once the template document is created, insert script instructions at the location you want to
generate documentation
• The generation will execute these instructions.
They will extract information from the input models and will generate the documentation
• In Gendoc2, script parts are written between the tags <gendoc> and </ gendoc >
• The script language is Acceleo: http://wiki.eclipse.org/Acceleo
• The syntax of Gendoc2 scripts is exactly the same as the Acceleo syntax
In the Acceleo syntax, variable parts are defined between special characters [ and ]
Example
Acceleo Gendoc2
[ for(e:Element|self.ownedElement) ] <gendoc> [for(e : Element|self.ownedElement)]
[e.name/] • [e.name/]
[ /for ] [ /for ] </gendoc>
It can own many <param> tags with (key, value) attributes to define global variables for the script parts
These variables can be used inside other <param> definition or inside context, by using: ${paramKey}
Example : <config>
<output path='D:/myFile.docx' />
<param key='modelFolder' value=‘C:/GenDocTutorial/Models' />
<param key='model' value='${modelFolder}/EquipmentMonitoring.uml'/>
</config>
Parameter value
8 Topcased GenDoc2 Tutorial
Step 2 : Insert script part – pre defined parameters
1. Define a global context to specify the model and the base element:
The context tag can contain an optional attribute : importedBundles, used to give access to specific external classes
defined in a bundle.
Example: <context model='${MODEL}' element='ModelRoot/MyPackage/MyClass'
importedBundles='topcased;myBundle' />
(OPTIONAL) Model element path (default : model root/ If defined, must start with model root element)=
- Values of the attributes that are not updated are kept from previous context (ex: importedBundles can be defined only
once in the document)
A. Using qualified name (all elements must have the property ‘name’)
Property ‘name’ is used for all elements in path
Ex : <context … element=‘modelRoot/package2/subPackage1’/>
• Loop
Loop is handled using the for expression. It is used to iterate on list objects
Example:
<gendoc>
…
[for ( c:Class | self.ownedElement->filter(Class)) ]
The class name is : [c.name/]
…
[for (p:Property | c.ownedAttribute->filter(Property))]
- property [p.name/] : [p.type/]
[/for]
[/for]
…
</gendoc>
• Conditional Statement
Conditional expression is handled using the if – else expression
<gendoc>
…
[if ( self.oclIsKindOf(Class) ) ]
Current element is a Class
[else]
Current element is not a Class
[/if]
…
</gendoc>
• Variable declaration
Local variables can be declared using the let instruction
Example:
<gendoc>
…
[let myVariable : Class = c]
class name: [myVariable.name/]
[/let]
…
</gendoc>
• Image:
The import of existing images is done using the <image> tag and
- either the filePath attribute : for an image full path
- or the object attribute : for an image from a diagram
The <image> tag shall contain a drawing area that will be used to contain the image
Example:
With an image file: <gendoc><image filePath=‘D:/myImage.jpg’ keepW=‘true’ keepH=‘false’>
</image></gendoc>
• Image:
Attributes ‘keepW’ and ‘keepH’ can be used to keep the width or height of the frame. Default values :
keepW=‘false’ and keepH=‘false’.
Attributes ‘maxW’ and ‘maxH’ can be used to set the width or height of the frame as the maximum.
Default values : maxW=‘false’ and maxH=‘false’.
If ‘keep’ dimensions set then image will always be scaled. If both values are set the image may not
retain the original aspect ratio.
If ‘max’ dimensions set then image will only be scaled if native dimensions are too large. The image
will always retain the original aspect ratio.
If both ‘keep’ and ‘max’ dimensions are set the ‘keep’ scaling is applied first with ‘max‘ applied to the
result.
keepH=‘true’ maxH=‘false’
keepW=‘false’ maxW=‘true’
• Table: All table rows found inside <table> tag are merged in a unique table.
Example :
<gendoc> …
<table>
[self.name/] Documentation
[for (u:UseCase|self.ownedElement)]
[u.name/] [u.getDocumentation()/]
[/for] </table>
…</gendoc>
After generation :
realtimeMonitoring Documentation
monitor equipment The system analyses signals sent by equipments
regularly. The received signals are frames with
the equipment state. Frame format differs
according to the equipment category.
handle proven failure The system displays a procedure to handle the
failure. This procedure differs according to the
equipment type.
17 Topcased GenDoc2 Tutorial
Syntax Elements: List Tags
• Lists: All list items inside a <list> tag are merged into a single list
Example:
<gendoc> …
<list>
[for (u:UseCase|self.ownedElement)]
• [u.name/]
[/for]
</list> …
</gendoc>
After generation:
• monitor equipment
• handle proven failure
• Drop: Any paragraphs containing a <drop> tag are removed from the generated
document.
Example:
<gendoc> …
[for (p:Element|self.ownedElement)] <drop/>
[if (p.oclIsKindOf(Package))] <drop/>
[p.name/]
[/if] <drop/>
[/for] <drop/>
</gendoc>
• This allows code to be written on separate lines (making it more readable) without
generating extra paragraphs in the final document.
• A multi-line comment can also be created inside a drop tag.
Example:
<gendoc> …
Description: <dropEmpty>[p.getDocumentation()/]</dropEmpty>
</gendoc>
Will drop the entire paragraph if the element does not have any
documentation.
• No Break: Removes the break between one paragraph and the next.
Example:
<gendoc> …
Name: <nobr/>
[if ( … )]<drop/>
[p.name/]
[else]<drop/>
[p.id/]
[/if]<drop/>
</gendoc>
Output:
• External bundles can be defined in order to provide a set of Acceleo services that
reference Java methods.
• Module XXX not found. : The external bundle specified is missing. Check that this bundle is present
in the environment (copied into « dropins » directory – see sl.6) , and that it is present in the attribute
« importedBundles » of tag « context ».
• The Acceleo script contains invalid blocks. Check that all tags are well
formed. : Some tags are not well closed. Ex : “[for (…)]” with missing “[/for]”, or “[if]” with
missing “[/if]”
• Cannot find operation XXX. : The external bundle referencing this operation is not referenced
inside “importedBundles” attribute of “context” tag.
[…]
<context model=’${model}’ importedBundles=’topcased’ searchMetamodels=’true’/>
•<gendoc>
Model Structure
[for (p:Package|self.ownedElement)]
1.1 [p.name/]
[if (p.getAllDiagrams()->size() > 0)]
<image object=’[self.getDiagram()/]’ keepW=‘true’>
WARNING : this frame is lost with copy/paste of this example. Create it again inside your document.
After document generation you can update fields of your document with F9 command.
You may need to update the index, table of figures, captions, etc.
• Office 2007
You can select all your document (ctrl + A) et press F9 to update all the fields
Available services :
• Rich text tag
• GMF bundle
Result :
• Usage :
add “gmf” inside attribute “importedBundles” of the <context> inside your template
document
• Services provided :
getElementsInDiagram(Diagram):Sequence(EObject)
- Get all elements containing in the diagram
isDiagramEmpty(Diagram) : boolean
- Indicates if the diagram passed as a parameter is empty or not.
getDiagramsUsingRelativePath(EObject, String) : Sequence(Diagram)
- Get the diagrams from relative path for an object
getDiagramsUsingAbsolutePath(EObject, String) : Sequence(Diagram)
- Get the diagrams from absolute path for an object
getDiagramsUsingExtension(EObject, String) : Sequence(Diagram)
- Get the diagrams from resource with the arg1 extension for an object
getDiagramsUsingNotation(EObject) : Sequence(Diagram)
- Get the diagrams from a .notation resource for an object
getDiagramsInModel(EObject) : Sequence(Diagram)
- Get diagrams contained in the model file resource for an object
getDiagram(Diagram) : String
- Get diagram id for a diagram
• Usage :
<context services=‘EPFLoader’ />