コード例 #1
0
ファイル: NoteModel.cs プロジェクト: ankushraizada/Dynamo
        protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
        {
            string name = updateValueParams.PropertyName;
            string value = updateValueParams.PropertyValue;

            if (name != "Text") 
                return base.UpdateValueCore(updateValueParams);
            
            Text = value;
            return true;
        }        
コード例 #2
0
ファイル: RevitDropDown.cs プロジェクト: Jamesbdsas/DynamoDS
        protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
        {
            string name  = updateValueParams.PropertyName;
            string value = updateValueParams.PropertyValue;

            if (name == "Value" && value != null)
            {
                // Un-exception: Find selection by display name, just like the base class does!
                SelectedIndex = ParseSelectedIndexImpl(value, Items);

                if (SelectedIndex < 0)
                {
                    Warning(Dynamo.Properties.Resources.NothingIsSelectedWarning);
                }
                return(true); // UpdateValueCore handled.
            }

            return(base.UpdateValueCore(updateValueParams));
        }
コード例 #3
0
        public void UpdateValueCoreTest()
        {
            string            propName;
            string            propValue;
            UpdateValueParams parameters;

            //FontSize property update case
            propName  = "FontSize";
            propValue = "15";

            parameters = new UpdateValueParams(propName, propValue);
            annotationModel.UpdateValue(parameters);

            var expectedCase1 = Convert.ToDouble(propValue);
            var resultCase1   = annotationModel.FontSize;

            Assert.AreEqual(expectedCase1, resultCase1);

            //Background property update case
            propName  = "Background";
            propValue = "#ff7bac";

            parameters = new UpdateValueParams(propName, propValue);
            annotationModel.UpdateValue(parameters);

            var expectedCase2 = propValue;
            var resultCase2   = annotationModel.Background;

            Assert.AreEqual(expectedCase2, resultCase2);

            //TextBlockText property update case
            propName  = "TextBlockText";
            propValue = "Test text";

            parameters = new UpdateValueParams(propName, propValue);
            annotationModel.UpdateValue(parameters);

            var expectedCase3 = propValue;
            var resultCase3   = annotationModel.AnnotationText;

            Assert.AreEqual(expectedCase3, resultCase3);
        }
コード例 #4
0
        public void SliderMaxValue()
        {
            var sliderNode = new DoubleSlider()
            {
                Value = 500
            };
            var updateValueParams = new UpdateValueParams("Value", "1000");

            sliderNode.UpdateValue(updateValueParams);

            Assert.AreEqual(
                1000,
                sliderNode.Max);

            updateValueParams = new UpdateValueParams("Value", "-1");
            sliderNode.UpdateValue(updateValueParams);

            Assert.AreEqual(
                -1,
                sliderNode.Min);
        }
コード例 #5
0
        public void DeserializeCoreTest()
        {
            var slider = new IntegerSlider64Bit();
            var param  = new UpdateValueParams("Min", "10");

            slider.UpdateValue(param);

            //Serializes slider into xml
            var testDocument = new XmlDocument();

            testDocument.LoadXml("<ElementTag/>");
            XmlElement xmlElement = slider.Serialize(new XmlDocument(), SaveContext.None);

            //Resets slider to constructor default
            slider = new IntegerSlider64Bit();
            Assert.AreNotEqual(10, slider.Min);

            //Recovers slider from xml
            slider.Deserialize(xmlElement, SaveContext.None);
            Assert.AreEqual(10, slider.Min);
        }
