Skip to content

Commit

Permalink
Merge bac2562 into 59c1755
Browse files Browse the repository at this point in the history
  • Loading branch information
rupakbajgain committed Jun 26, 2020
2 parents 59c1755 + bac2562 commit 7f84584
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions lcviewernoqt/documentcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,29 +523,39 @@ void DocumentCanvas::makeSelection(double x, double y, double w, double h, bool
// std::cout << *_selectedArea << std::endl;
_selectedAreaIntersects = occupies;


// remove old new selection
for(const auto& di: _newSelection) {
di->selected(false);
}
_newSelection.clear();

// refresh selection contents
for(const auto& di: _selectedDrawables) {
di->selected(true);
}

lc::storage::EntityContainer<lc::entity::CADEntity_CSPtr> entitiesInSelection;

if (occupies) {
entitiesInSelection = entityContainer().entitiesFullWithinArea(*_selectedArea);
}
else {
entitiesInSelection = entityContainer().entitiesWithinAndCrossingArea(*_selectedArea);
}
_newSelection.clear();
entitiesInSelection.each< const lc::entity::CADEntity >([&](lc::entity::CADEntity_CSPtr entity) {
auto di = _entityDrawItem[entity->id()];
auto iter = std::find(_selectedDrawables.begin(), _selectedDrawables.end(), di);
_newSelection.push_back(di);
di->selected(!entity || iter == _selectedDrawables.end());
//if not found in selected drawables
if (iter==_selectedDrawables.end()){
_newSelection.push_back(di);
di->selected(true);
}else{
// if already seen as selected, unselect
di->selected(false);
}
//@TODO: else remove from _selectedDrawables if code is required

//di->selected(!entity || iter == _selectedDrawables.end());
// why this check?
});
}

Expand All @@ -571,13 +581,10 @@ void DocumentCanvas::makeSelectionDevice(LcPainter& painter, unsigned int x, uns
void DocumentCanvas::closeSelection() {
for(const auto& drawable: _newSelection) {
auto iter = std::find(_selectedDrawables.begin(), _selectedDrawables.end(), drawable);
if(iter != _selectedDrawables.end()) {
drawable->selected(false);
_selectedDrawables.erase(iter);
}
else {
drawable->selected(true);
if(iter == _selectedDrawables.end()) {
_selectedDrawables.push_back(drawable);
}else{
_selectedDrawables.erase(iter);
}
};

Expand Down Expand Up @@ -615,9 +622,11 @@ void DocumentCanvas::inverseSelection() {

entityContainer().each< const lc::entity::CADEntity >([&](lc::entity::CADEntity_CSPtr entity) {
lc::viewer::LCVDrawItem_SPtr item = _entityDrawItem[entity->id()];
if (item->selected())
auto iter = std::find(_selectedDrawables.begin(), _selectedDrawables.end(), item);
if (iter != _selectedDrawables.end())
{
item->selected(false);
_selectedDrawables.erase(iter);
}
else
{
Expand Down Expand Up @@ -780,7 +789,16 @@ void DocumentCanvas::selectPoint(double x, double y) {
lc::geo::Area selectionArea(lc::geo::Coordinate(x - w, y - w), w * 2, w * 2);
auto entities = entityContainer().entitiesWithinAndCrossingAreaFast(selectionArea);
entities.each< const lc::entity::CADEntity >([=](lc::entity::CADEntity_CSPtr entity) {
_entityDrawItem[entity->id()]->selected(!_entityDrawItem[entity->id()]->selected());
auto di = _entityDrawItem[entity->id()];
auto iter = std::find(_selectedDrawables.begin(), _selectedDrawables.end(), di);
//if not found in selected drawables
if (iter==_selectedDrawables.end()){
di->selected(true);
_selectedDrawables.push_back(di);
}else{
di->selected(false);
_selectedDrawables.erase(iter);
}
});
}

Expand Down

0 comments on commit 7f84584

Please sign in to comment.