/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateCollection(IEnumerable <Bar> bars) { if (bars.Count() > 0) { int barIdNum = 0; int lineIdNum = 0; List <Bar> barList = bars.ToList(); rf.Member[] rfBars = new rf.Member[barList.Count()]; for (int i = 0; i < bars.Count(); i++) { barIdNum = GetAdapterId <int>(barList[i]); //create line lineIdNum = modelData.GetLineCount() + 1; rf.Line centreLine = new rf.Line(); int startNodeId = GetAdapterId <int>(barList[i].StartNode); int endNodeId = GetAdapterId <int>(barList[i].EndNode); centreLine.NodeList = String.Join(",", new int[] { startNodeId, endNodeId }); centreLine.Type = rf.LineType.PolylineType; modelData.SetLine(centreLine); rfBars[i] = barList[i].ToRFEM(barIdNum, lineIdNum); modelData.SetMember(rfBars[i]); } //modelData.SetMembers(rfBars); } return(true); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateCollection(IEnumerable <RigidLink> links) { if (links.Count() > 0) { int linkIdNum = 0; int lineIdNum = 0; List <RigidLink> linkList = links.ToList(); rf.Member[] rfLinks = new rf.Member[linkList.Count()]; for (int i = 0; i < links.Count(); i++) { linkIdNum = GetAdapterId <int>(linkList[i]); //check for multiple secondary nodes if (linkList[i].SecondaryNodes.Count > 1) { Engine.Base.Compute.RecordWarning("Multiple secondary nodes detected! Link no. " + linkIdNum + " was created using only the first secondary node!"); } //create line lineIdNum = modelData.GetLineCount() + 1; rf.Line centreLine = new rf.Line(); int startNodeId = GetAdapterId <int>(linkList[i].PrimaryNode); int endNodeId = GetAdapterId <int>(linkList[i].SecondaryNodes[0]); centreLine.NodeList = String.Join(",", new int[] { startNodeId, endNodeId }); centreLine.Type = rf.LineType.PolylineType; modelData.SetLine(centreLine); rf.Member rfLink = new rf.Member(); rfLink.No = linkIdNum; rfLink.LineNo = lineIdNum; rfLink.Type = rf.MemberType.Rigid; LinkConstraint lc = linkList[0].Constraint; if (lc != null) { if (lc.XtoX != true || lc.YtoY != true || lc.ZtoZ != true || lc.XXtoXX != true || lc.YYtoYY != true || lc.ZZtoZZ != true) { Engine.Base.Compute.RecordWarning("Hinges on RigidLinks are not supported. Member no. " + linkIdNum + " created as fixed!"); } } modelData.SetMember(rfLink); } //modelData.SetMembers(rfBars); } return(true); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static rf.Member ToRFEM(this Bar bar, int barId, int lineId) { rf.Member rfBar = new rf.Member(); rfBar.No = barId; rfBar.LineNo = lineId; rfBar.StartCrossSectionNo = bar.SectionProperty.AdapterId <int>(typeof(RFEMId)); rf.Rotation rotation = new rf.Rotation(); rotation.Angle = bar.OrientationAngle; rotation.Type = rf.RotationType.Angle; rfBar.Rotation = rotation; return(rfBar); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static Bar FromRFEM(this rf.Member member, rf.Line line, ISectionProperty sectionProperty) { rf.Point3D sPt = line.ControlPoints.First(); rf.Point3D ePt = line.ControlPoints.Last(); BH.oM.Geometry.Line ln = new oM.Geometry.Line() { Start = new oM.Geometry.Point() { X = sPt.X, Y = sPt.Y, Z = sPt.Z }, End = new oM.Geometry.Point() { X = ePt.X, Y = ePt.Y, Z = ePt.Z } }; Bar bhBar = BH.Engine.Structure.Create.Bar(ln, sectionProperty, member.Rotation.Angle); bhBar.SetAdapterId(typeof(RFEMId), member.No); return(bhBar); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private List <Bar> ReadBars(List <string> ids = null) { List <Bar> barList = new List <Bar>(); rf.Line line; ISectionProperty sectionProperty; if (ids == null) { foreach (rf.Member member in modelData.GetMembers()) { if (member.Type == rf.MemberType.Rigid | member.Type == rf.MemberType.CouplingHingeHinge | member.Type == rf.MemberType.CouplingHingeRigid | member.Type == rf.MemberType.CouplingRigidHinge | member.Type == rf.MemberType.CouplingRigidRigid) { continue; } line = modelData.GetLine(member.LineNo, rf.ItemAt.AtNo).GetData(); int firstSectionNo = 0; int secondSectionNo = 0; if (member.StartCrossSectionNo == 0 & member.EndCrossSectionNo != 0) { firstSectionNo = member.EndCrossSectionNo; } else { firstSectionNo = member.StartCrossSectionNo; secondSectionNo = member.EndCrossSectionNo; } if (firstSectionNo == secondSectionNo) { secondSectionNo = 0; } sectionProperty = GetSectionProperty(firstSectionNo); //check for tapered section if (secondSectionNo != 0) { ISectionProperty startSectionProperty = sectionProperty; ISectionProperty endSectionProperty = GetSectionProperty(secondSectionNo); sectionProperty = GetTaperedSectionProperty(startSectionProperty, endSectionProperty); } barList.Add(member.FromRFEM(line, sectionProperty)); } } else { foreach (string id in ids) { rf.Member member = modelData.GetMember(Int32.Parse(id), rf.ItemAt.AtNo).GetData(); if (member.Type == rf.MemberType.Rigid) { continue; } line = modelData.GetLine(member.LineNo, rf.ItemAt.AtNo).GetData(); int firstSectionNo = 0; int secondSectionNo = 0; if (member.StartCrossSectionNo == 0 & member.EndCrossSectionNo != 0) { firstSectionNo = member.EndCrossSectionNo; } else { firstSectionNo = member.StartCrossSectionNo; secondSectionNo = member.EndCrossSectionNo; } sectionProperty = GetSectionProperty(firstSectionNo); //check for tapered section if (secondSectionNo != 0) { ISectionProperty startSectionProperty = sectionProperty; ISectionProperty endSectionProperty = GetSectionProperty(secondSectionNo); sectionProperty = GetTaperedSectionProperty(startSectionProperty, endSectionProperty); } barList.Add(member.FromRFEM(line, sectionProperty)); } } return(barList); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private List <RigidLink> ReadLinks(List <string> ids = null) { List <RigidLink> linkList = new List <RigidLink>(); rf.Line line; if (ids == null) { rf.Member[] allLinks = modelData.GetMembers().Where(x => (x.Type == rf.MemberType.Rigid) | (x.Type == rf.MemberType.CouplingHingeHinge) | (x.Type == rf.MemberType.CouplingHingeRigid) | (x.Type == rf.MemberType.CouplingRigidHinge) | (x.Type == rf.MemberType.CouplingRigidRigid)).ToArray(); foreach (rf.Member link in allLinks) { line = modelData.GetLine(link.LineNo, rf.ItemAt.AtNo).GetData(); rf.Point3D sPt = line.ControlPoints.First(); rf.Point3D ePt = line.ControlPoints.Last(); Node startNode = new Node { Position = new oM.Geometry.Point() { X = sPt.X, Y = sPt.Y, Z = sPt.Z } }; Node endNode = new Node { Position = new oM.Geometry.Point() { X = ePt.X, Y = ePt.Y, Z = ePt.Z } }; RigidLink bhLink = new RigidLink { PrimaryNode = startNode, SecondaryNodes = new List <Node> { endNode } }; if (link.StartHingeNo == 0 && link.EndHingeNo == 0) { //no hinges set, then all fixed bhLink.Constraint = Engine.Structure.Create.LinkConstraintFixed(); } else { Engine.Base.Compute.RecordWarning("Hinges on Rigid links are not supported. See member No. " + link.No.ToString()); } bhLink.SetAdapterId(typeof(RFEMId), link.No); linkList.Add(bhLink); } } else { foreach (string id in ids) { rf.Member link = modelData.GetMember(Int32.Parse(id), rf.ItemAt.AtNo).GetData(); if (link.Type != rf.MemberType.Rigid | link.Type != rf.MemberType.CouplingHingeHinge | link.Type != rf.MemberType.CouplingHingeRigid | link.Type != rf.MemberType.CouplingRigidHinge | link.Type != rf.MemberType.CouplingRigidRigid) { continue; } line = modelData.GetLine(link.LineNo, rf.ItemAt.AtNo).GetData(); rf.Point3D sPt = line.ControlPoints.First(); rf.Point3D ePt = line.ControlPoints.Last(); Node startNode = new Node { Position = new oM.Geometry.Point() { X = sPt.X, Y = sPt.Y, Z = sPt.Z } }; Node endNode = new Node { Position = new oM.Geometry.Point() { X = ePt.X, Y = ePt.Y, Z = ePt.Z } }; RigidLink bhLink = new RigidLink { PrimaryNode = startNode, SecondaryNodes = new List <Node> { endNode } }; if (link.StartHingeNo == 0 && link.EndHingeNo == 0) { //no hinges set, then all fixed bhLink.Constraint.XtoX = true; bhLink.Constraint.YtoY = true; bhLink.Constraint.ZtoZ = true; bhLink.Constraint.XXtoXX = true; bhLink.Constraint.YYtoYY = true; bhLink.Constraint.ZZtoZZ = true; } else { Engine.Base.Compute.RecordWarning("Hinges on Rigid links are not supported. See member No. " + link.No.ToString()); } bhLink.SetAdapterId(typeof(RFEMId), link.No); linkList.Add(bhLink); } } return(linkList); }
private List <Dlubal.RFEM5.Member> CreateRfemMembers(List <Dlubal.RFEM5.Line> rfemLineMethodIn, string sectionIdMethodIn, string materialIdMethodIn, Dlubal.RFEM5.MemberHinge rfemHingeStartMethodIn, Dlubal.RFEM5.MemberHinge rfemHingeEndMethodIn, double rotationMethodIn, string commentsListMethodIn) { //---- Interface with RFEM, getting available element numbers ---- #region Estabilishing connection 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 , line support numbers int currentNewMemberNo = data.GetLastObjectNo(ModelObjectType.MemberObject) + 1; int currentNewSectionNo = data.GetLastObjectNo(ModelObjectType.CrossSectionObject) + 1; int currentNewMaterialNo = data.GetLastObjectNo(ModelObjectType.MaterialObject) + 1; int currentNewHingeNo = data.GetLastObjectNo(ModelObjectType.MemberHingeObject) + 1; #endregion //---- Defining material, cross section and releases ---- #region Defining material, cross section and releases //define material Dlubal.RFEM5.Material material = new Dlubal.RFEM5.Material(); material.No = currentNewMaterialNo; material.TextID = materialIdMethodIn; material.ModelType = MaterialModelType.IsotropicLinearElasticType; //define cross section CrossSection tempCrossSection = new CrossSection(); tempCrossSection.No = currentNewSectionNo; tempCrossSection.TextID = sectionIdMethodIn; tempCrossSection.MaterialNo = currentNewMaterialNo; //define member hinge numbers if (rfemHingeStartInput.No != -1) { rfemHingeStartInput.No = currentNewHingeNo; } if (rfemHingeEndInput.No != -1) { rfemHingeEndMethodIn.No = currentNewHingeNo + 1; } #endregion //---- Process all lines and create members on those ---- #region Processing all lines, creating RFEM member objects for (int i = 0; i < rfemLineMethodIn.Count; i++) { //test if line exists try { data.GetLine(rfemLineMethodIn[i].No, ItemAt.AtNo); } catch { continue; } //assign member properties Dlubal.RFEM5.Member tempMember = new Dlubal.RFEM5.Member(); tempMember.No = currentNewMemberNo; tempMember.LineNo = rfemLineMethodIn[i].No; tempMember.EndCrossSectionNo = currentNewSectionNo; tempMember.StartCrossSectionNo = currentNewSectionNo; tempMember.TaperShape = TaperShapeType.Linear; tempMember.Rotation.Type = RotationType.Angle; tempMember.Rotation.Angle = rotationMethodIn * (Math.PI / 180); if (rfemHingeStartInput.No != -1) { tempMember.StartHingeNo = currentNewHingeNo; } if (rfemHingeEndInput.No != -1) { tempMember.EndHingeNo = currentNewHingeNo + 1; } tempMember.Comment = commentsListMethodIn; // if -1 is input as section, member is created as rigid, otherwise it is "standard" if (sectionIdInput == "-1") { tempMember.Type = MemberType.Rigid; } else if (sectionIdInput == "0") { tempMember.Type = MemberType.NullMember; } else { tempMember.Type = MemberType.Beam; } RfemMemberList.Add(tempMember); currentNewMemberNo++; } #endregion //---- Writing information in RFEM ---- #region Writing info to RFEM try { // modification - set model in modification mode, new information can be written data.PrepareModification(); //set material, cross section and start&end hinges if (sectionIdInput != "-1") { data.SetMaterial(material); data.SetCrossSection(tempCrossSection); } if (rfemHingeStartInput.No != -1) { data.SetMemberHinge(rfemHingeStartInput); } if (rfemHingeEndInput.No != -1) { data.SetMemberHinge(rfemHingeEndMethodIn); } //This version writes members one-by-one because the data.SetNodes() for array appears not to be working //data.SetMembers(RfemMembers); foreach (Member currentRfemMember in RfemMemberList) { data.SetMember(currentRfemMember); } // finish modification - RFEM regenerates the data data.FinishModification(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error - Member Write", MessageBoxButtons.OK, MessageBoxIcon.Error); } #endregion //---- Releases interface to RFEM model ----- #region Releasing 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 member list writeSuccess = true; return(RfemMemberList); }