Fem: Remove callback added by filters task box and rework marker classes

This commit is contained in:
marioalexis
2023-10-08 19:01:13 -03:00
committed by wwmayer
parent 019bd50bbc
commit eb73a9bce0
2 changed files with 211 additions and 205 deletions

View File

@@ -71,12 +71,13 @@ using namespace Gui;
// ***************************************************************************
// point marker
PointMarker::PointMarker(Gui::View3DInventorViewer* iv, std::string ObjName)
: view(iv)
PointMarker::PointMarker(Gui::View3DInventorViewer* iv, App::DocumentObject* obj)
: connSelectPoint(QMetaObject::Connection())
, view(iv)
, obj(obj)
, vp(new ViewProviderPointMarker)
{
view->addViewProvider(vp);
m_name = ObjName;
}
PointMarker::~PointMarker()
@@ -89,6 +90,13 @@ void PointMarker::addPoint(const SbVec3f& pt)
{
int ct = countPoints();
vp->pCoords->point.set1Value(ct, pt);
vp->pMarker->numPoints = ct + 1;
}
void PointMarker::clearPoints() const
{
vp->pMarker->numPoints = 0;
vp->pCoords->point.setNum(0);
}
int PointMarker::countPoints() const
@@ -96,32 +104,24 @@ int PointMarker::countPoints() const
return vp->pCoords->point.getNum();
}
void PointMarker::clearPoints() const
SbVec3f PointMarker::getPoint(int idx) const
{
vp->pCoords->point.setNum(0);
return vp->pCoords->point[idx];
}
void PointMarker::customEvent(QEvent*)
void PointMarker::setPoint(int idx, const SbVec3f& pt) const
{
const SbVec3f& pt1 = vp->pCoords->point[0];
const SbVec3f& pt2 = vp->pCoords->point[1];
vp->pCoords->point.set1Value(idx, pt);
}
if (!m_name.empty()) {
Q_EMIT PointsChanged(pt1[0], pt1[1], pt1[2], pt2[0], pt2[1], pt2[2]);
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.Point1 = App.Vector(%f, %f, %f)",
m_name.c_str(),
pt1[0],
pt1[1],
pt1[2]);
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.Point2 = App.Vector(%f, %f, %f)",
m_name.c_str(),
pt2[0],
pt2[1],
pt2[2]);
}
Gui::Command::doCommand(Gui::Command::Doc, ObjectInvisible().c_str());
Gui::View3DInventorViewer* PointMarker::getView() const
{
return view;
}
App::DocumentObject* PointMarker::getObject() const
{
return obj;
}
std::string PointMarker::ObjectInvisible()
@@ -134,88 +134,10 @@ std::string PointMarker::ObjectInvisible()
apart.ViewObject.Visibility = False\n";
}
PROPERTY_SOURCE(FemGui::ViewProviderPointMarker, Gui::ViewProviderDocumentObject)
ViewProviderPointMarker::ViewProviderPointMarker()
{
pCoords = new SoCoordinate3();
pCoords->ref();
pCoords->point.setNum(0);
SoGroup* grp = new SoGroup();
grp->addChild(pCoords);
addDisplayMaskMode(grp, "Base");
setDisplayMaskMode("Base");
}
ViewProviderPointMarker::~ViewProviderPointMarker()
{
pCoords->unref();
}
// ***************************************************************************
// data marker
DataMarker::DataMarker(Gui::View3DInventorViewer* iv, std::string ObjName)
: view(iv)
, vp(new ViewProviderDataMarker)
{
view->addViewProvider(vp);
m_name = ObjName;
}
DataMarker::~DataMarker()
{
view->removeViewProvider(vp);
delete vp;
}
void DataMarker::addPoint(const SbVec3f& pt)
{
int ct = countPoints();
vp->pCoords->point.set1Value(ct, pt);
vp->pMarker->numPoints = ct + 1;
}
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];
if (!m_name.empty()) {
Q_EMIT PointsChanged(pt1[0], pt1[1], pt1[2]);
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.Center = App.Vector(%f, %f, %f)",
m_name.c_str(),
pt1[0],
pt1[1],
pt1[2]);
}
Gui::Command::doCommand(Gui::Command::Doc, ObjectInvisible().c_str());
}
std::string DataMarker::ObjectInvisible()
{
return "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 = False\n";
}
PROPERTY_SOURCE(FemGui::ViewProviderDataMarker, Gui::ViewProviderDocumentObject)
ViewProviderDataMarker::ViewProviderDataMarker()
{
pCoords = new SoCoordinate3();
pCoords->ref();
@@ -236,13 +158,63 @@ ViewProviderDataMarker::ViewProviderDataMarker()
setDisplayMaskMode("Base");
}
ViewProviderDataMarker::~ViewProviderDataMarker()
ViewProviderPointMarker::~ViewProviderPointMarker()
{
pCoords->unref();
pMarker->unref();
}
// ***************************************************************************
// DataAlongLine marker
DataAlongLineMarker::DataAlongLineMarker(Gui::View3DInventorViewer* iv,
Fem::FemPostDataAlongLineFilter* obj)
: PointMarker(iv, obj)
{}
void DataAlongLineMarker::customEvent(QEvent*)
{
const SbVec3f& pt1 = getPoint(0);
const SbVec3f& pt2 = getPoint(1);
Q_EMIT PointsChanged(pt1[0], pt1[1], pt1[2], pt2[0], pt2[1], pt2[2]);
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.Point1 = App.Vector(%f, %f, %f)",
getObject()->getNameInDocument(),
pt1[0],
pt1[1],
pt1[2]);
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.Point2 = App.Vector(%f, %f, %f)",
getObject()->getNameInDocument(),
pt2[0],
pt2[1],
pt2[2]);
Gui::Command::doCommand(Gui::Command::Doc, ObjectInvisible().c_str());
}
// ***************************************************************************
// 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,
@@ -602,7 +574,15 @@ TaskPostDataAlongLine::TaskPostDataAlongLine(ViewProviderDocumentObject* view, Q
updateEnumerationList(getTypedView<ViewProviderFemPostObject>()->VectorMode, ui->VectorMode);
}
TaskPostDataAlongLine::~TaskPostDataAlongLine() = default;
TaskPostDataAlongLine::~TaskPostDataAlongLine()
{
if (marker && marker->getView()) {
marker->getView()->setEditing(false);
marker->getView()->removeEventCallback(SoMouseButtonEvent::getClassTypeId(),
pointCallback,
marker);
}
}
void TaskPostDataAlongLine::setupConnectionsStep1()
{
@@ -688,28 +668,32 @@ static const char* cursor_triangle[] = {"32 17 3 1",
void TaskPostDataAlongLine::onSelectPointsClicked()
{
Gui::Command::doCommand(Gui::Command::Doc, ObjectVisible().c_str());
Gui::Document* doc = Gui::Application::Instance->getDocument(getDocument());
Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());
auto view = static_cast<Gui::View3DInventor*>(getView()->getDocument()->getActiveView());
if (view) {
Gui::View3DInventorViewer* viewer = view->getViewer();
viewer->setEditing(true);
viewer->setEditingCursor(QCursor(QPixmap(cursor_triangle), 7, 7));
// 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);
// Derives from QObject and we have a parent object, so we don't
// require a delete.
auto obj = static_cast<Fem::FemPostDataAlongLineFilter*>(getObject());
marker = new DataAlongLineMarker(viewer, obj);
marker->setParent(this);
}
else if (marker->countPoints() == 2) {
else if (marker->countPoints()) {
marker->clearPoints();
}
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
FemGui::TaskPostDataAlongLine::pointCallback,
marker);
connect(marker, &PointMarker::PointsChanged, this, &TaskPostDataAlongLine::onChange);
if (!marker->connSelectPoint) {
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
TaskPostDataAlongLine::pointCallback,
marker);
marker->connSelectPoint = connect(marker,
&DataAlongLineMarker::PointsChanged,
this,
&TaskPostDataAlongLine::onChange);
}
}
}
@@ -764,18 +748,34 @@ void TaskPostDataAlongLine::onChange(double x1,
ui->point2Y->blockSignals(false);
ui->point2Z->blockSignals(false);
point2Changed(0.0);
if (marker && marker->getView()) {
// leave mode
marker->getView()->setEditing(false);
marker->getView()->removeEventCallback(SoMouseButtonEvent::getClassTypeId(),
TaskPostDataAlongLine::pointCallback,
marker);
disconnect(marker->connSelectPoint);
}
}
void TaskPostDataAlongLine::point1Changed(double)
{
try {
SbVec3f vec(ui->point1X->value().getValue(),
ui->point1Y->value().getValue(),
ui->point1Z->value().getValue());
std::string ObjName = getObject()->getNameInDocument();
Gui::cmdAppDocumentArgs(getDocument(),
"%s.Point1 = App.Vector(%f, %f, %f)",
ObjName,
ui->point1X->value().getValue(),
ui->point1Y->value().getValue(),
ui->point1Z->value().getValue());
vec[0],
vec[1],
vec[2]);
if (marker && marker->countPoints() > 0) {
marker->setPoint(0, vec);
}
// recompute the feature to fill all fields with data at this point
getObject()->recomputeFeature();
@@ -793,13 +793,20 @@ void TaskPostDataAlongLine::point1Changed(double)
void TaskPostDataAlongLine::point2Changed(double)
{
try {
SbVec3f vec(ui->point2X->value().getValue(),
ui->point2Y->value().getValue(),
ui->point2Z->value().getValue());
std::string ObjName = getObject()->getNameInDocument();
Gui::cmdAppDocumentArgs(getDocument(),
"%s.Point2 = App.Vector(%f, %f, %f)",
ObjName,
ui->point2X->value().getValue(),
ui->point2Y->value().getValue(),
ui->point2Z->value().getValue());
vec[0],
vec[1],
vec[2]);
if (marker && marker->countPoints() > 1) {
marker->setPoint(1, vec);
}
// recompute the feature to fill all fields with data at this point
getObject()->recomputeFeature();
@@ -850,16 +857,16 @@ void TaskPostDataAlongLine::pointCallback(void* ud, SoEventCallback* n)
if (pm->countPoints() == 2) {
QEvent* e = new QEvent(QEvent::User);
QApplication::postEvent(pm, e);
// leave mode
view->setEditing(false);
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), pointCallback, ud);
}
}
else if (mbe->getButton() != SoMouseButtonEvent::BUTTON1
&& mbe->getState() == SoButtonEvent::UP) {
n->setHandled();
view->setEditing(false);
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), pointCallback, ud);
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(),
TaskPostDataAlongLine::pointCallback,
ud);
disconnect(pm->connSelectPoint);
}
}
@@ -981,6 +988,12 @@ TaskPostDataAtPoint::~TaskPostDataAtPoint()
if (doc) {
doc->recompute();
}
if (marker && marker->getView()) {
marker->getView()->setEditing(false);
marker->getView()->removeEventCallback(SoMouseButtonEvent::getClassTypeId(),
pointCallback,
marker);
}
}
void TaskPostDataAtPoint::setupConnections()
@@ -998,51 +1011,32 @@ void TaskPostDataAtPoint::setupConnections()
void TaskPostDataAtPoint::applyPythonCode()
{}
static const char* cursor_star[] = {"32 17 3 1",
" c None",
". c #FFFFFF",
"+ c #FF0000",
" . ",
" . ",
" . ",
" . ",
" . ",
" ",
"..... ..... ",
" ",
" . ",
" . ",
" . ++ ",
" . + + ",
" . + ++ + ",
" + ++++ + ",
" + ++ ++ + ",
" + ++++++++ + ",
" ++ ++ ++ ++ "};
void TaskPostDataAtPoint::onSelectPointClicked()
{
Gui::Command::doCommand(Gui::Command::Doc, ObjectVisible().c_str());
Gui::Document* doc = Gui::Application::Instance->getDocument(getDocument());
Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());
auto view = static_cast<Gui::View3DInventor*>(getView()->getDocument()->getActiveView());
if (view) {
Gui::View3DInventorViewer* viewer = view->getViewer();
viewer->setEditing(true);
viewer->setEditingCursor(QCursor(QPixmap(cursor_star), 7, 7));
// Derives from QObject and we have a parent object, so we don't
// require a delete.
std::string ObjName = getObject()->getNameInDocument();
viewer->setEditingCursor(QCursor(QPixmap(cursor_triangle), 7, 7));
if (!marker) {
marker = new FemGui::DataMarker(viewer, ObjName);
// 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);
}
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
FemGui::TaskPostDataAtPoint::pointCallback,
marker);
connect(marker, &DataMarker::PointsChanged, this, &TaskPostDataAtPoint::onChange);
if (!marker->connSelectPoint) {
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
TaskPostDataAtPoint::pointCallback,
marker);
marker->connSelectPoint = connect(marker,
&DataAtPointMarker::PointsChanged,
this,
&TaskPostDataAtPoint::onChange);
}
}
getTypedView<ViewProviderFemPostObject>()->DisplayMode.setValue(1);
updateEnumerationList(getTypedView<ViewProviderFemPostObject>()->Field, ui->Field);
@@ -1060,7 +1054,6 @@ std::string TaskPostDataAtPoint::ObjectVisible()
void TaskPostDataAtPoint::onChange(double x, double y, double z)
{
// call centerChanged only once
ui->centerX->blockSignals(true);
ui->centerY->blockSignals(true);
@@ -1072,6 +1065,14 @@ void TaskPostDataAtPoint::onChange(double x, double y, double z)
ui->centerY->blockSignals(false);
ui->centerZ->blockSignals(false);
centerChanged(0.0);
if (marker && marker->getView()) {
// leave mode
marker->getView()->setEditing(false);
marker->getView()->removeEventCallback(SoMouseButtonEvent::getClassTypeId(),
TaskPostDataAtPoint::pointCallback,
marker);
disconnect(marker->connSelectPoint);
}
}
void TaskPostDataAtPoint::centerChanged(double)
@@ -1085,6 +1086,12 @@ 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
@@ -1100,7 +1107,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());
DataMarker* pm = static_cast<DataMarker*>(ud);
PointMarker* pm = static_cast<PointMarker*>(ud);
// Mark all incoming mouse button events as handled, especially,
// to deactivate the selection node
@@ -1121,18 +1128,19 @@ void TaskPostDataAtPoint::pointCallback(void* ud, SoEventCallback* n)
else {
pm->setPoint(0, point->getPoint());
}
QEvent* e = new QEvent(QEvent::User);
QApplication::postEvent(pm, e);
// leave mode
view->setEditing(false);
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), pointCallback, ud);
}
}
else if (mbe->getButton() != SoMouseButtonEvent::BUTTON1
&& mbe->getState() == SoButtonEvent::UP) {
n->setHandled();
view->setEditing(false);
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), pointCallback, ud);
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(),
TaskPostDataAtPoint::pointCallback,
ud);
disconnect(pm->connSelectPoint);
}
}

