From 2a3317113fed5f404b7c9075ae645c7a9ce141ac Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 2 Apr 2012 09:11:58 +0200 Subject: [PATCH] 0000340: Make mesh 4-node parabolic instead of plain 3-node --- src/Mod/Fem/App/HypothesisPy.cpp | 9 ++ src/Mod/Fem/App/HypothesisPy.h | 2 + src/Mod/Fem/Gui/CMakeLists.txt | 20 +++- src/Mod/Fem/Gui/Command.cpp | 42 +------ src/Mod/Fem/Gui/Hypothesis.cpp | 186 +++++++++++++++++++++++++++++++ src/Mod/Fem/Gui/Hypothesis.h | 75 +++++++++++++ src/Mod/Fem/Gui/Hypothesis.ui | 166 +++++++++++++++++++++++++++ src/Mod/Fem/Gui/Makefile.am | 9 +- src/Mod/Fem/Init.py | 2 +- 9 files changed, 472 insertions(+), 39 deletions(-) create mode 100644 src/Mod/Fem/Gui/Hypothesis.cpp create mode 100644 src/Mod/Fem/Gui/Hypothesis.h create mode 100644 src/Mod/Fem/Gui/Hypothesis.ui diff --git a/src/Mod/Fem/App/HypothesisPy.cpp b/src/Mod/Fem/App/HypothesisPy.cpp index 207488bba..755e8a539 100644 --- a/src/Mod/Fem/App/HypothesisPy.cpp +++ b/src/Mod/Fem/App/HypothesisPy.cpp @@ -579,6 +579,8 @@ void StdMeshers_Deflection1DPy::init_type(PyObject* module) { behaviors().name("StdMeshers_Deflection1D"); behaviors().doc("StdMeshers_Deflection1D"); + + add_varargs_method("setDeflection", &StdMeshers_Deflection1DPy::setDeflection, "setDeflection()"); SMESH_HypothesisPyBase::init_type(module); } @@ -591,6 +593,13 @@ StdMeshers_Deflection1DPy::~StdMeshers_Deflection1DPy() { } +Py::Object StdMeshers_Deflection1DPy::setDeflection(const Py::Tuple& args) +{ + double fine = (double)Py::Float(args[0]); + hypothesis()->SetDeflection(fine); + return Py::None(); +} + // ---------------------------------------------------------------------------- void StdMeshers_Hexa_3DPy::init_type(PyObject* module) diff --git a/src/Mod/Fem/App/HypothesisPy.h b/src/Mod/Fem/App/HypothesisPy.h index 51d06bb25..776c80c8c 100644 --- a/src/Mod/Fem/App/HypothesisPy.h +++ b/src/Mod/Fem/App/HypothesisPy.h @@ -208,6 +208,8 @@ public: static void init_type(PyObject*); StdMeshers_Deflection1DPy(int hypId, int studyId, SMESH_Gen* gen); ~StdMeshers_Deflection1DPy(); + + Py::Object setDeflection(const Py::Tuple& args); }; class StdMeshers_Hexa_3DPy : public SMESH_HypothesisPy diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 8774505f4..5343beb2b 100644 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -28,6 +28,24 @@ if(SMESH_FOUND) include_directories( ${SMESH_INCLUDE_DIR} ) list( APPEND FemGui_LIBS ${SMESH_LIBRARIES} ) endif(SMESH_FOUND) + +set(FemGui_MOC_HDRS + Hypothesis.h +) +fc_wrap_cpp(FemGui_MOC_SRCS ${FemGui_MOC_HDRS}) +SOURCE_GROUP("Moc" FILES ${FemGui_MOC_SRCS}) + +set(FemGui_UIC_SRCS + Hypothesis.ui +) +qt4_wrap_ui(FemGui_UIC_HDRS ${FemGui_UIC_SRCS}) +SET(FemGui_DLG_SRCS + ${FemGui_UIC_HDRS} + Hypothesis.ui + Hypothesis.cpp + Hypothesis.h +) +SOURCE_GROUP("Dialogs" FILES ${FemGui_DLG_SRCS}) qt4_add_resources(FemResource_SRCS Resources/Fem.qrc) @@ -35,7 +53,7 @@ SOURCE_GROUP("Resources" FILES ${FemResource_SRCS}) SET(FemGui_SRCS - #${FemGui_UIC_HDRS} + ${FemGui_DLG_SRCS} ${FemResource_SRCS} AppFemGui.cpp AppFemGuiPy.cpp diff --git a/src/Mod/Fem/Gui/Command.cpp b/src/Mod/Fem/Gui/Command.cpp index 54b2086d7..61e033fc2 100644 --- a/src/Mod/Fem/Gui/Command.cpp +++ b/src/Mod/Fem/Gui/Command.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,7 @@ #include +#include "Hypothesis.h" using namespace std; @@ -57,46 +59,14 @@ CmdFemCreateFromShape::CmdFemCreateFromShape() void CmdFemCreateFromShape::activated(int iMsg) { - Base::Type type = Base::Type::fromName("Part::Feature"); - std::vector obj = Gui::Selection().getObjectsOfType(type); - - openCommand("Create FEM"); - doCommand(Doc, "import Fem"); - for (std::vector::iterator it = obj.begin(); it != obj.end(); ++it) { - App::Document* doc = (*it)->getDocument(); - QString name = QString::fromAscii((*it)->getNameInDocument()); - QString cmd = QString::fromAscii( - "__fem__=Fem.FemMesh()\n" - "__fem__.setShape(FreeCAD.getDocument(\"%1\").%2.Shape)\n" - "h1=Fem.StdMeshers_MaxLength(0,__fem__)\n" - "h1.setLength(1.0)\n" - "h2=Fem.StdMeshers_LocalLength(1,__fem__)\n" - "h2.setLength(1.0)\n" - "h3=Fem.StdMeshers_QuadranglePreference(2,__fem__)\n" - "h4=Fem.StdMeshers_Quadrangle_2D(3,__fem__)\n" - "h5=Fem.StdMeshers_MaxElementArea(4,__fem__)\n" - "h5.setMaxArea(1.0)\n" - "h6=Fem.StdMeshers_Regular_1D(5,__fem__)\n" - "__fem__.addHypothesis(h1)\n" - "__fem__.addHypothesis(h2)\n" - "__fem__.addHypothesis(h3)\n" - "__fem__.addHypothesis(h4)\n" - "__fem__.addHypothesis(h5)\n" - "__fem__.addHypothesis(h6)\n" - "__fem__.compute()\n" - "FreeCAD.getDocument(\"%1\").addObject" - "(\"Fem::FemMeshObject\",\"%2\").FemMesh=__fem__\n" - "del __fem__,h1,h2,h3,h4,h5,h6\n" - ) - .arg(QString::fromAscii(doc->getName())) - .arg(name); - doCommand(Doc, "%s", (const char*)cmd.toAscii()); - } - commitCommand(); + FemGui::TaskHypothesis* dlg = new FemGui::TaskHypothesis(); + Gui::Control().showDialog(dlg); } bool CmdFemCreateFromShape::isActive(void) { + if (Gui::Control().activeDialog()) + return false; Base::Type type = Base::Type::fromName("Part::Feature"); return Gui::Selection().countObjectsOfType(type) > 0; } diff --git a/src/Mod/Fem/Gui/Hypothesis.cpp b/src/Mod/Fem/Gui/Hypothesis.cpp new file mode 100644 index 000000000..3625b438f --- /dev/null +++ b/src/Mod/Fem/Gui/Hypothesis.cpp @@ -0,0 +1,186 @@ +/*************************************************************************** + * Copyright (c) 2012 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_ +# include +#endif + +#include "Hypothesis.h" +#include "ui_Hypothesis.h" + +#include +#include +#include + +using namespace FemGui; + +HypothesisWidget::HypothesisWidget(QWidget* parent) + : QWidget(parent), ui(new Ui_HypothesisWidget) +{ + ui->setupUi(this); +} + +HypothesisWidget::~HypothesisWidget() +{ + delete ui; +} + +bool HypothesisWidget::accept() +{ + Base::Type type = Base::Type::fromName("Part::Feature"); + std::vector obj = Gui::Selection().getObjectsOfType(type); + + Gui::Command::openCommand("Create FEM"); + Gui::Command::doCommand(Gui::Command::Doc, "import Fem"); + for (std::vector::iterator it = obj.begin(); it != obj.end(); ++it) { + QString cmd; + QTextStream str(&cmd); + App::Document* doc = (*it)->getDocument(); + QString doc_name = QString::fromAscii(doc->getName()); + QString obj_name = QString::fromAscii((*it)->getNameInDocument()); + str << QString::fromAscii( + "__fem__=Fem.FemMesh()\n" + "__fem__.setShape(FreeCAD.getDocument('%1').%2.Shape)\n") + .arg(doc_name).arg(obj_name); + int hyp=0; + + if (ui->maxLength->isChecked()) { + str << QString::fromAscii( + "hyp=Fem.StdMeshers_MaxLength(%1,__fem__)\n" + "hyp.setLength(%2)\n" + "__fem__.addHypothesis(hyp)\n") + .arg(hyp++).arg(ui->valMaxLength->value()); + } + + if (ui->localLength->isChecked()) { + str << QString::fromAscii( + "hyp=Fem.StdMeshers_LocalLength(%1,__fem__)\n" + "hyp.setLength(%2)\n" + "__fem__.addHypothesis(hyp)\n") + .arg(hyp++).arg(ui->valLocalLength->value()); + } + + if (ui->maxArea->isChecked()) { + str << QString::fromAscii( + "hyp=Fem.StdMeshers_MaxElementArea(%1,__fem__)\n" + "hyp.setMaxArea(%2)\n" + "__fem__.addHypothesis(hyp)\n"). + arg(hyp++).arg(ui->valMaxArea->value()); + } +#if 0 + str << QString::fromAscii( + "hyp=Fem.StdMeshers_NumberOfSegments(%1,__fem__)\n" + "hyp.setNumberOfSegments(1)\n" + "__fem__.addHypothesis(hyp)\n") + .arg(hyp++); + + str << QString::fromAscii( + "hyp=Fem.StdMeshers_Deflection1D(%1,__fem__)\n" + "hyp.setDeflection(0.02)\n" + "__fem__.addHypothesis(hyp)\n") + .arg(hyp++); +#endif + str << QString::fromAscii( + "hyp=Fem.StdMeshers_Regular_1D(%1,__fem__)\n" + "__fem__.addHypothesis(hyp)\n") + .arg(hyp++); + + if (ui->quadPref->isChecked()) { + str << QString::fromAscii( + "hyp=Fem.StdMeshers_QuadranglePreference(%1,__fem__)\n" + "__fem__.addHypothesis(hyp)\n") + .arg(hyp++); + } + + str << QString::fromAscii( + "hyp=Fem.StdMeshers_Quadrangle_2D(%1,__fem__)\n" + "__fem__.addHypothesis(hyp)\n") + .arg(hyp++); + + str << QString::fromAscii( + "__fem__.compute()\n" + "FreeCAD.getDocument('%1').addObject" + "(\"Fem::FemMeshObject\",'%2').FemMesh=__fem__\n" + "del __fem__, hyp\n") + .arg(doc_name).arg(obj_name); + Gui::Command::doCommand(Gui::Command::Doc, "%s", (const char*)cmd.toAscii()); + } + Gui::Command::commitCommand(); + return true; +} + +bool HypothesisWidget::reject() +{ + return true; +} + +void HypothesisWidget::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} + +// ----------------------------------------------- + +TaskHypothesis::TaskHypothesis() +{ + widget = new HypothesisWidget(); + taskbox = new Gui::TaskView::TaskBox( + QPixmap(), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskHypothesis::~TaskHypothesis() +{ +} + +void TaskHypothesis::open() +{ +} + +bool TaskHypothesis::accept() +{ + try { + return widget->accept(); + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + return false; + } + catch (...) { + Base::Console().Error("Unknown error\n"); + return false; + } +} + +bool TaskHypothesis::reject() +{ + return widget->reject(); +} + +#include "moc_Hypothesis.cpp" diff --git a/src/Mod/Fem/Gui/Hypothesis.h b/src/Mod/Fem/Gui/Hypothesis.h new file mode 100644 index 000000000..c3edfe9bf --- /dev/null +++ b/src/Mod/Fem/Gui/Hypothesis.h @@ -0,0 +1,75 @@ +/*************************************************************************** + * Copyright (c) 2012 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_HYPOTHESIS_H +#define FEMGUI_HYPOTHESIS_H + +#include +#include + +namespace FemGui { + +class Ui_HypothesisWidget; +class HypothesisWidget : public QWidget +{ + Q_OBJECT + +public: + HypothesisWidget(QWidget* parent = 0); + ~HypothesisWidget(); + bool accept(); + bool reject(); + +private: + void changeEvent(QEvent *e); + +private: + Ui_HypothesisWidget* ui; +}; + +class TaskHypothesis : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskHypothesis(); + ~TaskHypothesis(); + +public: + void open(); + bool accept(); + bool reject(); + + QDialogButtonBox::StandardButtons getStandardButtons() const + { return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; } + bool needsFullSpace() const + { return true; } + +private: + HypothesisWidget* widget; + Gui::TaskView::TaskBox* taskbox; +}; + +} //namespace FemGui + +#endif // FEMGUI_HYPOTHESIS_H diff --git a/src/Mod/Fem/Gui/Hypothesis.ui b/src/Mod/Fem/Gui/Hypothesis.ui new file mode 100644 index 000000000..c5ecd67d2 --- /dev/null +++ b/src/Mod/Fem/Gui/Hypothesis.ui @@ -0,0 +1,166 @@ + + + FemGui::HypothesisWidget + + + + 0 + 0 + 299 + 238 + + + + Hypothesis + + + + + + + + Quadrangle + + + true + + + + + + + Maximum length + + + true + + + + + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + Local length + + + true + + + + + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + Maximum element area + + + true + + + + + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + + + Qt::Vertical + + + + 20 + 65 + + + + + + + + quadPref + maxLength + valMaxLength + localLength + valLocalLength + maxArea + valMaxArea + + + + + maxLength + toggled(bool) + valMaxLength + setEnabled(bool) + + + 73 + 92 + + + 172 + 88 + + + + + localLength + toggled(bool) + valLocalLength + setEnabled(bool) + + + 44 + 116 + + + 186 + 118 + + + + + maxArea + toggled(bool) + valMaxArea + setEnabled(bool) + + + 61 + 144 + + + 197 + 145 + + + + + diff --git a/src/Mod/Fem/Gui/Makefile.am b/src/Mod/Fem/Gui/Makefile.am index 6a009e648..8c54a6194 100644 --- a/src/Mod/Fem/Gui/Makefile.am +++ b/src/Mod/Fem/Gui/Makefile.am @@ -2,9 +2,15 @@ SUBDIRS=Resources lib_LTLIBRARIES=libFemGui.la FemGui.la +BUILT_SOURCES=\ + ui_Hypothesis.h \ + moc_Hypothesis.cpp + libFemGui_la_SOURCES=\ AppFemGuiPy.cpp \ Command.cpp \ + Hypothesis.cpp \ + Hypothesis.h \ PreCompiled.cpp \ PreCompiled.h \ ViewProviderFemMesh.cpp \ @@ -78,5 +84,6 @@ libdir = $(prefix)/Mod/Fem CLEANFILES = $(BUILT_SOURCES) EXTRA_DIST = \ - CMakeLists.txt + CMakeLists.txt \ + Hypothesis.ui diff --git a/src/Mod/Fem/Init.py b/src/Mod/Fem/Init.py index c14018810..c8b99743d 100644 --- a/src/Mod/Fem/Init.py +++ b/src/Mod/Fem/Init.py @@ -45,4 +45,4 @@ ParGrp = App.ParamGet("System parameter:Modules").GetGroup("Fem") FreeCAD.addExportType("TetGen file (*.poly)","convert2TetGen") FreeCAD.addImportType("FEM formats (*.unv *.med *.dat *.bdf)","Fem") -FreeCAD.addExportType("FEM formats (*.unv *.med *.dat)","Fem") +FreeCAD.addExportType("FEM formats (*.unv *.med *.dat *.inp)","Fem")