Skip to content
  • Recent
  • Tags
  • Popular
  • SAMSON Connect
  • Get SAMSON
Collapse
SAMSON Forum
  1. Home
  2. Develop
  3. Modeling
  4. Creating our own predicates

Creating our own predicates

Scheduled Pinned Locked Moved Modeling
3 Posts 2 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E
    E
    Elisa
    wrote on last edited by
    #1

    Dear all,

    I have created a bunch of classes deriving from SAMSON's. I would like now to implement something similar to:

    SBMStructuralModelNodeRoot* root = getStructuralRoot();
    SBNodeIndexer nodeIndexer;
    root->getNodes(nodeIndexer, SBNode::IsType(SBNode::Atom));
    

    But using my own types instead of SBNode::Types. I have been taking a look at how is this implemented for samson classes, but I could not get it to work. I guess I'm missing something and I appreciate if someone points me in the right direction.

    Best regards,

    Elisa

    1 Reply Last reply
    0
    • StephaneS
      StephaneS
      Stephane
      wrote on last edited by Stephane
      #2

      Hi Elisa,

      The SBNode::IsType class is a node predicate (i.e. a class with a member function bool operator()(SBNode*)) that checks the enum returned by the SBNode::getType() function and compares it to the type passed to the constructor of SBNode::IsType. The list of node types is predefined and you cannot change it at the moment (since SBNode::Type is an enum).

      One possibility might be to hack the system: you can try to overload the getType function of your node to write something like

      SBNode::Type MyNode::getType() const { return (SBNode::Type)3216546; // return a unique identifier for this node type }
      

      I'm not sure this is gonna work on all compilers (will the cast convert the number to another one?). Moreover, you don't know what other developers are going to do, and if your SAMSON Element is used in conjunction with one that also adopts this hack and, unfortunately, because of bad luck you use the same identifier, then this might create issues.

      Normally, it seems you should be able to use other existing node predicates. For example, a SAMSON Element UUID is supposed to be unique (this is imposed on SAMSON Connect), and the name of an exposed class inside a SAMSON Element is unique as well. So the pair (class name, element UUID) should be unique. Thus, you should be able to find your nodes with something like this:

      SBMStructuralModelNodeRoot* root = getStructuralRoot();
      SBNodeIndexer nodeIndexer;
      root->getNodes(nodeIndexer, (SBNode::GetClass() == std::string("MyNode")) && (SBNode::GetElementUUID() == SBUUID("F03D2ED2-C93B-C86E-C66E-01A776229839")));
      

      Hope this helps. If you indeed need to write new predicates let me know and I'll give some details.

      Stephane

      1 Reply Last reply
      1
      • E
        E
        Elisa
        wrote on last edited by
        #3

        Thank you! Using the GetClass and GetElementUUID methods is enough for my purposes :)

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Recent
        • Tags
        • Popular
        • SAMSON Connect
        • Get SAMSON