Search in sources :

Example 1 with IllegalMappingException

use of cbit.vcell.mapping.IllegalMappingException in project vcell by virtualcell.

the class StructureMappingTableModel method setValueAt.

public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    if (rowIndex < 0 || rowIndex >= getRowCount()) {
        throw new RuntimeException("StructureMappingTableModel.setValueAt(), row = " + rowIndex + " out of range [" + 0 + "," + (getRowCount() - 1) + "]");
    }
    if (columnIndex < 0 || columnIndex >= getColumnCount()) {
        throw new RuntimeException("StructureMappingTableModel.setValueAt(), column = " + columnIndex + " out of range [" + 0 + "," + (getColumnCount() - 1) + "]");
    }
    StructureMapping structureMapping = getValueAt(rowIndex);
    Structure structure = structureMapping.getStructure();
    if (bNonSpatial) {
        switch(columnIndex) {
            case NONSPATIAL_COLUMN_SIZE:
                {
                    try {
                        Expression exp = null;
                        if (aValue instanceof String) {
                            exp = new Expression((String) aValue);
                        } else if (aValue instanceof Double) {
                            exp = new Expression(((Double) aValue).doubleValue());
                        }
                        // if the input volumn is null, leave it as it was.
                        if (exp != null) {
                            // for old ode model, once one size is input, solve the rest.                                                                                                          if it is unnamed compartment(the only one), we don't need to solve anything
                            if (!getGeometryContext().getSimulationContext().isStoch() && getGeometryContext().isAllSizeSpecifiedNull() && getGeometryContext().isAllVolFracAndSurfVolSpecified() && getGeometryContext().getStructureMappings().length > 1) {
                                structureMapping.getSizeParameter().setExpression(exp);
                                double size;
                                try {
                                    size = exp.evaluateConstant();
                                    VCUnitDefinition volumeUnit = getGeometryContext().getSimulationContext().getModel().getUnitSystem().getVolumeUnit();
                                    StructureSizeSolver.updateAbsoluteStructureSizes(getGeometryContext().getSimulationContext(), structure, size, volumeUnit);
                                    fireTableRowsUpdated(0, getRowCount());
                                } catch (ExpressionException ex) {
                                    ex.printStackTrace(System.out);
                                    PopupGenerator.showErrorDialog(ownerTable, "Size of Feature " + structure.getName() + " can not be solved as constant!");
                                } catch (Exception ex) {
                                    ex.printStackTrace(System.out);
                                    PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
                                }
                            } else {
                                structureMapping.getSizeParameter().setExpression(exp);
                                // set fraction in stoch math description, because these might be used when copy from stoch app to ode app.
                                if (getGeometryContext().isAllSizeSpecifiedPositive()) /*&& !getGeometryContext().getSimulationContext().isStoch()*/
                                {
                                    try {
                                        StructureSizeSolver.updateRelativeStructureSizes(getGeometryContext().getSimulationContext());
                                    } catch (Exception ex) {
                                        ex.printStackTrace(System.out);
                                        PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
                                    }
                                }
                            }
                        }
                    } catch (ExpressionException e) {
                        e.printStackTrace(System.out);
                        PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
                    }
                    break;
                }
        }
    } else {
        switch(columnIndex) {
            case SPATIAL_COLUMN_SUBDOMAIN:
                {
                    GeometryClass geometryClass = null;
                    if (aValue instanceof String) {
                        String svname = (String) aValue;
                        geometryClass = getGeometryContext().getGeometry().getGeometryClass(svname);
                    } else if (aValue instanceof GeometryClass) {
                        geometryClass = (GeometryClass) aValue;
                    }
                    if (geometryClass != null) {
                        try {
                            getGeometryContext().assignStructure(structure, geometryClass);
                        } catch (PropertyVetoException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
                        } catch (IllegalMappingException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
                        } catch (MappingException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
                        }
                    }
                    break;
                }
            case SPATIAL_COLUMN_SIZERATIO:
                try {
                    Expression exp = null;
                    if (aValue instanceof String) {
                        exp = new Expression((String) aValue);
                    } else if (aValue instanceof Double) {
                        exp = new Expression(((Double) aValue).doubleValue());
                    }
                    if (exp != null) {
                        structureMapping.getUnitSizeParameter().setExpression(exp);
                        StructureSizeSolver.updateUnitStructureSizes(getGeometryContext().getSimulationContext(), structureMapping.getGeometryClass());
                    }
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
                }
                break;
            case SPATIAL_COLUMN_X_MINUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeXm(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_X_PLUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeXp(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Y_MINUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeYm(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Y_PLUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeYp(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Z_MINUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeZm(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Z_PLUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeZp(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
        }
    }
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) StructureMapping(cbit.vcell.mapping.StructureMapping) ExpressionException(cbit.vcell.parser.ExpressionException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) PropertyVetoException(java.beans.PropertyVetoException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Structure(cbit.vcell.model.Structure)

Example 2 with IllegalMappingException

use of cbit.vcell.mapping.IllegalMappingException in project vcell by virtualcell.

the class SimulationContextDbDriver method getSimulationContextSQL.

/**
 * getModel method comment.
 */
private SimulationContext getSimulationContextSQL(QueryHashtable dbc, Connection con, User user, KeyValue simContextKey) throws /*, ReactStepDbDriver reactStepDB*/
SQLException, DataAccessException, IllegalMappingException, PropertyVetoException {
    SimulationContext simContext = null;
    String sql;
    Field[] f = { new cbit.sql.StarField(simContextTable), userTable.userid };
    Table[] t = { simContextTable, userTable };
    String condition = simContextTable.id.getQualifiedColName() + " = " + simContextKey + " AND " + simContextTable.ownerRef.getQualifiedColName() + " = " + userTable.id.getQualifiedColName();
    sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax);
    // System.out.println(sql);
    Statement stmt = con.createStatement();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        if (rset.next()) {
            simContext = simContextTable.getSimContext(dbc, con, user, rset, geomDB, modelDB, mathDescDB);
        } else {
            throw new ObjectNotFoundException("SimulationContext id=" + simContextKey + " not found for user '" + user + "'");
        }
    } finally {
        stmt.close();
    }
    DataSymbolTable.table.populateDataSymbols(con, simContextKey, simContext.getDataContext(), user, simContext.getModel().getUnitSystem());
    ArrayList<AnnotatedFunction> outputFunctionList = ApplicationMathTable.table.getOutputFunctionsSimcontext(con, simContextKey, dbSyntax);
    if (outputFunctionList != null) {
        OutputFunctionContext outputFnContext = simContext.getOutputFunctionContext();
        outputFnContext.setOutputFunctions(outputFunctionList);
    }
    SimContextTable.table.readAppComponents(con, simContext, dbSyntax);
    assignStimuliSQL(con, simContextKey, simContext);
    assignStructureMappingsSQL(dbc, con, simContextKey, simContext);
    assignSpeciesContextSpecsSQL(con, simContextKey, simContext);
    assignReactionSpecsSQL(con, simContextKey, simContext);
    for (GeometryClass gc : simContext.getGeometry().getGeometryClasses()) {
        try {
            StructureSizeSolver.updateUnitStructureSizes(simContext, gc);
        } catch (Exception e) {
            e.printStackTrace(System.out);
        }
    }
    simContext.getGeometryContext().enforceHierarchicalBoundaryConditions(simContext.getModel().getStructureTopology());
    simContext.getModel().refreshDependencies();
    assignAnalysisTasksSQL(con, simContextKey, simContext);
    // really needed to calculate MembraneMapping parameters that are not stored (inside/outside flux correction factors).
    simContext.refreshDependencies();
    return simContext;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) Table(cbit.sql.Table) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) SimulationContext(cbit.vcell.mapping.SimulationContext) PropertyVetoException(java.beans.PropertyVetoException) DependencyException(org.vcell.util.DependencyException) RecordChangedException(cbit.sql.RecordChangedException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) SQLException(java.sql.SQLException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) OutputFunctionContext(cbit.vcell.solver.OutputFunctionContext) Field(cbit.sql.Field) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) OuterJoin(cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin) ResultSet(java.sql.ResultSet) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 3 with IllegalMappingException

use of cbit.vcell.mapping.IllegalMappingException in project vcell by virtualcell.

the class StructureMappingCartoonTool method menuAction.

protected void menuAction(Shape shape, String menuAction) {
    // 
    if (shape == null) {
        return;
    }
    // 
    if (menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
        if (shape instanceof StructureMappingShape) {
            try {
                StructureMapping sm = (StructureMapping) ((StructureMappingShape) shape).getModelObject();
                getStructureMappingCartoon().getGeometryContext().assignStructure(sm.getStructure(), null);
                getStructureMappingCartoon().refreshAll();
            } catch (IllegalMappingException e) {
                e.printStackTrace(System.out);
                PopupGenerator.showErrorDialog(getGraphPane(), e.getMessage());
            } catch (java.beans.PropertyVetoException e) {
                e.printStackTrace(System.out);
                PopupGenerator.showErrorDialog(getGraphPane(), e.getMessage());
            } catch (MappingException e) {
                e.printStackTrace(System.out);
                PopupGenerator.showErrorDialog(getGraphPane(), e.getMessage());
            }
        }
    } else {
        // default action is to ignore
        System.out.println("unsupported menu action '" + menuAction + "' on shape '" + shape + "'");
    }
}
Also used : StructureMappingShape(cbit.vcell.graph.StructureMappingShape) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) StructureMapping(cbit.vcell.mapping.StructureMapping) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) MappingException(cbit.vcell.mapping.MappingException)

Aggregations

IllegalMappingException (cbit.vcell.mapping.IllegalMappingException)3 MappingException (cbit.vcell.mapping.MappingException)3 GeometryClass (cbit.vcell.geometry.GeometryClass)2 StructureMapping (cbit.vcell.mapping.StructureMapping)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 PropertyVetoException (java.beans.PropertyVetoException)2 Field (cbit.sql.Field)1 RecordChangedException (cbit.sql.RecordChangedException)1 Table (cbit.sql.Table)1 StructureMappingShape (cbit.vcell.graph.StructureMappingShape)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 BoundaryConditionType (cbit.vcell.math.BoundaryConditionType)1 MathException (cbit.vcell.math.MathException)1 Structure (cbit.vcell.model.Structure)1 OuterJoin (cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin)1 DivideByZeroException (cbit.vcell.parser.DivideByZeroException)1 Expression (cbit.vcell.parser.Expression)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)1 OutputFunctionContext (cbit.vcell.solver.OutputFunctionContext)1