예제 #1
0
        public static Tuple <bool, string> EvaluateTests(Guid testingMetaOpID, string filterPattern)
        {
            try
            {
                var result = new Tuple <bool, string>(false, "");

                var testingMetaOp = MetaManager.Instance.GetMetaOperator(testingMetaOpID);

                using (var mainOp = Utilities.CreateEmptyOperator())
                {
                    mainOp.Definition.Name = "Main";
                    MetaManager.Instance.AddMetaOperator(mainOp.Definition.ID, mainOp.Definition);

                    var addOpCmd = new AddOperatorCommand(mainOp, testingMetaOpID);
                    addOpCmd.Do();
                    var testingOp = testingMetaOp.GetOperatorInstance(addOpCmd.AddedInstanceID);

                    result = EvaluateTests(testingOp, filterPattern);

                    var deleteOperatorCmd = new DeleteOperatorsCommand(mainOp, new List <Operator>()
                    {
                        testingOp
                    });
                    deleteOperatorCmd.Do();

                    MetaManager.Instance.RemoveMetaOperator(mainOp.Definition.ID);
                }
                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to evaluate operator definition {0}: {1}", testingMetaOpID, ex.ToString());
                return(new Tuple <bool, string>(false, ""));
            }
        }
예제 #2
0
        public static Tuple <bool, string> EvaluateTests(Operator testingOp, string filterPattern)
        {
            try
            {
                //connect it to a testsevaluator
                var compositionOp = testingOp.Parent;

                var evaluatorMetaOpID = Guid.Parse("0316356c-b1fe-490a-89ce-73c8f67ebccc");
                var evaluatorMetaOp   = MetaManager.Instance.GetMetaOperator(evaluatorMetaOpID);

                var addOpCmd = new AddOperatorCommand(compositionOp, evaluatorMetaOpID);
                addOpCmd.Do();
                var evaluatorOp = evaluatorMetaOp.GetOperatorInstance(addOpCmd.AddedInstanceID);

                var connection = new MetaConnection(testingOp.ID, testingOp.Outputs[0].ID,
                                                    evaluatorOp.ID, evaluatorOp.Inputs[0].ID);
                var addConnectionCmd = new InsertConnectionCommand(compositionOp.Definition, connection, 0);
                addConnectionCmd.Do();

                //configure the testsevaluator op and start testing
                var startTestsTriggerOpPart = evaluatorOp.Inputs[1];
                var filterOpPart            = evaluatorOp.Inputs[3];

                //we must create a down flank for the startTestsTrigger value to start the tests properly
                var updateStartTestsCmd = new UpdateOperatorPartValueFunctionCommand(startTestsTriggerOpPart, new Float(1.0f));
                updateStartTestsCmd.Do();
                var updateFilterCmd = new UpdateOperatorPartValueFunctionCommand(filterOpPart, new Text(filterPattern));
                updateFilterCmd.Do();
                evaluatorOp.Outputs[0].Eval(new OperatorPartContext());

                updateStartTestsCmd.Value = new Float(0.0f);
                updateStartTestsCmd.Do();
                var resultLog = evaluatorOp.Outputs[0].Eval(new OperatorPartContext()).Text;

                var result = new Tuple <bool, string>(resultLog.StartsWith(compositionOp.Definition.Name + " : passed"), resultLog);

                var deleteOperatorCmd = new DeleteOperatorsCommand(compositionOp, new List <Operator>()
                {
                    evaluatorOp
                });
                deleteOperatorCmd.Do();
                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to evaluate operator definition {0}: {1}", testingOp.Name, ex.ToString());
                return(new Tuple <bool, string>(false, ""));
            }
        }