View File

@@ -50,6 +50,11 @@ class SoIndexedLineSet;
class SoEventCallback;
class SoMarkerSet;
namespace Fem
{
class FemPostDataAlongLineFilter;
class FemPostDataAtPointFilter;
} // namespace Fem
namespace FemGui
{
@@ -62,26 +67,28 @@ class PointMarker: public QObject
Q_OBJECT
public:
PointMarker(Gui::View3DInventorViewer* view, std::string ObjName);
PointMarker(Gui::View3DInventorViewer* view, App::DocumentObject* obj);
~PointMarker() override;
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);
int countPoints() const;
SbVec3f getPoint(int idx) const;
void setPoint(int idx, const SbVec3f& pt) const;
Gui::View3DInventorViewer* getView() const;
App::DocumentObject* getObject() const;
QMetaObject::Connection connSelectPoint;
protected:
void customEvent(QEvent* e) override;
std::string ObjectInvisible();
private:
Gui::View3DInventorViewer* view;
App::DocumentObject* obj;
ViewProviderPointMarker* vp;
std::string m_name;
std::string ObjectInvisible();
};
class FemGuiExport ViewProviderPointMarker: public Gui::ViewProviderDocumentObject
{
PROPERTY_HEADER_WITH_OVERRIDE(FemGui::ViewProviderPointMarker);
@@ -92,51 +99,42 @@ public:
protected:
SoCoordinate3* pCoords;
SoMarkerSet* pMarker;
friend class PointMarker;
};
// ***************************************************************************
// data marker
class ViewProviderDataMarker;
class DataMarker: public QObject
// DataAlongLine markers
class DataAlongLineMarker: public PointMarker
{
Q_OBJECT
public:
DataMarker(Gui::View3DInventorViewer* view, std::string ObjName);
~DataMarker() override;
DataAlongLineMarker(Gui::View3DInventorViewer* view, Fem::FemPostDataAlongLineFilter* obj);
void addPoint(const SbVec3f&);
int countPoints() const;
void setPoint(int idx, const SbVec3f& pt) const;
Q_SIGNALS:
void PointsChanged(double x1, double y1, double z1, double x2, double y2, double z2);
protected:
void customEvent(QEvent* e) override;
};
// ***************************************************************************
// 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;
private:
Gui::View3DInventorViewer* view;
ViewProviderDataMarker* vp;
std::string m_name;
std::string ObjectInvisible();
};
class FemGuiExport ViewProviderDataMarker: public Gui::ViewProviderDocumentObject
{
PROPERTY_HEADER_WITH_OVERRIDE(FemGui::ViewProviderDataMarker);
public:
ViewProviderDataMarker();
~ViewProviderDataMarker() override;
protected:
SoCoordinate3* pCoords;
SoMarkerSet* pMarker;
friend class DataMarker;
};
@@ -318,7 +316,7 @@ private:
std::string ObjectVisible();
QWidget* proxy;
std::unique_ptr<Ui_TaskPostDataAlongLine> ui;
PointMarker* marker;
DataAlongLineMarker* marker;
};
@@ -348,7 +346,7 @@ private:
std::string ObjectVisible();
QWidget* proxy;
std::unique_ptr<Ui_TaskPostDataAtPoint> ui;
DataMarker* marker;
DataAtPointMarker* marker;
};