// ----------------------------------------------------------------------
   void
   CreateEstimatedEdgesTask::
   run( shawn::SimulationController& sc )
      throw( std::runtime_error )
   {
      VisualizationTask::run(sc);

      std::string pref = sc.environment().
         optional_string_param("prefix",DrawableEdgeEstimated::PREFIX);
      std::string node_prefix =
         sc.environment().
         optional_string_param("node_prefix",DrawableNodeDefault::PREFIX);
      GroupElement* grp = group(sc);

      for( shawn::World::const_node_iterator
              it    = visualization().world().begin_nodes(),
              endit = visualization().world().end_nodes();
           it != endit; ++it )
      {
         if( it->has_est_position())
         {
            const DrawableNode* dn = drawable_node(*it, node_prefix);
            DrawableEdgeEstimated* dee = new DrawableEdgeEstimated(*it, *dn, 
               DrawableEdgeEstimated::PREFIX);
            dee->init();
            visualization_w().add_element(dee);
            if( grp != NULL )
               grp->add_element(*dee);
         }
      }
   }
Exemplo n.º 2
0
   // ----------------------------------------------------------------------
   void
   CreateGroupTask::
   run( shawn::SimulationController& sc )
      throw( std::runtime_error )
   {
      VisualizationTask::run(sc);

      GroupElement* ge =
         new GroupElement( sc.environment().required_string_param("group") );
      ge->init();
      visualization_w().add_element( ge );
   }
Exemplo n.º 3
0
   // ----------------------------------------------------------------------
   void
   CreateEdgesTagTask::
   run( shawn::SimulationController& sc )
      throw( std::runtime_error )
   {
      VisualizationTask::run(sc);
#ifndef HAVE_BOOST_REGEX
      throw std::runtime_error("no boost::regex support compiled in");
#else
      boost::regex sources(sc.environment().required_string_param("source_regex"));
      boost::regex targets(sc.environment().required_string_param("target_regex"));
      std::string taglabel = sc.environment().required_string_param("tag");

      std::string pref = sc.environment().
         optional_string_param("prefix",DrawableEdgeDefault::PREFIX);
      std::string node_prefix =
         sc.environment().
         optional_string_param("node_prefix",DrawableNodeDefault::PREFIX);
      GroupElement* grp = group(sc);

      for( shawn::World::const_node_iterator
              it    = visualization().world().begin_nodes(),
              endit = visualization().world().end_nodes();
           it != endit; ++it )
      {
         
         if( boost::regex_search(get_stringtag(&*it,taglabel)->value(),sources))
            {
               for( shawn::Node::const_adjacency_iterator
                       ait    = it->begin_adjacent_nodes(),
                       endait = it->end_adjacent_nodes();
                    ait != endait; ++ait )
                  if( *it != *ait )
                     if( boost::regex_search(get_stringtag(&*ait,taglabel)->value(),targets) )
                        if( (ait->label() > it->label()) ||
                            (!boost::regex_search(get_stringtag(&*it,taglabel)->value(),targets)) ||
                            (!boost::regex_search(get_stringtag(&*ait,taglabel)->value(),sources)) )
                           {
                              const DrawableNode* dsrc =
                                 drawable_node(*it,node_prefix);
                              const DrawableNode* dtgt =
                                 drawable_node(*ait,node_prefix);
                              DrawableEdgeDefault* ded =
                                 new DrawableEdgeDefault(*it,*ait,*dsrc,*dtgt,pref);
                              ded->init();
                              visualization_w().add_element(ded);
                              if( grp != NULL )
                                 grp->add_element(*ded);
                           }
            }
      }
#endif
   }
Exemplo n.º 4
0
   // ----------------------------------------------------------------------
   void
   VisualizationTaskCreate::
   run( shawn::SimulationController& sc )
      throw( std::runtime_error )
   {
      Visualization* vis;

      require_world(sc);

      std::string name = sc.environment().optional_string_param( "vis", "visualization" );
      visualization_keeper_w(sc).add(vis=new Visualization(name));

      std::string type = sc.environment().optional_string_param( "node_type", "default" );
      DrawableNodeFactoryHandle dnfh = sc.keeper_by_name_w<DrawableNodeKeeper>("DrawableNodeKeeper")
         ->find_w(sc.environment().optional_string_param("drawable_nodes", type));

      sc.world_w().add_node_change_listener(*vis);
      vis->set_world( sc.world() );
      vis->init();

      DEBUG( logger(),
             "created visualization '" << name << "'" );

      GroupElement* ge =
         new GroupElement( "all.nodes" );
      ge->init();
      vis->add_element(ge);

      for( shawn::World::const_node_iterator
              it = sc.world().begin_nodes();
           it != sc.world().end_nodes();
           ++it )
         {
            DrawableNode *dn = dnfh->create(*it);
            dn->init();
            vis->add_element(dn);
            ge->add_element(*dn);
         }
   }
Exemplo n.º 5
0
void CGeneratorInput::parseStatesGroup(const GroupElement& groupElem, CPinPass::States& states)
{
	const GroupElement::LeafElements& elems = groupElem.getChildren();

	std::string typeAttribute = "variable";
	if(!groupElem.findAttribute("type", typeAttribute))
		base::lwrn<<"GroupElement \""<<groupElem.getName()<<
					"\" has no information about it's type. "
					"Using default type \""<<typeAttribute<<
					"\".";
	else
		TheGenerator::Get().applyConstants(typeAttribute);

	uint max = 0;

	if(typeAttribute == "array" || typeAttribute == "turn")
	{
		std::string strMax;

		if(groupElem.findAttribute("max", strMax))
		{
			TheGenerator::Get().applyConstants(strMax);
			max = base::Lexical_cast<int, std::string>(strMax);
		}
		else
			base::lwrn<<"GroupElement \""<<groupElem.getName()<<
						"\" has no information about max size. Using "<<max<<"...";
	}


	for(size_t i = 0; i < elems.size(); i++)
	{
		const StateElement& stateElem = elems[i];

		IBaseState* pState = NULL;

		if((typeAttribute == "variable"))
		{
			IVariableState* pVariableState = new CVariableState(stateElem);
			pState = pVariableState;
			states.variableStates.insert(CPinPass::States::VariableStates::value_type(pVariableState->getName(), pVariableState));
		}
		else
		if(typeAttribute == "array")
		{
			IArrayState* pArrayState = new CArrayState(stateElem, max);
			pState = pArrayState;
			states.arrayStates.insert(CPinPass::States::ArrayStates::value_type(pArrayState->getName(), pArrayState));
		}
		else
		if(typeAttribute == "turn")
		{
			IVariableState* pVariableState = new CTurnState(stateElem, max);
			pState = pVariableState;
			states.variableStates.insert(CPinPass::States::VariableStates::value_type(pVariableState->getName(), pVariableState));
		}
		else
			base::lwrn<<"Group \""<<groupElem.getName()<<
						"\" has unknown type \""<<typeAttribute<<
						"\". Skipping...";

		if(NULL != pState)
			m_states.push_back(PState(pState));
	}
}