Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select_mode_normal_append_remove #1470

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion ui/zenoedit/viewport/cameracontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,18 @@ void CameraControl::fakeMouseReleaseEvent(QMouseEvent *event) {
int y0 = m_boundRectStartPos.y();
int x1 = releasePos.x();
int y1 = releasePos.y();
m_picker->pick(x0, y0, x1, y1);
zeno::SELECTION_MODE mode = zeno::SELECTION_MODE::NORMAL;
if (shift_pressed == false && ctrl_pressed == false) {
mode = zeno::SELECTION_MODE::NORMAL;
}
else if (shift_pressed == true && ctrl_pressed == false) {
mode = zeno::SELECTION_MODE::APPEND;
}
else if (shift_pressed == false && ctrl_pressed == true) {
mode = zeno::SELECTION_MODE::REMOVE;
}

m_picker->pick(x0, y0, x1, y1, mode);
m_picker->sync_to_scene();
if (scene->select_mode == zenovis::PICK_MODE::PICK_OBJECT)
onPrimSelected();
Expand Down Expand Up @@ -637,6 +648,12 @@ void CameraControl::fakeMouseReleaseEvent(QMouseEvent *event) {
}

bool CameraControl::fakeKeyPressEvent(int uKey) {
if (uKey & Qt::SHIFT) {
shift_pressed = true;
}
if (uKey & Qt::CTRL) {
ctrl_pressed = true;
}
if (!middle_button_pressed) {
return false;
}
Expand Down Expand Up @@ -684,6 +701,15 @@ bool CameraControl::fakeKeyPressEvent(int uKey) {
}
}

bool CameraControl::fakeKeyReleaseEvent(int uKey) {
if (uKey == Qt::Key_Shift) {
shift_pressed = false;
}
if (uKey == Qt::Key_Control) {
ctrl_pressed = false;
}
return false;
}
//void CameraControl::createPointNode(QPointF pnt) {
//auto pModel = zenoApp->graphsManagment()->currentModel();
//ZASSERT_EXIT(pModel);
Expand Down
3 changes: 3 additions & 0 deletions ui/zenoedit/viewport/cameracontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CameraControl : public QObject
void setKeyFrame();

bool fakeKeyPressEvent(int uKey);
bool fakeKeyReleaseEvent(int uKey);
void fakeMousePressEvent(QMouseEvent* event);
void fakeMouseReleaseEvent(QMouseEvent* event);
void fakeMouseMoveEvent(QMouseEvent* event);
Expand Down Expand Up @@ -66,6 +67,8 @@ class CameraControl : public QObject
Zenovis* m_zenovis;

bool middle_button_pressed = false;
bool shift_pressed = false;
bool ctrl_pressed = false;
};


Expand Down
2 changes: 1 addition & 1 deletion ui/zenoedit/viewport/displaywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ void DisplayWidget::onNodeSelected(const QModelIndex &subgIdx, const QModelIndex
node_context += prim_name + ":" + e.toStdString() + " ";

if (picker)
picker->load_from_str(node_context, scene->select_mode);
picker->load_from_str(node_context, scene->select_mode, zeno::SELECTION_MODE::NORMAL);
}
if (picker) {
picker->sync_to_scene();
Expand Down
5 changes: 5 additions & 0 deletions ui/zenoedit/viewport/viewportwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,9 @@ void ViewportWidget::keyPressEvent(QKeyEvent *event)

void ViewportWidget::keyReleaseEvent(QKeyEvent *event) {
_base::keyReleaseEvent(event);
int uKey = event->key();
if (m_camera->fakeKeyReleaseEvent(uKey)) {
zenoApp->getMainWindow()->updateViewport();
return;
}
}
17 changes: 8 additions & 9 deletions ui/zenoedit/viewportinteraction/picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void Picker::pick(int x, int y) {
// onPrimitiveSelected();
}

void Picker::pick(int x0, int y0, int x1, int y1) {
void Picker::pick(int x0, int y0, int x1, int y1, SELECTION_MODE mode) {
auto scene = this->scene();
ZASSERT_EXIT(scene);
auto selected = picker->getPicked(x0, y0, x1, y1);
Expand All @@ -155,14 +155,10 @@ void Picker::pick(int x0, int y0, int x1, int y1) {
selected_prims.clear();
return;
}
load_from_str(selected, zenovis::PICK_MODE::PICK_OBJECT);
load_from_str(selected, zenovis::PICK_MODE::PICK_OBJECT, SELECTION_MODE::NORMAL);
}
else {
if (selected.empty()) {
selected_elements.clear();
return;
}
load_from_str(selected, scene->select_mode);
load_from_str(selected, scene->select_mode, mode);
if (picked_elems_callback) picked_elems_callback(selected_elements);
}
}
Expand Down Expand Up @@ -201,7 +197,7 @@ void Picker::sync_to_scene() {

}

void Picker::load_from_str(const string& str, zenovis::PICK_MODE mode) {
void Picker::load_from_str(const string& str, zenovis::PICK_MODE mode, SELECTION_MODE sel_mode) {
if (str.empty()) return;
// parse selected string
std::regex reg(" ");
Expand All @@ -215,6 +211,9 @@ void Picker::load_from_str(const string& str, zenovis::PICK_MODE mode) {
}
}
else {
if (sel_mode == SELECTION_MODE::NORMAL) {
selected_elements.clear();
}
while (p != end) {
string result = *p++;
// qDebug() << result.c_str();
Expand All @@ -225,7 +224,7 @@ void Picker::load_from_str(const string& str, zenovis::PICK_MODE mode) {
int elem_id; ss >> elem_id;
if (selected_elements.find(obj_id) != selected_elements.end()) {
auto &elements = selected_elements[obj_id];
if (elements.count(elem_id) > 0)
if (sel_mode == SELECTION_MODE::REMOVE)
elements.erase(elem_id);
else
elements.insert(elem_id);
Expand Down
10 changes: 8 additions & 2 deletions ui/zenoedit/viewportinteraction/picker.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class ViewportWidget;

namespace zeno {

enum class SELECTION_MODE {
NORMAL,
APPEND,
REMOVE,
};

std::optional<float> ray_box_intersect(
zeno::vec3f const &bmin,
zeno::vec3f const &bmax,
Expand All @@ -38,14 +44,14 @@ class Picker
Picker(ViewportWidget* pViewport);
void initialize();
void pick(int x, int y);
void pick(int x0, int y0, int x1, int y1);
void pick(int x0, int y0, int x1, int y1, SELECTION_MODE mode = SELECTION_MODE::NORMAL);
void pick_depth(int x, int y);
void add(const std::string& prim_name);
std::string just_pick_prim(int x, int y);
const std::unordered_set<std::string>& get_picked_prims();
const std::unordered_map<std::string, std::unordered_set<int>>& get_picked_elems();
void sync_to_scene();
void load_from_str(const std::string& str, zenovis::PICK_MODE mode);
void load_from_str(const std::string& str, zenovis::PICK_MODE mode, SELECTION_MODE sel_mode);
std::string save_to_str(zenovis::PICK_MODE mode);
void save_context();
void load_context();
Expand Down
Loading