示例#1
0
        public override int Mutate(NodeModel node)
        {
            string chars  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*(),./[];=-:<\\>?";
            Random random = new Random();
            string value  = new string(Enumerable.Repeat(chars, 10).Select(s => s[random.Next(s.Length)]).ToArray());

            DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
            {
                DynamoModel.UpdateModelValueCommand updateValue =
                    new DynamoModel.UpdateModelValueCommand(System.Guid.Empty, node.GUID, "Value", value);

                DynamoViewModel.ExecuteCommand(updateValue);
            }));

            return(1);
        }
示例#2
0
        private void SetArgumentLacing(object parameter)
        {
            var modelGuids = DynamoSelection.Instance.Selection.
                             OfType <NodeModel>().Select(n => n.GUID);

            if (!modelGuids.Any())
            {
                return;
            }

            var command = new DynamoModel.UpdateModelValueCommand(Guid.Empty,
                                                                  modelGuids, "ArgumentLacing", (string)parameter);

            DynamoViewModel.Model.ExecuteCommand(command);
            RaisePropertyChanged("SelectionArgumentLacing");
        }
示例#3
0
        private void ShowHideAllGeometryPreview(object parameter)
        {
            var modelGuids = DynamoSelection.Instance.Selection.
                             OfType <NodeModel>().Select(n => n.GUID);

            if (!modelGuids.Any())
            {
                return;
            }

            var command = new DynamoModel.UpdateModelValueCommand(Guid.Empty,
                                                                  modelGuids, "IsVisible", (string)parameter);

            DynamoViewModel.Model.ExecuteCommand(command);
            RefreshViewOnSelectionChange(this, null);
        }
        public void MAGN9434_DisablePreview()
        {
            OpenVisualizationTest("CreatePoint.dyn");
            Assert.AreEqual(1, BackgroundPreviewGeometry.TotalPoints());
            var codeBlockNode = ViewModel.CurrentSpace.NodeFromWorkspace <CodeBlockNodeModel>(Guid.Parse("7883d92a-ef8b-4e05-8c7d-46cfc627c994"));

            var command = new DynamoModel.UpdateModelValueCommand(Guid.Empty, codeBlockNode.GUID, "Code", "p2 = Point.ByCoordinates();");

            ViewModel.Model.ExecuteCommand(command);
            Assert.AreEqual(1, BackgroundPreviewGeometry.TotalPoints());

            var disableCommand = new DynamoModel.UpdateModelValueCommand(Guid.Empty, codeBlockNode.GUID, "IsVisible", "false");

            ViewModel.Model.ExecuteCommand(disableCommand);
            Assert.AreEqual(0, BackgroundPreviewGeometry.TotalPoints());
        }
示例#5
0
        public override int Mutate(NodeModel node)
        {
            Random Rand = new Random(1);

            this.DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
            {
                string code = ((CodeBlockNodeModel)node).Code;

                if (code.Length == 0)
                {
                    code = "";
                }

                string replacement;

                if (Rand.NextDouble() <= 0.5)
                {
                    //Strategy 1: Replacement with simplest minimal replacement

                    replacement = "1;";
                }
                else
                {
                    //Strategy 2: Noise injection

                    replacement = code;

                    while (Rand.NextDouble() > 0.5)
                    {
                        int locat         = Rand.Next(code.Length);
                        const string junk = "<>:L/;'\\/[=+-";

                        replacement = code.Substring(0, locat) + junk[Rand.Next(junk.Length)] +
                                      code.Substring(locat);
                    }
                }

                var cmd = new DynamoModel.UpdateModelValueCommand(node.GUID, "Code", replacement);

                this.DynamoViewModel.ExecuteCommand(cmd);
            }));

            //We've performed a single edit from the perspective of undo
            return(1);
        }
示例#6
0
        private void ToggleIsFrozen(object parameters)
        {
            var node = this.nodeLogic;

            if (node != null)
            {
                var oldFrozen = (!node.isFrozenExplicitly).ToString();
                var command   = new DynamoModel.UpdateModelValueCommand(Guid.Empty,
                                                                        new[] { node.GUID }, "IsFrozen", oldFrozen);

                DynamoViewModel.Model.ExecuteCommand(command);
            }
            else if (DynamoSelection.Instance.Selection.Any())
            {
                node          = DynamoSelection.Instance.Selection.Cast <NodeModel>().First();
                node.IsFrozen = !node.IsFrozen;
            }

            RaiseFrozenPropertyChanged();
        }
