Search in sources :

Example 21 with SpeciesContextSpec

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

the class InitialConditionsPanel method initialize.

/**
 * Initialize the class.
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initialize() {
    try {
        // user code begin {1}
        // user code end
        setName("InitialConditionsPanel");
        setLayout(new BorderLayout());
        add(getRadioButtonAndCheckboxPanel(), BorderLayout.NORTH);
        add(getScrollPaneTable().getEnclosingScrollPane(), BorderLayout.CENTER);
        getScrollPaneTable().getSelectionModel().addListSelectionListener(ivjEventHandler);
        getJMenuItemPaste().addActionListener(ivjEventHandler);
        getJMenuItemCopy().addActionListener(ivjEventHandler);
        getJMenuItemCopyAll().addActionListener(ivjEventHandler);
        getJMenuItemPasteAll().addActionListener(ivjEventHandler);
        getAmountRadioButton().addActionListener(ivjEventHandler);
        getConcentrationRadioButton().addActionListener(ivjEventHandler);
        getRandomizeInitCondnCheckbox().addActionListener(ivjEventHandler);
        DefaultTableCellRenderer renderer = new DefaultScrollTableCellRenderer() {

            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                setIcon(null);
                defaultToolTipText = null;
                if (value instanceof Species) {
                    setText(((Species) value).getCommonName());
                    defaultToolTipText = getText();
                    setToolTipText(defaultToolTipText);
                } else if (value instanceof SpeciesContext) {
                    setText(((SpeciesContext) value).getName());
                    defaultToolTipText = getText();
                    setToolTipText(defaultToolTipText);
                } else if (value instanceof Structure) {
                    setText(((Structure) value).getName());
                    defaultToolTipText = getText();
                    setToolTipText(defaultToolTipText);
                } else if (value instanceof ScopedExpression) {
                    SpeciesContextSpec scSpec = tableModel.getValueAt(row);
                    VCUnitDefinition unit = null;
                    if (table.getColumnName(column).equals(SpeciesContextSpecsTableModel.ColumnType.COLUMN_INITIAL.label)) {
                        SpeciesContextSpecParameter initialConditionParameter = scSpec.getInitialConditionParameter();
                        unit = initialConditionParameter.getUnitDefinition();
                    } else if (table.getColumnName(column).equals(SpeciesContextSpecsTableModel.ColumnType.COLUMN_DIFFUSION.label)) {
                        SpeciesContextSpecParameter diffusionParameter = scSpec.getDiffusionParameter();
                        unit = diffusionParameter.getUnitDefinition();
                    }
                    if (unit != null) {
                        setHorizontalTextPosition(JLabel.LEFT);
                        setIcon(new TextIcon("[" + unit.getSymbolUnicode() + "]", DefaultScrollTableCellRenderer.uneditableForeground));
                    }
                    int rgb = 0x00ffffff & DefaultScrollTableCellRenderer.uneditableForeground.getRGB();
                    defaultToolTipText = "<html>" + StringEscapeUtils.escapeHtml4(getText()) + " <font color=#" + Integer.toHexString(rgb) + "> [" + unit.getSymbolUnicode() + "] </font></html>";
                    setToolTipText(defaultToolTipText);
                    if (unit != null) {
                        setText(defaultToolTipText);
                    }
                }
                TableModel tableModel = table.getModel();
                if (tableModel instanceof SortTableModel) {
                    DefaultScrollTableCellRenderer.issueRenderer(this, defaultToolTipText, table, row, column, (SortTableModel) tableModel);
                    setHorizontalTextPosition(JLabel.TRAILING);
                }
                return this;
            }
        };
        DefaultTableCellRenderer rbmSpeciesShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {

            SpeciesPatternSmallShape spss = null;

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                if (table.getModel() instanceof VCellSortTableModel<?>) {
                    Object selectedObject = null;
                    if (table.getModel() == tableModel) {
                        selectedObject = tableModel.getValueAt(row);
                    }
                    if (selectedObject != null) {
                        if (selectedObject instanceof SpeciesContextSpec) {
                            SpeciesContextSpec scs = (SpeciesContextSpec) selectedObject;
                            SpeciesContext sc = scs.getSpeciesContext();
                            // sp may be null for "plain" species contexts
                            SpeciesPattern sp = sc.getSpeciesPattern();
                            Graphics panelContext = table.getGraphics();
                            spss = new SpeciesPatternSmallShape(4, 2, sp, shapeManager, panelContext, sc, isSelected, issueManager);
                        }
                    } else {
                        spss = null;
                    }
                }
                setText("");
                return this;
            }

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if (spss != null) {
                    spss.paintSelf(g);
                }
            }
        };
        getScrollPaneTable().setDefaultRenderer(SpeciesContext.class, renderer);
        getScrollPaneTable().setDefaultRenderer(Structure.class, renderer);
        getScrollPaneTable().setDefaultRenderer(SpeciesPattern.class, rbmSpeciesShapeDepictionCellRenderer);
        getScrollPaneTable().setDefaultRenderer(Species.class, renderer);
        getScrollPaneTable().setDefaultRenderer(ScopedExpression.class, renderer);
        getScrollPaneTable().setDefaultRenderer(Boolean.class, new ScrollTableBooleanCellRenderer());
    } catch (java.lang.Throwable ivjExc) {
        handleException(ivjExc);
    }
}
Also used : VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) SortTableModel(org.vcell.util.gui.sorttable.SortTableModel) TextIcon(cbit.vcell.mapping.gui.StructureMappingTableRenderer.TextIcon) SpeciesPatternSmallShape(cbit.vcell.graph.SpeciesPatternSmallShape) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) ScrollTableBooleanCellRenderer(org.vcell.util.gui.ScrollTable.ScrollTableBooleanCellRenderer) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Graphics(java.awt.Graphics) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ScopedExpression(cbit.gui.ScopedExpression) BorderLayout(java.awt.BorderLayout) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) JTable(javax.swing.JTable) DefaultScrollTableCellRenderer(org.vcell.util.gui.DefaultScrollTableCellRenderer) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species) TableModel(javax.swing.table.TableModel) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) SortTableModel(org.vcell.util.gui.sorttable.SortTableModel) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)

Example 22 with SpeciesContextSpec

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

the class InitialConditionsPanel method jMenuItemCopy_ActionPerformed.

/**
 * Comment
 */
