コード例 #1
0
        //////////////////////////////////////////////////////////////////////////
        // React to a value change.
        public void OnValueChanged()
        {
            if (UDPReceiveComponent.flagUICommunicationStarted)
            {
                                #if DEBUG
                Debug.Log("ParameterUIMenu: Updating UI values.");
                                #endif
                // Find Objects.
                GameObject[] goBooleans = GameObject.FindGameObjectsWithTag(this.tagUIItemBoolean);
                GameObject[] goCounters = GameObject.FindGameObjectsWithTag(this.tagUIItemCounter);
                GameObject[] goSliders  = GameObject.FindGameObjectsWithTag(this.tagUIItemSlider);
                                #if DEBUG
                Debug.Log("ParameterUIMenu: Found items: booleans: " + goBooleans.Length + ", counters: " + goCounters.Length + ", sliders: " + goSliders.Length);
                                #endif

                // Extract data.
                List <bool>  bools  = new List <bool>();
                List <int>   ints   = new List <int>();
                List <float> floats = new List <float>();
                foreach (GameObject goItem in goBooleans)
                {
                    bools.Add(goItem.GetComponent <BooleanToggle>().value);
                }
                foreach (GameObject goItem in goCounters)
                {
                    ints.Add(goItem.GetComponent <Counter>().value);
                }
                foreach (GameObject goItem in goSliders)
                {
                    floats.Add(goItem.GetComponent <FloatSlider>().value);
                }
                UIData ui = new UIData(bools, ints, floats);

                // Encode and if changed - send it.
                byte[] data = EncodeUtilities.EncodeData("UIDATA", ui, out string currentMessage);
                if (ParameterUIMenu.lastMessage != currentMessage)                   // TODO: Technically not necessary now since we call directly from UI elements themselves.
                {
                    ParameterUIMenu.lastMessage = currentMessage;
                                        #if DEBUG
                    Debug.Log("ParameterUIMenu: values changed, sending: " + currentMessage);
                                        #endif

                    if (ParameterUIMenu.sender == null)
                    {
                        ParameterUIMenu.sender = FindObjectOfType <UDPSendComponent>();
                    }
                    if (ParameterUIMenu.sender == null)
                    {
                                                #if DEBUGWARNING
                        Debug.Log("ParameterUIMenu: No sender Found.");
                                                #endif
                        return;
                    }
                    ParameterUIMenu.sender.SendUI(data);
                }
            }
        }
コード例 #2
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)
        {
            // Get inputs.
            List <RobotData> inputRobots = new List <RobotData>();
            Connection       connect     = null;

            if (!DA.GetDataList(0, inputRobots))
            {
                return;
            }
            if (!DA.GetData <Connection>(1, ref connect))
            {
                return;
            }
            //////////////////////////////////////////////////////
            // Process data.
            if (connect.status)
            {
                // If connection open start acting.

                // Send robot data.
                byte[] bytes = EncodeUtilities.EncodeData("HOLOBOTS", inputRobots.ToArray(), out string currentMessage);
                if (this.flagForce || (this.lastMessage != currentMessage))
                {
                    connect.tcpSender.QueueUpData(bytes);
                    //bool success = connect.tcpSender.flagSuccess;
                    //string message = connect.tcpSender.debugMessages[connect.tcpSender.debugMessages.Count-1];
                    //if (success)
                    //	this.lastMessage = currentMessage;
                    //UniversalDebug(message, (success) ? GH_RuntimeMessageLevel.Remark : GH_RuntimeMessageLevel.Error);
                }
            }
            else
            {
                this.lastMessage = string.Empty;
                UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'.", GH_RuntimeMessageLevel.Warning);
            }
            //////////////////////////////////////////////////////
            // Output.
                        #if DEBUG
            DA.SetData(0, RobotStreaming.debugMessages[RobotStreaming.debugMessages.Count - 1]);
                        #endif

            // Expire Solution.
            if ((connect.status) && (connect.PendingMessages))
            {
                GH_Document document = this.OnPingDocument();
                if (document != null)
                {
                    document.ScheduleSolution(RobotStreaming.expireDelay, ScheduleCallback);
                }
            }
        }
