FEM: DataAlongLine: core implementation

This commit is contained in:
mkhizenz 2016-12-20 18:10:35 +01:00 committed by Yorik van Havre
parent 9e12af32da
commit ede94ba09c
12 changed files with 878 additions and 13 deletions

View File

@ -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();

View File

@ -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<vtkLineSource>::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<vtkProbeFilter>::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<double> coords;
std::vector<double> values;
vtkSmartPointer<vtkDataObject> 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; i<dset->GetNumberOfPoints(); ++i) {
double value = 0;
if(pdata->GetNumberOfComponents() == 1)
value = pdata->GetComponent(i, component);
else {
for(int j=0; j<pdata->GetNumberOfComponents(); ++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)

View File

@ -35,6 +35,9 @@
#include <vtkPlane.h>
#include <vtkWarpVector.h>
#include <vtkCutter.h>
#include <vtkLineSource.h>
#include <vtkProbeFilter.h>
#include <vtkThreshold.h>
namespace Fem
{
@ -58,6 +61,7 @@ protected:
//pipeline handling for derived filter
struct FilterPipeline {
vtkSmartPointer<vtkAlgorithm> source, target;
vtkSmartPointer<vtkProbeFilter> filterSource, filterTarget;
std::vector<vtkSmartPointer<vtkAlgorithm> > algorithmStorage;
};
@ -96,6 +100,37 @@ private:
vtkSmartPointer<vtkExtractGeometry> 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<vtkLineSource> m_line;
vtkSmartPointer<vtkProbeFilter> m_probe;
};
class AppFemExport FemPostScalarClipFilter : public FemPostFilter {

View File

@ -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();

View File

@ -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

View File

@ -1139,6 +1139,7 @@ CmdFemPostCreateDataAlongLineFilter::CmdFemPostCreateDataAlongLineFilter()
void CmdFemPostCreateDataAlongLineFilter::activated(int)
{
setupFilter(this, "DataAlongLine");
}
bool CmdFemPostCreateDataAlongLineFilter::isActive(void)

View File

@ -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 <Gui/Action.h>
#include <QMessageBox>
#include <QPushButton>
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
# include <Inventor/events/SoMouseButtonEvent.h>
# include <sstream>
# include <QApplication>
# include <Inventor/SoPickedPoint.h>
# include <Inventor/nodes/SoAnnotation.h>
# include <Inventor/nodes/SoBaseColor.h>
# include <Inventor/nodes/SoFontStyle.h>
# include <Inventor/nodes/SoPickStyle.h>
# include <Inventor/nodes/SoText2.h>
# include <Inventor/nodes/SoTranslation.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoIndexedLineSet.h>
# include <Inventor/nodes/SoMarkerSet.h>
# include <Inventor/nodes/SoDrawStyle.h>
#include <Gui/View3DInventorViewer.h>
#include <Base/Console.h>
#include <App/PropertyGeo.h>
#include <App/PropertyStandard.h>
#include <Base/Quantity.h>
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<std::string> vec = prop.getEnumVector();
for(std::vector<std::string>::iterator it = vec.begin(); it != vec.end(); ++it )
for(std::vector<std::string>::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<Fem::FemPostClipFilter*>(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<Fem::FemPostDataAlongLineFilter*>(getObject())->Point1.getValue();
ui->point1X->setValue(vec1.x);
ui->point1Y->setValue(vec1.y);
ui->point1Z->setValue(vec1.z);
const Base::Vector3d& vec2 = static_cast<Fem::FemPostDataAlongLineFilter*>(getObject())->Point2.getValue();
ui->point2X->setValue(vec2.x);
ui->point2Y->setValue(vec2.y);
ui->point2Z->setValue(vec2.z);
int res = static_cast<Fem::FemPostDataAlongLineFilter*>(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<ViewProviderFemPostObject>()->DisplayMode, ui->Representation);
updateEnumerationList(getTypedView<ViewProviderFemPostObject>()->Field, ui->Field);
updateEnumerationList(getTypedView<ViewProviderFemPostObject>()->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<Gui::View3DInventor*>(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<Fem::FemPostDataAlongLineFilter*>(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<Fem::FemPostDataAlongLineFilter*>(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<Fem::FemPostDataAlongLineFilter*>(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<Fem::FemPostDataAlongLineFilter*>(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<Fem::FemPostDataAlongLineFilter*>(getObject())->Resolution.setValue(val);
}
void TaskPostDataAlongLine::pointCallback(void * ud, SoEventCallback * n)
{
const SoMouseButtonEvent * mbe = static_cast<const SoMouseButtonEvent*>(n->getEvent());
Gui::View3DInventorViewer* view = reinterpret_cast<Gui::View3DInventorViewer*>(n->getUserData());
PointMarker *pm = reinterpret_cast<PointMarker*>(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<ViewProviderFemPostObject>()->DisplayMode.setValue(i);
updateEnumerationList(getTypedView<ViewProviderFemPostObject>()->Field, ui->Field);
updateEnumerationList(getTypedView<ViewProviderFemPostObject>()->VectorMode, ui->VectorMode);
}
void TaskPostDataAlongLine::on_Field_activated(int i) {
getTypedView<ViewProviderFemPostObject>()->Field.setValue(i);
std::string FieldName = ui->Field->currentText().toStdString();
static_cast<Fem::FemPostDataAlongLineFilter*>(getObject())->PlotData.setValue(FieldName);
updateEnumerationList(getTypedView<ViewProviderFemPostObject>()->VectorMode, ui->VectorMode);
}
void TaskPostDataAlongLine::on_VectorMode_activated(int i) {
getTypedView<ViewProviderFemPostObject>()->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";
}
//############################################################################################

View File

@ -30,17 +30,66 @@
#include <Base/Parameter.h>
#include <App/PropertyLinks.h>
#include "ViewProviderFemPostFunction.h"
#include <boost/signals.hpp>
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<TaskPostBox*> 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

View File

@ -0,0 +1,286 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TaskPostDataAlongLine</class>
<widget class="QWidget" name="TaskPostDataAlongLine">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>482</width>
<height>363</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Point1</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="point1X">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>70</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="point1Y">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>70</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="point1Z">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>70</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Point2</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="point2X">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>70</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="point2Y">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>70</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="point2Z">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>70</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="SelectPoints">
<property name="text">
<string>Select Points</string>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Resolution</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="resolution">
<property name="maximum">
<number>999999999</number>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_5"/>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="1">
<widget class="QComboBox" name="Representation"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Mode</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout_4">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Field</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="Field"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Vector</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="VectorMode"/>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="CreatePlot">
<property name="text">
<string>Create Plot</string>
</property>
</widget>
</item>
</layout>
<zorder>SelectPoints</zorder>
<zorder>line</zorder>
<zorder>line_2</zorder>
<zorder>line_3</zorder>
<zorder>CreatePlot</zorder>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -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)

View File

@ -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);

View File

@ -247,8 +247,11 @@ void ViewProviderFemPostObject::updateProperties() {
colorArrays.push_back("None");
vtkPointData* point = poly->GetPointData();
for(int i=0; i<point->GetNumberOfArrays(); ++i)
colorArrays.push_back(point->GetArrayName(i));
for(int i=0; i<point->GetNumberOfArrays(); ++i) {
std::string FieldName = point->GetArrayName(i);
if (FieldName != "Texture Coordinates")
colorArrays.push_back(FieldName);
}
vtkCellData* cell = poly->GetCellData();
for(int i=0; i<cell->GetNumberOfArrays(); ++i)