Skip to content

Commit

Permalink
Fem: Remove unnecessary DataAtPoint marker
Browse files Browse the repository at this point in the history
  • Loading branch information
marioalexis84 authored and wwmayer committed Oct 16, 2023
1 parent 57f71e2 commit e33bd29
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 91 deletions.
104 changes: 33 additions & 71 deletions src/Mod/Fem/Gui/TaskPostBoxes.cpp
Expand Up @@ -194,27 +194,6 @@ void DataAlongLineMarker::customEvent(QEvent*)
}


// ***************************************************************************
// DataAtPoint marker
DataAtPointMarker::DataAtPointMarker(Gui::View3DInventorViewer* iv,
Fem::FemPostDataAtPointFilter* obj)
: PointMarker(iv, obj)
{}

void DataAtPointMarker::customEvent(QEvent*)
{
const SbVec3f& pt1 = getPoint(0);
Q_EMIT PointsChanged(pt1[0], pt1[1], pt1[2]);
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.Center = App.Vector(%f, %f, %f)",
getObject()->getNameInDocument(),
pt1[0],
pt1[1],
pt1[2]);
Gui::Command::doCommand(Gui::Command::Doc, ObjectInvisible().c_str());
}


// ***************************************************************************
// main task dialog
TaskPostBox::TaskPostBox(Gui::ViewProviderDocumentObject* view,
Expand Down Expand Up @@ -931,8 +910,9 @@ TaskPostDataAtPoint::TaskPostDataAtPoint(ViewProviderFemPostDataAtPoint* view, Q
Gui::BitmapFactory().pixmap("FEM_PostFilterDataAtPoint"),
tr("Data at point options"),
parent)
, viewer(nullptr)
, connSelectPoint(QMetaObject::Connection())
, ui(new Ui_TaskPostDataAtPoint)
, marker(nullptr)
{
// we load the views widget
proxy = new QWidget(this);
Expand Down Expand Up @@ -996,11 +976,9 @@ TaskPostDataAtPoint::~TaskPostDataAtPoint()
if (doc) {
doc->recompute();
}
if (marker && marker->getView()) {
marker->getView()->setEditing(false);
marker->getView()->removeEventCallback(SoMouseButtonEvent::getClassTypeId(),
pointCallback,
marker);
if (viewer) {
viewer->setEditing(false);
viewer->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), pointCallback, this);
}
}

Expand All @@ -1021,43 +999,40 @@ void TaskPostDataAtPoint::applyPythonCode()

void TaskPostDataAtPoint::onSelectPointClicked()
{
Gui::Command::doCommand(Gui::Command::Doc, ObjectVisible().c_str());
Gui::Command::doCommand(Gui::Command::Doc, objectVisible(true).c_str());
auto view = static_cast<Gui::View3DInventor*>(getView()->getDocument()->getActiveView());
if (view) {
Gui::View3DInventorViewer* viewer = view->getViewer();
viewer = view->getViewer();
viewer->setEditing(true);
viewer->setEditingCursor(QCursor(QPixmap(cursor_triangle), 7, 7));

if (!marker) {
// Derives from QObject and we have a parent object, so we don't
// require a delete.
auto obj = static_cast<Fem::FemPostDataAtPointFilter*>(getObject());
marker = new DataAtPointMarker(viewer, obj);
marker->setParent(this);
}

if (!marker->connSelectPoint) {
if (!connSelectPoint) {
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
TaskPostDataAtPoint::pointCallback,
marker);
marker->connSelectPoint = connect(marker,
&DataAtPointMarker::PointsChanged,
this,
&TaskPostDataAtPoint::onChange);
this);
connSelectPoint = connect(this,
&TaskPostDataAtPoint::PointsChanged,
this,
&TaskPostDataAtPoint::onChange);
}
}
getTypedView<ViewProviderFemPostObject>()->DisplayMode.setValue(1);
updateEnumerationList(getTypedView<ViewProviderFemPostObject>()->Field, ui->Field);
}

std::string TaskPostDataAtPoint::ObjectVisible()
std::string TaskPostDataAtPoint::objectVisible(bool visible) const
{
return "for amesh in App.activeDocument().Objects:\n\
std::ostringstream oss;
std::string v = visible ? "True" : "False";
oss << "for amesh in App.activeDocument().Objects:\n\
if \"Mesh\" in amesh.TypeId:\n\
aparttoshow = amesh.Name.replace(\"_Mesh\",\"\")\n\
for apart in App.activeDocument().Objects:\n\
if aparttoshow == apart.Name:\n\
apart.ViewObject.Visibility = True\n";
apart.ViewObject.Visibility ="
<< v << "\n";

return oss.str();
}