コード例 #6
0
        /// <summary>
        /// Main method of our tool that unfancifies a graph.
        /// Actions depend on settings in UI.
        /// </summary>
        public void UnfancifyGraph()
        {
            // Identify all groups to keep/ungroup
            if (UngroupAll)
            {
                // Cycle through all groups in the graph
                foreach (var anno in viewModel.CurrentSpaceViewModel.Annotations)
                {
                    viewModel.AddToSelectionCommand.Execute(anno.AnnotationModel);
                }
                // Ungroup all obsolete groups
                viewModel.UngroupAnnotationCommand.Execute(null);
            }

            // Process nodes before we call node to code
            // We need this part to circumnavigate two minor node-to-code bugs
            // So this is actually a good example for how you can fix Dynamo issues for yourself without having to touch DynamoCore code
            foreach (var node in viewModel.Model.CurrentWorkspace.Nodes)
            {
                // Pre-processing of string input nodes only
                // Temporary fix for https://github.com/DynamoDS/Dynamo/issues/9117 (Escape backslashes in string nodes)
                // Temporary fix for https://github.com/DynamoDS/Dynamo/issues/9120 (Escape double quotes in string nodes)
                if (node.GetType() == typeof(StringInput))
                {
                    // Cast NodeModel to StringInput
                    var inputNode = (StringInput)node;
                    // Get the current value of the input node
                    var nodeVal = inputNode.Value;
                    // Escape backslahes and double quotes
                    nodeVal = nodeVal.Replace("\\", "\\\\").Replace("\"", "\\\"");
                    // Update the input node's value
                    var updateVal = new UpdateValueParams("Value", nodeVal);
                    node.UpdateValue(updateVal);
                }
                // Add each node to the current selection
                viewModel.AddToSelectionCommand.Execute(node);
            }
            // Call node to code
            viewModel.CurrentSpaceViewModel.NodeToCodeCommand.Execute(null);
        }
コード例 #7
0
        protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
        {
            string name  = updateValueParams.PropertyName;
            string value = updateValueParams.PropertyValue;

            if (name == "Value" && value != null)
            {
                selectedIndex = ParseSelectedIndex(value, Items);
                if (selectedIndex < 0)
                {
                    Warning(Dynamo.Properties.Resources.NothingIsSelectedWarning);
                    selectedString = String.Empty;
                }
                else
                {
                    selectedString = selectedIndex > Items.Count - 1 ? String.Empty : GetSelectedStringFromItem(Items.ElementAt(selectedIndex));
                }
                return(true); // UpdateValueCore handled.
            }

            return(base.UpdateValueCore(updateValueParams));
        }
コード例 #8
0
        protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
        {
            string name  = updateValueParams.PropertyName;
            string value = updateValueParams.PropertyValue;

            switch (name)
            {
            case "FontSize":
                FontSize = Convert.ToDouble(value);
                break;

            case "Background":
                Background = value;
                break;

            case "TextBlockText":
                AnnotationText = value;
                break;
            }

            return(base.UpdateValueCore(updateValueParams));
        }
コード例 #9
0
        public void UpdateValueCoreTest()
        {
            //Sets property to be updated
            testNode.Name = "Starting Name";

            //Updates Name property with new value
            var  updatedValue = new UpdateValueParams("Name", "UpdatedName");
            bool response     = testNode.UpdateValueCore(updatedValue);

            Assert.IsTrue(response);
            Assert.AreEqual(updatedValue.PropertyValue, testNode.Name);

            //Case: valid update "Value" property
            //Sets selectedIndex
            testNode.SelectedIndex = 0;

            ////Updates selectedIndex value
            updatedValue = new UpdateValueParams("Value", "1");
            response     = testNode.UpdateValueCore(updatedValue);
            Assert.IsTrue(response);
            Assert.AreEqual(1, testNode.SelectedIndex);
        }
コード例 #10
0
        protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
        {
            switch (updateValueParams.PropertyName)
            {
            case "Values":
                // Here we expect a string that represents an array of [ metric, from, to ] values which are separated by ";"
                // For example "Length;Meters;Feet"
                var vals = updateValueParams.PropertyValue.Split(';');
                ConversionMetricUnit metric;
                ConversionUnit       from, to;
                if (vals.Length == 3 && Enum.TryParse(vals[0], out metric) &&
                    Enum.TryParse(vals[1], out from) && Enum.TryParse(vals[2], out to))
                {
                    SelectedMetricConversion = metric;
                    SelectedFromConversion   = from;
                    SelectedToConversion     = to;
                }

                return(true);
            }

            return(base.UpdateValueCore(updateValueParams));
        }
コード例 #11
0
ファイル: CodeBlockNode.cs プロジェクト: DynamoDS/Dynamo
        protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
        {
            string name = updateValueParams.PropertyName;
            string value = updateValueParams.PropertyValue;
            ElementResolver workspaceElementResolver = updateValueParams.ElementResolver;

            if (name != "Code")
                return base.UpdateValueCore(updateValueParams);

            value = CodeBlockUtils.FormatUserText(value);

            if (!value.Equals(Code))
               SetCodeContent(value, workspaceElementResolver);

            return true;
        }
