Fem: do not access the active document but the document the FEM post object is part of

This commit is contained in:
wmayer
2022-06-13 16:46:15 +02:00
parent c0cccf7f7e
commit 7b225789da
2 changed files with 87 additions and 43 deletions

View File

@@ -40,7 +40,7 @@
#include <Gui/Action.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/CommandT.h>
#include <Gui/Document.h>
#include <Gui/MainWindow.h>
#include <Gui/View3DInventor.h>
@@ -253,7 +253,7 @@ void TaskDlgPost::open()
void TaskDlgPost::clicked(int button)
{
if (button == QDialogButtonBox::Apply)
getView()->getObject()->getDocument()->recompute();
recompute();
}
bool TaskDlgPost::accept()
@@ -268,7 +268,7 @@ bool TaskDlgPost::accept()
return false;
}
Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeDocument().resetEdit()");
Gui::cmdGuiDocument(getDocumentName(), "resetEdit()");
return true;
}
@@ -276,11 +276,19 @@ bool TaskDlgPost::reject()
{
// roll back the done things
Gui::Command::abortCommand();
Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeDocument().resetEdit()");
Gui::cmdGuiDocument(getDocumentName(), "resetEdit()");
return true;
}
void TaskDlgPost::recompute()
{
Gui::ViewProviderDocumentObject* vp = getView();
if (vp) {
vp->getObject()->getDocument()->recompute();
}
}
void TaskDlgPost::modifyStandardButtons(QDialogButtonBox* box) {
if (box->button(QDialogButtonBox::Apply))
@@ -305,10 +313,18 @@ bool TaskPostBox::autoApply() {
return FemSettings().getPostAutoRecompute();
}
App::Document* TaskPostBox::getDocument() const {
App::DocumentObject* obj = getObject();
return (obj ? obj->getDocument() : nullptr);
}
void TaskPostBox::recompute() {
if (autoApply())
App::GetApplication().getActiveDocument()->recompute();
if (autoApply()) {
App::Document* doc = getDocument();
if (doc)
doc->recompute();
}
}
void TaskPostBox::updateEnumerationList(App::PropertyEnumeration& prop, QComboBox* box) {
@@ -460,7 +476,7 @@ void TaskPostClip::applyPythonCode() {
void TaskPostClip::collectImplicitFunctions() {
std::vector<Fem::FemPostPipeline*> pipelines;
pipelines = App::GetApplication().getActiveDocument()->getObjectsOfType<Fem::FemPostPipeline>();
pipelines = getDocument()->getObjectsOfType<Fem::FemPostPipeline>();
if (!pipelines.empty()) {
Fem::FemPostPipeline* pipeline = pipelines.front();
if (pipeline->Functions.getValue() &&
@@ -505,7 +521,7 @@ void TaskPostClip::on_FunctionBox_currentIndexChanged(int idx) {
//set the correct property
std::vector<Fem::FemPostPipeline*> pipelines;
pipelines = App::GetApplication().getActiveDocument()->getObjectsOfType<Fem::FemPostPipeline>();
pipelines = getDocument()->getObjectsOfType<Fem::FemPostPipeline>();
if (!pipelines.empty()) {
Fem::FemPostPipeline* pipeline = pipelines.front();
if (pipeline->Functions.getValue() &&
@@ -525,7 +541,7 @@ void TaskPostClip::on_FunctionBox_currentIndexChanged(int idx) {
static_cast<Fem::FemPostClipFilter*>(getObject())->Function.getValue());
Gui::ViewProvider* view = nullptr;
if (fobj)
view = Gui::Application::Instance->activeDocument()->getViewProvider(fobj);
view = Gui::Application::Instance->getViewProvider(fobj);
if (fwidget)
fwidget->deleteLater();
@@ -655,7 +671,7 @@ static const char* cursor_triangle[] = {
void TaskPostDataAlongLine::on_SelectPoints_clicked() {
Gui::Command::doCommand(Gui::Command::Doc, ObjectVisible().c_str());
Gui::Document* doc = Gui::Application::Instance->activeDocument();
Gui::Document* doc = Gui::Application::Instance->getDocument(getDocument());
Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());
if (view) {
Gui::View3DInventorViewer* viewer = view->getViewer();
@@ -722,32 +738,46 @@ void TaskPostDataAlongLine::onChange(double x1, double y1, double z1, double x2,
void TaskPostDataAlongLine::point1Changed(double) {
std::string ObjName = getObject()->Label.getValue();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Point1 = App.Vector(%f, %f, %f)", ObjName.c_str(),
ui->point1X->value().getValue(), ui->point1Y->value().getValue(), ui->point1Z->value().getValue());
try {
std::string ObjName = getObject()->Label.getValue();
Gui::cmdAppDocumentArgs(getDocument(), "%s.Point1 = App.Vector(%f, %f, %f)", ObjName,
ui->point1X->value().getValue(),
ui->point1Y->value().getValue(),
ui->point1Z->value().getValue());
// recompute the feature to fill all fields with data at this point
getObject()->recomputeFeature();
// refresh the color bar range
auto currentField = getTypedView<ViewProviderFemPostObject>()->Field.getValue();
getTypedView<ViewProviderFemPostObject>()->Field.setValue(currentField);
// also the axis data must be refreshed to get correct plots
static_cast<Fem::FemPostDataAlongLineFilter*>(getObject())->GetAxisData();
// recompute the feature to fill all fields with data at this point
getObject()->recomputeFeature();
// refresh the color bar range
auto currentField = getTypedView<ViewProviderFemPostObject>()->Field.getValue();
getTypedView<ViewProviderFemPostObject>()->Field.setValue(currentField);
// also the axis data must be refreshed to get correct plots
static_cast<Fem::FemPostDataAlongLineFilter*>(getObject())->GetAxisData();
}
catch (const Base::Exception& e) {
e.ReportException();
}
}
void TaskPostDataAlongLine::point2Changed(double) {
std::string ObjName = getObject()->Label.getValue();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Point2 = App.Vector(%f, %f, %f)", ObjName.c_str(),
ui->point2X->value().getValue(), ui->point2Y->value().getValue(), ui->point2Z->value().getValue());
try {
std::string ObjName = getObject()->Label.getValue();
Gui::cmdAppDocumentArgs(getDocument(), "%s.Point2 = App.Vector(%f, %f, %f)", ObjName,
ui->point2X->value().getValue(),
ui->point2Y->value().getValue(),
ui->point2Z->value().getValue());
// recompute the feature to fill all fields with data at this point
getObject()->recomputeFeature();
// refresh the color bar range
auto currentField = getTypedView<ViewProviderFemPostObject>()->Field.getValue();
getTypedView<ViewProviderFemPostObject>()->Field.setValue(currentField);
// also the axis data must be refreshed to get correct plots
static_cast<Fem::FemPostDataAlongLineFilter*>(getObject())->GetAxisData();
// recompute the feature to fill all fields with data at this point
getObject()->recomputeFeature();
// refresh the color bar range
auto currentField = getTypedView<ViewProviderFemPostObject>()->Field.getValue();
getTypedView<ViewProviderFemPostObject>()->Field.setValue(currentField);
// also the axis data must be refreshed to get correct plots
static_cast<Fem::FemPostDataAlongLineFilter*>(getObject())->GetAxisData();
}
catch (const Base::Exception& e) {
e.what();
}
}
void TaskPostDataAlongLine::resolutionChanged(int val) {
@@ -887,7 +917,9 @@ TaskPostDataAtPoint::TaskPostDataAtPoint(ViewProviderDocumentObject* view, QWidg
}
TaskPostDataAtPoint::~TaskPostDataAtPoint() {
App::GetApplication().getActiveDocument()->recompute();
App::Document* doc = getDocument();
if (doc)
doc->recompute();
}
void TaskPostDataAtPoint::applyPythonCode() {
@@ -920,7 +952,7 @@ static const char* cursor_star[] = {
void TaskPostDataAtPoint::on_SelectPoint_clicked() {
Gui::Command::doCommand(Gui::Command::Doc, ObjectVisible().c_str());
Gui::Document* doc = Gui::Application::Instance->activeDocument();
Gui::Document* doc = Gui::Application::Instance->getDocument(getDocument());
Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());
if (view) {
Gui::View3DInventorViewer* viewer = view->getViewer();
@@ -966,15 +998,22 @@ void TaskPostDataAtPoint::onChange(double x, double y, double z) {
void TaskPostDataAtPoint::centerChanged(double) {
std::string ObjName = getObject()->Label.getValue();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Center = App.Vector(%f, %f, %f)", ObjName.c_str(),
ui->centerX->value().getValue(), ui->centerY->value().getValue(), ui->centerZ->value().getValue());
try {
std::string ObjName = getObject()->Label.getValue();
Gui::cmdAppDocumentArgs(getDocument(), "%s.Center = App.Vector(%f, %f, %f)", ObjName,
ui->centerX->value().getValue(),
ui->centerY->value().getValue(),
ui->centerZ->value().getValue());
// recompute the feature to fill all fields with data at this point
getObject()->recomputeFeature();
// show the data dialog by calling on_Field_activated with the field that is currently set
auto currentField = getTypedView<ViewProviderFemPostObject>()->Field.getValue();
on_Field_activated(currentField);
// recompute the feature to fill all fields with data at this point
getObject()->recomputeFeature();
// show the data dialog by calling on_Field_activated with the field that is currently set
auto currentField = getTypedView<ViewProviderFemPostObject>()->Field.getValue();
on_Field_activated(currentField);
}
catch (const Base::Exception& e) {
e.ReportException();
}
}
void TaskPostDataAtPoint::pointCallback(void* ud, SoEventCallback* n)
@@ -1386,7 +1425,7 @@ void TaskPostCut::applyPythonCode() {
void TaskPostCut::collectImplicitFunctions() {
std::vector<Fem::FemPostPipeline*> pipelines;
pipelines = App::GetApplication().getActiveDocument()->getObjectsOfType<Fem::FemPostPipeline>();
pipelines = getDocument()->getObjectsOfType<Fem::FemPostPipeline>();
if (!pipelines.empty()) {
Fem::FemPostPipeline* pipeline = pipelines.front();
if (pipeline->Functions.getValue() &&
@@ -1431,7 +1470,7 @@ void TaskPostCut::on_FunctionBox_currentIndexChanged(int idx) {
//set the correct property
std::vector<Fem::FemPostPipeline*> pipelines;
pipelines = App::GetApplication().getActiveDocument()->getObjectsOfType<Fem::FemPostPipeline>();
pipelines = getDocument()->getObjectsOfType<Fem::FemPostPipeline>();
if (!pipelines.empty()) {
Fem::FemPostPipeline* pipeline = pipelines.front();
if (pipeline->Functions.getValue() &&
@@ -1451,7 +1490,7 @@ void TaskPostCut::on_FunctionBox_currentIndexChanged(int idx) {
static_cast<Fem::FemPostCutFilter*>(getObject())->Function.getValue());
Gui::ViewProvider* view = nullptr;
if (fobj)
view = Gui::Application::Instance->activeDocument()->getViewProvider(fobj);
view = Gui::Application::Instance->getViewProvider(fobj);
if (fwidget)
fwidget->deleteLater();

View File

@@ -160,6 +160,8 @@ protected:
return m_view.get<T>();
}
App::Document* getDocument() const;
bool autoApply();
void recompute();
@@ -202,6 +204,9 @@ public:
/// returns for Close and Help button
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const;
protected:
void recompute();
protected:
Gui::ViewProviderWeakPtrT m_view;
std::vector<TaskPostBox*> m_boxes;