Package org.openquark.gems.client.Gem

Examples of org.openquark.gems.client.Gem.PartInput


    public void retargetArgumentsOnRemove(CollectorGem removedCollector, CollectorGem retargetCollector) {
        if (disableArgumentUpdating) {
            return;
        }
       
        PartInput collectingPart = removedCollector.getCollectingPart();
        CollectorGem collectingPartArgTarget = GemGraph.getInputArgumentTarget(collectingPart);

        // Remove the arg from its target, if any.
        if (collectingPartArgTarget != null) {
            collectingPartArgTarget.removeArgument(collectingPart);
View Full Code Here


       
        // Get the arguments on the connecting subtree.
        Gem.PartOutput outputPart = conn.getSource();
        List<PartInput> connectedInputList = GemGraph.obtainUnboundDescendantInputs(outputPart.getGem(), TraversalScope.TREE, InputCollectMode.UNBURNT_ONLY);
       
        PartInput replacedInputArgument = conn.getDestination();
       
        // Get the input argument which is disappearing.  Note the affected collector.
        CollectorGem replacedArgumentTarget = GemGraph.getInputArgumentTarget(replacedInputArgument);
       
        // The best collector for the new input arguments to target is whatever collector was targeted by the argument being connected.
        // The exception is where any of the new inputs belong to reflectors, in which case the best collector to target is the target itself.
        boolean reflectorInputsPresent = false;
        for (final PartInput input : connectedInputList) {
            if (input.getGem() instanceof ReflectorGem) {
                reflectorInputsPresent = true;
                break;
            }
        }
        CollectorGem collectorToTarget = reflectorInputsPresent ? targetCollector : GemGraph.getInputArgumentTarget(replacedInputArgument);
       
        // Gather the new args, and affected collectors.
        Set<PartInput> newArgSet = new LinkedHashSet<PartInput>();

        for (final PartInput newInput: connectedInputList) {
            newArgSet.add(newInput);
        }
       
        // Try to put the arguments in the right place.
        if (collectorToTarget == null) {
            // Remove the replaced argument (if any) from its target.
            if (replacedArgumentTarget != null) {
                replacedArgumentTarget.removeArgument(replacedInputArgument);
            }
           
        } else if (replacedArgumentTarget == collectorToTarget) {
            // Replace the argument with the new arguments.
            replacedArgumentTarget.replaceArgument(replacedInputArgument, newArgSet);
           
        } else {
            // Remove the replaced argument (if any) from its target.
            if (replacedArgumentTarget != null) {
                replacedArgumentTarget.removeArgument(replacedInputArgument);
            }

            // Retarget any new arguments.
            if (!newArgSet.isEmpty()) {
                // Get the inputs on the tree when connected.
                List<PartInput> joinedInputList = GemGraph.obtainUnboundDescendantInputs(replacedInputArgument.getGem().getRootGem(), TraversalScope.TREE,
                                                                              InputCollectMode.UNBURNT_ONLY);
               
                // Get the first and last indices of the new inputs in the list.
                int firstInputIndex = joinedInputList.indexOf(connectedInputList.get(0));    // if empty, should have been caught by the "if".
                int lastInputIndex = firstInputIndex + connectedInputList.size() - 1;
View Full Code Here

       
        // The set of affected collectors.
        // Note that in the body of this method we freely add nulls to this set.  Null is removed before returning the set to the caller.
        Set<CollectorGem> affectedCollectorSet = new HashSet<CollectorGem>();
       
        PartInput freedInput = conn.getDestination();
        Gem.PartOutput disconnectedOutput = conn.getSource();

        // Determine whether the disconnected input was originally orphaned (ie. only present because of the connection) when connected.
        // We really only have to check for orphaned reflector inputs, since code gem panels check for orphaned code gem inputs.
        boolean wasOrphanedReflectorInput = false;
        if (freedInput.getGem() instanceof ReflectorGem) {
            PartInput reflectedInput = ((ReflectorGem)freedInput.getGem()).getReflectedInput(freedInput);
            if (reflectedInput == null || reflectedInput.isConnected()) {
                wasOrphanedReflectorInput = true;

            } else {
                Gem reflectedInputGem = reflectedInput.getGem();
                int reflectedInputNum = reflectedInput.getInputNum();
                wasOrphanedReflectorInput = reflectedInputNum >= reflectedInputGem.getNInputs() ||
                                            reflectedInputGem.getInputPart(reflectedInputNum) != reflectedInput;
            }
        }
       
        // Get the inputs on the disconnecting subtree.
        List<PartInput> disconnectedTreeInputList = GemGraph.obtainUnboundDescendantInputs(disconnectedOutput.getGem(), TraversalScope.TREE,
                                                                                InputCollectMode.UNBURNT_ONLY);
       
        // (HACK!?) Temporarily re-bind a connection so that argument target resolution can take place.
        freedInput.bindConnection(conn);
        disconnectedOutput.bindConnection(conn);
       
        Map<PartInput, CollectorGem> disconnectedInputToTargetMap = new HashMap<PartInput, CollectorGem>();
        for (final PartInput disconnectedTreeInput : disconnectedTreeInputList) {
            CollectorGem affectedCollector = GemGraph.getInputArgumentTarget(disconnectedTreeInput);
            disconnectedInputToTargetMap.put(disconnectedTreeInput, affectedCollector);
        }
   
        // Figure out the collector to target.
        CollectorGem collectorToTarget = getCollectorToTarget(disconnectedTreeInputList);
        if (collectorToTarget == null) {
            collectorToTarget = GemGraph.obtainOutermostCollector(freedInput.getGem());
        }
        affectedCollectorSet.add(collectorToTarget);
         
        // Unbind the connection.
        freedInput.bindConnection(null);
        disconnectedOutput.bindConnection(null);

        // First the case of an orphaned input (just remove the input from its target).
        if (wasOrphanedReflectorInput) {
            CollectorGem argumentCollectorTarget = disconnectedInputToTargetMap.get(freedInput);
            if (argumentCollectorTarget != null) {
                argumentCollectorTarget.removeArgument(freedInput);
               
                affectedCollectorSet.add(argumentCollectorTarget);
            }
        }
       
        // Iterate over the inputs of the tree which was disconnected, removing them from their target collector.
        // Also, if necessary retarget the new free argument if any of the disconnecting inputs targeted the desired target.
        boolean needToRetargetFreedArgument = !wasOrphanedReflectorInput;
       
        for (final Map.Entry<PartInput, CollectorGem> mapEntry: disconnectedInputToTargetMap.entrySet()) {
            PartInput disconnectedTreeInput = mapEntry.getKey();
            CollectorGem affectedCollector = mapEntry.getValue();
           
            if (affectedCollector != null) {
               
                // Retarget the new free argument if this argument targets the target collector.
View Full Code Here

        // Replace the changed gem connections with the code gem connections.
        Set<Connection> oldConnections = new HashSet<Connection>();

        for (int i = 0, nOldInputs = oldInputs.length; i < nOldInputs; i++) {
            PartInput oldInput = oldInputs[i];
           
            Connection oldInputConnection = oldInput.getConnection();
           
            if (oldInputConnection != null) {
                oldConnections.add(oldInputConnection);
               
                Gem.PartOutput source = oldInputConnection.getSource();
                PartInput dest = codeGem.getInputPart(i);

                Connection newConnection = new Connection(source, dest);
                source.bindConnection(newConnection);
                dest.bindConnection(newConnection);
            }
        }

        Connection oldOutputConnection = changedGem.getOutputPart().getConnection();
        if (oldOutputConnection != null) {
            oldConnections.add(oldOutputConnection);
           
            Gem.PartOutput source = codeGem.getOutputPart();
            PartInput dest = oldOutputConnection.getDestination();

            Connection newConnection = new Connection(source, dest);
            source.bindConnection(newConnection);
            dest.bindConnection(newConnection);
        }       

        // Grab the old inputs.
        List<PartInput> oldUnburntTreeInputList =
            new ArrayList<PartInput>(GemGraph.obtainUnboundDescendantInputs(changedGem.getRootGem(), TraversalScope.TREE, InputCollectMode.UNBURNT_ONLY));
       
        // Replace code gem inputs with old inputs.
        int index = 0;
        for (final PartInput oldUnburntTreeInput : oldUnburntTreeInputList) {
            if (oldUnburntTreeInput.getGem() == codeGem) {
                PartInput oldInput = oldInputs[oldUnburntTreeInput.getInputNum()];
                oldUnburntTreeInputList.set(index, oldInput);
            }
            index++;
        }
       
View Full Code Here

       
        // Get the updated targetable inputs.
        Set<PartInput> updatedTargetableInputSet = new LinkedHashSet<PartInput>();
        int nArgs = changedGem.getNInputs();
        for (int i = 0; i < nArgs; i++) {
            PartInput updatedGemInput = changedGem.getInputPart(i);
            if (!updatedGemInput.isConnected() && !updatedGemInput.isBurnt()) {
                updatedTargetableInputSet.add(updatedGemInput);
            }
        }
       
        // Get the new (untargeted) arguments.
        List<PartInput> untargetedNewArguments = new ArrayList<PartInput>(updatedTargetableInputSet);
        untargetedNewArguments.removeAll(oldTargetableGemInputs);
       
        // Find the best collector to target.
        // This should only be null if there were no targetable inputs on the tree or the gem which changed.
        CollectorGem collectorToTarget = oldTargetableGemInputs.isEmpty() ? getCollectorToTarget(oldUnburntTreeInputList)
                                                                          : getCollectorToTarget(oldTargetableGemInputs);
        if (collectorToTarget == null) {
            collectorToTarget = GemGraph.obtainOutermostCollector(changedGem);
        }

        // Get the collector's old targeting arguments.
        List<PartInput> targetArgs = collectorToTarget.getTargetArguments();
        int nTargetArgs = targetArgs.size();

        // Get the tree arguments which used to target the collector to target, in order.
        List<PartInput> oldTargetingTreeInputs = new ArrayList<PartInput>();
        for (final PartInput unburntTreeInput : oldUnburntTreeInputList) {
            if (GemGraph.getInputArgumentTarget(unburntTreeInput) == collectorToTarget) {
                oldTargetingTreeInputs.add(unburntTreeInput);
            }
        }

        // Calculate characteristics of the previous tree inputs - whether they were together, and/or in natural order.
        Pair<Boolean, Boolean> oldTreeInputsTogetherOrInNaturalOrder = isTogetherOrInNaturalOrder(oldTargetingTreeInputs, targetArgs);
        boolean oldTreeInputsTogether = oldTreeInputsTogetherOrInNaturalOrder.fst().booleanValue();
        boolean oldTreeInputsInNaturalOrder = oldTreeInputsTogetherOrInNaturalOrder.snd().booleanValue();
       
        // Gem the gem inputs which carry over, in order.
        List<PartInput> remainingOldGemInputList = new ArrayList<PartInput>(unburntTreeInputSet);
        remainingOldGemInputList.retainAll(oldTargetableGemInputs);
       
        // Determine if they occur together in natural order (or just together) in the targeted collector's target arguments.
        Pair<Boolean, Boolean> isTogetherOrInNaturalOrder = isTogetherOrInNaturalOrder(oldTargetableGemInputs, targetArgs);
        boolean isTogether = isTogetherOrInNaturalOrder.fst().booleanValue();
        boolean isInNaturalOrder = isTogetherOrInNaturalOrder.snd().booleanValue();
       
        // If the old inputs (on the gem or on the tree) were in natural order, ensure that they remain so.
        if (oldTreeInputsInNaturalOrder) {
            collectorToTarget.removeArguments(targetArgs);
            targetArgs = getTargetArgsInOrder(targetArgs, unburntTreeInputList);
            collectorToTarget.addArguments(targetArgs);

            // The collector to target will also be affected..
            affectedCollectorSet.add(collectorToTarget);

        } else if (isInNaturalOrder) {
            collectorToTarget.removeArguments(targetArgs);
            targetArgs = getTargetArgsInOrder(targetArgs, Arrays.asList(changedGem.getInputParts()));
            collectorToTarget.addArguments(targetArgs);

            // The collector to target will also be affected..
            affectedCollectorSet.add(collectorToTarget);
        }

        // Calculate the inputs which are going away.
        Set<PartInput> departingInputs = new HashSet<PartInput>(oldTargetableGemInputs);
        departingInputs.removeAll(updatedTargetableInputSet);

        // If there aren't any untargeted new arguments, we're done.
        if (untargetedNewArguments.isEmpty()) {
            // Remove from their targets any arguments for inputs which are going away.
            affectedCollectorSet.addAll(removeFromTargets(departingInputs));

            return affectedCollectorSet;
        }
       
        //
        // The rest of this method deals with where to place untargeted new arguments.
        //
       
        // The collector to target will also be affected..
        affectedCollectorSet.add(collectorToTarget);
       
        if (isTogether && isInNaturalOrder) {
            // This is the argument on collectorToTarget before which this gem's args appear.
            //   Null means add to the beginning.
            PartInput argBefore;
           
            // Add the new args to wherever they appear in the tree input set.
            PartInput firstUpdatedInput = updatedTargetableInputSet.iterator().next();
            int firstUpdatedInputIndex = unburntTreeInputList.indexOf(firstUpdatedInput);
           
            if (firstUpdatedInputIndex < 1) {
                argBefore = null;
               
            } else {
                // Get the immediately preceding input on the tree which targets the same collector.
                List<PartInput> precedingTreeInputs = unburntTreeInputList.subList(0, firstUpdatedInputIndex);
                PartInput precedingTargetingInput = getTargetingArg(precedingTreeInputs, collectorToTarget, false);
               
                if (precedingTargetingInput != null) {
                    // Add after the preceding tree input which targets the same collector.
                    argBefore = precedingTargetingInput;

                } else {
                    // No preceding tree inputs target the same collector.

                    // Determine if any inputs which follow on the tree target the same collector.
                    PartInput lastUpdatedInput = (new ArrayList<PartInput>(updatedTargetableInputSet)).get(updatedTargetableInputSet.size() - 1);
                    int lastUpdatedInputIndex = unburntTreeInputList.indexOf(lastUpdatedInput);
                   
                    List<PartInput> followingTreeInputs = unburntTreeInputList.subList(lastUpdatedInputIndex + 1, unburntTreeInputList.size());
                    PartInput followingTargetingInput = getTargetingArg(followingTreeInputs, collectorToTarget, false);
                   
                    if (followingTargetingInput != null) {
                        // Add before the following tree input which targets the same collector.
                        int followingArgTargetIndex = targetArgs.indexOf(followingTargetingInput);
                       
                        // Construct the reverse list of preceding targeting args.
                        List<PartInput> reversedPrecedingTargetArgs = new ArrayList<PartInput>(targetArgs.subList(0, followingArgTargetIndex));
                        Collections.reverse(reversedPrecedingTargetArgs);
                       
                        // Set the arg before to the last preceding arg which isn't an input to the changed gem.
                        // If there isn't any such arg, add to the beginning.
                        argBefore = null;
                        for (final PartInput precedingTargetArg : reversedPrecedingTargetArgs) {
                            if (precedingTargetArg.getGem() != changedGem) {
                                argBefore = precedingTargetArg;
                                break;
                            }
                        }
                       
                    } else {
                        // Add to the end of the collector's args.
                        argBefore = targetArgs.get(nTargetArgs - 1);
                    }
                }
            }

            // remove all the old args..
            collectorToTarget.removeArguments(remainingOldGemInputList);
           
            // add all the updated args back..
            collectorToTarget.addArguments(argBefore, updatedTargetableInputSet, argBefore != null);

        } else if (isInNaturalOrder) {
            // The old inputs appear in natural order in the target arg list.
            // Maintain natural order among new inputs.
           
            // Get the tree arguments which will target the collector to target.
            List<PartInput> newTargetingTreeInputs = new ArrayList<PartInput>();
            for (final PartInput unburntTreeInput : unburntTreeInputList) {
                if (GemGraph.getInputArgumentTarget(unburntTreeInput) == collectorToTarget || unburntTreeInput.getGem() == changedGem) {
                    newTargetingTreeInputs.add(unburntTreeInput);
                }
            }
           
            // If the old tree inputs appeared together in natural order, replace with the new tree inputs.
            if (oldTreeInputsTogether && oldTreeInputsInNaturalOrder) {

                // Remove the arguments, add them back at the appropriate location.
                int addIndex = targetArgs.indexOf(oldTargetingTreeInputs.get(0));
                collectorToTarget.removeArguments(oldTargetingTreeInputs);
                collectorToTarget.addArguments(addIndex, newTargetingTreeInputs);
               

            } else if (oldTreeInputsInNaturalOrder) {
                // If the tree inputs just appear in natural order but not together, insert semi-smartly.
                for (final PartInput newInput : untargetedNewArguments) {
                    // If no preceding tree args, add before the first of the args which targeted the collector.
                    if (newInput == newTargetingTreeInputs.get(0)) {
                        PartInput firstTargetingArg = oldTargetingTreeInputs.get(0);
                        collectorToTarget.addArguments(firstTargetingArg, Collections.singleton(newInput), false);

                    } else {
                        // Add after the arg which precedes it.
                        PartInput precedingTargetingTreeInput = newTargetingTreeInputs.get(newTargetingTreeInputs.indexOf(newInput) - 1);
                        collectorToTarget.addArguments(precedingTargetingTreeInput, Collections.singleton(newInput), true);
                    }
                }
               
            } else {
                // Otherwise, the tree inputs are not in natural order, but the old gem inputs are.
                // Add to the end.
                // Note: it would be better to maintain order where this makes sense
                //   (eg. if intervening gem tree inputs appear together but are reordered wrt each other).
               
                // Now add the arguments to the collector, at the end of the target arg list.
                collectorToTarget.addArguments(untargetedNewArguments);
            }
           
        } else {
            // The remaining args are not in natural order on target args.
           
            // This is the argument on collectorToTarget before which the new args appear.
            //   Null means add to the end.
            PartInput argBefore;   

            if (isTogether) {
                // Add after the last of the target's arguments that belongs to an input on this gem.
                argBefore = null;
                for (final PartInput targetArg : targetArgs) {
View Full Code Here

        // Now add the arguments to the target.

        // Walk backwards over the inputs coming before the replaced input, looking for an input which targets the target collector.
        // If we find one, add all the arguments after that input.
        List<PartInput> beforeInputs = newInputList.subList(0, firstNewInputIndex);
        PartInput beforeInputArray[] = (new ArrayList<PartInput>(beforeInputs)).toArray(new PartInput[firstNewInputIndex]);
        for (int i = firstNewInputIndex - 1; i > -1; i--) {
            PartInput inputArgument = beforeInputArray[i];
            if (GemGraph.getInputArgumentTarget(inputArgument) == collectorToTarget) {
                collectorToTarget.addArguments(inputArgument, newArgSet, true);
                return collectorToTarget;
            }
        }
View Full Code Here

            collectorToTarget.addArguments(0, newArgSet);

        } else {
            // Add after the argument which comes before it in source gen.
            List<PartInput> targetedCollectorArgList = collectorToTarget.getTargetArguments();
            PartInput argBefore = (PartInput)argsFromSourceGen[firstArgPosition - 1];
           
            if (targetedCollectorArgList.contains(argBefore)) {
                collectorToTarget.addArguments(argBefore, newArgSet, true);
            } else {
                // The "argBefore" doesn't appear in the list if it's an unaccounted-for arg.
View Full Code Here

     * @param part the part to which intellicut should attempt to connect the current intellicut part
     * @return whether a connection was made
     */
    boolean attemptIntellicutAutoConnect(DisplayedPartConnectable part) {

        PartInput inPart = null;
        PartOutput outPart = null;
       
        // Copy the reference to avoid threading issues.
        DisplayedPartConnectable intellicutPartConnectable = intellicutPart;

        // Assign the correct parts to inPart and outPart.
        if (intellicutPartConnectable instanceof DisplayedPartInput) {
            inPart = (PartInput) intellicutPartConnectable.getPartConnectable();
        } else if (intellicutPartConnectable instanceof DisplayedPartOutput) {
            outPart = (PartOutput) intellicutPartConnectable.getPartConnectable();
        }
        if (part instanceof DisplayedPartInput) {
            inPart = (PartInput) part.getPartConnectable();
        } else if (part instanceof DisplayedPartOutput) {
            outPart = (PartOutput) part.getPartConnectable();
        }
       
        // Check if parts are valid. They maye be burnt, connected or have a null type.
        // A null type occurs if parts belong to a broken gem graph.
        if (inPart == null || inPart.isBurnt() || inPart.isConnected() || inPart.getType() == null ||
            outPart == null || outPart.isConnected() || outPart.getType() == null) {
           
            return false;
        }

        Gem inGem = inPart.getGem();
        Gem outGem = outPart.getGem();
        boolean makeIntellicutConnection = false;
   
        // Connection not possible if both parts are from the same gem.
        if (outGem != inGem) {   
           
            TableTop tableTop = gemCutter.getTableTop();
           
            // Check if it is possible to make the connection by burning or connecting directly.
            if (!GemGraph.isAncestorOfBrokenGemForest(outGem)) {

                TypeExpr destTypeExpr = inPart.getType();
                AutoburnLogic.AutoburnAction burnAction = tableTop.getBurnManager().handleAutoburnGemGesture(outGem, destTypeExpr, true);

                if (burnAction != AutoburnLogic.AutoburnAction.IMPOSSIBLE && burnAction != AutoburnLogic.AutoburnAction.MULTIPLE) {
                    makeIntellicutConnection = true;

View Full Code Here

                connection = gemCutter.getTableTop().doConnectIfValidUserAction(dGem.getGem().getOutputPart(), (PartInput) part);
            }
   
        } else if (intellicutMode == IntellicutMode.PART_OUTPUT){
           
            PartInput inputToConnect = GemGraph.isAutoConnectable(dGem.getGem(), (PartOutput) part, gemCutter.getConnectionContext());

            if (inputToConnect != null) {
                connection = gemCutter.getTableTop().doConnectIfValidUserAction((PartOutput) part, inputToConnect);
            }
        }
View Full Code Here

        // Construct the reverse map.
        // Mapping between value nodes and their corresponding inputs.
        Map<ValueNode, Gem.PartInput> valueNodeInputMap = new HashMap<ValueNode, Gem.PartInput>();
        for (final Map.Entry<PartInput, ValueNode> mapEntry : inputValueNodeMap.entrySet()) {
            PartInput nextInput = mapEntry.getKey();
            valueNodeInputMap.put(mapEntry.getValue(), nextInput);
        }

        // Construct a map from value node to unconstrained type
        Map<ValueNode, TypeExpr> valueNodeToUnconstrainedTypeMap = new HashMap<ValueNode, TypeExpr>();
        if (inputToUnconstrainedTypeMap == null) {
            for (final Map.Entry<PartInput, ValueNode> mapEntry : inputValueNodeMap.entrySet()) {
                Gem.PartInput nextInput = mapEntry.getKey();
                valueNodeToUnconstrainedTypeMap.put(mapEntry.getValue(), nextInput.getType());
            }
        } else {
            for (final Map.Entry<PartInput, ValueNode> mapEntry : inputValueNodeMap.entrySet()) {
                Gem.PartInput nextInput = mapEntry.getKey();
                valueNodeToUnconstrainedTypeMap.put(mapEntry.getValue(), inputToUnconstrainedTypeMap.get(nextInput));
View Full Code Here

TOP

Related Classes of org.openquark.gems.client.Gem.PartInput

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.