Skip to content

Commit

Permalink
style: all cs files reformatted, removed unused using
Browse files Browse the repository at this point in the history
  • Loading branch information
ZdenekM committed Apr 20, 2023
1 parent 76612f1 commit 1b4eb51
Show file tree
Hide file tree
Showing 100 changed files with 578 additions and 1,063 deletions.
227 changes: 151 additions & 76 deletions arcor2_AREditor/Assets/BASE/Scripts/Action.cs

Large diffs are not rendered by default.

77 changes: 38 additions & 39 deletions arcor2_AREditor/Assets/BASE/Scripts/ActionObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using IO.Swagger.Model;
using System;

namespace Base {
public abstract class ActionObject : InteractiveObject, IActionProvider, IActionPointParent {
Expand Down Expand Up @@ -44,7 +43,7 @@ public virtual void InitActionObject(IO.Swagger.Model.SceneObject sceneObject, V
}

}

public virtual void UpdateObjectName(string newUserId) {
Data.Name = newUserId;
SelectorItem.SetText(newUserId);
Expand Down Expand Up @@ -74,9 +73,9 @@ public virtual void ActionObjectUpdate(IO.Swagger.Model.SceneObject actionObject
} else {
ObjectParameters[p.Name].Value = p.Value;
}

}

}

public void ResetPosition() {
Expand All @@ -98,7 +97,7 @@ public bool TryGetParameter(string id, out IO.Swagger.Model.Parameter parameter)
parameter = null;
return false;
}

