Example #1
0
        public static object TryConvertItemToSpeckle(object value, ISpeckleConverter converter)
        {
            object result = null;

            if (value is null)
            {
                throw new Speckle.Core.Logging.SpeckleException("Null values are not supported, please clean your data tree.");
            }

            if (value is IGH_Goo)
            {
                value = value.GetType().GetProperty("Value").GetValue(value);
            }

            if (value is Base || value.GetType().IsSimpleType())
            {
                return(value);
            }

            if (converter.CanConvertToSpeckle(value))
            {
                return(converter.ConvertToSpeckle(value));
            }



            return(result);
        }
Example #2
0
        /// <summary>
        /// Try to convert a given object into native (Rhino) format.
        /// </summary>
        /// <param name="value">Object to convert</param>
        /// <param name="converter">Converter instance to use.</param>
        /// <param name="recursive">Indicates if any non-convertible <see cref="Base"/> instances should be traversed too.</param>
        /// <returns>An <see cref="IGH_Goo"/> instance holding the converted object. </returns>
        public static object TryConvertItemToSpeckle(object value, ISpeckleConverter converter, bool recursive = false, Action OnConversionProgress = null)
        {
            if (value is null)
            {
                throw new Exception("Null values are not allowed, please clean your data tree.");
            }

            if (value is IGH_Goo)
            {
                value = value.GetType().GetProperty("Value").GetValue(value);
            }

            if (value.GetType().IsSimpleType())
            {
                return(value);
            }


            if (converter.CanConvertToSpeckle(value))
            {
                return(converter.ConvertToSpeckle(value));
            }

            var subclass = value.GetType().IsSubclassOf(typeof(Base));

            if (subclass)
            {
                // TODO: Traverse through dynamic props only.
                return(value);
            }

            if (recursive && value is Base @base)
            {
                return(TraverseAndConvertToSpeckle(@base, converter));
            }

            if (value is Base @base2)
            {
                return(@base2);
            }

            return(null);
        }
Example #3
0
        private Base ConvertGridLines(ISpeckleConverter converter, ProgressViewModel progress)
        {
            Base converted = null;

            ITFApplication appInst = new TFApplicationList();

            if (0 == appInst.GetProject(0, out ITFLoadableProjectList projList) && projList != null)
            {
                ITFLoadableProject proj = projList.AsTFLoadableProject;
                if (null == proj)
                {
                    progress.Report.ConversionErrors.Add(new Exception("Could not retrieve project for exporting gridlines"));
                    return(converted);
                }

                ITFDrawingGrid drawingGrid = null;
                if (Control.InvokeRequired)
                {
                    Control.Invoke((Action)(() => { proj.GetDrawingGrid(false, 0, out drawingGrid); }));
                }
                else
                {
                    proj.GetDrawingGrid(false, 0, out drawingGrid);
                }

                if (null == drawingGrid)
                {
                    progress.Report.ConversionErrors.Add(new Exception("Could not retrieve drawing grid for exporting gridlines"));
                    return(converted);
                }

                if (Control.InvokeRequired)
                {
                    converted = (Base)Control.Invoke(new SpeckleConversionDelegate(converter.ConvertToSpeckle), new object[] { drawingGrid });
                }
                else
                {
                    converted = converter.ConvertToSpeckle(drawingGrid);
                }
            }
            return(converted);
        }
Example #4
0
        public static object TryConvertItemToSpeckle(object value, ISpeckleConverter converter)
        {
            object result = null;

            if (value is IGH_Goo)
            {
                value = value.GetType().GetProperty("Value").GetValue(value);
            }

            if (value is Base || value.GetType().IsSimpleType())
            {
                return(value);
            }

            if (converter.CanConvertToSpeckle(value))
            {
                return(converter.ConvertToSpeckle(value));
            }



            return(result);
        }