Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/instance vp doc #284

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions image.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 75 74 66 2d 38 22 3f 3e d a 3c 21 2d 2d 20 47 65 6e 65 72 61 74 6f 72 3a 20 41 64 6f 62 65 20 49 6c 6c 75 73 74 72 61 74 6f 72 20 31 36 2e 30 2e 30 2c 20 53 56 47 20 45 78 70 6f 72 74 20 50 6c 75 67 2d 49 6e 20 2e 20 53 56 47 20 56 65 72 73 69 6f 6e 3a 20 36 2e 30 30 20 42 75 69 6c 64 20 30 29 20 20 2d 2d 3e d a 3c 21 44 4f 43 54 59 50 45 20 73 76 67 20 50 55 42 4c 49 43 20 22 2d 2f 2f 57 33 43 2f 2f 44 54 44 20 53 56 47 20 31 2e 31 2f 2f 45 4e 22 20 22 68 74 74 70 3a 2f 2f 77 77 77 2e 77 33 2e 6f 72 67 2f 47 72 61 70 68 69 63 73 2f 53 56 47 2f 31 2e 31 2f 44 54 44 2f 73 76 67 31 31 2e 64 74 64 22 3e d a 3c 73 76 67 20 76 65 72 73 69 6f 6e 3d 22 31 2e 31 22 20 69 64 3d 22 4c 61 79 65 72 5f 31 22 20 78 6d 6c 6e 73 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 77 33 2e 6f 72 67 2f 32 30 30 30 2f 73 76 67 22 20 78 6d 6c 6e 73 3a 78 6c 69 6e 6b 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 77 33 2e 6f 72 67 2f 31 39 39 39 2f 78 6c 69 6e 6b 22 20 78 3d 22 30 70 78 22 20 79 3d 22 30 70 78 22 d a 9 20 77 69 64 74 68 3d 22 31 36 70 78 22 20 68 65 69 67 68 74 3d 22 31 36 70 78 22 20 76 69 65 77 42 6f 78 3d 22 30 20 30 20 31 36 20 31 36 22 20 73 74 79 6c 65 3d 22 65 6e 61 62 6c 65 2d 62 61 63 6b 67 72 6f 75 6e 64 3a 6e 65 77 20 30 20 30 20 31 36 20 31 36 3b 22 20 78 6d 6c 3a 73 70 61 63 65 3d 22 70 72 65 73 65 72 76 65 22 3e d a 3c 6c 69 6e 65 61 72 47 72 61 64 69 65 6e 74 20 69 64 3d 22 53 56 47 49 44 5f 31 5f 22 20 67 72 61 64 69 65 6e 74 55 6e 69 74 73 3d 22 75 73 65 72 53 70 61 63 65 4f 6e 55 73 65 22 20 78 31 3d 22 35 37 32 2e 36 39 39 32 22 20 79 31 3d 22 38 31 36 2e 33 30 30 38 22 20 78 32 3d 22 35 38 35 2e 36 39 39 32 22 20 79 32 3d 22 38 31 36 2e 33 30 30 38 22 20 67 72 61 64 69 65 6e 74 54 72 61 6e 73 66 6f 72 6d 3d 22 6d 61 74 72 69 78 28 31 20 30 20 30 20 31 20 2d 35 37 31 2e 31 39 39 32 20 2d 38 30 38 2e 38 30 30 38 29 22 3e d a 9 3c 73 74 6f 70 20 20 6f 66 66 73 65 74 3d 22 30 22 20 73 74 79 6c 65 3d 22 73 74 6f 70 2d 63 6f 6c 6f 72 3a 23 46 46 46 39 43 34 22 2f 3e d a 9 3c 73 74 6f 70 20 20 6f 66 66 73 65 74 3d 22 31 22 20 73 74 79 6c 65 3d 22 73 74 6f 70 2d 63 6f 6c 6f 72 3a 23 46 46 46 44 45 37 22 2f 3e d a 3c 2f 6c 69 6e 65 61 72 47 72 61 64 69 65 6e 74 3e d a 3c 72 65 63 74 20 78 3d 22 31 2e 35 22 20 79 3d 22 31 2e 35 22 20 73 74 79 6c 65 3d 22 66 69 6c 6c 3a 75 72 6c 28 23 53 56 47 49 44 5f 31 5f 29 3b 73 74 72 6f 6b 65 3a 23 34 32 34 32 34 32 3b 73 74 72 6f 6b 65 2d 6d 69 74 65 72 6c 69 6d 69 74 3a 31 30 3b 22 20 77 69 64 74 68 3d 22 31 33 22 20 68 65 69 67 68 74 3d 22 31 32 22 2f 3e d a 3c 6c 69 6e 65 20 73 74 79 6c 65 3d 22 66 69 6c 6c 3a 6e 6f 6e 65 3b 73 74 72 6f 6b 65 3a 23 34 32 34 32 34 32 3b 73 74 72 6f 6b 65 2d 6d 69 74 65 72 6c 69 6d 69 74 3a 31 30 3b 22 20 78 31 3d 22 32 22 20 79 31 3d 22 31 31 2e 35 22 20 78 32 3d 22 31 34 22 20 79 32 3d 22 31 31 2e 35 22 2f 3e d a 3c 6c 69 6e 65 20 73 74 79 6c 65 3d 22 66 69 6c 6c 3a 6e 6f 6e 65 3b 73 74 72 6f 6b 65 3a 23 34 32 34 32 34 32 3b 73 74 72 6f 6b 65 2d 6d 69 74 65 72 6c 69 6d 69 74 3a 31 30 3b 22 20 78 31 3d 22 32 22 20 79 31 3d 22 39 2e 35 22 20 78 32 3d 22 31 34 22 20 79 32 3d 22 39 2e 35 22 2f 3e d a 3c 67 3e d a 9 3c 70 61 74 68 20 73 74 79 6c 65 3d 22 66 69 6c 6c 3a 23 34 32 34 32 34 32 3b 22 20 64 3d 22 4d 36 2c 38 4c 34 2c 32 2e 33 68 31 2e 33 6c 31 2e 34 2c 34 2e 32 6c 31 2e 34 2d 34 2e 32 68 31 2e 32 4c 37 2e 33 2c 38 48 36 7a 22 2f 3e d a 9 3c 70 61 74 68 20 73 74 79 6c 65 3d 22 66 69 6c 6c 3a 23 34 32 34 32 34 32 3b 22 20 64 3d 22 4d 39 2e 32 2c 33 2e 38 68 31 76 30 2e 36 63 30 2e 31 2d 30 2e 32 2c 30 2e 33 2d 30 2e 34 2c 30 2e 35 2d 30 2e 35 73 30 2e 35 2d 30 2e 32 2c 30 2e 38 2d 30 2e 32 63 30 2e 35 2c 30 2c 30 2e 39 2c 30 2e 32 2c 31 2e 32 2c 30 2e 36 73 30 2e 35 2c 30 2e 39 2c 30 2e 35 2c 31 2e 36 d a 9 9 63 30 2c 30 2e 37 2d 30 2e 32 2c 31 2e 32 2d 30 2e 35 2c 31 2e 36 53 31 32 2c 38 2e 31 2c 31 31 2e 35 2c 38 2e 31 63 2d 30 2e 32 2c 30 2d 30 2e 34 2c 30 2d 30 2e 36 2d 30 2e 31 73 2d 30 2e 34 2d 30 2e 32 2d 30 2e 36 2d 30 2e 35 76 32 2e 31 48 39 2e 32 56 33 2e 38 7a 20 4d 31 30 2e 33 2c 35 2e 38 63 30 2c 30 2e 35 2c 30 2e 31 2c 30 2e 38 2c 30 2e 33 2c 31 d a 9 9 73 30 2e 34 2c 30 2e 33 2c 30 2e 37 2c 30 2e 33 63 30 2e 33 2c 30 2c 30 2e 35 2d 30 2e 31 2c 30 2e 36 2d 30 2e 33 73 30 2e 33 2d 30 2e 35 2c 30 2e 33 2d 31 63 30 2d 30 2e 34 2d 30 2e 31 2d 30 2e 38 2d 30 2e 33 2d 31 73 2d 30 2e 34 2d 30 2e 33 2d 30 2e 36 2d 30 2e 33 63 2d 30 2e 33 2c 30 2d 30 2e 35 2c 30 2e 31 2d 30 2e 37 2c 30 2e 33 d a 9 9 53 31 30 2e 33 2c 35 2e 34 2c 31 30 2e 33 2c 35 2e 38 7a 22 2f 3e d a 3c 2f 67 3e d a 3c 2f 73 76 67 3e d
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<diagram version="9" type="View Diagram" baseType="Class Diagram" abbreviation="vd" category="MDK">
<diagram version="10" type="View Diagram" baseType="Class Diagram" abbreviation="vd" category="MDK">
<requiredPlugin>org.openmbee.mdk#Model Development Kit;SysML Extensions.mdxml;UML_Standard_Profile.mdzip
</requiredPlugin>
<toolbarConfiguration>
Expand Down Expand Up @@ -630,6 +630,7 @@
</custom>
<standard action="ADD_DIRECTED_COMPOSITION"/>
<standard action="ADD_DIRECTED_AGGREGATION"/>
<standard action="ADD_TEMPLATE_BINDING" shortcut="pressed B "/>
</actions>
</category>
</toolbarConfiguration>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/openmbee/mdk/MDKPluginHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import com.nomagic.magicdraw.core.Application;
import com.nomagic.magicdraw.core.options.EnvironmentOptions;
import com.nomagic.magicdraw.evaluation.EvaluationConfigurator;
import com.nomagic.magicdraw.hyperlinks.HyperlinksHandlersRegistry;
import com.nomagic.magicdraw.uml.DiagramDescriptor;
import com.nomagic.magicdraw.uml.DiagramTypeConstants;
import org.openmbee.mdk.cli.AutomatedCommitter;
import org.openmbee.mdk.cli.AutomatedViewGenerator;
import org.openmbee.mdk.hyperlinks.TranclusionHandler;
import org.openmbee.mdk.hyperlinks.TransclusionEditorPanel;
import org.openmbee.mdk.mms.sync.status.SyncStatusConfigurator;
import org.openmbee.mdk.options.ConfigureProjectOptions;
import org.openmbee.mdk.options.MDKEnvironmentOptionsGroup;
Expand All @@ -34,6 +37,8 @@ public void init() {
// This somehow allows things to be loaded to evaluate opaque expressions or something.
EvaluationConfigurator.getInstance().registerBinaryImplementers(this.getClass().getClassLoader());

// Add Transclusion Handler
HyperlinksHandlersRegistry.addHandler(new TranclusionHandler());


CommandLineActionManager.getInstance().addAction(new AutomatedViewGenerator());
Expand Down
116 changes: 109 additions & 7 deletions src/main/java/org/openmbee/mdk/actions/InstanceViewpointAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@
import com.nomagic.magicdraw.core.Project;
import com.nomagic.magicdraw.openapi.uml.SessionManager;
import com.nomagic.magicdraw.sysml.util.SysMLProfile;
import com.nomagic.ui.ResizableIconImageIcon;
import com.nomagic.uml2.ext.jmi.helpers.ModelHelper;
import com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper;
import com.nomagic.uml2.ext.magicdraw.auxiliaryconstructs.mdtemplates.TemplateBinding;
import com.nomagic.uml2.ext.magicdraw.auxiliaryconstructs.mdtemplates.TemplateParameterSubstitution;
import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.*;
import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class;
import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Package;
import com.nomagic.uml2.ext.magicdraw.mdprofiles.Stereotype;
import com.nomagic.uml2.impl.ElementsFactory;
import org.openmbee.mdk.SysMLExtensions;
import org.openmbee.mdk.api.incubating.MDKConstants;
import org.openmbee.mdk.docgen.DocGenUtils;
import org.openmbee.mdk.options.MDKProjectOptions;
import org.openmbee.mdk.util.Utils;

import java.awt.event.ActionEvent;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* given a viewpoint composition hierarchy, makes the views, and have them
Expand Down Expand Up @@ -48,8 +58,8 @@ public InstanceViewpointAction(Element e) {
@Override
public void actionPerformed(ActionEvent e) {
GUILog gl = Application.getInstance().getGUILog();
sysmlView = SysMLExtensions.getInstanceByProject(project).view().getStereotype();
sysmlViewpoint = SysMLProfile.getInstanceByProject(project).viewpoint().getStereotype();;
sysmlView = SysMLProfile.getInstanceByProject(project).view().getStereotype();
sysmlViewpoint = SysMLProfile.getInstanceByProject(project).viewpoint().getStereotype();
ef = Project.getProject(viewpoint).getElementsFactory();
if (sysmlView == null) {
gl.log("The view stereotype cannot be found");
Expand All @@ -69,7 +79,7 @@ public void actionPerformed(ActionEvent e) {
Project project = Application.getInstance().getProject();
try {
SessionManager.getInstance().createSession(project, "instance viewpoint");
instance(pack, (Class) viewpoint, ((Class) viewpoint).getName());
instanceViewpoint(pack, (Class) viewpoint, ((Class) viewpoint).getName());
SessionManager.getInstance().closeSession(project);
} catch (Exception ex) {
SessionManager.getInstance().cancelSession(project);
Expand All @@ -81,13 +91,58 @@ public void actionPerformed(ActionEvent e) {
}
}

private Class instance(Element owner, Class vp, String name) {
private Class instanceViewpoint(Element owner, Class vp, String name) {


HashMap<String,String> paramMap = new HashMap<>();

if (vp.getTemplateBinding().size() > 0) {
TemplateBinding binding = vp.getTemplateBinding().stream().collect(Collectors.toList()).get(0);

getTemplateMap(paramMap, binding);
Class templateVP = (Class) binding.getTarget().stream().collect(Collectors.toList()).get(0).getOwner();

return instance(owner, templateVP, templateVP.getName(), paramMap);
} else {
return instance(owner, vp, name, paramMap);
}
}

private Class instance(Element owner, Class vp, String name, Map<String, String> paramMap) {


Class view = ef.createClassInstance();
view.setOwner(owner);

if (paramMap.size() > 0) {
StringBuilder nameSB = new StringBuilder(name);
paramMap.forEach((param, replace) -> {
replaceAll(nameSB, "[[" + param + "]]", replace);
});
name = nameSB.toString();
}
view.setName(name);
if (MDKProjectOptions.instanceVPDoc(project)) {

String vp_doc = ModelHelper.getComment(vp);
if (vp_doc.isEmpty()) {
vp_doc = "<i>" + name + " placeholder documentation</i>";
} else {
if (paramMap.size() > 0) {
StringBuilder docSB = new StringBuilder(vp_doc);
paramMap.forEach((param, replace) -> {
replaceAll(docSB, "[[" + param + "]]", replace);
});
vp_doc = docSB.toString();
}
}

ModelHelper.setComment(view, vp_doc);
}

StereotypesHelper.addStereotype(view, sysmlView);
Generalization conforms = ef.createGeneralizationInstance();
StereotypesHelper.addStereotype(conforms, SysMLExtensions.getInstance(owner).conforms().getStereotype());
StereotypesHelper.addStereotype(conforms, SysMLProfile.getInstance(owner).conform().getStereotype());
ModelHelper.setClientElement(conforms, view);
ModelHelper.setSupplierElement(conforms, vp);
conforms.setOwner(view);
Expand All @@ -96,10 +151,10 @@ private Class instance(Element owner, Class vp, String name) {
if (type instanceof Class && StereotypesHelper.hasStereotypeOrDerived(type, sysmlViewpoint)) {
Class child = null;
if (p.getName().isEmpty()) {
child = instance(view, (Class) type, type.getName());
child = instance(view, (Class) type, type.getName(), paramMap);
}
else {
child = instance(view, (Class) type, p.getName());
child = instance(view, (Class) type, p.getName(), paramMap);
}
Association asso = ef.createAssociationInstance();
asso.getMemberEnd().get(0).setOwner(view);
Expand All @@ -112,4 +167,51 @@ private Class instance(Element owner, Class vp, String name) {
}
return view;
}

public static void getTemplateMap(Map<String,String> paramMap, TemplateBinding binding) {
//Get Paramter Subs
binding.getParameterSubstitution().stream().forEach((parameter) -> {
String name = ((NamedElement) parameter.getFormal().getParameteredElement()).getName();
if (!paramMap.containsKey(name)) {
Element element = parameter.getActual();

if (!(name.endsWith(MDKConstants.ID_KEY_SUFFIX) || name.endsWith(MDKConstants.NAME_KEY_SUFFIX))) {
paramMap.put(name + MDKConstants.ID_KEY_SUFFIX, DocGenUtils.fixId(element));
paramMap.put(name + MDKConstants.NAME_KEY_SUFFIX, DocGenUtils.fixString(element));
paramMap.put(name, DocGenUtils.fixString(element));
} else if (name.endsWith(MDKConstants.ID_KEY_SUFFIX)) {
paramMap.put(name, DocGenUtils.fixId(element));
} else {
paramMap.put(name, DocGenUtils.fixString(element));
}
}

});
//Get Defaults
binding.getSignature().getParameter().forEach((parameter) -> {
String name = ((NamedElement) parameter.getParameteredElement()).getName();
if (!paramMap.containsKey(name)) {
Element element = parameter;

if (!(name.endsWith(MDKConstants.ID_KEY_SUFFIX) || name.endsWith(MDKConstants.NAME_KEY_SUFFIX))) {
paramMap.put(name + MDKConstants.ID_KEY_SUFFIX, DocGenUtils.fixId(element));
paramMap.put(name + MDKConstants.NAME_KEY_SUFFIX, DocGenUtils.fixString(element));
paramMap.put(name, DocGenUtils.fixString(element));
} else if (name.endsWith(MDKConstants.ID_KEY_SUFFIX)) {
paramMap.put(name, DocGenUtils.fixId(element));
} else {
paramMap.put(name, DocGenUtils.fixString(element));
}

}
});
}
public static void replaceAll(StringBuilder sb, String from, String to) {
int index = sb.indexOf(from);
while (index != -1) {
sb.replace(index, index + from.length(), to);
index += to.length();
index = sb.indexOf(from, index);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class MDKConstants {
TYPE_KEY = "type",
TYPE_ID_KEY = TYPE_KEY + ID_KEY_SUFFIX,
NAME_KEY = "name",
NAME_KEY_SUFFIX = "Name",
FQN_KEY = "fullyQualifiedName",
LABEL_KEY = "label",
ID_KEY = "id",
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/openmbee/mdk/docgen/DocGenUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,22 @@ else if (s != null) {
return "";
}

public static String fixId(Object s) {
if (s instanceof String) {
return (String) s;
} else if (s instanceof ElementValue) {
return MDUtils.getEID(((ElementValue) s).getElement());
} else if (s instanceof InstanceValue) {
InstanceSpecification is = ((InstanceValue) s).getInstance();
if (is != null) {
return MDUtils.getEID(is);
} else {
return "notFound";
}
} else {
return MDUtils.getEID((Element) s);
}
}
//in case Expression is used other than RestrictedValue, only considered as RestrictedValue when 1st operand is LiteralString with "RestrictedValue"
private static String getRestrictedValue(Object s) {
if (s instanceof Expression) { //Expression is NamedElement
Expand Down
Loading