Skip to content

Commit

Permalink
[2666] Performance improvement
Browse files Browse the repository at this point in the history
- Optimization of index computation: removed duplicates elements on
index
- Optimization of "Object present in diagrams" computation
- Fixed multiple generation of pages for model elements (CapellaControl)
- Fixed multiple regeneration of icon files

Bug: 2666
Change-Id: If3ead43240a1354e1b0e7f35c4e35740d2d24e69
Signed-off-by: Arnaud Dieumegard <[email protected]>
  • Loading branch information
arnauddieumegard committed Dec 2, 2019
1 parent 61676ba commit 2f5238d
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
import org.polarsys.kitalpha.doc.gen.business.core.services.IndexerService;
import org.polarsys.kitalpha.doc.gen.business.core.services.ExtensionService;
import org.polarsys.kitalpha.doc.gen.business.core.helper.IConceptsHelper;
import org.eclipse.egf.common.helper.*;
import java.util.*;
import org.eclipse.emf.ecore.*;
import org.eclipse.egf.model.pattern.*;
import org.eclipse.egf.pattern.execution.*;
import org.eclipse.egf.pattern.query.*;
import org.polarsys.kitalpha.doc.gen.business.core.util.DefaultFileNameService;

public class CollectCapellaItems {
protected static String nl;
Expand Down Expand Up @@ -126,6 +125,11 @@ protected void method_body(final StringBuffer stringBuffer, final PatternContext
String fileName = DocGenHtmlCapellaUtil.SERVICE.getFileName(parameter);
IndexItem item = new IndexItem(conceptLabel, parameter.eClass().getName(), iconTagOfElement,
linkTagTowardPageElement, fileName);
// Check if the default indexer have already indexed the element
String defaultFileName = DefaultFileNameService.INSTANCE.getFileName(parameter);
if (IndexerService.INSTANCE.getElementsToIndexItems().get(defaultFileName) != null) {
IndexerService.INSTANCE.getElementsToIndexItems().remove(defaultFileName);
}
IndexerService.INSTANCE.getElementsToIndexItems().put(fileName, item);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -22,33 +23,28 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.sirius.business.api.dialect.DialectManager;
import org.eclipse.sirius.business.api.query.EObjectQuery;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.common.tools.api.editing.EditingDomainFactoryService;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.DDiagramElement;
import org.eclipse.sirius.diagram.DSemanticDiagram;
import org.eclipse.sirius.table.metamodel.table.DTable;
import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.eclipse.sirius.viewpoint.description.DAnnotation;
import org.eclipse.sirius.viewpoint.description.DescriptionPackage;
import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.description.Viewpoint;
import org.polarsys.capella.common.data.modellingcore.AbstractType;
import org.polarsys.capella.common.data.modellingcore.AbstractTypedElement;
import org.polarsys.capella.core.data.capellacore.CapellaElement;
import org.polarsys.capella.core.data.cs.BlockArchitecture;
import org.polarsys.capella.core.data.cs.Part;
import org.polarsys.capella.core.data.interaction.InstanceRole;
import org.polarsys.capella.core.data.interaction.StateFragment;
import org.polarsys.capella.core.data.information.AbstractInstance;
import org.polarsys.capella.core.diagram.helpers.naming.DAnnotationSourceConstants;
import org.polarsys.capella.docgen.util.CapellaServices;
import org.polarsys.kitalpha.doc.gen.business.core.preference.helper.DocgenDiagramPreferencesHelper;
import org.polarsys.kitalpha.doc.gen.business.core.scope.GenerationGlobalScope;
import org.polarsys.kitalpha.doc.gen.business.core.scope.ScopeReferencesStrategy;
import org.polarsys.kitalpha.doc.gen.business.core.sirius.util.session.DiagramSessionHelper;
import org.polarsys.kitalpha.doc.gen.business.core.util.SiriusHelper;

public class CapellaHelper {
private static final String AIRD = ".aird";
Expand Down Expand Up @@ -82,60 +78,67 @@ public static Resource getAIRDResource(CapellaElement element) {

public static Set<DSemanticDiagram> getDiagramContainingObject(CapellaElement element) {
Set<DSemanticDiagram> diagrams = new HashSet<DSemanticDiagram>();
if (!DocgenDiagramPreferencesHelper.getExportDiagram()) {
return diagrams;
}


if (GenerationGlobalScope.getInstance().getReferencesStrategy().equals(ScopeReferencesStrategy.DONT_EXPORT)) {
element = (CapellaElement) GenerationGlobalScope.getInstance().getOriginalModelElement(element);
}

for (DRepresentation representation : DiagramSessionHelper.getSessionDRepresentation()) {
if (representation instanceof DSemanticDiagram) {
DSemanticDiagram dSemanticDiagram = (DSemanticDiagram) representation;
EObject semanticTarget = ((DSemanticDiagram) representation).getTarget();
final boolean copyInScope = GenerationGlobalScope.getInstance().isCopyInScope(semanticTarget);
if (copyInScope == false)
continue;

for (DDiagramElement diagramElement : dSemanticDiagram.getDiagramElements()) {
EObject repTarget = diagramElement.getTarget();
EList<EObject> targets = resolveReferencedElements(repTarget);
for (EObject target : targets) {
if (diagramElement.isVisible() && EcoreUtil.equals(element, target)
&& EcoreUtil.equals(semanticTarget, target) == false) {
// Current representation contains our model element.
// Add it in resulting set, break current loop to search for next
// representation.
diagrams.add((DSemanticDiagram) representation);
break;
}

getAllDiagramsForObject(element).stream()
.filter(rep -> rep instanceof DSemanticDiagram)
.filter(rep -> GenerationGlobalScope.getInstance().isCopyInScope(((DSemanticDiagram) rep).getTarget()))
.forEach(diag -> diagrams.add((DSemanticDiagram) diag));

return diagrams;
}

/**
* <p>
* Get all DRepresentation element displaying the model element.
* <br>
* This method keep only one instance of a given representation if it
* is return many times by Sirius APIs.
* </p>
* @param element The model element
* @return a {@link Collection} of all {@link DRepresentation}
*/
private static Collection<DRepresentation> getAllDiagramsForObject(EObject element) {
Collection<DRepresentation> result = new ArrayList<DRepresentation>();
// Check Diagram export preference
if (DocgenDiagramPreferencesHelper.getExportDiagram())
{
Collection<EObject> refElements = resolveReferencedElements(element);
for (EObject refElement: refElements) {
SiriusHelper.getDiagramForObject(refElement, false).stream().forEach(rep -> {
if (!result.contains(rep)) {
result.add(rep);
}
}
});
}
}
return diagrams;
return result;
}

private static EList<EObject> resolveReferencedElements(EObject repTarget) {
private static EList<EObject> resolveReferencedElements(EObject element) {
EList<EObject> objects = new BasicEList<EObject>();
objects.add(repTarget);
if (repTarget instanceof Part) {
objects.addAll(resolveReferencedElements(((Part) repTarget).getAbstractType()));
}

if (repTarget instanceof InstanceRole) {
objects.addAll(resolveReferencedElements(((InstanceRole) repTarget).getRepresentedInstance()));
}

if (repTarget instanceof StateFragment) {
objects.addAll(resolveReferencedElements(((StateFragment) repTarget).getRelatedAbstractFunction()));
objects.add(element);
// If we have a Component then we look also for Parts
if (element instanceof AbstractType) {
List<AbstractTypedElement> ates = ((AbstractType)element).getAbstractTypedElements();
objects.addAll(ates);
// Then we look for InstanceRoles for these parts
for (EObject ate : ates) {
if (element instanceof AbstractInstance) {
objects.addAll(((AbstractInstance)ate).getRepresentingInstanceRoles());
}
}
}
if (element instanceof AbstractInstance) {
objects.addAll(((AbstractInstance)element).getRepresentingInstanceRoles());
}
return objects;
}

/**
<<<<<<< HEAD
* Scrutinize all EOI (element of interest: See
* {@link org.polarsys.capella.core.diagram.helpers.naming.DAnnotationSourceConstants.CAPELLA_ELEMENT_OF_INTEREST})
* annotation of all representation descriptors to find all representations
Expand Down Expand Up @@ -163,8 +166,6 @@ public static Collection<DDiagram> getAllInterestedRepresentationsFor(EObject se
}

/**
=======
>>>>>>> 15dc1fd... [2547] Tree view of diagrams in architecture levels
* Retrieve all <code>DRepresentation</code> objects for elements of <code>archi</code>
*
* @param archi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package org.polarsys.capella.docgen.util;

import org.polarsys.capella.core.data.capellacommon.AbstractState;
import org.polarsys.capella.core.data.capellacommon.InitialPseudoState;
import org.polarsys.capella.core.data.capellacommon.Region;
import org.polarsys.capella.core.data.capellacommon.StateMachine;
import org.polarsys.capella.core.data.capellacore.CapellaElement;
Expand Down Expand Up @@ -115,7 +114,8 @@ public static boolean isPageCandidate(CapellaElement element) {
*/
public static boolean isPageCandidateForAnyElement(CapellaElement element) {
return (isPageCandidate(element) && !
( element instanceof Component
( element instanceof AbstractState
|| element instanceof Component
|| element instanceof Part
|| element instanceof AbstractFunction
|| element instanceof org.polarsys.capella.core.data.information.Class
Expand All @@ -127,6 +127,9 @@ public static boolean isPageCandidateForAnyElement(CapellaElement element) {
|| element instanceof Structure
|| element instanceof Mission
|| element instanceof FunctionalChain
|| element instanceof FunctionPort
|| element instanceof ComponentPort
|| element instanceof Scenario
|| element instanceof FunctionalExchange
|| element instanceof PhysicalLink
|| element instanceof ComponentExchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
Expand Down Expand Up @@ -50,7 +51,6 @@ public class ImageHelper {
private static final String FILES_SUFFIX = "_files";

private ImageHelper() {

}

public void copyProjectImageToSystemLocation(String srcFile, String targetFile) throws IOException {
Expand Down Expand Up @@ -162,6 +162,12 @@ public static String getTypePng(EObject eObject, String projectName, String fold
if (iconFileTemp != null) {
iconFile = iconFileTemp;
}
try {
iconFolder.refreshLocal(IResource.DEPTH_ONE, MONITOR);
} catch (CoreException e) {
org.polarsys.capella.docgen.Activator.getDefault().getLog()
.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, folderName + " can not be refreshed.", e));
}
}
if (image != null)
image.dispose();
Expand All @@ -183,7 +189,6 @@ private static IFolder getIconFolder(String projectName, String folderName) {
}
}
return iconFolder;

}

private static IFile createNewIconFile(Image iconImage, String fileName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%@ jet package="PACKAGE" class="CLASS" imports="org.polarsys.kitalpha.doc.gen.business.core.services.IndexItem org.polarsys.capella.docgen.util.CapellaServices org.polarsys.capella.docgen.util.DocGenHtmlCapellaUtil org.polarsys.kitalpha.doc.gen.business.core.services.IndexerService org.polarsys.kitalpha.doc.gen.business.core.services.ExtensionService org.polarsys.kitalpha.doc.gen.business.core.helper.IConceptsHelper org.eclipse.egf.common.helper.* java.util.* org.eclipse.emf.ecore.* org.eclipse.egf.model.pattern.* org.eclipse.egf.pattern.execution.* org.eclipse.egf.pattern.query.*" %>
<%@ jet package="PACKAGE" class="CLASS" imports="org.polarsys.kitalpha.doc.gen.business.core.services.IndexItem org.polarsys.capella.docgen.util.CapellaServices org.polarsys.capella.docgen.util.DocGenHtmlCapellaUtil org.polarsys.kitalpha.doc.gen.business.core.services.IndexerService org.polarsys.kitalpha.doc.gen.business.core.services.ExtensionService org.polarsys.kitalpha.doc.gen.business.core.helper.IConceptsHelper java.util.* org.eclipse.egf.model.pattern.* org.eclipse.egf.pattern.execution.* org.eclipse.egf.pattern.query.* org.polarsys.kitalpha.doc.gen.business.core.util.DefaultFileNameService" %>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ for (IConceptsHelper iConceptsHelper : conceptsHelperList) {
String fileName = DocGenHtmlCapellaUtil.SERVICE.getFileName(parameter);
IndexItem item = new IndexItem(conceptLabel, parameter.eClass().getName(),
iconTagOfElement, linkTagTowardPageElement, fileName);
// Check if the default indexer have already indexed the element
String defaultFileName = DefaultFileNameService.INSTANCE.getFileName(parameter);
if (IndexerService.INSTANCE.getElementsToIndexItems().get(defaultFileName) != null) {
IndexerService.INSTANCE.getElementsToIndexItems().remove(defaultFileName);
}
IndexerService.INSTANCE.getElementsToIndexItems().put(fileName, item);
break;
}
Expand Down

0 comments on commit 2f5238d

Please sign in to comment.