Changeset 6219
- Timestamp:
- Mar 29, 2016, 11:54:22 AM (8 years ago)
- Location:
- geovis/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
geovis/trunk/Renderer.cpp
r6211 r6219 1575 1575 } 1576 1576 1577 void Renderer::selectFeatures(std::vector<unsigned long>& featureIDs, const char *layerName) 1577 void 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 1594 void Renderer::selectFeatures(std::vector<unsigned long>& featureIDs, const char *layerName, bool clear) 1578 1595 { 1579 1596 TRACE("Select layer '%s', num features: %u", layerName, featureIDs.size()); 1580 clearSelection(); 1597 if (clear) { 1598 clearSelection(); 1599 _selectedFeatures.clear(); 1600 } 1581 1601 if (featureIDs.size() == 0) { 1582 1602 // clear selection … … 1588 1608 return; 1589 1609 } 1590 #ifdef WANT_TRACE1591 1610 for (unsigned int i = 0; i < featureIDs.size(); i++) { 1592 1611 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 } 1595 1623 unsigned long fid = featureIDs.at(0); 1596 1624 -
geovis/trunk/Renderer.h
r6083 r6219 469 469 } 470 470 471 bool mouseToLatLong(int mouseX, int mouseY, double *latitude, double *longitude); 471 bool mouseToLatLong(int mouseX, int mouseY, 472 double *latitude, double *longitude); 472 473 473 474 bool getWorldCoords(const osgEarth::GeoPoint& mapPt, osg::Vec3d *world); … … 529 530 void setSelectMode(SelectMode mode); 530 531 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); 532 537 533 538 void addPlacard(const osgEarth::GeoPoint& location, … … 537 542 void clearSelection(); 538 543 539 void addRhumbBox(double latMin, double latMax, double longMin, double longMax); 544 void addRhumbBox(double latMin, double latMax, 545 double longMin, double longMax); 540 546 541 547 void initBoxSelection(int x, int y); … … 585 591 typedef std::tr1::unordered_map<ViewpointId, osgEarth::Viewpoint> ViewpointHashmap; 586 592 typedef std::tr1::unordered_map<std::string, Placard> PlacardHashmap; 593 typedef std::tr1::unordered_map<std::string, std::set<unsigned long> > FeatureSelectionHashmap; 587 594 588 595 void initAnnotations(); … … 645 652 bool _pickPending; 646 653 osg::ref_ptr<osg::Group> _placeNodes; 654 FeatureSelectionHashmap _selectedFeatures; 647 655 std::set<osgEarth::Annotation::AnnotationNode *> _hovered; 648 656 std::set<osgEarth::Annotation::AnnotationNode *> _selected; -
geovis/trunk/RendererCmd.cpp
r6218 r6219 3459 3459 3460 3460 static int 3461 SelectAddOp(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 3487 static int 3461 3488 SelectClearOp(ClientData clientData, Tcl_Interp *interp, int objc, 3462 3489 Tcl_Obj *const *objv) 3463 3490 { 3464 3491 g_renderer->clearSelection(); 3492 return TCL_OK; 3493 } 3494 3495 static int 3496 SelectDeleteOp(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); 3465 3519 return TCL_OK; 3466 3520 } … … 3515 3569 static CmdSpec selectOps[] = { 3516 3570 {"clear", 1, SelectClearOp, 2, 2, ""}, 3571 {"fadd", 2, SelectAddOp, 4, 4, "idlist layerName"}, 3572 {"fdelete", 2, SelectDeleteOp, 4, 4, "idlist layerName"}, 3517 3573 {"feature", 1, SelectFeatureOp, 4, 4, "idlist layerName"}, 3518 3574 {"mode", 1, SelectModeOp, 3, 3, "mode"},
Note: See TracChangeset
for help on using the changeset viewer.