Material selection signal

pcicconepciccone Posts: 661
edited December 1969 in Daz SDK Developer Discussion

Hello again.

Is it possible to be notified of what material is selected without scanning all the materials? The DzScene class provides the notification of the event happening but not the details on which object and material have been selected.

Thanks in advance.

Comments

  • dtammdtamm Posts: 126
    edited December 1969

    Pret-A-3D said:
    Hello again.

    Is it possible to be notified of what material is selected without scanning all the materials? The DzScene class provides the notification of the event happening but not the details on which object and material have been selected.

    Thanks in advance.

    if you connect at the shape level, there are the following two signals:
    void materialSelected( DzMaterial *mat );
    void materialUnselected( DzMaterial *mat );

  • pcicconepciccone Posts: 661
    edited December 1969

    dtamm said:

    if you connect at the shape level, there are the following two signals:
    void materialSelected( DzMaterial *mat );
    void materialUnselected( DzMaterial *mat );

    Thank you. So, this means that I will have to connect to each object in the scene. In other words there is no Scene-level signaling for this kind of event. Am I correct?

    Thanks in advance.

  • rbtwhizrbtwhiz Posts: 1,925
    edited December 1969

    Pret-A-3D said:
    Is it possible to be notified of what material is selected without scanning all the materials? The DzScene class provides the notification of the event happening but not the details on which object and material have been selected.

    DzNode, DzObject and DzShape each provide a materialSelectionChanged() signal. DzMaterial provides a selectionStateChanged() signal. Each class in the chain causes the next higher in that chain to emit its signal, ultimately causing the signal on DzScene to emit.

    Rather than trigger your subroutine each time the signal is emitted, in order to keep from significantly impacting performance, the recommended approach is to create a custom event, if/when one does not already exist, when the DzScene::materialChanged() signal is emitted and then process the material list once; using the static functions on DzMaterial. If you need shape or node information, from a DzMaterial you can get a DzShapeListIterator, and from DzShape you can get the DzNode.

    
    /**
    **/
    class MyEvent: public QEvent
    {
    public:
     MyEvent() : QEvent( QEvent::Type( s_type ) ) {}
    
     static int s_type;
    };
    
    int MyEvent::s_type = QEvent::registerEventType();
    
    /**
    **/
    struct MyClass::Data
    {
     Data() : m_eventPosted( false ){ }
    
     bool m_eventPosted;
    };
    
    /**
    **/
    MyClass::MyClass() : m_data( new Data )
    {
     DzConnect( dzScene, SIGNAL(materialSelectionChanged()), this, SLOT(postMyEvent()) );
    }
    
    MyClass::~MyClass()
    {
     delete m_data;
    }
    
    void MyClass::postMyEvent()
    {
     if( m_data->m_eventPosted )
      return;
    
     if( !dzApp || dzApp->isClosing() )
      return;
    
     m_data->m_eventPosted = true;
     dzApp->postEvent( this, new MyEvent()  );
    }
    
    bool MyClass::event( QEvent *e )
    {
     if( e->type() == MyEvent::s_type )
     {
      doMyProcessing();
      
      m_data->m_eventPosted = false;
      return true;
     }
    
     return MySuperClass::event( e );
    }

    -Rob

  • SimonJMSimonJM Posts: 5,888
    edited December 1969

    rbtwhiz said:

    DzNode, DzObject and DzShape each provide a materialSelectionChanged() signal. DzMaterial provides a selectionStateChanged() signal. Each class in the chain causes the next higher in that chain to emit its signal, ultimately causing the signal on DzScene to emit.

    Rather than trigger your subroutine each time the signal is emitted, in order to keep from significantly impacting performance, the recommended approach is to create a custom event, if/when one does not already exist, when the DzScene::materialChanged() signal is emitted and then process the material list once; using the static functions on DzMaterial. If you need shape or node information, from a DzMaterial you can get a DzShapeListIterator, and from DzShape you can get the DzNode.


    -Rob


    I have to say, Rob, your support at the technical level is nothing less than spectacular! :)
Sign In or Register to comment.