import java.util.Stack;
import org.simantics.db.ReadGraph;
-import org.simantics.db.Session;
+import org.simantics.db.RequestProcessor;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.request.ReadRequest;
import org.simantics.db.common.request.WriteRequest;
private static final boolean DEBUG = false;
- protected Session session;
+ protected RequestProcessor session;
protected IMapping<DBObject,INode> mapping;
protected ParentNode<E> rootNode;
private boolean dirty = false;
- public ScriptNodeMap(Session session, IMapping<DBObject,INode> mapping, ParentNode<E> rootNode) {
+ public ScriptNodeMap(RequestProcessor session, IMapping<DBObject,INode> mapping, ParentNode<E> rootNode) {
this.session = session;
this.mapping = mapping;
this.rootNode = rootNode;
org.simantics.plant3d.scl,
org.simantics.plant3d.utils
Automatic-Module-Name: org.simantics.plant3d
+Import-Package: org.slf4j
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.simantics.Simantics;
+import org.simantics.db.Session;
import org.simantics.db.exception.DatabaseException;
import org.simantics.plant3d.Activator;
import org.simantics.plant3d.ontology.Plant3D;
}
protected List<Item> getItems(Class<?> c, String libUri) throws DatabaseException {
+ Session session = Simantics.getSession();
if (InlineComponent.class.equals(c)) {
- return P3DUtil.getInlines(libUri);
+ return P3DUtil.getInlines(session, libUri);
} else if (TurnComponent.class.equals(c)) {
- return P3DUtil.getTurns(libUri);
+ return P3DUtil.getTurns(session, libUri);
} else if (EndComponent.class.equals(c)) {
- return P3DUtil.getEnds(libUri);
+ return P3DUtil.getEnds(session, libUri);
} else {
return null;
}
package org.simantics.plant3d.dialog;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.resource.ResourceManager;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.swt.widgets.ExpandItem;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
+import org.simantics.Simantics;
+import org.simantics.db.Session;
import org.simantics.db.exception.DatabaseException;
import org.simantics.plant3d.ontology.Plant3D;
import org.simantics.plant3d.scenegraph.Equipment;
-import org.simantics.plant3d.scenegraph.InlineComponent;
import org.simantics.plant3d.scenegraph.Nozzle;
import org.simantics.plant3d.scenegraph.P3DRootNode;
-import org.simantics.plant3d.scenegraph.PipelineComponent;
-import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.PositionType;
import org.simantics.plant3d.utils.Item;
import org.simantics.plant3d.utils.P3DUtil;
import org.simantics.utils.ui.ExceptionUtils;
public class EquipmentSelectionDialog extends Dialog implements ISelectionChangedListener{
- private ResourceManager resourceManager;
private String libUri;
- private P3DRootNode root;
private Item selected;
private Item selectedNozzle;
public EquipmentSelectionDialog(Shell parentShell, P3DRootNode root, String libUri){
super(parentShell);
- this.root = root;
this.libUri = libUri;
}
- protected List<Item> getItems(Class c, String libUri) throws DatabaseException{
+ protected List<Item> getItems(Class<?> c, String libUri) throws DatabaseException{
+ Session session = Simantics.getSession();
if (Equipment.class.equals(c)) {
- return P3DUtil.getEquipments(libUri);
+ return P3DUtil.getEquipments(session, libUri);
} else if (Nozzle.class.equals(c)) {
- return P3DUtil.getNozzles(libUri);
+ return P3DUtil.getNozzles(session, libUri);
}
return null;
}
@Override
protected Control createDialogArea(Composite parent) {
- resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);
-
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2,false);
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.Session;
panel.setPickType(4);
try {
- ControlPointFactory.preloadCache(getLibraryUri());
- ComponentUtils.preloadCache();
+ ControlPointFactory.preloadCache(Simantics.getSession(), getLibraryUri());
+ ComponentUtils.preloadCache(Simantics.getSession());
} catch (Exception e) {
ExceptionUtils.logAndShowError("Cannot open Plant3D editor",e);
return;
if (node instanceof Equipment) {
m.add(translateAction);
m.add(rotateAction);
- for (Item eq : P3DUtil.getNozzles(getLibraryUri())) {
+ for (Item eq : P3DUtil.getNozzles(Simantics.getSession(), getLibraryUri())) {
AddNozzleAction add = new AddNozzleAction(rootNode, eq);
add.setEquipment((Equipment)node);
m.add(add);
import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
import org.simantics.db.Resource;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.request.Read;
private static Map<String,Instruction> cache = new HashMap<String, Instruction>();
- public static void preloadCache(String libUri) throws Exception {
- List<Item> items = P3DUtil.getEnds(libUri);
- items.addAll(P3DUtil.getInlines(libUri));
- items.addAll(P3DUtil.getNozzles(libUri));
- items.addAll(P3DUtil.getTurns(libUri));
+ public static void preloadCache(RequestProcessor session, String libUri) throws Exception {
+ List<Item> items = P3DUtil.getEnds(session, libUri);
+ items.addAll(P3DUtil.getInlines(session, libUri));
+ items.addAll(P3DUtil.getNozzles(session, libUri));
+ items.addAll(P3DUtil.getTurns(session, libUri));
for (Item item : items) {
- Instruction inst = createInstruction(item.getUri());
+ Instruction inst = createInstruction(session, item.getUri());
cache.put(item.getUri(), inst);
}
}
public static PipeControlPoint create(PipelineComponent component) throws Exception {
Instruction inst = cache.get(component.getType());
if (inst == null) {
- inst = createInstruction(component.getType());
+ inst = createInstruction(Simantics.getSession(), component.getType());
cache.put(component.getType(), inst);
}
if (inst == null) {
}
- private static Instruction createInstruction(final String type) throws Exception {
- return Simantics.getSession().syncRequest(new Read<Instruction>() {
+ private static Instruction createInstruction(RequestProcessor session, final String type) throws Exception {
+ return session.syncRequest(new Read<Instruction>() {
@Override
public Instruction perform(ReadGraph graph) throws DatabaseException {
Resource res = graph.getResource(type);
import java.util.Set;
import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
import org.simantics.db.Resource;
-import org.simantics.db.Session;
import org.simantics.db.exception.DatabaseException;
import org.simantics.g3d.ontology.G3D;
import org.simantics.g3d.scenegraph.base.INode;
private static final boolean DEBUG = false;
- public P3DScriptNodeMap(Session session, IMapping mapping, P3DRootNode rootNode) {
+ public P3DScriptNodeMap(RequestProcessor session, IMapping mapping, P3DRootNode rootNode) {
super(session,mapping,rootNode);
rootNode.setMapping(mapping);
}
import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
import org.simantics.db.Resource;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.request.Read;
import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
import org.simantics.plant3d.utils.ComponentUtils;
import org.simantics.plant3d.utils.P3DUtil;
+import org.simantics.scl.runtime.SCLContext;
public class SCLUtil {
}
public static P3DScriptNodeMap load(final Resource root) throws DatabaseException {
- preload(Plant3D.URIs.Builtin);
+ return load(getRequestProcessor(), root);
+ }
+
+ public static P3DScriptNodeMap load(RequestProcessor session, final Resource root) throws DatabaseException {
+ preload(Simantics.getSession(), Plant3D.URIs.Builtin);
SchemaProvider schemaProvider = g -> SchemaBuilder.getSchema(g);
NodeMapProvider mapProvider = (mapping, rootNode) -> new P3DScriptNodeMap(Simantics.getSession(), mapping, rootNode);
- return load(root, schemaProvider, mapProvider);
+ return load(session, root, schemaProvider, mapProvider);
}
public static P3DRootNode loadReadOnly(final Resource root) throws DatabaseException {
- preload(Plant3D.URIs.Builtin);
+ return loadReadOnly(getRequestProcessor(), root);
+ }
+
+ public static P3DRootNode loadReadOnly(RequestProcessor session, final Resource root) throws DatabaseException {
+ preload(session, Plant3D.URIs.Builtin);
SchemaProvider schemaProvider = g -> SchemaBuilder.getSchema(g);
- return loadReadOnly(root, schemaProvider);
+ return loadReadOnly(session, root, schemaProvider);
}
- public static void preload(String symbolSet) throws DatabaseException {
+ public static void preload(RequestProcessor session, String symbolSet) throws DatabaseException {
try {
- ControlPointFactory.preloadCache(symbolSet);
- ComponentUtils.preloadCache();
+ ControlPointFactory.preloadCache(session, symbolSet);
+ ComponentUtils.preloadCache(session);
} catch (Exception e) {
throw new DatabaseException(e);
}
}
public static <NodeMap extends P3DScriptNodeMap> NodeMap load(final Resource root, SchemaProvider schemaProvider, NodeMapProvider mapProvider) throws DatabaseException {
- return Simantics.getSession().syncRequest(new Read<NodeMap>() {
+ return load(getRequestProcessor(), root, schemaProvider, mapProvider);
+ }
+
+ public static <NodeMap extends P3DScriptNodeMap> NodeMap load(RequestProcessor session, final Resource root, SchemaProvider schemaProvider, NodeMapProvider mapProvider) throws DatabaseException {
+ return session.syncRequest(new Read<NodeMap>() {
@Override
public NodeMap perform(ReadGraph graph) throws DatabaseException {
PipingRules.setEnabled(false);
});
}
- public static <Root extends P3DRootNode> Root loadReadOnly(final Resource root, SchemaProvider schemaProvider)
+ public static <Root extends P3DRootNode> Root loadReadOnly(RequestProcessor session, final Resource root, SchemaProvider schemaProvider)
throws DatabaseException {
- return Simantics.getSession().syncRequest(new Read<Root>() {
+ return session.syncRequest(new Read<Root>() {
@Override
public Root perform(ReadGraph graph) throws DatabaseException {
PipingRules.setEnabled(false);
});
}
+ /**
+ * Load a read-only Java object representation of a Plant3d model.
+ *
+ * This method can be called from SCL either as a <Proc> or a <ReadGraph> function.
+ */
+ public static <Root extends P3DRootNode> Root loadReadOnly(final Resource root, SchemaProvider schemaProvider)
+ throws DatabaseException {
+ return loadReadOnly(getRequestProcessor(), root, schemaProvider);
+ }
+
+ public static RequestProcessor getRequestProcessor() {
+ RequestProcessor rp = (RequestProcessor) SCLContext.getCurrent().get("graph");
+ return rp != null ? rp : Simantics.getSession();
+ }
+
}
import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
import org.simantics.db.Resource;
import org.simantics.db.common.request.ReadRequest;
import org.simantics.db.common.utils.NameUtils;
import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.Direction;
import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.PositionType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
public class ComponentUtils {
+ private final static Logger LOGGER = LoggerFactory.getLogger(ComponentUtils.class);
private static Map<String,Class<? extends PipelineComponent>> clazzes = new HashMap<String, Class<? extends PipelineComponent>>();
private static Map<String,GeometryProvider> providers = new HashMap<String,GeometryProvider>();
private static Map<String,String> names = new HashMap<String,String>();
- public static void preloadCache() {
- Simantics.getSession().asyncRequest(new ReadRequest() {
-
- @Override
- public void run(ReadGraph graph) throws DatabaseException {
- List<String> types = new ArrayList<String>();
- types.add(Plant3D.URIs.Builtin_Straight);
- types.add(Plant3D.URIs.Builtin_Elbow);
- types.add(Plant3D.URIs.Builtin_ConcentricReducer);
- types.add(Plant3D.URIs.Builtin_BranchSplitComponent);
- types.add(Plant3D.URIs.Builtin_EccentricReducer);
- types.add(Plant3D.URIs.Builtin_Elbow45);
- types.add(Plant3D.URIs.Builtin_Elbow90);
+ public static void preloadCache(RequestProcessor session) {
+ try {
+ session.syncRequest(new ReadRequest() {
- for (String typeURI : types) {
- load(graph, typeURI);
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ List<String> types = new ArrayList<String>();
+ types.add(Plant3D.URIs.Builtin_Straight);
+ types.add(Plant3D.URIs.Builtin_Elbow);
+ types.add(Plant3D.URIs.Builtin_ConcentricReducer);
+ types.add(Plant3D.URIs.Builtin_BranchSplitComponent);
+ types.add(Plant3D.URIs.Builtin_EccentricReducer);
+ types.add(Plant3D.URIs.Builtin_Elbow45);
+ types.add(Plant3D.URIs.Builtin_Elbow90);
+
+ for (String typeURI : types) {
+ load(graph, typeURI);
+ }
}
- }
- });
+ });
+ } catch (DatabaseException e) {
+ LOGGER.error("ComponentUtils.preloadCache() failed unexpectedly", e);
+ }
}
private static GeometryProvider getProvider(ReadGraph graph, Resource type) throws DatabaseException {
import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
import org.simantics.db.exception.DatabaseException;
public class P3DUtil {
- public static List<Item> getEquipments() throws DatabaseException {
- return getEquipments(Plant3D.URIs.Builtin);
+ public static List<Item> getEquipments(RequestProcessor session) throws DatabaseException {
+ return getEquipments(session, Plant3D.URIs.Builtin);
}
- public static List<Item> getEquipments(final String libUri) throws DatabaseException {
- return Simantics.getSession().syncRequest(new Read<List<Item>>() {
+ public static List<Item> getEquipments(RequestProcessor session, final String libUri) throws DatabaseException {
+ return session.syncRequest(new Read<List<Item>>() {
@Override
public List<Item> perform(ReadGraph graph) throws DatabaseException {
Plant3D p3d = Plant3D.getInstance(graph);
});
}
- public static List<Item> getNozzles(String libUri) throws DatabaseException {
- return Simantics.getSession().syncRequest(new Read<List<Item>>() {
+ public static List<Item> getNozzles(RequestProcessor session, String libUri) throws DatabaseException {
+ return session.syncRequest(new Read<List<Item>>() {
@Override
public List<Item> perform(ReadGraph graph) throws DatabaseException {
Plant3D p3d = Plant3D.getInstance(graph);
return type.hashCode() + libUri.hashCode();
}
}
-
- public static List<Item> getEnds(String libUri) throws DatabaseException {
- return Simantics.getSession().syncRequest(new Read<List<Item>>() {
+
+ public static List<Item> getEnds(RequestProcessor session, String libUri) throws DatabaseException {
+ return session.syncRequest(new Read<List<Item>>() {
@Override
public List<Item> perform(ReadGraph graph) throws DatabaseException {
Plant3D p3d = Plant3D.getInstance(graph);
});
}
- public static List<Item> getTurns(String libUri) throws DatabaseException {
- return Simantics.getSession().syncRequest(new Read<List<Item>>() {
+ public static List<Item> getTurns(RequestProcessor session, String libUri) throws DatabaseException {
+ return session.syncRequest(new Read<List<Item>>() {
@Override
public List<Item> perform(ReadGraph graph) throws DatabaseException {
Plant3D p3d = Plant3D.getInstance(graph);
});
}
- public static List<Item> getInlines(String libUri) throws DatabaseException {
- return Simantics.getSession().syncRequest(new Read<List<Item>>() {
+ public static List<Item> getInlines(RequestProcessor session, String libUri) throws DatabaseException {
+ return session.syncRequest(new Read<List<Item>>() {
@Override
public List<Item> perform(ReadGraph graph) throws DatabaseException {
Plant3D p3d = Plant3D.getInstance(graph);