コード例 #3
0
        // Collect environment meshes
        public List <byte[]> EncodeEnvironmentMesh(out string currentMessage)
        {
            currentMessage = string.Empty;
            List <byte[]> data = new List <byte[]>();

            FindMeshes();
            if (this.scannedEnvironment.Count > 0)
            {
                // Combine meshes
                CombineInstance[] combineStructure = new CombineInstance[this.scannedEnvironment.Count];
                int i = 0;
                foreach (MeshRenderer meshRenderer in this.scannedEnvironment)
                {
                    MeshFilter meshFilter = meshRenderer.gameObject.GetComponent <MeshFilter>();
                    combineStructure[i].mesh      = meshFilter.sharedMesh;
                    combineStructure[i].transform = meshRenderer.transform.localToWorldMatrix;
                    i++;
                }
                Mesh mesh = new Mesh();
                mesh.CombineMeshes(combineStructure);

                // Encode mesh
                MeshData meshData  = MeshUtilities.EncodeMesh(mesh);
                byte[]   localData = EncodeUtilities.EncodeData("ENVIRONMENT", meshData, out string currentLocalMessage);
                data.Add(localData);
                                #if DEBUG
                DebugUtilities.UniversalDebug(this.sourceName, "Mesh Encoding: " + currentLocalMessage);
                                #endif
                currentMessage = currentLocalMessage;

                // // Encode meshes separately
                // // {
                // //   MeshRenderer meshRenderer = this.scannedEnvironment[0];
                // foreach (MeshRenderer meshRenderer in this.scannedEnvironment) {
                //  MeshFilter meshFilter = meshRenderer.gameObject.GetComponent<MeshFilter>();
                //  MeshData meshData = MeshUtilities.EncodeMesh(meshFilter.sharedMesh);
                //  byte[] localData = EncodeUtilities.EncodeData("ENVIRONMENT", meshData, out string currentLocalMessage);
                //  #if DEBUG
                //  DebugUtilities.UniversalDebug(this.sourceName, "Mesh Encoding: " + currentLocalMessage);
                //  #endif
                //  data.Add(localData);
                //  currentMessage += currentLocalMessage;
                // }
            }
            else
            {
                                #if DEBUG
                DebugUtilities.UniversalDebug(this.sourceName, "No meshes found.");
                                #endif
            }

            return(data);
        }
コード例 #4
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)
        {
            // Get inputs.
            List <RobotData> inputRobots = new List <RobotData>();
            Connection       connect     = null;

            if (!DA.GetDataList(0, inputRobots))
            {
                return;
            }
            if (!DA.GetData(1, ref connect))
            {
                return;
            }
            //////////////////////////////////////////////////////
            // Process data.
            if (connect.status)
            {
                // If connection open start acting.

                // Send robot data.
                byte[] bytes = EncodeUtilities.EncodeData("HOLOBOTS", inputRobots.ToArray(), out string currentMessage);
                if (this.lastMessage != currentMessage)
                {
                    connect.tcpSender.Send(bytes);
                    bool   success = connect.tcpSender.success;
                    string message = connect.tcpSender.debugMessages[connect.tcpSender.debugMessages.Count - 1];
                    if (success)
                    {
                        this.lastMessage = currentMessage;
                    }
                    UniversalDebug(message, (success) ? GH_RuntimeMessageLevel.Remark : GH_RuntimeMessageLevel.Error);
                }
            }
            else
            {
                this.lastMessage = string.Empty;
                UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'.", GH_RuntimeMessageLevel.Warning);
            }
            //////////////////////////////////////////////////////
            // Output.
                        #if DEBUG
            DA.SetData(0, RobotStreaming.debugMessages[RobotStreaming.debugMessages.Count - 1]);
                        #endif
        }
