Skip to content

Commit

Permalink
Merge pull request #1440 from umple/GvFeatureDiagramUmpleonline
Browse files Browse the repository at this point in the history
Graphviz feature diagram in umple online
  • Loading branch information
TimLethbridge committed Mar 3, 2019
2 parents 02510d7 + 0989450 commit 9232188
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 10 deletions.
20 changes: 16 additions & 4 deletions cruise.umple/src/Generator_CodeGvFeatureDiagram.ump
Expand Up @@ -28,6 +28,15 @@ digraph FeatureModel {

emit graphStart()(graphStart(UmpleModel.VERSION_NUMBER));

// Template for what is output if there is no feature diagram
nofeatureDiagram <<!
node [shape=plaintext];
message [fixedsize=true label ="No require-statement found in the umple file." width=4];
!>>
emit nofeatureDiagram()(nofeatureDiagram);



public void generateFeatureNodeShape(FeatureLink featureLink , StringBuilder code)
{
FeatureNode featureNode = ((FeatureNode) featureLink.getTargetFeature(0));
Expand Down Expand Up @@ -77,13 +86,15 @@ digraph FeatureModel {
public void generate(){
StringBuilder code = new StringBuilder();
featureModel = getModel().getFeatureModel();
// Output basic gv file header
_graphStart(0,code);
if(featureModel == null)
{
code.append("/* Umple code does not have feature diagram. */");
return;
code.append("// Umple code does not have feature diagram. // \n");
_nofeatureDiagram(0,code);
}
// Output basic gv file header
_graphStart(0,code);
else
{
//display the status of the invariant of FM
code.append(configurationStatus());
// Iterate through each root feature.
Expand All @@ -96,6 +107,7 @@ digraph FeatureModel {
generateFeatureNodeShape(flink,code);
}
}
}
terminateCode(code);
}

Expand Down
31 changes: 29 additions & 2 deletions umpleonline/scripts/compiler.php
Expand Up @@ -113,6 +113,7 @@

$javadoc = false;
$stateDiagram = false;
$featureDiagram = false;
$classDiagram = false;
$entityRelationshipDiagram = false;
$yumlDiagram = false;
Expand All @@ -121,6 +122,7 @@
$htmlContents = false;
$generatorType = "";

//featureDiagram

if ($language == "javadoc")
{
Expand All @@ -133,6 +135,12 @@
$generatorType = "";
$stateDiagram = True;
}
else if ($language == "featureDiagram")
{
$language = "GvFeatureDiagram";
$generatorType = "";
$featureDiagram = True;
}
else if ($language == "classDiagram")
{
$language = "GvClassDiagram";
Expand Down Expand Up @@ -236,7 +244,7 @@
return;
} // end html content

elseif (!in_array($language,array("Php","Java","Ruby","RTCpp","Cpp","Sql","GvStateDiagram","GvClassDiagram","GvEntityRelationshipDiagram","GvClassTraitDiagram","Yuml")))
elseif (!in_array($language,array("Php","Java","Ruby","RTCpp","Cpp","Sql","GvFeatureDiagram","GvStateDiagram","GvClassDiagram","GvEntityRelationshipDiagram","GvClassTraitDiagram","Yuml")))
{ // If NOT one of the basic languages, then use umplesync.jar
list($dataname, $dataHandle) = getOrCreateDataHandle();
$dataHandle->writeData($dataname, $input);
Expand Down Expand Up @@ -287,7 +295,7 @@
if($toRemove) { exec($rmcommand); }

// The following is a hack. The arguments to umplesync need fixing
if (!$stateDiagram && !$classDiagram && !$entityRelationshipDiagram && !$yumlDiagram) {
if (!$stateDiagram && !$classDiagram && !$entityRelationshipDiagram && !$yumlDiagram && !$featureDiagram) {
$command = "java -jar umplesync.jar -source {$filename} 2> {$errorFilename}";
}
else {
Expand Down Expand Up @@ -386,6 +394,25 @@
echo "</svg>";
} // end state diagram

else if ($featureDiagram) {
$thedir = dirname($outputFilename);
exec("rm -rf " . $thedir . "/featureDiagram.svg");
$command = "dot -Tsvg -Gdpi=63 " . $thedir . "/modelGvFeatureDiagram.gv -o " . $thedir . "/featureDiagram.svg";
exec($command);
if (!file_exists($thedir . "/featureDiagram.svg") && file_exists("doterr.svg"))
{
exec("cp " . "./doterr.svg " . $thedir . "/featureDiagram.svg");
}
$svgcode = readTemporaryFile("{$thedir}/featureDiagram.svg");
$svglink = $workDir->makePermalink('featureDiagram.svg');

$html = "<a href=\featureDiagram.svg\">Download the GraphViz file for the following</a>&nbsp;<a href=\"$svglink\">Download the SVG file for the following</a>&nbsp;<br/>{$errhtml}&nbsp;
<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" height=\"2000\" width=\"2000\">";
echo $html;
echo $svgcode;
echo "</svg>";
}

else if ($classDiagram) {
$thedir = dirname($outputFilename);
exec("rm -rf " . $thedir . "/classDiagram.svg");
Expand Down
1 change: 1 addition & 0 deletions umpleonline/scripts/compiler_config.php
Expand Up @@ -277,6 +277,7 @@ function generateMenu($buttonSuffix)
<option value=\"yumlDiagram:yumlDiagram\">Yuml Class Diagram</option>
<option value=\"classDiagram:classDiagram\">GraphViz Class Diagram (SVG)</option>
<option value=\"stateDiagram:stateDiagram\">State Diagram (GraphViz SVG)</option>
<option value=\"featureDiagram:featureDiagram\">Feature Diagram (GraphViz SVG)</option>
<option value=\"entityRelationship:entityRelationshipDiagram\">Entity Relationship Diagram (GraphViz SVG)</option>
<option id=\"genstatetables\" value=\"html:StateTables\">State Tables</option>
<option id=\"geneventsequence\" value=\"html:EventSequence\">Event Sequence</option>
Expand Down
34 changes: 30 additions & 4 deletions umpleonline/scripts/umple_action.js
Expand Up @@ -24,7 +24,6 @@ Action.clicked = function(event)

var obj = event.currentTarget;
var action = obj.id.substring(6);

if (action == "PhpCode")
{
Action.generateCode("php","Php");
Expand Down Expand Up @@ -69,6 +68,10 @@ Action.clicked = function(event)
{
Action.generateCode("structureDiagram","structureDiagram");
}
else if (action == "FeatureDiagram")
{
Action.generateCode("featureDiagram","featureDiagram");
}
else if (action == "classDiagram")
{
Action.generateCode("classDiagram","classDiagram");
Expand Down Expand Up @@ -162,6 +165,10 @@ Action.clicked = function(event)
{
Action.changeDiagramType({type:"GVClass"});
}
else if (action == "ShowGvFeatureDiagram")
{
Action.changeDiagramType({type:"GVFeature"});//buttonShowGvFeatureDiagram
}
else if (action == "ShowGvStateDiagram")
{
Action.changeDiagramType({type:"GVState"});
Expand Down Expand Up @@ -354,6 +361,7 @@ Action.changeDiagramType = function(newDiagramType)
Page.useJointJSClassDiagram = false;
Page.useGvClassDiagram = false;
Page.useGvStateDiagram = false;
Page.useGvFeatureDiagram = false;
Page.useStructureDiagram = false;
changedType = true;
jQuery("#buttonShowEditableClassDiagram").prop('checked', 'checked');
Expand All @@ -364,6 +372,7 @@ Action.changeDiagramType = function(newDiagramType)
Page.useJointJSClassDiagram = true;
Page.useGvClassDiagram = false;
Page.useGvStateDiagram = false;
Page.useGvFeatureDiagram = false;
Page.useStructureDiagram = false;
changedType = true;
jQuery("#buttonShowJointJSClassDiagram").prop('checked', 'checked');
Expand All @@ -374,6 +383,7 @@ Action.changeDiagramType = function(newDiagramType)
Page.useJointJSClassDiagram = false;
Page.useGvClassDiagram = true;
Page.useGvStateDiagram = false;
Page.useGvFeatureDiagram = false;
Page.useStructureDiagram = false;
changedType = true;
jQuery("#buttonShowGvClassDiagram").prop('checked', 'checked');
Expand All @@ -385,16 +395,29 @@ Action.changeDiagramType = function(newDiagramType)
Page.useGvClassDiagram = false;
Page.useGvStateDiagram = true;
Page.useStructureDiagram = false;
Page.useGvFeatureDiagram = false;
changedType = true;
jQuery("#buttonShowGvStateDiagram").prop('checked', 'checked');
}
else if(newDiagramType.type == "GVFeature") {
if(Page.useGvFeatureDiagram) return;
Page.useEditableClassDiagram = false;
Page.useJointJSClassDiagram = false;
Page.useGvClassDiagram = false;
Page.useGvStateDiagram = false;
Page.useStructureDiagram = false;
Page.useGvFeatureDiagram = true;
changedType = true;
jQuery("#buttonShowGvFeatureDiagram").prop('checked', 'checked');
}
else if(newDiagramType.type == "structure") { // Structure Diagram
if(Page.useGvStructureDiagram) return;
Page.useEditableClassDiagram = false;
Page.useJointJSClassDiagram = false;
Page.useGvClassDiagram = false;
Page.useGvStateDiagram = false;
Page.useStructureDiagram = true;
Page.useGvFeatureDiagram = false;
changedType = true;
jQuery("#buttonShowStructureDiagram").prop('checked', 'checked');
}
Expand Down Expand Up @@ -1728,7 +1751,7 @@ Action.updateUmpleDiagramCallback = function(response)

}
// Display static svg diagram
else if(Page.useGvClassDiagram || Page.useGvStateDiagram)
else if(Page.useGvClassDiagram || Page.useGvStateDiagram || Page.useGvFeatureDiagram )
{
jQuery("#umpleCanvas").html(format('{0}', diagramCode));
}
Expand Down Expand Up @@ -1791,7 +1814,7 @@ Action.getDiagramCode = function(responseText)
if(output == "null") output = "";

}
else if(Page.useGvClassDiagram || Page.useGvStateDiagram)
else if(Page.useGvClassDiagram || Page.useGvStateDiagram || Page.useGvFeatureDiagram)
{
// The graphviz diagrams are taken from the inner svg tag only.
// This allows the website to have a dynamic canvas size around the diagram
Expand Down Expand Up @@ -1825,7 +1848,7 @@ Action.getErrorCode = function(responseText)

if(output == "<p>") output = "";
}
else if(Page.useGvClassDiagram || Page.useGvStateDiagram)
else if(Page.useGvClassDiagram || Page.useGvStateDiagram || Page.useGvFeatureDiagram)
{
var miscStuffAndErrorMessages = responseText.split('<svg width=')[0];
var prelimparts = miscStuffAndErrorMessages.split('errorRow');
Expand Down Expand Up @@ -2405,6 +2428,9 @@ Action.getLanguage = function()
if(Page.showMethods) language=language+".showmethods";
if(!Page.showAttributes) language=language+".hideattributes";
}
if(Page.useGvFeatureDiagram) {language="language=featureDiagram"}


return language;
}

Expand Down
14 changes: 14 additions & 0 deletions umpleonline/scripts/umple_page.js
Expand Up @@ -31,6 +31,7 @@ Page.readOnly = false; // initially allow editing
Page.useEditableClassDiagram = true;
Page.useGvClassDiagram = false;
Page.useGvStateDiagram = false;
Page.useGvFeatureDiagram = false;
Page.useStructureDiagram = false;
Page.showAttributes = true;
Page.showMethods = false;
Expand Down Expand Up @@ -62,6 +63,12 @@ Page.init = function(doShowDiagram, doShowText, doShowMenu, doReadOnly, doShowLa
Page.useGvClassDiagram = true;
Page.useEditableClassDiagram = false;
}
else if(diagramType == "GVFeature")
{
Page.useGvFeatureDiagram = true;
Page.useEditableClassDiagram = false;
Page.useGvStateDiagram = false;
}
else if(diagramType == "structureDiagram")
{
Page.useStructureDiagram = true;
Expand Down Expand Up @@ -149,6 +156,7 @@ Page.initPaletteArea = function()
Page.initAction("buttonShowJointJSClassDiagram");
Page.initAction("buttonShowGvClassDiagram");
Page.initAction("buttonShowGvStateDiagram");
Page.initAction("buttonShowGvFeatureDiagram");//buttonShowGvFeatureDiagram
Page.initAction("buttonShowStructureDiagram");
Page.initAction("buttonShowHideLayoutEditor");
Page.initAction("buttonManualSync");
Expand Down Expand Up @@ -230,6 +238,9 @@ Page.initOptions = function()
jQuery("#buttonShowJointJSClassDiagram").prop('checked', true);
if(Page.useGvClassDiagram)
jQuery("#buttonShowGvClassDiagram").prop('checked', true);
if(Page.useGvFeatureDiagram)
jQuery("#buttonShowGvFeatureDiagram").prop('checked', true);

if(Page.useGvStateDiagram)
jQuery("#buttonShowGvStateDiagram").prop('checked', true);
if(Page.useStructureDiagram)
Expand Down Expand Up @@ -425,6 +436,9 @@ Page.clickShowGvClassDiagram = function() {
Page.clickShowGvStateDiagram = function() {
jQuery('#buttonShowGvStateDiagram').trigger('click');
}
Page.clickShowGvFeatureDiagram = function() {
jQuery('#buttonShowGvFeatureDiagram').trigger('click');
}
Page.clickShowStructureDiagram = function() {
jQuery('#buttonShowStructureDiagram').trigger('click');
}
Expand Down
4 changes: 4 additions & 0 deletions umpleonline/umple.php
Expand Up @@ -537,6 +537,10 @@
<input id="buttonShowGvStateDiagram" class="radio" type="radio" name="buttonCanvasType" value="buttonCanvasTypeGVStateDiagram"/>
<a id="labelShowGvStateDiagram" class="buttonExtend">GraphViz State</a>
</li>
<li id="ttShowGvFeatureDiagram">
<input id="buttonShowGvFeatureDiagram" class="radio" type="radio" name="buttonCanvasType" value="buttonCanvasTypeGVFeatureDiagram"/>
<a id="labelShowGvFeatureDiagram" class="buttonExtend">GraphViz Feature</a>
</li>
<li id="ttShowStructureDiagram">
<input id="buttonShowStructureDiagram" class="radio" type="radio" name="buttonCanvasType" value="buttonCanvasTypeStructureDiagram"/>
<a id="labelShowStructureDiagram" class="buttonExtend">Composite Structure</a>
Expand Down

0 comments on commit 9232188

Please sign in to comment.