Announcement

Collapse
No announcement yet.

a suggestion to move children in a another SoSwitch child node

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • a suggestion to move children in a another SoSwitch child node

    Dear All,
    Please, i'd like to know if there is a way to move children in another switch child node;
    I'l try to explain better:

    i have, for example the following tree:

    <root Separator>
    |
    +-- <Child 1>
    |
    +-- <Child 2>
    |
    .
    .
    |
    +-- <Child N>

    then i perform an "insertchild (0, SoSwitch)" in <root Separator> having so:


    <root Separator>
    |
    +-- <SoSwitch>
    |
    +-- <Child 1>
    |
    +-- <Child 2>
    |
    .
    .
    |
    +-- <Child N>


    Then i'd like to move all "child named" nodes in SoSwitch, having so:

    <root Separator>
    |
    +-- <SoSwitch>
    |
    +-- <Child 1>
    |
    +-- <Child 2>
    |
    .
    .
    |
    +-- <Child N>

    Is there a simple way to perform this action?

    I hope i well explained my issue.

    I thank You in advance for Your help.

    Best Regards,
    Vincenzo

  • #2
    Originally posted by [email protected] View Post
    Dear All,
    Is there a simple way to perform this action?
    Hi Vincenzo,
    Interesting question! And your explanation is perfect.
    We do not currently provide a "moveChild" method. So all the possible answers are similar and should have similar performance.
    I think the shortest solution would be to take advantage of the removeAllChildren() method. In other words, first add the existing children to the SoSwitch, then remove the existing children from 'root', then add the Switch to 'root', For example (in C++):
    Code:
    // Example: Move all children to a different parent.
    // Note: First step - create the new instances of all children to ensure that they are ref'd at all times.
    auto sw = new SoSwitch();
    for (int i = 0; i < root->getNumChildren(); ++i)
    {
      sw->addChild(root->getChild(i));
    }
    root->removeAllChildren();
    root->addChild(sw);
    Regards,
    Mike
    Last edited by mikeheck; August 5, 2020, 02:54 PM.

    Comment


    • #3
      Dear Mike,
      First of all, thank You very much for Your fast responce;
      I'll follow Your code suggestion that is fast, simply and clear!
      Thank You again very much and have a nice day!

      Regards,
      Vincenzo

      Comment

      Working...
      X