예제 #1
0
        /***************************************************/
        /**** Private Methods                           ****/
        /***************************************************/

        private int DeleteSurfaces(IEnumerable <object> ids)
        {
            int success = 1;

            if (ids != null)
            {
                List <int> indicies = ids.Cast <int>().ToList();

                foreach (int index in indicies)
                {
                    IFSurface lusasSurface = d_LusasData.getSurfaceByNumber(index);
                    if (lusasSurface.getHOFs().Count() > 0)
                    {
                        //Engine.Base.Compute.RecordWarning(index + @" has higher order features(HOFs)
                        //and cannot be deleted");
                    }
                    else
                    {
                        d_LusasData.Delete(lusasSurface);
                    }
                }
            }
            else
            {
                d_LusasData.deleteSurfaces();
            }

            return(success);
        }
예제 #2
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static Panel ToPanel(this IFSurface lusasSurface,
                                    Dictionary <string, Edge> edges,
                                    HashSet <string> groupNames,
                                    Dictionary <string, ISurfaceProperty> surfaceProperties,
                                    Dictionary <string, IMaterialFragment> materials,
                                    Dictionary <string, Constraint4DOF> supports,
                                    Dictionary <string, MeshSettings2D> meshes)

        {
            object[]      lusasSurfaceLines = lusasSurface.getLOFs();
            List <ICurve> dummyCurve        = new List <ICurve>();

            int n = lusasSurfaceLines.Length;
            HashSet <string> tags = new HashSet <string>(IsMemberOf(lusasSurface, groupNames));

            List <Edge> surfaceEdges = new List <Edge>();

            for (int i = 0; i < n; i++)
            {
                Edge edge = GetEdge(lusasSurface, i, edges);
                surfaceEdges.Add(edge);
            }

            Panel panel = Engine.Structure.Create.Panel(surfaceEdges, dummyCurve);

            panel.Tags = tags;

            int adapterID = lusasSurface.getID();

            panel.SetAdapterId(typeof(LusasId), adapterID);

            List <string> geometricAssignments = GetAttributeAssignments(lusasSurface, "Geometric");
            List <string> materialAssignments  = GetAttributeAssignments(lusasSurface, "Material");

            IMaterialFragment panelMaterial;
            ISurfaceProperty  surfaceProperty;

            if (!(geometricAssignments.Count() == 0))
            {
                surfaceProperties.TryGetValue(geometricAssignments[0], out surfaceProperty);
                if (!(materialAssignments.Count() == 0))
                {
                    materials.TryGetValue(materialAssignments[0], out panelMaterial);
                    surfaceProperty.Material = panelMaterial;
                }

                panel.Property = surfaceProperty;
            }

            MeshSettings2D surfaceMesh;
            List <string>  meshSettings = GetAttributeAssignments(lusasSurface, "Mesh");

            if (!(meshSettings.Count() == 0))
            {
                meshes.TryGetValue(meshSettings[0], out surfaceMesh);
                panel.Fragments.Add(surfaceMesh);
            }

            return(panel);
        }
예제 #3
0
        /***************************************************/
        /**** Private Methods                           ****/
        /***************************************************/

        private static Edge GetEdge(IFSurface lusasSurf, int lineIndex, Dictionary <string, Edge> bars)
        {
            Edge   edge;
            IFLine lusasEdge = lusasSurf.getLOFs()[lineIndex];

            bars.TryGetValue(lusasEdge.getID().ToString(), out edge);
            return(edge);
        }
