Example #1
0
void ScanningControl::next()
{
    Scanning *scanning = Scanning::instance();

    if (!scanning)
        return;

    if (!scanning->m_scanning.contains(scanning->m_selected))
        return;

    QList<Selectable *> *list = scanning->m_scanning.value(scanning->m_selected);

    if (list->size() == 0) {
        scanning->select(scanning->m_root);
    } else {
        Selectable *nowSelected = list->at(m_index);

        m_index = nowSelected->selected() ? (m_index + 1) % list->size() : 0;

        Selectable *nextSelected = list->at(m_index);

        nowSelected->setSelected(false);
        nextSelected->setSelected(true);
    }
}
Example #2
0
static gboolean entitylist_tree_select(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_currently_selected, gpointer data)
{
  GtkTreeIter iter;
  gtk_tree_model_get_iter(model, &iter, path);
  scene::Node* node;
  gtk_tree_model_get_pointer(model, &iter, 0, &node);
  scene::Instance* instance;
  gtk_tree_model_get_pointer(model, &iter, 1, &instance);
  Selectable* selectable = Instance_getSelectable(*instance);

  if(node == 0)
  {
    if(path_currently_selected != FALSE)
    {
      getEntityList().m_selection_disabled = true;
      GlobalSelectionSystem().setSelectedAll(false);
      getEntityList().m_selection_disabled = false;
    }
  }
  else if(selectable != 0)
  {
    getEntityList().m_selection_disabled = true;
    selectable->setSelected(path_currently_selected == FALSE);
    getEntityList().m_selection_disabled = false;
    return TRUE;
  }

  return FALSE;
}
Example #3
0
void ScanningControl::select()
{
    Scanning *scanning = Scanning::instance();

    if (!scanning)
        return;

    if (!scanning->m_scanning.contains(scanning->m_selected))
        return;

    QList<Selectable *> *list = scanning->m_scanning.value(scanning->m_selected);

    Selectable *selected = list->at(m_index);
    selected->setSelected(false);

    QList<Selectable *> *listSelected = scanning->m_scanning.value(selected);
    if (listSelected->size() == 0) {
        qDebug() << "Action from " << selected;
        scanning->select(scanning->m_root);
    } else {
        scanning->select(selected);
    }

    m_index = 0;
}
Example #4
0
void SelectableGroup::unselectAll()
{
	Selectable* selected = this->getSelection();
	
	if(selected != NULL)
		selected->setSelected(false);

	this->notifySelectionChanged();
}
Example #5
0
gboolean EntityList::onSelection(GtkTreeSelection* selection, 
								GtkTreeModel* model, 
								GtkTreePath* path, 
								gboolean path_currently_selected, 
								gpointer data)
{
	// Get a pointer to the class instance
	EntityList* self = reinterpret_cast<EntityList*>(data);

	if (self->_callbackActive) return TRUE; // avoid loops

	bool shouldFocus = gtk_toggle_button_get_active(
		GTK_TOGGLE_BUTTON(self->_focusOnSelectedEntityToggle)) ? true : false;
	
	if (!shouldFocus) return TRUE;

	GtkTreeIter iter;
	gtk_tree_model_get_iter(model, &iter, path);
	
	// Load the instance pointer from the columns
	scene::INode* node = reinterpret_cast<scene::Node*>(
		gtkutil::TreeModel::getPointer(model, &iter, GraphTreeModel::COL_NODE_POINTER)
	);
	
	Selectable* selectable = dynamic_cast<Selectable*>(node);

	if (selectable != NULL) {
		// We've found a selectable instance
		
		// Disable update to avoid loopbacks
		self->_callbackActive = true;
		
		// Select the instance
		selectable->setSelected(path_currently_selected == FALSE);

		const AABB& aabb = node->worldAABB();
		Vector3 origin(aabb.origin);
		
		// Move the camera a bit off the AABB origin
		origin += Vector3(-50, 0, 50);

		// Rotate the camera a bit towards the "ground"
		Vector3 angles(0, 0, 0);
		angles[CAMERA_PITCH] = -30;

		GlobalCameraView().focusCamera(origin, angles);

		// Now reactivate the callbacks
		self->_callbackActive = false;
		
		return TRUE; // don't propagate
	}

	return FALSE;
}
Example #6
0
void deselectCB(void *data, SoPath *path)
{
	ManipMaster *master = static_cast<ManipMaster *>(data);

	LabObject *obj;
	if (LabObject::isLabObject(path->getTail(), &obj)) {
		if (obj->getTypeId() == Selectable::classTypeId) {
			Selectable *sel = static_cast<Selectable *>(obj);
			sel->setSelected(false);

			master->setSelected(NULL);
		}
	}
}
/* greebo: This gets called by SelectObserver if the user just clicks into the scene (without dragging)
 * It checks for any possible targets (in the "line of click") and takes the actions according
 * to the modifiers that are held down (Alt-Shift, etc.)
 */