コード例 #12
0
ファイル: CodeBlockNode.cs プロジェクト: mikeyforrest/Dynamo
        protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
        {
            string name = updateValueParams.PropertyName;
            string value = updateValueParams.PropertyValue;
            ElementResolver workspaceElementResolver = updateValueParams.ElementResolver;

            if (name != "Code") 
                return base.UpdateValueCore(updateValueParams);

            value = CodeBlockUtils.FormatUserText(value);

            //Since an empty Code Block Node should not exist, this checks for such instances.
            // If an empty Code Block Node is found, it is deleted. Since the creation and deletion of 
            // an empty Code Block Node should not be recorded, this method also checks and removes
            // any unwanted recordings
            if (value == "")
            {
                Code = "";
            }
            else
            {
                if (!value.Equals(Code))
                    SetCodeContent(value, workspaceElementResolver);
            }
            return true;
        }
コード例 #13
0
ファイル: SliderTests.cs プロジェクト: ankushraizada/Dynamo
        public void SliderMaxResetsToIntMax()
        {
            var slider = new IntegerSlider();
            Assert.NotNull(slider);

            var param = new UpdateValueParams("Max", "2147483648");
            slider.UpdateValue(param);

            Assert.AreEqual(slider.Max, Int32.MaxValue);
        }
コード例 #14
0
        /// <summary>
        /// Main method of our tool that unfancifies a graph.
        /// Actions depend on settings in UI.
        /// </summary>
        public void UnfancifyGraph()
        {
            // Create a list for storing guids of groups, nodes and text notes that we want to keep
            var stuffToKeep = new List <string>();

            // Identify all groups to keep/ungroup
            if (UngroupAll)
            {
                // Make sure that no groups are currently selected
                GeneralUtils.ClearSelection();
                // Create an allowedlist of prefixes for group titles from what was entered by the user in the UI
                var groupIgnoreList = IgnoreGroupPrefixes.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                // Cycle through all groups in the graph
                foreach (var anno in viewModel.CurrentSpaceViewModel.Annotations)
                {
                    // Cycle through the allowedlist
                    foreach (var ignoreTerm in groupIgnoreList)
                    {
                        // Identify keepers (group and its contents)
                        if (anno.AnnotationText.StartsWith(ignoreTerm) && !stuffToKeep.Contains(anno.AnnotationModel.GUID.ToString()))
                        {
                            stuffToKeep.Add(anno.AnnotationModel.GUID.ToString());
                            // Identify all nodes and text notes within those groups
                            foreach (var element in anno.Nodes)
                            {
                                stuffToKeep.Add(element.GUID.ToString());
                            }
                        }
                    }
                    // Add all obsolete groups to selection
                    if (!stuffToKeep.Contains(anno.AnnotationModel.GUID.ToString()))
                    {
                        viewModel.AddToSelectionCommand.Execute(anno.AnnotationModel);
                    }
                }
                // Ungroup all obsolete groups
                viewModel.UngroupAnnotationCommand.Execute(null);
            }

            // Process nodes before we call node to code
            // Make sure that no nodes are currently selected
            GeneralUtils.ClearSelection();
            // We need this part to circumnavigate two minor node-to-code bugs
            // So this is actually a good example for how you can fix Dynamo issues for yourself without having to touch DynamoCore code
            foreach (var node in viewModel.Model.CurrentWorkspace.Nodes)
            {
                // We're not interested in keepers (i.e. nodes that will not be run through node-to-code)
                if (!stuffToKeep.Contains(node.GUID.ToString()))
                {
                    // Pre-processing of string input nodes only
                    // Temporary fix for https://github.com/DynamoDS/Dynamo/issues/9117 (Escape backslashes in string nodes)
                    // Temporary fix for https://github.com/DynamoDS/Dynamo/issues/9120 (Escape double quotes in string nodes)
                    if (node.GetType() == typeof(StringInput))
                    {
                        // Cast NodeModel to StringInput
                        var inputNode = (StringInput)node;
                        // Get the current value of the input node
                        var nodeVal = inputNode.Value;
                        // Escape backslahes and double quotes
                        nodeVal = nodeVal.Replace("\\", "\\\\").Replace("\"", "\\\"");
                        // Update the input node's value
                        var updateVal = new UpdateValueParams("Value", nodeVal);
                        node.UpdateValue(updateVal);
                    }
                    // Add each node to the current selection
                    viewModel.AddToSelectionCommand.Execute(node);
                }
            }
            // Call node to code
            viewModel.CurrentSpaceViewModel.NodeToCodeCommand.Execute(null);

            // Auto layout
            if (DoAutoLayout)
            {
                // Make sure nothing is selected
                GeneralUtils.ClearSelection();
                // Here we'll need to call the auto-layout via Dynamo's Dispatcher
                // Otherwise the auto layout command will not yet be aware of the size
                // of the code blocks generated by node to code and our graph will look less pretty.
                dynWindow.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                {
                    viewModel.CurrentSpaceViewModel.GraphAutoLayoutCommand.Execute(null);
                }));
            }
        }
