Esempio n. 1
0
        protected override void CaribouSolveInstance(IGH_DataAccess da)
        {
            logger.Reset();

            #region Input Parsing

            da.GetDataTree(0, out GH_Structure <IGH_Goo> itemsTree);
            if (itemsTree.Branches[0][0] as IGH_GeometricGoo == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error,
                                       "It looks like you have provided a non-geometry input to the Items parameter. This input should connect to the Nodes, Ways, or Buildings outputs produced by the Extract components.");
                return;
            }

            ProvidedNodes = itemsTree.Branches[0][0] is GH_Point;

            da.GetDataTree(1, out GH_Structure <GH_String> tagsTree);
            if (tagsTree.Branches[0].Count >= 3)
            {
                if (tagsTree.Branches[0][2].ToString().Contains(" found"))
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error,
                                           "It looks like you have provided a Report parameter output as the Tag parameter input. Use a Tag parameter output instead.");
                    return;
                }
            }

            if (itemsTree.PathCount != tagsTree.PathCount)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning,
                                       "The path counts of the Items and Tags do not match - check these are coming from the same component.");
            }
            else if (itemsTree.Branches.Count != tagsTree.Branches.Count)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning,
                                       "The branch structure of the Items and Tags do not match - check these are coming from the same component.");
            }

            logger.NoteTiming("Input capture");
            #endregion

            #region Form Data Setup
            // Setup form-presentable items for tags provided and parsed into OSM objects
            var requests = new OSMListWithPaths(tagsTree); // Parse provided tree into OSM objects and a dictionary of paths per object
            logger.NoteTiming("Tag parsing");

            // If tags have changed we write out current state so we can try to preserve it in the new tags list
            if (this.PreviousTagsDescription != null)
            {
                if (tagsTree.DataDescription(false, false) != this.PreviousTagsDescription)
                {
                    this.storedSelectionState = GetStateKeys();
                }
            }

            // If loading from scratch, or if the tags have changed
            if (this.storedSelectionState != null)
            {
                var availableOSMs = GetSelectableTagsFromInputTree(requests);
                this.selectableOSMs = TreeGridUtilities.SetSelectionsFromStoredState(
                    availableOSMs, this.storedSelectionState);
                this.storedSelectionState = null; // Reset flag
            }
            else
            {
                this.selectableOSMs = GetSelectableTagsFromInputTree(requests);
            }

            this.PreviousTagsDescription  = tagsTree.DataDescription(false, false); // Track tag input identity
            this.selectionStateSerialized = GetSelectedKeyValuesFromForm();
            logger.NoteTiming("State loading/making");
            #endregion

            #region Outputting
            // Match geometry paths to selected filters
            var geometryOutput = new GH_Structure <IGH_Goo>();
            var tagOutput      = new GH_Structure <GH_String>();
            // Setup tracking dictionary for the report tree output
            var foundItemCountsForResult = new Dictionary <OSMTag, int>();

            for (int i = 0; i < this.selectionStateSerialized.Count; i++)
            {
                string itemKeyValue = this.selectionStateSerialized[i];
                OSMTag osmItem      = new OSMTag(itemKeyValue);

                if (!requests.pathsPerItem.ContainsKey(osmItem))
                {
                    continue;
                }

                foundItemCountsForResult[osmItem] = 0;
                // Match keyvalues to OSMListwithpaths
                for (int j = 0; j < requests.pathsPerItem[osmItem].Count; j++)
                {
                    GH_Path inputPath = requests.pathsPerItem[osmItem][j];

                    var geometryItemsForPath = itemsTree.get_Branch(inputPath);
                    var tagItemsForPath      = tagsTree.get_Branch(inputPath);
                    if (geometryItemsForPath == null)
                    {
                        continue; // No provided geometry path for that OSM item
                    }
                    foundItemCountsForResult[osmItem] += 1;
                    for (int k = 0; k < geometryItemsForPath.Count; k++)
                    {
                        GH_Path outputPathFor = new GH_Path(i, j);
                        geometryOutput.EnsurePath(outputPathFor); // Need to ensure even an empty path exists to enable data matching
                        tagOutput.EnsurePath(outputPathFor);      // Need to ensure even an empty path exists to enable data matching

                        geometryOutput.Append(geometryItemsForPath[k] as IGH_Goo, outputPathFor);
                        foreach (GH_String tag in tagItemsForPath)
                        {
                            tagOutput.Append(tag, outputPathFor);
                        }
                    }
                }
            }
            logger.NoteTiming("Geometry matching");

            var requestReport = TreeFormatters.MakeReportForRequests(foundItemCountsForResult);
            logger.NoteTiming("Tree formatting");

            this.OutputMessageBelowComponent();

            da.SetDataTree(0, geometryOutput);
            da.SetDataTree(1, tagOutput);
            da.SetDataTree(2, requestReport);
            logger.NoteTiming("Data tree setting");
            #endregion
        }
Esempio n. 2
0
 public override void GetTreeForComponentType()
 {
     this.wayOutputs = TreeFormatters.MakeTreeForWays(this.foundWays);
 }
Esempio n. 3
0
 public override void GetTreeForComponentType()
 {
     this.nodeOutputs = TreeFormatters.MakeTreeForNodes(this.foundNodes);
 }
 public override void GetTreeForComponentType()
 {
     this.buildingOutputs = TreeFormatters.MakeTreeForBuildings(this.foundBuildings);
 }