public bool TryGetParameterMetadata(string id, out IO.Swagger.Model.ParameterMeta parameterMeta) {
foreach (IO.Swagger.Model.ParameterMeta p in ActionObjectMetadata.Settings) {
if (p.Name == id) {
Expand All @@ -109,7 +108,7 @@ public bool TryGetParameterMetadata(string id, out IO.Swagger.Model.ParameterMet
parameterMeta = null;
return false;
}

public abstract Vector3 GetScenePosition();

public abstract void SetScenePosition(Vector3 position);
Expand Down Expand Up @@ -146,7 +145,7 @@ public bool IsCamera() {
public virtual void DeleteActionObject() {
// Remove all actions of this action point
RemoveActionPoints();

// Remove this ActionObject reference from the scene ActionObject list
SceneManager.Instance.ActionObjects.Remove(this.Data.Id);

Expand Down Expand Up @@ -206,7 +205,7 @@ public override string GetName() {
return Data.Name;
}


public bool IsActionObject() {
return true;
}
Expand Down Expand Up @@ -245,45 +244,45 @@ public async override Task<RequestResult> Movable() {
public abstract void CreateModel(IO.Swagger.Model.CollisionModels customCollisionModels = null);
public abstract GameObject GetModelCopy();

public IO.Swagger.Model.Pose GetPose() {
if (ActionObjectMetadata.HasPose)
return new IO.Swagger.Model.Pose(position: DataHelper.Vector3ToPosition(TransformConvertor.UnityToROS(transform.localPosition)),
orientation: DataHelper.QuaternionToOrientation(TransformConvertor.UnityToROS(transform.localRotation)));
else
return new IO.Swagger.Model.Pose(orientation: new IO.Swagger.Model.Orientation(), position: new IO.Swagger.Model.Position());
}
public async override Task Rename(string name) {
try {
await WebsocketManager.Instance.RenameObject(GetId(), name);
Notifications.Instance.ShowToastMessage("Action object renamed");
} catch (RequestFailedException e) {
Notifications.Instance.ShowNotification("Failed to rename action object", e.Message);
throw;
public IO.Swagger.Model.Pose GetPose() {
if (ActionObjectMetadata.HasPose)
return new IO.Swagger.Model.Pose(position: DataHelper.Vector3ToPosition(TransformConvertor.UnityToROS(transform.localPosition)),
orientation: DataHelper.QuaternionToOrientation(TransformConvertor.UnityToROS(transform.localRotation)));
else
return new IO.Swagger.Model.Pose(orientation: new IO.Swagger.Model.Orientation(), position: new IO.Swagger.Model.Position());
}
public async override Task Rename(string name) {
try {
await WebsocketManager.Instance.RenameObject(GetId(), name);
Notifications.Instance.ShowToastMessage("Action object renamed");
} catch (RequestFailedException e) {
Notifications.Instance.ShowNotification("Failed to rename action object", e.Message);
throw;
}
}
}
public async override Task<RequestResult> Removable() {
if (GameManager.Instance.GetGameState() != GameManager.GameStateEnum.SceneEditor) {
return new RequestResult(false, "Action object could be removed only in scene editor");
} else if (SceneManager.Instance.SceneStarted) {
return new RequestResult(false, "Scene online");
} else {
public async override Task<RequestResult> Removable() {
if (GameManager.Instance.GetGameState() != GameManager.GameStateEnum.SceneEditor) {
return new RequestResult(false, "Action object could be removed only in scene editor");
} else if (SceneManager.Instance.SceneStarted) {
return new RequestResult(false, "Scene online");
} else {
IO.Swagger.Model.RemoveFromSceneResponse response = await WebsocketManager.Instance.RemoveFromScene(GetId(), false, true);
if (response.Result)
return new RequestResult(true);
else
return new RequestResult(false, response.Messages[0]);
if (response.Result)
return new RequestResult(true);
else
return new RequestResult(false, response.Messages[0]);
}
}
}


public async override void Remove() {
public async override void Remove() {
IO.Swagger.Model.RemoveFromSceneResponse response =
await WebsocketManager.Instance.RemoveFromScene(GetId(), false, false);
if (!response.Result) {
Notifications.Instance.ShowNotification("Failed to remove object " + GetName(), response.Messages[0]);
return;
if (!response.Result) {
Notifications.Instance.ShowNotification("Failed to remove object " + GetName(), response.Messages[0]);
return;
}
}
}

public Transform GetSpawnPoint() {
return transform;
Expand Down
11 changes: 4 additions & 7 deletions arcor2_AREditor/Assets/BASE/Scripts/Clickable.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using UnityEngine;

namespace Base
{
public abstract class Clickable : MonoBehaviour
{
namespace Base {
public abstract class Clickable : MonoBehaviour {
public enum Click {
MOUSE_LEFT_BUTTON = 0,
MOUSE_RIGHT_BUTTON = 1,
Expand All @@ -13,7 +10,7 @@ public enum Click {
TOUCH = 4,
LONG_TOUCH = 5,
TOUCH_ENDED = 6,

}

public bool Enabled = true;
Expand All @@ -24,6 +21,6 @@ public enum Click {

public abstract void OnHoverEnd();


}
}
5 changes: 1 addition & 4 deletions arcor2_AREditor/Assets/BASE/Scripts/CollisionObject.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Threading.Tasks;
using Base;
using UnityEngine;
public class CollisionObject : ActionObject3D
{
public class CollisionObject : ActionObject3D {
public override string GetObjectTypeName() {
return "Collision object";
}
Expand Down
2 changes: 0 additions & 2 deletions arcor2_AREditor/Assets/BASE/Scripts/DataHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

Expand Down
5 changes: 2 additions & 3 deletions arcor2_AREditor/Assets/BASE/Scripts/DropdownEndEffectors.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Michsky.UI.ModernUIPack;
Expand All @@ -24,8 +23,8 @@ public async Task Init(string robotId, string arm_id, UnityAction<string> onChan
Debug.LogError(ex);
Base.NotificationsModernUI.Instance.ShowNotification("End effector load failed", "Failed to load end effectors, try again later");
}


}

public void PutData(List<string> data, UnityAction<string> onChangeCallback) {
Expand Down
10 changes: 3 additions & 7 deletions arcor2_AREditor/Assets/BASE/Scripts/DropdownRobots.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using Michsky.UI.ModernUIPack;
using System.Linq;
using System.Threading.Tasks;
using Base;
using System;

public class DropdownRobots : MonoBehaviour
{
public class DropdownRobots : MonoBehaviour {
public DropdownParameter Dropdown;

/// <summary>
Expand All @@ -27,7 +23,7 @@ internal async Task Init(UnityAction<string> callback, bool withEEOnly, string s
if (!withEEOnly) {
foreach (IRobot robot in Base.SceneManager.Instance.GetRobots()) {
robotNames.Add(robot.GetName());

}
} else if (withEEOnly && SceneManager.Instance.SceneStarted) {
foreach (IRobot robot in Base.SceneManager.Instance.GetRobots()) {
Expand All @@ -47,7 +43,7 @@ public void Init(List<string> robotNames, UnityAction<string> callback, string s
int selectedItemIndex = 0;
foreach (string robotName in robotNames) {
CustomDropdown.Item item = new CustomDropdown.Item {
itemName = robotName
itemName = robotName
};
if (robotName == selectedRobotName)
selectedItemIndex = Dropdown.Dropdown.dropdownItems.Count;
Expand Down
7 changes: 1 addition & 6 deletions arcor2_AREditor/Assets/BASE/Scripts/ManualTooltip.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Michsky.UI.ModernUIPack;
using UnityEngine.EventSystems;
using RuntimeInspectorNamespace;
using TMPro;

[RequireComponent(typeof(TooltipContent))]
public class ManualTooltip : MonoBehaviour {
Expand Down Expand Up @@ -42,7 +37,7 @@ private void Start() {
tooltipContent.enabled = false;
return;
}


if (DisplayAlternativeDescription) {
ShowAlternativeDescription();
Expand Down
15 changes: 8 additions & 7 deletions arcor2_AREditor/Assets/BASE/Scripts/MeshImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Net;
using Base;
using TriLibCore;
using TriLibCore.General;
using UnityEngine;
using UnityEngine.Networking;

Expand Down Expand Up @@ -50,14 +49,16 @@ private void ImportMesh(string path, string aoId) {

GameObject loadedObject = new GameObject("ImportedMeshObject");
if (Path.GetExtension(path).ToLower() == ".dae") {
//Debug.LogError("importing dae mesh name: " + path);
//Debug.LogError("importing dae mesh name: " + path);
StreamReader reader = File.OpenText(path);
string daeFile = reader.ReadToEnd();

// Requires Simple Collada asset from Unity Asset Store: https://assetstore.unity.com/packages/tools/input-management/simple-collada-19579
// Supports: DAE
StartCoroutine(ColladaImporter.Instance.ImportAsync(daeFile, Quaternion.identity, Vector3.one, Vector3.zero,
onModelImported: delegate (GameObject loadedGameObject) { OnMeshImported?.Invoke(this, new ImportedMeshEventArgs(loadedGameObject, aoId));},
onModelImported: delegate (GameObject loadedGameObject) {
OnMeshImported?.Invoke(this, new ImportedMeshEventArgs(loadedGameObject, aoId));
},
wrapperGameObject: loadedObject));

} else {
Expand Down Expand Up @@ -97,7 +98,7 @@ private IEnumerator DownloadMesh(string meshId, string fileName, string aoId) {
string savePath = string.Format("{0}/{1}", meshDirectory, fileName);
System.IO.File.WriteAllBytes(savePath, www.downloadHandler.data);
meshSources[fileName] = false;

//Debug.LogError("MESH: download finished");
//if the mesh is zipped, extract it
if (Path.GetExtension(savePath).ToLower() == ".zip") {
Expand Down Expand Up @@ -147,7 +148,7 @@ private void OnMeshDownloaded(string meshID, string path, string aoId) {
private string GetPathToMesh(string meshId) {
if (Path.GetExtension(meshId).ToLower() == ".zip") {
string path = string.Format("{0}/meshes/{1}/mesh/", Application.persistentDataPath, meshId);
string[] extensions = { "dae", "fbx", "obj", "gltf2", "stl", "ply", "3mf"};
string[] extensions = { "dae", "fbx", "obj", "gltf2", "stl", "ply", "3mf" };
string[] files = { };
foreach (var extension in extensions) {
files = System.IO.Directory.GetFiles(path, "*." + extension);
Expand Down Expand Up @@ -198,7 +199,7 @@ public bool CheckIfNewerRobotModelExists(string meshId, string fileName) {
// Check whether downloading can be started and start it, if so.
return CanIDownload(meshId);
}

string uri = MainSettingsMenu.Instance.GetProjectServiceURI() + fileName;
DateTime downloadedZipLastModified = meshFileInfo.LastWriteTime;
try {
Expand Down Expand Up @@ -259,7 +260,7 @@ public GameObject RootGameObject {
}

public string Name {
get;set;
get; set;
}

public ImportedMeshEventArgs(GameObject gameObject, string name) {
Expand Down
5 changes: 1 addition & 4 deletions arcor2_AREditor/Assets/BASE/Scripts/NotificationEntry.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NotificationEntry : MonoBehaviour
{
public class NotificationEntry : MonoBehaviour {
public TMPro.TMP_Text Title, Description, Timestamp;
}
5 changes: 1 addition & 4 deletions arcor2_AREditor/Assets/BASE/Scripts/Notifications.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Base {
public abstract class Notifications : Singleton<Notifications> {
Expand All @@ -11,7 +8,7 @@ public virtual void SaveLogs(string customNotificationTitle = "") {
}
public abstract void ShowNotification(string title, string text);

public virtual void ShowToastMessage(string message, int timeout=3) {
public virtual void ShowToastMessage(string message, int timeout = 3) {
ToastMessage.Instance.ShowMessage(message, timeout);
}
}
Expand Down
16 changes: 7 additions & 9 deletions arcor2_AREditor/Assets/BASE/Scripts/NotificationsModernUI.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Michsky.UI.ModernUIPack;
using System.IO;
using System;
using System.IO.Compression;
using System.Net;
using System.Net.Sockets;
using System.Net.Http;

namespace Base {
Expand Down Expand Up @@ -82,7 +79,7 @@ public async override void SaveLogs(IO.Swagger.Model.Scene scene, IO.Swagger.Mod
if (GameManager.Instance.SystemInfo != null) {
logsFile.WriteLine("Server version: " + GameManager.Instance.SystemInfo.Version);
}

logsFile.WriteLine("Editor API version: " + GameManager.ApiVersion);
if (GameManager.Instance.SystemInfo != null) {
logsFile.WriteLine("Server API version: " + GameManager.Instance.SystemInfo.ApiVersion);
Expand All @@ -103,8 +100,9 @@ public async override void SaveLogs(IO.Swagger.Model.Scene scene, IO.Swagger.Mod

// TODO why we upload logs only when the editor is connected to the server?
string serverDomain = WebsocketManager.Instance.GetServerDomain();

if (String.IsNullOrEmpty(serverDomain)) return;

if (String.IsNullOrEmpty(serverDomain))
return;

string uri = "http://" + serverDomain + ":6799/upload";
try {
Expand All @@ -118,12 +116,12 @@ public async override void SaveLogs(IO.Swagger.Model.Scene scene, IO.Swagger.Mod
formData.Add(fileStreamContent, "files", Path.GetFileName(zipname));
HttpResponseMessage response = await client.PostAsync(uri, formData);
if (!response.IsSuccessStatusCode) {
Debug.LogError("Error:" + zipname + " not uploaded");
} else {
Debug.LogError("Error:" + zipname + " not uploaded");
} else {
}

}

} catch (HttpRequestException ex) {
Debug.LogError($"Failed to upload logs to {uri}: " + ex.Message);
} catch (InvalidOperationException ex) {
Expand Down
Loading

0 comments on commit 1b4eb51

Please sign in to comment.