コード例 #15
0
 public bool UpdateValueCore(UpdateValueParams updateValueParams) =>
 base.UpdateValueCore(updateValueParams);
コード例 #16
0
ファイル: SliderTests.cs プロジェクト: ankushraizada/Dynamo
        public void SliderMinResetsToIntMin()
        {
            var slider = new IntegerSlider();
            Assert.NotNull(slider);

            var param = new UpdateValueParams("Min", "-2147483649");
            slider.UpdateValue(param);

            Assert.AreEqual(slider.Min, Int32.MinValue);
        }
コード例 #17
0
 public bool UpdateValueCoreBool(UpdateValueParams uvParams) =>
 UpdateValueCore(uvParams);
コード例 #18
0
ファイル: PythonNode.cs プロジェクト: ankushraizada/Dynamo
        protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
        {
            string name = updateValueParams.PropertyName;
            string value = updateValueParams.PropertyValue;

            if (name == "ScriptContent")
            {
                script = value;
                return true;
            }

            return base.UpdateValueCore(updateValueParams);
        }
コード例 #19
0
ファイル: SliderTests.cs プロジェクト: ankushraizada/Dynamo
        public void SliderCanNotBeSetGreaterThanMaxIntValue()
        {
            var slider = new IntegerSlider();
            Assert.NotNull(slider);

            var param = new UpdateValueParams("Value", "2147483648");
            slider.UpdateValue(param);

            Assert.AreEqual(slider.Value, Int32.MaxValue);
        }
