SAMSON Forum
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • SAMSON Connect
    • Get SAMSON

    Creating our own predicates

    Modeling
    2
    3
    2512
    Loading More Posts
    • 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
      Elisa last edited by

      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 Reply Quote 0
      • Stephane
        Stephane last edited by Stephane

        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 Reply Quote 1
        • E
          Elisa last edited by

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post