Package ptolemy.domains.fsm.kernel

Examples of ptolemy.domains.fsm.kernel.State


            if (!(target instanceof State)) {
                MessageHandler.error("Can only add refinements to states.");
                return;
            }

            State state = (State) target;

            // Check that all these containers exist.
            Nameable immediateContainer = state.getContainer();

            if (immediateContainer == null) {
                MessageHandler.error("State has no container!");
                return;
            }

            final CompositeEntity container = (CompositeEntity) immediateContainer
                    .getContainer();

            if (container == null) {
                MessageHandler.error("State container has no container!");
                return;
            }

            // Open a dialog to get the refinement name and class.
            Query query = new Query();
            String defaultName = container.uniqueName(state.getName());
            query.addLine("Name", "Name", defaultName);

            // See whether the configuration offers state refinements.
            Configuration configuration = ((FSMGraphController) getController())
                    .getConfiguration();
            Entity refinements = configuration.getEntity("_stateRefinements");

            // Default choices.
            String[] choiceClasses = { "ptolemy.domains.fsm.modal.Refinement",
                    "ptolemy.domains.fsm.modal.ModalController" };
            String[] choiceNames = { "Default Refinement",
                    "State Machine Refinement" };

            // Check the configuration to see whether the default is overridden.
            if (refinements instanceof CompositeEntity) {
                // There is a specification.
                List refinementList = ((CompositeEntity) refinements)
                        .entityList();
                choiceNames = new String[refinementList.size()];
                choiceClasses = new String[refinementList.size()];

                Iterator iterator = refinementList.iterator();
                int count = 0;

                while (iterator.hasNext()) {
                    Entity entity = (Entity) iterator.next();
                    choiceNames[count] = entity.getName();
                    choiceClasses[count++] = entity.getClass().getName();
                }
            }

            query
                    .addChoice("Class", "Class", choiceNames, choiceNames[0],
                            true);

            // FIXME: Need a frame owner for first arg.
            // Perhaps calling getController(), which returns a GraphController
            // will be a good start.
            ComponentDialog dialog = new ComponentDialog(null,
                    "Specify Refinement", query);

            if (!dialog.buttonPressed().equals("OK")) {
                return;
            }

            final String newName = query.getStringValue("Name");

            if (container.getEntity(newName) != null) {
                MessageHandler.error("There is already a refinement with name "
                        + newName + ".");
                return;
            }

            int choiceIndex = query.getIntValue("Class");
            String newClass = choiceClasses[choiceIndex];

            String currentRefinements = state.refinementName.getExpression();

            if ((currentRefinements == null) || currentRefinements.equals("")) {
                currentRefinements = newName;
            } else {
                currentRefinements = currentRefinements.trim() + ", " + newName;
            }

            String moml;

            // The MoML we create depends on whether the configuration
            // specified a set of prototype refinements.
            if (refinements instanceof CompositeEntity) {
                String choiceName = choiceNames[choiceIndex];
                Entity template = ((CompositeEntity) refinements)
                        .getEntity(choiceName);
                String templateDescription = template.exportMoML(newName);
                moml = "<group>" + templateDescription + "<entity name=\""
                        + state.getName(container)
                        + "\"><property name=\"refinementName\" value=\""
                        + currentRefinements + "\"/></entity></group>";
            } else {
                moml = "<group><entity name=\"" + newName + "\" class=\""
                        + newClass + "\"/>" + "<entity name=\""
                        + state.getName(container)
                        + "\"><property name=\"refinementName\" value=\""
                        + currentRefinements + "\"/></entity></group>";
            }

            MoMLChangeRequest change = new MoMLChangeRequest(this, container,
View Full Code Here


                MessageHandler
                        .error("Can only remove refinements from states.");
                return;
            }

            State state = (State) target;

            // Check that all these containers exist.
            CompositeEntity immediateContainer = (CompositeEntity) state
                    .getContainer();

            if (immediateContainer == null) {
                MessageHandler.error("State has no container!");
                return;
            }

            final CompositeEntity container = (CompositeEntity) immediateContainer
                    .getContainer();

            if (container == null) {
                MessageHandler.error("State container has no container!");
                return;
            }

            TypedActor[] refinements;

            try {
                refinements = state.getRefinement();
            } catch (Exception ex) {
                MessageHandler.error("Invalid refinements.", ex);
                return;
            }

            if ((refinements == null) || (refinements.length < 1)) {
                MessageHandler.error("No refinements to remove.");
                return;
            }

            String[] choices = new String[refinements.length];

            for (int i = 0; i < refinements.length; i++) {
                choices[i] = ((Nameable) refinements[i]).getName();
            }

            // Open a dialog to get the refinement name and class.
            Query query = new Query();
            query.addChoice("Refinement", "Refinement", choices, choices[0],
                    false);

            // FIXME: Need a frame owner for first arg.
            // Perhaps calling getController(), which returns a GraphController
            // will be a good start.
            ComponentDialog dialog = new ComponentDialog(null,
                    "Specify Refinement", query);

            if (!dialog.buttonPressed().equals("OK")) {
                return;
            }

            String refinementName = query.getStringValue("Refinement");
            StringBuffer newRefinements = new StringBuffer();
            String currentRefinements = state.refinementName.getExpression();
            StringTokenizer tokenizer = new StringTokenizer(currentRefinements,
                    ",");

            while (tokenizer.hasMoreTokens()) {
                String token = tokenizer.nextToken();

                if (!token.trim().equals(refinementName)) {
                    if (newRefinements.length() > 0) {
                        newRefinements.append(", ");
                    }

                    newRefinements.append(token.trim());
                }
            }

            // Check to see whether any other state or transition has
            // this refinment, and if not, remove it from its container.
            Iterator states = immediateContainer.entityList().iterator();
            boolean foundOne = false;

            while (states.hasNext()) {
                NamedObj other = (NamedObj) states.next();

                if ((other != state) && other instanceof State) {
                    String refinementList = ((State) other).refinementName
                            .getExpression();

                    if (refinementList == null) {
                        continue;
                    }

                    tokenizer = new StringTokenizer(refinementList, ",");

                    while (tokenizer.hasMoreTokens()) {
                        String token = tokenizer.nextToken();

                        if (token.equals(refinementName)) {
                            foundOne = true;
                            break;
                        }
                    }

                    if (foundOne) {
                        break;
                    }
                }
            }

            if (!foundOne) {
                Iterator transitions = immediateContainer.relationList()
                        .iterator();

                while (transitions.hasNext()) {
                    NamedObj other = (NamedObj) transitions.next();

                    if (other instanceof Transition) {
                        String refinementList = ((Transition) other).refinementName
                                .getExpression();

                        if (refinementList == null) {
                            continue;
                        }

                        tokenizer = new StringTokenizer(refinementList, ",");

                        while (tokenizer.hasMoreTokens()) {
                            String token = tokenizer.nextToken();

                            if (token.equals(refinementName)) {
                                foundOne = true;
                                break;
                            }
                        }

                        if (foundOne) {
                            break;
                        }
                    }
                }
            }

            String removal = "";

            if (!foundOne) {
                removal = "<deleteEntity name=\"" + refinementName + "\"/>";
            }

            String moml = "<group><entity name=\"" + state.getName(container)
                    + "\"><property name=\"refinementName\" value=\""
                    + newRefinements.toString() + "\"/></entity>" + removal
                    + "</group>";
            MoMLChangeRequest change = new MoMLChangeRequest(this, container,
                    moml);
