Exemplo n.º 1
0
    private void TcpLoginMsgButtonClick()
    {
        Login login = new Login();

        login.UserName = "******";
        login.PassWord = "******";

        byte[] bodys = login.ToByteArray();

        string strs = "";

        for (int i = 0; i < bodys.Length; i++)
        {
            strs = strs + " " + bodys[i];
        }
        int bodycount = bodys.Length;

        byte[] bodycountbytes   = BitConverter.GetBytes(bodycount);
        byte[] headbackMsgbytes = BitConverter.GetBytes((ushort)TCPEvent.TcpBackLoginMsg);

        NetMsgBase ba  = new NetMsgBase(FrameTools.CombomBinaryArray(bodycountbytes, FrameTools.CombomBinaryArray(headbackMsgbytes, bodys)));
        TCPMsg     msg = new TCPMsg((ushort)TCPEvent.TcpSendLoginMsg, ba);

        SendMsg(msg);
    }
Exemplo n.º 2
0
    private void TcpSendMsgButtonClick()
    {
        string body = "body content = asdfasdf";

        byte[] data      = Encoding.Default.GetBytes(body);
        int    bodycount = body.Length;

        byte[] bodycountbytes   = BitConverter.GetBytes(bodycount);
        byte[] headbackMsgbytes = BitConverter.GetBytes((ushort)TCPEvent.TcpSendMsgBack);

        NetMsgBase ba  = new NetMsgBase(FrameTools.CombomBinaryArray(bodycountbytes, FrameTools.CombomBinaryArray(headbackMsgbytes, data)));
        TCPMsg     msg = new TCPMsg((ushort)TCPEvent.TcpSendMsg, ba);

        SendMsg(msg);
    }