private void jMenuItemCopy_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
    if (actionEvent.getSource() == getJMenuItemCopy() || actionEvent.getSource() == getJMenuItemCopyAll()) {
        try {
            // 
            // Copy Symbols and Values Init Conditions
            // 
            int[] rows = null;
            if (actionEvent.getSource() == getJMenuItemCopyAll()) {
                rows = new int[getScrollPaneTable().getRowCount()];
                for (int i = 0; i < rows.length; i += 1) {
                    rows[i] = i;
                }
            } else {
                rows = getScrollPaneTable().getSelectedRows();
            }
            MathSymbolMapping msm = null;
            try {
                msm = getSimulationContext().createNewMathMapping().getMathSymbolMapping();
            } catch (Exception e) {
                e.printStackTrace(System.out);
                DialogUtils.showWarningDialog(this, "current math not valid, some paste operations will be limited\n\nreason: " + e.getMessage());
            }
            StringBuffer sb = new StringBuffer();
            sb.append("initial Conditions Parameters for (BioModel)" + getSimulationContext().getBioModel().getName() + " (App)" + getSimulationContext().getName() + "\n");
            java.util.Vector<SymbolTableEntry> primarySymbolTableEntriesV = new java.util.Vector<SymbolTableEntry>();
            java.util.Vector<SymbolTableEntry> alternateSymbolTableEntriesV = new java.util.Vector<SymbolTableEntry>();
            java.util.Vector<Expression> resolvedValuesV = new java.util.Vector<Expression>();
            for (int i = 0; i < rows.length; i += 1) {
                SpeciesContextSpec scs = tableModel.getValueAt(rows[i]);
                if (scs.isConstant()) {
                    // need to change
                    primarySymbolTableEntriesV.add(scs.getInitialConditionParameter());
                    if (msm != null) {
                        alternateSymbolTableEntriesV.add(msm.getVariable(scs.getSpeciesContext()));
                    } else {
                        alternateSymbolTableEntriesV.add(null);
                    }
                    resolvedValuesV.add(new Expression(scs.getInitialConditionParameter().getExpression()));
                    sb.append(scs.getSpeciesContext().getName() + "\t" + scs.getInitialConditionParameter().getName() + "\t" + scs.getInitialConditionParameter().getExpression().infix() + "\n");
                } else {
                    for (int j = 0; j < scs.getParameters().length; j += 1) {
                        SpeciesContextSpec.SpeciesContextSpecParameter scsp = (SpeciesContextSpec.SpeciesContextSpecParameter) scs.getParameters()[j];
                        if (VCellCopyPasteHelper.isSCSRoleForDimension(scsp.getRole(), getSimulationContext().getGeometry().getDimension())) {
                            Expression scspExpression = scsp.getExpression();
                            sb.append(scs.getSpeciesContext().getName() + "\t" + scsp.getName() + "\t" + (scspExpression != null ? scspExpression.infix() : "") + "\n");
                            if (scspExpression != null) {
                                // "Default" boundary conditions can't be copied
                                primarySymbolTableEntriesV.add(scsp);
                                if (msm != null) {
                                    alternateSymbolTableEntriesV.add(msm.getVariable(scsp));
                                } else {
                                    alternateSymbolTableEntriesV.add(null);
                                }
                                resolvedValuesV.add(new Expression(scspExpression));
                            }
                        }
                    }
                }
            }
            // 
            // Send to clipboard
            // 
            VCellTransferable.ResolvedValuesSelection rvs = new VCellTransferable.ResolvedValuesSelection((SymbolTableEntry[]) BeanUtils.getArray(primarySymbolTableEntriesV, SymbolTableEntry.class), (SymbolTableEntry[]) BeanUtils.getArray(alternateSymbolTableEntriesV, SymbolTableEntry.class), (Expression[]) BeanUtils.getArray(resolvedValuesV, Expression.class), sb.toString());
            VCellTransferable.sendToClipboard(rvs);
        } catch (Throwable e) {
            PopupGenerator.showErrorDialog(InitialConditionsPanel.this, "InitialConditionsPanel Copy failed.  " + e.getMessage(), e);
        }
    }
}
Also used : VCellTransferable(cbit.vcell.desktop.VCellTransferable) MathSymbolMapping(cbit.vcell.mapping.MathSymbolMapping) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ScopedExpression(cbit.gui.ScopedExpression) Expression(cbit.vcell.parser.Expression) Vector(java.util.Vector) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)

