Skip to content

Commit dc972c5

Browse files
authored
[src] Update call to get SOFA logs and some cleaning in SofaConext. Also update header API (#29)
* backup work * backup investigations * backup backup * backup stable version doing ... nothing * restore name - still stable * Restore createScene and loadDefaultPlugin - still stable * Update use of getMessage_out with new signature. remove some catch, seems to have a conflict with other threads
1 parent e4d5641 commit dc972c5

File tree

2 files changed

+72
-45
lines changed

2 files changed

+72
-45
lines changed

Source/SofaUE5/Private/SofaContext.cpp

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ void ASofaContext::OnConstruction(const FTransform& Transform)
6969
Super::OnConstruction(Transform);
7070

7171
#if WITH_EDITOR
72+
UE_LOG(SUnreal_log, Log, TEXT("########## ASofaContext:: BEfore createSofaContext: %s | %s ##########"), *this->GetName(), *LexToString(this->GetFlags()));
7273
if (m_sofaAPI == nullptr)
7374
{
7475
createSofaContext();
@@ -93,15 +94,16 @@ void ASofaContext::Destroyed()
9394
// First stop SOFA simulation
9495
m_sofaAPI->stop();
9596

96-
if (m_isMsgHandlerActivated == true)
97-
catchSofaMessages();
97+
//if (m_isMsgHandlerActivated == true)
98+
// catchSofaMessages();
9899

99100
if (m_log)
100101
UE_LOG(SUnreal_log, Log, TEXT("## ASofaContext::BeginDestroy: m_sofaAPI stopped"));
101102

102-
// Deactivate message handler
103+
// Deactivate message handler
103104
m_sofaAPI->activateMessageHandler(false);
104-
// Free SOFA context Ptr
105+
106+
// Free SOFA context Ptr
105107
m_sofaAPI.Reset();
106108

107109
if (m_log)
@@ -134,6 +136,9 @@ void ASofaContext::BeginPlay()
134136

135137
// Start SOFA simulation on UE play
136138
m_sofaAPI->start();
139+
140+
if (m_isMsgHandlerActivated == true)
141+
catchSofaMessages();
137142
}
138143
else
139144
{
@@ -153,8 +158,8 @@ void ASofaContext::EndPlay(const EEndPlayReason::Type EndPlayReason)
153158
// Stop SOFA simulation on UE play
154159
m_sofaAPI->stop();
155160

156-
if (m_isMsgHandlerActivated == true)
157-
catchSofaMessages();
161+
if (m_isMsgHandlerActivated == true)
162+
catchSofaMessages();
158163
}
159164

160165
Super::EndPlay(EndPlayReason);
@@ -214,12 +219,14 @@ void ASofaContext::Tick( float DeltaTime )
214219
{
215220
if (m_status != -1 && m_sofaAPI)
216221
{
217-
// Step SOFA simulation on each UE tick
222+
// Step SOFA simulation on each UE tick
218223
m_sofaAPI->step();
219224

220-
float value = this->GetGameTimeSinceCreation();
221225
//double stime = m_sofaAPI->getTime();
222-
226+
227+
//if (m_isMsgHandlerActivated == true)
228+
// catchSofaMessages();
229+
float value = this->GetGameTimeSinceCreation();
223230
//UE_LOG(LogTemp, Warning, TEXT("## ASofaContext: Tick: %f %f"), value, stime);
224231
}
225232

@@ -231,8 +238,8 @@ void ASofaContext::Tick( float DeltaTime )
231238

232239
void ASofaContext::createSofaContext()
233240
{
234-
if (m_log)
235-
UE_LOG(SUnreal_log, Log, TEXT("########## ASofaContext::createSofaContext: %s | %s ##########"), *this->GetName(), *LexToString(this->GetFlags()));
241+
//if (m_log)
242+
UE_LOG(SUnreal_log, Log, TEXT("########## ASofaContext::createSofaContext: %s | %s ##########"), *this->GetName(), *LexToString(this->GetFlags()));
236243

237244
if (m_sofaAPI != nullptr) {
238245
UE_LOG(SUnreal_log, Error, TEXT("## ASofaContext::createSofaContext is called with a SofaAPI already created."));
@@ -324,39 +331,48 @@ void ASofaContext::loadSofaScene()
324331
// Pass default scene parameter
325332
// this->setDT(Dt);
326333
// this->setGravity(Gravity);
327-
328-
// Start parsing scene loaded in SOFA
329-
// Create the actor of the scene:
330334

331335
if (m_isMsgHandlerActivated == true)
332336
catchSofaMessages();
333-
334-
//m_status++;
335337
}
336338

337339
void ASofaContext::loadDefaultPlugin()
338340
{
339341
if (m_sofaAPI == nullptr)
340342
return;
341343

344+
bool debugMode = false;
345+
346+
#if (UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT) && !UE_BUILD_SHIPPING
347+
debugMode = true;
348+
#endif
349+
342350
FString curPath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir());
343-
FString pluginPaths = curPath + "Plugins/SofaUE5/Binaries/ThirdParty/SofaUE5Library/Win64";
351+
FString pluginPaths;
352+
if (debugMode)
353+
pluginPaths = curPath + "Plugins/SofaUE5/Binaries/ThirdParty/SofaUE5Library/Win64/Debug/";
354+
else
355+
pluginPaths = curPath + "Plugins/SofaUE5/Binaries/ThirdParty/SofaUE5Library/Win64/Release/";
356+
344357
const char* pluginPchar = TCHAR_TO_ANSI(*pluginPaths);
345358
int resPlug = m_sofaAPI->loadDefaultPlugins(pluginPchar);
346359
if (resPlug != 0) {
347360
UE_LOG(SUnreal_log, Error, TEXT("## ASofaContext::createSofaContext: loadDefaultPlugin failed, returns: %d"), resPlug);
348361
}
349362

350-
if (m_isMsgHandlerActivated == true)
351-
catchSofaMessages();
363+
//if (m_isMsgHandlerActivated == true)
364+
// catchSofaMessages();
352365
}
353366

354367

368+
// Start parsing scene loaded in SOFA
369+
// Create the actor of the scene:
370+
355371
void ASofaContext::loadNodeGraph()
356372
{
357373
if (m_sofaAPI == nullptr)
358374
return;
359-
375+
360376
clearNodeGraph();
361377

362378
int nbrNode = m_sofaAPI->getNbrDAGNode();
@@ -540,25 +556,23 @@ void ASofaContext::catchSofaMessages()
540556
{
541557
int nbrMsgs = m_sofaAPI->getNbMessages();
542558
UE_LOG(SUnreal_log, Warning, TEXT("## ASofaContext::catchSofaMessages: nbr message: %d"), nbrMsgs);
543-
544-
int* type = new int[1];
545-
type[0] = -1;
546-
std::string rawMsg;
559+
547560
for (int i = 0; i < nbrMsgs; ++i)
548561
{
549-
m_sofaAPI->getMessage_out(i, *type, rawMsg);
562+
std::string rawMsg;
563+
int type = m_sofaAPI->getMessage_out(i, rawMsg);
550564
FString FMessage(rawMsg.c_str());
551565

552-
if (type[0] == -1) {
566+
if (type == -1) {
553567
continue;
554568
}
555-
else if (type[0] == 3) {
569+
else if (type == 3) {
556570
UE_LOG(SofaLog, Warning, TEXT("%s"), *FMessage);
557571
}
558-
else if (type[0] == 4) {
572+
else if (type == 4) {
559573
UE_LOG(SofaLog, Error, TEXT("%s"), *FMessage);
560574
}
561-
else if (type[0] == 5) {
575+
else if (type == 5) {
562576
UE_LOG(SofaLog, Fatal, TEXT("%s"), *FMessage);
563577
}
564578
else {
@@ -567,6 +581,4 @@ void ASofaContext::catchSofaMessages()
567581
}
568582

569583
m_sofaAPI->clearMessages();
570-
571-
delete[] type;
572584
}

Source/ThirdParty/SofaUE5Library/Public/SofaUE5Library/SofaAdvancePhysicsAPI.h

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ namespace sofaVerseAPI
5252
class SofaBaseComponentAPI;
5353

5454
class SofaBaseMeshAPI;
55+
56+
class SofaPliersManager;
57+
5558
}
5659

5760

@@ -139,7 +142,10 @@ class SOFA_VERSE_API SofaAdvancePhysicsAPI
139142
int activateMessageHandler(bool value);
140143
int getNbMessages();
141144
std::string getMessage(int messageId, int& msgType);
142-
void getMessage_out(int messageId, int& msgType, std::string& outName);
145+
146+
/// Return the message type and copy the message in @param outName of the message id @param messageId
147+
int getMessage_out(int messageId, std::string& outName);
148+
/// Clear all stored in memory messages
143149
int clearMessages();
144150

145151
////////////////////////////////////////////
@@ -265,12 +271,14 @@ class SOFA_VERSE_API SofaAdvancePhysicsAPI
265271
int setToolAttribute(const std::string& name, const std::string& dataName, float* value);
266272
const std::string& getInteractObjectName(const std::string& name);
267273

268-
int createPliers(const std::string& pliersName, const std::string& nameMord1, const std::string& nameMord2, const std::string& nameModel, float _stiffness);
274+
int createPliers(const std::string& pliersName);
269275

270276
int unactivePliers(const std::string& pliersName);
271277
int reactivePliers(const std::string& pliersName);
272278
int closePliers(const std::string& pliersName);
273279
int releasePliers(const std::string& pliersName);
280+
int performAction(const std::string& pliersName);
281+
int stopAction(const std::string& pliersName);
274282
int idGrabed(const std::string& pliersName, int* ids);
275283

276284
int createEntactManager(const std::string& toolName);
@@ -412,23 +420,30 @@ class SOFA_VERSE_API SofaAdvancePhysicsAPI
412420
int registerRenderEvent(SofaRenderEventPtr event);
413421

414422
protected:
415-
sofaVerseAPI::SofaDAGNodesManager* m_sofaNodeManager = nullptr;
416423
/// Internal implementation sub-class
417-
sofaVerseAPI::SofaSimulationManager* m_simulationMgr;
418-
sofaVerseAPI::SofaComponentsManager* m_sofaComponentManager = nullptr;
424+
std::shared_ptr <sofaVerseAPI::SofaSimulationManager> m_simulationMgr = nullptr;
425+
std::shared_ptr <sofaVerseAPI::SofaDAGNodesManager> m_sofaNodeManager = nullptr;
426+
std::shared_ptr <sofaVerseAPI::SofaComponentsManager> m_sofaComponentManager = nullptr;
427+
428+
std::shared_ptr <SofaPhysicsObjectsManager> m_3DObjectManager = nullptr;
429+
std::shared_ptr <SofaPhysicsInteractionsManager> m_3DInteractionsManager = nullptr;
419430

420-
SofaPhysicsObjectsManager* m_3DObjectManager = nullptr;
421-
SofaPhysicsInteractionsManager* m_3DInteractionsManager = nullptr;
431+
std::shared_ptr <sofaVerseAPI::SofaPliersManager> m_pliersManager = nullptr;
422432

423-
SofaPliersManager* m_pliersManager = nullptr;
424-
SofaEntactManager* m_entactManager = nullptr;
425-
SofaGeomagicManager* m_geomagicManager = nullptr;
426-
SofaHaplyRoboticsManager* m_haplyManager = nullptr;
427-
SofaKeyEventManager* m_keyEventManager = nullptr;
433+
#ifdef HAS_ENTACT_PLUGIN
434+
std::shared_ptr <SofaEntactManager> m_entactManager = nullptr;
435+
#endif
436+
437+
std::shared_ptr <SofaGeomagicManager> m_geomagicManager = nullptr;
438+
439+
#ifdef HAS_HAPLY_PLUGIN
440+
std::shared_ptr <SofaHaplyRoboticsManager> m_haplyManager = nullptr;
441+
#endif
442+
std::shared_ptr <SofaGraphicManager> m_graphicManager = nullptr;
443+
std::shared_ptr <SofaKeyEventManager> m_keyEventManager = nullptr;
428444

429-
SofaGraphicManager* m_graphicManager = nullptr;
430445

431-
std::string m_APIName;
446+
std::string m_APIName = "SofaAdvancePhysicsAPI";
432447

433448
int m_stateMachine;
434449
};

0 commit comments

Comments
 (0)