Skip to content

Commit

Permalink
Updated GUIViewObjectsHandler. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent 15ea309 commit 6dfb145
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/utils/geom/Boundary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ Boundary::crosses(const Position& p1, const Position& p2) const {

double
Boundary::contains(const Boundary& b) const {
if ((myXmin >= b.xmin()) && (myYmin >= b.ymin()) &&
(myXmax <= b.xmax()) && (myYmax <= b.ymax())) {
if ((myXmin <= b.xmin()) && (myYmin <= b.ymin()) &&
(myXmax >= b.xmax()) && (myYmax >= b.ymax())) {
return true;
} else {
return false;
Expand Down
32 changes: 14 additions & 18 deletions src/utils/gui/div/GUIViewObjectsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ GUIViewObjectsHandler::checkCircleElement(const GUIVisualizationSettings::Detail
b.grow(radius);
// check if boundary overlaps
if (mySelectionBoundary.overlapsWith(b)) {
return addElementUnderCursor(GLObject);
return addElementUnderCursor(GLObject, false);
} else {
// get shape associated with SelectionBoundary
const auto boundaryVertices = mySelectionBoundary.getShape(false);
// check the four vertex
for (const auto &vertex : boundaryVertices) {
if (vertex.distanceSquaredTo2D(center) <= squaredRadius) {
return addElementUnderCursor(GLObject);
return addElementUnderCursor(GLObject, false);
}
}
// no intersection, then return false
Expand All @@ -100,15 +100,15 @@ GUIViewObjectsHandler::checkCircleElement(const GUIVisualizationSettings::Detail
} else {
// check if center is within mySelectionBoundary
if (mySelectionBoundary.around(center)) {
return addElementUnderCursor(GLObject);
return addElementUnderCursor(GLObject, false);
} else {
return false;
}
}
} else if (mySelectionPosition != Position::INVALID) {
// check distance between selection position and center
if (mySelectionPosition.distanceSquaredTo2D(center) <= squaredRadius) {
return addElementUnderCursor(GLObject);
return addElementUnderCursor(GLObject, false);
} else {
return false;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ GUIViewObjectsHandler::checkGeometryPoint(const GUIVisualizationSettings::Detail
} else {
// check if center is within mySelectionBoundary
if (mySelectionBoundary.around(center)) {
return addElementUnderCursor(GLObject);
return addElementUnderCursor(GLObject, false);
} else {
return false;
}
Expand Down Expand Up @@ -190,26 +190,22 @@ GUIViewObjectsHandler::checkShapeElement(const GUIVisualizationSettings::Detail
const PositionVector &shape) {
// continue depending if we're selecting a position or a boundary
if (mySelectionBoundary.isInitialised()) {
// first check if centering boundary is within selection boundary
const auto centeringBoundary = GLObject->getCenteringBoundary();
if ((centeringBoundary.xmin() >= mySelectionBoundary.xmin()) &&
(centeringBoundary.ymin() >= mySelectionBoundary.ymin()) &&
(centeringBoundary.xmax() <= mySelectionBoundary.xmax()) &&
(centeringBoundary.ymax() <= mySelectionBoundary.ymax())) {
return addElementUnderCursor(GLObject);
// first check if selection boundary contains the centering boundary of object
if (mySelectionBoundary.contains(GLObject->getCenteringBoundary())) {
return addElementUnderCursor(GLObject, true);
}
// check if shape crosses to selection boundary
for (int i = 1; i < shape.size(); i++) {
if (mySelectionBoundary.crosses(shape[i-1], shape[i])) {
return addElementUnderCursor(GLObject);
return addElementUnderCursor(GLObject, false);
}
}
// no intersection, then return false
return false;
} else if (mySelectionPosition != Position::INVALID) {
// check if selection position is around shape
if (shape.around(mySelectionPosition)) {
return addElementUnderCursor(GLObject);
return addElementUnderCursor(GLObject, false);
} else {
return false;
}
Expand Down Expand Up @@ -279,7 +275,7 @@ GUIViewObjectsHandler::updateFrontElement(const GUIGlObject* GLObject) {


bool
GUIViewObjectsHandler::addElementUnderCursor(const GUIGlObject* GLObject) {
GUIViewObjectsHandler::addElementUnderCursor(const GUIGlObject* GLObject, const bool fullBoundary) {
// avoid to insert duplicated elements
if (isElementSelected(GLObject)) {
return false;
Expand All @@ -293,7 +289,7 @@ GUIViewObjectsHandler::addElementUnderCursor(const GUIGlObject* GLObject) {
auto &layerContainer = myElementsUnderCursor[GLObject->getType() * -1];
layerContainer.insert(layerContainer.begin(), ObjectContainer(GLObject));
}
mySelectedObjets.insert(GLObject);
mySelectedObjets[GLObject] = fullBoundary;
return true;
}
}
Expand Down Expand Up @@ -328,7 +324,7 @@ GUIViewObjectsHandler::addGeometryPointUnderCursor(const GUIGlObject* GLObject,
auto it = layerContainer.insert(layerContainer.begin(), ObjectContainer(GLObject));
it->geometryPoints.push_back(newIndex);
}
mySelectedObjets.insert(GLObject);
mySelectedObjets[GLObject] = false;
return true;
}

Expand Down Expand Up @@ -359,7 +355,7 @@ GUIViewObjectsHandler::addPositionOverShape(const GUIGlObject* GLObject, const P
auto it = layerContainer.insert(layerContainer.begin(), ObjectContainer(GLObject));
it->posOverShape = pos;
}
mySelectedObjets.insert(GLObject);
mySelectedObjets[GLObject] = false;
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils/gui/div/GUIViewObjectsHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ class GUIViewObjectsHandler {
/// @brief elements under cursor and their geometry point indexes sorted from top to bot
GLObjectsSortedContainer myElementsUnderCursor;

/// @brief set with selected elements (used only to avoid double seletions)
std::set<const GUIGlObject*> mySelectedObjets;
/// @brief map with selected elements and if was selected with full boundary (used only to avoid double seletions)
std::map<const GUIGlObject*, bool> mySelectedObjets;

/// @brief add element into list of elements under cursor
bool addElementUnderCursor(const GUIGlObject* GLObject);
bool addElementUnderCursor(const GUIGlObject* GLObject, const bool fullBoundary);

/// @brief add geometryPoint into list of elements under cursor
bool addGeometryPointUnderCursor(const GUIGlObject* GLObject, const int newIndex);
Expand Down

0 comments on commit 6dfb145

Please sign in to comment.