Example #1
0
gint Selection::TimeOutCallback(gpointer data)
{
  Selection *oSelection = (Selection *)data;
  if (oSelection->Enable()) {

		if (conf->get_bool("/apps/stardict/preferences/dictionary/only_scan_while_modifier_key")) {
      bool do_scan = gpAppFrame->unlock_keys->is_pressed();
      if (!do_scan)
				return true;
    }

    if (oSelection->IsBusy) {
      oSelection->IsBusy++;
      if (oSelection->IsBusy*SELECTION_INTERVAL > 8000 ) {
				//"selection_received" signal is not received for 8 seconds.
				//there encounter some error,and i find that this often take a long time (serveral minutes) to get the signal at last,
				//during this perioed,if you call gtk_selection_convert(),the "selection_received" signal will not be received also,
				//and at last these signals are received at almost the same time...BAD.
				
				//so here create a new selection_widget, then call gtk_selection_convert()...this should can throw that error selection.
				//!!!:
				//But this seems(i am not sure) will make the widgets in StarDict become unselectable! see BUGS.
				g_warning("Error, selection data didn't received, retring!\n");
				oSelection->create_selection_widget();
				oSelection->IsBusy = 0;
      }
    } else {
      oSelection->IsBusy = 1;
      gtk_selection_convert (oSelection->selection_widget, GDK_SELECTION_PRIMARY, oSelection->UTF8_STRING_Atom, GDK_CURRENT_TIME);
    }
  }

  return true;
}
Example #2
0
void Viewer::Update () {
    Selection* s = GetSelection();
    GraphicView* view = GetGraphicView();
    Component* viewComp = view->GetGraphicComp();
    Component* edComp = _editor->GetComponent();

    if (viewComp != edComp) {
        ComponentView* newView = edComp->Create(ViewCategory());

        if (newView->IsA(GRAPHIC_VIEW)) {
            edComp->Attach(newView);
            newView->Update();
            SetGraphicView((GraphicView*) newView);

        } else {
            delete newView;
        }

    } else {
	s->Hide(this);
        _viewerView->Update();
        GraphicBlock::UpdatePerspective();
	_damage->Repair();
        s->Show(this);
    }
}
Example #3
0
Selection selectThisLine (const Document & document, const Selection & basis) {
    Location origin(0, basis.origin().row());

    std::uint64_t row = basis.extent().row();
    Location extent(document.row(row).size() - 1, row);
    return Selection(origin, extent);
}
Example #4
0
void InspectorPanel::newItemsInspected(const Selection& objects)
{
    // Ignore items in both
    // Create items in objects and not in current
    // Delete items in current and not in objects
    Selection toCreate, toDelete;
    std::set_difference(objects.begin(), objects.end(),
                        m_currentSel.begin(), m_currentSel.end(),
                        std::inserter(toCreate, toCreate.begin()));

    std::set_difference(m_currentSel.begin(), m_currentSel.end(),
                        objects.begin(), objects.end(),
                        std::inserter(toDelete, toDelete.begin()));
    for(const auto& object : toDelete)
    {
        auto widget_it = m_map.get<0>().find(object);
        if(widget_it != m_map.get<0>().end())
        {
            (*widget_it)->deleteLater();
            *m_map.get<0>().erase(widget_it);
        }
    }

    for(const auto& object : toCreate)
    {
        auto widget = InspectorWidgetList::makeInspectorWidget(object->objectName(),
                                                               object,
                                                               m_tabWidget);
        m_tabWidget->addTab(widget, widget->tabName());
        m_map.insert(widget);
    }

    m_currentSel = objects;
}
Example #5
0
void PlayContextMenu::fillContextMenu(
        QMenu *menu,
        const Selection & s,
        const TemporalScenarioPresenter& pres,
        const QPoint& pt,
        const QPointF& scenept)
{
    menu->addAction(m_playFromHere);
    auto scenPoint = Scenario::ConvertToScenarioPoint(scenept, pres.zoomRatio(), pres.view().height());
    m_playFromHere->setData(QVariant::fromValue(scenPoint.date));

    if(s.empty())
    {
        menu->addAction(m_recordAction);
        m_recordAction->setData(QVariant::fromValue(ScenarioRecordInitData{&pres, scenept}));
    }
    else
    {
        if(std::any_of(s.cbegin(), s.cend(), [] (auto obj) { return dynamic_cast<const StateModel*>(obj.data());}))
        {
            menu->addAction(m_playStates);
        }
        /*
    if(std::any_of(s.cbegin(), s.cend(), [] (auto obj) { return dynamic_cast<const ConstraintModel*>(obj);}))
    {
        menu->addAction(m_playConstraints);
    }
    if(std::any_of(s.cbegin(), s.cend(), [] (auto obj) { return dynamic_cast<const EventModel*>(obj);}))
    {
        menu->addAction(m_playEvents);
    }
    */
    }
}
Example #6
0
gint Selection::TimeOutCallback(gpointer data)
{
    Selection *oSelection = (Selection *)data;
  
    if (oSelection->IsBusy) {
        oSelection->IsBusy++;
        if (oSelection->IsBusy*SELECTION_INTERVAL > 8000 ) {
            //"selection_received" signal is not received for 8 seconds.
            //there encounter some error,and i find that this often take a long time (serveral minutes) to get the signal at last,
            //during this perioed,if you call gtk_selection_convert(),the "selection_received" signal will not be received also,
            //and at last these signals are received at almost the same time...BAD.
            //so here create a new selection_widget, then call gtk_selection_convert(). this should can throw that 
            //error selection.            
            g_warning("Error, selection data didn't received, retring!\n");
            oSelection->create_selection_widget();
            oSelection->IsBusy = 0;
        }
    } else {
        oSelection->IsBusy = 1;
        gtk_selection_convert (oSelection->selection_widget, GDK_SELECTION_PRIMARY, oSelection->UTF8_STRING_Atom, 
                               GDK_CURRENT_TIME);
    }

    return TRUE;
}
Example #7
0
Manipulator* ExamineTool::CreateManipulator (
    Viewer* v, Event& e, Transformer* t
){
    GraphicView* views = v->GetGraphicView();
    Selection* s = v->GetSelection();
    _selPath = new Selection;
    Manipulator* m = nil;

    s->Clear();
    ComputeViewPath(e, views, _selPath);
    _shift = e.shift_is_down();

    if (!_selPath->IsEmpty()) {
        Iterator i;
        _selPath->First(i);
	GraphicView* gv = _selPath->GetView(i);
        s->Append(gv);
        s->Update();
        _selPath->Last(i);
	gv = _selPath->GetView(i);
        
        m = gv->CreateManipulator(v, e, t, this);
    }
    delete _selPath;
    return m;
}
void QDesignerIntegrationPrivate::getSelection(Selection &s)
{
    QDesignerFormEditorInterface *core = q->core();
    // Get multiselection from object inspector
    if (QDesignerObjectInspector *designerObjectInspector = qobject_cast<QDesignerObjectInspector *>(core->objectInspector())) {
        designerObjectInspector->getSelection(s);
        // Action editor puts actions that are not on the form yet
        // into the property editor only.
        if (s.empty())
            if (QObject *object = core->propertyEditor()->object())
                s.objects.push_back(object);

    } else {
        // Just in case someone plugs in an old-style object inspector: Emulate selection
        s.clear();
        QDesignerFormWindowInterface *formWindow = core->formWindowManager()->activeFormWindow();
        if (!formWindow)
            return;

        QObject *object = core->propertyEditor()->object();
        if (object->isWidgetType()) {
            QWidget *widget = static_cast<QWidget*>(object);
            QDesignerFormWindowCursorInterface *cursor = formWindow->cursor();
            if (cursor->isWidgetSelected(widget)) {
                s.managed.push_back(widget);
            } else {
                s.unmanaged.push_back(widget);
            }
        } else {
            s.objects.push_back(object);
        }
    }
}
Example #9
0
void
TimeInstantLayer::moveSelection(Selection s, size_t newStartFrame)
{
    if (!m_model) return;

    SparseOneDimensionalModel::EditCommand *command =
	new SparseOneDimensionalModel::EditCommand(m_model,
						   tr("Drag Selection"));

    SparseOneDimensionalModel::PointList points =
	m_model->getPoints(s.getStartFrame(), s.getEndFrame());

    for (SparseOneDimensionalModel::PointList::iterator i = points.begin();
	 i != points.end(); ++i) {

	if (s.contains(i->frame)) {
	    SparseOneDimensionalModel::Point newPoint(*i);
	    newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
	    command->deletePoint(*i);
	    command->addPoint(newPoint);
	}
    }

    finish(command);
}
Example #10
0
// This avoids the expense of a full fledged delete operation, and avoids a layout that typically results
// from text removal.
bool InsertTextCommand::performTrivialReplace(const String& text, bool selectInsertedText)
{
    if (!endingSelection().isRange())
        return false;
    
    if (text.contains('\t') || text.contains(' ') || text.contains('\n'))
        return false;
    
    Position start = endingSelection().start();
    Position end = endingSelection().end();
    
    if (start.node() != end.node() || !start.node()->isTextNode() || isTabSpanTextNode(start.node()))
        return false;
        
    replaceTextInNode(static_cast<Text*>(start.node()), start.offset(), end.offset() - start.offset(), text);
    
    Position endPosition(start.node(), start.offset() + text.length());
    
    // We could have inserted a part of composed character sequence,
    // so we are basically treating ending selection as a range to avoid validation.
    // <http://bugs.webkit.org/show_bug.cgi?id=15781>
    Selection forcedEndingSelection;
    forcedEndingSelection.setWithoutValidation(start, endPosition);
    setEndingSelection(forcedEndingSelection);
    
    if (!selectInsertedText)
        setEndingSelection(Selection(endingSelection().visibleEnd()));
    
    return true;
}
Example #11
0
Selection filterSelections(
        T* pressedModel,
        Selection sel,
        bool cumulation)
{
    if(!cumulation)
    {
        sel.clear();
    }

    // If the pressed element is selected
    if(pressedModel->selection.get())
    {
        if(cumulation)
        {
            sel.erase(pressedModel);
        }
        else
        {
            sel.insert(pressedModel);
        }
    }
    else
    {
        sel.insert(pressedModel);
    }

    return sel;
}
void
SelectionManager::SetControlSelectionListener(dom::Element* aFocusedElm)
{
  // When focus moves such that the caret is part of a new frame selection
  // this removes the old selection listener and attaches a new one for
  // the current focus.
  ClearControlSelectionListener();

  mLastTextAccessible = nullptr;

  mCurrCtrlFrame = aFocusedElm->GetPrimaryFrame();
  if (!mCurrCtrlFrame)
    return;

  const nsFrameSelection* frameSel = mCurrCtrlFrame->GetConstFrameSelection();
  NS_ASSERTION(frameSel, "No frame selection for focused element!");
  if (!frameSel)
    return;

  // Register 'this' as selection listener for the normal selection.
  Selection* normalSel =
    frameSel->GetSelection(nsISelectionController::SELECTION_NORMAL);
  normalSel->AddSelectionListener(this);

  // Register 'this' as selection listener for the spell check selection.
  Selection* spellSel =
    frameSel->GetSelection(nsISelectionController::SELECTION_SPELLCHECK);
  spellSel->AddSelectionListener(this);
}
void MoveSelectionCommand::doApply()
{
    Selection selection = endingSelection();
    ASSERT(selection.isRange());

    Position pos = m_position;
    if (pos.isNull())
        return;
        
    // Update the position otherwise it may become invalid after the selection is deleted.
    Node *positionNode = m_position.node();
    int positionOffset = m_position.offset();
    Position selectionEnd = selection.end();
    int selectionEndOffset = selectionEnd.offset();    
    if (selectionEnd.node() == positionNode && selectionEndOffset < positionOffset) {
        positionOffset -= selectionEndOffset;
        Position selectionStart = selection.start();
        if (selectionStart.node() == positionNode) {
            positionOffset += selectionStart.offset();
        }
        pos = Position(positionNode, positionOffset);
    }

    deleteSelection(m_smartMove);

    // If the node for the destination has been removed as a result of the deletion,
    // set the destination to the ending point after the deletion.
    // Fixes: <rdar://problem/3910425> REGRESSION (Mail): Crash in ReplaceSelectionCommand; 
    //        selection is empty, leading to null deref
    if (!pos.node()->inDocument())
        pos = endingSelection().start();

    setEndingSelection(Selection(pos, endingSelection().affinity()));
    applyCommandToComposite(ReplaceSelectionCommand::create(positionNode->document(), m_fragment, true, m_smartMove));
}
void
SelectionManager::ProcessTextSelChangeEvent(AccEvent* aEvent)
{
  AccTextSelChangeEvent* event = downcast_accEvent(aEvent);
  Selection* sel = static_cast<Selection*>(event->mSel.get());

  // Fire selection change event if it's not pure caret-move selection change.
  if (sel->GetRangeCount() != 1 || !sel->IsCollapsed())
    nsEventShell::FireEvent(aEvent);

  // Fire caret move event if there's a caret in the selection.
  nsINode* caretCntrNode =
    nsCoreUtils::GetDOMNodeFromDOMPoint(sel->GetFocusNode(),
                                        sel->GetFocusOffset());
  if (!caretCntrNode)
    return;

  HyperTextAccessible* caretCntr = nsAccUtils::GetTextContainer(caretCntrNode);
  NS_ASSERTION(caretCntr,
               "No text container for focus while there's one for common ancestor?!");
  if (!caretCntr)
    return;

  int32_t caretOffset = -1;
  if (NS_SUCCEEDED(caretCntr->GetCaretOffset(&caretOffset)) && caretOffset != -1) {
    nsRefPtr<AccCaretMoveEvent> caretMoveEvent =
      new AccCaretMoveEvent(caretCntr, caretOffset, aEvent->FromUserInput());
    nsEventShell::FireEvent(caretMoveEvent);
  }
}
Example #15
0
/**
 * Scripter.activeDocument.selection
 * Property
 * List of selected Item objects on active document
 */