Example 23 with SpeciesContextSpec

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

the class SimulationContextDbDriver method assignSpeciesContextSpecsSQL.

/**
 * This method was created in VisualAge.
 * @param simContextKey cbit.sql.KeyValue
 * @param simContext cbit.vcell.mapping.SimulationContext
 */
private void assignSpeciesContextSpecsSQL(Connection con, KeyValue simContextKey, SimulationContext simContext) throws SQLException, DataAccessException {
    String sql;
    sql = " SELECT " + "*" + " FROM " + speciesContextSpecTable.getTableName() + " WHERE " + speciesContextSpecTable.simContextRef + " = " + simContextKey + " ORDER BY " + speciesContextSpecTable.id;
    Statement stmt = con.createStatement();
    Boolean bUseConcentration = null;
    try {
        ResultSet rset = stmt.executeQuery(sql);
        while (rset.next()) {
            KeyValue speciesContextRef = new KeyValue(rset.getBigDecimal(speciesContextSpecTable.specContextRef.toString()));
            // KeyValue simContextRef = new KeyValue(rset.getBigDecimal(speciesContextSpecTable.simContextRef.toString()));
            boolean bEnableDiffusing = rset.getBoolean(speciesContextSpecTable.bEnableDif.toString());
            boolean bForceConstant = rset.getBoolean(speciesContextSpecTable.bForceConst.toString());
            // boolean bForceIndep = rset.getBoolean(speciesContextSpecTable.bForceIndep.toString());
            String initCondConcExpS = null;
            String initCondCountExpS = null;
            initCondConcExpS = rset.getString(speciesContextSpecTable.initCondExp.toString());
            if (rset.wasNull()) {
                initCondConcExpS = null;
                initCondCountExpS = rset.getString(speciesContextSpecTable.initCondCountExp.toString());
                if (rset.wasNull()) {
                    throw new DataAccessException("Not expecting both initialCondition expressions types to be NULL");
                }
                if (bUseConcentration == null) {
                    bUseConcentration = false;
                } else if (bUseConcentration) {
                    throw new DataAccessException("Not expecting both Concentration and Count in initialConditions");
                }
            } else {
                if (bUseConcentration == null) {
                    bUseConcentration = true;
                } else if (!bUseConcentration) {
                    throw new DataAccessException("Not expecting both Concentration and Count in initialConditions");
                }
            }
            String diffRateString = rset.getString(speciesContextSpecTable.diffRateExp.toString());
            String boundaryXmString = rset.getString(speciesContextSpecTable.boundaryXmExp.toString());
            if (rset.wasNull()) {
                boundaryXmString = null;
            }
            String boundaryXpString = rset.getString(speciesContextSpecTable.boundaryXpExp.toString());
            if (rset.wasNull()) {
                boundaryXpString = null;
            }
            String boundaryYmString = rset.getString(speciesContextSpecTable.boundaryYmExp.toString());
            if (rset.wasNull()) {
                boundaryYmString = null;
            }
            String boundaryYpString = rset.getString(speciesContextSpecTable.boundaryYpExp.toString());
            if (rset.wasNull()) {
                boundaryYpString = null;
            }
            String boundaryZmString = rset.getString(speciesContextSpecTable.boundaryZmExp.toString());
            if (rset.wasNull()) {
                boundaryZmString = null;
            }
            String boundaryZpString = rset.getString(speciesContextSpecTable.boundaryZpExp.toString());
            if (rset.wasNull()) {
                boundaryZpString = null;
            }
            String velocityXString = rset.getString(speciesContextSpecTable.velocityXExp.toString());
            if (rset.wasNull()) {
                velocityXString = null;
            }
            String velocityYString = rset.getString(speciesContextSpecTable.velocityYExp.toString());
            if (rset.wasNull()) {
                velocityYString = null;
            }
            String velocityZString = rset.getString(speciesContextSpecTable.velocityZExp.toString());
            if (rset.wasNull()) {
                velocityZString = null;
            }
            String wellMixedString = rset.getString(speciesContextSpecTable.bWellMixed.toString());
            if (rset.wasNull()) {
                wellMixedString = null;
            }
            String forceContinuousString = rset.getString(speciesContextSpecTable.bForceContinuous.toString());
            if (rset.wasNull()) {
                forceContinuousString = null;
            }
            // 
            SpeciesContextSpec[] speciesContextSpecs = simContext.getReactionContext().getSpeciesContextSpecs();
            for (int i = 0; i < speciesContextSpecs.length; i++) {
                SpeciesContextSpec scs = speciesContextSpecs[i];
                if (scs.getSpeciesContext().getKey().compareEqual(speciesContextRef)) {
                    try {
                        // scs.setEnableDiffusing(bEnableDiffusing);
                        scs.setConstant(bForceConstant);
                        if (initCondConcExpS != null) {
                            scs.getInitialConcentrationParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(initCondConcExpS)));
                            scs.getInitialCountParameter().setExpression(null);
                        } else {
                            scs.getInitialCountParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(initCondCountExpS)));
                            scs.getInitialConcentrationParameter().setExpression(null);
                        }
                        scs.getDiffusionParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(diffRateString)));
                        if (boundaryXmString != null) {
                            scs.getBoundaryXmParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(boundaryXmString)));
                        } else {
                            scs.getBoundaryXmParameter().setExpression(null);
                        }
                        if (boundaryXpString != null) {
                            scs.getBoundaryXpParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(boundaryXpString)));
                        } else {
                            scs.getBoundaryXpParameter().setExpression(null);
                        }
                        if (boundaryYmString != null) {
                            scs.getBoundaryYmParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(boundaryYmString)));
                        } else {
                            scs.getBoundaryYmParameter().setExpression(null);
                        }
                        if (boundaryYpString != null) {
                            scs.getBoundaryYpParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(boundaryYpString)));
                        } else {
                            scs.getBoundaryYpParameter().setExpression(null);
                        }
                        if (boundaryZmString != null) {
                            scs.getBoundaryZmParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(boundaryZmString)));
                        } else {
                            scs.getBoundaryZmParameter().setExpression(null);
                        }
                        if (boundaryZpString != null) {
                            scs.getBoundaryZpParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(boundaryZpString)));
                        } else {
                            scs.getBoundaryZpParameter().setExpression(null);
                        }
                        if (velocityXString != null) {
                            scs.getVelocityXParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(velocityXString)));
                        } else {
                            scs.getVelocityXParameter().setExpression(null);
                        }
                        if (velocityYString != null) {
                            scs.getVelocityYParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(velocityYString)));
                        } else {
                            scs.getVelocityYParameter().setExpression(null);
                        }
                        if (velocityZString != null) {
                            scs.getVelocityZParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(velocityZString)));
                        } else {
                            scs.getVelocityZParameter().setExpression(null);
                        }
                        if (wellMixedString != null) {
                            int value = Integer.parseInt(wellMixedString);
                            if (value != 0 && value != 1) {
                                throw new DataAccessException("unexpected value for bSpatial column in SimulationCOntextDbDriver: \"" + wellMixedString + "\", expecting 0 or 1");
                            }
                            boolean bWellMixed = (value == 1) ? true : false;
                            scs.setWellMixed(bWellMixed);
                        }
                        if (forceContinuousString != null) {
                            int value = Integer.parseInt(forceContinuousString);
                            if (value != 0 && value != 1) {
                                throw new DataAccessException("unexpected value for bForceContinuous column in SimulationCOntextDbDriver: \"" + forceContinuousString + "\", expecting 0 or 1");
                            }
                            boolean bForceContinuous = (value == 1) ? true : false;
                            scs.setForceContinuous(bForceContinuous);
                        }
                    } catch (Exception e) {
                        throw new DataAccessException("Error setting SpeciesContextSpec info for SimulationContext:" + simContext.getVersion().getName() + " id=" + simContextKey);
                    }
                    break;
                }
            }
        }
    } finally {
        stmt.close();
    }
    if (bUseConcentration != null) {
        simContext.setUsingConcentration(bUseConcentration);
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) Expression(cbit.vcell.parser.Expression) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) DataAccessException(org.vcell.util.DataAccessException) 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)

