Esempio n. 1
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static List <RigidLink> SplitRigidLink(RigidLink link)
        {
            List <RigidLink> singleLinks = new List <RigidLink>();

            if (link.SecondaryNodes.Count() <= 1)
            {
                singleLinks.Add(link);
            }
            else
            {
                for (int i = 0; i < link.SecondaryNodes.Count(); i++)
                {
                    RigidLink subLink = BH.Engine.Base.Query.ShallowClone(link);
                    subLink.SecondaryNodes = new List <Node> {
                        link.SecondaryNodes[i]
                    };
                    if (link.Name != "")
                    {
                        subLink.Name = $"{link.Name}:::{i}";
                        subLink.Tags.Add($"BHoM_Link_{link.Name}");
                    }

                    singleLinks.Add(subLink);
                }
            }

            return(singleLinks);
        }
Esempio n. 2
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static List <RigidLink> JoinRigidLink(List <RigidLink> linkList)
        {
            Dictionary <string, RigidLink> joinedList = new Dictionary <string, RigidLink>();

            foreach (RigidLink link in linkList)
            {
                SAP2000Id idFragment = link.FindFragment <SAP2000Id>();
                string    Name       = idFragment.Id.ToString();
                string[]  nameParts  = Name.Split(new[] { ":::" }, StringSplitOptions.None);
                if (nameParts.Count() == 1)
                {
                    joinedList.Add(Name, link);
                }
                else
                {
                    string JoinedName = nameParts[0];
                    if (joinedList.ContainsKey(JoinedName))
                    {
                        joinedList[JoinedName].SecondaryNodes.Add(link.SecondaryNodes[0]);
                    }
                    else
                    {
                        RigidLink newJoinedLink = link.ShallowClone();
                        newJoinedLink.Name = JoinedName;
                        joinedList.Add(JoinedName, newJoinedLink);
                    }
                }
            }

            return(joinedList.Values.ToList());
        }
Esempio n. 3
0
        /***************************************************/

        private bool CreateObject(RigidLink bhLink)
        {
            bool success = true;
            int  retA    = 0;
            int  retB    = 0;

            string name      = "";
            string givenName = "";
            string bhId      = bhLink.CustomData[AdapterId].ToString();

            name = bhId;

            LinkConstraint constraint = bhLink.Constraint;//not used yet
            Node           masterNode = bhLink.MasterNode;
            List <Node>    slaveNodes = bhLink.SlaveNodes;
            bool           multiSlave = slaveNodes.Count() == 1 ? false : true;

            //double XI = masterNode.Position.X;
            //double YI = masterNode.Position.Y;
            //double ZI = masterNode.Position.Z;

            for (int i = 0; i < slaveNodes.Count(); i++)
            {
                //double XJ = slaveNodes[i].Position.X * 1000;//multiply by 1000 to compensate for Etabs strangeness: yes, one end is divided by 1000 the other end is not!
                //double YJ = slaveNodes[i].Position.Y * 1000;
                //double ZJ = slaveNodes[i].Position.Z * 1000;

                name = multiSlave == true ? name + ":::" + i : name;

                //retA = model.LinkObj.AddByCoord(XI, YI, ZI, XJ, YJ, ZJ, ref givenName, false, "Default", name);
                retA = m_model.LinkObj.AddByPoint(masterNode.CustomData[AdapterId].ToString(), slaveNodes[i].CustomData[AdapterId].ToString(), ref givenName, false, constraint.Name, name);
            }

            return(success);
        }
Esempio n. 4
0
        /***************************************************/

        private bool CreateObject(RigidLink bhLink)
        {
            bool success = true;

            List <string> linkIds = new List <string>();
            List <object> guids   = new List <object>();

            LinkConstraint constraint     = bhLink.Constraint;//not used yet
            Node           primaryNode    = bhLink.PrimaryNode;
            List <Node>    secondaryNodes = bhLink.SecondaryNodes;

            ETABSId multiId = new ETABSId();

            for (int i = 0; i < secondaryNodes.Count(); i++)
            {
                string name = "";
                string guid = null;

                m_model.LinkObj.AddByPoint(GetAdapterId <string>(primaryNode), GetAdapterId <string>(secondaryNodes[i]), ref name, false, constraint.DescriptionOrName());
                m_model.LinkObj.GetGUID(name, ref guid);

                linkIds.Add(name);
            }

            multiId.Id = linkIds;
            bhLink.SetAdapterId(multiId);

            return(success);
        }
Esempio n. 5
0
        public static RigidLink Transform(this RigidLink link, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            RigidLink result = link.ShallowClone();

            result.PrimaryNode    = result.PrimaryNode.Transform(transform, tolerance);
            result.SecondaryNodes = result.SecondaryNodes.Select(x => x.Transform(transform, tolerance)).ToList();
            return(result);
        }