コード例 #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)
        {
            // Get inputs.
            Connection connect = null;

            if (!DA.GetData(0, ref connect))
            {
                return;
            }
            //////////////////////////////////////////////////////
            // Process data.
            if (connect.status)
            {
                // If connection open start acting.
                if (!UIReceiver.flagProcessed)
                {
                    UIReceiver.flagProcessed = true;
                    // Send local IPAddress for device to communicate back.
                    byte[] bytes = EncodeUtilities.EncodeData("IPADDRESS", NetworkUtilities.LocalIPAddress(), out string currentMessage);
                    connect.udpSender.Send(bytes);
                    bool success = connect.udpSender.success;
                    UniversalDebug("Sent local IP.");
                }

                // Prepare to receive UI data.
                try {
                    if (!connect.udpReceiver.flagDataRead)
                    {
                        connect.udpReceiver.flagDataRead = true;
                        UIReceiver.currentInput          = connect.udpReceiver.dataMessages[connect.udpReceiver.dataMessages.Count - 1];
                        if (UIReceiver.lastInputs != currentInput)
                        {
                            currentInput          = EncodeUtilities.StripSplitter(currentInput);
                            UIReceiver.lastInputs = currentInput;
                            UniversalDebug("New Message without Message Splitter removed: " + currentInput);
                            string[] messageComponents = currentInput.Split(new string[] { EncodeUtilities.headerSplitter }, 2, StringSplitOptions.RemoveEmptyEntries);
                            if (messageComponents.Length > 1)
                            {
                                string header = messageComponents[0], content = messageComponents[1];
                                UniversalDebug("Header: " + header + ", content: " + content);
                                if (header == "UIDATA")
                                {
                                    // If any new data received - process it.
                                    UIData data = JsonConvert.DeserializeObject <UIData>(content);
                                    UIReceiver.currentBools  = new List <bool> (data.bools);
                                    UIReceiver.currentInts   = new List <int> (data.ints);
                                    UIReceiver.currentFloats = new List <float> (data.floats);
                                    UniversalDebug("Data Received!");
                                }
                                else
                                {
                                    UniversalDebug("Header Not Recognized!", GH_RuntimeMessageLevel.Warning);
                                }
                            }
                            else
                            {
                                UniversalDebug("Data not Received!", GH_RuntimeMessageLevel.Warning);
                            }
                        }
                        else
                        {
                            UniversalDebug("Improper Message!", GH_RuntimeMessageLevel.Warning);
                        }
                    }
                    else
                    {
                        UniversalDebug("No data received.");
                    }
                } catch {
                    UniversalDebug("Error Processing Data.", GH_RuntimeMessageLevel.Error);
                }
            }
            else
            {
                // If connection disabled - stop receiving.
                UIReceiver.flagProcessed = false;
                UIReceiver.lastInputs    = string.Empty;
                UIReceiver.currentBools  = new List <bool>();
                UIReceiver.currentInts   = new List <int>();
                UIReceiver.currentFloats = new List <float>();
                UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'", GH_RuntimeMessageLevel.Warning);
            }
            //////////////////////////////////////////////////////
            // Output.
            DA.SetDataList(0, UIReceiver.currentBools);
            DA.SetDataList(1, UIReceiver.currentInts);
            DA.SetDataList(2, UIReceiver.currentFloats);
                        #if DEBUG
            DA.SetData(3, this.debugMessages[this.debugMessages.Count - 1]);
                        #endif

            // Expire Solution.
            if (connect.status)
            {
                GH_Document document = this.OnPingDocument();
                if (document != null)
                {
                    document.ScheduleSolution(UIReceiver.expireDelay, ScheduleCallback);
                }
            }
        }
