Skip to content

Commit

Permalink
Merge pull request #189 from Kapim/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
Kapim authored Nov 20, 2020
2 parents 71e9dcb + badfcb1 commit 91a8aff
Show file tree
Hide file tree
Showing 34 changed files with 763 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void OnOverrideAddedOrUpdated(object sender, ParameterEventArgs args) {
public async void CreateNewAP(string name) {
Debug.Assert(CurrentObject != null);

Vector3 abovePoint = SceneManager.Instance.GetCollisionFreePointAbove(CurrentObject.transform, Vector3.one * 0.025f, Quaternion.identity);
Vector3 abovePoint = SceneManager.Instance.GetCollisionFreePointAbove(CurrentObject.transform, Vector3.one * 0.1f, Quaternion.identity);
IO.Swagger.Model.Position offset = DataHelper.Vector3ToPosition(TransformConvertor.UnityToROS(abovePoint));
bool result = await GameManager.Instance.AddActionPoint(name, CurrentObject.Data.Id, offset);
if (result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void ShowAddActionPointDialog() {
public async void AddAP(string name) {
Debug.Assert(CurrentActionPoint != null);

Vector3 abovePoint = SceneManager.Instance.GetCollisionFreePointAbove(CurrentActionPoint.transform, Vector3.one * 0.025f, Quaternion.identity);
Vector3 abovePoint = SceneManager.Instance.GetCollisionFreePointAbove(CurrentActionPoint.transform, Vector3.one * 0.1f, Quaternion.identity);
IO.Swagger.Model.Position offset = DataHelper.Vector3ToPosition(TransformConvertor.UnityToROS(abovePoint));
bool result = await GameManager.Instance.AddActionPoint(name, CurrentActionPoint.Data.Id, offset);
if (result)
Expand Down
29 changes: 11 additions & 18 deletions arcor2_AREditor/Assets/2D_EDITOR/Scripts/ConnectionManagerArcoro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,39 @@ public class ConnectionManagerArcoro : Base.Singleton<ConnectionManagerArcoro> {
[SerializeField]
private Material EnabledMaterial, DisabledMaterial;

public bool ConnectionsActive = true;

private void Start() {
virtualPointer = VirtualConnectionOnTouch.Instance.VirtualPointer;

Base.GameManager.Instance.OnCloseProject += OnCloseProject;
}


public Connection CreateConnection(GameObject o1, GameObject o2) {
if (!ConnectionsActive)
return null;
GameObject c = Instantiate(ConnectionPrefab);
Connection c = Instantiate(ConnectionPrefab).GetComponent<Connection>();
c.transform.SetParent(transform);
// Set correct targets. Output has to be always at 0 index, because we are connecting output to input.
// Output has direction to the east, while input has direction to the west.
if (o1.GetComponent<Base.InputOutput>().GetType() == typeof(Base.PuckOutput)) {
c.GetComponent<Connection>().target[0] = o1.GetComponent<RectTransform>();
c.GetComponent<Connection>().target[1] = o2.GetComponent<RectTransform>();
c.target[0] = o1.GetComponent<RectTransform>();
c.target[1] = o2.GetComponent<RectTransform>();
} else {
c.GetComponent<Connection>().target[1] = o1.GetComponent<RectTransform>();
c.GetComponent<Connection>().target[0] = o2.GetComponent<RectTransform>();
c.target[1] = o1.GetComponent<RectTransform>();
c.target[0] = o2.GetComponent<RectTransform>();
}
Connections.Add(c.GetComponent<Connection>());
return c.GetComponent<Connection>();
Connections.Add(c);
if (!ControlBoxManager.Instance.ConnectionsToggle.isOn)
c.gameObject.SetActive(false);

return c;
}

public void CreateConnectionToPointer(GameObject o) {
if (!ConnectionsActive)
return;
if (virtualConnectionToMouse != null)
Destroy(virtualConnectionToMouse.gameObject);
VirtualConnectionOnTouch.Instance.DrawVirtualConnection = true;
virtualConnectionToMouse = CreateConnection(o, virtualPointer);
}

public void DestroyConnectionToMouse() {
if (!ConnectionsActive)
return;
Destroy(virtualConnectionToMouse.gameObject);
Connections.Remove(virtualConnectionToMouse);
VirtualConnectionOnTouch.Instance.DrawVirtualConnection = false;
Expand Down Expand Up @@ -133,7 +127,7 @@ public async Task<bool> ValidateConnection(InputOutput output, InputOutput input
return true;
}

private void OnCloseProject(object sender, EventArgs e) {
public void Clear() {
foreach (Connection c in Connections) {
if (c != null && c.gameObject != null) {
Destroy(c.gameObject);
Expand All @@ -146,7 +140,6 @@ public void DisplayConnections(bool active) {
foreach (Connection connection in Connections) {
connection.gameObject.SetActive(active);
}
ConnectionsActive = active;
}

public void DisableConnectionToMouse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override void InitActionObject(string id, string type, Vector3 position,
throw new System.NotImplementedException();
}

public override void SetVisibility(float value) {
public override void SetVisibility(float value, bool forceShaderChange = false) {
throw new System.NotImplementedException();
}

Expand Down
4 changes: 2 additions & 2 deletions arcor2_AREditor/Assets/BASE/Scripts/ActionObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public void RemoveActionPoints() {
}


public virtual void SetVisibility(float value) {
Debug.Assert(value >= 0 && value <= 1, "Action object: " + Data.Id + " SetVisibility(" + value.ToString() + ")");
public virtual void SetVisibility(float value, bool forceShaderChange = false) {
//Debug.Assert(value >= 0 && value <= 1, "Action object: " + Data.Id + " SetVisibility(" + value.ToString() + ")");
visibility = value;
PlayerPrefsHelper.SaveFloat(SceneManager.Instance.SceneMeta.Id + "/ActionObject/" + Data.Id + "/visibility", value);
}
Expand Down
2 changes: 1 addition & 1 deletion arcor2_AREditor/Assets/BASE/Scripts/ControlBoxManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void ShowCreateGlobalActionPointDialog() {
}

public async void CreateGlobalActionPoint(string name) {
Vector3 abovePoint = SceneManager.Instance.GetCollisionFreePointAbove(SceneManager.Instance.SceneOrigin.transform, Vector3.one * 0.025f, Quaternion.identity);
Vector3 abovePoint = SceneManager.Instance.GetCollisionFreePointAbove(SceneManager.Instance.SceneOrigin.transform, Vector3.one * 0.1f, Quaternion.identity);
IO.Swagger.Model.Position offset = DataHelper.Vector3ToPosition(TransformConvertor.UnityToROS(abovePoint));

bool result = await GameManager.Instance.AddActionPoint(name, "", offset);
Expand Down
7 changes: 4 additions & 3 deletions arcor2_AREditor/Assets/BASE/Scripts/InputOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ public LogicItem GetLogicItem() {
}

public override async void OnClick(Click type) {
if (!ControlBoxManager.Instance.ConnectionsToggle.isOn) {
Notifications.Instance.ShowNotification("Cannot manipulate connections", "When connections are disabled, they cannot be manipulated");
return;
}
if (GameManager.Instance.GetEditorState() != GameManager.EditorStateEnum.Normal) {
//return;
}
if (!ConnectionManagerArcoro.Instance.ConnectionsActive) {
return;
}
if (GameManager.Instance.GetGameState() != GameManager.GameStateEnum.ProjectEditor) {
Notifications.Instance.ShowNotification("Not allowed", "Editation of connections only allowed in project editor");
return;
Expand Down
3 changes: 3 additions & 0 deletions arcor2_AREditor/Assets/BASE/Scripts/Interfaces/IRobot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public interface IRobot
void SetJointValue(string name, float angle, bool angle_in_degrees = false);

List<IO.Swagger.Model.Joint> GetJoints();

void SetGrey(bool grey);

}
1 change: 0 additions & 1 deletion arcor2_AREditor/Assets/BASE/Scripts/Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ public static GameObject InitializeJointsParameter(ParameterMetadata actionParam
foreach (Base.ActionPoint ap in Base.ProjectManager.Instance.GetAllActionPoints()) {
foreach (IO.Swagger.Model.ProjectRobotJoints joints in ap.GetAllJoints(false, null, false).Values) {
string prefix = "";
Debug.LogError(joints.RobotId + " - " + actionProviderId);
if (joints.RobotId != actionProviderId)
prefix = "(another robot) ";
else if (!joints.IsValid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UnityEngine.UI;
using Michsky.UI.ModernUIPack;
using UnityEngine.Events;
using UnityEngine.Analytics;

public class SwitchComponent : MonoBehaviour, IParameter
{
Expand Down Expand Up @@ -61,7 +62,10 @@ public void SetDarkMode(bool dark) {
}

public void AddOnValueChangedListener(UnityAction<bool> callback) {
Switch.OnEvents.RemoveAllListeners();
Switch.OnEvents.AddListener(OnChange);
Switch.OffEvents.RemoveAllListeners();
Switch.OffEvents.AddListener(OnChange);
onChangeCallback = callback;
}

Expand Down
7 changes: 4 additions & 3 deletions arcor2_AREditor/Assets/BASE/Scripts/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ public async Task<bool> CreateProject(IO.Swagger.Model.Project project, bool all
foreach (IO.Swagger.Model.Parameter p in objectOverrides.Parameters) {
if (actionObject.TryGetParameterMetadata(p.Name, out ParameterMeta meta)) {
Parameter parameter = new Parameter(meta, p.Value);
Debug.LogError(parameter);
actionObject.Overrides[p.Name] = parameter;
}

Expand Down Expand Up @@ -355,6 +354,8 @@ public bool DestroyProject() {
EndAction = null;
}
ActionPoints.Clear();
ConnectionManagerArcoro.Instance.Clear();
LogicItems.Clear();
return true;
}

Expand All @@ -367,9 +368,9 @@ private void UpdateLogicItems(List<IO.Swagger.Model.LogicItem> logic) {
if (!LogicItems.TryGetValue(projectLogicItem.Id, out LogicItem logicItem)) {
logicItem = new LogicItem(projectLogicItem);
LogicItems.Add(logicItem.Data.Id, logicItem);
} else {
logicItem.UpdateConnection(projectLogicItem);
}
logicItem.UpdateConnection(projectLogicItem);

}
}

Expand Down
15 changes: 13 additions & 2 deletions arcor2_AREditor/Assets/BASE/Scripts/SceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,18 @@ private void OnSceneState(object sender, SceneStateEventArgs args) {
Notifications.Instance.ShowNotification("Scene service failed", args.Event.Message);
}
OnHideRobotsEE?.Invoke(this, EventArgs.Empty);
foreach (IRobot robot in GetRobots()) {
robot.SetGrey(true);
}
break;
case SceneStateData.StateEnum.Started:
SceneStarted = true;
if (RobotsEEVisible)
OnShowRobotsEE?.Invoke(this, EventArgs.Empty);
RegisterRobotsForEvent(true, RegisterForRobotEventRequestArgs.WhatEnum.Joints);
foreach (IRobot robot in GetRobots()) {
robot.SetGrey(false);
}
GameManager.Instance.HideLoadingScreen();
break;
case SceneStateData.StateEnum.Stopped:
Expand All @@ -302,6 +308,10 @@ private void OnSceneState(object sender, SceneStateEventArgs args) {
OnSceneStateEvent?.Invoke(this, args);
}

private void InitScene() {

}

/// <summary>
/// Register or unregister to/from subsription of joints or end effectors pose of each robot in the scene.
/// </summary>
Expand Down Expand Up @@ -462,15 +472,15 @@ public Vector3 GetCollisionFreePointAbove(Transform transform, Vector3 bbSize, Q
tmpGo.transform.localPosition = Vector3.zero;
tmpGo.transform.localRotation = Quaternion.identity;

Collider[] colliders = Physics.OverlapBox(transform.position, bbSize / 2, orientation); //OverlapSphere(tmpGo.transform.position, 0.025f);
Collider[] colliders = Physics.OverlapBox(transform.position, bbSize, orientation); //OverlapSphere(tmpGo.transform.position, 0.025f);

// to avoid infinite loop
int i = 0;
while (colliders.Length > 0 && i < 40) {
Collider collider = colliders[0];
// TODO - depends on the rotation between detected marker and original position of camera, height of collision free point above will be slightly different
// How to solve this?
tmpGo.transform.Translate(new Vector3(0, collider.bounds.extents.y + 0.05f, 0), SceneOrigin.transform);
tmpGo.transform.Translate(new Vector3(0, collider.bounds.extents.y, 0), SceneOrigin.transform);
colliders = Physics.OverlapBox(tmpGo.transform.position, bbSize / 2, orientation);
++i;
}
Expand All @@ -494,6 +504,7 @@ public ActionObject SpawnActionObject(string id, string type, CollisionModels cu
if (aom.Robot) {
//Debug.Log("URDF: spawning RobotActionObject");
obj = Instantiate(RobotPrefab, ActionObjectsSpawn.transform);

} else {
obj = Instantiate(ActionObjectPrefab, ActionObjectsSpawn.transform);
}
Expand Down
Loading

0 comments on commit 91a8aff

Please sign in to comment.