From: lempinen Date: Wed, 10 Oct 2012 10:32:47 +0000 (+0000) Subject: Enumeration issue source for checking that an enumeration is not empty (refs #3048) X-Git-Tag: simantics-1.10.1~132 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=753135133a448534eea2b8f8f9f55a3d4250dc2f;p=simantics%2Fsysdyn.git Enumeration issue source for checking that an enumeration is not empty (refs #3048) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25965 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index cbaba954..0475c6b5 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/Validation.pgraph b/org.simantics.sysdyn.ontology/graph/Validation.pgraph index 72162a76..363c9d29 100644 --- a/org.simantics.sysdyn.ontology/graph/Validation.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Validation.pgraph @@ -10,17 +10,21 @@ SYSDYN.SysdynIssue enumerationIssueSources = graph.syncRequest(new ObjectsWithType(modelRoot, L0.ConsistsOf, sr.Validations_Enumerations_EnumerationIssueSource)); + if(enumerationIssueSources.isEmpty()) { + GraphUtils.create2(graph, + sr.Validations_Enumerations_EnumerationIssueSource, + L0X.IsActivatedBy, modelRoot, + L0.PartOf, modelRoot + ); + } } + protected void fixHasTailAndHasHead(WriteGraph graph, Resource modelRoot) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); SysdynResource sr = SysdynResource.getInstance(graph); @@ -214,20 +230,36 @@ public class ImportModelHandler extends AbstractHandler { } private Collection findAllConfigurations(ReadGraph graph, Resource modelRoot) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); SysdynResource sr = SysdynResource.getInstance(graph); StructuralResource2 SR2 = StructuralResource2.getInstance(graph); + Collection modulesAndModels = findAllModelsAndModules(graph, modelRoot); Collection configurations = new ArrayList(); - configurations.add(graph.getPossibleObject(modelRoot, SimulationResource.getInstance(graph).HasConfiguration)); - for(Resource r : graph.getObjects(modelRoot, L0.ConsistsOf)) { + for(Resource r : modulesAndModels) { if(graph.isInheritedFrom(r, sr.Module)) { configurations.add(graph.getPossibleObject(r, SR2.IsDefinedBy)); + } else if(graph.isInstanceOf(r, sr.SysdynModel)) { + configurations.add(graph.getPossibleObject(modelRoot, SimulationResource.getInstance(graph).HasConfiguration)); } } return configurations; } + + private Collection findAllModelsAndModules(ReadGraph graph, Resource modelRoot) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + Collection modelsAndModules = new ArrayList(); + modelsAndModules.add(modelRoot); + + for(Resource r : graph.getObjects(modelRoot, L0.ConsistsOf)) { + if(graph.isInheritedFrom(r, sr.Module)) { + modelsAndModules.add(r); + } + } + + return modelsAndModules; + } private void displayErrorMessage(Shell shell, String message) { MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java index 6bfc3767..3aa9e5f7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java @@ -99,24 +99,6 @@ public class NewModuleNodeHandler extends AbstractHandler { } } - GraphUtils.create2(g, - sr.Validations_Dependencies_MissingDependencyConnectionsIssueSource, - L0X.IsActivatedBy, model, - l0.PartOf, moduleType - ); - - GraphUtils.create2(g, - sr.Validations_Dependencies_DependencyConnectionsIssueSource, - L0X.IsActivatedBy, model, - l0.PartOf, moduleType - ); - - GraphUtils.create2(g, - sr.Validations_Expressions_ExpressionIssueSource, - L0X.IsActivatedBy, model, - l0.PartOf, moduleType - ); - Resource mapping = g.newResource(); g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); g.claim(diagram, L0X.HasTrigger, mapping); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java index b0d6197b..60b4280d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java @@ -90,6 +90,12 @@ public class ModelUtils { L0X.IsActivatedBy, model, l0.PartOf, model ); + + GraphUtils.create2(g, + sr.Validations_Enumerations_EnumerationIssueSource, + L0X.IsActivatedBy, model, + l0.PartOf, model + ); Resource conf = GraphUtils.create2(g, sr.Configuration, diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/EnumerationFunction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/EnumerationFunction.java new file mode 100644 index 00000000..21e9bb95 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/EnumerationFunction.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.validation; + +import java.util.Collections; +import java.util.List; + +import org.simantics.db.Issue; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.issues.common.StandardIssue; +import org.simantics.scl.reflection.annotations.SCLValue; +import org.simantics.sysdyn.SysdynResource; + +/** + * Functions for checking issues in Enumerations + * @author Teemu Lempinen + * + */ +public class EnumerationFunction { + + private static String NO_INDEXES = "Enumeration does not contain indexes."; + + @SCLValue(type = "ReadGraph -> Resource -> [Issue]") + public static List enumerationIndexValidator(ReadGraph graph, Resource component) throws DatabaseException { + + SysdynResource sr = SysdynResource.getInstance(graph); + + if(!graph.isInstanceOf(component, sr.Enumeration)) { + return Collections.emptyList(); + } + + boolean noIndexes = false; + + try { + Resource indexList = graph.getPossibleObject(component, sr.Enumeration_enumerationIndexes); + List indexes = OrderedSetUtils.toList(graph, indexList); + if(indexes.size() == 0) + noIndexes = true; + } catch (DatabaseException e) { + noIndexes = true; + } + + if(noIndexes) + return Collections.singletonList(new StandardIssue(sr.Validations_EmptyEnumerationIssue, component)); + else + return Collections.emptyList(); + } + + @SCLValue(type = "ReadGraph -> Resource -> Variable -> String") + public static String emptyEnumerationIssueDescription(ReadGraph graph, Resource converter, Variable property) throws DatabaseException { + return NO_INDEXES; + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/Functions.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/Functions.java index 78128ff2..d53a9128 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/Functions.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/Functions.java @@ -11,9 +11,16 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.validation; +import java.util.List; + import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.issues.common.IssueUtils; +import org.simantics.layer0.Layer0; +import org.simantics.project.ontology.ProjectResource; import org.simantics.scl.reflection.annotations.SCLValue; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.structural.stubs.StructuralResource2; @@ -37,4 +44,35 @@ public class Functions { else return null; } + + + @SCLValue(type = "ReadGraph -> Resource -> Variable -> String") + public static String path(ReadGraph graph, Resource source, Variable property) throws DatabaseException { + List contexts = IssueUtils.getContextsForProperty(graph, property); + if (contexts.size() > 0) { + Resource component = contexts.get(0); + Layer0 L0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + ProjectResource PROJECT = ProjectResource.getInstance(graph); + StringBuilder sb = new StringBuilder(""); + Resource parent = graph.getPossibleObject(component, L0.PartOf); + boolean first = true; + while(parent != null && !graph.isInstanceOf(parent, PROJECT.Project)) { + if(!graph.isInstanceOf(parent, sr.Configuration)) { + String name = NameUtils.getSafeName(graph, parent); + if(first) { + sb.append(name); + first = false; + } else { + sb.insert(0, "/"); + sb.insert(0, name); + } + } + parent = graph.getPossibleObject(parent, L0.PartOf); + } + return sb.toString(); + } else { + return ""; + } + } }