示例#7
0
        public override int Mutate(NodeModel node)
        {
            string   assemblyPath   = Assembly.GetExecutingAssembly().Location;
            string   assemblyDir    = Path.GetDirectoryName(assemblyPath);
            string   pathToNodesDll = assemblyDir + "\\nodes\\DSCoreNodesUI.dll";
            Assembly assembly       = Assembly.LoadFile(pathToNodesDll);

            Type type = assembly.GetType("Dynamo.Nodes.IntegerSlider");

            PropertyInfo propInfo    = type.GetProperty("Min");
            dynamic      propertyMin = propInfo.GetValue(node, null);

            propInfo = type.GetProperty("Max");
            dynamic propertyMax = propInfo.GetValue(node, null);

            int    min        = 0;
            int    max        = 0;
            int    returnCode = 0;
            Random rand       = new Random();

            if (Int32.TryParse(propertyMin.ToString(), out min) &&
                Int32.TryParse(propertyMax.ToString(), out max))
            {
                string value = (rand.Next(min, max)).ToString();

                DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                {
                    DynamoModel.UpdateModelValueCommand updateValue =
                        new DynamoModel.UpdateModelValueCommand(System.Guid.Empty, node.GUID, "Value", value);
                    DynamoViewModel.ExecuteCommand(updateValue);
                }));

                returnCode = 1;
            }

            return(returnCode);
        }
