Exemplo n.º 1
0
void MaterialNode::receiveFragmentDestroy(void* user,
                                          VNodeID nodeID,
                                          VNMFragmentID fragmentID)
{
  Session* session = Session::getCurrent();

  MaterialNode* node = dynamic_cast<MaterialNode*>(session->getNodeByID(nodeID));
  if (!node)
    return;

  //Fragment* fragment = node->getFragmentByID(fragmentID);
  //if (fragment)
  for (MaterialNode::FragmentList::iterator f = node->mFragments.begin();  f != node->mFragments.end();  f++)
  {
    if ((*f)->getID() == fragmentID)
    {
      // Notify fragment observers.
      const Fragment::ObserverList& fObservers = (*f)->getObservers();
      for (Fragment::ObserverList::const_iterator i = fObservers.begin();  i != fObservers.end();  i++)
      {
        if (FragmentObserver* observer = dynamic_cast<FragmentObserver*>(*i))
	  observer->onDestroy(*(*f));
      }

      // Notify node observers.
      const MaterialNode::ObserverList& nObservers = node->getObservers();
      for (MaterialNode::ObserverList::const_iterator i = nObservers.begin();  i != nObservers.end();  i++)
      {
	if (MaterialNodeObserver* observer = dynamic_cast<MaterialNodeObserver*>(*i))
          observer->onDestroyFragment(*node, *(*f));
      }

      delete *f;

      node->mFragments.erase(f);
      node->updateStructureVersion();

      //delete *f; SLAS::TMP
      //    Fragment* frag = *f;

      // SLAS::TMP
      /*
      for (Fragment::ObserverList::const_iterator i = fObservers.begin();  i != fObservers.end();  i++)
      {
        if (FragmentObserver* observer = dynamic_cast<FragmentObserver*>(*i))
          observer->postDestroy(*frag);
      }

      for (MaterialNode::ObserverList::const_iterator i = nObservers.begin();  i != nObservers.end();  i++)
      {
	      if (MaterialNodeObserver* observer = dynamic_cast<MaterialNodeObserver*>(*i))
            observer->postDestroyFragment(*node, *frag);
      }
      */

      //delete frag; // SLAS::TMP

      break;
    }
  }
}
Exemplo n.º 2
0
void MaterialNode::receiveFragmentCreate(void* user,
                                         VNodeID nodeID,
                                         VNMFragmentID fragmentID,
                                         VNMFragmentType type,
                                         const VMatFrag* value)
{
  Session* session = Session::getCurrent();

  MaterialNode* node = dynamic_cast<MaterialNode*>(session->getNodeByID(nodeID));
  if (!node)
    return;

  Fragment* fragment = node->getFragmentByID(fragmentID);
  if (fragment)
  {
    if (type != fragment->mType)
    {
      const Fragment::ObserverList& observers = fragment->getObservers();
      for (Fragment::ObserverList::const_iterator i = observers.begin();  i != observers.end();  i++)
        (*i)->onSetType(*fragment, type);

      fragment->mType = type;
      fragment->mValue = *value;
      fragment->updateStructureVersion();

      //for (Fragment::ObserverList::const_iterator i = observers.begin();  i != observers.end();  i++)
      //  (*i)->postSetType(*fragment, type);
    }
    else
    {
      const Fragment::ObserverList& observers = fragment->getObservers();
      for (Fragment::ObserverList::const_iterator i = observers.begin();  i != observers.end();  i++)
        (*i)->onSetValue(*fragment, *value);

      fragment->mValue = *value;
      fragment->updateDataVersion();

      //for (Fragment::ObserverList::const_iterator i = observers.begin();  i != observers.end();  i++)
      //  (*i)->postFragChange(*fragment, frag);
    }
  }
  else
  {
    fragment = new Fragment(fragmentID, *node, type, *value);

	// Notify node observers.
    const MaterialNode::ObserverList& nObservers = node->getObservers();
    for (MaterialNode::ObserverList::const_iterator i = nObservers.begin();  i != nObservers.end();  i++)
    {
      if (MaterialNodeObserver* observer = dynamic_cast<MaterialNodeObserver*>(*i))
        observer->onCreateFragment(*node, *fragment);
    }

    node->mFragments.push_back(fragment);
    node->updateStructureVersion();

    //for (MaterialNode::ObserverList::const_iterator i = nObservers.begin();  i != nObservers.end();  i++)
    //{
    //  if (MaterialNodeObserver* observer = dynamic_cast<MaterialNodeObserver*>(*i))
    //    observer->postCreateFragment(*node, *fragment);
    //}
  }
}