Search in sources :

Example 1 with BooleanLiteral

use of edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral in project AGREE by loonwerks.

the class InputConstraintDialog method addBooleanLiteralMenuItem.

private void addBooleanLiteralMenuItem(final Menu menu, final Reference ref, final boolean newValue) {
    final MenuItem menuItem = new MenuItem(menu, SWT.RADIO);
    menuItem.setSelection(ref.get() instanceof BooleanLiteral && ((BooleanLiteral) ref.get()).isValue() == newValue);
    menuItem.setText(Boolean.toString(newValue));
    menuItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (((MenuItem) e.widget).getSelection()) {
                final BooleanLiteral lit = InputConstraintFactory.eINSTANCE.createBooleanLiteral();
                lit.setValue(newValue);
                // Remove parent negation for boolean literals
                final Reference refToEdit = (ref.getParent() != null && ref.getParent().get() instanceof NegativeExpression) ? ref.getParent() : ref;
                refToEdit.set(lit);
                dlg.refreshContraint();
            }
        }
    });
}
Also used : BooleanLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) NegativeExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.NegativeExpression)

Example 2 with BooleanLiteral

use of edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral in project AGREE by loonwerks.

the class InputConstraintDialog method addScalarExpressionsMenuItems.

private void addScalarExpressionsMenuItems(final Menu menu, boolean showBoolean, final Reference ref) {
    if (ref.get() instanceof ScalarExpression && !(ref.get() instanceof BooleanLiteral)) {
        addNegateMenuItem(menu, ref);
    }
    addTextExpressionMenuItem(menu, ref, "Integer...", ResultType.INTEGER, "0");
    addTextExpressionMenuItem(menu, ref, "Real...", ResultType.REAL, "0.0");
    if (showBoolean) {
        final Menu booleanMenu = new Menu(menu);
        final MenuItem booleanMenuItem = new MenuItem(menu, SWT.CASCADE);
        booleanMenuItem.setText("Boolean");
        booleanMenuItem.setMenu(booleanMenu);
        addBooleanLiteralMenuItem(booleanMenu, ref, true);
        addBooleanLiteralMenuItem(booleanMenu, ref, false);
    }
    addReferenceMenuItems(menu, ref);
    addNewEClassMenuItem(menu, ref, "Random Integer", icp.getRandomIntegerExpression());
    addNewEClassMenuItem(menu, ref, "Random Real", icp.getRandomRealExpression());
    addNewEClassMenuItem(menu, ref, "Random Element", icp.getRandomElementExpression());
    addPreviousValueMenuItem(menu, ref);
}
Also used : BooleanLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) ScalarExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ScalarExpression)

Example 3 with BooleanLiteral

use of edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral in project AGREE by loonwerks.

the class CounterexampleLoaderHelper method lustreValueToInputConstraint.

private InputConstraint lustreValueToInputConstraint(final Value value) {
    if (value instanceof BooleanValue) {
        final BooleanLiteral ic = InputConstraintFactory.eINSTANCE.createBooleanLiteral();
        ic.setValue(((BooleanValue) value).value);
        return ic;
    } else if (value instanceof IntegerValue) {
        final IntegerLiteral ic = InputConstraintFactory.eINSTANCE.createIntegerLiteral();
        ic.setValue(((IntegerValue) value).value);
        return ic;
    } else if (value instanceof RealValue) {
        final BigFraction fraction = ((RealValue) value).value;
        final BinaryExpression ic = ExpressionFactory.createFraction(fraction.getNumerator(), fraction.getDenominator());
        return ic;
    } else {
        throw new RuntimeException("Unsupported value type: " + value.getClass());
    }
}
Also used : RealValue(jkind.lustre.values.RealValue) BigFraction(jkind.util.BigFraction) BinaryExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BinaryExpression) BooleanLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral) BooleanValue(jkind.lustre.values.BooleanValue) IntegerValue(jkind.lustre.values.IntegerValue) IntegerLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.IntegerLiteral)

Example 4 with BooleanLiteral

use of edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral in project AGREE by loonwerks.

