Skip to content

Commit

Permalink
Merge pull request #218 from xBambusekD/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
xBambusekD authored Jun 22, 2021
2 parents f6e122d + 9ee81a9 commit 06800ed
Show file tree
Hide file tree
Showing 32 changed files with 350 additions and 455 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using UnityEngine.UI;
using Newtonsoft.Json;
using Base;
using IO.Swagger.Model;

public class AddNewActionObjectDialog : Dialog {
public GameObject DynamicContent, CanvasRoot;
Expand Down Expand Up @@ -32,7 +33,7 @@ private void Init() {
/// <param name="callback">Function to be called if adding action object was successful</param>
public void InitFromMetadata(Base.ActionObjectMetadata metadata, System.Action callback = null) {
InitDialog(metadata);
actionParameters = Parameter.InitParameters(parametersMetadata.Values.ToList(), DynamicContent, OnChangeParameterHandler, DynamicContentLayout, CanvasRoot, false, false);
actionParameters = Base.Parameter.InitParameters(parametersMetadata.Values.ToList(), DynamicContent, OnChangeParameterHandler, DynamicContentLayout, CanvasRoot, false, false);
nameInput.SetValue(Base.SceneManager.Instance.GetFreeAOName(metadata.Type));
this.callback = callback;
}
Expand Down Expand Up @@ -79,12 +80,10 @@ public async void CreateActionObject() {
parameters.Add(DataHelper.ActionParameterToParameter(ap));
}
try {
IO.Swagger.Model.Pose pose = null;
if (actionObjectMetadata.HasPose) {
Vector3 abovePoint = SceneManager.Instance.GetCollisionFreePointAbove(SceneManager.Instance.SceneOrigin.transform, actionObjectMetadata.GetModelBB(), SceneManager.Instance.SceneOrigin.transform.localRotation);
IO.Swagger.Model.Position offset = DataHelper.Vector3ToPosition(TransformConvertor.UnityToROS(abovePoint));
pose = new IO.Swagger.Model.Pose(position: offset, orientation: new IO.Swagger.Model.Orientation(1, 0, 0, 0));
}
Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0f));
Vector3 point = TransformConvertor.UnityToROS(GameManager.Instance.Scene.transform.InverseTransformPoint(ray.GetPoint(0.5f)));
IO.Swagger.Model.Pose pose = new IO.Swagger.Model.Pose(position: DataHelper.Vector3ToPosition(point), orientation: DataHelper.QuaternionToOrientation(Quaternion.identity));
SceneManager.Instance.SelectCreatedActionObject = newActionObjectName;
await Base.WebsocketManager.Instance.AddObjectToScene(newActionObjectName, actionObjectMetadata.Type, pose, parameters);
callback?.Invoke();
Close();
Expand Down
29 changes: 1 addition & 28 deletions arcor2_AREditor/Assets/BASE/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -945,34 +945,7 @@ private async Task UpdateRobotsMeta() {
ActionsManager.Instance.UpdateRobotsMetadata(await WebsocketManager.Instance.GetRobotMeta());
}

/// <summary>
/// Sends request to the server to create a new Action Object of user specified type and id. Id has to be generated here in the client.
/// </summary>
/// <param name="type"></param>
/// <param name="name"></param>
/// <returns></returns>
public async Task<bool> AddObjectToScene(string type, string name) {
try {
IO.Swagger.Model.Pose pose = null;
if (ActionsManager.Instance.ActionObjectMetadata.TryGetValue(type, out ActionObjectMetadata actionObjectMetadata)) {
if (actionObjectMetadata.HasPose) {
Vector3 abovePoint = SceneManager.Instance.GetCollisionFreePointAbove(SceneManager.Instance.SceneOrigin.transform, actionObjectMetadata.GetModelBB(), SceneManager.Instance.SceneOrigin.transform.localRotation);
IO.Swagger.Model.Position offset = DataHelper.Vector3ToPosition(TransformConvertor.UnityToROS(abovePoint));
pose = new IO.Swagger.Model.Pose(position: offset, orientation: new IO.Swagger.Model.Orientation(1, 0, 0, 0));
}
await WebsocketManager.Instance.AddObjectToScene(name, type, pose, null);
} else {
throw new RequestFailedException("Object type " + type + " does not exists");
}
} catch (RequestFailedException ex) {
Debug.LogError(ex);
Notifications.Instance.ShowNotification("Failed to add object to scene", ex.Message);
return false;
}
return true;
}



/// <summary>
/// When package runs failed with exception, show notification to the user
/// </summary>
Expand Down
21 changes: 0 additions & 21 deletions arcor2_AREditor/Assets/BASE/Scripts/OnHoverCollider.cs

This file was deleted.

11 changes: 0 additions & 11 deletions arcor2_AREditor/Assets/BASE/Scripts/OnHoverCollider.cs.meta

This file was deleted.

4 changes: 0 additions & 4 deletions arcor2_AREditor/Assets/BASE/Scripts/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ public bool ProjectChanged {
}
}

