예제 #1
0
//------------------------------------------------------------------------------
// setComputematrix4 () - for Angle types
//------------------------------------------------------------------------------
bool Transform::setComputematrix4(const Angle* const sc4obj)
{
    bool ok = true;
    if (nv == 0 && isClassType(typeid(Rotation))) {
        Radians rad;
        v[nv++] = static_cast<LCreal>(rad.convert(*sc4obj));
        computeMatrix();
    }
    else {
        std::cerr << "Transform::setComputematrix4:  Invalid Angle type or input" << std::endl;
        ok = false;
    }
    return ok;
}
예제 #2
0
//------------------------------------------------------------------------------
// processComponents() -- process our new components list;
//   -- Add the components from the input list, 'list', to a new list, 'newList'
//      make sure they are all of type Component (or derived from it)
//      tell them that we are their container
//   -- Add an optional component to the end of the new list
//   -- Swap our 'components' list with the new list, newList
//   -- Handle selections.
//------------------------------------------------------------------------------
void Component::processComponents(
      PairStream* const list,
      const std::type_info& filter,
      Pair* const add,
      Component* const remove
   )
{
   PairStream* oldList = components.getRefPtr();

   // ---
   // Our dynamic_cast (see below) already filters on the Component class
   // ---
   bool skipFilter {};
   if (filter == typeid(Component)) {
      skipFilter = true;
   }

   // ---
   // Create a new list, copy (filter) the component pairs and set their container pointers
   // ---
   const auto newList = new PairStream();
   if (list != nullptr) {

      // Add the (filtered) components to the new list and set their container
      List::Item* item = list->getFirstItem();
      while (item != nullptr) {
         const auto pair = static_cast<Pair*>(item->getValue());
         const auto cp = dynamic_cast<Component*>( pair->object() );
         if ( cp != nullptr && cp != remove && (skipFilter || cp->isClassType(filter)) ) {
            newList->put(pair);
            cp->container(this);
         }
         else if ( cp != nullptr && cp == remove ) {
            cp->container(nullptr);
         }
         item = item->getNext();
      }

   }

   // ---
   // Add the optional component
   // ---
   if (add != nullptr) {
      const auto cp = dynamic_cast<Component*>( add->object() );
      if ( cp != nullptr && (skipFilter || cp->isClassType(filter)) ) {
         newList->put(add);
         cp->container(this);
      }
   }

   // ---
   // Swap lists
   // ---
   components = newList;
   newList->unref();

   // ---
   // Anything selected?
   // ---
   if (selection != nullptr) {
      if (selection->isClassType(typeid(String))) {
            const auto str = new String(*(static_cast<String*>(selection)));
            select(str);
            str->unref();
      }
      else {
            const auto num = new Integer((static_cast<Number*>(selection))->getInt());
            select(num);
            num->unref();
      }
   }

   if (oldList != nullptr) {
      oldList->unref();
   }
}