예제 #1
0
파일: Panel.cs 프로젝트: BHoM/RFEM_Toolkit
        /***************************************************/

        private List <Edge> GetEdgesFromRFEMSurface(rf.Surface surface)
        {
            List <Edge> edgeList       = new List <Edge>();
            string      boundaryString = modelData.GetSurface(surface.No, rf.ItemAt.AtNo).GetData().BoundaryLineList;

            List <int> boundaryLineIds = GetIdListFromString(boundaryString);


            foreach (int edgeId in boundaryLineIds)
            {
                List <oM.Geometry.Point> ptsInEdge = new List <oM.Geometry.Point>();
                string     nodeIdString            = modelData.GetLine(edgeId, rf.ItemAt.AtNo).GetData().NodeList;
                List <int> nodeIds = GetIdListFromString(nodeIdString);

                foreach (int ptId in nodeIds)
                {
                    rf.Node rfNode = modelData.GetNode(ptId, rf.ItemAt.AtNo).GetData();
                    ptsInEdge.Add(new oM.Geometry.Point()
                    {
                        X = rfNode.X, Y = rfNode.Y, Z = rfNode.Z
                    });
                }
                edgeList.Add(new Edge {
                    Curve = Engine.Geometry.Create.Polyline(ptsInEdge)
                });
            }

            return(edgeList);
        }
예제 #2
0
파일: Node.cs 프로젝트: BHoM/RFEM_Toolkit
        /***************************************************/
        /**** Private methods                           ****/
        /***************************************************/

        private bool CreateCollection(IEnumerable <Node> nodes)
        {
            if (nodes.Count() > 0)
            {
                int         nodeIdNum = 0;
                int         consIdNum = 0;
                List <Node> nodeList  = nodes.ToList();
                rf.Node[]   rfNodes   = new rf.Node[nodeList.Count()];

                for (int i = 0; i < nodes.Count(); i++)
                {
                    nodeIdNum  = GetAdapterId <int>(nodeList[i]);//(NextId(nodeList[i].GetType()));
                    rfNodes[i] = nodeList[i].ToRFEM(nodeIdNum);
                    modelData.SetNode(rfNodes[i]);

                    //set support here if the node contains one ! ! ! ! !
                    if (nodeList[i].Support != null)
                    {
                        consIdNum = System.Convert.ToInt32(NextFreeId(nodeList[i].Support.GetType()));
                        rf.NodalSupport rfConstraint = nodeList[i].Support.ToRFEM(consIdNum, nodeIdNum);
                        modelData.SetNodalSupport(rfConstraint);
                    }
                }

                //modelData.SetNodes(rfemNodes);
            }

            return(true);
        }
예제 #3
0
파일: Node.cs 프로젝트: BHoM/RFEM_Toolkit
 public static rf.Node ToRFEM(this Node node, int nodeId)
 {
     rf.Node rfNode = new rf.Node();
     rfNode.No = nodeId;
     rfNode.X  = node.Position.X;
     rfNode.Y  = node.Position.Y;
     rfNode.Z  = node.Position.Z;
     return(rfNode);
 }