Esempio n. 6
0
        /***************************************************/

        public static IGeometry Geometry(this RigidLink link)
        {
            List <IGeometry> lines = new List <IGeometry>();

            foreach (Node sn in link.SlaveNodes)
            {
                lines.Add(new Line()
                {
                    Start = link.MasterNode.Position(), End = sn.Position()
                });
            }
            return(new CompositeGeometry()
            {
                Elements = lines
            });
        }
Esempio n. 7
0
        public static IGeometry Geometry(this RigidLink link)
        {
            List <IGeometry> lines = new List <IGeometry>();

            foreach (Node sn in link.SecondaryNodes)
            {
                lines.Add(new Line()
                {
                    Start = link.PrimaryNode.Position, End = sn.Position
                });
            }
            return(new CompositeGeometry()
            {
                Elements = lines
            });
        }
Esempio n. 8
0
        /***************************************************/
        /**** Private Methods                           ****/
        /***************************************************/

        private List <RigidLink> ReadRigidLink(List <string> ids = null)
        {
            List <RigidLink>                    linkList            = new List <RigidLink>();
            Dictionary <string, Node>           bhomNodes           = ReadNodes().ToDictionary(x => GetAdapterId <string>(x));
            Dictionary <string, LinkConstraint> bhomLinkConstraints = ReadLinkConstraints().ToDictionary(x => GetAdapterId <string>(x));


            //Read all links, filter by id at end, so that we can join multi-links.
            int nameCount = 0;

            string[] nameArr = { };
            m_model.LinkObj.GetNameList(ref nameCount, ref nameArr);



            foreach (string id in nameArr)
            {
                RigidLink newLink   = new RigidLink();
                SAP2000Id sap2000id = new SAP2000Id();
                string    guid      = null;

                sap2000id.Id = id;

                try
                {
                    string primaryId   = "";
                    string secondaryId = "";
                    string propName    = "";
                    m_model.LinkObj.GetPoints(id, ref primaryId, ref secondaryId);
                    newLink.PrimaryNode    = bhomNodes[primaryId];
                    newLink.SecondaryNodes = new List <Node> {
                        bhomNodes[secondaryId]
                    };

                    if (m_model.LinkObj.GetProperty(id, ref propName) == 0)
                    {
                        LinkConstraint bhProp = new LinkConstraint();
                        bhomLinkConstraints.TryGetValue(propName, out bhProp);
                        newLink.Constraint = bhProp; m_model.LinkObj.GetProperty(id, ref propName);
                    }
                    else
                    {
                        Engine.Base.Compute.RecordWarning("Could not get link property for RigidLink " + id + ".");
                    }

                    // Get the groups the link is assigned to
                    int      numGroups  = 0;
                    string[] groupNames = new string[0];
                    if (m_model.LinkObj.GetGroupAssign(id, ref numGroups, ref groupNames) == 0)
                    {
                        foreach (string grpName in groupNames)
                        {
                            newLink.Tags.Add(grpName);
                        }
                    }

                    if (m_model.LinkObj.GetGUID(id, ref guid) == 0)
                    {
                        sap2000id.PersistentId = guid;
                    }

                    newLink.SetAdapterId(sap2000id);
                    linkList.Add(newLink);
                }

                catch
                {
                    ReadElementError("RigidLink", id.ToString());
                }
            }

            Dictionary <string, RigidLink> joinedLinks = BH.Engine.Adapters.SAP2000.Query.JoinRigidLink(linkList).ToDictionary(x => x.Name);

            ids = FilterIds(ids, joinedLinks.Keys);

            if (ids != null)
            {
                return(joinedLinks
                       .Where(x => ids.Contains(x.Key))
                       .Select(x => x.Value).ToList());
            }
            else
            {
                return(joinedLinks.Values.ToList());
            }
        }