the class InputConstraintDialog method createConstraintWidgets.

private void createConstraintWidgets(final Composite container, final Object parentValue, final Reference ref) {
    final Object value = ref.get();
    if (value instanceof IntervalExpression) {
        final IntervalExpression ie = (IntervalExpression) value;
        if (ref.getEType() == icp.getIntervalExpression()) {
            newLabel(container, "interval");
        } else {
            newLink(container, ref, "interval");
        }
        newLink(container, new StructuralFeatureReference(ref, ie, icp.getIntervalExpression_LeftClosed()), ie.isLeftClosed() ? "[" : "(");
        createConstraintWidgets(container, value, new StructuralFeatureReference(ref, ie, icp.getIntervalExpression_Left()));
        newLabel(container, ",");
        createConstraintWidgets(container, value, new StructuralFeatureReference(ref, ie, icp.getIntervalExpression_Right()));
        newLink(container, new StructuralFeatureReference(ref, ie, icp.getIntervalExpression_RightClosed()), ie.isRightClosed() ? "]" : ")");
    } else if (value instanceof SetExpression) {
        final SetExpression se = (SetExpression) value;
        if (ref.getEType() == icp.getSetExpression()) {
            newLabel(container, "set");
        } else {
            newLink(container, ref, "set");
        }
        newLabel(container, "{");
        final int numberOfMembers = se.getMembers().size();
        for (int i = 0; i < numberOfMembers; i++) {
            createConstraintWidgets(container, value, new ListMemberReference(ref, icp.getSetExpression_Members().getEType(), se.getMembers(), i));
            newLabel(container, ",");
        }
        newLink(container, new ListMemberReference(ref, icp.getSetExpression_Members().getEType(), se.getMembers(), -1), "<add>");
        newLabel(container, "}");
    } else if (value instanceof BinaryExpression) {
        final BinaryExpression be = (BinaryExpression) value;
        boolean showParentheses = parentValue instanceof NegativeExpression;
        if (!showParentheses && parentValue instanceof BinaryExpression) {
            final BinaryExpression parentBe = (BinaryExpression) parentValue;
            final boolean isAddOrSubstract = be.getOp() == Operator.ADDITION || be.getOp() == Operator.SUBTRACTION;
            final boolean isParentAddOrSubstract = parentBe.getOp() == Operator.ADDITION || parentBe.getOp() == Operator.SUBTRACTION;
            if (isAddOrSubstract && !isParentAddOrSubstract) {
                showParentheses = true;
            }
        }
        if (showParentheses) {
            newLabel(container, "(");
        }
        createConstraintWidgets(container, value, new StructuralFeatureReference(ref, be, icp.getBinaryExpression_Left()));
        newLink(container, new StructuralFeatureReference(ref, be, icp.getBinaryExpression_Op()), be.getOp().toString());
        createConstraintWidgets(container, value, new StructuralFeatureReference(ref, be, icp.getBinaryExpression_Right()));
        if (showParentheses) {
            newLabel(container, ")");
        }
    } else if (value instanceof NegativeExpression) {
        final NegativeExpression ne = (NegativeExpression) value;
        newLabel(container, "-");
        createConstraintWidgets(container, value, new StructuralFeatureReference(ref, ne, icp.getNegativeExpression_Value()));
    } else if (value instanceof PreExpression) {
        newLink(container, ref, "previous value of");
        createConstraintWidgets(container, value, new StructuralFeatureReference(ref, (PreExpression) value, icp.getPreExpression_Ref()));
    } else if (value instanceof RandomElementExpression) {
        newLink(container, ref, "random element");
        newLabel(container, "in");
        createConstraintWidgets(container, value, new StructuralFeatureReference(ref, (RandomElementExpression) value, icp.getRandomElementExpression_Set()));
    } else if (value instanceof RandomIntegerExpression) {
        newLink(container, ref, "random integer");
        newLabel(container, "in");
        createConstraintWidgets(container, value, new StructuralFeatureReference(ref, (RandomIntegerExpression) value, icp.getRandomIntegerExpression_Interval()));
    } else if (value instanceof RandomRealExpression) {
        newLink(container, ref, "random real");
        newLabel(container, "in");
        createConstraintWidgets(container, value, new StructuralFeatureReference(ref, (RandomRealExpression) value, icp.getRandomRealExpression_Interval()));
    } else if (value instanceof ConstRefExpression) {
        newLink(container, ref, model.unparse((ConstRefExpression) value));
    } else if (value instanceof ElementRefExpression) {
        newLink(container, ref, model.unparse((ElementRefExpression) value));
    } else if (value instanceof RealLiteral) {
        final RealLiteral rl = (RealLiteral) value;
        newLink(container, ref, rl.getValue().toString());
    } else if (value instanceof IntegerLiteral) {
        final IntegerLiteral il = (IntegerLiteral) value;
        newLink(container, ref, il.getValue().toString());
    } else if (value instanceof BooleanLiteral) {
        final BooleanLiteral bl = (BooleanLiteral) value;
        newLink(container, ref, Boolean.toString(bl.isValue()));
    } else if (value == null) {
        newLink(container, ref, "<select>");
    } else {
        throw new RuntimeException("Unexpected value: " + value);
    }
}
Also used : SetExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.SetExpression) ConstRefExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ConstRefExpression) BooleanLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral) RandomIntegerExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RandomIntegerExpression) PreExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.PreExpression) RealLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RealLiteral) BinaryExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BinaryExpression) RandomElementExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RandomElementExpression) RandomRealExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RandomRealExpression) EObject(org.eclipse.emf.ecore.EObject) IntervalExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.IntervalExpression) IntegerLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.IntegerLiteral) NegativeExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.NegativeExpression) ElementRefExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ElementRefExpression)

