Search in sources :

Example 36 with LocalParameter

use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.

the class TriggerTemplatePanel method init.

public void init(SimulationContext simulationContext, AutoCompleteSymbolFilter autoCompleteSymbolFilter, BioEvent existingBioEvent) {
    if (simulationContext != null) {
        // mathOpComboBox.removeAllItems();
        // mathOpComboBox.addItem(BioEvent.TriggerComparison.greaterThan);
        // mathOpComboBox.addItem(BioEvent.TriggerComparison.lessThan);
        // mathOpComboBox.addItem(BioEvent.TriggerComparison.greaterThanOrEqual);
        // mathOpComboBox.addItem(BioEvent.TriggerComparison.lessThanOrEqual);
        varAboveComboBox.removeAllItems();
        varBelowComboBox.removeAllItems();
        SymbolTableEntry[] triggerExprSymbols = ModelOptimizationSpec.calculateTimeDependentModelObjects(simulationContext);
        Arrays.sort(triggerExprSymbols, new Comparator<SymbolTableEntry>() {

            @Override
            public int compare(SymbolTableEntry o1, SymbolTableEntry o2) {
                return o1.getName().compareToIgnoreCase(o2.getName());
            }
        });
        for (SymbolTableEntry ste : triggerExprSymbols) {
            if (!(ste instanceof ReservedSymbol)) {
                varAboveComboBox.addItem(ste);
                varBelowComboBox.addItem(ste);
            }
        }
        // setVerifier(simulationContext);
        Map<String, SymbolTableEntry> entryMap = new HashMap<String, SymbolTableEntry>();
        simulationContext.getEntries(entryMap);
        textFieldAboveVarVal.setAutoCompleteSymbolFilter(autoCompleteSymbolFilter);
        textFieldAboveVarVal.setAutoCompletionWords(entryMap.keySet());
        textFieldBelowVarVal.setAutoCompleteSymbolFilter(autoCompleteSymbolFilter);
        textFieldBelowVarVal.setAutoCompletionWords(entryMap.keySet());
        textFieldSingleTime.setAutoCompleteSymbolFilter(autoCompleteSymbolFilter);
        textFieldSingleTime.setAutoCompletionWords(entryMap.keySet());
        textFieldGeneral.setAutoCompleteSymbolFilter(autoCompleteSymbolFilter);
        textFieldGeneral.setAutoCompletionWords(entryMap.keySet());
        if (existingBioEvent != null) {
            // Edit Trigger mode
            switch(existingBioEvent.getTriggerType()) {
                case GeneralTrigger:
                    {
                        textFieldGeneral.setText(existingBioEvent.getParameter(BioEventParameterType.GeneralTriggerFunction).getExpression().infix());
                        rdbtnGeneral.setSelected(true);
                        break;
                    }
                case LogRangeTimes:
                    {
                        LocalParameter rangeMinParam = existingBioEvent.getParameter(BioEventParameterType.RangeMinTime);
                        if (rangeMinParam != null && rangeMinParam.getExpression() != null) {
                            textFieldLogMin.setText(rangeMinParam.getExpression().infix());
                        } else {
                            textFieldLogMin.setText("");
                        }
                        LocalParameter rangeMaxParam = existingBioEvent.getParameter(BioEventParameterType.RangeMaxTime);
                        if (rangeMaxParam != null && rangeMaxParam.getExpression() != null) {
                            textFieldLogMax.setText(rangeMaxParam.getExpression().infix());
                        } else {
                            textFieldLogMax.setText("");
                        }
                        LocalParameter rangeNumParam = existingBioEvent.getParameter(BioEventParameterType.RangeNumTimes);
                        if (rangeNumParam != null && rangeNumParam.getExpression() != null) {
                            textFieldLogNum.setText(rangeNumParam.getExpression().infix());
                        } else {
                            textFieldLogNum.setText("");
                        }
                        rdbtnLogTimeRange.setSelected(true);
                        break;
                    }
                case LinearRangeTimes:
                    {
                        LocalParameter rangeMinParam = existingBioEvent.getParameter(BioEventParameterType.RangeMinTime);
                        if (rangeMinParam != null && rangeMinParam.getExpression() != null) {
                            textFieldLinearMin.setText(rangeMinParam.getExpression().infix());
                        } else {
                            textFieldLinearMin.setText("");
                        }
                        LocalParameter rangeMaxParam = existingBioEvent.getParameter(BioEventParameterType.RangeMaxTime);
                        if (rangeMaxParam != null && rangeMaxParam.getExpression() != null) {
                            textFieldLinearMax.setText(rangeMaxParam.getExpression().infix());
                        } else {
                            textFieldLinearMax.setText("");
                        }
                        LocalParameter rangeNumParam = existingBioEvent.getParameter(BioEventParameterType.RangeNumTimes);
                        if (rangeNumParam != null && rangeNumParam.getExpression() != null) {
                            textFieldLinearNum.setText(rangeNumParam.getExpression().infix());
                        } else {
                            textFieldLinearNum.setText("");
                        }
                        rdbtnLinearTimeRange.setSelected(true);
                        break;
                    }
                case ListOfTimes:
                    {
                        StringBuffer sb = new StringBuffer();
                        for (LocalParameter p : existingBioEvent.getEventParameters()) {
                            if (p.getRole() == BioEventParameterType.TimeListItem) {
                                if (sb.length() > 0) {
                                    sb.append(",");
                                }
                                sb.append(p.getExpression().infix());
                            }
                        }
                        textFieldListTimes.setText(sb.toString());
                        rdbtnListTimes.setSelected(true);
                        break;
                    }
                case ObservableAboveThreshold:
                    {
                        LocalParameter observableParameter = existingBioEvent.getParameter(BioEventParameterType.Observable);
                        SymbolTableEntry ste = null;
                        if (observableParameter != null && observableParameter.getExpression() != null && observableParameter.getExpression().isIdentifier()) {
                            ste = observableParameter.getExpression().getSymbolBinding(observableParameter.getExpression().getSymbols()[0]);
                            varAboveComboBox.setSelectedItem(ste);
                        }
                        textFieldAboveVarVal.setText(existingBioEvent.getParameter(BioEventParameterType.Threshold).getExpression().infix());
                        rdbtnVarAboveThreshold.setSelected(true);
                        break;
                    }
                case ObservableBelowThreshold:
                    {
                        LocalParameter observableParameter = existingBioEvent.getParameter(BioEventParameterType.Observable);
                        SymbolTableEntry ste = null;
                        if (observableParameter != null && observableParameter.getExpression() != null && observableParameter.getExpression().isIdentifier()) {
                            ste = observableParameter.getExpression().getSymbolBinding(observableParameter.getExpression().getSymbols()[0]);
                            varBelowComboBox.setSelectedItem(ste);
                        }
                        textFieldBelowVarVal.setText(existingBioEvent.getParameter(BioEventParameterType.Threshold).getExpression().infix());
                        rdbtnVarBelowThreshold.setSelected(true);
                        break;
                    }
                case SingleTriggerTime:
                    {
                        LocalParameter parameter = existingBioEvent.getParameter(BioEventParameterType.SingleTriggerTime);
                        textFieldSingleTime.setText(parameter.getExpression().infix());
                        rdbtnSingleTime.setSelected(true);
                        break;
                    }
            }
        }
    }
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) HashMap(java.util.HashMap) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol)

