From: Tuukka Lehtonen Date: Tue, 10 Dec 2019 09:37:36 +0000 (+0200) Subject: Added new user component SCL script simulation stage: post-preparation X-Git-Tag: v1.43.0~136^2~21 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=7da27cffbf636345be6a8227c1122389b2512314;p=simantics%2Fplatform.git Added new user component SCL script simulation stage: post-preparation Post-preparation scripts are executed after the possible native solver preparations have been executed. The old preparation scripts are executed before native solver preparation as before. gitlab #430 Change-Id: I0d8e0d0710cbe35407b2453f9e49ead085d486cf --- diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeScriptEditor.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeScriptEditor.java index 208c9f76f..026cd9c9f 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeScriptEditor.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeScriptEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2015 Association for Decentralized Information Management in + * Copyright (c) 2013, 2019 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 @@ -18,12 +18,8 @@ import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; import org.simantics.Simantics; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; @@ -33,7 +29,6 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ParametrizedRead; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.UniqueRead; -import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.request.combinations.Combinators; import org.simantics.db.request.Read; @@ -57,7 +52,6 @@ public class ComponentTypeScriptEditor extends SCLModuleEditor { @Override protected void preInitialize() { setDocumentProvider(new ComponentTypeScriptDocumentProvider(this)); - Display display = PlatformUI.getWorkbench().getDisplay(); SCLSourceViewerConfigurationNew sourceViewerConfiguration = new SCLSourceViewerConfigurationNew(resourceManager); setSourceViewerConfiguration(sourceViewerConfiguration); @@ -107,7 +101,8 @@ public class ComponentTypeScriptEditor extends SCLModuleEditor { "post-step", //$NON-NLS-1$ "analogAutomation", //$NON-NLS-1$ "binaryAutomation", //$NON-NLS-1$ - "preparation" //$NON-NLS-1$ + "preparation", //$NON-NLS-1$ + "post-preparation" //$NON-NLS-1$ }; private static final String[] EXECUTION_PHASE_LABELS = new String[] { @@ -116,7 +111,8 @@ public class ComponentTypeScriptEditor extends SCLModuleEditor { Messages.ComponentTypeScriptEditor_ExecuteAfterEachStep, Messages.ComponentTypeScriptEditor_ExecuteAnalogAutomation, Messages.ComponentTypeScriptEditor_ExecuteBinaryAutomation, - Messages.ComponentTypeScriptEditor_ExecuteDuringPreparation + Messages.ComponentTypeScriptEditor_ExecuteBeforePreparation, + Messages.ComponentTypeScriptEditor_ExecuteAfterPreparation }; @Override @@ -135,36 +131,26 @@ public class ComponentTypeScriptEditor extends SCLModuleEditor { StructuralResource2 STR = StructuralResource2.getInstance(graph); final String type = graph.getPossibleRelatedValue(script, STR.ComponentTypeScript_type); if(type != null) - combo.getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - for(int i=0;i { + for(int i=0;i { + int id = combo.getSelectionIndex(); + Simantics.getSession().asyncRequest((WriteGraph graph) -> { + StructuralResource2 STR = StructuralResource2.getInstance(graph); + String currentType = graph.getPossibleRelatedValue(script, STR.ComponentTypeScript_type); + String newType = EXECUTION_PHASES[id]; + if(!newType.equals(currentType)) + graph.claimLiteral(script, STR.ComponentTypeScript_type, newType, Bindings.STRING); + }); + })); GridDataFactory.fillDefaults().grab(true, false).applyTo(combo); Composite editorComposite = new Composite(parent, SWT.NONE); diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/Messages.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/Messages.java index 7890358fd..78ebf9c11 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/Messages.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/Messages.java @@ -10,7 +10,8 @@ public class Messages extends NLS { public static String ComponentTypeScriptEditor_ExecuteAtEachStep; public static String ComponentTypeScriptEditor_ExecuteBeforeEachStep; public static String ComponentTypeScriptEditor_ExecuteBinaryAutomation; - public static String ComponentTypeScriptEditor_ExecuteDuringPreparation; + public static String ComponentTypeScriptEditor_ExecuteBeforePreparation; + public static String ComponentTypeScriptEditor_ExecuteAfterPreparation; public static String ComponentTypeViewer_OpenedInReadOnly; public static String ComponentTypeViewerData_ContainsInvalidCharacters; public static String ComponentTypeViewerData_CtrlEnterApplyChanges; diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/messages.properties b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/messages.properties index 406ebfed6..fa819c9b0 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/messages.properties +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/messages.properties @@ -4,7 +4,8 @@ ComponentTypeScriptEditor_ExecuteAfterEachStep=Execute after each step ComponentTypeScriptEditor_ExecuteAtEachStep=Execute at each step ComponentTypeScriptEditor_ExecuteBeforeEachStep=Execute before each step ComponentTypeScriptEditor_ExecuteBinaryAutomation=Execute together with binary automation -ComponentTypeScriptEditor_ExecuteDuringPreparation=Execute during preparation +ComponentTypeScriptEditor_ExecuteBeforePreparation=Execute before solver preparation +ComponentTypeScriptEditor_ExecuteAfterPreparation=Execute after solver preparation ComponentTypeViewer_OpenedInReadOnly=(Opened in read-only mode) ComponentTypeViewerData_ContainsInvalidCharacters=Property name ''{0}'' contains invalid characters, does not match pattern {1}. ComponentTypeViewerData_CtrlEnterApplyChanges=Ctrl+Enter to apply changes, ESC to cancel.