MCPcopy Create free account
hub / github.com/URLab-Sim/UnrealRoboticsLab / AutoParentSCSNode

Method AutoParentSCSNode

Source/URLabEditor/Private/URLabEditor.cpp:338–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

336}
337
338bool FURLabEditorModule::AutoParentSCSNode(USCS_Node* Node, USimpleConstructionScript* SCS)
339{
340 if (!Node || !Node->ComponentTemplate)
341 return false;
342
343 // Determine the correct parent folder name for this component type
344 FString TargetParentName;
345 if (Node->ComponentTemplate->IsA<UMjSensor>())
346 TargetParentName = TEXT("SensorsRoot");
347 else if (Node->ComponentTemplate->IsA<UMjActuator>())
348 TargetParentName = TEXT("ActuatorsRoot");
349 else if (Node->ComponentTemplate->IsA<UMjDefault>())
350 TargetParentName = TEXT("DefaultsRoot");
351 else if (Node->ComponentTemplate->IsA<UMjTendon>())
352 TargetParentName = TEXT("TendonsRoot");
353 else if (Node->ComponentTemplate->IsA<UMjContactPair>() || Node->ComponentTemplate->IsA<UMjContactExclude>())
354 TargetParentName = TEXT("ContactsRoot");
355 else if (Node->ComponentTemplate->IsA<UMjEquality>())
356 TargetParentName = TEXT("EqualitiesRoot");
357 else
358 return false;
359
360 // Check if already correctly parented
361 USCS_Node* CurrentParent = SCS->FindParentNode(Node);
362 if (CurrentParent && CurrentParent->GetVariableName().ToString() == TargetParentName)
363 return false;
364
365 // Skip components that are under DefaultsRoot — they are default templates
366 // and must not be moved to organizational folders
367 {
368 USCS_Node* Ancestor = CurrentParent;
369 while (Ancestor)
370 {
371 if (Ancestor->GetVariableName().ToString() == TEXT("DefaultsRoot"))
372 return false;
373 Ancestor = SCS->FindParentNode(Ancestor);
374 }
375 }
376
377 // Find the target parent node
378 USCS_Node* TargetParent = nullptr;
379 for (USCS_Node* SearchNode : SCS->GetAllNodes())
380 {
381 if (SearchNode->GetVariableName().ToString() == TargetParentName)
382 {
383 TargetParent = SearchNode;
384 break;
385 }
386 }
387
388 if (!TargetParent)
389 return false;
390
391 // Reparent
392 if (CurrentParent)
393 {
394 CurrentParent->RemoveChildNode(Node);
395 }

Callers

nothing calls this directly

Calls 1

ToStringMethod · 0.45

Tested by

no test coverage detected