Skip to content

Commit

Permalink
Measure: Parse existing selection when command is invoked
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorus committed Jul 2, 2023
1 parent 37aa03c commit 1c167c0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/Gui/TaskMeasure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ TaskMeasure::TaskMeasure(){

Content.push_back(taskbox);

gatherSelection();
attachSelection();
}

Expand Down Expand Up @@ -215,6 +216,31 @@ void TaskMeasure::addElement(const char* mod, const char* obName, const char* su
update();
}

void TaskMeasure::gatherSelection() {
// Fills the selection stack from the global selection and triggers an update

if (!Gui::Selection().hasSelection()) {
return;
}

App::Document* doc = App::GetApplication().getActiveDocument();

for (auto sel : Gui::Selection().getSelection()) {
const char* obName = sel.pObject->getNameInDocument();
App::DocumentObject* ob = doc->getObject(obName);
auto sub = ob->getSubObject(sel.SubName);
std::string mod = sub->getClassTypeId().getModuleName(sub->getTypeId().getName());

if (mod != measureModule){
clearSelection();
}
measureModule = mod;
selection.push_back(std::tuple<std::string, std::string>(obName, sel.SubName));
}

update();
}

void TaskMeasure::removeObject() {
if (_mMeasureObject == nullptr) {
return;
Expand Down
5 changes: 3 additions & 2 deletions src/Gui/TaskMeasure.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TaskMeasure : public TaskView::TaskDialog, public Gui::SelectionObserver {

QColumnView* dialog;
void(*eventCallback)(void*, SoEventCallback*);
App::MeasureElementInfo *elementInfo;
App::MeasureElementInfo *elementInfo = nullptr;

TaskMeasure();
~TaskMeasure();
Expand All @@ -55,7 +55,8 @@ class TaskMeasure : public TaskView::TaskDialog, public Gui::SelectionObserver {

void addElement(const char* mod, const char* obName, const char* subName);
bool hasSelection();
void clearSelection();
void clearSelection();
void gatherSelection();

protected:
App::MeasurementBase *_mMeasureObject = nullptr;
Expand Down

0 comments on commit 1c167c0

Please sign in to comment.