Пример #1
0
        private void GroupOpenSliceElements(SDTreeNode node)
        {
            if (node.IsSetupSlice && (!node.IsSetupSliceForExtension))
            {
                List <SDTreeNode> nodesToGroup = new List <SDTreeNode>();

                foreach (SDTreeNode childNode in node.Children)
                {
                    if (!childNode.IsSlice)
                    {
                        nodesToGroup.Add(childNode);
                    }
                }

                if (node.Element.slicing.rules.value == SlicingRuleslist.open)
                {
                    ElementDefinition openSliceElement = new ElementDefinition();
                    openSliceElement.path       = new @string();
                    openSliceElement.path.value = node.Element.path.value + "#n";
                    openSliceElement.name       = new @string();
                    // openSliceElement.name.value = "open";
                    // also fix cardinalities
                    openSliceElement.type = node.GetElementDefinitionType();
                    SDTreeNode openSlice = new SDTreeNode(openSliceElement);
                    openSlice.AddChildren(nodesToGroup.ToArray());
                    node.AddChild(openSlice);
                }
                else if (node.Element.slicing.rules.value == SlicingRuleslist.openAtEnd)
                {
                    ElementDefinition openAtEndSliceElement = new ElementDefinition();
                    openAtEndSliceElement.path       = new @string();
                    openAtEndSliceElement.path.value = node.Element.path.value + "#n";
                    openAtEndSliceElement.name       = new @string();
                    // openAtEndSliceElement.name.value = "openAtEnd";
                    // also fix cardinalities
                    openAtEndSliceElement.type = node.GetElementDefinitionType();
                    SDTreeNode openAtEndSlice = new SDTreeNode(openAtEndSliceElement);
                    openAtEndSlice.AddChildren(nodesToGroup.ToArray());
                    node.AddChild(openAtEndSlice);
                }
                else
                {
                    foreach (SDTreeNode childNodeToRemove in nodesToGroup)
                    {
                        node.RemoveChild(childNodeToRemove);
                    }
                }
            }
        }
Пример #2
0
        private SDTreeNode GenerateTree(ElementDefinition[] elements)
        {
            ElementDefinition rootElement = elements.GetRootElement();

            if (rootElement == null)
            {
                throw new Exception("Could not find root element");
            }

            SDTreeNode rootNode = new SDTreeNode(rootElement);

            Stack <SDTreeNode> stack = new Stack <SDTreeNode>();

            stack.Push(rootNode);

            while (stack.Any())
            {
                SDTreeNode node = stack.Pop();

                foreach (ElementDefinition element in elements.GetChildren(node.Element))
                {
                    SDTreeNode childNode = new SDTreeNode(element);
                    node.AddChild(childNode);
                    stack.Push(childNode);
                }
            }

            return(rootNode);
        }