Example 24 with SpeciesContextSpec

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

the class InitialConditionsPanel method jMenuItemPaste_ActionPerformed.

/**
 * Comment
 */
private void jMenuItemPaste_ActionPerformed(final java.awt.event.ActionEvent actionEvent) {
    final Vector<String> pasteDescriptionsV = new Vector<String>();
    final Vector<Expression> newExpressionsV = new Vector<Expression>();
    final Vector<SpeciesContextSpec.SpeciesContextSpecParameter> changedParametersV = new Vector<SpeciesContextSpec.SpeciesContextSpecParameter>();
    AsynchClientTask task1 = new AsynchClientTask("validating", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (actionEvent.getSource() == getJMenuItemPaste() || actionEvent.getSource() == getJMenuItemPasteAll()) {
                Object pasteThis = VCellTransferable.getFromClipboard(VCellTransferable.OBJECT_FLAVOR);
                MathSymbolMapping msm = null;
                Exception mathMappingException = null;
                try {
                    MathMapping mm = null;
                    mm = getSimulationContext().createNewMathMapping();
                    msm = mm.getMathSymbolMapping();
                } catch (Exception e) {
                    mathMappingException = e;
                    e.printStackTrace(System.out);
                }
                int[] rows = null;
                if (actionEvent.getSource() == getJMenuItemPasteAll()) {
                    rows = new int[getScrollPaneTable().getRowCount()];
                    for (int i = 0; i < rows.length; i += 1) {
                        rows[i] = i;
                    }
                } else {
                    rows = getScrollPaneTable().getSelectedRows();
                }
                // 
                // Check paste
                // 
                StringBuffer errors = null;
                for (int i = 0; i < rows.length; i += 1) {
                    SpeciesContextSpec scs = tableModel.getValueAt(rows[i]);
                    try {
                        if (pasteThis instanceof VCellTransferable.ResolvedValuesSelection) {
                            VCellTransferable.ResolvedValuesSelection rvs = (VCellTransferable.ResolvedValuesSelection) pasteThis;
                            for (int j = 0; j < rvs.getPrimarySymbolTableEntries().length; j += 1) {
                                SpeciesContextSpec.SpeciesContextSpecParameter pasteDestination = null;
                                SpeciesContextSpec.SpeciesContextSpecParameter clipboardBiologicalParameter = null;
                                if (rvs.getPrimarySymbolTableEntries()[j] instanceof SpeciesContextSpec.SpeciesContextSpecParameter) {
                                    clipboardBiologicalParameter = (SpeciesContextSpec.SpeciesContextSpecParameter) rvs.getPrimarySymbolTableEntries()[j];
                                } else if (rvs.getAlternateSymbolTableEntries() != null && rvs.getAlternateSymbolTableEntries()[j] instanceof SpeciesContextSpec.SpeciesContextSpecParameter) {
                                    clipboardBiologicalParameter = (SpeciesContextSpec.SpeciesContextSpecParameter) rvs.getAlternateSymbolTableEntries()[j];
                                }
                                if (clipboardBiologicalParameter == null) {
                                    Variable pastedMathVariable = null;
                                    if (rvs.getPrimarySymbolTableEntries()[j] instanceof Variable) {
                                        pastedMathVariable = (Variable) rvs.getPrimarySymbolTableEntries()[j];
                                    } else if (rvs.getAlternateSymbolTableEntries() != null && rvs.getAlternateSymbolTableEntries()[j] instanceof Variable) {
                                        pastedMathVariable = (Variable) rvs.getAlternateSymbolTableEntries()[j];
                                    }
                                    if (pastedMathVariable != null) {
                                        if (msm == null) {
                                            throw mathMappingException;
                                        }
                                        Variable localMathVariable = msm.findVariableByName(pastedMathVariable.getName());
                                        if (localMathVariable == null) {
                                            // try if localMathVariable is a speciesContext init parameter
                                            String initSuffix = DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONC_UNIT_PREFIX + TokenMangler.fixTokenStrict(scs.getInitialConcentrationParameter().getUnitDefinition().getSymbol());
                                            localMathVariable = msm.findVariableByName(pastedMathVariable.getName() + initSuffix);
                                        }
                                        if (localMathVariable != null) {
                                            SymbolTableEntry[] localBiologicalSymbolArr = msm.getBiologicalSymbol(localMathVariable);
                                            for (int k = 0; k < localBiologicalSymbolArr.length; k += 1) {
                                                if (localBiologicalSymbolArr[k] instanceof SpeciesContext && scs.getSpeciesContext() == localBiologicalSymbolArr[k]) {
                                                    // need to change
                                                    pasteDestination = scs.getInitialConditionParameter();
                                                } else if (localBiologicalSymbolArr[k] instanceof SpeciesContextSpec.SpeciesContextSpecParameter) {
                                                    for (int l = 0; l < scs.getParameters().length; l += 1) {
                                                        if (scs.getParameters()[l] == localBiologicalSymbolArr[k]) {
                                                            pasteDestination = (SpeciesContextSpec.SpeciesContextSpecParameter) localBiologicalSymbolArr[k];
                                                            break;
                                                        }
                                                    }
                                                }
                                                if (pasteDestination != null) {
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    for (int k = 0; k < scs.getParameters().length; k += 1) {
                                        SpeciesContextSpec.SpeciesContextSpecParameter scsp = (SpeciesContextSpec.SpeciesContextSpecParameter) scs.getParameters()[k];
                                        if (scsp.getRole() == clipboardBiologicalParameter.getRole() && scs.getSpeciesContext().compareEqual(((SpeciesContextSpec) clipboardBiologicalParameter.getNameScope().getScopedSymbolTable()).getSpeciesContext())) {
                                            pasteDestination = (SpeciesContextSpec.SpeciesContextSpecParameter) scsp;
                                        }
                                    }
                                }
                                if (pasteDestination != null) {
                                    changedParametersV.add(pasteDestination);
                                    newExpressionsV.add(rvs.getExpressionValues()[j]);
                                    pasteDescriptionsV.add(VCellCopyPasteHelper.formatPasteList(scs.getSpeciesContext().getName(), pasteDestination.getName(), pasteDestination.getExpression().infix(), rvs.getExpressionValues()[j].infix()));
                                }
                            }
                        }
                    } catch (Throwable e) {
                        if (errors == null) {
                            errors = new StringBuffer();
                        }
                        errors.append(scs.getSpeciesContext().getName() + " (" + e.getClass().getName() + ") " + e.getMessage() + "\n\n");
                    }
                }
                if (errors != null) {
                    throw new Exception(errors.toString());
                }
            }
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("pasting", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // Do paste
            if (pasteDescriptionsV.size() > 0) {
                String[] pasteDescriptionArr = new String[pasteDescriptionsV.size()];
                pasteDescriptionsV.copyInto(pasteDescriptionArr);
                SpeciesContextSpec.SpeciesContextSpecParameter[] changedParametersArr = new SpeciesContextSpec.SpeciesContextSpecParameter[changedParametersV.size()];
                changedParametersV.copyInto(changedParametersArr);
                Expression[] newExpressionsArr = new Expression[newExpressionsV.size()];
                newExpressionsV.copyInto(newExpressionsArr);
                VCellCopyPasteHelper.chooseApplyPaste(InitialConditionsPanel.this, pasteDescriptionArr, changedParametersArr, newExpressionsArr);
            } else {
                PopupGenerator.showInfoDialog(InitialConditionsPanel.this, "No paste items match the destination (no changes made).");
            }
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Variable(cbit.vcell.math.Variable) VCellTransferable(cbit.vcell.desktop.VCellTransferable) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Vector(java.util.Vector) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) Hashtable(java.util.Hashtable) MathSymbolMapping(cbit.vcell.mapping.MathSymbolMapping) ScopedExpression(cbit.gui.ScopedExpression) Expression(cbit.vcell.parser.Expression) DiffEquMathMapping(cbit.vcell.mapping.DiffEquMathMapping) MathMapping(cbit.vcell.mapping.MathMapping)

Example 25 with SpeciesContextSpec

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

the class SpeciesContextSpecPanel method onSelectedObjectsChange.

@Override
protected void onSelectedObjectsChange(Object[] selectedObjects) {
    SpeciesContextSpec speciesContextSpec = null;
    if (selectedObjects != null && selectedObjects.length == 1 && selectedObjects[0] instanceof SpeciesContextSpec) {
        speciesContextSpec = (SpeciesContextSpec) selectedObjects[0];
    }
    setSpeciesContextSpec(speciesContextSpec);
}
Also used : SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec)

Aggregations

SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)58 Expression (cbit.vcell.parser.Expression)33 SpeciesContext (cbit.vcell.model.SpeciesContext)28 SimulationContext (cbit.vcell.mapping.SimulationContext)23 Model (cbit.vcell.model.Model)21 BioModel (cbit.vcell.biomodel.BioModel)19 StructureMapping (cbit.vcell.mapping.StructureMapping)17 ReactionStep (cbit.vcell.model.ReactionStep)16 Simulation (cbit.vcell.solver.Simulation)13 ReactionSpec (cbit.vcell.mapping.ReactionSpec)12 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)12 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)12 Structure (cbit.vcell.model.Structure)12 ExpressionException (cbit.vcell.parser.ExpressionException)12 MathDescription (cbit.vcell.math.MathDescription)11 ModelParameter (cbit.vcell.model.Model.ModelParameter)11 FeatureMapping (cbit.vcell.mapping.FeatureMapping)10 SpeciesContextMapping (cbit.vcell.mapping.SpeciesContextMapping)10 Feature (cbit.vcell.model.Feature)10 Parameter (cbit.vcell.model.Parameter)10