public RFSurface(Dlubal.RFEM5.Surface surface, RFLine[] edges, RFOpening[] openings) { Comment = surface.Comment; ID = surface.ID; IsGenerated = surface.IsGenerated; IsValid = surface.IsValid; No = surface.No; Tag = surface.Tag; Area = surface.Area; BoundaryLineCount = surface.BoundaryLineCount; BoundaryLineList = surface.BoundaryLineList; ControlPoints = surface.ControlPoints.ToPoint3d(); Eccentricity = surface.Eccentricity; GeometryType = surface.GeometryType; IntegratedLineCount = surface.IntegratedLineCount; IntegratedLineList = surface.IntegratedLineList; IntegratedNodeCount = surface.IntegratedNodeCount; IntegratedNodeList = surface.IntegratedNodeList; MaterialNo = surface.MaterialNo; SetIntegratedObjects = surface.SetIntegratedObjects; StiffnessType = surface.StiffnessType; ThicknessType = surface.Thickness.Type; Thickness = surface.Thickness.Constant; Edges = edges; Openings = openings; ToModify = false; ToDelete = false; }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static rf.Surface ToRFEM(this Panel panel, int panelId, int[] boundaryIdArr) { rf.Surface rfSurface = new rf.Surface(); rfSurface.No = panelId; rfSurface.GeometryType = rf.SurfaceGeometryType.PlaneSurfaceType;//several other types are available! rfSurface.BoundaryLineList = string.Join <int>(",", boundaryIdArr); int materialId = panel.Property.Material.AdapterId <int>(typeof(RFEMId)); rfSurface.MaterialNo = materialId; if (panel.Property.GetType() == typeof(ConstantThickness)) { //do simple panel rfSurface.StiffnessType = rf.SurfaceStiffnessType.StandardStiffnessType;//several other types available rfSurface.Thickness.Constant = (panel.Property as ConstantThickness).Thickness; } else { rfSurface.StiffnessType = rf.SurfaceStiffnessType.OrthotropicStiffnessType; } return(rfSurface); }
/***************************************************/ 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); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static Panel FromRFEM(this rf.Surface surface, ISurfaceProperty surfaceProperty) { ICurve outline = null; string[] boundLineList = surface.BoundaryLineList.Split(','); List <Opening> openings = null; Panel bhPanel = Engine.Structure.Create.Panel(outline, openings, surfaceProperty); bhPanel.SetAdapterId(typeof(RFEMId), surface.No); return(bhPanel); }
public RFSurface(Dlubal.RFEM5.Surface surface, RFLine[] edges, RFOpening[] openings, Dlubal.RFEM5.SurfaceAxes axes) : this(surface, edges, openings) { SurfaceAxes = new SurfaceAxes(axes); }
public RFSurface(Dlubal.RFEM5.Surface surface) : this(surface, null, null) { }
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); }
/***************************************************/ /**** 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); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private List <Panel> ReadPanels(List <string> ids = null) { List <Panel> panelList = new List <Panel>(); ISurfaceProperty surfaceProperty; if (ids == null) { foreach (rf.Surface surface in modelData.GetSurfaces()) { if (surface.GeometryType != rf.SurfaceGeometryType.PlaneSurfaceType) { Engine.Base.Compute.RecordError("Only plane surface types are supported at the moment"); } List <Edge> edgeList = GetEdgesFromRFEMSurface(surface); IMaterialFragment material = modelData.GetMaterial(surface.MaterialNo, rf.ItemAt.AtNo).GetData().FromRFEM(); if (surface.StiffnessType == rf.SurfaceStiffnessType.StandardStiffnessType) { surfaceProperty = new ConstantThickness { Thickness = surface.Thickness.Constant, Material = material }; } else if (surface.StiffnessType == rf.SurfaceStiffnessType.OrthotropicStiffnessType) { rf.ISurface s = modelData.GetSurface(surface.No, rf.ItemAt.AtNo); rf.IOrthotropicThickness ortho = s.GetOrthotropicThickness(); rf.SurfaceStiffness stiffness = ortho.GetData(); surfaceProperty = stiffness.FromRFEM(material); } else { surfaceProperty = null; Engine.Base.Compute.RecordError("could not create surface property of type " + surface.StiffnessType.ToString()); } List <Opening> openings = null; Panel panel = Engine.Structure.Create.Panel(edgeList, openings, surfaceProperty); panelList.Add(panel); } } else { foreach (string id in ids) { rf.Surface surface = modelData.GetSurface(Int32.Parse(id), rf.ItemAt.AtNo).GetData(); if (surface.GeometryType != rf.SurfaceGeometryType.PlaneSurfaceType) { Engine.Base.Compute.RecordError("Only plane surface types are supported at the moment"); } List <Edge> edgeList = GetEdgesFromRFEMSurface(surface); IMaterialFragment material = modelData.GetMaterial(surface.MaterialNo, rf.ItemAt.AtNo).GetData().FromRFEM(); rf.ISurface s = modelData.GetSurface(surface.No, rf.ItemAt.AtNo); rf.IOrthotropicThickness ortho = s.GetOrthotropicThickness(); rf.SurfaceStiffness stiffness = ortho.GetData(); surfaceProperty = stiffness.FromRFEM(material); List <Opening> openings = null; Panel panel = Engine.Structure.Create.Panel(edgeList, openings, surfaceProperty); panelList.Add(panel); } } return(panelList); }