QList<QVariant> DocumentAPI::selection()
{
	QList<QVariant> l;
	Selection *sel = ScCore->primaryMainWindow()->doc->m_Selection;
	for (int i=0; i < sel->count(); i++)
	{
		/**
		 * Checking whether it is a textframe. If yes, we are trying to cast 
		 * it onto TextWrapper class, which can effectively perform all 
		 * the text operations
		 */
		PageItem *item = sel->itemAt(i);
		if (item->asTextFrame())
		{
			TextAPI *textItem = new TextAPI(item->asTextFrame());
			l.append(qVariantFromValue((QObject *)(textItem)));
		}
		else if(item->asImageFrame())
		{
			ImageAPI *imageItem = new ImageAPI(item->asImageFrame());
			l.append(qVariantFromValue((QObject *)(imageItem)));
		}
		else
		{
			ItemAPI *otherItem = new ItemAPI(item);
			l.append(qVariantFromValue(
			             (QObject *)(otherItem)
			         ));
		}
	}
	return l;
}
Example #16
0
static void
DispatchSelectionStateChangedEvent(nsIPresShell* aPresShell,
                             nsISelection* aSel,
                             const dom::Sequence<SelectionState>& aStates)
{
  nsIDocument* doc = aPresShell->GetDocument();

  MOZ_ASSERT(doc);

  SelectionStateChangedEventInit init;
  init.mBubbles = true;

  if (aSel) {
    Selection* selection = static_cast<Selection*>(aSel);
    nsRect rect = GetSelectionBoundingRect(selection, doc->GetShell());
    nsRefPtr<DOMRect>domRect = new DOMRect(ToSupports(doc));

    domRect->SetLayoutRect(rect);
    init.mBoundingClientRect = domRect;

    selection->Stringify(init.mSelectedText);
  }
  init.mStates = aStates;

  nsRefPtr<SelectionStateChangedEvent> event =
    SelectionStateChangedEvent::Constructor(doc, NS_LITERAL_STRING("mozselectionstatechanged"), init);

  event->SetTrusted(true);
  event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;
  bool ret;
  doc->DispatchEvent(event, &ret);
}
Example #17
0
void FindQueryTab::activateCheckerEvents()
{
    Selection events = model_->events();

    // Process checker's events
    set<int> checker_events = active_checker->events();
    for (set<int>::iterator it = checker_events.begin();
        it != checker_events.end(); it++)
    {
        int eventLink = events.itemLink(*it);
        events.setEnabled(eventLink, true);

        // Process checker's subevents
        set<int> checker_subevents = active_checker->subevents(*it);
        for (set<int>::iterator it2 = checker_subevents.begin();
            it2 != checker_subevents.end(); it2++)
        {
            if (events.itemsCount(eventLink) > *it2)
                events.setEnabled(*it2, eventLink, true);
        }
    }

    Canvas * canvas = find_tool_->getCanvas();
    canvas->setModel(canvas->getModel()->filter_events(events));
}
Example #18
0
// _Select
void
PathManipulator::_Select(BRect r)
{
	BPoint p;
	BPoint pIn;
	BPoint pOut;
	int32 count = fPath->CountPoints();
	Selection temp;
	for (int32 i = 0; i < count && fPath->GetPointsAt(i, p, pIn, pOut); i++) {
		if (r.Contains(p) || r.Contains(pIn) || r.Contains(pOut)) {
			temp.Add(i);
		}
	}
	// merge old and new selection
	count = fOldSelection->CountItems();
	for (int32 i = 0; i < count; i++) {
		int32 index = fOldSelection->IndexAt(i);
		if (temp.Contains(index))
			temp.Remove(index);
		else
			temp.Add(index);
	}
	if (temp != *fSelection) {
		*fSelection = temp;
		_UpdateSelection();
	}
}
static QString objectTypeName(const Selection& sel)
{
    if (sel.star() != NULL)
    {
        if (!sel.star()->getVisibility())
            return QObject::tr("Barycenter");
        else
            return QObject::tr("Star");
    }
    else if (sel.body() != NULL)
    {
        int classification = sel.body()->getClassification();
        if (classification == Body::Planet)
            return QObject::tr("Planet");
        else if (classification == Body::DwarfPlanet)
            return QObject::tr("Dwarf planet");
        else if (classification == Body::Moon || classification == Body::MinorMoon)
            return QObject::tr("Moon");
        else if (classification == Body::Asteroid)
            return QObject::tr("Asteroid");
        else if (classification == Body::Comet)
            return QObject::tr("Comet");
        else if (classification == Body::Spacecraft)
            return QObject::tr("Spacecraft");
        else if (classification == Body::Invisible)
            return QObject::tr("Reference point");
		else if (classification == Body::Component)
			return QObject::tr("Component");
		else if (classification == Body::SurfaceFeature)
			return QObject::tr("Surface feature");
    }

    return QObject::tr("Unknown");
}
Example #20
0
void GLGizmoRotate::transform_to_local(const Selection& selection) const
{
    glsafe(::glTranslated(m_center(0), m_center(1), m_center(2)));

    if (selection.is_single_volume() || selection.is_single_modifier() || selection.requires_local_axes())
    {
        Transform3d orient_matrix = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(true, false, true, true);
        glsafe(::glMultMatrixd(orient_matrix.data()));
    }

    switch (m_axis)
    {
    case X:
    {
        glsafe(::glRotatef(90.0f, 0.0f, 1.0f, 0.0f));
        glsafe(::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f));
        break;
    }
    case Y:
    {
        glsafe(::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f));
        glsafe(::glRotatef(-90.0f, 0.0f, 1.0f, 0.0f));
        break;
    }
    default:
    case Z:
    {
        // no rotation
        break;
    }
    }
}
Example #21
0
Manipulator* NarrowTool::CreateManipulator (Viewer* v, Event& e,Transformer*){
    Manipulator* m = nil;
    _popup = false;
    GraphicView* views = v->GetGraphicView();
    if (!e.shift_is_down()) {
        Selection* s = v->GetSelection(), *newSel = new Selection;
        
        s->Clear();
        ComputeViewPath(e, views, newSel);
        
        if (!newSel->IsEmpty()) {
            Iterator i;
            newSel->First(i);
            GraphicView* gv = newSel->GetView(i);
            
            s->Append(gv);
            s->Update();

            m = CreatePopupManip(newSel, v);
            _popup = true;
        }
        
        delete newSel;
    } else {
        m = new NarrowManip(v);
    }
    return m;
}
Example #22
0
Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const
{
    double half_pi = 0.5 * (double)PI;

    Transform3d m = Transform3d::Identity();

    switch (m_axis)
    {
    case X:
    {
        m.rotate(Eigen::AngleAxisd(half_pi, Vec3d::UnitZ()));
        m.rotate(Eigen::AngleAxisd(-half_pi, Vec3d::UnitY()));
        break;
    }
    case Y:
    {
        m.rotate(Eigen::AngleAxisd(half_pi, Vec3d::UnitY()));
        m.rotate(Eigen::AngleAxisd(half_pi, Vec3d::UnitZ()));
        break;
    }
    default:
    case Z:
    {
        // no rotation applied
        break;
    }
    }

    if (selection.is_single_volume() || selection.is_single_modifier() || selection.requires_local_axes())
        m = m * selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(true, false, true, true).inverse();

    m.translate(-m_center);

    return transform(mouse_ray, m).intersect_plane(0.0);
}
Example #23
0
void TextManip::Grasp (Event& e) {
    _grasp_e = e;

    Viewer* v = GetViewer();
    Selection* s = v->GetSelection();
    v->Constrain(e.x, e.y);

    _selecting = true;
    if (!_prepositioned) {
        _xpos = e.x;
        _ypos = e.y;
    }

    PlaceTextDisplay(_xpos, _ypos);
    Coord l, b, r, t;
    _display->CaretStyle(BarCaret);
    _display->Bounds(l, b, r, t);
    _display->Redraw(l, b, r, t);

    _selection = new Selection(s);
    s->Clear();

    if (_prepositioned) {
        Select(Locate(e.x, e.y));
    }
}
Example #24
0
Manipulator* LinkView::CreateLinkCompManip (
    Viewer* v, Event& e, Transformer* rel, Tool* tool
) {
    GraphicView* views = v->GetGraphicView();
    Selection* s = v->GetSelection();
    RubberGroup* rg = new RubberGroup(nil, nil);
    float x, y, tx, ty;
    Coord cx = 0, rad = PIN_RAD, dum1 = 0, dum2 = 0;
    ConnectorView* target = views->ConnectorIntersecting(
        e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP
    );

    s->Clear();
    if (target != nil) {
        target->GetConnector()->GetCenter(x, y);
        rel->Transform(x, y, tx, ty);
        e.x = Math::round(tx);
        e.y = Math::round(ty);
    }
    if (rel != nil) {
        rel->Transform(cx, dum1);
        rel->Transform(rad, dum2);
        rad = abs(rad - cx);
    }
    rg->Append(
        new RubberLine(nil, nil, e.x, e.y, e.x, e.y),
        new FixedPin(nil, nil, e.x, e.y, rad),
        new SlidingPin(nil, nil, e.x, e.y, rad, e.x, e.y)
    );
    return new ConnectManip(v, rg, rel, tool);
}
Example #25
0
int
AnalysisTemplate::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
                               TrajectoryAnalysisModuleData *pdata)
{
    AnalysisDataHandle *dh = pdata->dataHandle("avedist");
    NeighborhoodSearch *nb = static_cast<ModuleData *>(pdata)->_nb;

    int rc = nb->init(pbc, _refsel->positions());
    if (rc != 0)
    {
        return rc;
    }
    dh->startFrame(frnr, fr.time);
    for (size_t g = 0; g < _sel.size(); ++g)
    {
        Selection *sel = pdata->parallelSelection(_sel[g]);
        int   nr = sel->posCount();
        real  frave = 0.0;
        for (int i = 0; i < nr; ++i)
        {
            frave += nb->minimumDistance(sel->x(i));
        }
        frave /= nr;
        dh->addPoint(g, frave);
    }
    dh->finishFrame();
    return 0;
}
Example #26
0
 bool Selector::ProcessTerrainMesh(Node *node, Virtual::TerrainMesh *terrain)
 {        
     if (terrain)
     {
         Virtual::StaticGeometry* geom = terrain->GetGeometry();
         if (geom)
         {
             Math::Line3D line = m_local_transform.top().Inversed() * m_view_ray;
             std::vector<Math::vec3> points;
             std::vector<size_t> faces;
             Math::Relation r = Math::CrossLineTriangles(line, geom->GetCpuCache().GetVertices(), geom->GetCpuCache().GetFaces(), points, faces);
             if (r == Math::Relation::INTERSECT)
             {
                 Selection selection;
                 //  return points to the worlds coordinate system
                 for (auto& p : points)
                 {
                     p = m_local_transform.top() * p;
                 }
                 selection.SetPoints(points);
                 selection.SetFaces(faces);
                 selection.SetObject(node);
                 m_selections.push_back(selection);
             }
         }
     }
     ProcessChildren(node);
     return true;
 }