View Full Code Here

        TypedIOPort hscInR = new TypedIOPort(hsctrl, "outputR");
        hscInR.setInput(true);
        hscInR.setOutput(false);

        State hoverState = new State(hsctrl, "HoverState");
        State accelState = new State(hsctrl, "AccelState");
        State cruise1State = new State(hsctrl, "Cruise1State");
        State climbState = new State(hsctrl, "ClimbState");
        State cruise2State = new State(hsctrl, "Cruise2State");
        hsctrl.initialStateName.setExpression("HoverState");

        /* CTCompositeActor linHover = */_createLinearizer(sub, 0);

        /* CTCompositeActor linAccel = */_createLinearizer(sub, 1);
View Full Code Here

    /** React to an event by highlighting the new state.
     *  @param event The debug event.
     */
    public void event(DebugEvent event) {
        if (event instanceof StateEvent) {
            State state = ((StateEvent) event).getState();

            if (state != null) {
                Object location = state.getAttribute("_location");

                if (location != null) {
                    Figure figure = getFigure(location);

                    if (figure != null) {
View Full Code Here

                        boolean removeIt = true;
                        Iterator states = master.entityList(State.class)
                                .iterator();

                        while (removeIt && states.hasNext()) {
                            State state = (State) states.next();
                            TypedActor[] stateRefinements = null;

                            try {
                                stateRefinements = state.getRefinement();
                            } catch (IllegalActionException e1) {
                                // Ignore, no refinement to check.
                            }

                            if (stateRefinements == null) {
View Full Code Here

                NamedObj tail = (NamedObj) getSemanticObject(linkTail);

                if (head instanceof State && tail instanceof State) {
                    // When we connect two states, we actually connect the
                    // appropriate ports.
                    State headState = (State) head;
                    State tailState = (State) tail;
                    ComponentPort headPort = headState.incomingPort;
                    ComponentPort tailPort = tailState.outgoingPort;
                    NamedObj ptolemyModel = getPtolemyModel();

                    // If the context is not the entity that we're editing,
View Full Code Here

                NamedObj tail = (NamedObj) getSemanticObject(linkTail);

                if (head instanceof State && tail instanceof State) {
                    // When we connect two states, we actually connect the
                    // appropriate ports.
                    State headState = (State) head;
                    State tailState = (State) tail;
                    ComponentPort headPort = headState.incomingPort;
                    ComponentPort tailPort = tailState.outgoingPort;
                    NamedObj ptolemyModel = getPtolemyModel();

                    // If the context is not the entity that we're editing,
View Full Code Here

         *  specified container.
         */
        private String _unlinkHead(NamedObj container, NamedObj linkHead,
                Relation relation) {
            NamedObj head = (NamedObj) getSemanticObject(linkHead);
            State headState = (State) head;
            ComponentPort headPort = headState.incomingPort;
            return "<unlink port=\"" + headPort.getName(container)
                    + "\" relation=\"" + relation.getName(container) + "\"/>\n";
        }
View Full Code Here

         *  specified container.
         */
        private String _unlinkTail(NamedObj container, NamedObj linkTail,
                Relation relation) {
            NamedObj tail = (NamedObj) getSemanticObject(linkTail);
            State tailState = (State) tail;
            ComponentPort tailPort = tailState.outgoingPort;
            return "<unlink port=\"" + tailPort.getName(container)
                    + "\" relation=\"" + relation.getName(container) + "\"/>\n";
        }
View Full Code Here

        int[][] containerRates = containerHelper.getRates();

        Iterator states = controller.entityList().iterator();
        int configurationNumber = 0;
        while (states.hasNext()) {
            State state = (State) states.next();
            TypedActor[] actors = state.getRefinement();
            if (actors != null) {
                // There should be at most one refinement for each state.
                CodeGeneratorHelper refinementHelper = (CodeGeneratorHelper) _getHelper((NamedObj) actors[0]);
                int[][] rates = refinementHelper.getRates();
                int length = 1;
View Full Code Here

TOP

Related Classes of ptolemy.domains.fsm.kernel.State

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.