diff --git a/src/Mod/Fem/App/AppFem.cpp b/src/Mod/Fem/App/AppFem.cpp index f70df02c0..96d025287 100644 --- a/src/Mod/Fem/App/AppFem.cpp +++ b/src/Mod/Fem/App/AppFem.cpp @@ -162,7 +162,7 @@ PyMODINIT_FUNC initFem() Fem::ConstraintContact ::init(); Fem::ConstraintFluidBoundary ::init(); Fem::ConstraintTransform ::init(); - + Fem::FemResultObject ::init(); Fem::FemResultObjectPython ::init(); Fem::FemSolverObject ::init(); @@ -173,6 +173,7 @@ PyMODINIT_FUNC initFem() Fem::FemPostPipeline ::init(); Fem::FemPostFilter ::init(); Fem::FemPostClipFilter ::init(); + Fem::FemPostDataAlongLineFilter ::init(); Fem::FemPostScalarClipFilter ::init(); Fem::FemPostWarpVectorFilter ::init(); Fem::FemPostCutFilter ::init(); diff --git a/src/Mod/Fem/App/FemPostFilter.cpp b/src/Mod/Fem/App/FemPostFilter.cpp index cbf900035..dbc0a2951 100644 --- a/src/Mod/Fem/App/FemPostFilter.cpp +++ b/src/Mod/Fem/App/FemPostFilter.cpp @@ -68,12 +68,21 @@ void FemPostFilter::setActiveFilterPipeline(std::string name) { DocumentObjectExecReturn* FemPostFilter::execute(void) { if(!m_pipelines.empty() && !m_activePipeline.empty()) { - FemPostFilter::FilterPipeline& pipe = m_pipelines[m_activePipeline]; - pipe.source->SetInputDataObject(getInputData()); - pipe.target->Update(); + if (m_activePipeline.length() >= 13) { + std::string LineClip = m_activePipeline.substr(0,13); + if (LineClip == "DataAlongLine") { + pipe.filterSource->SetSourceData(getInputData()); + pipe.filterTarget->Update(); + + Data.setValue(pipe.filterTarget->GetOutputDataObject(0)); + } + } else { + pipe.source->SetInputDataObject(getInputData()); + pipe.target->Update(); + Data.setValue(pipe.target->GetOutputDataObject(0)); + } - Data.setValue(pipe.target->GetOutputDataObject(0)); } return StdReturn; } @@ -171,6 +180,121 @@ DocumentObjectExecReturn* FemPostClipFilter::execute(void) { return Fem::FemPostFilter::execute(); } +PROPERTY_SOURCE(Fem::FemPostDataAlongLineFilter, Fem::FemPostFilter) + +FemPostDataAlongLineFilter::FemPostDataAlongLineFilter(void) : FemPostFilter() { + + ADD_PROPERTY_TYPE(Point1,(Base::Vector3d(0.0,0.0,0.0)), "DataAlongLine", App::Prop_None, "The point 1 used to define end point of line"); + ADD_PROPERTY_TYPE(Point2,(Base::Vector3d(0.0,0.0,1.0)), "DataAlongLine", App::Prop_None, "The point 2 used to define end point of line"); + ADD_PROPERTY_TYPE(Resolution,(100), "DataAlongLine", App::Prop_None, "The number of intervals between the 2 end points of line"); + ADD_PROPERTY_TYPE(XAxisData,(0), "DataAlongLine",App::Prop_None,"X axis data values used for plotting"); + ADD_PROPERTY_TYPE(YAxisData,(0), "DataAlongLine",App::Prop_None,"Y axis data values used for plotting"); + ADD_PROPERTY_TYPE(PlotData ,(""),"DataAlongLine",App::Prop_None,"Field used for plotting"); + + PlotData.setStatus(App::Property::ReadOnly, true); + XAxisData.setStatus(App::Property::ReadOnly, true); + YAxisData.setStatus(App::Property::ReadOnly, true); + + FilterPipeline clip; + + m_line = vtkSmartPointer::New(); + const Base::Vector3d& vec1 = Point1.getValue(); + m_line->SetPoint1(vec1.x, vec1.y, vec1.z); + const Base::Vector3d& vec2 = Point2.getValue(); + m_line->SetPoint2(vec2.x, vec2.y, vec2.z); + m_line->SetResolution(Resolution.getValue()); + + + m_probe = vtkSmartPointer::New(); + m_probe->SetInputConnection(m_line->GetOutputPort()); + m_probe->SetValidPointMaskArrayName("ValidPointArray"); + m_probe->SetPassPointArrays(1); + m_probe->SetPassCellArrays(1); + m_probe->ComputeToleranceOff(); + m_probe->SetTolerance(0.01); + + clip.filterSource = m_probe; + clip.filterTarget = m_probe; + + addFilterPipeline(clip, "DataAlongLine"); + setActiveFilterPipeline("DataAlongLine"); +} + +FemPostDataAlongLineFilter::~FemPostDataAlongLineFilter() { + +} + +DocumentObjectExecReturn* FemPostDataAlongLineFilter::execute(void) { + + //recalculate the filter + return Fem::FemPostFilter::execute(); +} + + +void FemPostDataAlongLineFilter::onChanged(const Property* prop) { + if(prop == &Point1) { + const Base::Vector3d& vec1 = Point1.getValue(); + m_line->SetPoint1(vec1.x, vec1.y, vec1.z); + } + else if(prop == &Point2) { + const Base::Vector3d& vec2 = Point2.getValue(); + m_line->SetPoint2(vec2.x, vec2.y, vec2.z); + } + else if(prop == &Resolution) { + m_line->SetResolution(Resolution.getValue()); + } + else if(prop == &PlotData) { + GetAxisData(); + } + Fem::FemPostFilter::onChanged(prop); +} + +short int FemPostDataAlongLineFilter::mustExecute(void) const { + + if(Point1.isTouched() || + Point2.isTouched() || + Resolution.isTouched()){ + + return 1; + } + else return App::DocumentObject::mustExecute(); +} + +void FemPostDataAlongLineFilter::GetAxisData() { + + std::vector coords; + std::vector values; + + vtkSmartPointer data = m_probe->GetOutputDataObject(0); + vtkDataSet* dset = vtkDataSet::SafeDownCast(data); + vtkDataArray* pdata = dset->GetPointData()->GetArray(PlotData.getValue()); + vtkDataArray *tcoords = dset->GetPointData()->GetTCoords("Texture Coordinates"); + + int component = 0; + + const Base::Vector3d& vec1 = Point1.getValue(); + const Base::Vector3d& vec2 = Point2.getValue(); + const Base::Vector3d diff = vec1 - vec2; + double Len = diff.Length(); + + for(int i=0; iGetNumberOfPoints(); ++i) { + + double value = 0; + if(pdata->GetNumberOfComponents() == 1) + value = pdata->GetComponent(i, component); + else { + for(int j=0; jGetNumberOfComponents(); ++j) + value += std::pow(pdata->GetComponent(i, j),2); + + value = std::sqrt(value); + } + values.push_back(value); + double tcoord = tcoords->GetComponent(i, component); + coords.push_back(tcoord*Len); + } + YAxisData.setValues(values); + XAxisData.setValues(coords); +} PROPERTY_SOURCE(Fem::FemPostScalarClipFilter, Fem::FemPostFilter) diff --git a/src/Mod/Fem/App/FemPostFilter.h b/src/Mod/Fem/App/FemPostFilter.h index 52d59ffcb..b2e59377a 100644 --- a/src/Mod/Fem/App/FemPostFilter.h +++ b/src/Mod/Fem/App/FemPostFilter.h @@ -35,6 +35,9 @@ #include #include #include +#include +#include +#include namespace Fem { @@ -58,6 +61,7 @@ protected: //pipeline handling for derived filter struct FilterPipeline { vtkSmartPointer source, target; + vtkSmartPointer filterSource, filterTarget; std::vector > algorithmStorage; }; @@ -96,6 +100,37 @@ private: vtkSmartPointer m_extractor; }; +class AppFemExport FemPostDataAlongLineFilter : public FemPostFilter { + + PROPERTY_HEADER(Fem::FemPostDataAlongLineFilter); + +public: + FemPostDataAlongLineFilter(void); + virtual ~FemPostDataAlongLineFilter(); + + App::PropertyVector Point2; + App::PropertyVector Point1; + App::PropertyInteger Resolution; + App::PropertyFloatList XAxisData; + App::PropertyFloatList YAxisData; + App::PropertyString PlotData; + + virtual const char* getViewProviderName(void) const { + return "FemGui::ViewProviderFemPostDataAlongLine"; + } + virtual short int mustExecute(void) const; + +protected: + virtual App::DocumentObjectExecReturn* execute(void); + virtual void onChanged(const App::Property* prop); + void GetAxisData(); + +private: + + vtkSmartPointer m_line; + vtkSmartPointer m_probe; + +}; class AppFemExport FemPostScalarClipFilter : public FemPostFilter { diff --git a/src/Mod/Fem/Gui/AppFemGui.cpp b/src/Mod/Fem/Gui/AppFemGui.cpp index e8bb5266d..c8f5f42b1 100644 --- a/src/Mod/Fem/Gui/AppFemGui.cpp +++ b/src/Mod/Fem/Gui/AppFemGui.cpp @@ -146,6 +146,7 @@ PyMODINIT_FUNC initFemGui() FemGui::ViewProviderFemPostPlaneFunction ::init(); FemGui::ViewProviderFemPostSphereFunction ::init(); FemGui::ViewProviderFemPostClip ::init(); + FemGui::ViewProviderFemPostDataAlongLine ::init(); FemGui::ViewProviderFemPostScalarClip ::init(); FemGui::ViewProviderFemPostWarpVector ::init(); FemGui::ViewProviderFemPostCut ::init(); diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 195a0c002..1f6779479 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -53,7 +53,7 @@ set(FemGui_MOC_HDRS TaskFemConstraintBearing.h TaskFemConstraintFixed.h TaskFemConstraintForce.h - TaskFemConstraintFluidBoundary.h + TaskFemConstraintFluidBoundary.h TaskFemConstraintPressure.h TaskFemConstraintGear.h TaskFemConstraintPulley.h @@ -109,6 +109,7 @@ if(BUILD_FEM_VTK) ${FemGui_UIC_SRCS} TaskPostDisplay.ui TaskPostClip.ui + TaskPostDataAlongLine.ui TaskPostScalarClip.ui TaskPostWarpVector.ui TaskPostCut.ui @@ -270,6 +271,7 @@ if(BUILD_FEM_VTK) PlaneWidget.ui SphereWidget.ui TaskPostClip.ui + TaskPostDataAlongLine.ui TaskPostScalarClip.ui TaskPostDisplay.ui TaskPostWarpVector.ui diff --git a/src/Mod/Fem/Gui/Command.cpp b/src/Mod/Fem/Gui/Command.cpp index 63e04959b..ba42f5235 100644 --- a/src/Mod/Fem/Gui/Command.cpp +++ b/src/Mod/Fem/Gui/Command.cpp @@ -1139,6 +1139,7 @@ CmdFemPostCreateDataAlongLineFilter::CmdFemPostCreateDataAlongLineFilter() void CmdFemPostCreateDataAlongLineFilter::activated(int) { + setupFilter(this, "DataAlongLine"); } bool CmdFemPostCreateDataAlongLineFilter::isActive(void) diff --git a/src/Mod/Fem/Gui/TaskPostBoxes.cpp b/src/Mod/Fem/Gui/TaskPostBoxes.cpp index 9d91cbc27..279005deb 100644 --- a/src/Mod/Fem/Gui/TaskPostBoxes.cpp +++ b/src/Mod/Fem/Gui/TaskPostBoxes.cpp @@ -28,6 +28,7 @@ #include "ui_TaskPostDisplay.h" #include "ui_TaskPostClip.h" +#include "ui_TaskPostDataAlongLine.h" #include "ui_TaskPostScalarClip.h" #include "ui_TaskPostWarpVector.h" #include "ui_TaskPostCut.h" @@ -45,10 +46,98 @@ #include #include #include +#include +#include +# include + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#include +#include + +#include +#include +#include using namespace FemGui; using namespace Gui; +// ---------------------------------------------------------------------------- + +PointMarker::PointMarker(Gui::View3DInventorViewer* iv, std::string ObjName) : view(iv), + vp(new ViewProviderPointMarker) +{ + view->addViewProvider(vp); + m_name = ObjName; +} + +PointMarker::~PointMarker() +{ + view->removeViewProvider(vp); + delete vp; +} + +void PointMarker::addPoint(const SbVec3f& pt) +{ + int ct = countPoints(); + vp->pCoords->point.set1Value(ct, pt); +} + +int PointMarker::countPoints() const +{ + return vp->pCoords->point.getNum(); +} + +void PointMarker::customEvent(QEvent*) +{ + const SbVec3f& pt1 = vp->pCoords->point[0]; + const SbVec3f& pt2 = vp->pCoords->point[1]; + + 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()); + PointsChanged(pt1[0],pt1[1], pt1[2], pt2[0],pt2[1], pt2[2]); +} + +std::string PointMarker::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::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(); +} + //************************************************************************** //************************************************************************** // TaskDialog @@ -129,8 +218,6 @@ void TaskDlgPost::modifyStandardButtons(QDialogButtonBox* box) { if(box->button(QDialogButtonBox::Apply)) box->button(QDialogButtonBox::Apply)->setDefault(true); } - - //############################################################################################ TaskPostBox::TaskPostBox(Gui::ViewProviderDocumentObject* view, const QPixmap &icon, const QString &title, QWidget* parent) @@ -161,8 +248,9 @@ void TaskPostBox::updateEnumerationList(App::PropertyEnumeration& prop, QComboBo box->clear(); QStringList list; std::vector vec = prop.getEnumVector(); - for(std::vector::iterator it = vec.begin(); it != vec.end(); ++it ) + for(std::vector::iterator it = vec.begin(); it != vec.end(); ++it ) { list.push_back(QString::fromStdString(*it)); + } box->insertItems(0, list); box->setCurrentIndex(prop.getValue()); @@ -221,7 +309,7 @@ void TaskPostDisplay::applyPythonCode() { //############################################################################################ -TaskPostFunction::TaskPostFunction(ViewProviderDocumentObject* view, QWidget* parent): TaskPostBox(view, Gui::BitmapFactory().pixmap("fem-femmesh-create-node-by-poly"), tr("Implicit function"), parent) { +TaskPostFunction::TaskPostFunction(ViewProviderDocumentObject* view, QWidget* parent): TaskPostBox(view, Gui::BitmapFactory().pixmap("fem-fem-mesh-create-node-by-poly"), tr("Implicit function"), parent) { assert(view->isDerivedFrom(ViewProviderFemPostFunction::getClassTypeId())); @@ -359,6 +447,222 @@ void TaskPostClip::on_InsideOut_toggled(bool val) { static_cast(getObject())->InsideOut.setValue(val); recompute(); } +//############################################################################################ + +TaskPostDataAlongLine::TaskPostDataAlongLine(ViewProviderDocumentObject* view, QWidget* parent) + : TaskPostBox(view,Gui::BitmapFactory().pixmap("fem-femmesh-create-node-by-poly"), tr("Data Along Line"), parent) { + + assert(view->isDerivedFrom(ViewProviderFemPostDataAlongLine::getClassTypeId())); + + //we load the views widget + proxy = new QWidget(this); + ui = new Ui_TaskPostDataAlongLine(); + ui->setupUi(proxy); + + QMetaObject::connectSlotsByName(this); + this->groupLayout()->addWidget(proxy); + + const Base::Vector3d& vec1 = static_cast(getObject())->Point1.getValue(); + ui->point1X->setValue(vec1.x); + ui->point1Y->setValue(vec1.y); + ui->point1Z->setValue(vec1.z); + + const Base::Vector3d& vec2 = static_cast(getObject())->Point2.getValue(); + ui->point2X->setValue(vec2.x); + ui->point2Y->setValue(vec2.y); + ui->point2Z->setValue(vec2.z); + + int res = static_cast(getObject())->Resolution.getValue(); + ui->resolution->setValue(res); + + connect(ui->point1X, SIGNAL(valueChanged(double)), this, SLOT(point1Changed(double))); + connect(ui->point1Y, SIGNAL(valueChanged(double)), this, SLOT(point1Changed(double))); + connect(ui->point1Z, SIGNAL(valueChanged(double)), this, SLOT(point1Changed(double))); + connect(ui->point2X, SIGNAL(valueChanged(double)), this, SLOT(point2Changed(double))); + connect(ui->point2Y, SIGNAL(valueChanged(double)), this, SLOT(point2Changed(double))); + connect(ui->point2Z, SIGNAL(valueChanged(double)), this, SLOT(point2Changed(double))); + connect(ui->resolution, SIGNAL(valueChanged(int)), this, SLOT(resolutionChanged(int))); + + //update all fields + updateEnumerationList(getTypedView()->DisplayMode, ui->Representation); + updateEnumerationList(getTypedView()->Field, ui->Field); + updateEnumerationList(getTypedView()->VectorMode, ui->VectorMode); +} + +TaskPostDataAlongLine::~TaskPostDataAlongLine() { + +} + +void TaskPostDataAlongLine::applyPythonCode() { + +} + +static const char * cursor_triangle[] = { +"32 32 3 1", +" c None", +". c #FFFFFF", +"+ c #FF0000", +" . ", +" . ", +" . ", +" . ", +" . ", +" ", +"..... ..... ", +" ", +" . ", +" . ", +" . ++ ", +" . + + ", +" . + ++ + ", +" + ++++ + ", +" + ++ ++ + ", +" + ++++++++ + ", +" ++ ++ ++ ++ "}; + +void TaskPostDataAlongLine::on_SelectPoints_clicked() { + + Gui::Command::doCommand(Gui::Command::Doc, ObjectVisible().c_str()); + Gui::Document* doc = Gui::Application::Instance->activeDocument(); + Gui::View3DInventor* view = static_cast(doc->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 = static_cast(getObject())->Label.getValue(); + + FemGui::PointMarker* marker = new FemGui::PointMarker(viewer, ObjName); + viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), + FemGui::TaskPostDataAlongLine::pointCallback, marker); + connect(marker, SIGNAL(PointsChanged(double, double, double, double, double, double)), this, SLOT(onChange(double, double, double, double, double, double))); + } + +} + +std::string TaskPostDataAlongLine::ObjectVisible(){ +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 = True\n"; +} + +void TaskPostDataAlongLine::on_CreatePlot_clicked() { + + std::string ObjName = static_cast(getObject())->Label.getValue(); + Gui::Command::doCommand(Gui::Command::Doc,"x = App.ActiveDocument.%s.XAxisData",ObjName.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"y = App.ActiveDocument.%s.YAxisData",ObjName.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"title = App.ActiveDocument.%s.PlotData",ObjName.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, Plot().c_str()); + recompute(); +} + +void TaskPostDataAlongLine::onChange(double x1, double y1, double z1, double x2, double y2, double z2) { + + ui->point2X->setValue(x2); + ui->point2Y->setValue(y2); + ui->point2Z->setValue(z2); + + ui->point1X->setValue(x1); + ui->point1Y->setValue(y1); + ui->point1Z->setValue(z1); + +} + +void TaskPostDataAlongLine::point1Changed(double) { + + Base::Vector3d vec(ui->point1X->value(), ui->point1Y->value(), ui->point1Z->value()); + std::string ObjName = static_cast(getObject())->Label.getValue(); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Point1 = App.Vector(%f, %f, %f)",ObjName.c_str(), ui->point1X->value(), ui->point1Y->value(), ui->point1Z->value()); + + +} + +void TaskPostDataAlongLine::point2Changed(double) { + + Base::Vector3d vec(ui->point2X->value(), ui->point2Y->value(), ui->point2Z->value()); + std::string ObjName = static_cast(getObject())->Label.getValue(); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Point2 = App.Vector(%f, %f, %f)", ObjName.c_str(), ui->point2X->value(), ui->point2Y->value(), ui->point2Z->value()); + +} + +void TaskPostDataAlongLine::resolutionChanged(int val) { + + static_cast(getObject())->Resolution.setValue(val); + +} + +void TaskPostDataAlongLine::pointCallback(void * ud, SoEventCallback * n) +{ + const SoMouseButtonEvent * mbe = static_cast(n->getEvent()); + Gui::View3DInventorViewer* view = reinterpret_cast(n->getUserData()); + PointMarker *pm = reinterpret_cast(ud); + + // Mark all incoming mouse button events as handled, especially, to deactivate the selection node + n->getAction()->setHandled(); + + if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) { + const SoPickedPoint * point = n->getPickedPoint(); + if (point == NULL) { + Base::Console().Message("No point picked.\n"); + return; + } + + n->setHandled(); + pm->addPoint(point->getPoint()); + 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); + pm->deleteLater(); + } +} + +void TaskPostDataAlongLine::on_Representation_activated(int i) { + + getTypedView()->DisplayMode.setValue(i); + updateEnumerationList(getTypedView()->Field, ui->Field); + updateEnumerationList(getTypedView()->VectorMode, ui->VectorMode); +} + +void TaskPostDataAlongLine::on_Field_activated(int i) { + + getTypedView()->Field.setValue(i); + std::string FieldName = ui->Field->currentText().toStdString(); + static_cast(getObject())->PlotData.setValue(FieldName); + updateEnumerationList(getTypedView()->VectorMode, ui->VectorMode); +} + +void TaskPostDataAlongLine::on_VectorMode_activated(int i) { + + getTypedView()->VectorMode.setValue(i); +} + +std::string TaskPostDataAlongLine::Plot() { + return "import FreeCAD\n\ +import numpy as np\n\ +from matplotlib import pyplot as plt\n\ +plt.figure(1)\n\ +plt.plot(x, y)\n\ +plt.xlabel(\"Length\")\n\ +plt.ylabel(title)\n\ +plt.title(title)\n\ +plt.grid()\n\ +plt.show()\n"; + +} //############################################################################################ diff --git a/src/Mod/Fem/Gui/TaskPostBoxes.h b/src/Mod/Fem/Gui/TaskPostBoxes.h index aa7681535..ebab074cf 100644 --- a/src/Mod/Fem/Gui/TaskPostBoxes.h +++ b/src/Mod/Fem/Gui/TaskPostBoxes.h @@ -30,17 +30,66 @@ #include #include #include "ViewProviderFemPostFunction.h" +#include class QComboBox; class Ui_TaskPostDisplay; class Ui_TaskPostClip; +class Ui_TaskPostDataAlongLine; class Ui_TaskPostScalarClip; class Ui_TaskPostWarpVector; class Ui_TaskPostCut; +class SoFontStyle; +class SoText2; +class SoBaseColor; +class SoTranslation; +class SoCoordinate3; +class SoIndexedLineSet; +class SoEventCallback; +class SoMarkerSet; + namespace FemGui { +class ViewProviderPointMarker; +class PointMarker : public QObject +{ + Q_OBJECT + +public: + PointMarker(Gui::View3DInventorViewer* view, std::string ObjName); + ~PointMarker(); + + void addPoint(const SbVec3f&); + int countPoints() const; + +Q_SIGNALS: + void PointsChanged(double x1, double y1, double z1, double x2, double y2, double z2); + +protected: + void customEvent(QEvent* e); + +private: + Gui::View3DInventorViewer *view; + ViewProviderPointMarker *vp; + std::string m_name; + std::string ObjectInvisible(); +}; + +class FemGuiExport ViewProviderPointMarker : public Gui::ViewProviderDocumentObject +{ + PROPERTY_HEADER(FemGui::ViewProviderPointMarker); + +public: + ViewProviderPointMarker(); + virtual ~ViewProviderPointMarker(); + +protected: + SoCoordinate3 * pCoords; + friend class PointMarker; +}; + class TaskPostBox : public Gui::TaskView::TaskBox { Q_OBJECT @@ -105,7 +154,6 @@ protected: std::vector m_boxes; }; - class TaskPostDisplay : public TaskPostBox { Q_OBJECT @@ -164,6 +212,36 @@ private: FunctionWidget* fwidget; }; +class TaskPostDataAlongLine: public TaskPostBox { + + Q_OBJECT + +public: + TaskPostDataAlongLine(Gui::ViewProviderDocumentObject* view, QWidget* parent = 0); + virtual ~TaskPostDataAlongLine(); + + virtual void applyPythonCode(); + static void pointCallback(void * ud, SoEventCallback * n); + +private Q_SLOTS: + void on_SelectPoints_clicked(); + void on_CreatePlot_clicked(); + void on_Representation_activated(int i); + void on_Field_activated(int i); + void on_VectorMode_activated(int i); + void point2Changed(double); + void point1Changed(double); + void resolutionChanged(int val); + void onChange(double x1, double y1, double z1, double x2, double y2, double z2); + + +private: + std::string Plot(); + std::string ObjectVisible(); + QWidget* proxy; + Ui_TaskPostDataAlongLine* ui; +}; + class TaskPostScalarClip : public TaskPostBox { Q_OBJECT diff --git a/src/Mod/Fem/Gui/TaskPostDataAlongLine.ui b/src/Mod/Fem/Gui/TaskPostDataAlongLine.ui new file mode 100644 index 000000000..7c80824e2 --- /dev/null +++ b/src/Mod/Fem/Gui/TaskPostDataAlongLine.ui @@ -0,0 +1,286 @@ + + + TaskPostDataAlongLine + + + + 0 + 0 + 482 + 363 + + + + Form + + + + + + Qt::Horizontal + + + + + + + + + Point1 + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 70 + 0 + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + + + + + + 0 + 0 + + + + + 70 + 0 + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + + + + + + 0 + 0 + + + + + 70 + 0 + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + + + + + + + + + Point2 + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 70 + 0 + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + + + + + + 0 + 0 + + + + + 70 + 0 + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + + + + + + 0 + 0 + + + + + 70 + 0 + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + + + + + + + Select Points + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Resolution + + + + + + + 999999999 + + + + + + + + + + + + Qt::Horizontal + + + + + + + + + + + + Mode + + + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Field + + + + + + + + + + Vector + + + + + + + + + + + + Qt::Horizontal + + + + + + + Create Plot + + + + + SelectPoints + line + line_2 + line_3 + CreatePlot + + + + diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostFilter.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostFilter.cpp index 6698d8bd6..a5832a899 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostFilter.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostFilter.cpp @@ -51,6 +51,24 @@ void ViewProviderFemPostClip::setupTaskDialog(TaskDlgPost* dlg) { FemGui::ViewProviderFemPostObject::setupTaskDialog(dlg); } +PROPERTY_SOURCE(FemGui::ViewProviderFemPostDataAlongLine, FemGui::ViewProviderFemPostObject) + +ViewProviderFemPostDataAlongLine::ViewProviderFemPostDataAlongLine() { + + sPixmap = "fem-DataAlongLine"; +} + +ViewProviderFemPostDataAlongLine::~ViewProviderFemPostDataAlongLine() { + +} + +void ViewProviderFemPostDataAlongLine::setupTaskDialog(TaskDlgPost* dlg) { + + //add the function box + dlg->appendBox(new TaskPostDataAlongLine(dlg->getView())); + +} + PROPERTY_SOURCE(FemGui::ViewProviderFemPostScalarClip, FemGui::ViewProviderFemPostObject) diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostFilter.h b/src/Mod/Fem/Gui/ViewProviderFemPostFilter.h index 396ba8999..426b0afd9 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostFilter.h +++ b/src/Mod/Fem/Gui/ViewProviderFemPostFilter.h @@ -42,6 +42,18 @@ protected: virtual void setupTaskDialog(TaskDlgPost* dlg); }; +class FemGuiExport ViewProviderFemPostDataAlongLine : public ViewProviderFemPostObject { + + PROPERTY_HEADER(FemGui::ViewProviderFemPostDataAlongLine); + +public: + /// constructor. + ViewProviderFemPostDataAlongLine(); + ~ViewProviderFemPostDataAlongLine(); + +protected: + virtual void setupTaskDialog(TaskDlgPost* dlg); +}; class FemGuiExport ViewProviderFemPostScalarClip : public ViewProviderFemPostObject { PROPERTY_HEADER(FemGui::ViewProviderFemPostScalarClip); diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp index fa8fedf2b..65f6b0745 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp @@ -247,8 +247,11 @@ void ViewProviderFemPostObject::updateProperties() { colorArrays.push_back("None"); vtkPointData* point = poly->GetPointData(); - for(int i=0; iGetNumberOfArrays(); ++i) - colorArrays.push_back(point->GetArrayName(i)); + for(int i=0; iGetNumberOfArrays(); ++i) { + std::string FieldName = point->GetArrayName(i); + if (FieldName != "Texture Coordinates") + colorArrays.push_back(FieldName); + } vtkCellData* cell = poly->GetCellData(); for(int i=0; iGetNumberOfArrays(); ++i)