예제 #4
0
        private List <Rhino.Geometry.Point3d> ReadRfemNodes(string pointsListInput)
        {
            // Gets interface to running RFEM application.
            app = Marshal.GetActiveObject("RFEM5.Application") as IApplication;
            // Locks RFEM licence
            app.LockLicense();

            // Gets interface to active RFEM model.
            model = app.GetActiveModel();

            // Gets interface to model data.
            IModelData data = model.GetModelData();

            //Create new array for Rhino point objects
            List <Rhino.Geometry.Point3d> rhinoPointArray = new List <Rhino.Geometry.Point3d>();

            try
            {
                for (int index = 0; index < data.GetNodeCount(); index++)
                {
                    Dlubal.RFEM5.Node      currentNode      = data.GetNode(index, ItemAt.AtIndex).GetData();
                    Rhino.Geometry.Point3d currentRhinoNode = new Rhino.Geometry.Point3d();
                    currentRhinoNode.X = currentNode.X;
                    currentRhinoNode.Y = currentNode.Y;
                    currentRhinoNode.Z = currentNode.Z;

                    rhinoPointArray.Add(currentRhinoNode);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // Releases interface to RFEM model.
            model = null;

            // Unlocks licence and releases interface to RFEM application.
            if (app != null)
            {
                app.UnlockLicense();
                app = null;
            }

            // Cleans Garbage Collector and releases all cached COM interfaces.
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();

            ///the lines below outputs created RFEM nodes in output parameter
            ///current funcionality does not use this
            ///it uses a custom class (written within this project) RfemNodeType to wrap the Dlubal.RFEM5.Node objects.
            return(rhinoPointArray);
        }
예제 #5
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static Node FromRFEM(this rf.Node node)
        {
            Node bhNode = new Node {
                Position = new oM.Geometry.Point()
                {
                    X = node.X, Y = node.Y, Z = node.Z
                }
            };

            bhNode.SetAdapterId(typeof(RFEMId), node.No);

            return(bhNode);
        }
예제 #6
0
파일: Edge.cs 프로젝트: BHoM/RFEM_Toolkit
        /***************************************************/
        /**** Private methods                           ****/
        /***************************************************/

        private bool CreateCollection(IEnumerable <Edge> edges)
        {
            if (edges.Count() > 0)
            {
                int edgeIdNum = 0;

                List <Edge> edgeList = edges.ToList();
                rf.Line[]   rfLines  = new rf.Line[edgeList.Count()];

                for (int i = 0; i < edges.Count(); i++)
                {
                    edgeIdNum = GetAdapterId <int>(edgeList[i]);


                    //create rfem nodes, i.e. bhom points
                    Line edgeAsLine = edgeList[i].Curve as Line;

                    rf.Node rfNode1 = new rf.Node();
                    rfNode1.No = (int)this.NextFreeId(typeof(Node));
                    rfNode1.X  = edgeAsLine.Start.X;
                    rfNode1.Y  = edgeAsLine.Start.Y;
                    rfNode1.Z  = edgeAsLine.Start.Z;
                    modelData.SetNode(rfNode1);

                    rf.Node rfNode2 = new rf.Node();
                    int     nodeId1 = (int)this.NextFreeId(typeof(Node));
                    rfNode2.X = edgeAsLine.End.X;
                    rfNode2.Y = edgeAsLine.End.Y;
                    rfNode2.Z = edgeAsLine.End.Z;
                    modelData.SetNode(rfNode1);



                    //create line
                    rf.Line centreLine = new rf.Line();
                    centreLine.No       = edgeIdNum;
                    centreLine.NodeList = String.Join(",", new int[] { rfNode1.No, rfNode2.No });
                    centreLine.Type     = rf.LineType.PolylineType;
                    modelData.SetLine(centreLine);
                }

                //modelData.SetMembers(rfBars);
            }

            return(true);
        }
예제 #7
0
        private List <Dlubal.RFEM5.Node> CreateRfemNodes(List <Point3d> Rh_pt3d, Dlubal.RFEM5.NodalSupport rfemNodalSupportMethodIn, string commentsListMethodIn)
        {
            //---- Estabish connection with RFEM----
            #region Creating connection with RFEM

            // Gets interface to running RFEM application.
            IApplication app = Marshal.GetActiveObject("RFEM5.Application") as IApplication;
            // Locks RFEM licence
            app.LockLicense();

            // Gets interface to active RFEM model.
            IModel model = app.GetActiveModel();

            // Gets interface to model data.
            IModelData data = model.GetModelData();
            #endregion

            //---- Further lines gets information about available object numbers in model;----
            #region Getting available element numbers

            // Gets Max node Number
            int currentNewNodeNo = data.GetLastObjectNo(ModelObjectType.NodeObject) + 1;
            // Gets Max nodal support number
            int currentNewNodalSupportNo = data.GetLastObjectNo(ModelObjectType.NodalSupportObject) + 1;
            #endregion

            //---- Creating new variables for use within this method----
            List <Dlubal.RFEM5.Node> RfemNodeList = new List <Dlubal.RFEM5.Node>(); //Create new list for RFEM point objects
            string createdNodesList = "";                                           //Create a string for list with nodes

            //---- Assigning node propertiess----
            #region Creating RFEM node elements


            for (int i = 0; i < Rh_pt3d.Count; i++)
            {
                Dlubal.RFEM5.Node tempCurrentNode = new Dlubal.RFEM5.Node();
                tempCurrentNode.No      = currentNewNodeNo;
                tempCurrentNode.CS      = CoordinateSystemType.Cartesian;
                tempCurrentNode.Type    = NodeType.Standard;
                tempCurrentNode.X       = Rh_pt3d[i].X;
                tempCurrentNode.Y       = Rh_pt3d[i].Y;
                tempCurrentNode.Z       = Rh_pt3d[i].Z;
                tempCurrentNode.Comment = commentsListMethodIn;
                RfemNodeList.Add(tempCurrentNode);

                if (i == Rh_pt3d.Count - 1)
                {
                    createdNodesList = createdNodesList + currentNewNodeNo.ToString();
                }
                else
                {
                    createdNodesList = createdNodesList + currentNewNodeNo.ToString() + ",";
                }

                currentNewNodeNo++;
            }

            //create an array of nodes;
            Dlubal.RFEM5.Node[] RfemNodeArray = new Dlubal.RFEM5.Node[RfemNodeList.Count];
            RfemNodeArray = RfemNodeList.ToArray();
            #endregion


            //---- Writing nodes----
            #region Writing RFEM nodes and supports

            try
            {
                // modification - set model in modification mode, new information can be written
                data.PrepareModification();

                ///This version writes nodes one-by-one, because the API method data.SetNodes() for
                ///array appears not to be working
                //data.SetNodes(RfemNodeList.ToArray());
                foreach (Node currentRfemNode in RfemNodeList)
                {
                    data.SetNode(currentRfemNode);
                }

                //addition of nodal supports
                rfemNodalSupportMethodIn.No       = currentNewNodalSupportNo;
                rfemNodalSupportMethodIn.NodeList = createdNodesList;
                data.SetNodalSupport(ref rfemNodalSupportMethodIn);


                // finish modification - RFEM regenerates the data (this operation takes some time)
                data.FinishModification();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error - Writing nodes", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            #endregion


            //---- Releasing RFEM model----
            #region Releasing RFEM model

            // Releases interface to RFEM model.
            model = null;

            // Unlocks licence and releases interface to RFEM application.
            if (app != null)
            {
                app.UnlockLicense();
                app = null;
            }

            // Cleans Garbage Collector and releases all cached COM interfaces.
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            #endregion

            ///the lines below outputs created RFEM nodes in output parameter
            //output 'success' as true
            writeSuccess = true;
            return(RfemNodeList);
        }
예제 #8
0
        private List <Dlubal.RFEM5.Node> CreateRfemNodes(List <Point3d> Rh_pt3d)
        {
            // Gets interface to running RFEM application.
            app = Marshal.GetActiveObject("RFEM5.Application") as IApplication;
            // Locks RFEM licence
            //app.LockLicense();

            // Gets interface to active RFEM model.
            //model = app.GetActiveModel();

            // Gets interface to model data.
            //IModelData data = model.GetModelData();

            //List<Dlubal.RFEM5.Node> RfemNodeList = new List<Dlubal.RFEM5.Node>();
            Dlubal.RFEM5.Node[] RfemNodeArray = new Dlubal.RFEM5.Node[Rh_pt3d.Count];


            try
            {
                // modification
                // Sets all objects to model data.
                // data.PrepareModification();

                for (int index = 0; index < Rh_pt3d.Count; index++)

                {
                    //Dlubal.RFEM5.Node RfemNode = new Dlubal.RFEM5.Node();
                    // Node RfemNode = new Node();
                    RfemNodeArray[index].No = index + 1;
                    RfemNodeArray[index].X  = Rh_pt3d[index].X;
                    RfemNodeArray[index].Y  = Rh_pt3d[index].Y;
                    RfemNodeArray[index].Z  = Rh_pt3d[index].Z;


                    //data.SetNode(RfemNodeArray[index]);
                }

                //modification
                //data.FinishModification();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            // Releases interface to RFEM model.
            model = null;

            // Unlocks licence and releases interface to RFEM application.
            if (app != null)
            {
                //app.UnlockLicense();
                app = null;
            }

            // Cleans Garbage Collector and releases all cached COM interfaces.
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();

            List <Dlubal.RFEM5.Node> RfemNodeList        = RfemNodeArray.OfType <Dlubal.RFEM5.Node>().ToList(); // this isn't going to be fast.
            List <RfemNodeType>      RfemNodeGHParamList = new List <RfemNodeType>();

            // List<RfemNodeType> aaaa = new List<RfemNodeType>();

            foreach (Dlubal.RFEM5.Node rfemNode in RfemNodeList)
            {
                RfemNodeType rfemNodeWrapper = new RfemNodeType(rfemNode);
                RfemNodeGHParamList.Add(rfemNodeWrapper);
            }

            return(RfemNodeList);
        }
예제 #9
0
        private List <Rhino.Geometry.Curve> CreateRhinoCurves(string selectedLineList)
        {
            //defining the list with lines that will have to be returned later on
            List <Rhino.Geometry.Curve> rhOutputCurves = new List <Rhino.Geometry.Curve>();


            // Gets interface to running RFEM application.
            app = Marshal.GetActiveObject("RFEM5.Application") as IApplication;
            // Locks RFEM licence
            app.LockLicense();

            // Gets interface to active RFEM model.
            model = app.GetActiveModel();

            // Gets interface to model data.
            IModelData data = model.GetModelData();

            //Create new array for Rhino Curve objects
            List <Rhino.Geometry.Curve> rhinoLineList = new List <Rhino.Geometry.Curve>();

            //Create new array for Rhino point objects
            List <Rhino.Geometry.Point3d> rhinoPointArray = new List <Rhino.Geometry.Point3d>();


            try
            {
                for (int index = 0; index < data.GetLineCount(); index++)
                {
                    Dlubal.RFEM5.Line currentLine = data.GetLine(index, ItemAt.AtIndex).GetData();

                    // the code below converts string describing nodes used in line definition into
                    // list fo all used node numbers. e.g. converts "1,2,4-7,9" into "1,2,4,5,6,7,9"
                    string     lineNodes = currentLine.NodeList;
                    List <int> nodesList = new List <int>();

                    foreach (string tempLineNode in lineNodes.Split(','))
                    {
                        if (tempLineNode.Contains('-'))
                        {
                            string[] tempLineNodeDashes = new string[2];
                            tempLineNodeDashes = tempLineNode.Split('-');
                            int startNumber = Int32.Parse(tempLineNodeDashes[0]);
                            int endNumber   = Int32.Parse(tempLineNodeDashes[1]);

                            for (int i = startNumber; i <= endNumber; i++)
                            {
                                nodesList.Add(i);
                            }
                        }
                        else
                        {
                            nodesList.Add(Int32.Parse(tempLineNode));
                        }
                    }

                    //currently component only reads "polyline" type from RFEM, i.e. straight lines

                    if (currentLine.Type == LineType.PolylineType)
                    {
                        for (int i = 0; i < nodesList.Count - 1; i++)
                        {
                            //getting data for start point and end point from RFEM
                            Dlubal.RFEM5.Node rfemStartPoint = data.GetNode(nodesList[i], ItemAt.AtNo).GetData();
                            Dlubal.RFEM5.Node rfemEndPoint   = data.GetNode(nodesList[i + 1], ItemAt.AtNo).GetData();

                            //creating Rhino Objects
                            Point3d rhinoStartPoint = new Point3d(rfemStartPoint.X, rfemStartPoint.Y, rfemStartPoint.Z);
                            Point3d rhinoEndPoint   = new Point3d(rfemEndPoint.X, rfemEndPoint.Y, rfemEndPoint.Z);

                            Rhino.Geometry.LineCurve currentRhinoCurve = new Rhino.Geometry.LineCurve(rhinoStartPoint, rhinoEndPoint);

                            rhOutputCurves.Add(currentRhinoCurve);
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // Releases interface to RFEM model.
            model = null;

            // Unlocks licence and releases interface to RFEM application.
            if (app != null)
            {
                app.UnlockLicense();
                app = null;
            }

            // Cleans Garbage Collector and releases all cached COM interfaces.
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();

            //list with all Rhino Curves is prepared for output
            return(rhOutputCurves);
        }
        private List <Dlubal.RFEM5.Surface> CreateRfemSurfaces(List <Rhino.Geometry.Brep> Rh_Srf, double srfThicknessInMethod, string srfMaterialTextDescription, string srfCommentMethodIn)
        {
            //cycling through all Surfaces and creating RFEM objects;
            int nodeCount    = 1;
            int lineCount    = 1;
            int surfaceCount = 1;

            //list for curves describing surface edges
            List <Rhino.Geometry.Curve> RhSimpleLines = new List <Rhino.Geometry.Curve>();

            //lists for nodes, lines and surfaces to be created
            List <Dlubal.RFEM5.Node>    RfemNodeList    = new List <Dlubal.RFEM5.Node>();
            List <Dlubal.RFEM5.Line>    RfemLineList    = new List <Dlubal.RFEM5.Line>();
            List <Dlubal.RFEM5.Surface> RfemSurfaceList = new List <Dlubal.RFEM5.Surface>();

            //---- Interface with RFEM, getting available element numbers ----
            #region Interface with RFEM, getting available element numbers

            // Gets interface to running RFEM application.
            IApplication app = Marshal.GetActiveObject("RFEM5.Application") as IApplication;
            // Locks RFEM licence
            app.LockLicense();

            // Gets interface to active RFEM model.
            IModel model = app.GetActiveModel();

            // Gets interface to model data.
            IModelData data = model.GetModelData();

            // Gets Max node, line , surface support numbers
            int currentNewNodeNo     = data.GetLastObjectNo(ModelObjectType.NodeObject) + 1;
            int currentNewLineNo     = data.GetLastObjectNo(ModelObjectType.LineObject) + 1;
            int currentNewSurfaceNo  = data.GetLastObjectNo(ModelObjectType.SurfaceObject) + 1;
            int currentNewMaterialNo = data.GetLastObjectNo(ModelObjectType.MaterialObject) + 1;

            #endregion

            // Defines material used for all surfaces
            Dlubal.RFEM5.Material material = new Dlubal.RFEM5.Material();
            material.No        = currentNewMaterialNo;
            material.TextID    = srfMaterialTextDescription;
            material.ModelType = MaterialModelType.IsotropicLinearElasticType;



            //start cycling through all surfaces
            foreach (Rhino.Geometry.Brep RhSingleSurface in Rh_Srf)
            {
                #region simplification of perimeter edges
                // clearing previous surface data before starting to work on new surface:
                RhSimpleLines.Clear();

                //simplifying edges - adding to array;
                Rhino.Geometry.Curve[] curves = RhSingleSurface.DuplicateEdgeCurves(true);
                curves = Rhino.Geometry.Curve.JoinCurves(curves);

                foreach (Rhino.Geometry.Curve RhSingleCurve in curves)
                {
                    if (RhSingleCurve.IsPolyline())
                    {
                        if (RhSingleCurve.SpanCount == 1)
                        {
                            //if this is simple linear line
                            RhSimpleLines.Add(RhSingleCurve);
                        }
                        else
                        {
                            foreach (Rhino.Geometry.Curve explodedSurface in RhSingleCurve.DuplicateSegments())
                            {
                                //if this is polyline
                                RhSimpleLines.Add(explodedSurface);
                            }
                        }
                    }

                    else
                    {
                        foreach (Rhino.Geometry.Curve explodedLine in RhSingleCurve.ToPolyline(0, 0, 3.14, 1, 0, 0, 0, segmentLength, true).DuplicateSegments())
                        {
                            //if this is curved lines
                            RhSimpleLines.Add(explodedLine);
                        }
                    }


                    #endregion

                    int surfaceNodeCounter = 0; //counts nodes witin one surface. nodeCount counts overall nodes in model
                    int surfaceLineCounter = 0; // counts lines (edges) for one surface, lineCount counts overall lines in model

                    //cycling through perimeter of the surface and defining lines surface
                    #region Defining nodes and lines for one surface

                    for (int i = 0; i < RhSimpleLines.Count; i++)
                    {
                        //defining variables needed to store geometry and RFEM info
                        Rhino.Geometry.Point3d startPoint = RhSimpleLines[i].PointAtStart;
                        Rhino.Geometry.Point3d endPoint   = RhSimpleLines[i].PointAtEnd;

                        //if this is the first line for the surface
                        if (i == 0)
                        {
                            // defining start and end nodes of the line
                            Dlubal.RFEM5.Node tempCurrentStartNode = new Dlubal.RFEM5.Node();
                            Dlubal.RFEM5.Node tempCurrentEndNode   = new Dlubal.RFEM5.Node();

                            tempCurrentStartNode.No = currentNewNodeNo;
                            tempCurrentStartNode.X  = Math.Round(startPoint.X, 5);
                            tempCurrentStartNode.Y  = Math.Round(startPoint.Y, 5);
                            tempCurrentStartNode.Z  = Math.Round(startPoint.Z, 5);

                            tempCurrentEndNode.No = currentNewNodeNo + 1;
                            tempCurrentEndNode.X  = Math.Round(endPoint.X, 5);
                            tempCurrentEndNode.Y  = Math.Round(endPoint.Y, 5);
                            tempCurrentEndNode.Z  = Math.Round(endPoint.Z, 5);

                            RfemNodeList.Add(tempCurrentStartNode);
                            RfemNodeList.Add(tempCurrentEndNode);

                            // defining line
                            Dlubal.RFEM5.Line tempCurrentLine = new Dlubal.RFEM5.Line();
                            tempCurrentLine.No       = currentNewLineNo;
                            tempCurrentLine.Type     = LineType.PolylineType;
                            tempCurrentLine.NodeList = $"{tempCurrentStartNode.No}, {tempCurrentEndNode.No}";

                            RfemLineList.Add(tempCurrentLine);

                            nodeCount          = nodeCount + 2;
                            surfaceNodeCounter = surfaceNodeCounter + 2;
                            lineCount++;
                            surfaceLineCounter++;

                            currentNewNodeNo = currentNewNodeNo + 2;
                            currentNewLineNo++;
                        }
                        //if this is the last node for the surface
                        else if (i == RhSimpleLines.Count - 1)
                        {
                            //no need to define new node as these are both already defined
                            //create line connecting previous node with first node for surface
                            // defining start and end nodes of the line
                            Dlubal.RFEM5.Line tempCurrentLine = new Dlubal.RFEM5.Line();

                            tempCurrentLine.No   = currentNewLineNo;
                            tempCurrentLine.Type = LineType.PolylineType;

                            tempCurrentLine.NodeList = $"{RfemNodeList[RfemNodeList.Count - 1].No}, {RfemNodeList[RfemNodeList.Count - surfaceNodeCounter].No}";
                            RfemLineList.Add(tempCurrentLine);
                            lineCount++;
                            surfaceLineCounter++;
                            currentNewLineNo++;
                        }
                        else
                        {
                            //if this is just a node somewhere on edges
                            //defining end node of line
                            Dlubal.RFEM5.Node tempCurrentEndNode = new Dlubal.RFEM5.Node();
                            // defining start and end nodes of the line
                            Dlubal.RFEM5.Line tempCurrentLine = new Dlubal.RFEM5.Line();


                            tempCurrentEndNode.No = currentNewNodeNo;
                            tempCurrentEndNode.X  = Math.Round(endPoint.X, 5);
                            tempCurrentEndNode.Y  = Math.Round(endPoint.Y, 5);
                            tempCurrentEndNode.Z  = Math.Round(endPoint.Z, 5);

                            RfemNodeList.Add(tempCurrentEndNode);

                            tempCurrentLine.No   = currentNewLineNo;
                            tempCurrentLine.Type = LineType.PolylineType;

                            tempCurrentLine.NodeList = $"{RfemNodeList[RfemNodeList.Count - 2].No}, {RfemNodeList[RfemNodeList.Count - 1].No}";
                            RfemLineList.Add(tempCurrentLine);

                            nodeCount++;
                            surfaceNodeCounter++;
                            lineCount++;
                            surfaceLineCounter++;

                            currentNewNodeNo++;
                            currentNewLineNo++;
                        }
                    }

                    #endregion

                    //defines surface data
                    #region Defining data of the surface to be written

                    // start with making a string with "list" of lines forming the surface
                    int    surfaceFirstLine = currentNewLineNo - RhSimpleLines.Count;
                    int    surfaceLastLine  = surfaceFirstLine + RhSimpleLines.Count - 1;
                    string surfaceLineList  = "";

                    for (int i = surfaceFirstLine; i < surfaceLastLine; i++)
                    {
                        surfaceLineList = surfaceLineList + i.ToString() + ",";
                    }
                    surfaceLineList = surfaceLineList + surfaceLastLine.ToString();

                    // defining RFEM parameter of surface
                    Dlubal.RFEM5.Surface surfaceData = new Dlubal.RFEM5.Surface();
                    surfaceData.No               = currentNewSurfaceNo;
                    surfaceData.MaterialNo       = material.No;
                    surfaceData.GeometryType     = SurfaceGeometryType.PlaneSurfaceType;
                    surfaceData.BoundaryLineList = surfaceLineList;
                    surfaceData.Comment          = srfCommentMethodIn;
                    // if -1 is input as thickness, surface is created as rigid, otherwise it is "standard"
                    if (srfThicknessInMethod == -1)
                    {
                        surfaceData.StiffnessType = SurfaceStiffnessType.RigidStiffnessType;
                    }
                    else if (srfThicknessInMethod == 0)
                    {
                        surfaceData.StiffnessType = SurfaceStiffnessType.NullStiffnessType;
                    }
                    else
                    {
                        surfaceData.StiffnessType      = SurfaceStiffnessType.StandardStiffnessType;
                        surfaceData.Thickness.Constant = srfThicknessInMethod;
                    }

                    //adding surface to elements to be written
                    RfemSurfaceList.Add(surfaceData);

                    surfaceCount++;
                    currentNewSurfaceNo++;

                    #endregion
                }
            }

            //try writing the surface;
            #region Writing the surface and releasing RFEM model

            try
            {
                //prepares model for modification.
                data.PrepareModification();
                data.SetMaterial(material);

                //This version writes nodes one-by-one because the data.SetNodes() for array appears not to be working
                foreach (Node currentRfemNode in RfemNodeList)
                {
                    data.SetNode(currentRfemNode);
                }

                //This version writes lines one-by-one because the data.SetLines() for array appears not to be working
                foreach (Dlubal.RFEM5.Line currentRfemLine in RfemLineList)
                {
                    data.SetLine(currentRfemLine);
                }

                //This version writes lines one-by-one because the data.SetLines() for array appears not to be working
                foreach (Dlubal.RFEM5.Surface currentRfemSurface in RfemSurfaceList)
                {
                    data.SetSurface(currentRfemSurface);
                }

                //finishes modifications - regenerates numbering etc.
                data.FinishModification();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error - Surface Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //resetting counters;
            nodeCount    = 1;
            lineCount    = 1;
            surfaceCount = 1;


            // Releases interface to RFEM model.
            model = null;

            // Unlocks licence and releases interface to RFEM application.
            if (app != null)
            {
                app.UnlockLicense();
                app = null;
            }

            // Cleans Garbage Collector and releases all cached COM interfaces.
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();

            #endregion



            //output 'success' as true
            writeSuccess = true;

            ///the Surfaces below outputs created RFEM surfaces in output parameter
            ///current funcionality does not use this
            return(RfemSurfaceList);
        }
예제 #11
0
        private List <Dlubal.RFEM5.Line> CreateRfemLines(List <Rhino.Geometry.Curve> Rh_Crv, Dlubal.RFEM5.LineSupport rfemLineSupportMethodIn, string commentsListMethodIn)
        {
            //defining variables needed to store geometry and RFEM info
            Rhino.Geometry.Point3d   startPoint;
            Rhino.Geometry.Point3d   endPoint;
            List <Dlubal.RFEM5.Node> RfemNodeList = new List <Dlubal.RFEM5.Node>();
            List <Dlubal.RFEM5.Line> RfemLineList = new List <Dlubal.RFEM5.Line>();
            string createdLinesList = "";

            //---- Rhino geometry simplification and creating a list of simple straight lines ----
            #region Rhino geometry processing

            //start by reducing the input curves to simple lines with start/end points
            List <Rhino.Geometry.Curve> RhSimpleLines = new List <Rhino.Geometry.Curve>();

            foreach (Rhino.Geometry.Curve RhSingleCurve in Rh_Crv)
            {
                if (RhSingleCurve.IsPolyline())
                {
                    if (RhSingleCurve.SpanCount == 1)
                    {
                        // if line is a simple straight line
                        RhSimpleLines.Add(RhSingleCurve);
                    }
                    else
                    {
                        foreach (Rhino.Geometry.Curve explodedLine in RhSingleCurve.DuplicateSegments())
                        {
                            // if line is polyline, then it gets exploded
                            RhSimpleLines.Add(explodedLine);
                        }
                    }
                }

                else
                {
                    foreach (Rhino.Geometry.Curve explodedLine in RhSingleCurve.ToPolyline(0, 0, 3.14, 1, 0, 0, 0, segmentLengthInput, true).DuplicateSegments())
                    {
                        // if line is a an arc or nurbs or have any curvature, it gets simplified
                        RhSimpleLines.Add(explodedLine);
                    }
                }
            }
            #endregion

            //---- Interface with RFEM, getting available element numbers ----
            #region Gets interface with RFEM and currently available element numbers

            // Gets interface to running RFEM application.
            IApplication app = Marshal.GetActiveObject("RFEM5.Application") as IApplication;
            // Locks RFEM licence
            app.LockLicense();

            // Gets interface to active RFEM model.
            IModel model = app.GetActiveModel();

            // Gets interface to model data.
            IModelData data = model.GetModelData();

            // Gets Max node, line , line support numbers
            int currentNewNodeNo        = data.GetLastObjectNo(ModelObjectType.NodeObject) + 1;
            int currentNewLineNo        = data.GetLastObjectNo(ModelObjectType.LineObject) + 1;
            int currentNewLineSupportNo = data.GetLastObjectNo(ModelObjectType.LineSupportObject) + 1;

            #endregion

            //----- cycling through all lines and creating RFEM objects ----
            #region Creates RFEM node and line elements

            for (int i = 0; i < RhSimpleLines.Count; i++)
            {
                // defining start and end nodes of the line
                Dlubal.RFEM5.Node tempCurrentStartNode = new Dlubal.RFEM5.Node();
                Dlubal.RFEM5.Node tempCurrentEndNode   = new Dlubal.RFEM5.Node();

                startPoint = RhSimpleLines[i].PointAtStart;
                endPoint   = RhSimpleLines[i].PointAtEnd;

                tempCurrentStartNode.No = currentNewNodeNo;
                tempCurrentStartNode.X  = startPoint.X;
                tempCurrentStartNode.Y  = startPoint.Y;
                tempCurrentStartNode.Z  = startPoint.Z;

                tempCurrentEndNode.No = currentNewNodeNo + 1;
                tempCurrentEndNode.X  = endPoint.X;
                tempCurrentEndNode.Y  = endPoint.Y;
                tempCurrentEndNode.Z  = endPoint.Z;

                RfemNodeList.Add(tempCurrentStartNode);
                RfemNodeList.Add(tempCurrentEndNode);

                // defining line
                Dlubal.RFEM5.Line tempCurrentLine = new Dlubal.RFEM5.Line();

                tempCurrentLine.No       = currentNewLineNo;
                tempCurrentLine.Type     = LineType.PolylineType;
                tempCurrentLine.Comment  = commentsListMethodIn;
                tempCurrentLine.NodeList = $"{tempCurrentStartNode.No}, {tempCurrentEndNode.No}";

                RfemLineList.Add(tempCurrentLine);


                // adding line numbers to list with all lines
                if (i == RhSimpleLines.Count)
                {
                    createdLinesList = createdLinesList + currentNewLineNo.ToString();
                }
                else
                {
                    createdLinesList = createdLinesList + currentNewLineNo.ToString() + ",";
                }

                // increasing counters for numbering
                currentNewLineNo++;
                currentNewNodeNo = currentNewNodeNo + 2;
            }
            #endregion

            //----- Writing nodes and lines to RFEM ----
            #region Write nodes, lines and supports to RFEM

            try
            {
                // modification - set model in modification mode, new information can be written
                data.PrepareModification();

                //This version writes lines one-by-one because the data.SetNodes() for array appears not to be working
                //data.SetNodes(RfemNodeArray);
                foreach (Node currentRfemNode in RfemNodeList)
                {
                    data.SetNode(currentRfemNode);
                }

                //This version writes lines one-by-one because the data.SetLines() for array appears not to be working
                foreach (Dlubal.RFEM5.Line currentRfemLine in RfemLineList)
                {
                    data.SetLine(currentRfemLine);
                }

                //Definition of line supports - only is there is input for support:
                if (rfemLineSupportInput.No != -1)
                {
                    rfemLineSupportMethodIn.No       = currentNewLineSupportNo;
                    rfemLineSupportMethodIn.LineList = createdLinesList;
                    data.SetLineSupport(ref rfemLineSupportMethodIn);
                }

                // finish modification - RFEM regenerates the data
                data.FinishModification();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error - Line Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            #endregion


            // Releases interface to RFEM model.
            #region Releases interface to RFEM

            model = null;

            // Unlocks licence and releases interface to RFEM application.
            if (app != null)
            {
                app.UnlockLicense();
                app = null;
            }

            // Cleans Garbage Collector and releases all cached COM interfaces.
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();


            #endregion

            //output 'success' as true and return the list of the lines;
            writeSuccess = true;
            return(RfemLineList);
        }
예제 #12
0
파일: Panel.cs 프로젝트: BHoM/RFEM_Toolkit
        /***************************************************/
        /**** Private methods                           ****/
        /***************************************************/

        private bool CreateCollection(IEnumerable <Panel> panels)
        {
            if (panels.Count() > 0)
            {
                int          panelIdNum = 0;
                List <Panel> panelList  = panels.ToList();
                rf.Surface[] rfSurfaces = new rf.Surface[panelList.Count()];

                for (int i = 0; i < panels.Count(); i++)
                {
                    panelIdNum = GetAdapterId <int>(panelList[i]);

                    //get ids outside of BHoM process - might need to be changed
                    int lastLineId = modelData.GetLastObjectNo(rf.ModelObjectType.LineObject);


                    int[] boundaryIdArr = new int[panelList[i].ExternalEdges.Count()];

                    //create outline
                    List <string> outlineNodeList = new List <string>();
                    foreach (Edge e in panelList[i].ExternalEdges)
                    {
                        //create rfem nodes, i.e. bhom points - NOTE: RFEM will remove the coincident points itself leaving jumps in node numbering ! 1,2,4,6,8,10,...
                        Line edgeAsLine = e.Curve as Line;

                        rf.Node rfNode1 = new rf.Node
                        {
                            No = (int)this.NextFreeId(typeof(Node)),
                            X  = edgeAsLine.Start.X,
                            Y  = edgeAsLine.Start.Y,
                            Z  = edgeAsLine.Start.Z
                        };
                        modelData.SetNode(rfNode1);

                        outlineNodeList.Add(rfNode1.No.ToString());
                    }
                    outlineNodeList.Add(outlineNodeList[0]);

                    rf.Line outline = new rf.Line()
                    {
                        No       = lastLineId + 1,
                        Type     = rf.LineType.PolylineType,
                        NodeList = String.Join(",", outlineNodeList)
                    };
                    modelData.SetLine(outline);


                    rfSurfaces[i] = panelList[i].ToRFEM(panelIdNum, new int[] { outline.No });

                    if (rfSurfaces[i].StiffnessType == rf.SurfaceStiffnessType.StandardStiffnessType)
                    {
                        modelData.SetSurface(rfSurfaces[i]);
                    }
                    else
                    {
                        rf.SurfaceStiffness stiffness = panelList[i].Property.ToRFEM();
                        rfSurfaces[i].Thickness.Constant = stiffness.Thickness;
                        rf.ISurface srf = modelData.SetSurface(rfSurfaces[i]);
                        rf.IOrthotropicThickness ortho = srf.GetOrthotropicThickness();
                        ortho.SetData(stiffness);
                    }
                }
            }

            return(true);
        }