void RadiantSelectionSystem::SelectPoint(const View& view,
                                         const Vector2& device_point,
                                         const Vector2& device_epsilon,
                                         SelectionSystem::EModifier modifier,
                                         bool face)
{
    ASSERT_MESSAGE(fabs(device_point[0]) <= 1.0f && fabs(device_point[1]) <= 1.0f, "point-selection error");
    // If the user is holding the replace modifiers (default: Alt-Shift), deselect the current selection
    if (modifier == SelectionSystem::eReplace) {
        if (face) {
            setSelectedAllComponents(false);
        }
        else {
            deselectAll();
        }
    }

    {
        View scissored(view);
        // Construct a selection test according to a small box with 2*epsilon edge length
        ConstructSelectionTest(scissored, Rectangle::ConstructFromPoint(device_point, device_epsilon));

        // Create a new SelectionPool instance and fill it with possible candidates
        SelectionVolume volume(scissored);
        // The possible candidates are stored in the SelectablesSet
        SelectablesList candidates;

        if (face)
        {
            SelectionPool selector;

            ComponentSelector selectionTester(selector, volume, eFace);
            GlobalSceneGraph().foreachVisibleNodeInVolume(scissored, selectionTester);

            // Load them all into the vector
            for (SelectionPool::iterator i = selector.begin(); i != selector.end(); ++i)
            {
                candidates.push_back(i->second);
            }
        }
        else {
            testSelectScene(candidates, volume, scissored, Mode(), ComponentMode());
        }

        // Was the selection test successful (have we found anything to select)?
        if (candidates.size() > 0) {
            // Yes, now determine how we should interpret the click
            switch (modifier) {
                // If we are in toggle mode (Shift-Left-Click by default), just toggle the
                // selection of the "topmost" item
                case SelectionSystem::eToggle: {
                    Selectable* best = *candidates.begin();
                    // toggle selection of the object with least depth (=first in the list)
                    best->setSelected(!best->isSelected());
                }
                break;
                // greebo: eReplace mode gets active as soon as the user holds the replace modifiers down
                // and clicks (by default: Alt-Shift). eReplace is only active during the first click
                // afterwards we are in cycle mode.
                // if cycle mode not enabled, enable it
                case SelectionSystem::eReplace: {
                    // select closest (=first in the list)
                    (*candidates.begin())->setSelected(true);
                }
                break;
                // select the next object in the list from the one already selected
                // greebo: eCycle is set if the user keeps holding the replace modifiers (Alt-Shift)
                // and does NOT move the mouse between the clicks, otherwise we fall back into eReplace mode
                // Note: The mode is set in SelectObserver::testSelect()
                case SelectionSystem::eCycle: {
                    // Cycle through the selection pool and activate the item right after the currently selected
                    SelectablesList::iterator i = candidates.begin();

                    while (i != candidates.end()) {
                        if ((*i)->isSelected()) {
                            // unselect the currently selected one
                            (*i)->setSelected(false);
                            // check if there is a "next" item in the list, if not: select the first item
                            ++i;
                            if (i != candidates.end()) {
                                (*i)->setSelected(true);
                            }
                            else {
                                (*candidates.begin())->setSelected(true);
                            }
                            break;
                        }
                        ++i;
                    } // while
                } // case
                break;
                default:
                break;
            } // switch
        }
    }
}
void TranslateManipulator::testSelect(const render::View& view, const Matrix4& pivot2world) {
    _pivot.update(pivot2world, view.GetModelview(), view.GetProjection(), view.GetViewport());

    SelectionPool selector;

    Vector3 x = _pivot._worldSpace.x().getVector3().getNormalised();
    bool show_x = manipulator_show_axis(_pivot, x);

    Vector3 y = _pivot._worldSpace.y().getVector3().getNormalised();
    bool show_y = manipulator_show_axis(_pivot, y);

    Vector3 z = _pivot._worldSpace.z().getVector3().getNormalised();
    bool show_z = manipulator_show_axis(_pivot, z);

    {
		Matrix4 local2view(view.GetViewMatrix().getMultipliedBy(_pivot._viewpointSpace));

      {
        SelectionIntersection best;
        Quad_BestPoint(local2view, eClipCullCW, &_quadScreen.front(), best);
        if(best.valid())
        {
          best = SelectionIntersection(0, 0);
          selector.addSelectable(best, &_selectableScreen);
        }
      }
    }

    {
		Matrix4 local2view(view.GetViewMatrix().getMultipliedBy(_pivot._worldSpace));

      if(show_x)
      {
        SelectionIntersection best;
        Line_BestPoint(local2view, &_arrowX.front(), best);
        Triangles_BestPoint(local2view, eClipCullCW, &_arrowHeadX._vertices.front(), &*(_arrowHeadX._vertices.end()-1)+1, best);
        selector.addSelectable(best, &_selectableX);
      }

      if(show_y)
      {
        SelectionIntersection best;
        Line_BestPoint(local2view, &_arrowY.front(), best);
        Triangles_BestPoint(local2view, eClipCullCW, &_arrowHeadY._vertices.front(), &*(_arrowHeadY._vertices.end()-1)+1, best);
        selector.addSelectable(best, &_selectableY);
      }

      if(show_z)
      {
        SelectionIntersection best;
        Line_BestPoint(local2view, &_arrowZ.front(), best);
        Triangles_BestPoint(local2view, eClipCullCW, &_arrowHeadZ._vertices.front(), &*(_arrowHeadZ._vertices.end()-1)+1, best);
        selector.addSelectable(best, &_selectableZ);
      }
    }

	// greebo: If any of the above arrows could be selected, select the first in the SelectionPool
    if(!selector.failed()) {
      (*selector.begin()).second->setSelected(true);
    } else {
    	Selectable* selectable = NULL;

    	if (registry::getValue<bool>(RKEY_TRANSLATE_CONSTRAINED)) {
	    	// None of the shown arrows (or quad) has been selected, select an axis based on the precedence
	    	Matrix4 local2view(view.GetViewMatrix().getMultipliedBy(_pivot._worldSpace));

	    	// Get the (relative?) distance from the mouse pointer to the manipulator
	    	Vector3 delta = local2view.t().getProjected();

	    	// Get the precedence (which axis has the absolute largest value in it)
	    	bool xGreaterY = (fabs(delta.x()) > fabs(delta.y()));

	    	// The precedence has to be interpreted according to which axes are visible
	    	if (show_z) {
	    		// Either XZ or YZ
	    		if (show_y) {
	    			// YZ
	    			selectable = (xGreaterY) ? &_selectableY : &_selectableZ;
	    		}
	    		else {
	    			// XZ
	    			selectable = (xGreaterY) ? &_selectableX : &_selectableZ;
	    		}
	    	}
	    	else {
	    		// XY
	    		selectable = (xGreaterY) ? &_selectableX : &_selectableY;
	    	}
    	}
    	else {
    		// Don't constrain to axis, choose the freemove translator
    		selectable = &_selectableScreen;
    	}

		// If everything went ok, there is a selectable available, add it
    	if (selectable != NULL) {
    		selector.addSelectable(SelectionIntersection(0,0), selectable);
    		selectable->setSelected(true);
    	}
    }
}