예제 #3
0
        private void BuildTree(Operator fbxOp, List <ICommand> importFbxCommandList, Operator parent, OperatorPart input, Node node, double x, double y, string rootName = "")
        {
            Guid metaIDToAdd = GetIDOfNode(node);

            var newOpName = "";

            if (node is Group)
            {
                newOpName = "+ " + node.Name;
            }
            else if (node is Transform)
            {
                newOpName = "Transform";
            }
            else if (node is TransformMatrix)
            {
                newOpName = "TransformMatrix";
            }
            else if (node is Material)
            {
                newOpName = "Material";
            }
            else
            {
                newOpName = node.Name;
            }

            if (parent == null)
            {
                newOpName += rootName;
            }

            var addOperatorCommand = new AddOperatorCommand(fbxOp, metaIDToAdd, x, y, TreeWidth(node), true, newOpName);

            importFbxCommandList.Add(addOperatorCommand);
            addOperatorCommand.Do();

            var newOp = (from o in fbxOp.InternalOps
                         where addOperatorCommand.AddedInstanceID == o.ID
                         select o).Single();

            SetupValues(newOp, node);

            if (input != null)
            {
                var newConnection = new MetaConnection(newOp.ID, newOp.Outputs[0].ID,
                                                       parent == null ? Guid.Empty : parent.ID, input.ID);

                var firstOccuranceOfTargetOpID = fbxOp.Definition.Connections.FindIndex(con => (con.TargetOpID == newConnection.TargetOpID) &&
                                                                                        (con.TargetOpPartID == newConnection.TargetOpPartID));
                var lastOccuranceOfTargetOpID = fbxOp.Definition.Connections.FindLastIndex(con => (con.TargetOpID == newConnection.TargetOpID) &&
                                                                                           (con.TargetOpPartID == newConnection.TargetOpPartID));

                int index = 0;
                if (firstOccuranceOfTargetOpID > -1 && lastOccuranceOfTargetOpID > -1)
                {
                    index = lastOccuranceOfTargetOpID - firstOccuranceOfTargetOpID + 1;
                }

                var addConnectionCommand = new InsertConnectionCommand(fbxOp.Definition, newConnection, index);
                addConnectionCommand.Do();
                importFbxCommandList.Add(addConnectionCommand);
            }

            double childX = 0;

            foreach (Node child in node.Children)
            {
                BuildTree(fbxOp, importFbxCommandList, newOp, newOp.Inputs[0], child, x + childX, y + CompositionGraphView.GRID_SIZE);
                childX += TreeWidth(child);
            }
        }