예제 #4
0
        private List <ILoad> ReadAreaUniformTemperatureLoads(List <string> ids = null)
        {
            /***************************************************/
            /**** Private Methods                           ****/
            /***************************************************/

            List <ILoad> areaUniformTemperatureLoads = new List <ILoad>();

            object[] lusasTemperatureLoads = d_LusasData.getAttributes("Temperature");

            if (!(lusasTemperatureLoads.Count() == 0))
            {
                List <Panel> panelsList           = ReadPanels();
                Dictionary <string, Panel> panels = panelsList.ToDictionary(
                    x => x.AdapterId <string>(typeof(LusasId)));

                List <IFLoadcase> allLoadcases = new List <IFLoadcase>();

                for (int i = 0; i < lusasTemperatureLoads.Count(); i++)
                {
                    IFLoading lusasTemperatureLoad = (IFLoading)lusasTemperatureLoads[i];

                    IEnumerable <IGrouping <string, IFAssignment> > groupedByLoadcases =
                        GetLoadAssignments(lusasTemperatureLoad);

                    foreach (IEnumerable <IFAssignment> groupedAssignment in groupedByLoadcases)
                    {
                        List <IFAssignment> surfaceAssignments = new List <IFAssignment>();

                        foreach (IFAssignment assignment in groupedAssignment)
                        {
                            IFSurface trySurf = assignment.getDatabaseObject() as IFSurface;

                            if (trySurf != null)
                            {
                                surfaceAssignments.Add(assignment);
                            }
                        }

                        List <string> analysisName = new List <string> {
                            lusasTemperatureLoad.getAttributeType()
                        };

                        if (surfaceAssignments.Count != 0)
                        {
                            AreaUniformTemperatureLoad areaUniformTemperatureLoad =
                                Adapters.Lusas.Convert.ToAreaTempratureLoad(
                                    lusasTemperatureLoad, groupedAssignment, panels);

                            areaUniformTemperatureLoad.Tags = new HashSet <string>(analysisName);
                            areaUniformTemperatureLoads.Add(areaUniformTemperatureLoad);
                        }
                    }
                }
            }

            return(areaUniformTemperatureLoads);
        }
예제 #5
0
        /***************************************************/
        /**** Private Methods                           ****/
        /***************************************************/

        private IFSurface CreateSurface(Panel panel)
        {
            List <IFLine> edges = new List <IFLine>();

            foreach (Edge edge in panel.ExternalEdges)
            {
                string edgeId = GetAdapterId <string>(edge);

                if (string.IsNullOrEmpty(edgeId))
                {
                    Engine.Base.Compute.RecordError("Could not find the ids for at least one Edge, Panel not created.");
                    return(null);
                }
                else
                {
                    edges.Add(d_LusasData.getLineByNumber(edgeId));
                }
            }

            IFSurface lusasSurface = d_LusasData.createSurfaceBy(edges.ToArray());

            if (lusasSurface != null)
            {
                int adapterIdName = lusasSurface.getID();
                panel.SetAdapterId(typeof(LusasId), adapterIdName);

                if (!(panel.Tags.Count == 0))
                {
                    AssignObjectSet(lusasSurface, panel.Tags);
                }

                if (CheckPropertyWarning(panel, p => p.Property) && !Engine.Adapters.Lusas.Query.InvalidSurfaceProperty(panel.Property))
                {
                    IFAttribute lusasGeometricSurface = d_LusasData.getAttribute("Surface Geometric", panel.Property.AdapterId <int>(typeof(LusasId)));

                    lusasGeometricSurface.assignTo(lusasSurface);
                    if (CheckPropertyWarning(panel, p => p.Property.Material))
                    {
                        IFAttribute lusasMaterial = d_LusasData.getAttribute("Material", panel.Property.Material.AdapterId <int>(typeof(LusasId)));
                        lusasMaterial.assignTo(lusasSurface);
                    }
                }

                if (panel.Fragments.Contains(typeof(MeshSettings2D)))
                {
                    IFAssignment meshAssignment = m_LusasApplication.newAssignment();
                    meshAssignment.setAllDefaults();

                    MeshSettings2D meshSettings2D = panel.FindFragment <MeshSettings2D>();
                    IFMeshAttr     mesh           = d_LusasData.getMesh(meshSettings2D.Name);
                    mesh.assignTo(lusasSurface, meshAssignment);
                }
            }

            return(lusasSurface);
        }