コード例 #6
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)
        {
            // Get inputs.
            List <string>  inputText          = new List <string>();
            List <Point3d> inputTextLocations = new List <Point3d>();
            List <double>  inputTextSize      = new List <double>();
            List <Color>   inputTextColor     = new List <Color>();
            Connection     connect            = null;

            if (!DA.GetDataList(0, inputText))
            {
                return;
            }
            if (!DA.GetDataList(1, inputTextLocations))
            {
                return;
            }
            DA.GetDataList(2, inputTextSize);
            DA.GetDataList(3, inputTextColor);
            if (!DA.GetData <Connection>(4, ref connect))
            {
                return;
            }
            // Check inputs.
            if (inputTextLocations.Count != inputText.Count)
            {
                UniversalDebug("The number of 'tag locations' and 'tag texts' should be equal.",
                               GH_RuntimeMessageLevel.Error);
                return;
            }
            if ((inputTextSize.Count > 1) && (inputTextSize.Count != inputText.Count))
            {
                UniversalDebug("The number of 'tag text sizes' should be one or equal to one or the number of 'tag texts'.",
                               GH_RuntimeMessageLevel.Error);
                return;
            }
            if ((inputTextColor.Count > 1) && (inputTextColor.Count != inputText.Count))
            {
                UniversalDebug("The number of 'tag text colors' should be one or equal to one or the number of 'tag texts'.",
                               GH_RuntimeMessageLevel.Error);
                return;
            }
            //////////////////////////////////////////////////////
            // Process data.
            if (connect.status)
            {
                // If connection open start acting.
                List <string> currentTexts = new List <string>()
                {
                };
                List <float[]> currentTextLocations = new List <float[]>()
                {
                };
                List <float> currentTextSizes = new List <float>()
                {
                };
                List <int[]> currentTextColors = new List <int[]>()
                {
                };
                for (int i = 0; i < inputText.Count; i++)
                {
                    float currentSize  = (float)((inputTextSize.Count > 1) ? inputTextSize[i] : inputTextSize[0]);
                    Color currentColor = (inputTextColor.Count > 1) ? inputTextColor[i] : inputTextColor[0];
                    currentTexts.Add(inputText[i]);
                    currentTextLocations.Add(EncodeUtilities.EncodeLocation(inputTextLocations[i]));
                    currentTextSizes.Add((float)Math.Round(currentSize / 1000.0, 3));
                    currentTextColors.Add(EncodeUtilities.EncodeColor(currentColor));
                }
                LabelData tags = new LabelData(currentTexts, currentTextLocations, currentTextSizes, currentTextColors);

                // Send tag data.
                byte[] bytes = EncodeUtilities.EncodeData("HOLOTAG", tags, out string currentMessage);
                if (this.flagForce || (this.lastMessage != currentMessage))
                {
                    connect.udpSender.QueueUpData(bytes);
                    //bool success = connect.udpSender.flagSuccess;
                    //string message = connect.udpSender.debugMessages[connect.udpSender.debugMessages.Count-1];
                    //if (success)
                    //	this.lastMessage = currentMessage;
                    //UniversalDebug(message, (success) ? GH_RuntimeMessageLevel.Remark : GH_RuntimeMessageLevel.Error);
                }
            }
            else
            {
                this.lastMessage = string.Empty;
                UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'", GH_RuntimeMessageLevel.Warning);
            }
            //////////////////////////////////////////////////////
            // Output.
                        #if DEBUG
            DA.SetData(0, this.debugMessages[this.debugMessages.Count - 1]);
                        #endif

            //// Expire Solution.
            //if ((connect.status) && (connect.PendingMessages)) {
            //	GH_Document document = this.OnPingDocument();
            //	if (document != null)
            //		document.ScheduleSolution(HoloTag.expireDelay, ScheduleCallback);
            //}
        }
コード例 #7
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)
        {
            //CheckType();
            // Get inputs.
            string       message;
            List <Mesh>  inputMeshes = new List <Mesh>();
            List <Color> inputColor  = new List <Color>();
            Connection   connect     = null;

            if (!DA.GetDataList(0, inputMeshes))
            {
                return;
            }
            DA.GetDataList(1, inputColor);
            if (!DA.GetData(2, ref connect))
            {
                return;
            }
            // Check inputs.
            if ((inputColor.Count > 1) && (inputColor.Count != inputMeshes.Count))
            {
                message = (inputColor.Count > inputMeshes.Count) ?
                          "The number of Colors does not match the number of Mesh objects. Extra colors will be ignored." :
                          "The number of Colors does not match the number of Mesh objects. The last color will be repeated.";
                UniversalDebug(message, GH_RuntimeMessageLevel.Warning);
            }
            ////////////////////////////////////////////////////////////////////

            // If connection open start acting.
            if (connect.status)
            {
                // Encode mesh data.
                List <MeshData> inputMeshData = new List <MeshData> {
                };
                for (int i = 0; i < inputMeshes.Count; i++)
                {
                    Color currentColor = inputColor[Math.Min(i, inputColor.Count)];
                    inputMeshData.Add(MeshUtilities.EncodeMesh(inputMeshes[i], currentColor));
                }
                // Send mesh data.
                byte[] bytes = EncodeUtilities.EncodeData("MESHSTREAMING", inputMeshData, out string currentMessage);
                if (this.lastMessage != currentMessage)
                {
                    bool success = false;
                    if (this.sourceType == SourceType.TCP)
                    {
                        connect.tcpSender.Send(bytes);
                        success = connect.tcpSender.success;
                        message = connect.tcpSender.debugMessages[connect.tcpSender.debugMessages.Count - 1];
                    }
                    else
                    {
                        connect.udpSender.Send(bytes);
                        success = connect.udpSender.success;
                        message = connect.udpSender.debugMessages[connect.udpSender.debugMessages.Count - 1];
                    }
                    if (success)
                    {
                        this.lastMessage = currentMessage;
                    }
                    UniversalDebug(message, (success) ? GH_RuntimeMessageLevel.Remark : GH_RuntimeMessageLevel.Error);
                }
            }
            else
            {
                this.lastMessage = string.Empty;
                UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'", GH_RuntimeMessageLevel.Warning);
            }

            // Output.
                        #if DEBUG
            DA.SetData(0, this.debugMessages[this.debugMessages.Count - 1]);
                        #endif
        }
