Exemple #1
0
        protected SpeckleObject ToSpeckle(IBHoMObject bhomObject, SpecklePushConfig config)
        {
            // Assign SpeckleStreamId to the Fragments of the IBHoMObjects
            SetAdapterId(bhomObject, SpeckleClient.Stream.StreamId);

            // SpeckleObject "container". Top level has geometry representation of BHoM Object, so it can be visualised in the SpeckleViewer.
            SpeckleObject speckleObject = SpeckleRepresentation(bhomObject, config.RendermeshOptions);

            // If no Speckle representation is found, it will be sent as an "Abstract" SpeckleObject (no visualisation).
            if (speckleObject == null)
            {
                speckleObject = (SpeckleObject)SpeckleCore.Converter.Serialise(bhomObject);
            }

            // Save BHoMObject data inside the speckleObject.
            Modify.SetBHoMData(speckleObject, bhomObject, config.UseSpeckleSerialiser);

            speckleObject.SetDiffingHash(bhomObject, config);

            // If the BHoMObject has a "RevisionName" string field in the Customdata,
            // use that value to create a Layer for it, and set the SpeckleObject's layer.
            //object revisionValue = null;
            //string revisionName = "";
            //if (bhomObject.CustomData.TryGetValue("RevisionName", out revisionValue))
            //{
            //    revisionName = revisionValue as string;
            //    if (!string.IsNullOrWhiteSpace(revisionName))
            //        speckleObject.Properties["revisionName"] = revisionName;
            //}

            return(speckleObject);
        }
Exemple #2
0
        protected SpeckleObject ToSpeckle(IObject iObject, SpecklePushConfig config)
        {
            // Convert the objects into the appropriate SpeckleObject using the available converters.
            SpeckleObject speckleObject = null;

            if (typeof(IGeometry).IsAssignableFrom(iObject.GetType()))
            {
                speckleObject = Speckle.Convert.IToSpeckle((IGeometry)iObject);
            }

            if (speckleObject == null)
            {
                BH.oM.Graphics.RenderMesh rm = null;

                try
                {
                    rm = BH.Engine.Representation.Compute.IRenderMesh(iObject);
                }
                catch
                {
                    BH.Engine.Reflection.Compute.RecordNote($"Could not compute the representation for an object of type {iObject.GetType().Name}.\n" +
                                                            $"This simply means that the object will not be viewable in the browser (SpeckleViewer).");
                }

                if (rm != null)
                {
                    speckleObject = Speckle.Convert.ToSpeckle(rm);
                }
                else
                {
                    speckleObject = (SpeckleObject)SpeckleCore.Converter.Serialise(iObject); // These will be exported as `Abstract` Speckle Objects.
                }
            }

            // Save BHoMObject data inside the speckleObject.
            Modify.SetBHoMData(speckleObject, iObject, config.UseSpeckleSerialiser);

            speckleObject.SetDiffingHash(iObject, config);

            return(speckleObject);
        }