Exemplo n.º 3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // 1. Declare placeholder variables
            var    struts = new List <Curve>();
            double tol    = 0.0;

            // 2. Attempt to retrieve input
            if (!DA.GetDataList(0, struts))
            {
                return;
            }
            if (!DA.GetData(1, ref tol))
            {
                return;
            }
            // 3. Validate input
            if (struts == null || struts.Count == 1)
            {
                return;
            }
            if (tol < 0)
            {
                return;
            }

            // 4. Call cleaning method
            var nodes     = new Point3dList();
            var nodePairs = new List <IndexPair>();

            struts = FrameTools.CleanNetwork(struts, tol, out nodes, out nodePairs);

            // 5. Organize index lists
            var strutStart = new List <int>();
            var strutEnd   = new List <int>();

            foreach (IndexPair nodePair in nodePairs)
            {
                strutStart.Add(nodePair.I);
                strutEnd.Add(nodePair.J);
            }

            // 6. Set output
            DA.SetDataList(0, struts);
            DA.SetDataList(1, nodes);
            DA.SetDataList(2, strutStart);
            DA.SetDataList(3, strutEnd);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Instace constructor based on a list of curves (i.e. a lattice).
        /// </summary>
        public ExoMesh(List <Curve> struts)
        {
            m_hulls   = new List <ExoHull>();
            m_sleeves = new List <ExoSleeve>();
            m_plates  = new List <ExoPlate>();
            m_mesh    = new Mesh();

            double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

            // First, we convert the struts to a list of unique nodes and node pairs
            // We use the following lists to extract valid data from the input list
            var nodeList     = new Point3dList();           // List of unique nodes
            var nodePairList = new List <IndexPair>();      // List of struts, as node index pairs

            struts = FrameTools.CleanNetwork(struts, tol, out nodeList, out nodePairList);

            // Set hull locations
            foreach (Point3d node in nodeList)
            {
                m_hulls.Add(new ExoHull(node));
            }


            // Create sleeves, plates and relational indices
            for (int i = 0; i < struts.Count; i++)
            {
                m_sleeves.Add(new ExoSleeve(struts[i], nodePairList[i]));
                // Construct plates
                m_plates.Add(new ExoPlate(nodePairList[i].I, struts[i].TangentAtStart));
                m_plates.Add(new ExoPlate(nodePairList[i].J, -struts[i].TangentAtEnd));
                // Set sleeve relational parameters
                IndexPair platePair = new IndexPair(m_plates.Count - 2, m_plates.Count - 1);
                m_sleeves[i].PlatePair = platePair;
                // Set hull relational parameters
                m_hulls[nodePairList[i].I].SleeveIndices.Add(i);
                m_hulls[nodePairList[i].J].SleeveIndices.Add(i);
                m_hulls[nodePairList[i].I].PlateIndices.Add(platePair.I);
                m_hulls[nodePairList[i].J].PlateIndices.Add(platePair.J);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // 1. Retrieve and validate data
            var          cell             = new UnitCell();
            GeometryBase designSpace      = null;
            Plane        orientationPlane = Plane.Unset;
            double       xCellSize        = 0;
            double       yCellSize        = 0;
            double       zCellSize        = 0;
            double       minLength        = 0; // the trim tolerance (i.e. minimum strut length)
            double       maxLength        = 0;
            bool         strictlyIn       = false;

            if (!DA.GetData(0, ref cell))
            {
                return;
            }
            if (!DA.GetData(1, ref designSpace))
            {
                return;
            }
            if (!DA.GetData(2, ref orientationPlane))
            {
                return;
            }
            if (!DA.GetData(3, ref xCellSize))
            {
                return;
            }
            if (!DA.GetData(4, ref yCellSize))
            {
                return;
            }
            if (!DA.GetData(5, ref zCellSize))
            {
                return;
            }
            if (!DA.GetData(6, ref minLength))
            {
                return;
            }
            if (!DA.GetData(7, ref maxLength))
            {
                return;
            }
            if (!DA.GetData(8, ref strictlyIn))
            {
                return;
            }

            if (!cell.isValid)
            {
                return;
            }
            if (!designSpace.IsValid)
            {
                return;
            }
            if (!orientationPlane.IsValid)
            {
                return;
            }
            if (xCellSize == 0)
            {
                return;
            }
            if (yCellSize == 0)
            {
                return;
            }
            if (zCellSize == 0)
            {
                return;
            }
            if (minLength >= xCellSize || minLength >= yCellSize || minLength >= zCellSize)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Tolerance parameter cannot be larger than the unit cell dimensions.");
                return;
            }
            // 2. Validate the design space
            int spaceType = FrameTools.ValidateSpace(ref designSpace);

            if (spaceType == 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Design space must be a closed Brep, Mesh or Surface");
                return;
            }

            double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

            // 3. Compute oriented bounding box and its corner points
            Box bBox = new Box();

            designSpace.GetBoundingBox(orientationPlane, out bBox);
            Point3d[] bBoxCorners = bBox.GetCorners();
            //    Set basePlane based on the bounding box
            Plane basePlane = new Plane(bBoxCorners[0], bBoxCorners[1], bBoxCorners[3]);

            // 4. Determine number of iterations required to fill the box, and package into array
            double xLength = bBoxCorners[0].DistanceTo(bBoxCorners[1]);
            double yLength = bBoxCorners[0].DistanceTo(bBoxCorners[3]);
            double zLength = bBoxCorners[0].DistanceTo(bBoxCorners[4]);
            int    nX      = (int)Math.Ceiling(xLength / xCellSize); // Roundup to next integer if non-integer
            int    nY      = (int)Math.Ceiling(yLength / yCellSize);
            int    nZ      = (int)Math.Ceiling(zLength / zCellSize);

            float[] N = new float[3] {
                nX, nY, nZ
            };

            // 5. Initialize nodeTree
            var lattice = new Lattice();

            // 6. Prepare cell (this is a UnitCell object)
            cell = cell.Duplicate();
            cell.FormatTopology();

            // 7. Define iteration vectors in each direction (accounting for Cell Size)
            Vector3d vectorU = xCellSize * basePlane.XAxis;
            Vector3d vectorV = yCellSize * basePlane.YAxis;
            Vector3d vectorW = zCellSize * basePlane.ZAxis;

            // 8. Map nodes to design space
            //    Loop through the uvw cell grid
            for (int u = 0; u <= N[0]; u++)
            {
                for (int v = 0; v <= N[1]; v++)
                {
                    for (int w = 0; w <= N[2]; w++)
                    {
                        // Construct cell path in tree
                        GH_Path treePath = new GH_Path(u, v, w);
                        // Fetch the list of nodes to append to, or initialise it
                        var nodeList = lattice.Nodes.EnsurePath(treePath);

                        // This loop maps each node in the cell
                        for (int i = 0; i < cell.Nodes.Count; i++)
                        {
                            double   usub = cell.Nodes[i].X;                  // u-position within unit cell (local)
                            double   vsub = cell.Nodes[i].Y;                  // v-position within unit cell (local)
                            double   wsub = cell.Nodes[i].Z;                  // w-position within unit cell (local)
                            double[] uvw  = { u + usub, v + vsub, w + wsub }; // uvw-position (global)

                            // Check if the node belongs to another cell (i.e. it's relative path points outside the current cell)
                            bool isOutsideCell = (cell.NodePaths[i][0] > 0 || cell.NodePaths[i][1] > 0 || cell.NodePaths[i][2] > 0);

                            // Check if current uvw-position is beyond the upper boundary
                            bool isOutsideSpace = (uvw[0] > N[0] || uvw[1] > N[1] || uvw[2] > N[2]);

                            if (isOutsideCell || isOutsideSpace)
                            {
                                nodeList.Add(null);
                            }
                            else
                            {
                                // Compute position vector
                                Vector3d V       = uvw[0] * vectorU + uvw[1] * vectorV + uvw[2] * vectorW;
                                var      newNode = new LatticeNode(basePlane.Origin + V);

                                // Check if point is inside - use unstrict tolerance, meaning it can be outside the surface by the specified tolerance
                                bool isInside = FrameTools.IsPointInside(designSpace, newNode.Point3d, spaceType, tol, strictlyIn);

                                // Set the node state (it's location wrt the design space)
                                if (isInside)
                                {
                                    newNode.State = LatticeNodeState.Inside;
                                }
                                else
                                {
                                    newNode.State = LatticeNodeState.Outside;
                                }

                                // Add node to tree
                                nodeList.Add(newNode);
                            }
                        }
                    }
                }
            }

            // 9. Map struts to the node tree
            lattice.UniformMapping(cell, designSpace, spaceType, N, minLength, maxLength);

            // 10. Set output
            DA.SetDataList(0, lattice.Struts);
        }