Example 5 with BooleanLiteral

use of edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral in project AGREE by loonwerks.

the class SimulatePossibilitiesHandler method openChart.

private void openChart(final IProgressMonitor monitor, final Shell shell, final Object simControlLock, final SimulationUIService simulationUIService, final SimulationEngine simulationEngine, final List<SimulationEngineState> simulationEngineStates, final SimulationEngineState initialState) {
    simulationEngine.queueNotification(new NotificationHandler() {

        @Override
        public void handleNotification(final SimulationEngineNotification notification) {
            Display.getDefault().syncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        if (!simulationEngineStates.isEmpty() && !monitor.isCanceled()) {
                            // Listening for cancellation
                            final SimulatorStateListener simListener = new SimulatorStateListener() {

                                @Override
                                public void onSimulatorStateChanged(SimulatorState simulatorState) {
                                    if (simulationUIService.getCurrentState().getEngineState() == null) {
                                        if (shell != null && !shell.isDisposed()) {
                                            // Close SimulatingPossibilitiesView on cancel
                                            shell.close();
                                            // Notify on cancel
                                            synchronized (simControlLock) {
                                                simControlLock.notify();
                                            }
                                        }
                                    }
                                }
                            };
                            simulationUIService.addStateChangeListener(simListener);
                            try {
                                // Notify to complete progress monitor
                                synchronized (simControlLock) {
                                    simControlLock.notify();
                                }
                                monitor.done();
                                // Lock simulation while chart is open
                                simulationUIService.lockUserInterface();
                                final SimulatePossibilitiesChartDialog view = new SimulatePossibilitiesChartDialog(shell, simulationUIService, simulationEngineStates);
                                final SetValueSelectionAdapter setValueSelectionAdapter = view.getSetValueSelectionAdapter();
                                final SimulationEngineState returnedState = setValueSelectionAdapter.getSelectedState();
                                if (returnedState != null) {
                                    setSelectedState(view, returnedState);
                                }
                            } finally {
                                simulationUIService.removeStateChangeListener(simListener);
                            }
                        }
                    } finally {
                        simulationUIService.unlockUserInterface();
                    }
                }

                private void setSelectedState(final SimulatePossibilitiesChartDialog view, final SimulationEngineState returnedState) {
                    final SimulationEngine originalSimulationEngine = simulationUIService.getCurrentState().getSimulationEngine();
                    for (final ChartElement chartElement : view.getChartElements()) {
                        final Object simulationStateElement = chartElement.getSimulationStateElement();
                        if (simulationStateElement != null) {
                            final Object value = returnedState.getElementValue(returnedState.getNumberOfFrames() - 1, simulationStateElement);
                            if (value != null) {
                                if (value instanceof BigInteger) {
                                    final IntegerLiteral il = InputConstraintFactory.eINSTANCE.createIntegerLiteral();
                                    il.setValue((BigInteger) value);
                                    originalSimulationEngine.setInputConstraint(simulationStateElement, il);
                                } else if (value instanceof Rational) {
                                    final Rational rational = (Rational) value;
                                    final BinaryExpression be = ExpressionFactory.createFraction(rational.numerator, rational.denominator);
                                    originalSimulationEngine.setInputConstraint(simulationStateElement, be);
                                } else if (value instanceof Boolean) {
                                    final BooleanLiteral bl = InputConstraintFactory.eINSTANCE.createBooleanLiteral();
                                    bl.setValue((Boolean) value);
                                    originalSimulationEngine.setInputConstraint(simulationStateElement, bl);
                                } else {
                                    throw new RuntimeException("Unhandled Type: " + returnedState.getElementType(simulationStateElement));
                                }
                            }
                        }
                    }
                    simulationUIService.stepForward();
                    originalSimulationEngine.resetInputConstraints();
                    for (final ChartElement chartElement : view.getChartElements()) {
                        final Object simulationStateElement = chartElement.getSimulationStateElement();
                        if (simulationStateElement != null) {
                            originalSimulationEngine.setInputConstraint(simulationStateElement, initialState.getElementInputConstraintForNextFrame(simulationStateElement));
                        }
                    }
                }
            });
        }
    });
}
Also used : SetValueSelectionAdapter(edu.uah.rsesc.aadlsimulator.ui.dialogs.SimulatePossibilitiesChartDialog.SetValueSelectionAdapter) Rational(edu.uah.rsesc.aadlsimulator.Rational) SimulationEngineState(edu.uah.rsesc.aadlsimulator.SimulationEngineState) SimulatorStateListener(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorStateListener) ChartElement(edu.uah.rsesc.aadlsimulator.ui.dialogs.ChartHelper.ChartElement) BooleanLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral) SimulatorState(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState) SimulationEngine(edu.uah.rsesc.aadlsimulator.SimulationEngine) BinaryExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BinaryExpression) NotificationHandler(edu.uah.rsesc.aadlsimulator.NotificationHandler) SimulationEngineNotification(edu.uah.rsesc.aadlsimulator.SimulationEngineNotification) BigInteger(java.math.BigInteger) SimulatePossibilitiesChartDialog(edu.uah.rsesc.aadlsimulator.ui.dialogs.SimulatePossibilitiesChartDialog) IntegerLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.IntegerLiteral)

Aggregations

BooleanLiteral (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral)6 BinaryExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BinaryExpression)4 IntegerLiteral (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.IntegerLiteral)4 NegativeExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.NegativeExpression)3 ConstRefExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ConstRefExpression)2 ElementRefExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ElementRefExpression)2 IntervalExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.IntervalExpression)2 PreExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.PreExpression)2 RandomElementExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RandomElementExpression)2 RandomIntegerExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RandomIntegerExpression)2 RandomRealExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RandomRealExpression)2 RealLiteral (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RealLiteral)2 SetExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.SetExpression)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2 NotificationHandler (edu.uah.rsesc.aadlsimulator.NotificationHandler)1 Rational (edu.uah.rsesc.aadlsimulator.Rational)1 SimulationEngine (edu.uah.rsesc.aadlsimulator.SimulationEngine)1 SimulationEngineNotification (edu.uah.rsesc.aadlsimulator.SimulationEngineNotification)1 SimulationEngineState (edu.uah.rsesc.aadlsimulator.SimulationEngineState)1 ChartElement (edu.uah.rsesc.aadlsimulator.ui.dialogs.ChartHelper.ChartElement)1