Example 37 with LocalParameter

use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.

the class TriggerTemplatePanel method setTrigger.

// private void setVerifier(final SimulationContext simulationContext){
// textFieldGeneral.setInputVerifier(new InputVerifier() {
// @Override
// public boolean verify(JComponent input) {
// boolean bValid = true;
// if (textFieldGeneral.isEnabled()) {
// String text = textFieldGeneral.getText();
// String errorText = null;
// if (text == null || text.trim().length() == 0) {
// bValid = false;
// errorText = "Trigger expression cannot be empty";
// }else{
// Expression expr = null;
// try{
// expr = EventPanel.bindTriggerExpression(textFieldGeneral.getText(),simulationContext);
// }catch(Exception e){
// bValid = false;
// errorText = e.getMessage();
// }
// }
// if (bValid) {
// textFieldGeneral.setBorder(UIManager.getBorder("TextField.border"));
// //						getBtnPlotTrigger().setEnabled(true);
// textFieldGeneral.setToolTipText(null);
// } else {
// textFieldGeneral.setBorder(GuiConstants.ProblematicTextFieldBorder);
// //						getBtnPlotTrigger().setEnabled(false);
// textFieldGeneral.setToolTipText(errorText);
// //						SwingUtilities.invokeLater(new Runnable() {
// //						    public void run() {
// //						    	getTriggerTextField().requestFocus();
// //						    }
// //						});
// }
// }
// return bValid;
// }
// });
// 
// }
public void setTrigger(BioEvent bioEvent) throws Exception {
    LocalParameter delayParam = bioEvent.getParameter(BioEventParameterType.TriggerDelay);
    if (rdbtnGeneral.isSelected()) {
        bioEvent.setTriggerType(TriggerType.GeneralTrigger);
        bioEvent.setParameterValue(BioEventParameterType.GeneralTriggerFunction, new Expression(textFieldGeneral.getText()));
    } else if (rdbtnListTimes.isSelected()) {
        bioEvent.setTriggerType(TriggerType.ListOfTimes);
        Expression[] listExps = new Expression("myFunc(" + textFieldListTimes.getText() + ")").getFunctionInvocations(null)[0].getArguments();
        bioEvent.setTimeList(listExps);
    } else if (rdbtnLinearTimeRange.isSelected()) {
        bioEvent.setTriggerType(TriggerType.LinearRangeTimes);
        bioEvent.setParameterValue(BioEventParameterType.RangeMinTime, new Expression(textFieldLinearMin.getText()));
        bioEvent.setParameterValue(BioEventParameterType.RangeMaxTime, new Expression(textFieldLinearMax.getText()));
        bioEvent.setParameterValue(BioEventParameterType.RangeNumTimes, new Expression(textFieldLinearNum.getText()));
    } else if (rdbtnLogTimeRange.isSelected()) {
        bioEvent.setTriggerType(TriggerType.LogRangeTimes);
        bioEvent.setParameterValue(BioEventParameterType.RangeMinTime, new Expression(textFieldLogMin.getText()));
        bioEvent.setParameterValue(BioEventParameterType.RangeMaxTime, new Expression(textFieldLogMax.getText()));
        bioEvent.setParameterValue(BioEventParameterType.RangeNumTimes, new Expression(textFieldLogNum.getText()));
    } else if (rdbtnSingleTime.isSelected()) {
        bioEvent.setTriggerType(TriggerType.SingleTriggerTime);
        bioEvent.setParameterValue(BioEventParameterType.SingleTriggerTime, new Expression(textFieldSingleTime.getText()));
    } else if (rdbtnVarAboveThreshold.isSelected()) {
        bioEvent.setTriggerType(TriggerType.ObservableAboveThreshold);
        bioEvent.setParameterValue(BioEventParameterType.Observable, new Expression(((SymbolTableEntry) varAboveComboBox.getSelectedItem()).getName()));
        bioEvent.setParameterValue(BioEventParameterType.Threshold, new Expression(textFieldAboveVarVal.getText()));
    } else if (rdbtnVarBelowThreshold.isSelected()) {
        bioEvent.setTriggerType(TriggerType.ObservableBelowThreshold);
        bioEvent.setParameterValue(BioEventParameterType.Observable, new Expression(((SymbolTableEntry) varBelowComboBox.getSelectedItem()).getName()));
        bioEvent.setParameterValue(BioEventParameterType.Threshold, new Expression(textFieldBelowVarVal.getText()));
    }
    if (delayParam.getExpression() != null) {
        bioEvent.setParameterValue(BioEventParameterType.TriggerDelay, delayParam.getExpression());
    }
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression)