コード例 #8
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)
        {
            // Get inputs.
            List <RobotData>         inputRobots     = new List <RobotData>();
            GH_Structure <GH_Number> inputAxisAngles = new GH_Structure <GH_Number> {
            };
            Connection connect = null;

            if (!DA.GetDataList(0, inputRobots))
            {
                return;
            }
            if (!DA.GetDataTree(1, out inputAxisAngles))
            {
                return;
            }
            if (!DA.GetData(2, ref connect))
            {
                return;
            }
            // Check inputs.
            if ((inputAxisAngles.Paths.Count > 1) && (inputAxisAngles.Paths.Count != inputRobots.Count))
            {
                UniversalDebug("The number of Branches of Axis Angles should be one or equal to the number of HoloBot objects.",
                               GH_RuntimeMessageLevel.Error);
                return;
            }
            // if (inputAxisAngles.Count != 6) {
            //  Positioner.debugMessages.Add("Component: Controller: The number of Axis should be equal to the number of Robot Joints.");
            //  return;
            // }
            //////////////////////////////////////////////////////
            // Process data.
            if (connect.status)
            {
                // If connection open start acting.
                UniversalDebug("Robots Found: " + inputRobots.Count + ", Axis Count, " + inputAxisAngles.Paths.Count);
                List <RobotControllerData> robotControllers = new List <RobotControllerData>();
                for (int i = 0; i < inputRobots.Count; i++)
                {
                    List <double> currentRobotAxisValues = new List <double> {
                    };
                    int index = (inputAxisAngles.Paths.Count > 1) ? i : 0;
                    Console.WriteLine(index);
                    double currentValue;
                    for (int j = 0; j < inputAxisAngles[index].Count; j++)
                    {
                        currentValue = (double)inputAxisAngles[index][j].Value;
                        currentRobotAxisValues.Add(currentValue * (180.0 / Math.PI));
                    }
                    robotControllers.Add(new RobotControllerData(inputRobots[i].robotID, currentRobotAxisValues));
                }

                // Send robot controller data.
                byte[] bytes = EncodeUtilities.EncodeData("CONTROLLER", robotControllers, out string currentMessage);
                if (this.lastMessage != currentMessage)
                {
                    connect.udpSender.Send(bytes);
                    bool   success = connect.udpSender.success;
                    string message = connect.udpSender.debugMessages[connect.udpSender.debugMessages.Count - 1];
                    if (success)
                    {
                        this.lastMessage = currentMessage;
                    }
                    UniversalDebug(message, (success) ? GH_RuntimeMessageLevel.Remark : GH_RuntimeMessageLevel.Error);
                }
            }
            else
            {
                this.lastMessage = string.Empty;
                UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'.", GH_RuntimeMessageLevel.Warning);
            }
            //////////////////////////////////////////////////////
            // Output.
                        #if DEBUG
            DA.SetData(0, this.debugMessages[this.debugMessages.Count - 1]);
                        #endif
        }