예제 #6
0
        public List <List <double[]> > getSurfaceCoordinatesFromLusas()
        {
            IFSelection userInp = lusas.getSelection();

            //check if selection is at least one point
            if (userInp.countSurfaces() < 1)
            {
                MessageBox.Show("please select at least one point", "", MessageBoxButtons.OK);
                return(null);
            }

            //create collection to popoulate surfaces
            List <List <double[]> > surfaces = new List <List <double[]> >();

            for (int i = 0; i < userInp.countSurfaces(); i++)
            {
                //gereate array of ids
                List <int> pointIds = new List <int>();

                //generate collection for populating vertices
                List <double[]> vertexes = new List <double[]>();

                IFSurface surface = userInp.getSurface(i);
                object[]  lines   = surface.getLOFs() as object[];
                for (int l = 0; l < lines.Length; l++)
                {
                    IFLine   line   = lines[l] as IFLine;
                    object[] points = line.getLOFs() as object[];
                    for (int k = 0; k < points.Length; k++)
                    {
                        IFPoint point = points[k] as IFPoint;
                        int     id    = point.getID();

                        if (!pointIds.Contains(id))
                        {
                            pointIds.Add(id);
                            double[] position = new double[3];
                            position[0] = point.getX();
                            position[1] = point.getY();
                            position[2] = point.getZ();
                            //point.getXYZ(position[0],position[1],position[2]);
                            vertexes.Add(position);
                        }
                    }
                }
                surfaces.Add(vertexes);
            }
            return(surfaces);
        }
예제 #7
0
        /***************************************************/
        /**** Private Methods                           ****/
        /***************************************************/

        private List <Panel> ReadPanels(List <string> ids = null)
        {
            object[]     lusasSurfaces = d_LusasData.getObjects("Surface");
            List <Panel> panels        = new List <Panel>();

            if (!(lusasSurfaces.Count() == 0))
            {
                IEnumerable <Edge>        edgesList = ReadEdges();
                Dictionary <string, Edge> edges     = edgesList.ToDictionary(
                    x => x.AdapterId <string>(typeof(LusasId)));

                HashSet <string> groupNames = ReadTags();
                IEnumerable <IMaterialFragment>        materialList = ReadMaterials();
                Dictionary <string, IMaterialFragment> materials    = materialList.ToDictionary(
                    x => x.Name.ToString());

                IEnumerable <ISurfaceProperty>        sectionPropertiesList = Read2DProperties();
                Dictionary <string, ISurfaceProperty> sectionProperties     = sectionPropertiesList.ToDictionary(
                    x => x.Name.ToString());

                IEnumerable <Constraint4DOF>        supportsList = Read4DOFConstraints();
                Dictionary <string, Constraint4DOF> supports     = supportsList.ToDictionary(
                    x => x.Name);

                List <MeshSettings2D> meshesList           = ReadMeshSettings2D();
                Dictionary <string, MeshSettings2D> meshes = meshesList.ToDictionary(
                    x => x.Name.ToString());

                for (int i = 0; i < lusasSurfaces.Count(); i++)
                {
                    IFSurface lusasSurface = (IFSurface)lusasSurfaces[i];
                    Panel     panel        = Adapters.Lusas.Convert.ToPanel(lusasSurface,
                                                                            edges,
                                                                            groupNames,
                                                                            sectionProperties,
                                                                            materials,
                                                                            supports,
                                                                            meshes);

                    panels.Add(panel);
                }
            }

            return(panels);
        }