Example 38 with LocalParameter

use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.

the class ReactionRuleKineticsPropertiesPanel method setReversible.

private void setReversible(boolean bReversible) {
    reactionRule.setReversible(bReversible);
    if (!bReversible && reactionRule != null) {
        // we know for sure it must be MassAction
        LocalParameter lp = reactionRule.getKineticLaw().getLocalParameter(RbmKineticLawParameterType.MassActionReverseRate);
        try {
            lp.setExpression(new Expression(0.0d));
        } catch (ExpressionBindingException e) {
            e.printStackTrace();
        }
    }
    getReactionRulePropertiesTableModel().refreshData();
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) Expression(cbit.vcell.parser.Expression) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException)

Example 39 with LocalParameter

use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.

the class ReactionRulePropertiesTableModel method propertyChange.

/**
 * This method gets called when a bound property is changed.
 * @param evt A PropertyChangeEvent object describing the event source
 *   and the property that has changed.
 */
public void propertyChange(java.beans.PropertyChangeEvent evt) {
    if (evt.getSource() == this && evt.getPropertyName().equals("reactionRule")) {
        ReactionRule oldValue = (ReactionRule) evt.getOldValue();
        if (oldValue != null) {
            oldValue.removePropertyChangeListener(this);
            oldValue.getKineticLaw().removePropertyChangeListener(this);
            for (int i = 0; i < oldValue.getKineticLaw().getLocalParameters().length; i++) {
                oldValue.getKineticLaw().getLocalParameters()[i].removePropertyChangeListener(this);
            }
            for (int i = 0; i < oldValue.getKineticLaw().getProxyParameters().length; i++) {
                oldValue.getKineticLaw().getProxyParameters()[i].removePropertyChangeListener(this);
            }
        }
        ReactionRule newValue = (ReactionRule) evt.getNewValue();
        if (newValue != null) {
            newValue.addPropertyChangeListener(this);
            newValue.getKineticLaw().addPropertyChangeListener(this);
            for (int i = 0; i < newValue.getKineticLaw().getLocalParameters().length; i++) {
                newValue.getKineticLaw().getLocalParameters()[i].addPropertyChangeListener(this);
            }
            for (int i = 0; i < newValue.getKineticLaw().getProxyParameters().length; i++) {
                newValue.getKineticLaw().getProxyParameters()[i].addPropertyChangeListener(this);
            }
            autoCompleteSymbolFilter = reactionRule.getAutoCompleteSymbolFilter();
        }
        refreshData();
    }
    if (evt.getSource() == reactionRule && evt.getPropertyName().equals(ReactionRule.PROPERTY_NAME_KINETICLAW)) {
        RbmKineticLaw oldValue = (RbmKineticLaw) evt.getOldValue();
        if (oldValue != null) {
            oldValue.removePropertyChangeListener(this);
            for (int i = 0; i < oldValue.getLocalParameters().length; i++) {
                oldValue.getLocalParameters()[i].removePropertyChangeListener(this);
            }
            for (int i = 0; i < oldValue.getProxyParameters().length; i++) {
                oldValue.getProxyParameters()[i].removePropertyChangeListener(this);
            }
        }
        RbmKineticLaw newValue = (RbmKineticLaw) evt.getNewValue();
        if (newValue != null) {
            newValue.addPropertyChangeListener(this);
            for (int i = 0; i < newValue.getLocalParameters().length; i++) {
                newValue.getLocalParameters()[i].addPropertyChangeListener(this);
            }
            for (int i = 0; i < newValue.getProxyParameters().length; i++) {
                newValue.getProxyParameters()[i].addPropertyChangeListener(this);
            }
        }
        refreshData();
    }
    if (evt.getSource() instanceof RbmKineticLaw && (evt.getPropertyName().equals("localParameters") || evt.getPropertyName().equals("proxyParameters"))) {
        Parameter[] oldParams = (Parameter[]) evt.getOldValue();
        Parameter[] newParams = (Parameter[]) evt.getNewValue();
        for (int i = 0; oldParams != null && i < oldParams.length; i++) {
            oldParams[i].removePropertyChangeListener(this);
        }
        for (int i = 0; newParams != null && i < newParams.length; i++) {
            newParams[i].addPropertyChangeListener(this);
        }
        refreshData();
    }
    if (evt.getSource() instanceof LocalParameter || evt.getSource() instanceof LocalProxyParameter) {
        refreshData();
    }
    if (evt.getSource() instanceof Parameter) {
        fireTableRowsUpdated(0, getRowCount() - 1);
    }
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) LocalProxyParameter(cbit.vcell.mapping.ParameterContext.LocalProxyParameter) ReactionRule(cbit.vcell.model.ReactionRule) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) Parameter(cbit.vcell.model.Parameter) LocalProxyParameter(cbit.vcell.mapping.ParameterContext.LocalProxyParameter) UnresolvedParameter(cbit.vcell.mapping.ParameterContext.UnresolvedParameter) RbmKineticLaw(cbit.vcell.model.RbmKineticLaw)