public string SelectAPNameWhenCreated {
get;
internal set;
}

/// <summary>
/// Invoked when some of the action point weas updated. Contains action point description
Expand Down
8 changes: 7 additions & 1 deletion arcor2_AREditor/Assets/BASE/Scripts/SceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public bool RobotsEEVisible {

public RobotEE SelectedEndEffector;

public string SelectCreatedActionObject;

public bool Valid = false;
/// <summary>
/// Public setter for sceneChanged property. Invokes OnSceneChanged event with each change and
Expand Down Expand Up @@ -720,7 +722,11 @@ public void SceneObjectBaseUpdated(SceneObject sceneObject) {
/// <param name="sceneObject">Description of action object</param>
/// <returns></returns>
public void SceneObjectAdded(SceneObject sceneObject) {
ActionObject actionObject = SpawnActionObject(sceneObject);
ActionObject actionObject = SpawnActionObject(sceneObject);
if (!string.IsNullOrEmpty(SelectCreatedActionObject) && sceneObject.Name.Contains(SelectCreatedActionObject)) {
SelectorMenu.Instance.SetSelectedObject(actionObject.SelectorItem, true);
}
SelectCreatedActionObject = "";
updateScene = true;
}

Expand Down
8 changes: 3 additions & 5 deletions arcor2_AREditor/Assets/BASE/Scripts/URDF/RobotActionObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@ private Task<bool> WaitUntilResourcesReady() {

public async Task<bool> LoadEndEffectors() {
// TODO: maybe wrong condition
if (((GameManager.Instance.GetGameState() == GameManager.GameStateEnum.SceneEditor) && !SceneManager.Instance.Valid)
|| ((GameManager.Instance.GetGameState() == GameManager.GameStateEnum.ProjectEditor) && !ProjectManager.Instance.Valid)) {
Debug.LogError("SceneManager or ProjectManager instance not valid");
Debug.LogError(GameManager.Instance.GetGameState());
if (!SceneManager.Instance.Valid) {
Debug.LogError("SceneManager instance not valid");
return false;
}
if (loadingEndEffectors) {
Expand Down Expand Up @@ -690,7 +690,6 @@ public void SetGrey(bool grey, bool force = false) {
public override async void OpenMenu() {
if (!await this.WriteLock(false))
return;
TransformGizmo.Instance.ClearTargets();
outlineOnClick.GizmoUnHighlight();
if (Base.GameManager.Instance.GetGameState() == Base.GameManager.GameStateEnum.SceneEditor) {
actionObjectMenu.CurrentObject = this;
Expand All @@ -709,7 +708,6 @@ public override bool HasMenu() {
public override async void StartManipulation() {
if (!await this.WriteLock(true))
return;
TransformGizmo.Instance.ClearTargets();
manipulationStarted = true;
HideRobotEE();
TransformGizmo.Instance.AddTarget(transform);
Expand Down
2 changes: 1 addition & 1 deletion arcor2_AREditor/Assets/BASE/Scripts/URDF/RobotModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private bool IsRobotLoaded() {
private void OnRobotLoaded() {
//Debug.Log("URDF: robot is fully loaded");

SetActiveAllVisuals(true);
SetActiveAllVisuals(false);

AddOnClickScriptToColliders(RobotModelGameObject);

Expand Down
14 changes: 6 additions & 8 deletions arcor2_AREditor/Assets/BASE/Scripts/WebsocketManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2297,14 +2297,12 @@ public async Task StartScene(bool dryRun) {
}
}

public async Task StopScene(bool dryRun) {
int r_id = Interlocked.Increment(ref requestID);
IO.Swagger.Model.StopSceneRequest request = new IO.Swagger.Model.StopSceneRequest(r_id, "StopScene", dryRun: dryRun);
SendDataToServer(request.ToJson(), r_id, true);
IO.Swagger.Model.StopSceneResponse response = await WaitForResult<IO.Swagger.Model.StopSceneResponse>(r_id);
if (response == null || !response.Result) {
throw new RequestFailedException(response == null ? new List<string>() { "Failed to stop scene" } : response.Messages);
}
public void StopScene(bool dryRun, UnityAction<string, string> callback) {
int id = Interlocked.Increment(ref requestID);
if (callback != null)
responsesCallback.Add(id, Tuple.Create("", callback));
IO.Swagger.Model.StopSceneRequest request = new IO.Swagger.Model.StopSceneRequest(id, "StopScene", dryRun: dryRun);
SendDataToServer(request.ToJson(), id, false);
}

public async Task UpdateObjectParameters(string id, List<IO.Swagger.Model.Parameter> parameters, bool dryRun) {
Expand Down
23 changes: 9 additions & 14 deletions arcor2_AREditor/Assets/TABLET/Prefabs/Action.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
Enabled: 1
SelectorItem: {fileID: 0}
Colliders:
- {fileID: 7592340303395121290}
Action: {fileID: -4901143462678197493}
Expand All @@ -125,6 +126,8 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
Enabled: 1
OutlineSize: 1
OutlineHoverSize: 1
OutlineShaderType: 0
OutlineClickFirstPass: {fileID: 2100000, guid: ad5f46c258da37740a57c75f33330d0d,
type: 2}
Expand Down Expand Up @@ -427,6 +430,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
Enabled: 1
SelectorItem: {fileID: 0}
Colliders:
- {fileID: 5362052914937072908}
Action: {fileID: -4901143462678197493}
Expand All @@ -444,6 +448,8 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
Enabled: 1
OutlineSize: 1
OutlineHoverSize: 1
OutlineShaderType: 0
OutlineClickFirstPass: {fileID: 2100000, guid: ad5f46c258da37740a57c75f33330d0d,
type: 2}
Expand Down Expand Up @@ -472,7 +478,6 @@ GameObject:
- component: {fileID: 6417292780173919764}
- component: {fileID: 6417292780173919765}
- component: {fileID: 6417292780173919763}
- component: {fileID: 8409126376922550219}
- component: {fileID: 7467850720681680514}
m_Layer: 0
m_Name: Cylinder
Expand Down Expand Up @@ -556,19 +561,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
Enabled: 1
Target: {fileID: 6417292780430755493}
--- !u!114 &8409126376922550219
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6417292780173919761}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9673c2375ff70d043956c1eebf26e270, type: 3}
m_Name:
m_EditorClassIdentifier:
Target: {fileID: 6417292780430755493}
--- !u!64 &7467850720681680514
MeshCollider:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -630,6 +622,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
Enabled: 1
SelectorItem: {fileID: 0}
Colliders:
- {fileID: 7467850720681680514}
Input: {fileID: 4512397415820150178}
Expand All @@ -654,6 +647,8 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
Enabled: 1
OutlineSize: 1
OutlineHoverSize: 1
OutlineShaderType: 0
OutlineClickFirstPass: {fileID: 2100000, guid: ad5f46c258da37740a57c75f33330d0d,
type: 2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
Enabled: 1
OutlineShaderType: 0
OutlineSize: 1
OutlineHoverSize: 1
OutlineShaderType: 1
OutlineClickFirstPass: {fileID: 2100000, guid: 5a34724aa4ed6d942bea3c530bc7477e,
type: 2}
OutlineClickSecondPass: {fileID: 2100000, guid: 70d480e8ad3b0114995e1ef19f3e76b6,
Expand Down
Loading

0 comments on commit 06800ed

Please sign in to comment.