Esempio n. 9
0
        /***************************************************/
        /**** Private Methods                            ****/
        /***************************************************/

        private bool CreateObject(RigidLink bhLink)
        {
            List <RigidLink> subLinks  = BH.Engine.Adapters.SAP2000.Query.SplitRigidLink(bhLink);
            List <string>    linkIds   = new List <string>();
            SAP2000Id        sap2000id = new SAP2000Id();

            if (subLinks.Count > 1)
            {
                Engine.Base.Compute.RecordNote($"The RigidLink {bhLink.Name} was split into {subLinks.Count} separate links. They will be added to a new group called \"BHoM_Link_{bhLink.Name}\"");
            }

            foreach (RigidLink subLink in subLinks)
            {
                string name = "";

                string primaryNode   = GetAdapterId <string>(subLink.PrimaryNode);
                string secondaryNode = GetAdapterId <string>(subLink.SecondaryNodes[0]);


                if (m_model.LinkObj.AddByPoint(primaryNode, secondaryNode, ref name, false, "Default", subLink.Name) == 0)
                {
                    //Check if SAP respected the link name.
                    if (subLink.Name != "" && subLink.Name != name)
                    {
                        Engine.Base.Compute.RecordNote($"RigidLink {bhLink.Name} was assigned SAP2000_id of {name}");
                    }

                    //Attempt to set property (if property has been pushed)
                    if (subLink.Constraint != null)
                    {
                        if (m_model.LinkObj.SetProperty(name, GetAdapterId <string>(subLink.Constraint)) != 0)
                        {
                            CreatePropertyWarning("LinkConstraint", "RigidLink", bhLink.Name);
                        }
                    }
                    else
                    {
                        CreatePropertyWarning("LinkConstraint", "RigidLink", bhLink.Name);
                    }


                    //Add to groups per tags. For links that have been split, the original name will be tagged
                    foreach (string gName in subLink.Tags)
                    {
                        string groupName = gName.ToString();
                        if (m_model.LinkObj.SetGroupAssign(name, groupName) != 0)
                        {
                            m_model.GroupDef.SetGroup(groupName);
                            m_model.LinkObj.SetGroupAssign(name, groupName);
                        }
                    }

                    linkIds.Add(name);
                }
                else
                {
                    //The sublink had a problem in SAP. the sublink property has not been set and the sublink was not added to a group. The sublink may or may not have been created.
                    CreateElementError("RigidLink", subLink.Name);
                }
            }

            sap2000id.Id = linkIds;
            bhLink.SetAdapterId(sap2000id);

            return(true);
        }
Esempio n. 10
0
        /***************************************************/
        /**** 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);
        }
Esempio n. 11
0
        /***************************************************/

        private List <RigidLink> ReadRigidLink(List <string> ids = null)
        {
            List <RigidLink> linkList = new List <RigidLink>();

            int nameCount = 0;

            string[] names = { };

            if (ids == null)
            {
                m_model.LinkObj.GetNameList(ref nameCount, ref names);
                ids = names.ToList();
            }

            //read master-multiSlave nodes if these were initially created from (non-etabs)BHoM side
            Dictionary <string, List <string> > idDict = new Dictionary <string, List <string> >();

            string[] masterSlaveId;

            foreach (string id in ids)
            {
                masterSlaveId = id.Split(new[] { ":::" }, StringSplitOptions.None);
                if (masterSlaveId.Count() > 1)
                {
                    //has multi slaves
                    if (idDict.ContainsKey(masterSlaveId[0]))
                    {
                        idDict[masterSlaveId[0]].Add(masterSlaveId[1]);
                    }
                    else
                    {
                        idDict.Add(masterSlaveId[0], new List <string>()
                        {
                            masterSlaveId[1]
                        });
                    }
                }
                else
                {
                    //normal single link
                    idDict.Add(id, null);
                }
            }

            Dictionary <string, LinkConstraint> constraints = new Dictionary <string, LinkConstraint>();


            foreach (KeyValuePair <string, List <string> > kvp in idDict)
            {
                RigidLink bhLink = new RigidLink();

                if (kvp.Value == null)
                {
                    bhLink.CustomData.Add(AdapterId, kvp.Key);
                    string startId = "";
                    string endId   = "";
                    m_model.LinkObj.GetPoints(kvp.Key, ref startId, ref endId);

                    List <Node> endNodes = ReadNodes(new List <string> {
                        startId, endId
                    });
                    bhLink.MasterNode = endNodes[0];
                    bhLink.SlaveNodes = new List <Node>()
                    {
                        endNodes[1]
                    };
                }
                else
                {
                    bhLink.CustomData.Add(AdapterId, kvp.Key);
                    string        startId       = "";
                    string        endId         = "";
                    string        multiLinkId   = kvp.Key + ":::0";
                    List <string> nodeIdsToRead = new List <string>();

                    m_model.LinkObj.GetPoints(multiLinkId, ref startId, ref endId);
                    nodeIdsToRead.Add(startId);

                    for (int i = 1; i < kvp.Value.Count(); i++)
                    {
                        multiLinkId = kvp.Key + ":::" + i;
                        m_model.LinkObj.GetPoints(multiLinkId, ref startId, ref endId);
                        nodeIdsToRead.Add(endId);
                    }

                    List <Node> endNodes = ReadNodes(nodeIdsToRead);
                    bhLink.MasterNode = endNodes[0];
                    endNodes.RemoveAt(0);
                    bhLink.SlaveNodes = endNodes;
                }
                string propName = "";
                m_model.LinkObj.GetProperty(kvp.Key, ref propName);

                LinkConstraint constr;
                if (!constraints.TryGetValue(propName, out constr))
                {
                    constr = ReadLinkConstraints(new List <string> {
                        propName
                    }).FirstOrDefault();
                    constraints[propName] = constr;
                }
                bhLink.Constraint = constr;

                linkList.Add(bhLink);
            }

            return(linkList);
        }