Permalink
Browse files

Remove entities from selection when reselected

  • Loading branch information...
feragon committed May 31, 2016
1 parent 73347ed commit 7375701aea112f2c86c5217896c0f45c212686f7
Showing with 45 additions and 5 deletions.
  1. +36 −5 lcviewernoqt/documentcanvas.cpp
  2. +7 −0 lcviewernoqt/documentcanvas.h
  3. +2 −0 lcviewerqt/lcadviewer.cpp
@@ -454,21 +454,36 @@ void DocumentCanvas::makeSelection(double x, double y, double w, double h, bool
// std::cout << *_selectedArea << std::endl;
_selectedAreaIntersects = occupies;
// Remove current selection
if (!addTo) {
removeSelection();
}
_newSelection.each< LCVDrawItem >([](LCVDrawItem_SPtr di) {
di->selected(false);
});
_selectedEntities.each< LCVDrawItem >([](LCVDrawItem_SPtr di) {
di->selected(true);
});
if (occupies) {
_selectedEntities.combine(_entityContainer.entitiesFullWithinArea(*_selectedArea));
_newSelection = _entityContainer.entitiesFullWithinArea(*_selectedArea);
} else {
_selectedEntities.combine(_entityContainer.entitiesWithinAndCrossingArea(*_selectedArea));
_newSelection = _entityContainer.entitiesWithinAndCrossingArea(*_selectedArea);
}
_selectedEntities.each< LCVDrawItem >([](LCVDrawItem_SPtr di) {
_newSelection.each< LCVDrawItem >([&](LCVDrawItem_SPtr di) {
// std::cerr<< __FILE__ << " : " << __FUNCTION__ << " : " << __LINE__ << " " << typeid(*di).name() << std::endl;
di->selected(true);
auto entity = std::dynamic_pointer_cast<lc::entity::CADEntity>(di);
if(entity && _selectedEntities.entityByID(entity->id()) != nullptr) {
di->selected(false);
}
else {
di->selected(true);
}
});
}
@@ -488,6 +503,22 @@ void DocumentCanvas::makeSelectionDevice(unsigned int x, unsigned int y, unsigne
makeSelection(dx, dy, dw, dh, occupies, addTo);
}
void DocumentCanvas::closeSelection() {
_newSelection.each<lc::entity::CADEntity>([&](lc::entity::CADEntity_SPtr entity) {
auto drawable = std::dynamic_pointer_cast<LCVDrawItem>(entity);
if(_selectedEntities.entityByID(entity->id()) != nullptr) {
_selectedEntities.remove(entity);
drawable->selected(false);
}
else {
_selectedEntities.insert(entity);
drawable->selected(true);
}
});
_newSelection = lc::EntityContainer<lc::entity::CADEntity_SPtr>();
}
void DocumentCanvas::removeSelectionArea() {
if (_selectedArea != nullptr) {
@@ -142,6 +142,12 @@ class DocumentCanvas {
*/
void makeSelectionDevice(unsigned int x, unsigned int y, unsigned int w, unsigned int h, bool occupies, bool addTo = false);
/**
* @brief closeSelection
* appends current selection to document
*/
void closeSelection();
/**
* @brief removeSelectionArea removed the colord selection area from the screen
*/
@@ -241,6 +247,7 @@ class DocumentCanvas {
std::function<void(LcPainter&, lc::geo::Area, bool)> _selectedAreaPainter;
lc::EntityContainer<lc::entity::CADEntity_SPtr> _selectedEntities;
lc::EntityContainer<lc::entity::CADEntity_SPtr> _newSelection;
};
using DocumentCanvas_SPtr = std::shared_ptr<DocumentCanvas>;
@@ -206,6 +206,8 @@ void LCADViewer::mouseReleaseEvent(QMouseEvent *event) {
_dragManager->onMouseRelease();
_docCanvas->closeSelection();
std::vector<lc::EntityDistance> emptyList;
// MouseReleaseEvent e(this, _lastMousePosition, event, emptyList);
// emit mouseReleaseEvent(e);

0 comments on commit 7375701

Please sign in to comment.