Fem: Remove markers from scenegraph - fixes #10438

This commit is contained in:
marioalexis
2023-10-06 18:13:13 -03:00
committed by wwmayer
parent 96efff81c7
commit 05e28cf550
2 changed files with 40 additions and 8 deletions

View File

@@ -98,6 +98,11 @@ int PointMarker::countPoints() const
return vp->pCoords->point.getNum();
}
void PointMarker::clearPoints() const
{
vp->pCoords->point.setNum(0);
}
void PointMarker::customEvent(QEvent*)
{
const SbVec3f& pt1 = vp->pCoords->point[0];
@@ -179,6 +184,11 @@ int DataMarker::countPoints() const
return vp->pCoords->point.getNum();
}
void DataMarker::setPoint(int idx, const SbVec3f& pt) const
{
vp->pCoords->point.set1Value(idx, pt);
}
void DataMarker::customEvent(QEvent*)
{
const SbVec3f& pt1 = vp->pCoords->point[0];
@@ -532,6 +542,7 @@ TaskPostDataAlongLine::TaskPostDataAlongLine(ViewProviderDocumentObject* view, Q
tr("Data along a line options"),
parent)
, ui(new Ui_TaskPostDataAlongLine)
, marker(nullptr)
{
assert(view->isDerivedFrom(ViewProviderFemPostDataAlongLine::getClassTypeId()));
@@ -654,7 +665,7 @@ void TaskPostDataAlongLine::setupConnectionsStep2()
void TaskPostDataAlongLine::applyPythonCode()
{}
static const char* cursor_triangle[] = {"32 32 3 1",
static const char* cursor_triangle[] = {"32 17 3 1",
" c None",
". c #FFFFFF",
"+ c #FF0000",
@@ -689,8 +700,14 @@ void TaskPostDataAlongLine::onSelectPointsClicked()
// Derives from QObject and we have a parent object, so we don't
// require a delete.
std::string ObjName = getObject()->getNameInDocument();
if (!marker) {
marker = new FemGui::PointMarker(viewer, ObjName);
marker->setParent(this);
}
else if (marker->countPoints() == 2) {
marker->clearPoints();
}
FemGui::PointMarker* marker = new FemGui::PointMarker(viewer, ObjName);
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
FemGui::TaskPostDataAlongLine::pointCallback,
marker);
@@ -828,7 +845,10 @@ void TaskPostDataAlongLine::pointCallback(void* ud, SoEventCallback* n)
}
n->setHandled();
pm->addPoint(point->getPoint());
if (pm->countPoints() < 2) {
pm->addPoint(point->getPoint());
}
if (pm->countPoints() == 2) {
QEvent* e = new QEvent(QEvent::User);
QApplication::postEvent(pm, e);
@@ -842,7 +862,6 @@ void TaskPostDataAlongLine::pointCallback(void* ud, SoEventCallback* n)
n->setHandled();
view->setEditing(false);
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), pointCallback, ud);
pm->deleteLater();
}
}
@@ -898,6 +917,7 @@ TaskPostDataAtPoint::TaskPostDataAtPoint(ViewProviderDocumentObject* view, QWidg
tr("Data at point options"),
parent)
, ui(new Ui_TaskPostDataAtPoint)
, marker(nullptr)
{
assert(view->isDerivedFrom(ViewProviderFemPostDataAtPoint::getClassTypeId()));
@@ -1016,7 +1036,11 @@ void TaskPostDataAtPoint::onSelectPointClicked()
// require a delete.
std::string ObjName = getObject()->getNameInDocument();
FemGui::DataMarker* marker = new FemGui::DataMarker(viewer, ObjName);
if (!marker) {
marker = new FemGui::DataMarker(viewer, ObjName);
marker->setParent(this);
}
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
FemGui::TaskPostDataAtPoint::pointCallback,
marker);
@@ -1092,8 +1116,13 @@ void TaskPostDataAtPoint::pointCallback(void* ud, SoEventCallback* n)
}
n->setHandled();
pm->addPoint(point->getPoint());
if (pm->countPoints() == 1) {
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);
// leave mode
@@ -1106,7 +1135,6 @@ void TaskPostDataAtPoint::pointCallback(void* ud, SoEventCallback* n)
n->setHandled();
view->setEditing(false);
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), pointCallback, ud);
pm->deleteLater();
}
}

View File

@@ -67,6 +67,7 @@ public:
void addPoint(const SbVec3f&);
int countPoints() const;
void clearPoints() const;
Q_SIGNALS:
void PointsChanged(double x1, double y1, double z1, double x2, double y2, double z2);
@@ -108,6 +109,7 @@ public:
void addPoint(const SbVec3f&);
int countPoints() const;
void setPoint(int idx, const SbVec3f& pt) const;
Q_SIGNALS:
void PointsChanged(double x, double y, double z);
@@ -316,6 +318,7 @@ private:
std::string ObjectVisible();
QWidget* proxy;
std::unique_ptr<Ui_TaskPostDataAlongLine> ui;
PointMarker* marker;
};
@@ -345,6 +348,7 @@ private:
std::string ObjectVisible();
QWidget* proxy;
std::unique_ptr<Ui_TaskPostDataAtPoint> ui;
DataMarker* marker;
};