Пример #1
0
        /// <summary>
        /// Recursive function to populate the tree.
        /// </summary>
        /// <param name="tv">The treeView control</param>
        /// <param name="entList">The entity list</param>
        /// <param name="blocks">The block collection</param>
        /// <param name="parentNode">The parent node. Can be null for root level nodes.</param>
        public static void PopulateTree(TreeView tv, List <Entity> entList, BlockDictionary blocks, TreeNode parentNode = null)
        {
            TreeNodeCollection nodes;

            if (parentNode == null)
            {
                tv.Nodes.Clear();
                nodes = tv.Nodes;
            }
            else
            {
                nodes = parentNode.Nodes;
            }

            for (int i = 0; i < entList.Count; i++)
            {
                IfcEntity ifcEntity = (IfcEntity)entList[i];

                string keyWord, name;

                ifcEntity.Identification.TryGetValue("KeyWord", out keyWord);

                ifcEntity.Identification.TryGetValue("Name", out name);

                TreeNode keyWordNode = null;

                foreach (TreeNode node in nodes)
                {
                    if (node.Text.Equals(keyWord))
                    {
                        keyWordNode = node;
                        break;
                    }
                }
                if (keyWordNode == null)
                {
                    keyWordNode                    = new TreeNode(keyWord);
                    keyWordNode.ImageIndex         = 1;
                    keyWordNode.SelectedImageIndex = 1;
                    nodes.Add(keyWordNode);
                }
                TreeNode nameNode = new TreeNode(name);

                nameNode.Tag = entList[i];

                nameNode.ImageIndex = 1;

                nameNode.SelectedImageIndex = 1;

                keyWordNode.Nodes.Add(nameNode);

                //if (ent is BlockReference)
                //{
                //    Block child;
                //    string blockName = ((BlockReference)ent).BlockName;

                //    if (blocks.TryGetValue(blockName, out child))
                //    {
                //        TreeNode parentTn = new TreeNode(GetNodeName(blockName, i));
                //        parentTn.Tag = ent;
                //        parentTn.ImageIndex = 0;
                //        parentTn.SelectedImageIndex = 0;

                //        nodes.Add(parentTn);
                //        PopulateTree(tv, child.Entities, blocks, parentTn);
                //    }
                //}
                //else
            }
        }
Пример #2
0
        public static void loadProperties(IfcEntity ifcEntity, IfcProduct ifcProduct)
        {
            ifcEntity.ColorMethod = colorMethodType.byEntity;

            #region Identification
            ifcEntity.Identification.Add("Model", "nome del file");
            ifcEntity.Identification.Add("Name", ifcProduct.Name);
            ifcEntity.Identification.Add("Type", ifcProduct.ObjectType);
            ifcEntity.Identification.Add("GUID", ifcProduct.GlobalId);
            ifcEntity.Identification.Add("KeyWord", ifcProduct.KeyWord);
            #endregion

            if (ifcProduct is IfcElement)
            {
                IfcElement ifcElement = (IfcElement)ifcProduct;

                #region Material
                if (ifcElement.MaterialSelect != null)
                {
                    if (ifcElement.MaterialSelect is IfcMaterialLayerSetUsage)
                    {
                        IfcMaterialLayerSetUsage mlsu = (IfcMaterialLayerSetUsage)ifcElement.MaterialSelect;

                        //foreach(IfcMaterialLayer ml in mlsu.ForLayerSet.MaterialLayers)
                        IfcMaterialLayerSet mls = mlsu.ForLayerSet;
                        for (int i = 0; i < mls.MaterialLayers.Count; i++)
                        {
                            ifcEntity.Material.Add(i + " " + mls.MaterialLayers[i].Material.Name, mls.MaterialLayers[i].LayerThickness);

                            IfcMaterial ifcMaterial = mls.MaterialLayers[i].Material;

                            if (ifcMaterial.HasRepresentation != null)
                            {
                                IfcMaterialDefinitionRepresentation imdr = ifcMaterial.HasRepresentation;
                                foreach (IfcStyledRepresentation isr in imdr.Representations)
                                {
                                    foreach (IfcStyledItem isi in isr.Items)
                                    {
                                        foreach (IfcPresentationStyleAssignment isas in isi.Styles) // se c'e' presentatio style direttamente
                                        {
                                            foreach (IfcPresentationStyle ips in isas.Styles)
                                            {
                                                if (ips is IfcSurfaceStyle)
                                                {
                                                    IfcSurfaceStyle iss = (IfcSurfaceStyle)ips;

                                                    foreach (var item in iss.Styles)
                                                    {
                                                        // vedere IFcSurfaceStyleElementSelect
                                                        if (item is IfcSurfaceStyleRendering)
                                                        {
                                                            IfcSurfaceStyleRendering issr = (IfcSurfaceStyleRendering)item;

                                                            int alpha = Convert.ToInt32((1 - issr.Transparency) * 255);

                                                            ifcEntity.Color = Color.FromArgb(alpha, issr.SurfaceColour.Colour);

                                                            ifcEntity.Identification.Add(i + "C" + mls.MaterialLayers[i].Material.Name, issr.SurfaceColour.Colour.ToString());
                                                        }
                                                    }
                                                }
                                                else if (ips is IfcCurveStyle)
                                                {
                                                    //ddgfdg
                                                }
                                            }
                                        }

                                        //IfcStyledItem ifcStyledItem = reprItem.mStyledByItem;

                                        //IfcStyleAssignmentSelect sas = (IfcPresentationStyleAssignment)ifcStyledItem.Styles[0];

                                        //IfcSurfaceStyle ss = (IfcSurfaceStyle)sas.Styles[0];

                                        //IfcSurfaceStyleRendering ssr = (IfcSurfaceStyleRendering)ss.Styles[0];

                                        //color = ssr.SurfaceColour.Colour;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            if (ifcEntity.Color == Color.Black)
            {
                Color color;
                if (defaultColor.TryGetValue(ifcProduct.KeyWord, out color))
                {
                    ifcEntity.Color = color;
                }
                //else
                //Debug.Write(ifcElement.KeyWord + " default color not set\n");
            }
        }