/// <summary>
        /// Adds the geometry fragment to the hidden mesh, if the model is not null
        /// the fragment is placed on a sub layer of the correct style
        /// the sub layer is automaticaly created if it does not exist.
        /// </summary>
        /// <param name="geomData"></param>
        /// <param name="model"></param>
        public void AddToHidden(XbimGeometryData geomData, IModel model = null)
        {
            int modelId = 0;

            if (model != null)
            {
                modelId = model.UserDefinedId;
            }
            if (model != null && geomData.StyleLabel > 0) // check if we need to put this item on a sub layer
            {
                XbimMeshLayer <TMesh, TMaterial> subLayer;
                var layerName = geomData.StyleLabel.ToString();
                if (!_subLayerMap.Contains(layerName))
                {
                    var style = model.Instances[geomData.StyleLabel] as IfcSurfaceStyle;
                    //create a sub layer
                    subLayer = new XbimMeshLayer <TMesh, TMaterial>(model, style)
                    {
                        Name = layerName
                    };
                    _subLayerMap.Add(subLayer);
                }
                else
                {
                    subLayer = _subLayerMap[layerName];
                }

                subLayer.AddToHidden(geomData, null, (short)modelId);
            }
            else
            {
                AddToHidden(geomData, model, (short)modelId);
            }
        }
        /// <summary>
        /// Adds the geometry fragment to the hidden mesh, if the model is not null
        /// the fragment is placed on a sub layer of the correct style
        /// the sub layer is automaticaly created if it does not exist.
        /// </summary>
        /// <param name="geomData"></param>
        /// <param name="model"></param>
        public void AddToHidden(XbimGeometryData geomData, IModel model, short modelId)
        {
            var addingSuccessfull = Hidden.Add(geomData, modelId); // this is where the geometry is added to the main layer.

            if (addingSuccessfull)
            {
                return;
            }
            //if the main layer is too big split it.
            //try and find a sublayer that is a split of this, i.e. has the same texture
            foreach (var sublayer in _subLayerMap.Reverse())
            {
                if (!Equals(sublayer.Style, Style))
                {
                    continue;
                }
                sublayer.AddToHidden(geomData, model, modelId); //try and add the data to this mesh
                return;                                         //succeeded so return
            }
            //didn't find a layer to add it to so create a new one
            var subLayer = new XbimMeshLayer <TMesh, TMaterial>(model, Style)
            {
                Name = Name + "-" + _subLayerMap.Count
            };

            _subLayerMap.Add(subLayer);
            subLayer.Hidden.Add(geomData, modelId); //this should always pass as it is a new mesh and ifc geom rarely exceeds max mesh size, graphics cards will truncate anyway
        }
        protected override void InsertItem(int index, XbimMeshLayer <TVISIBLE, TMATERIAL> item)
        {
            XbimMeshLayer <TVISIBLE, TMATERIAL> removed = null;

            if (index < Count)
            {
                removed = this[index];
            }
            base.InsertItem(index, item);
            NotifyCollectionChangedEventHandler collChanged = _collectionChanged;

            if (collChanged != null)
            {
                if (index == Count)
                {
                    collChanged(this,
                                new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, removed, index));
                }
                else
                {
                    collChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
                    NotifyCountChanged(Count - 1);
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// Add the layer to the scene
 /// </summary>
 /// <param name="layer"></param>
 public void Add(XbimMeshLayer <TVISIBLE, TMATERIAL> layer)
 {
     if (string.IsNullOrEmpty(layer.Name)) //ensure a layer has a unique name if the user has not defined one
     {
         layer.Name = "Layer " + _layers.Count();
     }
     if (!_layers.Contains(layer))
     {
         _layers.Add(layer);
     }
 }
        protected override void RemoveItem(int index)
        {
            int oldCount = Count;
            XbimMeshLayer <TVISIBLE, TMATERIAL> removed = this[index];

            base.RemoveItem(index);
            NotifyCollectionChangedEventHandler collChanged = _collectionChanged;

            if (collChanged != null)
            {
                collChanged(this,
                            new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removed, index));
            }
            NotifyCountChanged(oldCount);
        }
 public MeshInfo(XbimMeshFragment mf, XbimMeshLayer <TMesh, TMaterial> xbimMeshLayer)
 {
     _mf            = mf;
     _xbimMeshLayer = xbimMeshLayer;
 }
 protected override string GetKeyForItem(XbimMeshLayer <TVISIBLE, TMATERIAL> item)
 {
     return(item.Name);
 }