예제 #4
0
        /**
         * This is an extremely rough stub for testing the TimeClip splitting functionality.
         * Need fixes for...
         * - duplicate connections of original op
         * - get rid of magic numbers of parameters
         * - fix potential problems when parameters are animated of connected
         * - move this to an Memento-Operation
         * - resolve direct dependencies to CompositionGraphView an it's members
         */
        public static void SplitSelectedTimeClips()
        {
            var nextSelection = new List <ISelectable>();
            var currentTime   = (float)App.Current.Model.GlobalTime;

            var selectedOpWidgets = new List <OperatorWidget>();

            foreach (var element in App.Current.MainWindow.CompositionView.CompositionGraphView.SelectionHandler.SelectedElements)
            {
                var opWidget = element as OperatorWidget;

                if (opWidget == null || !(opWidget.Operator.InternalParts[0].Func is ITimeClip))
                {
                    continue;
                }

                selectedOpWidgets.Add(opWidget);
            }

            var commandList = new List <ICommand>();

            foreach (var opWidget in selectedOpWidgets)
            {
                var op = opWidget.Operator;
                if (op == null)
                {
                    continue;
                }

                var startTime     = op.Inputs[HACK_TIMECLIP_STARTTIME_PARAM_INDEX].Eval(new OperatorPartContext()).Value;
                var endTime       = op.Inputs[HACK_TIMECLIP_ENDTIME_PARAM_INDEX].Eval(new OperatorPartContext()).Value;
                var sourceIn      = op.Inputs[HACK_TIMECLIP_SOURCEIN_PARAM_INDEX].Eval(new OperatorPartContext()).Value;
                var sourceOut     = op.Inputs[HACK_TIMECLIP_SOURCEOUT_PARAM_INDEX].Eval(new OperatorPartContext()).Value;
                var layerIndex    = op.Inputs[HACK_TIMECLIP_SOURCEOUT_LAYER_ID].Eval(new OperatorPartContext()).Value;
                var sourceCutTime = (currentTime - startTime) / (endTime - startTime) * (sourceOut - sourceIn) + sourceIn;

                if (!(startTime + MIN_SEGMENT_DURATION < currentTime) || !(currentTime < endTime - MIN_SEGMENT_DURATION))
                {
                    continue;
                }

                nextSelection.Add(opWidget);

                // Cut current op
                var currentOpSetEndtimeCommand = new UpdateOperatorPartValueFunctionCommand(op.Inputs[HACK_TIMECLIP_ENDTIME_PARAM_INDEX], new Core.Float(currentTime));
                currentOpSetEndtimeCommand.Do();

                var currentOpSetSourceOutCommand = new UpdateOperatorPartValueFunctionCommand(op.Inputs[HACK_TIMECLIP_SOURCEOUT_PARAM_INDEX], new Core.Float(sourceCutTime));
                currentOpSetSourceOutCommand.Do();

                // Intitial new op
                var compositionOp = App.Current.MainWindow.CompositionView.CompositionGraphView.CompositionOperator;

                var addNewOpCommand = new AddOperatorCommand(compositionOp, op.Definition.ID, op.Position.X + 10, op.Position.Y + 10);
                addNewOpCommand.Do();

                var newOpWidget = App.Current.MainWindow.CompositionView.CompositionGraphView.FindOperatorWidgetById(addNewOpCommand.AddedInstanceID);

                nextSelection.Add(newOpWidget);
                var newOp = newOpWidget.Operator;

                if (!String.IsNullOrEmpty(op.Name))
                {
                    newOp.Name = Utilities.GetDuplicatedTitle(op.Name);
                }

                var newOpSetStartTimeCommand = new UpdateOperatorPartValueFunctionCommand(newOp.Inputs[HACK_TIMECLIP_STARTTIME_PARAM_INDEX], new Core.Float(currentTime));
                newOpSetStartTimeCommand.Do();

                var newOpSetEndTimeCommand = new UpdateOperatorPartValueFunctionCommand(newOp.Inputs[HACK_TIMECLIP_ENDTIME_PARAM_INDEX], new Core.Float(endTime));
                newOpSetEndTimeCommand.Do();

                var newOpSetSourceInCommand = new UpdateOperatorPartValueFunctionCommand(newOp.Inputs[HACK_TIMECLIP_SOURCEIN_PARAM_INDEX], new Core.Float(sourceCutTime));
                newOpSetSourceInCommand.Do();

                var newOpSetSourceOutCommand = new UpdateOperatorPartValueFunctionCommand(newOp.Inputs[HACK_TIMECLIP_SOURCEOUT_PARAM_INDEX], new Core.Float(sourceOut));
                newOpSetSourceOutCommand.Do();

                var newOpSetLayerCommand = new UpdateOperatorPartValueFunctionCommand(newOp.Inputs[HACK_TIMECLIP_SOURCEOUT_LAYER_ID], new Float(layerIndex));
                newOpSetLayerCommand.Do();

                commandList.AddRange(new ICommand[]
                                     { currentOpSetEndtimeCommand,
                                       currentOpSetSourceOutCommand,
                                       addNewOpCommand,
                                       newOpSetStartTimeCommand,
                                       newOpSetEndTimeCommand,
                                       newOpSetSourceInCommand,
                                       newOpSetSourceOutCommand,
                                       newOpSetLayerCommand });
            }
            App.Current.UndoRedoStack.Add(new MacroCommand("Split time clip", commandList));

            if (nextSelection.Any())
            {
                App.Current.MainWindow.CompositionView.CompositionGraphView.SelectionHandler.SetElements(nextSelection);
            }
        }