예제 #1
0
/// This method creates an XML-snippet of the phase components.
std::string makeComponents(std::vector<Component> const& components)
{
    std::stringstream sComponents;
    sComponents << indent(10) << "<components>\n";
    for (auto const& c : components)
    {
        sComponents << makeComponent(c);
    }
    sComponents << indent(10) << "</components>\n";
    return sComponents.str();
}
예제 #2
0
viewer::PluginPtr ModeHarnessPlugin::init(ViewerPtr viewer)
{
   mViewer = viewer;

   signal::RepositoryPtr signal_data =
      viewer->getSceneObj()->getSceneData<signal::Repository>();

   // Configuration.
   const std::string elt_type_name(getElementType());
   jccl::ConfigElementPtr cfg_elt =
      viewer->getConfiguration().getConfigElement(elt_type_name);

   if ( cfg_elt )
   {
      // Configure ourselves.
      configure(cfg_elt);
   }

   typedef std::vector<ComponentInfo>::iterator citer_type;
   for ( citer_type i = mComponentInfo.begin(); i != mComponentInfo.end(); ++i )
   {
      const std::string& name((*i).name);
      const std::string& plugin((*i).plugin);

      mode::ComponentPtr component;

      if ( mComponents.count(name) == 0 )
      {
         try
         {
            component = makeComponent(plugin, viewer);
            mComponents[name] = component;
         }
         catch (std::runtime_error& ex)
         {
            VRKIT_STATUS << "[Mode Harness] ERROR: Failed to load mode "
                         << "component '" << name << "':\n" << ex.what()
                         << std::endl;
         }
      }
      // If the named compnent is already known, reuse the existing instance.
      // XXX: Should component reuse be configurable? It matters for the case
      // of one component being activated by multiple mode activation signals.
      else
      {
         component = mComponents[name];
      }
   }

   std::vector<std::string> registered_signals;

   typedef std::vector<SignalDef>::iterator siter_type;
   for ( siter_type i = mSignalDefs.begin(); i != mSignalDefs.end(); ++i )
   {
      const std::string& sig_name((*i).name);
      const std::string& comp_name((*i).componentName);

      // Determine whether a component has already been registered to respond
      // to signal_id.
      std::vector<std::string>::iterator ei =
         std::find(registered_signals.begin(), registered_signals.end(),
                   sig_name);

      // If sig_name was not found in registered_signals, then we can go ahead
      // and hook up the mode component with sig_name.
      if ( ei == registered_signals.end() )
      {
         if ( mComponents.count(comp_name) > 0 )
         {
            mode::ComponentPtr component = mComponents[comp_name];

            VRKIT_STATUS << "[Mode Harness] Connecting mode component '"
                         << component->getDescription() << "'\n"
                         << "               to signal '" << sig_name << "'"
                         << std::endl;

            typedef boost::signal<void ()> signal_type;
            typedef signal::Container<signal_type> signal_container_type;

            // Ensure that sig_name is a known signal.
            if ( ! signal_data->hasSignal(sig_name) )
            {
               signal_data->addSignal(sig_name,
                                      signal_container_type::create());
            }

            // Connect the newly instantiated component with its signal.
            mConnections.push_back(
               signal_data->getSignal<signal_type>(sig_name)->connect(
                  boost::bind(&ModeHarnessPlugin::prepComponentSwitch,
                              this, component)
               )
            );

            registered_signals.push_back(sig_name);
         }
         else
         {
            VRKIT_STATUS << "[Mode Harness] ERROR: No component '"
                         << comp_name << "' to connect to signal '"
                         << sig_name << "'" << std::endl;
         }
      }
      else
      {
         VRKIT_STATUS << "[Mode Harness] ERROR: Component already registered "
                      << "for signal '" << sig_name << "'" << std::endl;
      }
   }

   mode::ComponentPtr default_component;

   // Set the default component.
   if ( ! mDefaultComponentName.empty() )
   {
      if ( mComponents.count(mDefaultComponentName) == 0 )
      {
         VRKIT_STATUS << "[Mode Harness] ERROR: Unknown or invalid component '"
                      << mDefaultComponentName
                      << "' used for default component!" << std::endl;
      }
      else
      {
         default_component = mComponents[mDefaultComponentName];
      }
   }
   else
   {
      VRKIT_STATUS << "[Mode Harness] WARNING: No default mode component "
                   << "has been identified!" << std::endl;
   }

   // If we have a default component, assign it mNextComponent. The default
   // component will be activated on the first pass through the application
   // frame loop when run() is invoked. This ensures that data initialization
   // has completed before the component is activated.
   if ( default_component )
   {
      mNextComponent = default_component;
   }
   // Not having a default componnt could be a bad thing, but it is not
   // considered to be a fatal error.
   else
   {
      VRKIT_STATUS << "WARNING: There is no default mode component."
                   << std::endl;
   }

   return shared_from_this();
}