From: lempinen Date: Tue, 27 Mar 2012 06:23:36 +0000 (+0000) Subject: Almost completely functional model browser defined in sysdynmodelbrowserviewpoint... X-Git-Tag: simantics-1.6~20 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=1b996426e315717d692d3e55236f5619f1cb476a;p=simantics%2Fsysdyn.git Almost completely functional model browser defined in sysdynmodelbrowserviewpoint. The main thing missing is deleting module types and datasets and removing delete-option from nodes that can not / should not be deleted. (refs #2926) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@24540 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 958e4d0a..6dc2005b 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/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index 74f88326..aa7e10bc 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -67,6 +67,7 @@ SYSDYN.SymbolReferences : DIA.SymbolReferenceLibrary BasicSymbols = SYSDYN.SymbolReferences.BasicSymbols : DIA.SymbolReferenceLibrary SYSDYN.Configuration -- SYSDYN.ValveSymbol.orientation --> SYSDYN.Orientation -- SYSDYN.ValveSymbol.orientation --> SYSDYN.Orientation -- SYSDYN.ValveSymbol.textLocation --> SYSDYN.Location -- SYSDYN.ValveSymbol.textLocation --> SYSDYN.Location +VP = +SIMU = +PROJECT = +IMAGE = +ACT = +MOD = +STR = +SYSDYN = +SILK = +SHEET = +JFREE = + + +SBC = SYSDYN.ModelingBrowseContext : VP.BrowseContext +SAC = SYSDYN.ModelingActionContext : VP.BrowseContext + VP.BrowseContext.IsIncludedIn PROJECT.ProjectActionContext + +SBC.VariableNodeType +SBC.BuiltinFunctions : VP.ResourceNodeType +SBC.ModuleTypeChildRule : VP.ChildRule +SBC.ModuleContentChildRule : VP.ChildRule +SBC.VariableChildRule : VP.ChildRule + +SBC + @VP.relationChildRuleWithFolder SIMU.Model L0.ConsistsOf SYSDYN.Experiment + SBC.ExperimentsFolder : VP.ResourceNodeType + + @VP.relationChildRule SYSDYN.Experiment SYSDYN.Experiment.result SYSDYN.Result + + @VP.customChildRule MBC.Configuration SBC.VariableChildRule + SBC.Variable : SBC.VariableNodeType + + @VP.customChildRule SBC.Variable SBC.VariableChildRule + SBC.Variable + + @VP.relationChildRule MBC.Configuration L0.ConsistsOf SHEET.Book + @VP.relationChildRule SHEET.Book L0.ConsistsOf SHEET.Spreadsheet + + + // Function libraries + // Functions folder + @VP.relationChildRuleWithFolder MOD.StructuralModel L0.ConsistsOf SYSDYN.SysdynModelicaFunction + SBC.FunctionsFolder : VP.ResourceNodeType + @VP.relationChildRule SBC.FunctionsFolder L0.ConsistsOf SYSDYN.SysdynModelicaFunctionLibrary + + // Function libraries + @VP.relationChildRule SYSDYN.SysdynModelicaFunctionLibrary L0.ConsistsOf SYSDYN.SysdynModelicaFunctionLibrary + @VP.relationChildRule SYSDYN.SysdynModelicaFunctionLibrary L0.ConsistsOf SYSDYN.SysdynModelicaFunction + @VP.relationChildRule SYSDYN.SharedFunctionOntology L0.ConsistsOf SYSDYN.SysdynModelicaFunctionLibrary + @VP.relationChildRule SYSDYN.SharedFunctionOntology L0.ConsistsOf SYSDYN.SysdynModelicaFunction + + // Built-in functions + VP.BrowseContext.HasChildContribution _ : VP.ChildContribution + VP.ChildContribution.HasParentNodeType SBC.FunctionsFolder + VP.ChildContribution.HasChildNodeType SBC.BuiltinFunctions + VP.ChildContribution.HasRule _ : VP.ConstantChildRule + VP.ConstantChildRule.HasChild BuiltinFunctions + @VP.relationChildRule SBC.BuiltinFunctions L0.ConsistsOf SYSDYN.SysdynModelicaFunctionLibrary + @VP.relationChildRule SBC.BuiltinFunctions L0.ConsistsOf SYSDYN.SysdynModelicaFunction + + // Shared functions linked to a model + @VP.relationChildRuleWithFolder SBC.FunctionsFolder L0.IsLinkedTo SYSDYN.SharedFunctionOntology + SBC.SharedFunctionsFolder : VP.ResourceNodeType + + + // Modules + @VP.equalContentChildRule MOD.StructuralModel + SBC.ModulesFolder : VP.ResourceNodeType + @VP.customChildRule SBC.ModulesFolder SBC.ModuleTypeChildRule + SBC.ModuleSymbol + @VP.customChildRule SBC.ModuleSymbol SBC.ModuleContentChildRule STR.Component + + // Charts + @VP.relationChildRuleWithFolder MOD.StructuralModel L0.ConsistsOf JFREE.Chart + SBC.ChartsFolder : VP.ResourceNodeType + +// Labels +SBC.VariableNameLabelRule : VP.LabelRule +SBC.ModuleTypeLabelRule : VP.LabelRule + +SBC + @VP.constantLabelRule SBC.ExperimentsFolder "Experiments" + @VP.constantLabelRule SBC.FunctionsFolder "Functions" + @VP.constantLabelRule SBC.ChartsFolder "Charts" + @VP.constantLabelRule SBC.ModulesFolder "Modules" + @VP.constantLabelRule SBC.SharedFunctionsFolder "Shared Functions" + @VP.constantLabelRule SHEET.Book "Spreadsheets" + + @VP.customLabelRule SIMU.Run PROJECT.ProjectBrowseContext.RunLabelRule + @VP.customLabelRule SBC.BuiltinFunctions VP.ResourceNameLabelRule + @VP.customLabelRule SBC.ModuleSymbol SBC.ModuleTypeLabelRule + @VP.customLabelRule SBC.Variable SBC.VariableNameLabelRule + @VP.customLabelRule SHEET.Spreadsheet VP.ResourceNameLabelRule + @VP.customLabelRule SYSDYN.HistoryDataset VP.ResourceLabelLabelRule + @VP.customLabelRule JFREE.Chart VP.ResourceLabelLabelRule + +// Modifiers +SBC + @VP.customLabelRule SYSDYN.SysdynModelicaFunction VP.ResourceNameModifierRule + @VP.customLabelRule SYSDYN.HistoryDataset VP.ResourceLabelModifierRule + @VP.customLabelRule JFREE.Chart VP.ResourceLabelModifierRule + @VP.customLabelRule SBC.FunctionsFolder VP.NoModifierRule + + +// Decorations +SBC.ActiveLabelDecorationRule : VP.ConstantLabelDecorationRule + VP.ConstantLabelDecorationRule.HasFormat "%s [ACTIVE]" + VP.ConstantLabelDecorationRule.HasStyle "B" + + +// Images +SBC.VariableImageRule : VP.ImageRule +SBC.ChartImageRule : VP.ImageRule +SBC.ResultImageRule : VP.ImageRule + +SBC + @VP.customImageRule SBC.Variable SBC.VariableImageRule + @VP.customImageRule JFREE.Chart SBC.ChartImageRule + @VP.customImageRule SYSDYN.Result SBC.ResultImageRule + + + @VP.constantImageRule SBC.ExperimentsFolder SILK.folder + @VP.constantImageRule SBC.FunctionsFolder SILK.folder + @VP.constantImageRule SBC.SharedFunctionsFolder SILK.folder_link + @VP.constantImageRule SYSDYN.SysdynModelicaFunctionLibrary SILK.folder + @VP.constantImageRule SYSDYN.SysdynModelicaFunction SILK.brick + @VP.constantImageRule SBC.ModulesFolder SILK.folder + @VP.constantImageRule SBC.ModuleSymbol SILK.bricks + @VP.constantImageRule SBC.BuiltinFunctions SILK.folder_link + @VP.constantImageRule SYSDYN.SharedFunctionOntology SILK.folder_link + @VP.constantImageRule SHEET.Book SILK.table_multiple + @VP.constantImageRule SHEET.Spreadsheet SILK.table + @VP.constantImageRule SYSDYN.BasicExperiment SILK.time + @VP.constantImageRule SYSDYN.PlaybackExperiment SILK.timeline_marker + @VP.constantImageRule SBC.ChartsFolder SILK.folder + @VP.constantImageRule SYSDYN.HistoryDataset SILK.table + +SBC + // Active experiment + VP.BrowseContext.HasVisualsContribution _ : VP.VisualsContribution + VP.VisualsContribution.HasNodeType SYSDYN.Experiment + VP.VisualsContribution.HasCondition _ : VP.HasStatementTest + VP.HasStatementTest.HasRelation SIMU.IsActive + VP.VisualsContribution.HasRule SBC.ActiveLabelDecorationRule + + // Show result in charts + VP.BrowseContext.HasVisualsContribution _ : VP.VisualsContribution + VP.VisualsContribution.HasNodeType SYSDYN.Result + VP.VisualsContribution.HasCondition _ : VP.HasStatementTest + VP.HasStatementTest.HasRelation SYSDYN.Result.showResult + VP.VisualsContribution.HasRule SBC.ActiveLabelDecorationRule + + +// Actions +ACTIONS = SAC.Actions : L0.Library + +// NEW -Actions +ACTIONS.NewModuleType : ACT.Action +ACTIONS.NewEnumeration : ACT.Action +ACTIONS.NewFunction : ACT.Action +ACTIONS.NewFunctionLibrary : ACT.Action +ACTIONS.NewSharedFunctionLibrary : ACT.Action +ACTIONS.NewExperiment : ACT.Action +ACTIONS.NewSimulationPlaybackExperiment : ACT.Action +ACTIONS.NewLineChart : ACT.Action +ACTIONS.NewBarChart : ACT.Action +ACTIONS.NewPieChart : ACT.Action +ACTIONS.NewSheet : ACT.Action +ACTIONS.NewHistoryData : ACT.Action + +SAC + @VP.actionContribution "Module" SBC.ModulesFolder SILK.bricks VP.NewActionCategory ACTIONS.NewModuleType + @VP.actionContribution "Enumeration" MBC.Configuration SILK.brick VP.NewActionCategory ACTIONS.NewEnumeration + @VP.actionContribution "Enumeration" SBC.ModuleSymbol SILK.brick VP.NewActionCategory ACTIONS.NewEnumeration + @VP.actionContribution "Function" SBC.FunctionsFolder SILK.brick VP.NewActionCategory ACTIONS.NewFunction + @VP.actionContribution "Function" SYSDYN.SysdynModelicaFunctionLibrary SILK.brick VP.NewActionCategory ACTIONS.NewFunction + @VP.actionContribution "Function" SYSDYN.SharedFunctionOntology SILK.brick VP.NewActionCategory ACTIONS.NewFunction + @VP.actionContribution "Function Library" SBC.FunctionsFolder SILK.folder VP.NewActionCategory ACTIONS.NewFunctionLibrary + @VP.actionContribution "Function Library" SYSDYN.SysdynModelicaFunctionLibrary SILK.folder VP.NewActionCategory ACTIONS.NewFunctionLibrary + @VP.actionContribution "Function Library" SYSDYN.SharedFunctionOntology SILK.folder VP.NewActionCategory ACTIONS.NewFunctionLibrary + @VP.actionContribution "Shared Function Library" SBC.SharedFunctionsFolder SILK.folder VP.NewActionCategory ACTIONS.NewSharedFunctionLibrary + @VP.actionContribution "Experiment" SBC.ExperimentsFolder SILK.time VP.NewActionCategory ACTIONS.NewExperiment + @VP.actionContribution "Simulation Playback Experiment" SBC.ExperimentsFolder SILK.timeline_marker VP.NewActionCategory ACTIONS.NewSimulationPlaybackExperiment + @VP.actionContribution "Line Chart" SBC.ChartsFolder SILK.chart_line VP.NewActionCategory ACTIONS.NewLineChart + @VP.actionContribution "Pie Chart" SBC.ChartsFolder SILK.chart_pie VP.NewActionCategory ACTIONS.NewPieChart + @VP.actionContribution "Bar Chart" SBC.ChartsFolder SILK.chart_bar VP.NewActionCategory ACTIONS.NewBarChart + @VP.actionContribution "Sheet" SHEET.Book SILK.table VP.NewActionCategory ACTIONS.NewSheet + @VP.actionContribution "History Data" SYSDYN.Experiment SILK.table VP.NewActionCategory ACTIONS.NewHistoryData + + +// Drop actions +ACTIONS.FunctionDropAction : ACT.DropAction +ACTIONS.ChartDropAction : ACT.DropAction + +SBC + @VP.dropActionContribution SBC.FunctionsFolder ACTIONS.FunctionDropAction 1.0 + @VP.dropActionContribution SYSDYN.SysdynModelicaFunction ACTIONS.FunctionDropAction 1.0 + @VP.dropActionContribution SYSDYN.SysdynModelicaFunctionLibrary ACTIONS.FunctionDropAction 1.0 + @VP.dropActionContribution SYSDYN.SharedFunctionOntology ACTIONS.FunctionDropAction 1.0 + @VP.dropActionContribution JFREE.Chart ACTIONS.ChartDropAction 1.0 + diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn_ModelBrowser_Viewpoint.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn_ModelBrowser_Viewpoint.pgraph deleted file mode 100644 index 29442e80..00000000 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn_ModelBrowser_Viewpoint.pgraph +++ /dev/null @@ -1,114 +0,0 @@ -L0 = -VP = -SIMU = -PROJECT = -IMAGE = -ACT = -MOD = -STR = -SYSDYN = -SILK = - -SBC = SYSDYN.ProjectBrowseContext : VP.BrowseContext -SAC = SYSDYN.ProjectActionContext : VP.BrowseContext - -MBC = MOD.ModelingBrowseContext : VP.BrowseContext - VP.BrowseContext.IsIncludedIn PROJECT.ProjectBrowseContext -MAC = MOD.ModelingActionContext : VP.BrowseContext - VP.BrowseContext.IsIncludedIn PROJECT.ProjectActionContext - -BuiltinFunctions = -SBC.BuiltinFunctions : VP.ResourceNodeType -SBC.ModuleTypeChildRule : VP.ChildRule -SBC.ModuleContentChildRule : VP.ChildRule -SBC.ModuleTypeLabelRule : VP.LabelRule - -MBC - @VP.relationChildRuleWithFolder SIMU.Model L0.ConsistsOf SIMU.Experiment - SBC.ExperimentsFolder : VP.ResourceNodeType - //@VP.relationChildRule SIMU.Experiment L0.ConsistsOf SIMU.Run - // Function libraries - // Functions folder - @VP.relationChildRuleWithFolder MOD.StructuralModel L0.ConsistsOf SYSDYN.SysdynModelicaFunction - SBC.FunctionsFolder : VP.ResourceNodeType - @VP.relationChildRule SBC.FunctionsFolder L0.ConsistsOf SYSDYN.SysdynModelicaFunctionLibrary - // Function libraries - @VP.relationChildRule SYSDYN.SysdynModelicaFunctionLibrary L0.ConsistsOf SYSDYN.SysdynModelicaFunctionLibrary - @VP.relationChildRule SYSDYN.SysdynModelicaFunctionLibrary L0.ConsistsOf SYSDYN.SysdynModelicaFunction - // Built-in functions - VP.BrowseContext.HasChildContribution _ : VP.ChildContribution - VP.ChildContribution.HasParentNodeType SBC.FunctionsFolder - VP.ChildContribution.HasChildNodeType SBC.BuiltinFunctions - VP.ChildContribution.HasRule _ : VP.ConstantChildRule - VP.ConstantChildRule.HasChild BuiltinFunctions - @VP.relationChildRule SBC.BuiltinFunctions L0.ConsistsOf SYSDYN.SysdynModelicaFunctionLibrary - @VP.relationChildRule SBC.BuiltinFunctions L0.ConsistsOf SYSDYN.SysdynModelicaFunction - // Shared functions linked to a model - @VP.relationChildRuleWithFolder SBC.FunctionsFolder L0.IsLinkedTo SYSDYN.SharedFunctionOntology - SBC.SharedFunctionsFolder : VP.ResourceNodeType - - - //Modules - @VP.equalContentChildRule MOD.StructuralModel - SBC.ModulesFolder : VP.ResourceNodeType - @VP.customChildRule SBC.ModulesFolder SBC.ModuleTypeChildRule - SBC.ModuleSymbol : VP.ResourceNodeType - @VP.customChildRule SBC.ModuleSymbol SBC.ModuleContentChildRule STR.Component - - -// Labels -MBC - @VP.constantLabelRule SBC.ExperimentsFolder "Experiments" - @VP.customLabelRule SIMU.Run PROJECT.ProjectBrowseContext.RunLabelRule - @VP.constantLabelRule SBC.FunctionsFolder "Functions" - @VP.constantLabelRule SBC.SharedFunctionsFolder "Shared Functions" - @VP.constantLabelRule SBC.ModulesFolder "Modules" - @VP.customLabelRule SBC.BuiltinFunctions VP.ResourceNameLabelRule - @VP.customLabelRule SBC.ModuleSymbol SBC.ModuleTypeLabelRule - - -// Images -MBC - @VP.constantImageRule SBC.ExperimentsFolder PROJECT.ProjectBrowseContext.Images.Folder - @VP.constantImageRule SBC.FunctionsFolder SILK.folder - @VP.constantImageRule SBC.SharedFunctionsFolder SILK.folder - @VP.constantImageRule SYSDYN.SysdynModelicaFunction SILK.brick - @VP.constantImageRule SBC.ModulesFolder SILK.folder - @VP.constantImageRule SBC.ModuleSymbol SILK.bricks - @VP.constantImageRule SBC.BuiltinFunctions SILK.folder - -// Modifiers -MBC - @VP.customLabelRule SYSDYN.SysdynModelicaFunction VP.ResourceNameModifierRule - - -// Actions -ACTIONS = SAC.Actions : L0.Library - -// NEW -Actions -ACTIONS.NewModuleType : ACT.Action -ACTIONS.NewEnumeration : ACT.Action -ACTIONS.NewFunction : ACT.Action -ACTIONS.NewFunctionLibrary : ACT.Action -ACTIONS.NewSharedFunctionLibrary : ACT.Action -ACTIONS.OpenWorkbook : ACT.Action - - -MAC - @VP.actionContribution "Module" SBC.ModulesFolder SILK.bricks VP.NewActionCategory ACTIONS.NewModuleType - VP.BrowseContext.HasActionContribution _ : VP.ActionContribution - L0.HasLabel "Open Workbook" - VP.ActionContribution.HasImage SILK.brick - VP.ActionContribution.HasNodeType MBC.Configuration - VP.ActionContribution.HasAction ACTIONS.OpenWorkbook - - @VP.actionContribution "Enumeration" MBC.Configuration SILK.brick VP.NewActionCategory ACTIONS.NewEnumeration - //@VP.actionContribution "Open Workbook" MBC.Configuration SILK.brick VP.NewActionCategory ACTIONS.OpenWorkbook - @VP.actionContribution "Enumeration" SBC.ModuleSymbol SILK.brick VP.NewActionCategory ACTIONS.NewEnumeration - @VP.actionContribution "Function" SBC.FunctionsFolder SILK.brick VP.NewActionCategory ACTIONS.NewFunction - @VP.actionContribution "Function" SYSDYN.SysdynModelicaFunctionLibrary SILK.brick VP.NewActionCategory ACTIONS.NewFunction - @VP.actionContribution "Function" SYSDYN.SharedFunctionOntology SILK.brick VP.NewActionCategory ACTIONS.NewFunction - @VP.actionContribution "Function Library" SBC.FunctionsFolder SILK.folder VP.NewActionCategory ACTIONS.NewFunctionLibrary - @VP.actionContribution "Function Library" SYSDYN.SysdynModelicaFunctionLibrary SILK.folder VP.NewActionCategory ACTIONS.NewFunctionLibrary - @VP.actionContribution "Function Library" SYSDYN.SharedFunctionOntology SILK.folder VP.NewActionCategory ACTIONS.NewFunctionLibrary - @VP.actionContribution "Shared Function Library" SBC.SharedFunctionsFolder SILK.folder VP.NewActionCategory ACTIONS.NewSharedFunctionLibrary \ No newline at end of file diff --git a/org.simantics.sysdyn.ontology/graph/WorkModel.pgraph b/org.simantics.sysdyn.ontology/graph/WorkModel.pgraph index aa22c018..6205b847 100644 --- a/org.simantics.sysdyn.ontology/graph/WorkModel.pgraph +++ b/org.simantics.sysdyn.ontology/graph/WorkModel.pgraph @@ -17,6 +17,7 @@ WM = : PROJ.Project @L0.new */ +/* WM = : PROJ.Project @L0.new @@ -463,12 +464,7 @@ WMC.f41 : SYSDYN.Flow WorkModuleConfigurationDiagram : SYSDYN.ConfigurationDiagram - none 0 fill 1 + none 0 fill 1 \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 05cd9c9c..6a90ec0e 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -159,12 +159,6 @@ relationship="left" relative="org.eclipse.ui.editorss"> - - + + + + + + + + bss = ISelectionUtils.filterSetSelection(e.getResource(), BrowserSelection.class); if(!bss.isEmpty()) { - Layer0 l0 = Layer0.getInstance(g); + // Find varaible from BrowserSelection. (Will be replaced with the Variable adaption above) for(BrowserSelection bs : bss) { Resource configuration = (Resource)bs.getAdapter(Resource.class); Resource instanceOf = g.getSingleObject(configuration, l0.InstanceOf); SysdynResource sr = SysdynResource.getInstance(g); - StructuralResource2 sr2 = StructuralResource2.getInstance(g); if(g.isInheritedFrom(instanceOf, sr.Module)) { configuration = g.getSingleObject(instanceOf, sr2.IsDefinedBy); - Variable variable = (Variable) bs.getAdapter(Variable.class); + variable = (Variable) bs.getAdapter(Variable.class); String rvi = Variables.getRVI(g, variable).substring(1); Resource model = Variables.getModel(g, variable); addShowModuleAction(e, getResourceEditorInput(g, model, configuration, rvi)); @@ -65,8 +88,6 @@ public class ShowInstantiatedModuleAction implements IDoubleClickAction { } else { ModuleNode moduleNode = ISelectionUtils.filterSingleSelection(e.getResource(), ModuleNode.class); if(moduleNode != null) { - Layer0 l0 = Layer0.getInstance(g); - StructuralResource2 sr2 = StructuralResource2.getInstance(g); Resource model; String rvi; if(moduleNode.getVariable() != null) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynModelBrowser.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynModelBrowser.java index bf28f106..00115826 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynModelBrowser.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynModelBrowser.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser; import java.util.Arrays; @@ -5,18 +16,23 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; -import org.simantics.structural.ui.modelBrowser.ModelBrowser; +import org.simantics.structural.ui.modelBrowser.ModelBrowser2; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.properties.SysdynPropertyPage; import org.simantics.ui.workbench.IPropertyPage; -public class SysdynModelBrowser extends ModelBrowser { +/** + * Model browser for sysdyn models. Content configured in SysdynModelingViewpoint.pgraph + * @author Teemu Lempinen + * + */ +public class SysdynModelBrowser extends ModelBrowser2 { - final private Set browseContexts = new HashSet(Arrays.asList(SysdynResource.URIs.ProjectBrowseContext, "http://www.simantics.org/Operating-1.1/Browser", "http://www.simantics.org/Image-1.0/Browser")); + final private Set browseContexts = new HashSet(Arrays.asList(SysdynResource.URIs.ModelingBrowseContext, "http://www.simantics.org/Operating-1.1/Browser", "http://www.simantics.org/Image-1.0/Browser")); @Override protected IPropertyPage getPropertyPage() { - return new SysdynPropertyPage(getSite(), Collections.singleton(SysdynResource.URIs.ModelBrowser)); + return new SysdynPropertyPage(getSite(), Collections.singleton(SysdynResource.URIs.ModelingBrowseContext)); } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/ActivateResultDatasetAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/ActivateResultDatasetAction.java new file mode 100644 index 00000000..8c7e6fbf --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/ActivateResultDatasetAction.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.DoubleClickEvent; +import org.simantics.ui.IDoubleClickAction; +import org.simantics.ui.utils.ResourceAdaptionUtils; + +/** + * Activates a result dataset to be shown in charts and other result visualizations + * + * @author Teemu Lempinen + * + */ +public class ActivateResultDatasetAction implements IDoubleClickAction { + + @Override + public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException { + final Resource result = ResourceAdaptionUtils.toSingleResource(e.getResource()); + if (result == null) + return; + + ReadGraph graph = e.getGraph(); + + if(graph.isInstanceOf(result, SysdynResource.getInstance(graph).Result)) { + + graph.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.isInstanceOf(result, sr.Result)) { + if (graph.hasStatement(result, sr.Result_showResult)) { + graph.denyStatement(result, sr.Result_showResult, result); + } else { + graph.claim(result, sr.Result_showResult, result); + } + } + } + }); + } + + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewSharedFunctionLibraryAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewSharedFunctionLibraryAction.java deleted file mode 100644 index c5bdeba4..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewSharedFunctionLibraryAction.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.simantics.sysdyn.ui.browser.actions; - -import org.simantics.db.Resource; - -public class NewSharedFunctionLibraryAction extends NewFunctionLibraryAction { - - - @Override - public Runnable create(Object target) { - if(!(target instanceof Resource)) - return null; - final Resource resource = (Resource)target; - - return new Runnable() { - @Override - public void run() { - createLibrary(resource, true); - } - }; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/OpenSheetAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/OpenSheetAction.java new file mode 100644 index 00000000..17e37c0b --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/OpenSheetAction.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions; + +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.spreadsheet.resource.SpreadsheetResource; +import org.simantics.ui.DoubleClickEvent; +import org.simantics.ui.IDoubleClickAction; +import org.simantics.ui.utils.ResourceAdaptionUtils; +import org.simantics.ui.workbench.ResourceEditorInput2; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +/** + * Opens the selected spreadsheet in a spreadsheet editor + * @author Teemu Lempinen + * + */ +public class OpenSheetAction implements IDoubleClickAction { + + @Override + public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException { + Resource result = ResourceAdaptionUtils.toSingleResource(e.getResource()); + if (result == null) + return; + + ReadGraph graph = e.getGraph(); + SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph); + + final Resource sheet = result; + + if(graph.isInstanceOf(sheet, SHEET.Spreadsheet)) { + Variable variable = graph.adapt(sheet, Variable.class); + Resource model = Variables.getModel(graph, variable); + final String modelURI = graph.getURI(model); + final String RVI = Variables.getRVI(graph, variable); + + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + + private static final String EDITOR_ID = "org.simantics.spreadsheet.ui.editor2"; + + @Override + public void run() { + try { + WorkbenchUtils.openEditor(EDITOR_ID, new ResourceEditorInput2(EDITOR_ID, sheet, modelURI, RVI)); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + }); + + } + } +} \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/OpenWorkbookAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/OpenWorkbookAction.java deleted file mode 100644 index f233f3a4..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/OpenWorkbookAction.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.simantics.sysdyn.ui.browser.actions; - -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.PossibleObjectWithType; -import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.ActionFactory; -import org.simantics.db.layer0.util.Simantics; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.layer0.variable.Variables; -import org.simantics.layer0.Layer0; -import org.simantics.modeling.ui.diagramEditor.OpenSheetAdapter; -import org.simantics.simulation.ontology.SimulationResource; -import org.simantics.spreadsheet.resource.SpreadsheetResource; -import org.simantics.ui.SimanticsUI; -import org.simantics.ui.workbench.ResourceEditorInput2; -import org.simantics.utils.ui.workbench.WorkbenchUtils; - -public class OpenWorkbookAction implements ActionFactory{ - - @Override - public Runnable create(Object target) { - - if(!(target instanceof Resource)) - return null; - - final Resource resource = (Resource)target; - - return new Runnable() { - - @Override - public void run() { - - try { - - SimanticsUI.getSession().asyncRequest(new ReadRequest() { - @Override - public void run(ReadGraph graph) throws DatabaseException { - - Layer0 L0 = Layer0.getInstance(graph); - SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); - - Resource book = graph.syncRequest(new PossibleObjectWithType(resource, L0.ConsistsOf, sr.Book)); - final Resource sheet = graph.syncRequest(new PossibleObjectWithType(book, L0.ConsistsOf, sr.Spreadsheet)); - - SimulationResource SIMU = SimulationResource.getInstance(graph); - Variable variable = graph.adapt(sheet, Variable.class); - Resource model = Variables.getModel(graph, variable); - final String modelURI = graph.getURI(model); - final String RVI = Variables.getRVI(graph, variable); - - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - - private static final String EDITOR_ID = "org.simantics.spreadsheet.ui.editor2"; - - @Override - public void run() { - try { - System.out.println("Activating sheet: model=" + modelURI + " rvi=" + RVI); - WorkbenchUtils.openEditor(EDITOR_ID, new ResourceEditorInput2(EDITOR_ID, sheet, modelURI, RVI)); - } catch (PartInitException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - }); - } - }); - } catch (Exception e) { - e.printStackTrace(); - } - - } - - }; - - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/drop/ChartDropAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/drop/ChartDropAction.java new file mode 100644 index 00000000..19ec9743 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/drop/ChartDropAction.java @@ -0,0 +1,180 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.drop; + +import java.util.Iterator; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.request.SingleObjectWithType; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.DropActionFactory; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.trend.chart.ChartUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Action for droppin variables to charts + * @author Teemu Lempinen + * + */ +public class ChartDropAction implements DropActionFactory { + + @Override + public Runnable create(ReadGraph g, Object target, Object source) throws DatabaseException { + + final Resource targetChart = AdaptionUtils.adaptToSingle(target, Resource.class); + if(targetChart == null || source == null || !(source instanceof IStructuredSelection)) + return null; + + final IStructuredSelection selection = (IStructuredSelection) source; + + return new Runnable() { + + @Override + public void run() { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 L0 = Layer0.getInstance(graph); + JFreeChartResource JFREE = JFreeChartResource.getInstance(graph); + + Iterator iterator = selection.iterator(); + + // Run through all selections and add all IndependentVariables and Inputs to the target chart + while(iterator.hasNext()) { + + Variable variable = AdaptionUtils.adaptToSingle(iterator.next(), Variable.class); + if(variable == null) + continue; + + Resource represents = (Resource)variable.getPropertyValue(graph, Variables.REPRESENTS); + if(represents == null || + !(graph.isInstanceOf(represents, sr.IndependentVariable) || + graph.isInstanceOf(represents, sr.Input))) + continue; + + Resource plot = graph.syncRequest(new PossibleObjectWithType(targetChart, L0.ConsistsOf, JFREE.Plot)); + if(plot != null) { + if(graph.isInstanceOf(plot, JFREE.XYPlot)) { + dropToLineChart(graph, targetChart, variable); + } else if(graph.isInstanceOf(plot, JFREE.CategoryPlot)) { + dropToBarChart(graph, targetChart, variable); + } else if(graph.isInstanceOf(plot, JFREE.PiePlot)) { + dropToPieChart(graph, targetChart, variable); + } + } + } + + } + }); + } + }; + } + + + /** + * Drop variable to a pie chart + * @param graph ReadGraph + * @param pieChart Pie chart resource + * @param variable Dropped variable + * @throws DatabaseException + */ + private void dropToPieChart(WriteGraph graph, Resource pieChart, Variable variable) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + Resource plot = graph.syncRequest(new SingleObjectWithType(pieChart, l0.ConsistsOf, jfree.Plot)); + if(plot == null) + return; + + Resource dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset)); + + if(dataset == null) + return; + + // Create the series and attach it to the dataset + String rvi = Variables.getRVI(graph, variable); + Resource series = ChartUtils.createSeries(graph, dataset, rvi); + graph.claimLiteral(series, jfree.Series_exploded, false); + } + + /** + * Drop variable to a bar chart + * @param graph ReadGraph + * @param barChart Bar chart resource + * @param variable Dropped variable + * @throws DatabaseException + */ + private void dropToBarChart(WriteGraph graph, Resource barChart, Variable variable) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + Resource plot = graph.syncRequest(new SingleObjectWithType(barChart, l0.ConsistsOf, jfree.Plot)); + if(plot == null) + return; + + Resource dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset)); + + if(dataset == null) + return; + + // Create the series and attach it to the dataset + String rvi = Variables.getRVI(graph, variable); + ChartUtils.createSeries(graph, dataset, rvi); + } + + /** + * Drop variable to a line chart + * @param graph ReadGraph + * @param lineChart Line chart resource + * @param variable Dropped variable + * @throws DatabaseException + */ + private void dropToLineChart(WriteGraph graph, Resource lineChart, Variable variable) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + Resource plot = graph.syncRequest(new SingleObjectWithType(lineChart, l0.ConsistsOf, jfree.Plot)); + if(plot == null) + return; + + Resource rangeAxis = null; + Resource dataset = null; + Resource rangeAxisList = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); + if(rangeAxisList == null || ListUtils.toList(graph, rangeAxisList).isEmpty()) { + // No range axis -> Create a new one + rangeAxis = ChartUtils.createNumberRangeAxis(graph, plot); + Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis); + dataset = ChartUtils.createXYDataset(graph, plot, domainAxis, rangeAxis); + } else { + rangeAxis = ListUtils.toList(graph, rangeAxisList).get(0); + dataset = graph.getPossibleObject(rangeAxis, jfree.Dataset_mapToRangeAxis_Inverse); + } + + // Create the series and attach it to the dataset + String rvi = Variables.getRVI(graph, variable); + ChartUtils.createSeries(graph, dataset, rvi); + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/drop/FunctionDropAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/drop/FunctionDropAction.java new file mode 100644 index 00000000..588ac878 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/drop/FunctionDropAction.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.drop; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.DropActionFactory; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Action for moving functions and function libraries in model browser + * @author Teemu Lempinen + * + */ +public class FunctionDropAction implements DropActionFactory { + + @Override + public Runnable create(ReadGraph g, Object target, Object source) throws DatabaseException { + Resource t = AdaptionUtils.adaptToSingle(target, Resource.class); + Resource s = AdaptionUtils.adaptToSingle(source, Resource.class); + + if(t == null || s == null) + return null; + + SysdynResource sr = SysdynResource.getInstance(g); + Layer0 L0 = Layer0.getInstance(g); + + // If target is a function, find functions parent to be the drop target + if(g.isInstanceOf(t, sr.SysdynModelicaFunction)) + t = g.getSingleObject(t, L0.PartOf); + + final Resource library = t; + final Resource tobemoved = s; + + // Libraries and model accept drops + if(!(g.isInstanceOf(library, sr.SysdynModelicaFunctionLibrary) || + g.isInstanceOf(library, sr.SysdynModel) || + g.isInstanceOf(library, sr.SharedFunctionOntology))) + return null; + + // Functions and function libraries can be dropped + if(!(g.isInstanceOf(tobemoved, sr.SysdynModelicaFunction) || + g.isInstanceOf(tobemoved, sr.SysdynModelicaFunctionLibrary))) + return null; + + + return new Runnable() { + + @Override + public void run() { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource oldLib = graph.getSingleObject(tobemoved, L0.PartOf); + + // Remove dragged entity from its parent and add it to the new parent + graph.claim(tobemoved, L0.PartOf, library); + graph.deny(tobemoved, L0.PartOf, oldLib); + FunctionUtils.updateFunctionFileForLibrary(graph, oldLib); + FunctionUtils.updateFunctionFileForLibrary(graph, library); + } + + }); + } + }; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewBarChartAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewBarChartAction.java new file mode 100644 index 00000000..2e16bcec --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewBarChartAction.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.newActions; + +import java.util.Collections; +import java.util.UUID; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.ui.SimanticsUI; + +/** + * Creates a new bar chart to a model + * @author Teemu Lempinen + * + */ +public class NewBarChartAction implements ActionFactory{ + + @Override + public Runnable create(Object target) { + if(!(target instanceof Resource)) + return null; + final Resource model = (Resource)target; + + return new Runnable() { + @Override + public void run() { + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + G2DResource g2d = G2DResource.getInstance(graph); + + // Chart + Resource jfreechart = GraphUtils.create2(graph, jfree.Chart, + l0.HasName, "BarChart" + UUID.randomUUID().toString(), + l0.HasLabel, NameUtils.findFreshLabel(graph, "Bar Chart", model), + l0.PartOf, model, + jfree.Chart_visibleBorder, true, + jfree.Chart_borderWidth, 3, + jfree.Chart_visibleLegend, false + ); + + // Border color + graph.claimLiteral(jfreechart, jfree.Chart_borderColor, g2d.Color, new float[] {0,0,0,1}); + + // Title + GraphUtils.create2(graph, jfree.TextTitle, + l0.HasName, "TextTitle" + UUID.randomUUID().toString(), + l0.HasLabel, "Bar Chart Title", + jfree.Title_position, jfree.Top, + l0.PartOf, jfreechart); + + // X-axis + Resource domainAxis = GraphUtils.create2(graph, jfree.CategoryAxis, + l0.HasName, "CategoryAxis" + UUID.randomUUID().toString()); + + // Y-axis + Resource rangeAxis = GraphUtils.create2(graph, jfree.NumberAxis, + l0.HasName, "NumberAxis" + UUID.randomUUID().toString()); + + // Renderer + Resource renderer = GraphUtils.create2(graph, jfree.BarRenderer); + + // Dataset + Resource dataset = GraphUtils.create2(graph, jfree.CategoryDataset, + l0.HasName, "CategoryDataset" + UUID.randomUUID().toString(), + jfree.Dataset_mapToDomainAxis, domainAxis, + jfree.Dataset_mapToRangeAxis, rangeAxis, + jfree.Dataset_seriesList, ListUtils.create(graph, Collections.emptyList()), + jfree.Dataset_renderer, renderer); + + // Plot + GraphUtils.create2(graph, jfree.CategoryPlot, + l0.HasName, "Category plot" + UUID.randomUUID().toString(), + l0.PartOf, jfreechart, + jfree.Plot_domainAxis, domainAxis, + jfree.Plot_rangeAxis, rangeAxis, + jfree.Plot_rangeAxisList, ListUtils.create(graph, Collections.singletonList(rangeAxis)), + l0.ConsistsOf, dataset, + l0.ConsistsOf, domainAxis, + l0.ConsistsOf, rangeAxis); + } + + }); + } + }; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewEnumerationAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewEnumerationAction.java similarity index 69% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewEnumerationAction.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewEnumerationAction.java index 8984a09b..dc3d4d0d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewEnumerationAction.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewEnumerationAction.java @@ -1,4 +1,15 @@ -package org.simantics.sysdyn.ui.browser.actions; +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.newActions; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -14,6 +25,11 @@ import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; import org.simantics.ui.SimanticsUI; +/** + * Creates a new enumeration to a model or module + * @author Teemu Lempinen + * + */ public class NewEnumerationAction implements ActionFactory{ @Override @@ -34,13 +50,16 @@ public class NewEnumerationAction implements ActionFactory{ SysdynResource sr = SysdynResource.getInstance(g); Layer0 l0 = Layer0.getInstance(g); + // Find the configuration from... Resource configuration = null; if(g.isInstanceOf(resource, sr.Configuration)) { configuration = resource; } else if(g.isInheritedFrom(resource, sr.ModuleSymbol)) { + // Module symbol Resource module = g.getPossibleObject(resource,ModelingResources.getInstance(g).SymbolToComponentType); configuration = g.getPossibleObject(module, StructuralResource2.getInstance(g).IsDefinedBy); } else { + // Module instance Resource instanceOf = g.getSingleObject(resource, l0.InstanceOf); if(g.isInheritedFrom(instanceOf, sr.Module)) { configuration = g.getPossibleObject(instanceOf, StructuralResource2.getInstance(g).IsDefinedBy); @@ -49,14 +68,14 @@ public class NewEnumerationAction implements ActionFactory{ } } - Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes); - + // Find unique name String name = NameUtils.findFreshName(g, "Enum", configuration, l0.ConsistsOf, "%s%d"); - + + // Create enumeration GraphUtils.create2(g, sr.Enumeration, l0.HasName, name, - sr.Enumeration_enumerationIndexes, enumerationIndexes, + sr.Enumeration_enumerationIndexes, OrderedSetUtils.create(g, sr.EnumerationIndexes), l0.PartOf, configuration); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewExperimentAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewExperimentAction.java new file mode 100644 index 00000000..05f79146 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewExperimentAction.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.newActions; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +/** + * Creates a new basic experiment + * @author Teemu Lempinen + * + */ +public class NewExperimentAction implements ActionFactory{ + + @Override + public Runnable create(Object target) { + if(!(target instanceof Resource)) + return null; + final Resource model = (Resource)target; + + return new Runnable() { + @Override + public void run() { + + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + String name = NameUtils.findFreshName(graph, getNameSuggestion(), model, l0.ConsistsOf, "%s%d"); + + Resource experiment = GraphUtils.create2(graph, getExperimentType(graph), + l0.HasName, name, + l0.HasLabel, name, + l0.PartOf, model); + + configureExperiment(graph, experiment); + } + }); + } + }; + } + + /** + * Override to do experiment-specific alterations + */ + protected void configureExperiment(WriteGraph graph, Resource experiment) throws DatabaseException { + + } + + /** + * Get the type of this experiment. + * + * @param g ReadGraph + * @return The type resource of this experiment + */ + protected Resource getExperimentType(ReadGraph g) { + return SysdynResource.getInstance(g).BasicExperiment; + } + + /** + * Returns the suggested name for this experiment. + * If the name has already been taken, appropriate prefix needs to be added. + * + * @return Suggested name for this experiment. + */ + protected String getNameSuggestion() { + return "Experiment"; + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewFunctionAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewFunctionAction.java similarity index 68% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewFunctionAction.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewFunctionAction.java index 506f7bcc..c4e0b3dc 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewFunctionAction.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewFunctionAction.java @@ -1,4 +1,15 @@ -package org.simantics.sysdyn.ui.browser.actions; +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.newActions; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -12,6 +23,11 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.manager.FunctionUtils; import org.simantics.ui.SimanticsUI; +/** + * Creates a new modelica function to a model, function library or shared function library. + * @author Teemu Lempinen + * + */ public class NewFunctionAction implements ActionFactory{ @Override @@ -49,7 +65,7 @@ public class NewFunctionAction implements ActionFactory{ sr.SysdynModelicaFunction_modelicaFunctionCode, "", l0.PartOf, library); - FunctionUtils.updateFunctionFileForLibrary(g, library); + FunctionUtils.updateFunctionFileForLibrary(g, library); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewFunctionLibraryAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewFunctionLibraryAction.java similarity index 77% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewFunctionLibraryAction.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewFunctionLibraryAction.java index 1064e019..38670b8c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewFunctionLibraryAction.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewFunctionLibraryAction.java @@ -1,4 +1,15 @@ -package org.simantics.sysdyn.ui.browser.actions; +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.newActions; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -13,6 +24,11 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.manager.FunctionUtils; import org.simantics.ui.SimanticsUI; +/** + * Creates a new function library + * @author Teemu Lempinen + * + */ public class NewFunctionLibraryAction implements ActionFactory{ @Override @@ -44,6 +60,7 @@ public class NewFunctionLibraryAction implements ActionFactory{ Layer0 l0 = Layer0.getInstance(g); SysdynResource sr = SysdynResource.getInstance(g); + // Libraries can be created to model, function library and shared function library if(!(g.isInstanceOf(libraryLocation, sr.SysdynModel) || g.isInstanceOf(libraryLocation, sr.SysdynModelicaFunctionLibrary) || g.isInstanceOf(libraryLocation, sr.SharedFunctionOntology))) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewHistoryDataAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewHistoryDataAction.java new file mode 100644 index 00000000..43f0ffac --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewHistoryDataAction.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.newActions; + +import java.util.UUID; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +/** + * Create a new history data + * + * @author Teemu Lempinen + * + */ +public class NewHistoryDataAction implements ActionFactory{ + + @Override + public Runnable create(Object target) { + if(!(target instanceof Resource)) + return null; + final Resource experiment = (Resource)target; + + return new Runnable() { + @Override + public void run() { + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + if(!graph.isInstanceOf(experiment, sr.Experiment)) + return; // Not called from an experiment + + Resource model = graph.getPossibleObject(experiment, l0.PartOf); + // Create the history dataset + GraphUtils.create2(graph, + sr.HistoryDataset, + l0.HasName, "HistoryDataset" + UUID.randomUUID().toString(), + l0.HasLabel, NameUtils.findFreshLabel(graph, "History Dataset", experiment), + sr.Experiment_result_Inverse, experiment, + sr.HistoryDataset_columns, Boolean.TRUE, + l0.PartOf, model); + } + }); + } + }; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewLineChartAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewLineChartAction.java new file mode 100644 index 00000000..b21e7fcf --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewLineChartAction.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.newActions; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.UUID; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.ui.SimanticsUI; + +/** + * Creates a new line chart + * @author Teemu Lempinen + * + */ +public class NewLineChartAction implements ActionFactory{ + + @Override + public Runnable create(Object target) { + if(!(target instanceof Resource)) + return null; + final Resource model = (Resource)target; + + return new Runnable() { + @Override + public void run() { + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + G2DResource g2d = G2DResource.getInstance(graph); + + // Chart + Resource jfreechart = GraphUtils.create2(graph, jfree.Chart, + l0.HasName, "Chart" + UUID.randomUUID().toString(), + l0.HasLabel, NameUtils.findFreshLabel(graph, "Chart", model), + l0.PartOf, model, + jfree.Chart_visibleBorder, true, + jfree.Chart_borderWidth, 3); + graph.claimLiteral(jfreechart, jfree.Chart_borderColor, g2d.Color, new float[] {0,0,0,1}); + + // Title + GraphUtils.create2(graph, jfree.TextTitle, + l0.HasName, "TextTitle" + UUID.randomUUID().toString(), + l0.HasLabel, "Chart Title", + jfree.Title_position, jfree.Top, + l0.PartOf, jfreechart); + + // X-axis + Resource domainAxis = GraphUtils.create2(graph, jfree.NumberAxis, + l0.HasName, "NumberAxis" + UUID.randomUUID().toString()); + + // Y-axis + Resource rangeAxis = GraphUtils.create2(graph, jfree.NumberAxis, + l0.HasName, "NumberAxis" + UUID.randomUUID().toString(), + l0.HasLabel, "Y-axis"); + + // Renderer + Resource renderer = GraphUtils.create2(graph, jfree.XYLineRenderer); + + // Dataset + Resource dataset = GraphUtils.create2(graph, jfree.XYDataset, + l0.HasName, "XYDataset" + UUID.randomUUID().toString(), + jfree.Dataset_mapToDomainAxis, domainAxis, + jfree.Dataset_mapToRangeAxis, rangeAxis, + jfree.Dataset_seriesList, ListUtils.create(graph, new ArrayList()), + jfree.Dataset_renderer, renderer); + + // Plot + GraphUtils.create2(graph, jfree.XYPlot, + l0.HasName, "XYPlot" + UUID.randomUUID().toString(), + l0.PartOf, jfreechart, + jfree.Plot_domainAxis, domainAxis, + jfree.Plot_rangeAxis, rangeAxis, + jfree.Plot_rangeAxisList, ListUtils.create(graph, Collections.singletonList(rangeAxis)), + l0.ConsistsOf, dataset, + l0.ConsistsOf, domainAxis, + l0.ConsistsOf, rangeAxis); + } + + }); + } + }; + } + + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewModuleTypeAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewModuleTypeAction.java similarity index 70% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewModuleTypeAction.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewModuleTypeAction.java index 0f8234e2..8b400bde 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewModuleTypeAction.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewModuleTypeAction.java @@ -1,4 +1,15 @@ -package org.simantics.sysdyn.ui.browser.actions; +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.newActions; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -8,7 +19,6 @@ import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.ActionFactory; import org.simantics.db.layer0.adapter.Template; -import org.simantics.diagram.stubs.DiagramResource; import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; @@ -19,6 +29,11 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.ArrayMap; +/** + * Creates a new module type + * @author Teemu Lempinen + * + */ public class NewModuleTypeAction implements ActionFactory{ @Override @@ -34,13 +49,11 @@ public class NewModuleTypeAction implements ActionFactory{ @Override public void perform(WriteGraph g) throws DatabaseException { - // Same as in SysdynProject.java. Should use the same code, not copy. SysdynResource sr = SysdynResource.getInstance(g); Layer0 l0 = Layer0.getInstance(g); Layer0X L0X = Layer0X.getInstance(g); ModelingResources mr = ModelingResources.getInstance(g); StructuralResource2 sr2 = StructuralResource2.getInstance(g); - DiagramResource dr = DiagramResource.getInstance(g); String name = NameUtils.findFreshName(g, "ModuleType", model, l0.ConsistsOf, "%s%d"); @@ -49,6 +62,8 @@ public class NewModuleTypeAction implements ActionFactory{ g.claim(moduleType, l0.Inherits, sr.Module); g.claim(moduleType, l0.PartOf, model); + + Resource configuration = GraphUtils.create2(g, sr.Configuration, l0.HasName, name + "Configuration", @@ -70,6 +85,25 @@ public class NewModuleTypeAction implements ActionFactory{ g.deny(diagram, L0X.HasTrigger, trigger); } } + + 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); @@ -83,15 +117,16 @@ public class NewModuleTypeAction implements ActionFactory{ Resource terminal = g.newResource(); g.claim(terminal, l0.InstanceOf, sr.SysdynTerminal); - DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal, sr.IsHeadOfTerminal); + DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal, sr.IsHeadOfTerminal); Resource terminal2 = g.newResource(); g.claim(terminal2, l0.InstanceOf, sr.SysdynTerminal); DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal2, sr.IsTailOfTerminal); - + g.claim(moduleSymbol, sr2.IsDefinedBy, OrderedSetUtils.create(g, sr2.Composite, terminal, terminal2)); + } }); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewPieChartAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewPieChartAction.java new file mode 100644 index 00000000..1ae83a6a --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewPieChartAction.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.newActions; + +import java.util.Collections; +import java.util.UUID; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.ui.SimanticsUI; + +/** + * Creates a new pie chart + * @author Teemu Lempinen + * + */ +public class NewPieChartAction implements ActionFactory{ + + @Override + public Runnable create(Object target) { + if(!(target instanceof Resource)) + return null; + final Resource model = (Resource)target; + + return new Runnable() { + @Override + public void run() { + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + G2DResource g2d = G2DResource.getInstance(graph); + + // Chart + Resource jfreechart = GraphUtils.create2(graph, jfree.Chart, + l0.HasName, "PieChart" + UUID.randomUUID().toString(), + l0.HasLabel, NameUtils.findFreshLabel(graph, "Pie Chart", model), + l0.PartOf, model, + jfree.Chart_visibleBorder, true, + jfree.Chart_borderWidth, 3); + graph.claimLiteral(jfreechart, jfree.Chart_borderColor, g2d.Color, new float[] {0,0,0,1}); + + // Title + GraphUtils.create2(graph, jfree.TextTitle, + l0.HasName, "TextTitle" + UUID.randomUUID().toString(), + l0.HasLabel, "Pie Chart Title", + jfree.Title_position, jfree.Top, + l0.PartOf, jfreechart); + + // Dataset + Resource dataset = GraphUtils.create2(graph, jfree.PieDataset, + l0.HasName, "CategoryDataset" + UUID.randomUUID().toString(), + jfree.Dataset_seriesList, ListUtils.create(graph, Collections.emptyList()) + ); + + // Plot + GraphUtils.create2(graph, jfree.PiePlot, + l0.HasName, "PiePlot" + UUID.randomUUID().toString(), + l0.PartOf, jfreechart, + l0.ConsistsOf, dataset + ); + } + + }); + } + }; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSharedFunctionLibraryAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSharedFunctionLibraryAction.java new file mode 100644 index 00000000..98efd114 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSharedFunctionLibraryAction.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.newActions; + +import org.simantics.db.Resource; + +/** + * Creates a new shared function library + * @author Teemu Lempinen + * + */ +public class NewSharedFunctionLibraryAction extends NewFunctionLibraryAction { + + + @Override + public Runnable create(Object target) { + if(!(target instanceof Resource)) + return null; + final Resource resource = (Resource)target; + + return new Runnable() { + @Override + public void run() { + createLibrary(resource, true); + } + }; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSheetAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSheetAction.java new file mode 100644 index 00000000..418f0194 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSheetAction.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.newActions; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.sysdyn.ui.utils.SheetUtils; +import org.simantics.ui.SimanticsUI; + +/** + * Creates a new spreadsheet to a book + * @author Teemu Lempinen + * + */ +public class NewSheetAction implements ActionFactory{ + + @Override + public Runnable create(Object target) { + if(!(target instanceof Resource)) + return null; + final Resource book = (Resource)target; + + return new Runnable() { + @Override + public void run() { + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SheetUtils.createSheet(graph, book, null, new String[] {}, new int[] {50}); + } + + }); + } + }; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSimulationPlaybackExperimentAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSimulationPlaybackExperimentAction.java new file mode 100644 index 00000000..b0363b95 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSimulationPlaybackExperimentAction.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.newActions; + +import java.awt.Color; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; + +/** + * Creates a new simulation playback experiment + * @author Teemu Lempinen + * + */ +public class NewSimulationPlaybackExperimentAction extends NewExperimentAction { + + protected void configureExperiment(WriteGraph graph, Resource experiment) throws DatabaseException { + G2DResource g2d = G2DResource.getInstance(graph); + Resource defaultGradient = GraphUtils.create2(graph, g2d.ColorGradient); + graph.claim(experiment, g2d.HasColorGradient, defaultGradient); + + Resource placement = GraphUtils.create2(graph, g2d.ColorPlacement, + g2d.HasGradientPosition, 0.0); + graph.claimLiteral(placement, g2d.HasColor, g2d.Color, new Color(0, 62, 133).getColorComponents(new float[4])); + graph.claim(defaultGradient, g2d.HasColorPlacement, placement); + + placement = GraphUtils.create2(graph, g2d.ColorPlacement, + g2d.HasGradientPosition, 1.0); + graph.claimLiteral(placement, g2d.HasColor, g2d.Color, new Color(255, 230, 0).getColorComponents(new float[4])); + graph.claim(defaultGradient, g2d.HasColorPlacement, placement); + } + + protected Resource getExperimentType(ReadGraph g) { + return SysdynResource.getInstance(g).PlaybackExperiment; + } + + protected String getNameSuggestion() { + return "Playback Experiment"; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/remove/ModuleTypeRemover.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/remove/ModuleTypeRemover.java new file mode 100644 index 00000000..e21bd811 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/remove/ModuleTypeRemover.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.actions.remove; + +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.Remover; +import org.simantics.modeling.ui.modelBrowser.handlers.DeleteNodeHandler; + +/** + * Remover for module type nodes. Not functioning - {@link DeleteNodeHandler} prevents deleting other than entityNodes + * + * @author Teemu Lempinen + * + */ +public class ModuleTypeRemover implements Remover { + + private Resource resource; + + public ModuleTypeRemover(ReadGraph graph, Resource resource) { + this.resource = resource; + } + + @Override + public String canRemove(ReadGraph graph, Map aux) throws DatabaseException { + return null; + } + + @Override + public void remove(WriteGraph graph) throws DatabaseException { + System.out.println("Delete resource " + resource); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleContentChildRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleContentChildRule.java index 3bb27557..df545e7f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleContentChildRule.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleContentChildRule.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.childrules; import java.util.ArrayList; @@ -12,6 +23,11 @@ import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; import org.simantics.structural.stubs.StructuralResource2; +/** + * Child rule for displaying children of module types in Modules folder + * @author Teemu Lempinen + * + */ public class ModuleContentChildRule implements ChildRule { @Override @@ -32,16 +48,19 @@ public class ModuleContentChildRule implements ChildRule { Resource symbol = (Resource)parent; + // Find module component Resource component = graph.getPossibleObject(symbol,ModelingResources.getInstance(graph).SymbolToComponentType); if(component == null) return children; + // Find component configuration Resource configuration = graph.getSingleObject(component, str.IsDefinedBy); if(configuration == null) return children; + // Add all components children.addAll(graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, str.Component))); return children; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleTypeChildRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleTypeChildRule.java index 7afcb1b9..111d12c3 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleTypeChildRule.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleTypeChildRule.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.childrules; import java.util.ArrayList; @@ -13,7 +24,11 @@ import org.simantics.modeling.ModelingResources; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; - +/** + * Child rule for finding module types defined in a model + * @author Teemu Lempinen + * + */ public class ModuleTypeChildRule implements ChildRule { @Override @@ -38,6 +53,7 @@ public class ModuleTypeChildRule implements ChildRule { if(!graph.isInstanceOf(model, SysdynResource.getInstance(graph).SysdynModel)) return children; + // Find all component types that are inherited from SYSDYN.Module for(Resource r : graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, st.ComponentType))) { if(graph.isInheritedFrom(r, SysdynResource.getInstance(graph).Module)) { Resource symbol = graph.getPossibleObject(r,ModelingResources.getInstance(graph).ComponentTypeToSymbol); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/VariableChildRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/VariableChildRule.java new file mode 100644 index 00000000..aaecd2d0 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/VariableChildRule.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.childrules; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.model.children.ChildRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.sysdyn.SysdynResource; + +/** + * Child rule for building model configuration out of Variable nodes + * @author Teemu Lempinen + * + */ +public class VariableChildRule implements ChildRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Variable.class) || contentType.equals(Resource.class); + } + + @Override + public Collection getChildren(ReadGraph graph, Object parent) throws DatabaseException { + + ArrayList result = new ArrayList(); + + if (parent == null) { + return result; + } + + Variable variable = null; + + if(parent instanceof Variable) { + variable = (Variable) parent; + } else if(parent instanceof Resource) { + variable = Variables.getVariable(graph, (Resource)parent); + } + + if(variable == null) + return result; + + SysdynResource sr = SysdynResource.getInstance(graph); + + ArrayList variables = new ArrayList(); + + for(Variable child : variable.browseChildren(graph)) { + Resource represents = (Resource)child.getPropertyValue(graph, Variables.REPRESENTS); + if(graph.isInstanceOf(represents, sr.IndependentVariable)) { + variables.add(child); + } else if (graph.isInstanceOf(represents, sr.Input)) { + variables.add(child); + } else if (graph.isInstanceOf(represents, sr.Module)) { + variables.add(child); + } else if (graph.isInstanceOf(represents, sr.Enumeration)) { + variables.add(child); + } + } + + for (Variable v : variables) { + result.add(v); + } + + return result; + } + + @Override + public Collection getParents(ReadGraph graph, Object child) throws DatabaseException { + return null; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/imagerules/ChartImageRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/imagerules/ChartImageRule.java new file mode 100644 index 00000000..044d9bc0 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/imagerules/ChartImageRule.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.imagerules; + +import java.util.Collections; +import java.util.Map; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.model.images.ImageRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.Activator; + +public class ChartImageRule implements ImageRule { + + @Override + public boolean isCompatible(Class contentType) { + return Resource.class.equals(contentType); + } + + @Override + public Map getImage(ReadGraph graph, Object content) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + String image = "icons/chart_line.png"; + + Resource chart = (Resource) content; + + Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.Plot)); + if(plot != null) { + if(graph.isInstanceOf(plot, jfree.CategoryPlot)) { + image = "icons/chart_bar.png"; + } else if(graph.isInstanceOf(plot, jfree.PiePlot)) { + image = "icons/chart_pie.png"; + } + } + + return Collections.singletonMap(ColumnKeys.SINGLE, + ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource(image)) + ); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/imagerules/ResultImageRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/imagerules/ResultImageRule.java new file mode 100644 index 00000000..ed7024ed --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/imagerules/ResultImageRule.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.imagerules; + +import java.util.Collections; +import java.util.Map; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.model.images.ImageRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; + +public class ResultImageRule implements ImageRule { + + @Override + public boolean isCompatible(Class contentType) { + return Resource.class.equals(contentType); + } + + @Override + public Map getImage(ReadGraph graph, Object content) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource data = (Resource) content; + + String image = "icons/chart_bar_blackAndWhite.png"; + if(graph.hasStatement(data, sr.Result_showResult)) + image ="icons/chart_bar.png"; + + return Collections.singletonMap(ColumnKeys.SINGLE, + ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource(image)) + ); + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/imagerules/VariableImageRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/imagerules/VariableImageRule.java new file mode 100644 index 00000000..c35a895d --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/imagerules/VariableImageRule.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.imagerules; + +import java.util.Collections; +import java.util.Map; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.model.images.ImageRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.ui.utils.AdaptionUtils; + +public class VariableImageRule implements ImageRule { + + @Override + public boolean isCompatible(Class contentType) { + return Variable.class.equals(contentType); + } + + @Override + public Map getImage(ReadGraph graph, Object content) throws DatabaseException { + Variable var = AdaptionUtils.adaptToSingle(content, Variable.class); + + String image = "icons/brick.png"; + + Resource r = (Resource)var.getPropertyValue(graph, Variables.REPRESENTS); + if(r != null) { + Layer0 L0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + Resource type = graph.getSingleObject(r, L0.InstanceOf); + if(graph.isInheritedFrom(type, sr.Module)) { + image = "icons/bricks.png"; + } + } + + return Collections.singletonMap(ColumnKeys.SINGLE, + ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource(image)) + ); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/labelrules/VariableNameLabelRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/labelrules/VariableNameLabelRule.java new file mode 100644 index 00000000..03def7f0 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/labelrules/VariableNameLabelRule.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.labelrules; + +import java.util.Collections; +import java.util.Map; + +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.model.labels.LabelRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.ui.utils.AdaptionUtils; + +public class VariableNameLabelRule implements LabelRule { + public static final ModuleTypeLabelRule INSTANCE = new ModuleTypeLabelRule(); + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Variable.class); + } + + @Override + public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { + Variable var = AdaptionUtils.adaptToSingle(content, Variable.class); + return Collections.singletonMap(ColumnKeys.SINGLE, + var != null ? var.getName(graph) : "No variable" + ); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodeTypes/ModuleSymbolNodeType.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodeTypes/ModuleSymbolNodeType.java new file mode 100644 index 00000000..3ab81f1e --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodeTypes/ModuleSymbolNodeType.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2007, 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.browser.nodeTypes; + +import java.util.Collection; +import java.util.Collections; +import java.util.WeakHashMap; + +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.common.NodeContextBuilder; +import org.simantics.browsing.ui.model.nodetypes.NodeType; +import org.simantics.browsing.ui.model.nodetypes.SpecialNodeType; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; + +/** + * Experimental node type for Module symbols. Copied mostly from {@link SpecialNodeType}. + * Not necessary needed. + * + * @author Teemu Lempinen + * + */ +public class ModuleSymbolNodeType implements NodeType { + + private Resource resource; + private Class contentType; + + private static final WeakHashMap nodeTypeCache = + new WeakHashMap(); + + public ModuleSymbolNodeType(Resource resource) { + this.resource = resource; + this.contentType = Resource.class; + } + + public static ModuleSymbolNodeType create(Resource entityType) { + synchronized(nodeTypeCache) { + ModuleSymbolNodeType result = nodeTypeCache.get(entityType); + if(result == null) { + result = new ModuleSymbolNodeType(entityType); + nodeTypeCache.put(entityType, result); + } + return result; + } + } + + @Override + public NodeContext createNodeContext(ReadGraph graph, Object content) + throws DatabaseException { + if(contentType.isInstance(content)) + return NodeContextBuilder.buildWithData(KEY_SEQUENCE, + new Object[] {content, this} + ); + else + return null; + } + + @Override + public Class getContentType() { + return contentType; + } + + @Override + public int hashCode() { + return resource.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ModuleSymbolNodeType other = (ModuleSymbolNodeType) obj; + return resource.equals(other.resource); + } + + @Override + public boolean inherits(ReadGraph graph, NodeType superType) { + // Special node type does not support inheritance + return equals(superType); + } + + @Override + public Collection getSuper(ReadGraph g) { + return Collections.emptyList(); + } + + @Override + public String toString(ReadGraph graph) throws DatabaseException { + return "(" + NameUtils.getSafeName(graph, resource) + ")"; + } + + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java index 261d04db..ca386d6b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Copyright (c) 2007, 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 @@ -27,7 +27,7 @@ import org.simantics.ui.workbench.IResourceEditorInput2; * If the viewer shows an instantiated module, the service provides a name of type: "instanceName : instanceOf". * Otherwise works as standard EditorNamingService2. * - * @author TLTEEMU + * @author Teemu Lempinen * */ public class SysdynEditorNamingService extends EditorNamingService2 { @@ -37,8 +37,9 @@ public class SysdynEditorNamingService extends EditorNamingService2 { if(in instanceof IResourceEditorInput2) { IResourceEditorInput2 input = (IResourceEditorInput2) in; + Resource model = g.getPossibleResource(input.getModelURI()); + if(!input.getRVI().isEmpty()) { - Resource model = g.getPossibleResource(input.getModelURI()); if(model != null) { Resource configuration = g.getPossibleObject(model, SimulationResource.getInstance(g).HasConfiguration); String configurationName = NameUtils.getSafeName(g, configuration); @@ -54,6 +55,8 @@ public class SysdynEditorNamingService extends EditorNamingService2 { } } + } else { + return NameUtils.getSafeLabel(g, model); } } return super.getName(g, editorId, in); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java index d871355a..b3bc6d9f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in + * Copyright (c) 2010, 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 @@ -99,7 +99,7 @@ public class SysdynProject extends AbstractProjectFeature { } } - + ModelManager mm; @@ -193,8 +193,8 @@ public class SysdynProject extends AbstractProjectFeature { ErrorLogger.defaultLogError(e); } } - - + + // Issues try { session.syncRequest(new ReadRequest() { @@ -233,8 +233,10 @@ public class SysdynProject extends AbstractProjectFeature { for(Resource experiment : graph.getObjects(model, l0.ConsistsOf)) { if(graph.isInstanceOf(experiment, SIMU.Experiment)) { for(Resource result : graph.getObjects(experiment, sr.Experiment_result)) { - String resultFile = (String)graph.getPossibleRelatedValue(result, sr.Result_resultFile); - if(result != null) resultPaths.put(resultFile, result); + if(!graph.isInstanceOf(result, sr.HistoryDataset)) { + String resultFile = (String)graph.getPossibleRelatedValue(result, sr.Result_resultFile); + if(result != null) resultPaths.put(resultFile, result); + } } } } @@ -279,9 +281,9 @@ public class SysdynProject extends AbstractProjectFeature { } } } - + public void onActivated(final ReadGraph graph, final IProject project) throws DatabaseException { - + GraphChangeListenerSupport changeSupport = graph.getService(GraphChangeListenerSupport.class); changeSupport.addMetadataListener(new GenericChangeListener() { @@ -294,9 +296,9 @@ public class SysdynProject extends AbstractProjectFeature { } }); - + IssueUtils.listenActiveProjectIssueSources(graph, project.get()); - + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java index aa8bc2a1..dab187f9 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -17,6 +17,9 @@ import java.util.Collections; import java.util.List; import org.eclipse.jface.viewers.ISelection; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.model.nodetypes.NodeType; +import org.simantics.browsing.ui.model.nodetypes.SpecialNodeType; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.ObjectsWithType; @@ -24,6 +27,8 @@ import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; import org.simantics.db.exception.ServiceException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; @@ -51,6 +56,8 @@ import org.simantics.ui.utils.AdaptionUtils; */ public class ResourceSelectionProcessor implements SelectionProcessor { + private SpecialNodeType sharedFunctionsTestNode; + @Override public Collection process(Object selection, ReadGraph backend) { Collection tabs = new ArrayList(); @@ -60,6 +67,10 @@ public class ResourceSelectionProcessor implements SelectionProcessor && ((ArrayList) selection).size() > 1) { @@ -84,9 +95,13 @@ public class ResourceSelectionProcessor implements SelectionProcessor result = new ArrayList(); + boolean isStock = isStock(graph, component); StandardIssue noSuchVariableIssue = null; // Check that all references have corresponding arrows if (references != null && dependencies != null) { @@ -126,7 +127,12 @@ public class DependencyFunction { if (!dependencies.contains(reference)) { Resource variable = null; if ((variable = ValidationUtils.reach(graph, component, reference)) != null) { - result.add(new StandardIssue(sr.Validations_MissingLinkIssue, component, variable)); + if(isStock) { + /* Stocks do not get incoming dependencies. They are allowed + to have references without arrows */ + } else { + result.add(new StandardIssue(sr.Validations_MissingLinkIssue, component, variable)); + } } else { if (noSuchVariableIssue == null) { noSuchVariableIssue = new StandardIssue(sr.Validations_NoSuchVariableIssue, component); @@ -140,6 +146,19 @@ public class DependencyFunction { return result; } + + private static boolean isStock(ReadGraph graph, Resource variable) throws DatabaseException { + List expressionList = ValidationUtils.getExpressions(graph, variable); + if(expressionList == null || expressionList.isEmpty()) { + return false; + } else { + for(Resource expression : expressionList) { + if(!graph.isInstanceOf(expression, SysdynResource.getInstance(graph).StockExpression)) + return false; + } + return true; + } + } /** * Missing link description diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java index 3826bbc9..e6fa77b6 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Copyright (c) 2007, 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 @@ -92,7 +92,7 @@ public class ValidationUtils { * @return List of expression (resources) * @throws DatabaseException */ - private static List getExpressions(ReadGraph graph, Resource r) throws DatabaseException { + public static List getExpressions(ReadGraph graph, Resource r) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); Resource hasExpressions = graph.getPossibleObject(r, sr.Variable_expressions); if(hasExpressions != null) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/HistoryDatasetResult.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/HistoryDatasetResult.java index 21ed8b0b..9b0d515c 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/HistoryDatasetResult.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/HistoryDatasetResult.java @@ -239,7 +239,8 @@ public class HistoryDatasetResult extends SimulationResult { // Update result set and send message to model that results have been changed HistoryDatasetResult.this.variables = result.second; sysdynResult.setResult(HistoryDatasetResult.this); - result.first.resultChanged(); + if(result.first != null) + result.first.resultChanged(); } @Override diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IndependentVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IndependentVariable.java index 4ae415bf..0b95bf6b 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IndependentVariable.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IndependentVariable.java @@ -31,7 +31,7 @@ public abstract class IndependentVariable extends Variable { */ public String getDeclaration() { Variability variability = Variability.getVariability(this); - + // [variability] type name[range] StringBuilder sb = new StringBuilder(); sb.append(" "); @@ -51,11 +51,13 @@ public abstract class IndependentVariable extends Variable { sb.append(";\n"); // Possible additions to expressions. e.g. helper classes and variables - String addition; - for(IExpression e : getExpressions().getExpressions()) { - addition = e.getDeclarationAddition(this); - if(addition != null) - sb.append(addition); + if(getExpressions() != null) { + String addition; + for(IExpression e : getExpressions().getExpressions()) { + addition = e.getDeclarationAddition(this); + if(addition != null) + sb.append(addition); + } } return sb.toString(); @@ -125,6 +127,9 @@ public abstract class IndependentVariable extends Variable { * @return equations or null */ protected String getVariableEquation() { + if(this.expressions == null) + return null; + ArrayList expressions = this.expressions.getExpressions(); ArrayIndexes ai = this.getArrayIndexes(); ArrayList enumerations = null; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java index e027774a..dc4f483f 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java @@ -139,6 +139,9 @@ public enum Variability { * @return Variabilty of a variable */ static public Variability getVariability(IndependentVariable variable, boolean allowVariableReferences, Configuration configuration) { + if(variable == null || variable.getExpressions() == null) + return Variability.CONTINUOUS; + ArrayList expressions = variable.getExpressions().getExpressions(); if(expressions.size() != 1)