Skip to content

Commit 10791b9

Browse files
committed
[src] Add option to reload a SOFA scene which is already registered in the SofaContext. Will clear on the SOFA, reload and then reconnect objects on the Unity side
1 parent fa82d46 commit 10791b9

4 files changed

Lines changed: 38 additions & 4 deletions

File tree

Core/Scripts/Core/DAGNode/SofaDAGNode.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ protected override void Reconnect_impl()
320320
{
321321
if (m_impl != null)
322322
{
323-
SofaLog("SofaDAGNode " + UniqueNameId + " already has a SofaDAGNodeAPI.", 2);
323+
// This is not an error if unity node is not deleted. The api is still there and jsut need to be reconnected.
324+
SofaLog("SofaDAGNode " + UniqueNameId + " already has a SofaDAGNodeAPI.", 0);
324325
return;
325326
}
326327

Core/Scripts/Core/Data/SofaDataArchiver.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Collections.Generic;
44
using UnityEngine;
55
using SofaUnity;
6-
using XCharts.Runtime;
76

87
namespace SofaUnity
98
{

Core/Scripts/Editor/SofaContextEditor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,12 @@ void SceneFileSection(SofaContext context)
184184
EditorGUILayout.Separator();
185185
}
186186

187+
EditorGUILayout.Separator();
187188
// Label of the filename loaded
188189
EditorGUILayout.LabelField("Scene Filename: ", context.SceneFileMgr.SceneFilename);
189190

190191
context.UnLoadScene = GUILayout.Button("Unload Scene file");
192+
context.ReloadScene = GUILayout.Button("Reload Sofa Scene file");
191193
EditorGUILayout.Separator();
192194
}
193195

Core/Scripts/SofaContext.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,35 @@ public bool AsyncSimulation
150150
}
151151
}
152152

153-
153+
/// Setter to unload the current scene and clear the sofa context. Will call @sa ClearSofaScene.
154154
public bool UnLoadScene
155155
{
156156
set
157157
{
158158
if (value && m_impl != null)
159159
{
160-
Debug.Log("UnLoadScene " + value);
160+
if (m_log)
161+
Debug.Log("#### SofaContext UnLoadScene: " + value);
162+
161163
ClearSofaScene();
162164
}
163165
}
164166
}
165167

168+
/// Setter to reload the current scene. Will clear SOFA scene and reload it internally. Then will reconnect the graph in Unity. Will call @sa ReloadSofaScene.
169+
public bool ReloadScene
170+
{
171+
set
172+
{
173+
if (value && m_impl != null)
174+
{
175+
if (m_log)
176+
Debug.Log("#### SofaContext ReloadScene: " + value);
177+
178+
ReloadSofaScene();
179+
}
180+
}
181+
}
166182

167183
////////////////////////////////////////////
168184
//////// scale conversions ///////
@@ -619,6 +635,8 @@ public void LoadSofaScene()
619635
DoCatchSofaMessages();
620636
}
621637

638+
639+
/// Method to reconnect the current scene already loaded in SOFA with the existing Unity GameObject Hierarchy.
622640
protected void ReconnectSofaScene()
623641
{
624642
if (m_sceneFileMgr == null)
@@ -647,6 +665,20 @@ protected void ReconnectSofaScene()
647665
DoCatchSofaMessages();
648666
}
649667

668+
669+
/// Method to reload the current scene. Will clear SOFA scene and reload it internally. Then will reconnect the graph in Unity.
670+
public void ReloadSofaScene()
671+
{
672+
m_impl.stop();
673+
m_impl.unload();
674+
675+
ReconnectSofaScene();
676+
677+
m_impl.start();
678+
}
679+
680+
681+
/// Method to clear the current scene in SOFA and clear the graph in Unity.
650682
public void ClearSofaScene()
651683
{
652684
m_impl.stop();

0 commit comments

Comments
 (0)