Changeset 6219


Ignore:
Timestamp:
Mar 29, 2016, 11:54:22 AM (8 years ago)
Author:
ldelgass
Message:

Stubs for editing feature selection set

Location:
geovis/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • geovis/trunk/Renderer.cpp

    r6211 r6219  
    15751575}
    15761576
    1577 void Renderer::selectFeatures(std::vector<unsigned long>& featureIDs, const char *layerName)
     1577void Renderer::deselectFeatures(std::vector<unsigned long>& featureIDs, const char *layerName)
     1578{
     1579    TRACE("Deselect features layer '%s', num features: %u", layerName, featureIDs.size());
     1580    for (unsigned int i = 0; i < featureIDs.size(); i++) {
     1581        _selectedFeatures[layerName].erase(featureIDs.at(i));
     1582    }
     1583    FeatureSelectionHashmap::iterator itr = _selectedFeatures.find(layerName);
     1584    if (itr != _selectedFeatures.end()) {
     1585        for (FeatureSelectionHashmap::mapped_type::iterator fitr = itr->second.begin();
     1586             fitr != itr->second.end(); ++fitr) {
     1587            TRACE("Selection: %lu", *fitr);
     1588        }
     1589    } else {
     1590        TRACE("No selection");
     1591    }
     1592}
     1593
     1594void Renderer::selectFeatures(std::vector<unsigned long>& featureIDs, const char *layerName, bool clear)
    15781595{
    15791596    TRACE("Select layer '%s', num features: %u", layerName, featureIDs.size());
    1580     clearSelection();
     1597    if (clear) {
     1598        clearSelection();
     1599        _selectedFeatures.clear();
     1600    }
    15811601    if (featureIDs.size() == 0) {
    15821602        // clear selection
     
    15881608        return;
    15891609    }
    1590 #ifdef WANT_TRACE
    15911610    for (unsigned int i = 0; i < featureIDs.size(); i++) {
    15921611        TRACE("feature ID: %u", featureIDs.at(i));
    1593     }
    1594 #endif
     1612        _selectedFeatures[layerName].insert(featureIDs.at(i));
     1613    }
     1614    FeatureSelectionHashmap::iterator itr = _selectedFeatures.find(layerName);
     1615    if (itr != _selectedFeatures.end()) {
     1616        for (FeatureSelectionHashmap::mapped_type::iterator fitr = itr->second.begin();
     1617             fitr != itr->second.end(); ++fitr) {
     1618            TRACE("Selection: %lu", *fitr);
     1619        }
     1620    } else {
     1621        TRACE("No selection");
     1622    }
    15951623    unsigned long fid = featureIDs.at(0);
    15961624
  • geovis/trunk/Renderer.h

    r6083 r6219  
    469469    }
    470470
    471     bool mouseToLatLong(int mouseX, int mouseY, double *latitude, double *longitude);
     471    bool mouseToLatLong(int mouseX, int mouseY,
     472                        double *latitude, double *longitude);
    472473
    473474    bool getWorldCoords(const osgEarth::GeoPoint& mapPt, osg::Vec3d *world);
     
    529530    void setSelectMode(SelectMode mode);
    530531
    531     void selectFeatures(std::vector<unsigned long>& featureIDs, const char *layerName);
     532    void selectFeatures(std::vector<unsigned long>& featureIDs,
     533                        const char *layerName, bool clear = true);
     534
     535    void deselectFeatures(std::vector<unsigned long>& featureIDs,
     536                          const char *layerName);
    532537
    533538    void addPlacard(const osgEarth::GeoPoint& location,
     
    537542    void clearSelection();
    538543
    539     void addRhumbBox(double latMin, double latMax, double longMin, double longMax);
     544    void addRhumbBox(double latMin, double latMax,
     545                     double longMin, double longMax);
    540546
    541547    void initBoxSelection(int x, int y);
     
    585591    typedef std::tr1::unordered_map<ViewpointId, osgEarth::Viewpoint> ViewpointHashmap;
    586592    typedef std::tr1::unordered_map<std::string, Placard> PlacardHashmap;
     593    typedef std::tr1::unordered_map<std::string, std::set<unsigned long> > FeatureSelectionHashmap;
    587594
    588595    void initAnnotations();
     
    645652    bool _pickPending;
    646653    osg::ref_ptr<osg::Group> _placeNodes;
     654    FeatureSelectionHashmap _selectedFeatures;
    647655    std::set<osgEarth::Annotation::AnnotationNode *> _hovered;
    648656    std::set<osgEarth::Annotation::AnnotationNode *> _selected;
  • geovis/trunk/RendererCmd.cpp

    r6218 r6219  
    34593459
    34603460static int
     3461SelectAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
     3462            Tcl_Obj *const *objv)
     3463{
     3464    int numIDs;
     3465    Tcl_Obj **ids;
     3466    if (Tcl_ListObjGetElements(interp, objv[2], &numIDs, &ids) != TCL_OK) {
     3467        return TCL_ERROR;
     3468    }
     3469    if (numIDs == 0) {
     3470        Tcl_AppendResult(interp, "no IDs in list", (char *)NULL);
     3471        return TCL_ERROR;
     3472    }
     3473    std::vector<unsigned long> featureIDs;
     3474    for (int i = 0; i < numIDs; i++) {
     3475        long id;
     3476        if (Tcl_GetLongFromObj(interp, ids[i], &id) != TCL_OK) {
     3477            return TCL_ERROR;
     3478        }
     3479        featureIDs.push_back((unsigned long)id);
     3480    }
     3481    const char *layerName = Tcl_GetString(objv[3]);
     3482
     3483    g_renderer->selectFeatures(featureIDs, layerName, false);
     3484    return TCL_OK;
     3485}
     3486
     3487static int
    34613488SelectClearOp(ClientData clientData, Tcl_Interp *interp, int objc,
    34623489              Tcl_Obj *const *objv)
    34633490{
    34643491    g_renderer->clearSelection();
     3492    return TCL_OK;
     3493}
     3494
     3495static int
     3496SelectDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
     3497               Tcl_Obj *const *objv)
     3498{
     3499    int numIDs;
     3500    Tcl_Obj **ids;
     3501    if (Tcl_ListObjGetElements(interp, objv[2], &numIDs, &ids) != TCL_OK) {
     3502        return TCL_ERROR;
     3503    }
     3504    if (numIDs == 0) {
     3505        Tcl_AppendResult(interp, "no IDs in list", (char *)NULL);
     3506        return TCL_ERROR;
     3507    }
     3508    std::vector<unsigned long> featureIDs;
     3509    for (int i = 0; i < numIDs; i++) {
     3510        long id;
     3511        if (Tcl_GetLongFromObj(interp, ids[i], &id) != TCL_OK) {
     3512            return TCL_ERROR;
     3513        }
     3514        featureIDs.push_back((unsigned long)id);
     3515    }
     3516    const char *layerName = Tcl_GetString(objv[3]);
     3517
     3518    g_renderer->deselectFeatures(featureIDs, layerName);
    34653519    return TCL_OK;
    34663520}
     
    35153569static CmdSpec selectOps[] = {
    35163570    {"clear",   1, SelectClearOp,   2, 2, ""},
     3571    {"fadd",    2, SelectAddOp,     4, 4, "idlist layerName"},
     3572    {"fdelete", 2, SelectDeleteOp,  4, 4, "idlist layerName"},
    35173573    {"feature", 1, SelectFeatureOp, 4, 4, "idlist layerName"},
    35183574    {"mode",    1, SelectModeOp,    3, 3, "mode"},
Note: See TracChangeset for help on using the changeset viewer.