コード例 #20
0
        public void UnfancifyGraph()
        {
            // Create a list for storing guids of groups, nodes and text notes that we want to keep
            var stuffToKeep = new List <string>();

            GeneralUtils.ClearSelection();
            // Identify all groups to keep/ungroup
            if (ungroupAll)
            {
                var groupIgnoreList = ignoreGroupPrefixes.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var anno in viewModel.CurrentSpaceViewModel.Annotations)
                {
                    foreach (var ignoreTerm in groupIgnoreList)
                    {
                        // Identify keepers
                        if (anno.AnnotationText.StartsWith(ignoreTerm) && !stuffToKeep.Contains(anno.AnnotationModel.GUID.ToString()))
                        {
                            stuffToKeep.Add(anno.AnnotationModel.GUID.ToString());
                            // Identify all nodes and text notes within those groups
                            foreach (var element in anno.SelectedModels)
                            {
                                stuffToKeep.Add(element.GUID.ToString());
                            }
                        }
                    }
                    // Add all obsolete groups to selection
                    if (!stuffToKeep.Contains(anno.AnnotationModel.GUID.ToString()))
                    {
                        viewModel.AddToSelectionCommand.Execute(anno.AnnotationModel);
                    }
                }
                // Ungroup all obsolete groups
                viewModel.UngroupAnnotationCommand.Execute(null);
            }
            // Identify all text notes to keep/delete
            if (deleteTextNotes)
            {
                var textNoteIgnoreList = ignoreTextNotePrefixes.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var note in viewModel.Model.CurrentWorkspace.Notes)
                {
                    foreach (var ignoreTerm in textNoteIgnoreList)
                    {
                        // Identify keepers
                        if (note.Text.StartsWith(ignoreTerm) && !stuffToKeep.Contains(note.GUID.ToString()))
                        {
                            stuffToKeep.Add(note.GUID.ToString());
                        }
                    }
                    // Add all obsolete text notes to selection
                    if (!stuffToKeep.Contains(note.GUID.ToString()))
                    {
                        viewModel.AddToSelectionCommand.Execute(note);
                    }
                }
                // Delete all obsolete text notes
                viewModel.DeleteCommand.Execute(null);
            }
            // Process nodes
            foreach (var node in viewModel.Model.CurrentWorkspace.Nodes)
            {
                // Select all obsolete nodes and pre-process string nodes
                if (!stuffToKeep.Contains(node.GUID.ToString()))
                {
                    // Pre-Processing
                    // Temporary fix for https://github.com/DynamoDS/Dynamo/issues/9117 (Escape backslashes in string nodes)
                    // Temporary fix for https://github.com/DynamoDS/Dynamo/issues/9120 (Escape double quotes in string nodes)
                    if (node.GetType() == typeof(StringInput))
                    {
                        StringInput inputNode = (StringInput)node;
                        string      nodeVal   = inputNode.Value;
                        nodeVal = nodeVal.Replace("\\", "\\\\").Replace("\"", "\\\"");
                        var updateVal = new UpdateValueParams("Value", nodeVal);
                        node.UpdateValue(updateVal);
                    }
                    viewModel.AddToSelectionCommand.Execute(node);
                }
            }
            // Node to code
            viewModel.CurrentSpaceViewModel.NodeToCodeCommand.Execute(null);
            GeneralUtils.ClearSelection();
            // Process remaining nodes
            var nodesToDelete = new List <NodeModel>();

            if (disableGeometryPreview || disablePreviewBubbles || deleteWatchNodes)
            {
                foreach (var node in viewModel.CurrentSpaceViewModel.Nodes)
                {
                    // Turn off geometry preview
                    if (disableGeometryPreview)
                    {
                        if (node.IsVisible)
                        {
                            node.ToggleIsVisibleCommand.Execute(null);
                        }
                    }
                    // Turn off preview bubbles (only works after file has been saved and re-opened)
                    if (disablePreviewBubbles)
                    {
                        if (node.PreviewPinned)
                        {
                            node.PreviewPinned = false;
                        }
                    }
                    // Identify Watch nodes
                    if (deleteWatchNodes)
                    {
                        string nodeType = node.NodeModel.GetType().ToString();
                        if (nodeType == "CoreNodeModels.Watch" || nodeType == "Watch3DNodeModels.Watch3D" || nodeType == "CoreNodeModels.WatchImageCore")
                        {
                            if (node.NodeModel.OutputNodes.Count == 0)
                            {
                                viewModel.AddToSelectionCommand.Execute(node.NodeModel);
                            }
                        }
                    }
                }
            }
            // Delete Watch nodes
            if (deleteWatchNodes)
            {
                viewModel.DeleteCommand.Execute(null);
            }
            // Auto layout
            dynWindow.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
            {
                viewModel.CurrentSpaceViewModel.GraphAutoLayoutCommand.Execute(null);
            }));
        }
コード例 #21
0
ファイル: SliderTests.cs プロジェクト: ankushraizada/Dynamo
        public void  SliderCanNotBeSetLessThanMinIntValue()
        {
            var slider = new IntegerSlider();
            Assert.NotNull(slider);

            var param = new UpdateValueParams("Value", "-2147483649");
            slider.UpdateValue(param);

            Assert.AreEqual(slider.Value, Int32.MinValue);
        }
コード例 #22
0
ファイル: AnnotationModel.cs プロジェクト: sh4nnongoh/Dynamo
        protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
        {
            string name = updateValueParams.PropertyName;
            string value = updateValueParams.PropertyValue;

            switch (name)
            {
                case "FontSize":
                    FontSize = Convert.ToDouble(value);
                    break;
                case "Background":
                    Background = value;
                    break;  
                case "TextBlockText":
                    AnnotationText = value;
                    break;
            }

            return base.UpdateValueCore(updateValueParams);
        }