include "Simantics/SCL"
include "Simantics/UI"
include "Document/All"
+include "Spreadsheet/Solver"
include "File"
-
-effect SpreadsheetTransaction
- "spreadsheetTransaction"
- "org.simantics.spreadsheet.Transaction"
-
-importJava "org.simantics.spreadsheet.graph.ExternalRef" where
- data ExternalRef
-
importJava "org.simantics.spreadsheet.common.TableCell" where
data TableCell
-importJava "java.util.function.Consumer" where
- data Consumer
-
-importJava "org.simantics.spreadsheet.CellEditor" where
- data CellEditor
- startTransaction :: CellEditor -> OperationMode -> <Proc> Transaction
- @JavaName "edit"
- editProperty_ :: CellEditor -> String -> String -> a -> Binding a -> Maybe Consumer -> <SpreadsheetTransaction> ()
- @JavaName "edit"
- editContent :: CellEditor -> String -> Variant -> Maybe Consumer -> <SpreadsheetTransaction> ()
-
@inline
editProperty :: Serializable a => CellEditor -> String -> String -> a -> Maybe Consumer -> <SpreadsheetTransaction> ()
editProperty editor location property value consumer = editProperty_ editor location property value binding consumer
-importJava "org.simantics.spreadsheet.OperationMode" where
- data OperationMode
- OPERATION :: OperationMode
- EDIT_MODE :: OperationMode
-
-importJava "org.simantics.spreadsheet.Transaction" where
- data Transaction
- commit :: Transaction -> <Proc> ()
-
importJava "org.simantics.spreadsheet.common.TreeTableCell" where
data TreeTableCell
treeTableCellRow :: TreeTableCell -> <Proc> Integer
@JavaName getColumn
treeTableCellColumn :: TreeTableCell -> <Proc> Integer
-
-importJava "org.simantics.spreadsheet.common.SpreadsheetCell" where
- data SpreadsheetCell
importJava "org.simantics.spreadsheet.graph.SCL" where
toVariant :: a -> Variant
invalidateAll :: Variable -> <ReadGraph> ()
extRefVariable :: Variable -> <ReadGraph> Variant
extRefActiveVariable :: Variable -> <ReadGraph> Variant
+ forRows :: Variable -> String -> Integer -> Integer -> (Variable -> <ReadGraph,Proc> ()) -> <ReadGraph> ()
+ rowCell :: Variable -> Integer -> <ReadGraph> Maybe Variable
+ offsetCell :: Variable -> Integer -> Integer -> <ReadGraph> Maybe Variable
cellEditor :: Resource -> <ReadGraph> CellEditor
syncExec :: CellEditor -> OperationMode -> (<SpreadsheetTransaction, Proc> a) -> <Proc> a
cellColumn :: Variable -> <ReadGraph> Integer
-
-importJava "org.simantics.spreadsheet.Spreadsheets" where
- cellName :: Integer -> Integer -> String
+ spreadsheetBook :: Variable -> <Proc> SpreadsheetBook
importJava "org.simantics.spreadsheet.util.SpreadsheetUtils" where
createSheet :: Resource -> String -> <WriteGraph> Resource
@JavaName "sheetRun"
bookRun :: Resource -> Variable -> <ReadGraph> Variable
-sheetRunDefault :: Resource -> <ReadGraph> Variable
-sheetRunDefault sheet = sheetRun sheet (resourceVariable sheet)
+sheetRunDefault = bookRunDefault
-importJava "org.simantics.spreadsheet.graph.SpreadsheetSessionManager" where
- removeSpreadsheetSession :: Variable -> <Proc, WriteGraph> ()
+bookRunDefault :: Resource -> <ReadGraph> Variable
+bookRunDefault book = bookRun book (resourceVariable book)
importJava "org.simantics.spreadsheet.graph.ExcelImport" where
importBook :: Resource -> File -> <Proc> ()
} else if(Cell.CELL_TYPE_STRING == val.getCellType()) {
graph.claimLiteral(cell, SR.Cell_content, SR.Cell_content_Inverse, L0.Variant, Variant.ofInstance(val.toString()), Bindings.VARIANT);
} else if(Cell.CELL_TYPE_NUMERIC == val.getCellType()) {
- Double value = Double.parseDouble(val.toString());
- graph.claimLiteral(cell, SR.Cell_content, SR.Cell_content_Inverse, L0.Variant, Variant.ofInstance(value), Bindings.VARIANT);
+ try {
+ Double value = Double.parseDouble(val.toString());
+ graph.claimLiteral(cell, SR.Cell_content, SR.Cell_content_Inverse, L0.Variant, Variant.ofInstance(value), Bindings.VARIANT);
+ } catch (Exception e) {
+ graph.claimLiteral(cell, SR.Cell_content, SR.Cell_content_Inverse, L0.Variant, Variant.ofInstance(val.toString()), Bindings.VARIANT);
+ }
} else {
graph.claimLiteral(cell, SR.Cell_content, SR.Cell_content_Inverse, L0.Variant, Variant.ofInstance(val.toString()), Bindings.VARIANT);
System.err.println("Unprocessed cell type " + val.getCellType() + ", SheetName: " + sheetName + ", Row: " + rowN + ", Col:" + i);
import java.util.List;
import java.util.Map;
+import javax.xml.soap.Node;
+
import org.simantics.Simantics;
import org.simantics.databoard.Bindings;
import org.simantics.databoard.binding.mutable.Variant;
import org.simantics.db.layer0.util.Layer0Utils;
import org.simantics.db.layer0.variable.StandardGraphChildVariable;
import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.VariableNode;
import org.simantics.db.layer0.variable.Variables;
import org.simantics.db.procedure.Listener;
import org.simantics.db.service.ClusteringSupport;
import org.simantics.layer0.Layer0;
-import org.simantics.scl.compiler.commands.CommandSession;
import org.simantics.scl.runtime.SCLContext;
import org.simantics.scl.runtime.function.Function;
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.scl.runtime.tuple.Tuple;
import org.simantics.scl.runtime.tuple.Tuple0;
import org.simantics.scl.runtime.tuple.Tuple2;
import org.simantics.simulator.toolkit.StandardRealm;
}
-
+ public static void forRows(ReadGraph graph, Variable run, String sheetName, int min, int max, Function1<Variable, Tuple> fn) throws DatabaseException {
+
+ String sessionName = run.getParent(graph).getURI(graph);
+ StandardRealm<SheetNode, SpreadsheetBook> realm = SpreadsheetSessionManager.getInstance().getOrCreateRealm(graph, sessionName);
+ SpreadsheetBook book = realm.getEngine();
+ SpreadsheetEngine engine = book.getEngine(sheetName);
+ if(engine == null) return;
+
+ engine.forLines(line -> {
+
+ String path = line.getPath();
+ if(path == null) return;
+ try {
+ Variable lineVariable = run.browse(graph, path);
+ if(lineVariable != null)
+ fn.apply(lineVariable);
+ } catch (DatabaseException e) {
+ // This is not reported here
+ }
+
+ } , min, max);
+
+ }
+
public static List<Variable> possibleConfigurationCellVariables(ReadGraph graph, Variable sheet, Range range) throws DatabaseException {
List<Variable> rowVariables = possibleConfigurationLineVariables(graph, sheet, range);
List<Variable> result = new ArrayList<>();
throw new IllegalStateException("Expected StandardGraphChildVariable, got " + cell.getClass().getName());
}
+ private static SpreadsheetCell getCellFromVariable(Variable cell) {
+ StandardGraphChildVariable std = (StandardGraphChildVariable)cell;
+ return (SpreadsheetCell)std.node.node;
+ }
+
+ private static SpreadsheetLine getLineFromVariable(Variable cell) {
+ StandardGraphChildVariable std = (StandardGraphChildVariable)cell;
+ return (SpreadsheetLine)std.node.node;
+ }
+
+ public static Variable linesVariable(ReadGraph graph, Variable sheetVariable) throws DatabaseException {
+ while(!"Lines".equals(sheetVariable.getName(graph)))
+ sheetVariable = sheetVariable.getParent(graph);
+ return sheetVariable;
+ }
+
+ public static Variable offsetCell(ReadGraph graph, Variable cellVariable, int x, int y) throws DatabaseException {
+
+ Variable lineVariable = cellVariable.getParent(graph);
+ Variable offsetLine = offsetRow(graph, lineVariable, y);
+ if(offsetLine == null) return null;
+ SpreadsheetCell cell = getCellFromVariable(cellVariable);
+ return rowCell(graph, offsetLine, cell.column + x);
+
+ }
+
+ public static Variable offsetRow(ReadGraph graph, Variable lineVariable, int offset) throws DatabaseException {
+
+ if(offset == 0) return lineVariable;
+
+ SpreadsheetLine line = getLineFromVariable(lineVariable);
+ SpreadsheetLine offsetLine = line.possibleOffset(offset);
+ if(offsetLine == null) return null;
+
+ Variable linesVariable = linesVariable(graph, lineVariable);
+ String path = offsetLine.getLinesPath();
+ return linesVariable.browsePossible(graph, path);
+
+ }
+
+ public static Variable rowCell(ReadGraph graph, Variable lineVariable, int column) throws DatabaseException {
+
+ SpreadsheetLine line = getLineFromVariable(lineVariable);
+
+ return lineVariable.getPossibleChild(graph, Spreadsheets.cellName(line.row, column));
+
+ }
+
+ public static SpreadsheetBook spreadsheetBook(Variable variable) {
+ if(variable instanceof StandardGraphChildVariable) {
+ VariableNode<Node> node = ((StandardGraphChildVariable)variable).node;
+ if(node != null) {
+ if(node.node instanceof SpreadsheetBook)
+ return (SpreadsheetBook) node.node;
+ }
+ }
+ return null;
+ }
+
}
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
- .
+ .,\
+ scl/
--- /dev/null
+
+importJava "org.simantics.spreadsheet.ExternalRef" where
+ data ExternalRef
+
+importJava "org.simantics.spreadsheet.solver.SpreadsheetBook" where
+ data SpreadsheetBook
+ @JavaName "getEngine"
+ spreadsheetBookEngine :: SpreadsheetBook -> String -> <Proc> SpreadsheetEngine
+
+importJava "org.simantics.spreadsheet.solver.SpreadsheetEngine" where
+ data SpreadsheetEngine
+ @JavaName "getLines"
+ spreadsheetEngineLines :: SpreadsheetEngine -> Integer -> Integer -> <Proc> [SpreadsheetLine]
+
+importJava "org.simantics.spreadsheet.solver.SpreadsheetLine" where
+ data SpreadsheetLine
+ @JavaName "getRow"
+ spreadsheetLineRow :: SpreadsheetLine -> Integer
+ @JavaName "getCells"
+ spreadsheetLineCells :: SpreadsheetLine -> Integer -> Integer -> <Proc> [SpreadsheetCell]
+
+importJava "org.simantics.spreadsheet.solver.SpreadsheetCell" where
+ data SpreadsheetCell
+ @JavaName "getColumn"
+ spreadsheetCellColumn :: SpreadsheetCell -> Integer
+ @JavaName "getContentVariant"
+ spreadsheetCellContentVariant :: SpreadsheetCell -> SpreadsheetBook -> <Proc> Maybe Variant
+
+importJava "java.util.function.Consumer" where
+ data Consumer
+
+importJava "org.simantics.spreadsheet.Spreadsheets" where
+ cellName :: Integer -> Integer -> String
+
+importJava "org.simantics.spreadsheet.OperationMode" where
+ data OperationMode
+ OPERATION :: OperationMode
+ EDIT_MODE :: OperationMode
+
+importJava "org.simantics.spreadsheet.Transaction" where
+ data Transaction
+ commit :: Transaction -> <Proc> ()
+
+effect SpreadsheetTransaction
+ "spreadsheetTransaction"
+ "org.simantics.spreadsheet.Transaction"
+
+importJava "org.simantics.spreadsheet.CellEditor" where
+ data CellEditor
+ startTransaction :: CellEditor -> OperationMode -> <Proc> Transaction
+ @JavaName "edit"
+ editProperty_ :: CellEditor -> String -> String -> a -> Binding a -> Maybe Consumer -> <SpreadsheetTransaction> ()
+ @JavaName "edit"
+ editContent :: CellEditor -> String -> Variant -> Maybe Consumer -> <SpreadsheetTransaction> ()
+
this.startColumn = copy.startColumn;
this.endColumn = copy.endColumn;
}
+
+ public static Range parse(String identifier) {
+ return Spreadsheets.decodeCellAbsolute(identifier);
+ }
public static Range combine(Range from, Range to) {
return new Range(from.startRow, to.endRow, from.startColumn, to.endColumn);
--- /dev/null
+package org.simantics.spreadsheet.solver;
+
+public class BinarySearch {
+ public int column;
+ BinarySearch() {}
+ BinarySearch(int column) {
+ this.column = column;
+ }
+}
import org.simantics.spreadsheet.solver.formula.parser.ast.AstValue;
@SuppressWarnings("rawtypes")
-public class SpreadsheetCell implements SpreadsheetElement, SheetNode {
+public class SpreadsheetCell extends BinarySearch implements SpreadsheetElement, SheetNode {
private static final long serialVersionUID = 6616793596542239339L;
private int iterations = 0;
final private SpreadsheetLine line;
- final private int column;
int style;
- private Object content;
+ Object content;
final private Map<String, SheetNode> properties;
public SpreadsheetCell(SpreadsheetLine line, int column) {
+ super(column);
this.properties = createProperties();
this.line = line;
- this.column = column;
}
//All SpreadsheetCells have these properties - create them when object is created
public Object getContent() {
return content;
}
+
+ public Variant getContentVariant(SpreadsheetBook book) {
+
+ try {
+ Object content = evaluate(SpreadsheetEvaluationEnvironment.getInstance(book));
+ if(content == null) return Variant.ofInstance("");
+ if(content instanceof Variant) return (Variant)content;
+ if(content instanceof ExternalRefData) return ((ExternalRefData)content).getContent();
+ else return Variant.ofInstance(content);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ return Variant.ofInstance(t.toString());
+ }
+ }
+
+ public SpreadsheetLine getLine() {
+ return line;
+ }
public static SpreadsheetCell empty(SpreadsheetLine line, int column) {
SpreadsheetCell cell = new SpreadsheetCell(line, column);
package org.simantics.spreadsheet.solver;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.function.Consumer;
import org.simantics.spreadsheet.Range;
import org.simantics.spreadsheet.SpreadsheetVisitor;
return root.getLine(row);
}
+ public void forLines(Consumer<SpreadsheetLine> consumer, int min, int max) {
+ assert(lines.nodes.size() == 1);
+ SpreadsheetLines root = lines.nodes.values().iterator().next();
+ root.forLines(consumer, min, max);
+ }
+
+ public List<SpreadsheetLine> getLines(int min, int max) {
+ ArrayList<SpreadsheetLine> result = new ArrayList<>();
+ forLines(line -> result.add(line), min, max);
+ return result;
+ }
+
@Override
public void accept(SpreadsheetVisitor v) {
v.visit(this);
package org.simantics.spreadsheet.solver;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.function.Consumer;
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.scl.runtime.tuple.Tuple;
import org.simantics.spreadsheet.Range;
import org.simantics.spreadsheet.SpreadsheetVisitor;
import org.simantics.spreadsheet.Spreadsheets;
public SpreadsheetEngine getEngine() {
return ((SpreadsheetLines)parent).getEngine();
}
+
+ public int getRow() {
+ return row;
+ }
+
+ public SpreadsheetLine possibleOffset(int offset) {
+ return getEngine().getLine(row+offset);
+ }
+
+ public SpreadsheetCell cellAt(int column) {
+ int index = Collections.binarySearch(cells, new BinarySearch(column), new Comparator<BinarySearch>() {
+ @Override
+ public int compare(BinarySearch bs1, BinarySearch bs2) {
+ return Integer.compare(bs1.column, bs2.column);
+ }
+ });
+ if(index >= 0)
+ return cells.get(index);
+ else
+ return null;
+ }
+
+ public String getLinesPath() {
+ return "/" + ((SpreadsheetLines)parent).getLinesPath() + "/" + getName();
+ }
+
+ public void forCells(Consumer<SpreadsheetCell> consumer, int min, int max) {
+ for(int i=min;i<cells.size() && i<max;i++) {
+ SpreadsheetCell cell = cells.get(i);
+ if(SpreadsheetCell.EMPTY == cell) continue;
+ consumer.accept(cell);
+ }
+ }
+
+ public List<SpreadsheetCell> getCells(int min, int max) {
+ ArrayList<SpreadsheetCell> result = new ArrayList<>();
+ forCells(cell -> result.add(cell), min, max);
+ return result;
+ }
@Override
public String getName() {
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
+import java.util.function.Consumer;
import org.simantics.spreadsheet.SpreadsheetVisitor;
import org.simantics.spreadsheet.Spreadsheets;
}
+ public String getLinesPath() {
+ return getName();
+ }
+
+ public void forLines(Consumer<SpreadsheetLine> consumer, int min, int max) {
+
+ int i=1;
+ int n = (keys.length - 1) / 2;
+
+ // Smaller keys
+ while(i <= n && min > getKey(i-1)) i++;
+
+ while(i <= n && max > getKey(i-1)) {
+
+ int nodeName = getChild(i-1);
+
+ SpreadsheetLines node = nodes.get(nodeName);
+ if(node == null) {
+ consumer.accept(lines.get(-getKey(i-1)));
+ } else {
+ node.forLines(consumer, min, max);
+ }
+
+ i++;
+
+ }
+
+ }
+
public int getMaxRow() {
// if keys == null then this is the root of BTree which has only one child
if (keys == null) {
@Override
public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating,
Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
-// System.err.println("LineUpdater.apply " + value);
LineCommandBuilder builder = context.<LineCommandBuilder>getConcreteCommand();
try {
LineContentBean valuee = (LineContentBean) value.getValue(LineContentBean.BINDING);