void TaskPostDataAtPoint::onChange(double x, double y, double z)
Expand All @@ -1073,13 +1048,15 @@ void TaskPostDataAtPoint::onChange(double x, double y, double z)
ui->centerY->blockSignals(false);
ui->centerZ->blockSignals(false);
centerChanged(0.0);
if (marker && marker->getView()) {
Gui::Command::doCommand(Gui::Command::Doc, objectVisible(false).c_str());

if (viewer) {
// leave mode
marker->getView()->setEditing(false);
marker->getView()->removeEventCallback(SoMouseButtonEvent::getClassTypeId(),
TaskPostDataAtPoint::pointCallback,
marker);
disconnect(marker->connSelectPoint);
viewer->setEditing(false);
viewer->removeEventCallback(SoMouseButtonEvent::getClassTypeId(),
TaskPostDataAtPoint::pointCallback,
this);
disconnect(connSelectPoint);
}
}

Expand All @@ -1094,12 +1071,6 @@ void TaskPostDataAtPoint::centerChanged(double)
ui->centerY->value().getValue(),
ui->centerZ->value().getValue());

if (marker && marker->countPoints() == 1) {
SbVec3f vec(ui->centerX->value().getValue(),
ui->centerY->value().getValue(),
ui->centerZ->value().getValue());
marker->setPoint(0, vec);
}
// 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
Expand All @@ -1115,7 +1086,7 @@ void TaskPostDataAtPoint::pointCallback(void* ud, SoEventCallback* n)
{
const SoMouseButtonEvent* mbe = static_cast<const SoMouseButtonEvent*>(n->getEvent());
Gui::View3DInventorViewer* view = static_cast<Gui::View3DInventorViewer*>(n->getUserData());
PointMarker* pm = static_cast<PointMarker*>(ud);
auto taskPost = static_cast<TaskPostDataAtPoint*>(ud);

// Mark all incoming mouse button events as handled, especially,
// to deactivate the selection node
Expand All @@ -1129,17 +1100,8 @@ void TaskPostDataAtPoint::pointCallback(void* ud, SoEventCallback* n)
}

n->setHandled();
if (pm->countPoints() < 2) {
if (pm->countPoints() == 0) {
pm->addPoint(point->getPoint());
}
else {
pm->setPoint(0, point->getPoint());
}

QEvent* e = new QEvent(QEvent::User);
QApplication::postEvent(pm, e);
}
const SbVec3f& pt = point->getPoint();
Q_EMIT taskPost->PointsChanged(pt[0], pt[1], pt[2]);
}
else if (mbe->getButton() != SoMouseButtonEvent::BUTTON1
&& mbe->getState() == SoButtonEvent::UP) {
Expand All @@ -1148,7 +1110,7 @@ void TaskPostDataAtPoint::pointCallback(void* ud, SoEventCallback* n)
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(),
TaskPostDataAtPoint::pointCallback,
ud);
disconnect(pm->connSelectPoint);
disconnect(taskPost->connSelectPoint);
}
}

Expand Down
28 changes: 8 additions & 20 deletions src/Mod/Fem/Gui/TaskPostBoxes.h
Expand Up @@ -122,23 +122,6 @@ class DataAlongLineMarker: public PointMarker
};


// ***************************************************************************
// DataAtPoint markers
class DataAtPointMarker: public PointMarker
{
Q_OBJECT

public:
DataAtPointMarker(Gui::View3DInventorViewer* view, Fem::FemPostDataAtPointFilter* obj);

Q_SIGNALS:
void PointsChanged(double x, double y, double z);

protected:
void customEvent(QEvent* e) override;
};


// ***************************************************************************
// main task dialog
class TaskPostBox: public Gui::TaskView::TaskBox
Expand Down Expand Up @@ -342,20 +325,25 @@ class TaskPostDataAtPoint: public TaskPostBox
void applyPythonCode() override;
static void pointCallback(void* ud, SoEventCallback* n);

Q_SIGNALS:
void PointsChanged(double x, double y, double z);

protected:
Gui::View3DInventorViewer* viewer;
QMetaObject::Connection connSelectPoint;

private:
void setupConnections();
void onSelectPointClicked();
void onFieldActivated(int i);
void centerChanged(double);
void onChange(double x, double y, double z);

private:
std::string toString(double val) const;
void showValue(double value, const char* unit);
std::string ObjectVisible();
std::string objectVisible(bool visible) const;
QWidget* proxy;
std::unique_ptr<Ui_TaskPostDataAtPoint> ui;
DataAtPointMarker* marker;
};


Expand Down

0 comments on commit e33bd29

Please sign in to comment.