From 4f2291f420834cb0a4ce211e018bd772c5f24775 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 23 Dec 2015 15:44:11 +0100 Subject: [PATCH] + implement property editor item for FEM mesh --- src/Mod/Fem/App/FemMeshProperty.h | 1 + src/Mod/Fem/Gui/AppFemGui.cpp | 2 + src/Mod/Fem/Gui/CMakeLists.txt | 3 + src/Mod/Fem/Gui/PropertyFemMeshItem.cpp | 204 ++++++++++++++++++++++++ src/Mod/Fem/Gui/PropertyFemMeshItem.h | 78 +++++++++ 5 files changed, 288 insertions(+) create mode 100644 src/Mod/Fem/Gui/PropertyFemMeshItem.cpp create mode 100644 src/Mod/Fem/Gui/PropertyFemMeshItem.h diff --git a/src/Mod/Fem/App/FemMeshProperty.h b/src/Mod/Fem/App/FemMeshProperty.h index a72fea473..00630a99a 100644 --- a/src/Mod/Fem/App/FemMeshProperty.h +++ b/src/Mod/Fem/App/FemMeshProperty.h @@ -82,6 +82,7 @@ public: App::Property *Copy(void) const; void Paste(const App::Property &from); unsigned int getMemSize (void) const; + const char* getEditorName(void) const { return "FemGui::PropertyFemMeshItem"; } //@} private: diff --git a/src/Mod/Fem/Gui/AppFemGui.cpp b/src/Mod/Fem/Gui/AppFemGui.cpp index 37cf31b78..3a4aa29c8 100644 --- a/src/Mod/Fem/Gui/AppFemGui.cpp +++ b/src/Mod/Fem/Gui/AppFemGui.cpp @@ -32,6 +32,7 @@ #include #include #include +#include "PropertyFemMeshItem.h" #include "DlgSettingsFemImp.h" #include "ViewProviderFemMesh.h" #include "ViewProviderFemMeshShape.h" @@ -104,6 +105,7 @@ void FemGuiExport initFemGui() FemGui::ViewProviderFemConstraintPulley ::init(); FemGui::ViewProviderResult ::init(); FemGui::ViewProviderResultPython ::init(); + FemGui::PropertyFemMeshItem ::init(); // register preferences pages new Gui::PrefPageProducer ("FEM"); diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 986e582db..420e3981e 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -42,6 +42,7 @@ SOURCE_GROUP("Python" FILES ${Python_SRCS}) set(FemGui_MOC_HDRS DlgSettingsFemImp.h + PropertyFemMeshItem.h TaskObjectName.h TaskCreateNodeSet.h TaskDlgCreateNodeSet.h @@ -187,6 +188,8 @@ SET(FemGui_SRCS_Module Resources/Fem.qrc PreCompiled.cpp PreCompiled.h + PropertyFemMeshItem.cpp + PropertyFemMeshItem.h Workbench.cpp Workbench.h ) diff --git a/src/Mod/Fem/Gui/PropertyFemMeshItem.cpp b/src/Mod/Fem/Gui/PropertyFemMeshItem.cpp new file mode 100644 index 000000000..41d364c15 --- /dev/null +++ b/src/Mod/Fem/Gui/PropertyFemMeshItem.cpp @@ -0,0 +1,204 @@ +/*************************************************************************** + * Copyright (c) 2015 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +#include "PropertyFemMeshItem.h" +#include +#include + +using namespace FemGui; + + +TYPESYSTEM_SOURCE(FemGui::PropertyFemMeshItem, Gui::PropertyEditor::PropertyItem); + +PropertyFemMeshItem::PropertyFemMeshItem() +{ + m_n = static_cast + (Gui::PropertyEditor::PropertyIntegerItem::create()); + m_n->setParent(this); + m_n->setPropertyName(QLatin1String("Nodes")); + this->appendChild(m_n); + m_e = static_cast + (Gui::PropertyEditor::PropertyIntegerItem::create()); + m_e->setParent(this); + m_e->setPropertyName(QLatin1String("Edges")); + this->appendChild(m_e); + m_f = static_cast + (Gui::PropertyEditor::PropertyIntegerItem::create()); + m_f->setParent(this); + m_f->setPropertyName(QLatin1String("Faces")); + this->appendChild(m_f); + m_p = static_cast + (Gui::PropertyEditor::PropertyIntegerItem::create()); + m_p->setParent(this); + m_p->setPropertyName(QLatin1String("Polygons")); + this->appendChild(m_p); + m_v = static_cast + (Gui::PropertyEditor::PropertyIntegerItem::create()); + m_v->setParent(this); + m_v->setPropertyName(QLatin1String("Volumes")); + this->appendChild(m_v); + m_h = static_cast + (Gui::PropertyEditor::PropertyIntegerItem::create()); + m_h->setParent(this); + m_h->setPropertyName(QLatin1String("Polyhedrons")); + this->appendChild(m_h); +} + +void PropertyFemMeshItem::initialize() +{ + this->setReadOnly(true); +} + +QVariant PropertyFemMeshItem::value(const App::Property*) const +{ + int ctN = 0; + int ctE = 0; + int ctF = 0; + int ctP = 0; + int ctV = 0; + int ctH = 0; + + const std::vector& props = getPropertyData(); + for (std::vector::const_iterator pt = props.begin(); pt != props.end(); ++pt) { + Fem::PropertyFemMesh* prop = static_cast(*pt); + SMESH_Mesh* mesh = const_cast(prop->getValue().getSMesh()); + ctN += mesh->NbNodes(); + ctE += mesh->NbEdges(); + ctF += mesh->NbFaces(); + ctP += mesh->NbPolygons(); + ctV += mesh->NbVolumes(); + ctH += mesh->NbPolyhedrons(); + } + + QString str = QObject::tr("[Nodes: %1, Edges: %2, Faces: %3, Polygons: %4, Volumes: %5, Polyhedrons: %6]") + .arg(ctN).arg(ctE).arg(ctF).arg(ctP).arg(ctV).arg(ctH); + return QVariant(str); +} + +QVariant PropertyFemMeshItem::toolTip(const App::Property* prop) const +{ + return value(prop); +} + +void PropertyFemMeshItem::setValue(const QVariant& value) +{ +} + +QWidget* PropertyFemMeshItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const +{ + return 0; +} + +void PropertyFemMeshItem::setEditorData(QWidget *editor, const QVariant& data) const +{ +} + +QVariant PropertyFemMeshItem::editorData(QWidget *editor) const +{ + return QVariant(); +} + +int PropertyFemMeshItem::countNodes() const +{ + int ctN = 0; + const std::vector& props = getPropertyData(); + for (std::vector::const_iterator pt = props.begin(); pt != props.end(); ++pt) { + Fem::PropertyFemMesh* prop = static_cast(*pt); + SMESH_Mesh* mesh = const_cast(prop->getValue().getSMesh()); + ctN += mesh->NbNodes(); + } + + return ctN; +} + +int PropertyFemMeshItem::countEdges() const +{ + int ctE = 0; + const std::vector& props = getPropertyData(); + for (std::vector::const_iterator pt = props.begin(); pt != props.end(); ++pt) { + Fem::PropertyFemMesh* prop = static_cast(*pt); + SMESH_Mesh* mesh = const_cast(prop->getValue().getSMesh()); + ctE += mesh->NbEdges(); + } + + return ctE; +} + +int PropertyFemMeshItem::countFaces() const +{ + int ctF = 0; + const std::vector& props = getPropertyData(); + for (std::vector::const_iterator pt = props.begin(); pt != props.end(); ++pt) { + Fem::PropertyFemMesh* prop = static_cast(*pt); + SMESH_Mesh* mesh = const_cast(prop->getValue().getSMesh()); + ctF += mesh->NbFaces(); + } + + return ctF; +} + +int PropertyFemMeshItem::countPolygons() const +{ + int ctP = 0; + const std::vector& props = getPropertyData(); + for (std::vector::const_iterator pt = props.begin(); pt != props.end(); ++pt) { + Fem::PropertyFemMesh* prop = static_cast(*pt); + SMESH_Mesh* mesh = const_cast(prop->getValue().getSMesh()); + ctP += mesh->NbPolygons(); + } + + return ctP; +} + +int PropertyFemMeshItem::countVolumes() const +{ + int ctV = 0; + const std::vector& props = getPropertyData(); + for (std::vector::const_iterator pt = props.begin(); pt != props.end(); ++pt) { + Fem::PropertyFemMesh* prop = static_cast(*pt); + SMESH_Mesh* mesh = const_cast(prop->getValue().getSMesh()); + ctV += mesh->NbVolumes(); + } + + return ctV; +} + +int PropertyFemMeshItem::countPolyhedrons() const +{ + int ctH = 0; + const std::vector& props = getPropertyData(); + for (std::vector::const_iterator pt = props.begin(); pt != props.end(); ++pt) { + Fem::PropertyFemMesh* prop = static_cast(*pt); + SMESH_Mesh* mesh = const_cast(prop->getValue().getSMesh()); + ctH += mesh->NbPolyhedrons(); + } + + return ctH; +} + +#include "moc_PropertyFemMeshItem.cpp" diff --git a/src/Mod/Fem/Gui/PropertyFemMeshItem.h b/src/Mod/Fem/Gui/PropertyFemMeshItem.h new file mode 100644 index 000000000..bcb3924b2 --- /dev/null +++ b/src/Mod/Fem/Gui/PropertyFemMeshItem.h @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (c) 2015 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef FEMGUI_PROPERTY_FEMMESH_ITEM_H +#define FEMGUI_PROPERTY_FEMMESH_ITEM_H + +#include + +namespace FemGui { + +/** + * Display data of an FEM mesh. + * \author Werner Mayer + */ +class PropertyFemMeshItem : public Gui::PropertyEditor::PropertyItem +{ + Q_OBJECT + Q_PROPERTY(int Nodes READ countNodes) + Q_PROPERTY(int Edges READ countEdges) + Q_PROPERTY(int Faces READ countFaces) + Q_PROPERTY(int Polygons READ countPolygons) + Q_PROPERTY(int Volumes READ countVolumes) + Q_PROPERTY(int Polyhedrons READ countPolyhedrons) + TYPESYSTEM_HEADER(); + + virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const; + virtual void setEditorData(QWidget *editor, const QVariant& data) const; + virtual QVariant editorData(QWidget *editor) const; + + int countNodes() const; + int countEdges() const; + int countFaces() const; + int countPolygons() const; + int countVolumes() const; + int countPolyhedrons() const; + +protected: + virtual QVariant toolTip(const App::Property*) const; + virtual QVariant value(const App::Property*) const; + virtual void setValue(const QVariant&); + +protected: + PropertyFemMeshItem(); + void initialize(); + +private: + Gui::PropertyEditor::PropertyIntegerItem* m_n; + Gui::PropertyEditor::PropertyIntegerItem* m_e; + Gui::PropertyEditor::PropertyIntegerItem* m_f; + Gui::PropertyEditor::PropertyIntegerItem* m_p; + Gui::PropertyEditor::PropertyIntegerItem* m_v; + Gui::PropertyEditor::PropertyIntegerItem* m_h; +}; + +} // namespace FemGui + + +#endif // FEMGUI_PROPERTY_FEMMESH_ITEM_H +