package org.simantics.sysdyn.ui.handlers.exports;\r
\r
import java.io.File;\r
+import java.util.HashMap;\r
\r
import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.simantics.db.common.primitiverequest.PossibleRelatedValue;\r
import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;\r
import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;\r
import org.simantics.db.layer0.util.TransferableGraphConfiguration2;\r
import org.simantics.db.request.Read;\r
\r
@Override\r
public void run(ReadGraph graph) throws DatabaseException {\r
+ HashMap<Resource, ExtentStatus> map = new HashMap<Resource, ExtentStatus>();\r
+ \r
+ Resource relation = graph.getPossibleResource("http://www.simantics.org/Documentation-1.1/createdBy");\r
+ if(relation != null) {\r
+ Resource createdBy = graph.getPossibleObject(model, relation);\r
+ if(createdBy != null)\r
+ map.put(createdBy, ExtentStatus.EXCLUDED);\r
+ }\r
+ \r
TransferableGraphConfiguration2 conf = new TransferableGraphConfiguration2(graph, model);\r
+ conf.preStatus.putAll(map);\r
+ \r
TransferableGraphSource s = graph.syncRequest(new ModelTransferableGraphSourceRequest(conf));\r
try {\r
TransferableGraphs.writeTransferableGraph(graph, "sysdynModel", 1, s,new File(selected));\r
@JavaName getRoleVariables\r
getRoleVariables :: Variable -> <ReadGraph> [Variable] \r
\r
+ @JavaName getDocumentVariables\r
+ getDocumentVariables :: Variable -> <ReadGraph> [Variable] \r
+\r
+ @JavaName getIndexDocuments\r
+ getIndexDocuments :: Variable -> <ReadGraph> [Variable] \r
+ \r
+ @JavaName getResultVariables\r
+ getResultVariables :: Variable -> <ReadGraph> [Variable] \r
+ \r
@JavaName getConfiguration\r
getConfiguration :: Resource -> <ReadGraph> Resource\r
\r
\r
@JavaName numberOfModuleTypes\r
numberOfModuleTypes :: Variable -> <ReadGraph> Integer\r
+ \r
+ @JavaName base64Encode\r
+ base64Encode :: Variable -> String -> <ReadGraph> String \r
+ \r
+ @JavaName formatDate\r
+ formatDate :: Long -> <ReadGraph> String \r
+ \r
\r
\ No newline at end of file
package org.simantics.sysdyn.utils;\r
\r
+import java.text.DateFormat;\r
import java.util.ArrayList;\r
import java.util.Collections;\r
import java.util.Comparator;\r
+import java.util.Date;\r
import java.util.List;\r
\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.util.Base64;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.request.ObjectsWithSupertype;\r
return result;\r
}\r
\r
+ public static List<org.simantics.db.layer0.variable.Variable> getDocumentVariables(ReadGraph graph, org.simantics.db.layer0.variable.Variable model) throws DatabaseException {\r
+ if(model == null)\r
+ return Collections.emptyList();\r
+ \r
+ Resource documentType = graph.getPossibleResource("http://www.simantics.org/Documentation-1.1/Document");\r
+ if(documentType == null)\r
+ return Collections.emptyList();\r
+ \r
+ ArrayList<org.simantics.db.layer0.variable.Variable> result = new ArrayList<org.simantics.db.layer0.variable.Variable>();\r
+ for(org.simantics.db.layer0.variable.Variable part : model.getChildren(graph)) {\r
+ if(graph.isInstanceOf(part.getRepresents(graph), documentType)) {\r
+ result.add(part);\r
+ }\r
+ }\r
+\r
+ return result;\r
+ }\r
+ \r
+ public static List<org.simantics.db.layer0.variable.Variable> getResultVariables(ReadGraph graph, org.simantics.db.layer0.variable.Variable model) throws DatabaseException {\r
+ if(model == null)\r
+ return Collections.emptyList();\r
+ \r
+ org.simantics.db.layer0.variable.Variable library = model.getPossibleChild(graph, "PDFLibrary");\r
+ if(library == null)\r
+ return Collections.emptyList();\r
+ \r
+ \r
+ return new ArrayList<org.simantics.db.layer0.variable.Variable>(library.getChildren(graph));\r
+ }\r
+ \r
+ public static List<org.simantics.db.layer0.variable.Variable> getIndexDocuments(ReadGraph graph, org.simantics.db.layer0.variable.Variable project) throws DatabaseException {\r
+ Resource indexRelation = graph.getPossibleResource("http://www.simantics.org/Documentation-1.1/indexDocument");\r
+\r
+ if(indexRelation == null)\r
+ return Collections.emptyList();\r
+ \r
+ ArrayList<org.simantics.db.layer0.variable.Variable> result = new ArrayList<org.simantics.db.layer0.variable.Variable>();\r
+ for(org.simantics.db.layer0.variable.Variable model : project.getChildren(graph)) {\r
+ Resource modelResource = model.getRepresents(graph);\r
+ if(modelResource == null)\r
+ continue;\r
+ \r
+ Resource indexDocumentResource = graph.getPossibleObject(modelResource, indexRelation);\r
+ if(indexDocumentResource != null) {\r
+ org.simantics.db.layer0.variable.Variable indexDoc = Variables.getVariable(graph, indexDocumentResource);\r
+ result.add(indexDoc);\r
+ } \r
+ }\r
+ return result;\r
+ }\r
+ \r
public static Resource getConfiguration(ReadGraph graph, Resource module) throws DatabaseException {\r
if(module == null)\r
return null;\r
.size();\r
}\r
\r
+ public static String base64Encode(ReadGraph graph, org.simantics.db.layer0.variable.Variable variable, String property) throws DatabaseException {\r
+ byte[] fileBArray = variable.getPossiblePropertyValue(graph, property, Bindings.BYTE_ARRAY);\r
+ if(fileBArray != null)\r
+ return Base64.encode(fileBArray);\r
+ else\r
+ return "";\r
+ }\r
+ \r
+ public static String formatDate(long timeMillis) {\r
+ Date date = new Date(timeMillis);\r
+ String result = DateFormat.getDateInstance().format(date);\r
+ return result;\r
+ }\r
}\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.modeling.utils.BatchValidations;\r
import org.simantics.operation.Layer0X;\r
+import org.simantics.scl.runtime.function.Function1;\r
import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.structural.stubs.StructuralResource2;\r
-import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.Activator;\r
+import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.utils.ModelUtils;\r
\r
/**\r
/* ******* IMPORT MODEL ********* */\r
/* ********************************* */\r
public static IStatus importModelFile(String path, final IProgressMonitor monitor) {\r
+ return importModelFile(path, monitor, null);\r
+ }\r
+ public static IStatus importModelFile(String path, final IProgressMonitor monitor, Function1<Resource,WriteRequest> callback) {\r
final Resource project = Simantics.getProject().get();\r
if(project == null) return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model: project not found", null);\r
\r
\r
worked(monitor, 1);\r
\r
+ if(callback != null) {\r
+ WriteRequest userRequest = callback.apply(result);\r
+ if(userRequest != null)\r
+ Simantics.sync(userRequest);\r
+ }\r
+\r
} catch (DatabaseException e) {\r
e.printStackTrace();\r
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed: Model could not be imported.", e);\r
\r
protected static void addSCLMain(WriteGraph graph, Resource modelRoot) throws DatabaseException {\r
Layer0 L0 = Layer0.getInstance(graph);\r
- SysdynResource SR = SysdynResource.getInstance(graph);\r
\r
Collection<Resource> SCLModules = graph.syncRequest(new ObjectsWithType(modelRoot, L0.ConsistsOf, L0.SCLModule));\r
\r