示例#8
0
        private static void TryOpenAndExecuteWorkspaceInCommandData(DynamoRevitCommandData commandData)
        {
            if (commandData.JournalData == null)
            {
                return;
            }

            if (commandData.JournalData.ContainsKey(JournalKeys.DynPathKey))
            {
                bool isAutomationMode = CheckJournalForKey(commandData, JournalKeys.AutomationModeKey);
                bool forceManualRun   = CheckJournalForKey(commandData, JournalKeys.ForceManualRunKey);

                bool useExistingWorkspace = false;
                if (CheckJournalForKey(commandData, JournalKeys.DynPathCheckExisting))
                {
                    WorkspaceModel currentWorkspace = revitDynamoModel.CurrentWorkspace;
                    if (currentWorkspace.FileName.Equals(commandData.JournalData[JournalKeys.DynPathKey],
                                                         StringComparison.OrdinalIgnoreCase))
                    {
                        useExistingWorkspace = true;
                    }
                }

                if (!useExistingWorkspace) //if use existing is false, open the specified workspace
                {
                    if (ModelState == RevitDynamoModelState.StartedUIless)
                    {
                        revitDynamoModel.OpenFileFromPath(commandData.JournalData[JournalKeys.DynPathKey], forceManualRun);
                    }
                    else
                    {
                        dynamoViewModel.OpenIfSavedCommand.Execute(new Dynamo.Models.DynamoModel.OpenFileCommand(commandData.JournalData[JournalKeys.DynPathKey], forceManualRun));
                        dynamoViewModel.ShowStartPage = false;
                    }
                }

                //If we have information about the nodes and their values we want to push those values after the file is opened.
                if (commandData.JournalData.ContainsKey(JournalKeys.ModelNodesInfo))
                {
                    try
                    {
                        var allNodesInfo = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >(commandData.JournalData[JournalKeys.ModelNodesInfo]);
                        if (allNodesInfo != null)
                        {
                            foreach (var nodeInfo in allNodesInfo)
                            {
                                if (nodeInfo.ContainsKey(JournalNodeKeys.Id) &&
                                    nodeInfo.ContainsKey(JournalNodeKeys.Name) &&
                                    nodeInfo.ContainsKey(JournalNodeKeys.Value))
                                {
                                    var modelCommand = new DynamoModel.UpdateModelValueCommand(nodeInfo[JournalNodeKeys.Id],
                                                                                               nodeInfo[JournalNodeKeys.Name],
                                                                                               nodeInfo[JournalNodeKeys.Value]);
                                    modelCommand.Execute(revitDynamoModel);
                                }
                            }
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Exception while trying to update nodes with new values");
                    }
                }

                //If we are in automation mode the model will run anyway (on the main thread
                //without the idle loop) regardless of the DynPathExecuteKey.
                if (!isAutomationMode && commandData.JournalData.ContainsKey(JournalKeys.DynPathExecuteKey))
                {
                    bool executePath = false;
                    bool.TryParse(commandData.JournalData[JournalKeys.DynPathExecuteKey], out executePath);
                    if (executePath)
                    {
                        HomeWorkspaceModel modelToRun = revitDynamoModel.CurrentWorkspace as HomeWorkspaceModel;
                        if (modelToRun != null)
                        {
                            modelToRun.Run();
                            return;
                        }
                    }
                }
            }
        }
示例#9
0
        public void TurnUpstreamPreviewOffAffectsOnlyRelevantUpstreamNodes()
        {
            var model = ViewModel.Model;

            var testDirectory = GetTestDirectory(ExecutingDirectory);
            var openPath      = Path.Combine(testDirectory, @"core\visualization\PreviewUpstream.dyn");

            ViewModel.OpenCommand.Execute(openPath);

            var workspace = ViewModel.Model.CurrentWorkspace as HomeWorkspaceModel;

            workspace.RunSettings.RunType = RunType.Automatic;

            // Identifiers for all nodes in the workspace.
            var nodeIds = new[]
            {
                Guid.Parse("5c92328a-b412-456a-9c9f-83581a60b865"), // finalPoints
                Guid.Parse("513c2342-88bf-4dc1-a291-66ee964a8093"), // line0
                Guid.Parse("1dd35280-d93b-41b6-9f6d-ae30883e32bd"), // line1
                Guid.Parse("0750d269-26f3-47d7-bb25-79c762a540ff"), // point0
                Guid.Parse("33b03fa4-50e7-4d08-a5d8-ae7f168c2624"), // point1
                Guid.Parse("fa226a63-1a31-4f13-8b93-1286dac2c695"), // point2
                Guid.Parse("27870e68-907f-48d4-9f02-7872bb389af8"), // arrayCodeBlock
                Guid.Parse("e7b0f340-a0bc-46b2-a05d-7dd71c72e27c"), // originCodeBlock
            };

            // Ensure we do have all the nodes we expected here.
            var nodes = nodeIds.Select(workspace.NodeFromWorkspace).ToList();

            Assert.IsFalse(nodes.Any(n => n == null)); // Nothing should be null.

            // All nodes should have their visibility set to true for a start.
            Assert.IsTrue(nodes.All(n => n.IsVisible));
            Assert.IsTrue(nodes.All(n => n.IsUpstreamVisible));

            // Ensure that visulations match our expectations
            Assert.AreEqual(5, BackgroundPreview.Points.Positions.Count);
            Assert.AreEqual(4, BackgroundPreview.Lines.Positions.Count);

            // Now turn off the upstream preview for "FinalPoints"...
            var setUpstreamInvisible = new DynamoModel.UpdateModelValueCommand(
                Guid.Empty, nodeIds[0], "IsUpstreamVisible", "false");

            model.ExecuteCommand(setUpstreamInvisible);

            // Ensure setting upstream visibility also sets node's visibility.
            Assert.IsTrue(nodes.Select(n => n.IsVisible).SequenceEqual(new[]
            {
                true, false, true, false, false, true, false, false
            }));

            // Ensure setting upstream visibility does not alter other settings.
            Assert.IsTrue(nodes.Select(n => n.IsUpstreamVisible).SequenceEqual(new[]
            {
                false, true, true, true, true, true, true, true
            }));

            // Should be left with just FinalPoints, Line1 and Point2.
            Assert.AreEqual(3, BackgroundPreview.Points.Positions.Count);
            Assert.AreEqual(2, BackgroundPreview.Lines.Positions.Count);

            // Turn the upstream preview back on for "FinalPoints"...
            var setUpstreamVisible = new DynamoModel.UpdateModelValueCommand(
                Guid.Empty, nodeIds[0], "IsUpstreamVisible", "true");

            model.ExecuteCommand(setUpstreamVisible);

            // Ensure all nodes' visibility values are updated to true.
            Assert.IsTrue(nodes.All(n => n.IsVisible));
            Assert.IsTrue(nodes.All(n => n.IsUpstreamVisible));

            // Ensure we get back those hidden geometries.
            Assert.AreEqual(5, BackgroundPreview.Points.Positions.Count);
            Assert.AreEqual(4, BackgroundPreview.Lines.Positions.Count);
        }