Example 40 with LocalParameter

use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.

the class EventPanel method updateEventPanel.

private void updateEventPanel() {
    if (getBioEvent() == null) {
        setEnabled(false);
    } else {
        if (getSimulationContext().getGeometry() != null && getSimulationContext().getGeometry().getDimension() > 0 || getSimulationContext().isStoch()) {
            getAddEventAssgnButton().setEnabled(false);
        }
        getDeleteEventAssgnButton().setEnabled(false);
        setEnabled(true);
        // we are initializing EventsPanel, hence no focuslistener should not be active on the text fields
        // getTriggerTextField().removeFocusListener(ivjEventHandler);
        // getDelayTextField().removeFocusListener(ivjEventHandler);
        // set
        // getTriggerTextField().setText(fieldBioEvent.getTriggerExpression().infix());
        // try{
        // String expr = fieldBioEvent.getTrigger().getGeneratedExpression().infix();
        // getLabelTriggerType().setText(
        // getBioEvent().getTrigger().getClass().getSimpleName()+
        // " '"+
        // BeanUtils.forceStringSize(expr, 15, " ", false)+
        // (expr.length()>10?"...":"")+"'");
        // }catch(ExpressionException e){
        // e.printStackTrace();
        // getLabelTriggerType().setText(getBioEvent().getTrigger().getClass().getSimpleName());
        // }
        getLabelTriggerType().setText(getBioEvent().getTriggerType().name());
        LocalParameter delayParam = getBioEvent().getParameter(BioEventParameterType.TriggerDelay);
        if (delayParam != null) {
            if (delayParam.getExpression() != null) {
                getDelayTextField().setText(delayParam.getExpression().infix());
            }
            enableTriggerRadioButtons(true);
            if (getBioEvent().getUseValuesFromTriggerTime()) {
                getRdbtnTrigTime().setSelected(true);
            } else {
                getRdbtnDelayTime().setSelected(true);
            }
        // getUseValuesAtTriggerTimeCheckBox().setSelected(delay.useValuesFromTriggerTime());
        } else {
            getDelayTextField().setText("");
            enableTriggerRadioButtons(false);
        }
        getEventAssignmentsTableModel().setSimulationContext(fieldSimContext);
        getEventAssignmentsTableModel().setBioEvent(fieldBioEvent);
    // for some reason, when events are selected in the table, the delayTextField gains focus (this fires table update whenever
    // another selection is made. To avoid this, adding a request focus for the events table.
    // requestFocusInWindow();
    // addFocusListener(new FocusListener() {
    // public void focusLost(FocusEvent e) {
    // }
    // public void focusGained(FocusEvent e) {
    // removeFocusListener(this);
    // getTriggerTextField().addFocusListener(ivjEventHandler);
    // getDelayTextField().addFocusListener(ivjEventHandler);
    // }
    // });
    }
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter)

Aggregations

LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)45 Expression (cbit.vcell.parser.Expression)31 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)17 PropertyVetoException (java.beans.PropertyVetoException)12 ModelParameter (cbit.vcell.model.Model.ModelParameter)11 SpeciesContext (cbit.vcell.model.SpeciesContext)11 ExpressionException (cbit.vcell.parser.ExpressionException)11 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)9 Parameter (cbit.vcell.model.Parameter)9 ArrayList (java.util.ArrayList)9 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)8 Element (org.jdom.Element)8 ProxyParameter (cbit.vcell.model.ProxyParameter)7 CurrentDensityClampStimulus (cbit.vcell.mapping.CurrentDensityClampStimulus)6 LocalProxyParameter (cbit.vcell.mapping.ParameterContext.LocalProxyParameter)6 TotalCurrentClampStimulus (cbit.vcell.mapping.TotalCurrentClampStimulus)6 Model (cbit.vcell.model.Model)6 ElectricalStimulus (cbit.vcell.mapping.ElectricalStimulus)5 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)5 Domain (cbit.vcell.math.Variable.Domain)5