void AddRobotBase::pointDeleted(std::string marker_name)
{
  for (int i = 0; i < waypoints_pos.size(); i++)
      ROS_DEBUG_STREAM("vecotr before delete: \n"
                       << "x:" << waypoints_pos[i].getOrigin().x() << "; " << waypoints_pos[i].getOrigin().y() << "; "
                       << waypoints_pos[i].getOrigin().z() << ";\n");

    // get the index of the selected marker
    int index = atoi(marker_name.c_str());
    server->erase(marker_name.c_str());
    waypoints_pos.erase(waypoints_pos.begin() + index - 1);

    for (int i = 0; i < waypoints_pos.size(); i++)
      ROS_DEBUG_STREAM("vecotr before delete: \n"
                       << "x:" << waypoints_pos[i].getOrigin().x() << "; " << waypoints_pos[i].getOrigin().y() << "; "
                       << waypoints_pos[i].getOrigin().z() << ";\n");
    // InteractiveMarker int_marker;
    for (int i = index + 1; i <= count; i++)
    {
      std::stringstream s;
      s << i;
      server->erase(s.str());
      makeArrow(waypoints_pos[i - 2], (i - 1));
    }
    count--;
    server->applyChanges();
}
void AddWayPoint::pointDeleted(std::string marker_name)
{
  /*! The point can be deleted either from the RViz or the RQT Widged.
      This function handles the event of removing a point from the RViz enviroment. It finds the name of the selected
     marker which the user wants to delete and updates the RViz enviroment and the vector that contains all the
     Way-Points.
   */
  for (int i = 0; i < waypoints_pos.size(); i++)
    ROS_DEBUG_STREAM("vecotr before delete: \n"
                     << "x:" << waypoints_pos[i].getOrigin().x() << "; " << waypoints_pos[i].getOrigin().y() << "; "
                     << waypoints_pos[i].getOrigin().z() << ";\n");

  // get the index of the selected marker
  int index = atoi(marker_name.c_str());
  server->erase(marker_name.c_str());
  waypoints_pos.erase(waypoints_pos.begin() + index - 1);

  for (int i = 0; i < waypoints_pos.size(); i++)
    ROS_DEBUG_STREAM("vecotr before delete: \n"
                     << "x:" << waypoints_pos[i].getOrigin().x() << "; " << waypoints_pos[i].getOrigin().y() << "; "
                     << waypoints_pos[i].getOrigin().z() << ";\n");
  // InteractiveMarker int_marker;
  for (int i = index + 1; i <= count; i++)
  {
    std::stringstream s;
    s << i;
    server->erase(s.str());
    makeArrow(waypoints_pos[i - 2], (i - 1));
  }
  count--;
  server->applyChanges();
}
void AddWayPoint::addPointFromUI(const tf::Transform point_pos)
{
  /*! Function for handling the signal of the RQT to add a new Way-Point in the RViz enviroment.
  */
  ROS_INFO("Point Added");
  makeArrow(point_pos, count);
  server->applyChanges();
}
GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : GuiComponent(window), 
	mSystem(system), 
	mMenu(window, "OPTIONS")
{
	addChild(&mMenu);

	// jump to letter
	char curChar = toupper(getGamelist()->getCursor()->getName()[0]);
	if(curChar < 'A' || curChar > 'Z')
		curChar = 'A';

	mJumpToLetterList = std::make_shared<LetterList>(mWindow, "JUMP TO LETTER", false);
	for(char c = 'A'; c <= 'Z'; c++)
		mJumpToLetterList->add(std::string(1, c), c, c == curChar);

	ComponentListRow row;
	row.addElement(std::make_shared<TextComponent>(mWindow, "JUMP TO LETTER", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
	row.addElement(mJumpToLetterList, false);
	row.input_handler = [&](InputConfig* config, Input input) {
		if(config->isMappedTo("a", input) && input.value)
		{
			jumpToLetter();
			return true;
		}
		else if(mJumpToLetterList->input(config, input))
		{
			return true;
		}
		return false;
	};
	mMenu.addRow(row);

	// sort list by
	mListSort = std::make_shared<SortList>(mWindow, "SORT GAMES BY", false);
	for(unsigned int i = 0; i < FileSorts::SortTypes.size(); i++)
	{
		const FileData::SortType& sort = FileSorts::SortTypes.at(i);
		mListSort->add(sort.description, &sort, i == system->sortId);
	}

	mMenu.addWithLabel("SORT GAMES BY", mListSort);

	// edit game metadata
	row.elements.clear();
	row.addElement(std::make_shared<TextComponent>(mWindow, "EDIT THIS GAME'S METADATA", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
	row.addElement(makeArrow(mWindow), false);
	row.makeAcceptInputHandler(std::bind(&GuiGamelistOptions::openMetaDataEd, this));
	mMenu.addRow(row);

	// center the menu
	setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
	mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, (mSize.y() - mMenu.getSize().y()) / 2);
}
void GuiSystemSettings::addEntry(const char* name, unsigned int color, bool add_arrow, const std::function<void()>& func)
{
	std::shared_ptr<Font> font = Font::get(FONT_SIZE_MEDIUM);
	
	// populate the list
	ComponentListRow row;
	row.addElement(std::make_shared<TextComponent>(mWindow, name, font, color), true);

	if(add_arrow)
	{
		std::shared_ptr<ImageComponent> bracket = makeArrow(mWindow);
		row.addElement(bracket, false);
	}
	
	row.makeAcceptInputHandler(func);

	mMenu.addRow(row);
}
Example #6
0
//
// Constructor
//
//InvPlaneMover::InvPlaneMover(InvViewer *vv):
InvPlaneMover::InvPlaneMover()
    : show_(0)
    , distOffset_(0, 0, 0)
    , feedbackInfo_(NULL)
    , planeNormal_(0, 1, 0)
    , iNorm_(0, 1, 0)
    , motionMode_(InvPlaneMover::FREE)

{
    handle_ = new SoSeparator;
    handle_->ref();

    // our move-handle is a SoJackDragger with appropriate decoration
    // i.e. a square with a vector in its center

    handleSwitch_ = new SoSwitch();
    handleSwitch_->whichChild.setValue(SO_SWITCH_NONE);
    handle_->addChild(handleSwitch_);

    jDrag_ = new SoJackDragger;
    jDrag_->addFinishCallback(InvPlaneMover::dragFinishCB, this);

    handleDrawStyle_ = new SoDrawStyle;
    handleDrawStyle_->style.setValue(SoDrawStyle::FILLED);

    transl_ = new SoTranslation;
    handleSwitch_->addChild(transl_);

    fullRot_ = new SoRotation;
    handleSwitch_->addChild(fullRot_);

    scale_ = new SoScale;
    handleSwitch_->addChild(scale_);

    int ii;
    SoSeparator *plane[6];
    for (ii = 0; ii < 6; ii++)
    {
        plane[ii] = new SoSeparator;
        plane[ii]->addChild(handleDrawStyle_);
        plane[ii]->addChild(makePlane());
    }

    SoSeparator *empty[6];
    for (ii = 0; ii < 6; ii++)
    {
        empty[ii] = new SoSeparator;
        empty[ii]->addChild(handleDrawStyle_);
    }

    SoSeparator *scale[2];
    for (ii = 0; ii < 2; ii++)
    {
        scale[ii] = new SoSeparator;
        scale[ii]->addChild(handleDrawStyle_);
        //scale[ii]->addChild(makeArrow());
    }

    SoSeparator *arrow[2];
    for (ii = 0; ii < 2; ii++)
    {
        arrow[ii] = new SoSeparator;
        arrow[ii]->addChild(handleDrawStyle_);
        arrow[ii]->addChild(makeArrow());
    }

    transl_ = new SoTranslation;
    handleSwitch_->addChild(transl_);

    fullRot_ = new SoRotation;
    handleSwitch_->addChild(fullRot_);

    scale_ = new SoScale;
    handleSwitch_->addChild(scale_);

    handleSwitch_->addChild(jDrag_);

    jDrag_->setPart("rotator.rotator", arrow[0]);
    jDrag_->setPart("rotator.rotatorActive", arrow[1]);

    jDrag_->setPart("translator.yTranslator.translator", plane[0]);
    jDrag_->setPart("translator.xTranslator.translator", plane[2]);
    jDrag_->setPart("translator.zTranslator.translator", plane[4]);
    jDrag_->setPart("translator.yTranslator.translatorActive", plane[1]);
    jDrag_->setPart("translator.xTranslator.translatorActive", plane[3]);
    jDrag_->setPart("translator.zTranslator.translatorActive", plane[5]);

    jDrag_->setPart("translator.yzTranslator.translatorActive", empty[0]);
    jDrag_->setPart("translator.xzTranslator.translatorActive", empty[1]);
    jDrag_->setPart("translator.xyTranslator.translatorActive", empty[2]);
    jDrag_->setPart("translator.yzTranslator.translator", empty[3]);
    jDrag_->setPart("translator.xzTranslator.translator", empty[4]);
    jDrag_->setPart("translator.xyTranslator.translator", empty[5]);
}
void AddWayPoint::processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback)
{
  /*! This function is one of the most essential ones since it handles the events of the InteractiveMarkers from the
     User in the RViz Enviroment.
      In this function we have handlers for all the necessary events of the User Interaction with the
     InteractiveMarkers.
      When the user clicks on the User Interactive Arrow, it acts as button and adds new Way-Point in the RViz
     enviroment.
      When the User changes the pose of an InteractiveMarker from the RViz enviroment the position of the
     InteractiveMarker is updated synchronously in the RViz enviroment and in the RQT Widget.
      The Menu handlers take care of the User selected items from the menu of the Way-Point and call the necessary
     functions to change their state depending on the item selected from the menu.
  */
  switch (feedback->event_type)
  {
    case visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK:
    {
      tf::Transform point_pos;
      tf::poseMsgToTF(feedback->pose, point_pos);
      // ROS_INFO_STREAM("on click feedback pose is"<<feedback->pose.position.x<<", "<<feedback->pose.position.y<<",
      // "<<feedback->pose.position.z<<";");

      makeArrow(point_pos, count);
      break;
    }

    case visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE:
    {
      tf::Transform point_pos;
      tf::poseMsgToTF(feedback->pose, point_pos);
      pointPoseUpdated(point_pos, feedback->marker_name.c_str());

      Q_EMIT pointPoseUpdatedRViz(point_pos, feedback->marker_name.c_str());

      break;
    }
    case visualization_msgs::InteractiveMarkerFeedback::MENU_SELECT:
    {
      // get the menu item which is pressed
      interactive_markers::MenuHandler::EntryHandle menu_item = feedback->menu_entry_id;
      interactive_markers::MenuHandler::CheckState state;

      menu_handler.getCheckState(menu_item, state);

      if (menu_item == 1)
      {
        std::string marker_name = feedback->marker_name;
        int marker_nr = atoi(marker_name.c_str());
        Q_EMIT pointDeleteRviz(marker_nr);
        pointDeleted(marker_name);
        break;
      }
      else
      {
        if (state == interactive_markers::MenuHandler::UNCHECKED)
        {
          ROS_INFO("The selected marker is shown with 6DOF control");
          menu_handler.setCheckState(menu_item, interactive_markers::MenuHandler::CHECKED);
          geometry_msgs::Pose pose;
          changeMarkerControlAndPose(feedback->marker_name.c_str(), true);
          break;
        }
        else
        {
          menu_handler.setCheckState(menu_item, interactive_markers::MenuHandler::UNCHECKED);
          ROS_INFO("The selected marker is shown as default");
          geometry_msgs::Pose pose;
          changeMarkerControlAndPose(feedback->marker_name.c_str(), false);
          break;
        }
      }
      break;
    }
  }
  server->applyChanges();
}
void AddRobotBase::processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
{
  switch (feedback->event_type)
    {
      case visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK:
      {
        tf::Transform point_pos;
        tf::poseMsgToTF(feedback->pose, point_pos);
        // ROS_INFO_STREAM("on click feedback pose is"<<feedback->pose.position.x<<", "<<feedback->pose.position.y<<",
        // "<<feedback->pose.position.z<<";");

        makeArrow(point_pos, count);
        break;
      }

      case visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE:
      {
        tf::Transform point_pos;
        tf::poseMsgToTF(feedback->pose, point_pos);
        pointPoseUpdated(point_pos, feedback->marker_name.c_str());

        //Q_EMIT pointPoseUpdatedRViz(point_pos, feedback->marker_name.c_str());

        break;
      }
      case visualization_msgs::InteractiveMarkerFeedback::MENU_SELECT:
      {
        // get the menu item which is pressed
        interactive_markers::MenuHandler::EntryHandle menu_item = feedback->menu_entry_id;
        interactive_markers::MenuHandler::CheckState state;

        menu_handler.getCheckState(menu_item, state);

        if (menu_item == 1)
        {
          std::string marker_name = feedback->marker_name;
          int marker_nr = atoi(marker_name.c_str());
          //Q_EMIT pointDeleteRviz(marker_nr);
          pointDeleted(marker_name);
          break;
        }
        else
        {
          if (state == interactive_markers::MenuHandler::UNCHECKED)
          {
            ROS_INFO("The selected marker is shown with 6DOF control");
            menu_handler.setCheckState(menu_item, interactive_markers::MenuHandler::CHECKED);
            geometry_msgs::Pose pose;
            changeMarkerControlAndPose(feedback->marker_name.c_str(), true);
            break;
          }
          else
          {
            menu_handler.setCheckState(menu_item, interactive_markers::MenuHandler::UNCHECKED);
            ROS_INFO("The selected marker is shown as default");
            geometry_msgs::Pose pose;
            changeMarkerControlAndPose(feedback->marker_name.c_str(), false);
            break;
          }
        }
        break;
      }
    }
    server->applyChanges();
}
GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : GuiComponent(window), 
	mSystem(system), 
	mMenu(window, "OPTIONS")
{
	LOG(LogDebug) << "GUIGamelistOptions::GuiGamelistOptions()";
	addChild(&mMenu);

	// jump to letter
	char curChar = toupper(getGamelist()->getCursor()->getName()[0]);
	if(curChar < 'A' || curChar > 'Z')
		curChar = 'A';

	mJumpToLetterList = std::make_shared<LetterList>(mWindow, "JUMP TO LETTER", false);
	for(char c = 'A'; c <= 'Z'; c++)
		mJumpToLetterList->add(std::string(1, c), c, c == curChar);

	ComponentListRow row;
	row.addElement(std::make_shared<TextComponent>(mWindow, "JUMP TO LETTER", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
	row.addElement(mJumpToLetterList, false);
	row.input_handler = [&](InputConfig* config, Input input) {
		if(config->isMappedTo("a", input) && input.value)
		{
			jumpToLetter();
			return true;
		}
		else if(mJumpToLetterList->input(config, input))
		{
			return true;
		}
		return false;
	};
	mMenu.addRow(row);

	row.elements.clear();
	row.addElement(std::make_shared<TextComponent>(mWindow, "SURPRISE ME!", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
	row.input_handler = [&](InputConfig* config, Input input) {
		if(config->isMappedTo("a", input) && input.value)
		{
			SurpriseMe();
			return true;
		}
		return false;
	};
	mMenu.addRow(row);
	
	// sort list by
	mListSort = std::make_shared<SortList>(mWindow, "SORT GAMES BY", false);
	for(unsigned int i = 0; i < FileSorts::SortTypes.size(); i++)
	{
		const FileData::SortType& sort = FileSorts::SortTypes.at(i);
		mListSort->add(sort.description, &sort, i == 0); // TODO - actually make the sort type persistent
	}

	mMenu.addWithLabel("SORT GAMES BY", mListSort);
	
	// Show favorites-only
	auto favorite_only = std::make_shared<SwitchComponent>(mWindow);
	favorite_only->setState(Settings::getInstance()->getBool("FavoritesOnly"));
	mMenu.addWithLabel("FAVORITES ONLY", favorite_only);
	addSaveFunc([favorite_only, this] { Settings::getInstance()->setBool("FavoritesOnly", favorite_only->getState()); mFavoriteStateChanged = true; });
	
	// edit game metadata - only in Full UI mode
	if(Settings::getInstance()->getString("UIMode") == "Full")
	{
		row.elements.clear();
		row.addElement(std::make_shared<TextComponent>(mWindow, "EDIT THIS GAME'S METADATA", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
		row.addElement(makeArrow(mWindow), false);
		row.makeAcceptInputHandler(std::bind(&GuiGamelistOptions::openMetaDataEd, this));
		mMenu.addRow(row);
	}

	// center the menu
	setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
	mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, (mSize.y() - mMenu.getSize().y()) / 2);
}
Example #10
0
void Primitive::addScaleControls()
{
    show_scale_control_ = true;

    min_size_.x = pose_.position.x - scale_.x * 0.5;
    max_size_.x = pose_.position.x + scale_.x * 0.5;
    min_size_.y = pose_.position.y - scale_.y * 0.5;
    max_size_.y = pose_.position.y + scale_.y * 0.5;
    min_size_.z = pose_.position.z - scale_.z * 0.5;
    max_size_.z = pose_.position.z + scale_.z * 0.5;

    for (int axis = 0; axis < 3; axis++)
    {
        for (int sign = -1; sign <= 1; sign += 2)
        {
            InteractiveMarker int_marker;
            int_marker.header.frame_id = frame_id_;
            int_marker.scale = 1.0;
            int_marker.pose = pose_;

            InteractiveMarkerControl control;
            control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
            control.orientation_mode = InteractiveMarkerControl::INHERIT;
            control.always_visible = false;

            control.orientation.w = 1;

            switch (axis)
            {
            case 0:
                int_marker.name = sign > 0 ? name_ + "_max_x" : name_ + "_min_x";
                int_marker.pose.position.x = sign > 0 ? max_size_.x : min_size_.x;
                int_marker.pose.position.z = sign > 0 ? max_size_.z : min_size_.z;
                control.orientation.x = 1;
                control.orientation.y = 0;
                control.orientation.z = 0;
                break;
            case 1:
                int_marker.name = sign > 0 ? name_ + "_max_y" : name_ + "_min_y";
                int_marker.pose.position.y = sign > 0 ? max_size_.y : min_size_.y;
                int_marker.pose.position.x = sign > 0 ? max_size_.x : min_size_.x;
                control.orientation.x = 0;
                control.orientation.y = 0;
                control.orientation.z = 1;
                break;
            default:
                int_marker.name = sign > 0 ? name_ + "_max_z" : name_ + "_min_z";
                int_marker.pose.position.z = sign > 0 ? max_size_.z : min_size_.z;
                int_marker.pose.position.y = sign > 0 ? max_size_.y : min_size_.y;
                control.orientation.x = 0;
                control.orientation.y = -1;
                control.orientation.z = 0;
                break;
            }

            makeArrow(int_marker, control, 0.5 * sign);

            int_marker.controls.push_back(control);
            server_->insert(int_marker, boost::bind(&Primitive::scaleFeedback, this, _1));
        }
    }
}