Example #27
0
void PlayContextMenu::fillContextMenu(QMenu *menu, const Selection & s)
{
    if(std::any_of(s.cbegin(), s.cend(), [] (auto obj) { return dynamic_cast<const StateModel*>(obj);}))
    {
        menu->addAction(m_playStates);
    }
}
Example #28
0
 bool Selector::ProcessNaviMesh(Node *node, AI::NaviMesh *mesh)
 {     
     if (mesh)
     {
         auto line = m_local_transform.top().Inversed() * m_view_ray;
         std::vector<Math::vec3> points;
         std::vector<size_t> faces;
         Math::Relation res = Math::CrossLineTriangles(line, mesh->GetPoints(), mesh->GetFaces(), points, faces);
         if (res == Math::Relation::INTERSECT)
         {
             //  return points to the worlds coordinate system
             for (auto& p : points)
             {
                 p = m_local_transform.top() * p;
             }
             Selection selection;
             selection.SetPoints(points);
             selection.SetFaces(faces);
             selection.SetObject(node);
             m_selections.push_back(selection);
         }
     }
     ProcessChildren(node);
     return true;
 } 
Example #29
0
void CommandGoto::process(ExecutionEnvironment& env)
{
    Selection sel = env.getSimulation()->getSelection();
    env.getSimulation()->gotoSelection(gotoTime,
                                       astro::kilometersToLightYears(sel.radius() * distance),
                                       up, upFrame);
}
Example #30
0
void GraphicsWindow::HitTestMakeSelection(Point2d mp) {
    int i;
    double d, dmin = 1e12;
    Selection s;
    ZERO(&s);

    // Always do the entities; we might be dragging something that should
    // be auto-constrained, and we need the hover for that.
    for(i = 0; i < SK.entity.n; i++) {
        Entity *e = &(SK.entity.elem[i]);
        // Don't hover whatever's being dragged.
        if(e->h.request().v == pending.point.request().v) {
            // The one exception is when we're creating a new cubic; we
            // want to be able to hover the first point, because that's
            // how we turn it into a periodic spline.
            if(!e->IsPoint()) continue;
            if(!e->h.isFromRequest()) continue;
            Request *r = SK.GetRequest(e->h.request());
            if(r->type != Request::CUBIC) continue;
            if(r->extraPoints < 2) continue;
            if(e->h.v != r->h.entity(1).v) continue;
        }

        d = e->GetDistance(mp);
        if(d < 10 && d < dmin) {
            memset(&s, 0, sizeof(s));
            s.entity = e->h;
            dmin = d;
        }
    }

    // The constraints and faces happen only when nothing's in progress.
    if(pending.operation == 0) {
        // Constraints
        for(i = 0; i < SK.constraint.n; i++) {
            d = SK.constraint.elem[i].GetDistance(mp);
            if(d < 10 && d < dmin) {
                memset(&s, 0, sizeof(s));
                s.constraint = SK.constraint.elem[i].h;
                dmin = d;
            }
        }

        // Faces, from the triangle mesh; these are lowest priority
        if(s.constraint.v == 0 && s.entity.v == 0 && showShaded && showFaces) {
            Group *g = SK.GetGroup(activeGroup);
            SMesh *m = &(g->displayMesh);

            uint32_t v = m->FirstIntersectionWith(mp);
            if(v) {
                s.entity.v = v;
            }
        }
    }

    if(!s.Equals(&hover)) {
        hover = s;
        InvalidateGraphics();
    }
}