Ejemplo n.º 1
0
        public static AdjacencyCluster ToSAM_AdjacencyCluster(this string path_TSD, IEnumerable <SpaceDataType> spaceDataTypes = null, IEnumerable <PanelDataType> panelDataTypes = null)
        {
            if (string.IsNullOrWhiteSpace(path_TSD))
            {
                return(null);
            }

            AdjacencyCluster result = null;

            using (SAMTSDDocument sAMTSDDocument = new SAMTSDDocument(path_TSD))
            {
                result = sAMTSDDocument.ToSAM(spaceDataTypes, panelDataTypes);
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="dataAccess">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess dataAccess)
        {
            int index_Successful;

            index_Successful = Params.IndexOfOutputParam("successful");
            if (index_Successful != -1)
            {
                dataAccess.SetData(index_Successful, false);
            }

            int index;

            bool run = false;

            index = Params.IndexOfInputParam("_run");
            if (index != -1)
            {
                if (!dataAccess.GetData(index, ref run))
                {
                    run = false;
                }
            }

            if (!run)
            {
                return;
            }

            index = Params.IndexOfInputParam("_pathTasTSD");
            if (index == -1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            string path = null;

            if (!dataAccess.GetData(index, ref path) || string.IsNullOrWhiteSpace(path) || !System.IO.File.Exists(path))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }


            List <PanelDataType> panelDataTypes = null;

            index = Params.IndexOfInputParam("panelDataTypes_");
            if (index != -1)
            {
                List <GH_ObjectWrapper> objectWrappers = new List <GH_ObjectWrapper>();
                if (dataAccess.GetDataList(index, objectWrappers))
                {
                    panelDataTypes = new List <PanelDataType>();
                    foreach (GH_ObjectWrapper objectWrapper in objectWrappers)
                    {
                        PanelDataType panelDataType = PanelDataType.Undefined;
                        if (objectWrapper.Value is GH_String)
                        {
                            panelDataType = Analytical.Tas.Query.PanelDataType(((GH_String)objectWrapper.Value).Value);
                        }
                        else
                        {
                            panelDataType = Analytical.Tas.Query.PanelDataType(objectWrapper.Value);
                        }

                        if (panelDataType != PanelDataType.Undefined)
                        {
                            panelDataTypes.Add(panelDataType);
                        }
                    }
                }
            }

            List <SpaceDataType> spaceDataTypes = null;

            index = Params.IndexOfInputParam("spaceDataTypes_");
            if (index != -1)
            {
                List <GH_ObjectWrapper> objectWrappers = new List <GH_ObjectWrapper>();
                if (dataAccess.GetDataList(index, objectWrappers))
                {
                    spaceDataTypes = new List <SpaceDataType>();
                    foreach (GH_ObjectWrapper objectWrapper in objectWrappers)
                    {
                        SpaceDataType spaceDataType = SpaceDataType.Undefined;
                        if (objectWrapper.Value is GH_String)
                        {
                            spaceDataType = Analytical.Tas.Query.SpaceDataType(((GH_String)objectWrapper.Value).Value);
                        }
                        else
                        {
                            spaceDataType = Analytical.Tas.Query.SpaceDataType(objectWrapper.Value);
                        }

                        if (spaceDataType != SpaceDataType.Undefined)
                        {
                            spaceDataTypes.Add(spaceDataType);
                        }
                    }
                }
            }

            AdjacencyCluster   adjacencyCluster = null;
            List <Core.Result> results          = new List <Core.Result>();

            int index_Result           = Params.IndexOfOutputParam("results");
            int index_AdjacencyCluster = Params.IndexOfOutputParam("adjacencyCluster");

            if (index_Result != -1 || index_AdjacencyCluster != -1)
            {
                using (SAMTSDDocument sAMTSDDocument = new SAMTSDDocument(path, true))
                {
                    if (index_AdjacencyCluster != -1)
                    {
                        adjacencyCluster = sAMTSDDocument.ToSAM(spaceDataTypes, panelDataTypes);
                        dataAccess.SetData(index_AdjacencyCluster, new GooAdjacencyCluster(adjacencyCluster));
                    }


                    if (index_Result != -1)
                    {
                        results = Analytical.Tas.Convert.ToSAM(sAMTSDDocument);
                        dataAccess.SetDataList(index_Result, results?.ConvertAll(x => new GooResult(x)));
                    }

                    sAMTSDDocument.Close();
                }
            }

            if (index_Successful != -1)
            {
                dataAccess.SetData(index_Successful, true);
            }
        }