예제 #8
0
        /***************************************************/
        /**** Private Methods                           ****/
        /***************************************************/

        private static IEnumerable <IAreaElement> GetSurfaceAssignments(IEnumerable <IFAssignment> lusasAssignments,
                                                                        Dictionary <string, Panel> panels)
        {
            List <IAreaElement> assignedSurfs = new List <IAreaElement>();
            Panel panel;

            foreach (IFAssignment lusasAssignment in lusasAssignments)
            {
                if (lusasAssignment.getDatabaseObject() is IFSurface)
                {
                    IFSurface lusasSurface = (IFSurface)lusasAssignment.getDatabaseObject();
                    panels.TryGetValue(lusasSurface.getID().ToString(), out panel);
                    assignedSurfs.Add(panel);
                }
                else
                {
                    AssignmentWarning(lusasAssignment);
                }
            }

            return(assignedSurfs);
        }
예제 #9
0
        /***************************************************/

        private bool CreateCollection(IEnumerable <Panel> panels)
        {
            if (panels != null)
            {
                CreateTags(panels);

                List <Panel> validPanels = new List <Panel>();

                foreach (Panel panel in panels)
                {
                    if (panel.ExternalEdges.Count > 0)
                    {
                        if (CheckPropertyError(panel, p => p.ExternalEdges))
                        {
                            if (CheckPropertyError(panel.ExternalEdges, e => e.Select(x => x.Curve)))
                            {
                                if (panel.ExternalEdges.All(x => x != null) && panel.ExternalEdges.Select(x => x.Curve).All(y => y != null))
                                {
                                    if (panel.Openings.Count > 0)
                                    {
                                        Engine.Base.Compute.RecordWarning("Lusas_Toolkit does not support Panels with Openings. The Panel will be pushed if valid, the Openings will not be pushed.");
                                    }
                                    if (panel.ExternalEdges.All(x => !Engine.Adapters.Lusas.Query.InvalidEdge(x)))
                                    {
                                        if (Engine.Spatial.Query.IsPlanar(panel, false, Tolerance.MacroDistance))
                                        {
                                            for (int i = 0; i < panel.ExternalEdges.Count; i++)
                                            {
                                                if (!CheckPropertyError(panel, p => panel.ExternalEdges[i]) && Engine.Adapters.Lusas.Query.InvalidEdge(panel.ExternalEdges[i]))
                                                {
                                                    break;
                                                }

                                                if (i == panel.ExternalEdges.Count - 1)
                                                {
                                                    validPanels.Add(panel);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Engine.Base.Compute.RecordError("The geometry defining the Panel is not Planar, and therefore the Panel will not be created.");
                                        }
                                    }
                                    else
                                    {
                                        Engine.Base.Compute.RecordError("One or more of the External Edges of the Panel are invalid.");
                                    }
                                }
                                else
                                {
                                    Engine.Base.Compute.RecordError("One of more of the External Edges of the Panel or Curves defining the External Edges are null.");
                                }
                            }
                        }
                    }
                    else
                    {
                        Engine.Base.Compute.RecordError($"An object of type {panel.GetType().Name} could not be created due to a property of type {typeof(Edge).Name} being null. Please check your input data!");
                    }
                }

                if (validPanels.Any(x => x.Fragments.Contains(typeof(MeshSettings2D))))
                {
                    BHoMObjectNameComparer comparer       = new BHoMObjectNameComparer();
                    List <MeshSettings2D>  distinctMeshes = panels.Select(x => x.FindFragment <MeshSettings2D>())
                                                            .Distinct <MeshSettings2D>(comparer)
                                                            .ToList();

                    foreach (MeshSettings2D mesh in distinctMeshes)
                    {
                        CreateMeshSettings2D(mesh);
                    }

                    foreach (Panel validPanel in validPanels)
                    {
                        validPanel.AddFragment(distinctMeshes.First(x => comparer.Equals(x, (validPanel.FindFragment <MeshSettings2D>()))), true);
                    }
                }

                ReduceRuntime(true);

                IFSurface lusasSurface = null;

                foreach (Panel validPanel in validPanels)
                {
                    lusasSurface = CreateSurface(validPanel);
                }

                ReduceRuntime(false);
            }
            return(true);
        }