/**
     * Actualiza la información de la ventana "Positions(0/0)".
     * @return void
     */
    public void UpdatePositionLog()
    {
        int    nSync      = 0;
        string auxLog     = "";
        string auxSyncLog = "";

        // Get positions name and sync state
        for (int i = 0; i < targetControl.Count(); i++)
        {
            TargetModel model = targetControl.GetTarget(i).GetComponent <TargetModel>();
            auxLog += model.GetName() + "\n";

            if (!model.GetSync())
            {
                auxSyncLog += "No sync" + "\n";
            }
            else
            {
                auxSyncLog += "\n";
                nSync++;
            }
        }
        // Write positions name
        positionLog.text = auxLog;
        // Write positions sync state
        positionSyncLog.text = auxSyncLog;
        // Fix containers to fit names
        AdjustContent(positionLog.gameObject, contentPositionLog);

        // Count data
        UpdateCountData(nSync, targetControl.Count());
    }
    /**
     * Guarda las posiciones actuales y sus datos en el fichero "backup.txt". (normal|relative) name x y z p r (relativeTo).
     * @return void
     */
    public void Save()
    {
        string[] lines = new string[targetControl.Count()];

        // Get positions data
        for (int i = 0; i < targetControl.Count(); i++)
        {
            string      aux    = "";
            TargetModel target = targetControl.GetTarget(i).GetComponent <TargetModel>();

            // Relative position?
            if (target.GetRelativeTo() == null)
            {
                aux += NORMAL + " ";
                aux += target.GetName() + " ";
                aux += target.GetPositionInScorbot().x + " ";
                aux += target.GetPositionInScorbot().y + " ";
                aux += target.GetPositionInScorbot().z + " ";
                aux += target.GetPitch() + " ";
                aux += target.GetRoll();
            }
            else
            {
                aux += RELATIVE + " ";
                aux += target.GetName() + " ";
                aux += target.GetRelativePosInScorbot().x + " ";
                aux += target.GetRelativePosInScorbot().y + " ";
                aux += target.GetRelativePosInScorbot().z + " ";
                aux += target.GetRelativeP() + " ";
                aux += target.GetRelativeR() + " ";
                aux += target.GetRelativeTo().GetComponent <TargetModel>().GetName();
            }

            lines[i] = aux;
        }

        // Overwrite everything
        System.IO.File.WriteAllLines(BACKUP_FILE, lines);

        gameController.backupFileOutput.text = "File saved.";
    }
Exemplo n.º 3
0
    public void RecordPosition()
    {
        Transform newTarget = Instantiate(targetPrefab).transform;

        // No points recorded
        if (targetControl.Count() == 0)
        {
            //ValidTarget(newTarget);
            if (targetNameInput.text.Equals("") || targetNameInput.text == null)
            {
                stateOutput.text = "Name required";
                Destroy(newTarget.gameObject);
                return;
            }


            Vector3 recordedPos = defaultPosition;
            newTarget.position = recordedPos;

            // Check if it's an unreachable point
            if (!robot.TargetInRange(newTarget.transform))
            {
                Destroy(newTarget.gameObject);
                stateOutput.text = "Unreachable point";
                return;
            }

            stateOutput.text = "OK";

            // Add target
            Transform addedTarget = targetControl.Add(targetNameInput.text, recordedPos, robot.GetAnglesFromCopy());
            selectionControl.SetActiveAxis(addedTarget, true);
            selectionControl.SelectedObject(addedTarget.gameObject);
            SetTarget(addedTarget);

            UpdateTargets(targetControl.GetNames());
            targetNameInput.text = "";
            //DrawTrayectory();
        }
        else // Already at least one point
        {
            GameObject prevSelectedObject = selectionControl.SearchContainTag("Target");

            if (prevSelectedObject != null)
            {
                prevSelectedObject = prevSelectedObject.transform.parent.gameObject;

                if (targetNameInput.text.Equals("") || targetNameInput.text == null)
                {
                    stateOutput.text = "Name required";
                    Destroy(newTarget.gameObject);
                    return;
                }


                Vector3 recordedPos = prevSelectedObject.transform.position;
                newTarget.position = recordedPos;

                // Check if it's an unreachable point
                if (!robot.TargetInRange(prevSelectedObject.transform))
                {
                    Destroy(newTarget.gameObject);
                    stateOutput.text = "Unreachable point";
                    return;
                }

                stateOutput.text = "OK";

                // Add target
                Transform addedTarget = targetControl.Add(targetNameInput.text, recordedPos, robot.GetAnglesFromCopy());
                selectionControl.SetActiveAxis(addedTarget, false);
                selectionControl.SelectedObject(prevSelectedObject);

                UpdateTargets(targetControl.GetNames());

                targetNameInput.text = "";

                //DrawTrayectory();
            }
        }

        Destroy(newTarget.gameObject);
    }
Exemplo n.º 4
0
    /**
     * Crea una posición (objeto) y la válida. El nombre se obtiene del campo la interfaz gráfica.
     * @param fromCommand Si es para el comando "defp".
     * @return Transform
     */
    public void RecordPosition(bool fromCommand)
    {
        Transform addedTarget = null;

        InputField targetNameInput = this.targetNameInput;

        if (fromCommand)
        {
            targetNameInput = this.DefpNameInput;
        }
        stateMessageControl.NewBlock();
        // No positions recorded
        if (targetControl.Count() == 0)
        {
            CreateDefaultTarget(targetNameInput.text);
        }
        else // Already at least one point
        {
            GameObject prevSelectedObject = selectionControl.SearchContainTag("Target");

            if (prevSelectedObject != null)
            {
                prevSelectedObject = prevSelectedObject.transform.parent.gameObject;

                // Validate target
                Vector3 newPos = prevSelectedObject.transform.position;
                if (!ValidTarget(targetNameInput.text, prevSelectedObject.transform, newPos))
                {
                    return;
                }

                // Add target
                addedTarget = targetControl.Add(targetNameInput.text, newPos, robot.GetAnglesFromCopy());
                addedTarget.GetComponent <TargetModel>().SetValid(true);
                selectionControl.SetActiveAxis(addedTarget, false);
                selectionControl.SelectedObject(prevSelectedObject);

                stateMessageControl.WriteMessage("Done. Recorded position \"" + targetNameInput.text + "\"", true);

                UpdateTargets(targetControl.GetNames());
                targetNameInput.text = "";
            }
            else
            {
                CreateDefaultTarget(targetNameInput.text);
            }
        }

        stateMessageControl.UpdatePositionLog();
    }